Comparing version 4.0.0-beta.6 to 4.0.0-beta.7
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseAuthAPI = exports.AuthApiError = void 0; | ||
exports.grant = exports.BaseAuthAPI = exports.AuthApiError = void 0; | ||
const errors_js_1 = require("../lib/errors.js"); | ||
@@ -50,3 +50,8 @@ const runtime_js_1 = require("../lib/runtime.js"); | ||
constructor(options) { | ||
super({ ...options, baseUrl: `https://${options.domain}`, parseError }); | ||
super({ | ||
...options, | ||
baseUrl: `https://${options.domain}`, | ||
parseError, | ||
retry: { enabled: false, ...options.retry }, | ||
}); | ||
this.domain = options.domain; | ||
@@ -61,7 +66,6 @@ this.clientId = options.clientId; | ||
*/ | ||
async addClientAuthentication(payload, required) { | ||
async addClientAuthentication(payload) { | ||
return (0, client_authentication_js_1.addClientAuthentication)({ | ||
payload, | ||
domain: this.domain, | ||
required, | ||
clientId: this.clientId, | ||
@@ -75,2 +79,26 @@ clientSecret: this.clientSecret, | ||
exports.BaseAuthAPI = BaseAuthAPI; | ||
/** | ||
* @private | ||
* Perform an OAuth 2.0 grant. | ||
*/ | ||
async function grant(grantType, bodyParameters, { idTokenValidateOptions, initOverrides } = {}, clientId, idTokenValidator, request) { | ||
const response = await request({ | ||
path: '/oauth/token', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: new URLSearchParams({ | ||
client_id: clientId, | ||
...bodyParameters, | ||
grant_type: grantType, | ||
}), | ||
}, initOverrides); | ||
const res = await runtime_js_1.JSONApiResponse.fromResponse(response); | ||
if (res.data.id_token) { | ||
await idTokenValidator.validate(res.data.id_token, idTokenValidateOptions); | ||
} | ||
return res; | ||
} | ||
exports.grant = grant; | ||
//# sourceMappingURL=base-auth-api.js.map |
@@ -37,3 +37,3 @@ "use strict"; | ||
*/ | ||
const addClientAuthentication = async ({ payload, domain, clientId, required, clientAssertionSigningKey, clientAssertionSigningAlg, clientSecret, }) => { | ||
const addClientAuthentication = async ({ payload, domain, clientId, clientAssertionSigningKey, clientAssertionSigningAlg, clientSecret, }) => { | ||
const cid = payload.client_id || clientId; | ||
@@ -57,4 +57,3 @@ if (clientAssertionSigningKey && !payload.client_assertion) { | ||
} | ||
if (required && | ||
(!payload.client_secret || payload.client_secret.trim().length === 0) && | ||
if ((!payload.client_secret || payload.client_secret.trim().length === 0) && | ||
(!payload.client_assertion || payload.client_assertion.trim().length === 0)) { | ||
@@ -61,0 +60,0 @@ throw new Error('The client_secret or client_assertion field is required.'); |
@@ -15,30 +15,3 @@ "use strict"; | ||
} | ||
async validateIdToken(tokenSet, idTokenValidateOptions) { | ||
const { id_token: idToken } = tokenSet; | ||
if (idToken) { | ||
await this.idTokenValidator.validate(idToken, idTokenValidateOptions); | ||
} | ||
} | ||
/** | ||
* Perform an OAuth 2.0 grant. | ||
* (You should only need this if you can't find the grant you need in this library.) | ||
*/ | ||
async grant(grantType, bodyParameters, { idTokenValidateOptions, initOverrides } = {}) { | ||
const response = await this.request({ | ||
path: '/oauth/token', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: new URLSearchParams({ | ||
client_id: this.clientId, | ||
...bodyParameters, | ||
grant_type: grantType, | ||
}), | ||
}, initOverrides); | ||
const res = await runtime_js_1.JSONApiResponse.fromResponse(response); | ||
await this.validateIdToken(res.data, idTokenValidateOptions); | ||
return res; | ||
} | ||
/** | ||
* This is the flow that regular web apps use to access an API. | ||
@@ -63,3 +36,3 @@ * | ||
(0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ['code']); | ||
return this.grant('authorization_code', await this.addClientAuthentication(bodyParameters, true), options); | ||
return (0, base_auth_api_js_1.grant)('authorization_code', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -89,3 +62,3 @@ /** | ||
(0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ['code', 'code_verifier']); | ||
return this.grant('authorization_code', await this.addClientAuthentication(bodyParameters, false), options); | ||
return (0, base_auth_api_js_1.grant)('authorization_code', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -113,3 +86,3 @@ /** | ||
(0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ['audience']); | ||
return this.grant('client_credentials', await this.addClientAuthentication(bodyParameters, true), options); | ||
return (0, base_auth_api_js_1.grant)('client_credentials', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -130,7 +103,7 @@ /** | ||
* | ||
* await auth0.oauth.clientCredentialsGrant({ | ||
* await auth0.oauth.passwordGrant({ | ||
* username: 'myusername@example.com', | ||
* password: 'mypassword' | ||
* }, | ||
* { headers: { 'auth0-forwarded-for': 'END.USER.IP.123' } } | ||
* { initOverrides: { headers: { 'auth0-forwarded-for': 'END.USER.IP.123' } } } | ||
* ); | ||
@@ -147,3 +120,3 @@ * ``` | ||
(0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ['username', 'password']); | ||
return this.grant(bodyParameters.realm ? 'http://auth0.com/oauth/grant-type/password-realm' : 'password', await this.addClientAuthentication(bodyParameters, false), options); | ||
return (0, base_auth_api_js_1.grant)(bodyParameters.realm ? 'http://auth0.com/oauth/grant-type/password-realm' : 'password', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -168,3 +141,3 @@ /** | ||
(0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ['refresh_token']); | ||
return this.grant('refresh_token', await this.addClientAuthentication(bodyParameters, false), options); | ||
return (0, base_auth_api_js_1.grant)('refresh_token', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -200,3 +173,3 @@ /** | ||
}, | ||
body: await this.addClientAuthentication({ client_id: this.clientId, ...bodyParameters }, false), | ||
body: await this.addClientAuthentication({ client_id: this.clientId, ...bodyParameters }), | ||
}, options.initOverrides); | ||
@@ -203,0 +176,0 @@ return runtime_js_1.VoidApiResponse.fromResponse(response); |
@@ -6,3 +6,3 @@ "use strict"; | ||
const base_auth_api_js_1 = require("./base-auth-api.js"); | ||
const oauth_js_1 = require("./oauth.js"); | ||
const id_token_validator_js_1 = require("./id-token-validator.js"); | ||
/** | ||
@@ -14,3 +14,3 @@ * Handles passwordless flows using Email and SMS. | ||
super(configuration); | ||
this.oauth = new oauth_js_1.OAuth(configuration); | ||
this.idTokenValidator = new id_token_validator_js_1.IDTokenValidator(configuration); | ||
} | ||
@@ -61,3 +61,7 @@ /** | ||
}, | ||
body: await this.addClientAuthentication({ client_id: this.clientId, connection: 'email', ...bodyParameters }, false), | ||
body: await this.addClientAuthentication({ | ||
client_id: this.clientId, | ||
connection: 'email', | ||
...bodyParameters, | ||
}), | ||
}, initOverrides); | ||
@@ -97,3 +101,7 @@ return runtime_js_1.VoidApiResponse.fromResponse(response); | ||
}, | ||
body: await this.addClientAuthentication({ client_id: this.clientId, connection: 'sms', ...bodyParameters }, false), | ||
body: await this.addClientAuthentication({ | ||
client_id: this.clientId, | ||
connection: 'sms', | ||
...bodyParameters, | ||
}), | ||
}, initOverrides); | ||
@@ -122,3 +130,3 @@ return runtime_js_1.VoidApiResponse.fromResponse(response); | ||
const { email: username, code: otp, ...otherParams } = bodyParameters; | ||
return this.oauth.grant('http://auth0.com/oauth/grant-type/passwordless/otp', await this.addClientAuthentication({ | ||
return (0, base_auth_api_js_1.grant)('http://auth0.com/oauth/grant-type/passwordless/otp', await this.addClientAuthentication({ | ||
username, | ||
@@ -128,3 +136,3 @@ otp, | ||
...otherParams, | ||
}, false), options); | ||
}), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -151,3 +159,3 @@ /** | ||
const { phone_number: username, code: otp, ...otherParams } = bodyParameters; | ||
return this.oauth.grant('http://auth0.com/oauth/grant-type/passwordless/otp', await this.addClientAuthentication({ | ||
return (0, base_auth_api_js_1.grant)('http://auth0.com/oauth/grant-type/passwordless/otp', await this.addClientAuthentication({ | ||
username, | ||
@@ -157,3 +165,3 @@ otp, | ||
...otherParams, | ||
}, false), options); | ||
}), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -160,0 +168,0 @@ } |
@@ -20,2 +20,3 @@ "use strict"; | ||
__exportStar(require("./userinfo/index.js"), exports); | ||
__exportStar(require("./lib/errors.js"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -6,6 +6,5 @@ "use strict"; | ||
const MAX_REQUEST_RETRY_DELAY = 10000; | ||
const MIN_REQUEST_RETRY_DELAY = 250; | ||
const DEFAULT_NUMBER_RETRIES = 5; | ||
const DEFAULT_NUMBER_RETRIES = 3; | ||
const MAX_NUMBER_RETRIES = 10; | ||
const BASE_DELAY = 250; | ||
const BASE_DELAY = 500; | ||
/** | ||
@@ -47,3 +46,2 @@ * @private | ||
wait = Math.min(wait, MAX_REQUEST_RETRY_DELAY); | ||
wait = Math.max(wait, MIN_REQUEST_RETRY_DELAY); | ||
await pause(wait); | ||
@@ -50,0 +48,0 @@ result = await retryAndWait(); |
@@ -17,14 +17,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseFormParam = exports.applyQueryParams = exports.validateRequiredRequestParams = exports.COLLECTION_FORMATS = exports.BaseAPI = exports.getFormDataCls = void 0; | ||
exports.parseFormParam = exports.applyQueryParams = exports.validateRequiredRequestParams = exports.COLLECTION_FORMATS = exports.BaseAPI = void 0; | ||
const retry_js_1 = require("./retry.js"); | ||
const errors_js_1 = require("./errors.js"); | ||
/** | ||
* @private | ||
*/ | ||
const nodeFetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args)); | ||
/** | ||
* @private | ||
*/ | ||
const getFormDataCls = async () => import('node-fetch').then(({ FormData }) => FormData); | ||
exports.getFormDataCls = getFormDataCls; | ||
__exportStar(require("./models.js"), exports); | ||
@@ -118,3 +109,3 @@ /** | ||
this.middleware = configuration.middleware || []; | ||
this.fetchApi = configuration.fetchApi || nodeFetch; | ||
this.fetchApi = configuration.fetchApi || fetch; | ||
this.parseError = configuration.parseError; | ||
@@ -157,6 +148,5 @@ this.timeoutDuration = | ||
}; | ||
const { Blob } = await import('node-fetch'); | ||
const init = { | ||
...overriddenInit, | ||
body: (await isFormData(overriddenInit.body)) || | ||
body: overriddenInit.body instanceof FormData || | ||
overriddenInit.body instanceof URLSearchParams || | ||
@@ -171,6 +161,2 @@ overriddenInit.body instanceof Blob | ||
exports.BaseAPI = BaseAPI; | ||
async function isFormData(value) { | ||
const FormData = await (0, exports.getFormDataCls)(); | ||
return typeof FormData !== 'undefined' && value instanceof FormData; | ||
} | ||
/** | ||
@@ -243,8 +229,2 @@ * @private | ||
value = typeof value == 'number' || typeof value == 'boolean' ? '' + value : value; | ||
if (typeof originalValue === 'object' && | ||
'path' in originalValue && | ||
typeof originalValue.path === 'string') { | ||
const { fileFrom } = await import('node-fetch'); | ||
value = await fileFrom(originalValue.path, 'application/json'); | ||
} | ||
return value; | ||
@@ -251,0 +231,0 @@ } |
@@ -85,3 +85,3 @@ "use strict"; | ||
async importUsers(bodyParameters, initOverrides) { | ||
const formParams = new (await runtime.getFormDataCls())(); | ||
const formParams = new FormData(); | ||
if (bodyParameters.users !== undefined) { | ||
@@ -88,0 +88,0 @@ formParams.append('users', await runtime.parseFormParam(bodyParameters.users)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '4.0.0-beta.6'; | ||
exports.version = '4.0.0-beta.7'; | ||
//# sourceMappingURL=version.js.map |
import { ResponseError } from '../lib/errors.js'; | ||
import { BaseAPI } from '../lib/runtime.js'; | ||
import { BaseAPI, JSONApiResponse, } from '../lib/runtime.js'; | ||
import { addClientAuthentication, } from './client-authentication.js'; | ||
@@ -46,3 +46,8 @@ export class AuthApiError extends Error { | ||
constructor(options) { | ||
super({ ...options, baseUrl: `https://${options.domain}`, parseError }); | ||
super({ | ||
...options, | ||
baseUrl: `https://${options.domain}`, | ||
parseError, | ||
retry: { enabled: false, ...options.retry }, | ||
}); | ||
this.domain = options.domain; | ||
@@ -57,7 +62,6 @@ this.clientId = options.clientId; | ||
*/ | ||
async addClientAuthentication(payload, required) { | ||
async addClientAuthentication(payload) { | ||
return addClientAuthentication({ | ||
payload, | ||
domain: this.domain, | ||
required, | ||
clientId: this.clientId, | ||
@@ -70,2 +74,25 @@ clientSecret: this.clientSecret, | ||
} | ||
/** | ||
* @private | ||
* Perform an OAuth 2.0 grant. | ||
*/ | ||
export async function grant(grantType, bodyParameters, { idTokenValidateOptions, initOverrides } = {}, clientId, idTokenValidator, request) { | ||
const response = await request({ | ||
path: '/oauth/token', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: new URLSearchParams({ | ||
client_id: clientId, | ||
...bodyParameters, | ||
grant_type: grantType, | ||
}), | ||
}, initOverrides); | ||
const res = await JSONApiResponse.fromResponse(response); | ||
if (res.data.id_token) { | ||
await idTokenValidator.validate(res.data.id_token, idTokenValidateOptions); | ||
} | ||
return res; | ||
} | ||
//# sourceMappingURL=base-auth-api.js.map |
@@ -11,3 +11,3 @@ import * as jose from 'jose'; | ||
*/ | ||
export const addClientAuthentication = async ({ payload, domain, clientId, required, clientAssertionSigningKey, clientAssertionSigningAlg, clientSecret, }) => { | ||
export const addClientAuthentication = async ({ payload, domain, clientId, clientAssertionSigningKey, clientAssertionSigningAlg, clientSecret, }) => { | ||
const cid = payload.client_id || clientId; | ||
@@ -31,4 +31,3 @@ if (clientAssertionSigningKey && !payload.client_assertion) { | ||
} | ||
if (required && | ||
(!payload.client_secret || payload.client_secret.trim().length === 0) && | ||
if ((!payload.client_secret || payload.client_secret.trim().length === 0) && | ||
(!payload.client_assertion || payload.client_assertion.trim().length === 0)) { | ||
@@ -35,0 +34,0 @@ throw new Error('The client_secret or client_assertion field is required.'); |
@@ -1,3 +0,3 @@ | ||
import { JSONApiResponse, VoidApiResponse, validateRequiredRequestParams, } from '../lib/runtime.js'; | ||
import { BaseAuthAPI } from './base-auth-api.js'; | ||
import { VoidApiResponse, validateRequiredRequestParams, } from '../lib/runtime.js'; | ||
import { BaseAuthAPI, grant } from './base-auth-api.js'; | ||
import { IDTokenValidator } from './id-token-validator.js'; | ||
@@ -12,30 +12,3 @@ /** | ||
} | ||
async validateIdToken(tokenSet, idTokenValidateOptions) { | ||
const { id_token: idToken } = tokenSet; | ||
if (idToken) { | ||
await this.idTokenValidator.validate(idToken, idTokenValidateOptions); | ||
} | ||
} | ||
/** | ||
* Perform an OAuth 2.0 grant. | ||
* (You should only need this if you can't find the grant you need in this library.) | ||
*/ | ||
async grant(grantType, bodyParameters, { idTokenValidateOptions, initOverrides } = {}) { | ||
const response = await this.request({ | ||
path: '/oauth/token', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: new URLSearchParams({ | ||
client_id: this.clientId, | ||
...bodyParameters, | ||
grant_type: grantType, | ||
}), | ||
}, initOverrides); | ||
const res = await JSONApiResponse.fromResponse(response); | ||
await this.validateIdToken(res.data, idTokenValidateOptions); | ||
return res; | ||
} | ||
/** | ||
* This is the flow that regular web apps use to access an API. | ||
@@ -60,3 +33,3 @@ * | ||
validateRequiredRequestParams(bodyParameters, ['code']); | ||
return this.grant('authorization_code', await this.addClientAuthentication(bodyParameters, true), options); | ||
return grant('authorization_code', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -86,3 +59,3 @@ /** | ||
validateRequiredRequestParams(bodyParameters, ['code', 'code_verifier']); | ||
return this.grant('authorization_code', await this.addClientAuthentication(bodyParameters, false), options); | ||
return grant('authorization_code', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -110,3 +83,3 @@ /** | ||
validateRequiredRequestParams(bodyParameters, ['audience']); | ||
return this.grant('client_credentials', await this.addClientAuthentication(bodyParameters, true), options); | ||
return grant('client_credentials', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -127,7 +100,7 @@ /** | ||
* | ||
* await auth0.oauth.clientCredentialsGrant({ | ||
* await auth0.oauth.passwordGrant({ | ||
* username: 'myusername@example.com', | ||
* password: 'mypassword' | ||
* }, | ||
* { headers: { 'auth0-forwarded-for': 'END.USER.IP.123' } } | ||
* { initOverrides: { headers: { 'auth0-forwarded-for': 'END.USER.IP.123' } } } | ||
* ); | ||
@@ -144,3 +117,3 @@ * ``` | ||
validateRequiredRequestParams(bodyParameters, ['username', 'password']); | ||
return this.grant(bodyParameters.realm ? 'http://auth0.com/oauth/grant-type/password-realm' : 'password', await this.addClientAuthentication(bodyParameters, false), options); | ||
return grant(bodyParameters.realm ? 'http://auth0.com/oauth/grant-type/password-realm' : 'password', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -165,3 +138,3 @@ /** | ||
validateRequiredRequestParams(bodyParameters, ['refresh_token']); | ||
return this.grant('refresh_token', await this.addClientAuthentication(bodyParameters, false), options); | ||
return grant('refresh_token', await this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -197,3 +170,3 @@ /** | ||
}, | ||
body: await this.addClientAuthentication({ client_id: this.clientId, ...bodyParameters }, false), | ||
body: await this.addClientAuthentication({ client_id: this.clientId, ...bodyParameters }), | ||
}, options.initOverrides); | ||
@@ -200,0 +173,0 @@ return VoidApiResponse.fromResponse(response); |
import { VoidApiResponse, validateRequiredRequestParams, } from '../lib/runtime.js'; | ||
import { BaseAuthAPI } from './base-auth-api.js'; | ||
import { OAuth } from './oauth.js'; | ||
import { BaseAuthAPI, grant } from './base-auth-api.js'; | ||
import { IDTokenValidator } from './id-token-validator.js'; | ||
/** | ||
@@ -10,3 +10,3 @@ * Handles passwordless flows using Email and SMS. | ||
super(configuration); | ||
this.oauth = new OAuth(configuration); | ||
this.idTokenValidator = new IDTokenValidator(configuration); | ||
} | ||
@@ -57,3 +57,7 @@ /** | ||
}, | ||
body: await this.addClientAuthentication({ client_id: this.clientId, connection: 'email', ...bodyParameters }, false), | ||
body: await this.addClientAuthentication({ | ||
client_id: this.clientId, | ||
connection: 'email', | ||
...bodyParameters, | ||
}), | ||
}, initOverrides); | ||
@@ -93,3 +97,7 @@ return VoidApiResponse.fromResponse(response); | ||
}, | ||
body: await this.addClientAuthentication({ client_id: this.clientId, connection: 'sms', ...bodyParameters }, false), | ||
body: await this.addClientAuthentication({ | ||
client_id: this.clientId, | ||
connection: 'sms', | ||
...bodyParameters, | ||
}), | ||
}, initOverrides); | ||
@@ -118,3 +126,3 @@ return VoidApiResponse.fromResponse(response); | ||
const { email: username, code: otp, ...otherParams } = bodyParameters; | ||
return this.oauth.grant('http://auth0.com/oauth/grant-type/passwordless/otp', await this.addClientAuthentication({ | ||
return grant('http://auth0.com/oauth/grant-type/passwordless/otp', await this.addClientAuthentication({ | ||
username, | ||
@@ -124,3 +132,3 @@ otp, | ||
...otherParams, | ||
}, false), options); | ||
}), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
@@ -147,3 +155,3 @@ /** | ||
const { phone_number: username, code: otp, ...otherParams } = bodyParameters; | ||
return this.oauth.grant('http://auth0.com/oauth/grant-type/passwordless/otp', await this.addClientAuthentication({ | ||
return grant('http://auth0.com/oauth/grant-type/passwordless/otp', await this.addClientAuthentication({ | ||
username, | ||
@@ -153,5 +161,5 @@ otp, | ||
...otherParams, | ||
}, false), options); | ||
}), options, this.clientId, this.idTokenValidator, this.request.bind(this)); | ||
} | ||
} | ||
//# sourceMappingURL=passwordless.js.map |
export * from './management/index.js'; | ||
export * from './auth/index.js'; | ||
export * from './userinfo/index.js'; | ||
export * from './lib/errors.js'; | ||
//# sourceMappingURL=index.js.map |
const MAX_REQUEST_RETRY_JITTER = 250; | ||
const MAX_REQUEST_RETRY_DELAY = 10000; | ||
const MIN_REQUEST_RETRY_DELAY = 250; | ||
const DEFAULT_NUMBER_RETRIES = 5; | ||
const DEFAULT_NUMBER_RETRIES = 3; | ||
const MAX_NUMBER_RETRIES = 10; | ||
const BASE_DELAY = 250; | ||
const BASE_DELAY = 500; | ||
/** | ||
@@ -43,3 +42,2 @@ * @private | ||
wait = Math.min(wait, MAX_REQUEST_RETRY_DELAY); | ||
wait = Math.max(wait, MIN_REQUEST_RETRY_DELAY); | ||
await pause(wait); | ||
@@ -46,0 +44,0 @@ result = await retryAndWait(); |
import { retry } from './retry.js'; | ||
import { FetchError, RequiredError, TimeoutError } from './errors.js'; | ||
/** | ||
* @private | ||
*/ | ||
const nodeFetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args)); | ||
/** | ||
* @private | ||
*/ | ||
export const getFormDataCls = async () => import('node-fetch').then(({ FormData }) => FormData); | ||
export * from './models.js'; | ||
@@ -99,3 +91,3 @@ /** | ||
this.middleware = configuration.middleware || []; | ||
this.fetchApi = configuration.fetchApi || nodeFetch; | ||
this.fetchApi = configuration.fetchApi || fetch; | ||
this.parseError = configuration.parseError; | ||
@@ -138,6 +130,5 @@ this.timeoutDuration = | ||
}; | ||
const { Blob } = await import('node-fetch'); | ||
const init = { | ||
...overriddenInit, | ||
body: (await isFormData(overriddenInit.body)) || | ||
body: overriddenInit.body instanceof FormData || | ||
overriddenInit.body instanceof URLSearchParams || | ||
@@ -151,6 +142,2 @@ overriddenInit.body instanceof Blob | ||
} | ||
async function isFormData(value) { | ||
const FormData = await getFormDataCls(); | ||
return typeof FormData !== 'undefined' && value instanceof FormData; | ||
} | ||
/** | ||
@@ -221,10 +208,4 @@ * @private | ||
value = typeof value == 'number' || typeof value == 'boolean' ? '' + value : value; | ||
if (typeof originalValue === 'object' && | ||
'path' in originalValue && | ||
typeof originalValue.path === 'string') { | ||
const { fileFrom } = await import('node-fetch'); | ||
value = await fileFrom(originalValue.path, 'application/json'); | ||
} | ||
return value; | ||
} | ||
//# sourceMappingURL=runtime.js.map |
@@ -59,3 +59,3 @@ import * as runtime from '../../../lib/runtime.js'; | ||
async importUsers(bodyParameters, initOverrides) { | ||
const formParams = new (await runtime.getFormDataCls())(); | ||
const formParams = new FormData(); | ||
if (bodyParameters.users !== undefined) { | ||
@@ -62,0 +62,0 @@ formParams.append('users', await runtime.parseFormParam(bodyParameters.users)); |
@@ -1,2 +0,2 @@ | ||
export const version = '4.0.0-beta.6'; | ||
export const version = '4.0.0-beta.7'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "auth0", | ||
"version": "4.0.0-beta.6", | ||
"version": "4.0.0-beta.7", | ||
"description": "SDK for Auth0 API v2", | ||
"main": "dist/cjs/index.js", | ||
"types": "dist/types/index.d.ts", | ||
"types": "dist/cjs/index.d.ts", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"require": "./dist/cjs/index.js", | ||
"import": "./dist/esm/index.js", | ||
"types": "./dist/types/index.d.ts" | ||
"import": { | ||
"default": "./dist/esm/index.js", | ||
"types": "./dist/esm/index.d.ts" | ||
}, | ||
"require": { | ||
"default": "./dist/cjs/index.js", | ||
"types": "./dist/cjs/index.d.ts" | ||
} | ||
} | ||
@@ -21,10 +26,8 @@ }, | ||
"prebuild": "rm -rf dist", | ||
"build": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json && echo '{\"type\": \"commonjs\"}'> dist/cjs/package.json", | ||
"build": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json && echo '{\"type\": \"commonjs\"}'> dist/cjs/package.json", | ||
"docs": "typedoc --options typedoc.cjs", | ||
"test": "npm run test:mocha && npm run test:jest", | ||
"test:mocha": "TS_NODE_COMPILER_OPTIONS='{\"moduleResolution\":\"node\"}' NODE_OPTIONS='--experimental-vm-modules --no-warnings' mocha", | ||
"test:jest": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest", | ||
"test:ci": "c8 npm run test", | ||
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest", | ||
"test:ci": "c8 npm run test -- --maxWorkers=1", | ||
"precommit": "pretty-quick --staged", | ||
"lint": "eslint ./src --ext ts", | ||
"lint": "eslint ./src ./test --ext ts", | ||
"start:playground": "node --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm playground/index.ts" | ||
@@ -37,3 +40,3 @@ }, | ||
"engines": { | ||
"node": ">=16" | ||
"node": ">=18" | ||
}, | ||
@@ -52,10 +55,6 @@ "keywords": [ | ||
"jose": "^4.13.2", | ||
"node-fetch": "^3.3.1", | ||
"uuid": "^9.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.3.4", | ||
"@types/chai-as-promised": "^7.1.5", | ||
"@types/jest": "^29.5.0", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^16.18.37", | ||
@@ -67,4 +66,2 @@ "@types/node-fetch": "^2.6.3", | ||
"c8": "^7.13.0", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"commander": "^10.0.1", | ||
@@ -80,7 +77,6 @@ "dotenv": "^16.0.3", | ||
"jest": "^29.5.0", | ||
"mocha": "^9.1.3", | ||
"nock": "^13.2.7", | ||
"node-fetch": "^3.3.1", | ||
"prettier": "^2.8.7", | ||
"pretty-quick": "^1.11.1", | ||
"sinon": "^14.0.0", | ||
"ts-jest": "^29.1.0", | ||
@@ -87,0 +83,0 @@ "ts-node": "^10.9.1", |
@@ -23,3 +23,3 @@ ![Node.js client library for Auth0](https://cdn.auth0.com/website/sdks/banner/node-auth0-banner.png) | ||
- Node.js: `>=16` | ||
- Node.js: `>=18` | ||
@@ -40,4 +40,2 @@ ### Installation | ||
The **AuthenticationClient** constructor takes an _optional_ client ID, if specified it will be used as default value for all endpoints that accept a client ID. | ||
```js | ||
@@ -53,2 +51,4 @@ import { AuthenticationClient } from 'auth0'; | ||
See [more examples](./EXAMPLES.md#authentication-client). | ||
#### Management API Client | ||
@@ -58,3 +58,3 @@ | ||
Initialize your client class with an API v2 token and a domain. | ||
Initialize your client class with a client ID, client secret and a domain. | ||
@@ -65,8 +65,9 @@ ```js | ||
var management = new ManagementClient({ | ||
domain: '{YOUR_ACCOUNT}.auth0.com', | ||
token: '{YOUR_API_V2_TOKEN}', | ||
domain: '{YOUR_TENANT_AND REGION}.auth0.com', | ||
clientId: '{YOUR_CLIENT_ID}', | ||
clientSecret: '{YOUR_CLIENT_SECRET}', | ||
}); | ||
``` | ||
Or, initialize your client class with a client secret and a domain. | ||
Or, initialize your client class with an API v2 token and a domain. | ||
@@ -77,7 +78,9 @@ ```js | ||
var management = new ManagementClient({ | ||
domain: '{YOUR_TENANT_AND REGION}.auth0.com', | ||
token: '{YOUR_API_V2_TOKEN}', | ||
domain: '{YOUR_ACCOUNT}.auth0.com', | ||
}); | ||
``` | ||
See [more examples](./EXAMPLES.md#management-client). | ||
## API Reference | ||
@@ -84,0 +87,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2026505
2
25
340
50873
117
3
- Removednode-fetch@^3.3.1
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)