@supabase/gotrue-js
Advanced tools
Comparing version 2.46.2 to 2.47.0
@@ -49,2 +49,4 @@ import GoTrueAdminApi from './GoTrueAdminApi'; | ||
protected lock: LockFunc; | ||
protected lockAcquired: boolean; | ||
protected pendingInLock: Promise<any>[]; | ||
/** | ||
@@ -102,2 +104,3 @@ * Used to broadcast state change events to other tabs listening. | ||
exchangeCodeForSession(authCode: string): Promise<AuthTokenResponse>; | ||
private _exchangeCodeForSession; | ||
/** | ||
@@ -150,2 +153,3 @@ * Allows signing in with an OIDC ID token. The authentication provider used | ||
reauthenticate(): Promise<AuthResponse>; | ||
private _reauthenticate; | ||
/** | ||
@@ -197,2 +201,3 @@ * Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP. | ||
getUser(jwt?: string): Promise<UserResponse>; | ||
private _getUser; | ||
/** | ||
@@ -204,2 +209,5 @@ * Updates user data for a logged in user. | ||
}): Promise<UserResponse>; | ||
protected _updateUser(attributes: UserAttributes, options?: { | ||
emailRedirectTo?: string | undefined; | ||
}): Promise<UserResponse>; | ||
/** | ||
@@ -218,2 +226,6 @@ * Decodes a JWT (without performing any validation). | ||
}): Promise<AuthResponse>; | ||
protected _setSession(currentSession: { | ||
access_token: string; | ||
refresh_token: string; | ||
}): Promise<AuthResponse>; | ||
/** | ||
@@ -228,2 +240,5 @@ * Returns a new session, regardless of expiry status. | ||
}): Promise<AuthResponse>; | ||
protected _refreshSession(currentSession?: { | ||
refresh_token: string; | ||
}): Promise<AuthResponse>; | ||
/** | ||
@@ -250,5 +265,8 @@ * Gets the session data from a URL string | ||
*/ | ||
signOut({ scope }?: SignOut): Promise<{ | ||
signOut(options?: SignOut): Promise<{ | ||
error: AuthError | null; | ||
}>; | ||
protected _signOut({ scope }?: SignOut): Promise<{ | ||
error: AuthError | null; | ||
}>; | ||
/** | ||
@@ -255,0 +273,0 @@ * Receive a notification every time an auth event happens. |
@@ -47,32 +47,3 @@ import { SupportedStorage } from './types'; | ||
export declare function generatePKCEChallenge(verifier: string): Promise<string>; | ||
/** | ||
* Checks if the current caller of the function is in a {@link | ||
* #stackGuard} of the provided `name`. Works by looking through | ||
* the stack trace of an `Error` object for a special function | ||
* name (generated by {@link #stackGuard}). | ||
* | ||
* @param name The name of the stack guard to check for. Must be `[a-zA-Z0-9_-]` only. | ||
*/ | ||
export declare function isInStackGuard(name: string): boolean; | ||
/** | ||
* Creates a minification resistant stack guard, i.e. if you | ||
* call {@link #isInStackGuard} from within the `fn` parameter | ||
* function, you will always get `true` otherwise it will be | ||
* `false`. | ||
* | ||
* Works by dynamically defining a function name before calling | ||
* into `fn`, which is then parsed from the stack trace on an | ||
* `Error` object within {@link #isInStackGuard}. | ||
* | ||
* @param name The name of the stack guard. Must be `[a-zA-Z0-9_-]` only. | ||
* @param fn The async/await function to be run within the stack guard. | ||
*/ | ||
export declare function stackGuard<R>(name: string, fn: () => Promise<R>): Promise<R>; | ||
/** | ||
* Returns if the JavaScript engine supports stack guards. If it doesn't | ||
* certain features that depend on detecting recursive calls should be disabled | ||
* to prevent deadlocks. | ||
*/ | ||
export declare function stackGuardsSupported(): Promise<boolean>; | ||
export {}; | ||
//# sourceMappingURL=helpers.d.ts.map |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stackGuardsSupported = exports.stackGuard = exports.isInStackGuard = exports.generatePKCEChallenge = exports.generatePKCEVerifier = exports.retryable = exports.sleep = exports.decodeJWTPayload = exports.Deferred = exports.decodeBase64URL = exports.removeItemAsync = exports.getItemAsync = exports.setItemAsync = exports.looksLikeFetchResponse = exports.resolveFetch = exports.parseParametersFromURL = exports.supportsLocalStorage = exports.isBrowser = exports.uuid = exports.expiresAt = void 0; | ||
exports.generatePKCEChallenge = exports.generatePKCEVerifier = exports.retryable = exports.sleep = exports.decodeJWTPayload = exports.Deferred = exports.decodeBase64URL = exports.removeItemAsync = exports.getItemAsync = exports.setItemAsync = exports.looksLikeFetchResponse = exports.resolveFetch = exports.parseParametersFromURL = exports.supportsLocalStorage = exports.isBrowser = exports.uuid = exports.expiresAt = void 0; | ||
function expiresAt(expiresIn) { | ||
@@ -290,118 +290,2 @@ const timeNow = Math.round(Date.now() / 1000); | ||
exports.generatePKCEChallenge = generatePKCEChallenge; | ||
const STACK_GUARD_PREFIX = `__stack_guard__`; | ||
const STACK_GUARD_SUFFIX = `__`; | ||
// Firefox and WebKit based browsers encode the stack entry differently, but | ||
// they all include the function name. So instead of trying to parse the entry, | ||
// we're only looking for the special string `__stack_guard__${guardName}__`. | ||
// Guard names can only be letters with dashes or underscores. | ||
// | ||
// Example Firefox stack trace: | ||
// ``` | ||
// __stack_guard__EXAMPLE__@debugger eval code:1:55 | ||
// @debugger eval code:1:3 | ||
// ``` | ||
// | ||
// Example WebKit/Chrome stack trace: | ||
// ``` | ||
// Error | ||
// at Object.__stack_guard__EXAMPLE__ (<anonymous>:1:55) | ||
// at <anonymous>:1:13 | ||
// ``` | ||
// | ||
const STACK_ENTRY_REGEX = /__stack_guard__([a-zA-Z0-9_-]+)__/; | ||
let STACK_GUARD_CHECKED = false; | ||
let STACK_GUARD_CHECK_FN; // eslint-disable-line prefer-const | ||
let STACK_GUARDS_SUPPORTED = false; | ||
/** | ||
* Checks if the current caller of the function is in a {@link | ||
* #stackGuard} of the provided `name`. Works by looking through | ||
* the stack trace of an `Error` object for a special function | ||
* name (generated by {@link #stackGuard}). | ||
* | ||
* @param name The name of the stack guard to check for. Must be `[a-zA-Z0-9_-]` only. | ||
*/ | ||
function isInStackGuard(name) { | ||
var _a, _b; | ||
STACK_GUARD_CHECK_FN(); | ||
let error; | ||
try { | ||
throw new Error(); | ||
} | ||
catch (e) { | ||
error = e; | ||
} | ||
const stack = (_b = (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n')) !== null && _b !== void 0 ? _b : []; | ||
for (let i = 0; i < stack.length; i += 1) { | ||
const entry = stack[i]; | ||
const match = entry.match(STACK_ENTRY_REGEX); | ||
if (match && match[1] === name) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
exports.isInStackGuard = isInStackGuard; | ||
/** | ||
* Creates a minification resistant stack guard, i.e. if you | ||
* call {@link #isInStackGuard} from within the `fn` parameter | ||
* function, you will always get `true` otherwise it will be | ||
* `false`. | ||
* | ||
* Works by dynamically defining a function name before calling | ||
* into `fn`, which is then parsed from the stack trace on an | ||
* `Error` object within {@link #isInStackGuard}. | ||
* | ||
* @param name The name of the stack guard. Must be `[a-zA-Z0-9_-]` only. | ||
* @param fn The async/await function to be run within the stack guard. | ||
*/ | ||
async function stackGuard(name, fn) { | ||
await STACK_GUARD_CHECK_FN(); | ||
const guardName = `${STACK_GUARD_PREFIX}${name}${STACK_GUARD_SUFFIX}`; | ||
const guardFunc = { | ||
// per ECMAScript rules, this defines a new function with the dynamic name | ||
// contained in the `guardName` variable | ||
// this function name shows up in stack traces and is resistant to mangling | ||
// from minification processes as it is determined at runtime | ||
[guardName]: async () => await fn(), | ||
}; | ||
// Safari does not log the name of a dynamically named function unless you | ||
// explicitly set the displayName | ||
Object.assign(guardFunc[guardName], { displayName: guardName }); | ||
return await guardFunc[guardName](); | ||
} | ||
exports.stackGuard = stackGuard; | ||
/** | ||
* Returns if the JavaScript engine supports stack guards. If it doesn't | ||
* certain features that depend on detecting recursive calls should be disabled | ||
* to prevent deadlocks. | ||
*/ | ||
async function stackGuardsSupported() { | ||
if (STACK_GUARD_CHECKED) { | ||
return STACK_GUARDS_SUPPORTED; | ||
} | ||
await STACK_GUARD_CHECK_FN(); | ||
return STACK_GUARDS_SUPPORTED; | ||
} | ||
exports.stackGuardsSupported = stackGuardsSupported; | ||
let STACK_GUARD_WARNING_LOGGED = false; | ||
// In certain cases, if this file is transpiled using an ES2015 target, or is | ||
// running in a JS engine that does not support async/await stack traces, this | ||
// function will log a single warning message. | ||
STACK_GUARD_CHECK_FN = async () => { | ||
if (!STACK_GUARD_CHECKED) { | ||
STACK_GUARD_CHECKED = true; | ||
await stackGuard('ENV_CHECK', async () => { | ||
// sleeping for the next tick as Safari loses track of the async/await | ||
// trace beyond this point | ||
await sleep(0); | ||
const result = isInStackGuard('ENV_CHECK'); | ||
STACK_GUARDS_SUPPORTED = result; | ||
if (!result && !STACK_GUARD_WARNING_LOGGED) { | ||
STACK_GUARD_WARNING_LOGGED = true; | ||
console.warn('@supabase/gotrue-js: Stack guards not supported in this environment. Generally not an issue but may point to a very conservative transpilation environment (use ES2017 or above) that implements async/await with generators, or this is a JavaScript engine that does not support async/await stack traces. Safari is known to not support stack guards.'); | ||
} | ||
return result; | ||
}); | ||
} | ||
}; | ||
//# sourceMappingURL=helpers.js.map |
@@ -55,64 +55,30 @@ "use strict"; | ||
} | ||
let beginOperation = null; | ||
let rejectOperation = null; | ||
const beginOperationPromise = new Promise((accept, reject) => { | ||
beginOperation = accept; | ||
rejectOperation = reject; | ||
}); | ||
// this lets us preserve stack traces over the operation, which the | ||
// navigator.locks.request function does not preserve well still | ||
const result = (async () => { | ||
await beginOperationPromise; | ||
if (exports.internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock: operation start'); | ||
} | ||
try { | ||
return await fn(); | ||
} | ||
finally { | ||
if (exports.internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock: operation end'); | ||
} | ||
} | ||
})(); | ||
const abortController = new globalThis.AbortController(); | ||
if (acquireTimeout > 0) { | ||
setTimeout(() => { | ||
beginOperation = null; | ||
abortController.abort(); | ||
if (rejectOperation) { | ||
if (exports.internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name); | ||
} | ||
if (rejectOperation) { | ||
rejectOperation(new NavigatorLockAcquireTimeoutError(`Acquiring an exclusive Navigator LockManager lock "${name}" timed out after ${acquireTimeout}ms`)); | ||
} | ||
beginOperation = null; | ||
rejectOperation = null; | ||
if (exports.internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name); | ||
} | ||
}, acquireTimeout); | ||
} | ||
await globalThis.navigator.locks.request(name, { | ||
mode: 'exclusive', | ||
ifAvailable: acquireTimeout === 0, | ||
signal: abortController.signal, | ||
}, async (lock) => { | ||
return await globalThis.navigator.locks.request(name, acquireTimeout === 0 | ||
? { | ||
mode: 'exclusive', | ||
ifAvailable: true, | ||
} | ||
: { | ||
mode: 'exclusive', | ||
signal: abortController.signal, | ||
}, async (lock) => { | ||
if (lock) { | ||
if (exports.internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock acquired', name); | ||
console.log('@supabase/gotrue-js: navigatorLock: acquired', name); | ||
} | ||
try { | ||
if (beginOperation) { | ||
beginOperation(); | ||
beginOperation = null; | ||
rejectOperation = null; | ||
await result; | ||
} | ||
return await fn(); | ||
} | ||
catch (e) { | ||
// not important to handle the error here | ||
} | ||
finally { | ||
if (exports.internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock released', name); | ||
console.log('@supabase/gotrue-js: navigatorLock: released', name); | ||
} | ||
@@ -123,17 +89,9 @@ } | ||
if (exports.internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock not immediately available', name); | ||
console.log('@supabase/gotrue-js: navigatorLock: not immediately available', name); | ||
} | ||
// no lock was available because acquireTimeout === 0 | ||
const timeout = new Error(`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`); | ||
timeout.isAcquireTimeout = true; | ||
if (rejectOperation) { | ||
rejectOperation(new NavigatorLockAcquireTimeoutError(`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`)); | ||
} | ||
beginOperation = null; | ||
rejectOperation = null; | ||
throw new NavigatorLockAcquireTimeoutError(`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`); | ||
} | ||
}); | ||
return await result; | ||
} | ||
exports.navigatorLock = navigatorLock; | ||
//# sourceMappingURL=locks.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.46.2"; | ||
export declare const version = "2.47.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// Generated by genversion. | ||
exports.version = '2.46.2'; | ||
exports.version = '2.47.0'; | ||
//# sourceMappingURL=version.js.map |
@@ -49,2 +49,4 @@ import GoTrueAdminApi from './GoTrueAdminApi'; | ||
protected lock: LockFunc; | ||
protected lockAcquired: boolean; | ||
protected pendingInLock: Promise<any>[]; | ||
/** | ||
@@ -102,2 +104,3 @@ * Used to broadcast state change events to other tabs listening. | ||
exchangeCodeForSession(authCode: string): Promise<AuthTokenResponse>; | ||
private _exchangeCodeForSession; | ||
/** | ||
@@ -150,2 +153,3 @@ * Allows signing in with an OIDC ID token. The authentication provider used | ||
reauthenticate(): Promise<AuthResponse>; | ||
private _reauthenticate; | ||
/** | ||
@@ -197,2 +201,3 @@ * Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP. | ||
getUser(jwt?: string): Promise<UserResponse>; | ||
private _getUser; | ||
/** | ||
@@ -204,2 +209,5 @@ * Updates user data for a logged in user. | ||
}): Promise<UserResponse>; | ||
protected _updateUser(attributes: UserAttributes, options?: { | ||
emailRedirectTo?: string | undefined; | ||
}): Promise<UserResponse>; | ||
/** | ||
@@ -218,2 +226,6 @@ * Decodes a JWT (without performing any validation). | ||
}): Promise<AuthResponse>; | ||
protected _setSession(currentSession: { | ||
access_token: string; | ||
refresh_token: string; | ||
}): Promise<AuthResponse>; | ||
/** | ||
@@ -228,2 +240,5 @@ * Returns a new session, regardless of expiry status. | ||
}): Promise<AuthResponse>; | ||
protected _refreshSession(currentSession?: { | ||
refresh_token: string; | ||
}): Promise<AuthResponse>; | ||
/** | ||
@@ -250,5 +265,8 @@ * Gets the session data from a URL string | ||
*/ | ||
signOut({ scope }?: SignOut): Promise<{ | ||
signOut(options?: SignOut): Promise<{ | ||
error: AuthError | null; | ||
}>; | ||
protected _signOut({ scope }?: SignOut): Promise<{ | ||
error: AuthError | null; | ||
}>; | ||
/** | ||
@@ -255,0 +273,0 @@ * Receive a notification every time an auth event happens. |
@@ -47,32 +47,3 @@ import { SupportedStorage } from './types'; | ||
export declare function generatePKCEChallenge(verifier: string): Promise<string>; | ||
/** | ||
* Checks if the current caller of the function is in a {@link | ||
* #stackGuard} of the provided `name`. Works by looking through | ||
* the stack trace of an `Error` object for a special function | ||
* name (generated by {@link #stackGuard}). | ||
* | ||
* @param name The name of the stack guard to check for. Must be `[a-zA-Z0-9_-]` only. | ||
*/ | ||
export declare function isInStackGuard(name: string): boolean; | ||
/** | ||
* Creates a minification resistant stack guard, i.e. if you | ||
* call {@link #isInStackGuard} from within the `fn` parameter | ||
* function, you will always get `true` otherwise it will be | ||
* `false`. | ||
* | ||
* Works by dynamically defining a function name before calling | ||
* into `fn`, which is then parsed from the stack trace on an | ||
* `Error` object within {@link #isInStackGuard}. | ||
* | ||
* @param name The name of the stack guard. Must be `[a-zA-Z0-9_-]` only. | ||
* @param fn The async/await function to be run within the stack guard. | ||
*/ | ||
export declare function stackGuard<R>(name: string, fn: () => Promise<R>): Promise<R>; | ||
/** | ||
* Returns if the JavaScript engine supports stack guards. If it doesn't | ||
* certain features that depend on detecting recursive calls should be disabled | ||
* to prevent deadlocks. | ||
*/ | ||
export declare function stackGuardsSupported(): Promise<boolean>; | ||
export {}; | ||
//# sourceMappingURL=helpers.d.ts.map |
@@ -246,115 +246,2 @@ export function expiresAt(expiresIn) { | ||
} | ||
const STACK_GUARD_PREFIX = `__stack_guard__`; | ||
const STACK_GUARD_SUFFIX = `__`; | ||
// Firefox and WebKit based browsers encode the stack entry differently, but | ||
// they all include the function name. So instead of trying to parse the entry, | ||
// we're only looking for the special string `__stack_guard__${guardName}__`. | ||
// Guard names can only be letters with dashes or underscores. | ||
// | ||
// Example Firefox stack trace: | ||
// ``` | ||
// __stack_guard__EXAMPLE__@debugger eval code:1:55 | ||
// @debugger eval code:1:3 | ||
// ``` | ||
// | ||
// Example WebKit/Chrome stack trace: | ||
// ``` | ||
// Error | ||
// at Object.__stack_guard__EXAMPLE__ (<anonymous>:1:55) | ||
// at <anonymous>:1:13 | ||
// ``` | ||
// | ||
const STACK_ENTRY_REGEX = /__stack_guard__([a-zA-Z0-9_-]+)__/; | ||
let STACK_GUARD_CHECKED = false; | ||
let STACK_GUARD_CHECK_FN; // eslint-disable-line prefer-const | ||
let STACK_GUARDS_SUPPORTED = false; | ||
/** | ||
* Checks if the current caller of the function is in a {@link | ||
* #stackGuard} of the provided `name`. Works by looking through | ||
* the stack trace of an `Error` object for a special function | ||
* name (generated by {@link #stackGuard}). | ||
* | ||
* @param name The name of the stack guard to check for. Must be `[a-zA-Z0-9_-]` only. | ||
*/ | ||
export function isInStackGuard(name) { | ||
var _a, _b; | ||
STACK_GUARD_CHECK_FN(); | ||
let error; | ||
try { | ||
throw new Error(); | ||
} | ||
catch (e) { | ||
error = e; | ||
} | ||
const stack = (_b = (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n')) !== null && _b !== void 0 ? _b : []; | ||
for (let i = 0; i < stack.length; i += 1) { | ||
const entry = stack[i]; | ||
const match = entry.match(STACK_ENTRY_REGEX); | ||
if (match && match[1] === name) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* Creates a minification resistant stack guard, i.e. if you | ||
* call {@link #isInStackGuard} from within the `fn` parameter | ||
* function, you will always get `true` otherwise it will be | ||
* `false`. | ||
* | ||
* Works by dynamically defining a function name before calling | ||
* into `fn`, which is then parsed from the stack trace on an | ||
* `Error` object within {@link #isInStackGuard}. | ||
* | ||
* @param name The name of the stack guard. Must be `[a-zA-Z0-9_-]` only. | ||
* @param fn The async/await function to be run within the stack guard. | ||
*/ | ||
export async function stackGuard(name, fn) { | ||
await STACK_GUARD_CHECK_FN(); | ||
const guardName = `${STACK_GUARD_PREFIX}${name}${STACK_GUARD_SUFFIX}`; | ||
const guardFunc = { | ||
// per ECMAScript rules, this defines a new function with the dynamic name | ||
// contained in the `guardName` variable | ||
// this function name shows up in stack traces and is resistant to mangling | ||
// from minification processes as it is determined at runtime | ||
[guardName]: async () => await fn(), | ||
}; | ||
// Safari does not log the name of a dynamically named function unless you | ||
// explicitly set the displayName | ||
Object.assign(guardFunc[guardName], { displayName: guardName }); | ||
return await guardFunc[guardName](); | ||
} | ||
/** | ||
* Returns if the JavaScript engine supports stack guards. If it doesn't | ||
* certain features that depend on detecting recursive calls should be disabled | ||
* to prevent deadlocks. | ||
*/ | ||
export async function stackGuardsSupported() { | ||
if (STACK_GUARD_CHECKED) { | ||
return STACK_GUARDS_SUPPORTED; | ||
} | ||
await STACK_GUARD_CHECK_FN(); | ||
return STACK_GUARDS_SUPPORTED; | ||
} | ||
let STACK_GUARD_WARNING_LOGGED = false; | ||
// In certain cases, if this file is transpiled using an ES2015 target, or is | ||
// running in a JS engine that does not support async/await stack traces, this | ||
// function will log a single warning message. | ||
STACK_GUARD_CHECK_FN = async () => { | ||
if (!STACK_GUARD_CHECKED) { | ||
STACK_GUARD_CHECKED = true; | ||
await stackGuard('ENV_CHECK', async () => { | ||
// sleeping for the next tick as Safari loses track of the async/await | ||
// trace beyond this point | ||
await sleep(0); | ||
const result = isInStackGuard('ENV_CHECK'); | ||
STACK_GUARDS_SUPPORTED = result; | ||
if (!result && !STACK_GUARD_WARNING_LOGGED) { | ||
STACK_GUARD_WARNING_LOGGED = true; | ||
console.warn('@supabase/gotrue-js: Stack guards not supported in this environment. Generally not an issue but may point to a very conservative transpilation environment (use ES2017 or above) that implements async/await with generators, or this is a JavaScript engine that does not support async/await stack traces. Safari is known to not support stack guards.'); | ||
} | ||
return result; | ||
}); | ||
} | ||
}; | ||
//# sourceMappingURL=helpers.js.map |
@@ -51,64 +51,30 @@ import { supportsLocalStorage } from './helpers'; | ||
} | ||
let beginOperation = null; | ||
let rejectOperation = null; | ||
const beginOperationPromise = new Promise((accept, reject) => { | ||
beginOperation = accept; | ||
rejectOperation = reject; | ||
}); | ||
// this lets us preserve stack traces over the operation, which the | ||
// navigator.locks.request function does not preserve well still | ||
const result = (async () => { | ||
await beginOperationPromise; | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock: operation start'); | ||
} | ||
try { | ||
return await fn(); | ||
} | ||
finally { | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock: operation end'); | ||
} | ||
} | ||
})(); | ||
const abortController = new globalThis.AbortController(); | ||
if (acquireTimeout > 0) { | ||
setTimeout(() => { | ||
beginOperation = null; | ||
abortController.abort(); | ||
if (rejectOperation) { | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name); | ||
} | ||
if (rejectOperation) { | ||
rejectOperation(new NavigatorLockAcquireTimeoutError(`Acquiring an exclusive Navigator LockManager lock "${name}" timed out after ${acquireTimeout}ms`)); | ||
} | ||
beginOperation = null; | ||
rejectOperation = null; | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name); | ||
} | ||
}, acquireTimeout); | ||
} | ||
await globalThis.navigator.locks.request(name, { | ||
mode: 'exclusive', | ||
ifAvailable: acquireTimeout === 0, | ||
signal: abortController.signal, | ||
}, async (lock) => { | ||
return await globalThis.navigator.locks.request(name, acquireTimeout === 0 | ||
? { | ||
mode: 'exclusive', | ||
ifAvailable: true, | ||
} | ||
: { | ||
mode: 'exclusive', | ||
signal: abortController.signal, | ||
}, async (lock) => { | ||
if (lock) { | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock acquired', name); | ||
console.log('@supabase/gotrue-js: navigatorLock: acquired', name); | ||
} | ||
try { | ||
if (beginOperation) { | ||
beginOperation(); | ||
beginOperation = null; | ||
rejectOperation = null; | ||
await result; | ||
} | ||
return await fn(); | ||
} | ||
catch (e) { | ||
// not important to handle the error here | ||
} | ||
finally { | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock released', name); | ||
console.log('@supabase/gotrue-js: navigatorLock: released', name); | ||
} | ||
@@ -119,16 +85,8 @@ } | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock not immediately available', name); | ||
console.log('@supabase/gotrue-js: navigatorLock: not immediately available', name); | ||
} | ||
// no lock was available because acquireTimeout === 0 | ||
const timeout = new Error(`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`); | ||
timeout.isAcquireTimeout = true; | ||
if (rejectOperation) { | ||
rejectOperation(new NavigatorLockAcquireTimeoutError(`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`)); | ||
} | ||
beginOperation = null; | ||
rejectOperation = null; | ||
throw new NavigatorLockAcquireTimeoutError(`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`); | ||
} | ||
}); | ||
return await result; | ||
} | ||
//# sourceMappingURL=locks.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.46.2"; | ||
export declare const version = "2.47.0"; | ||
//# sourceMappingURL=version.d.ts.map |
// Generated by genversion. | ||
export const version = '2.46.2'; | ||
export const version = '2.47.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@supabase/gotrue-js", | ||
"version": "2.46.2", | ||
"version": "2.47.0", | ||
"description": "Isomorphic GoTrue client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -301,141 +301,1 @@ import { SupportedStorage } from './types' | ||
} | ||
const STACK_GUARD_PREFIX = `__stack_guard__` | ||
const STACK_GUARD_SUFFIX = `__` | ||
// Firefox and WebKit based browsers encode the stack entry differently, but | ||
// they all include the function name. So instead of trying to parse the entry, | ||
// we're only looking for the special string `__stack_guard__${guardName}__`. | ||
// Guard names can only be letters with dashes or underscores. | ||
// | ||
// Example Firefox stack trace: | ||
// ``` | ||
// __stack_guard__EXAMPLE__@debugger eval code:1:55 | ||
// @debugger eval code:1:3 | ||
// ``` | ||
// | ||
// Example WebKit/Chrome stack trace: | ||
// ``` | ||
// Error | ||
// at Object.__stack_guard__EXAMPLE__ (<anonymous>:1:55) | ||
// at <anonymous>:1:13 | ||
// ``` | ||
// | ||
const STACK_ENTRY_REGEX = /__stack_guard__([a-zA-Z0-9_-]+)__/ | ||
let STACK_GUARD_CHECKED = false | ||
let STACK_GUARD_CHECK_FN: () => Promise<void> // eslint-disable-line prefer-const | ||
let STACK_GUARDS_SUPPORTED = false | ||
/** | ||
* Checks if the current caller of the function is in a {@link | ||
* #stackGuard} of the provided `name`. Works by looking through | ||
* the stack trace of an `Error` object for a special function | ||
* name (generated by {@link #stackGuard}). | ||
* | ||
* @param name The name of the stack guard to check for. Must be `[a-zA-Z0-9_-]` only. | ||
*/ | ||
export function isInStackGuard(name: string): boolean { | ||
STACK_GUARD_CHECK_FN() | ||
let error: Error | ||
try { | ||
throw new Error() | ||
} catch (e: any) { | ||
error = e | ||
} | ||
const stack = error.stack?.split('\n') ?? [] | ||
for (let i = 0; i < stack.length; i += 1) { | ||
const entry = stack[i] | ||
const match = entry.match(STACK_ENTRY_REGEX) | ||
if (match && match[1] === name) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
/** | ||
* Creates a minification resistant stack guard, i.e. if you | ||
* call {@link #isInStackGuard} from within the `fn` parameter | ||
* function, you will always get `true` otherwise it will be | ||
* `false`. | ||
* | ||
* Works by dynamically defining a function name before calling | ||
* into `fn`, which is then parsed from the stack trace on an | ||
* `Error` object within {@link #isInStackGuard}. | ||
* | ||
* @param name The name of the stack guard. Must be `[a-zA-Z0-9_-]` only. | ||
* @param fn The async/await function to be run within the stack guard. | ||
*/ | ||
export async function stackGuard<R>(name: string, fn: () => Promise<R>): Promise<R> { | ||
await STACK_GUARD_CHECK_FN() | ||
const guardName = `${STACK_GUARD_PREFIX}${name}${STACK_GUARD_SUFFIX}` | ||
const guardFunc: { | ||
[funcName: string]: () => Promise<R> | ||
} = { | ||
// per ECMAScript rules, this defines a new function with the dynamic name | ||
// contained in the `guardName` variable | ||
// this function name shows up in stack traces and is resistant to mangling | ||
// from minification processes as it is determined at runtime | ||
[guardName]: async () => await fn(), | ||
} | ||
// Safari does not log the name of a dynamically named function unless you | ||
// explicitly set the displayName | ||
Object.assign(guardFunc[guardName], { displayName: guardName }) | ||
return await guardFunc[guardName]() | ||
} | ||
/** | ||
* Returns if the JavaScript engine supports stack guards. If it doesn't | ||
* certain features that depend on detecting recursive calls should be disabled | ||
* to prevent deadlocks. | ||
*/ | ||
export async function stackGuardsSupported(): Promise<boolean> { | ||
if (STACK_GUARD_CHECKED) { | ||
return STACK_GUARDS_SUPPORTED | ||
} | ||
await STACK_GUARD_CHECK_FN() | ||
return STACK_GUARDS_SUPPORTED | ||
} | ||
let STACK_GUARD_WARNING_LOGGED = false | ||
// In certain cases, if this file is transpiled using an ES2015 target, or is | ||
// running in a JS engine that does not support async/await stack traces, this | ||
// function will log a single warning message. | ||
STACK_GUARD_CHECK_FN = async () => { | ||
if (!STACK_GUARD_CHECKED) { | ||
STACK_GUARD_CHECKED = true | ||
await stackGuard('ENV_CHECK', async () => { | ||
// sleeping for the next tick as Safari loses track of the async/await | ||
// trace beyond this point | ||
await sleep(0) | ||
const result = isInStackGuard('ENV_CHECK') | ||
STACK_GUARDS_SUPPORTED = result | ||
if (!result && !STACK_GUARD_WARNING_LOGGED) { | ||
STACK_GUARD_WARNING_LOGGED = true | ||
console.warn( | ||
'@supabase/gotrue-js: Stack guards not supported in this environment. Generally not an issue but may point to a very conservative transpilation environment (use ES2017 or above) that implements async/await with generators, or this is a JavaScript engine that does not support async/await stack traces. Safari is known to not support stack guards.' | ||
) | ||
} | ||
return result | ||
}) | ||
} | ||
} |
@@ -62,27 +62,2 @@ import { supportsLocalStorage } from './helpers' | ||
let beginOperation: (() => void) | null = null | ||
let rejectOperation: ((error: any) => void) | null = null | ||
const beginOperationPromise = new Promise<void>((accept, reject) => { | ||
beginOperation = accept | ||
rejectOperation = reject | ||
}) | ||
// this lets us preserve stack traces over the operation, which the | ||
// navigator.locks.request function does not preserve well still | ||
const result = (async () => { | ||
await beginOperationPromise | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock: operation start') | ||
} | ||
try { | ||
return await fn() | ||
} finally { | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock: operation end') | ||
} | ||
} | ||
})() | ||
const abortController = new globalThis.AbortController() | ||
@@ -92,19 +67,5 @@ | ||
setTimeout(() => { | ||
beginOperation = null | ||
abortController.abort() | ||
if (rejectOperation) { | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name) | ||
} | ||
if (rejectOperation) { | ||
rejectOperation( | ||
new NavigatorLockAcquireTimeoutError( | ||
`Acquiring an exclusive Navigator LockManager lock "${name}" timed out after ${acquireTimeout}ms` | ||
) | ||
) | ||
} | ||
beginOperation = null | ||
rejectOperation = null | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name) | ||
} | ||
@@ -114,27 +75,24 @@ }, acquireTimeout) | ||
await globalThis.navigator.locks.request( | ||
return await globalThis.navigator.locks.request( | ||
name, | ||
{ | ||
mode: 'exclusive', | ||
ifAvailable: acquireTimeout === 0, | ||
signal: abortController.signal, | ||
}, | ||
acquireTimeout === 0 | ||
? { | ||
mode: 'exclusive', | ||
ifAvailable: true, | ||
} | ||
: { | ||
mode: 'exclusive', | ||
signal: abortController.signal, | ||
}, | ||
async (lock) => { | ||
if (lock) { | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock acquired', name) | ||
console.log('@supabase/gotrue-js: navigatorLock: acquired', name) | ||
} | ||
try { | ||
if (beginOperation) { | ||
beginOperation() | ||
beginOperation = null | ||
rejectOperation = null | ||
await result | ||
} | ||
} catch (e: any) { | ||
// not important to handle the error here | ||
return await fn() | ||
} finally { | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock released', name) | ||
console.log('@supabase/gotrue-js: navigatorLock: released', name) | ||
} | ||
@@ -144,25 +102,11 @@ } | ||
if (internals.debug) { | ||
console.log('@supabase/gotrue-js: navigatorLock not immediately available', name) | ||
console.log('@supabase/gotrue-js: navigatorLock: not immediately available', name) | ||
} | ||
// no lock was available because acquireTimeout === 0 | ||
const timeout: any = new Error( | ||
throw new NavigatorLockAcquireTimeoutError( | ||
`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed` | ||
) | ||
timeout.isAcquireTimeout = true | ||
if (rejectOperation) { | ||
rejectOperation( | ||
new NavigatorLockAcquireTimeoutError( | ||
`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed` | ||
) | ||
) | ||
} | ||
beginOperation = null | ||
rejectOperation = null | ||
} | ||
} | ||
) | ||
return await result | ||
} |
// Generated by genversion. | ||
export const version = '2.46.2' | ||
export const version = '2.47.0' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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 too big to display
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 too big to display
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
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
693297
12603