first build
This commit is contained in:
-9
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const GoTrueAdminApi_1 = __importDefault(require("./GoTrueAdminApi"));
|
||||
const AuthAdminApi = GoTrueAdminApi_1.default;
|
||||
exports.default = AuthAdminApi;
|
||||
//# sourceMappingURL=AuthAdminApi.js.map
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const GoTrueClient_1 = __importDefault(require("./GoTrueClient"));
|
||||
const AuthClient = GoTrueClient_1.default;
|
||||
exports.default = AuthClient;
|
||||
//# sourceMappingURL=AuthClient.js.map
|
||||
-278
@@ -1,278 +0,0 @@
|
||||
"use strict";
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fetch_1 = require("./lib/fetch");
|
||||
const helpers_1 = require("./lib/helpers");
|
||||
const types_1 = require("./lib/types");
|
||||
const errors_1 = require("./lib/errors");
|
||||
class GoTrueAdminApi {
|
||||
constructor({ url = '', headers = {}, fetch, }) {
|
||||
this.url = url;
|
||||
this.headers = headers;
|
||||
this.fetch = (0, helpers_1.resolveFetch)(fetch);
|
||||
this.mfa = {
|
||||
listFactors: this._listFactors.bind(this),
|
||||
deleteFactor: this._deleteFactor.bind(this),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Removes a logged-in session.
|
||||
* @param jwt A valid, logged-in JWT.
|
||||
* @param scope The logout sope.
|
||||
*/
|
||||
async signOut(jwt, scope = types_1.SIGN_OUT_SCOPES[0]) {
|
||||
if (types_1.SIGN_OUT_SCOPES.indexOf(scope) < 0) {
|
||||
throw new Error(`@supabase/auth-js: Parameter scope must be one of ${types_1.SIGN_OUT_SCOPES.join(', ')}`);
|
||||
}
|
||||
try {
|
||||
await (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/logout?scope=${scope}`, {
|
||||
headers: this.headers,
|
||||
jwt,
|
||||
noResolveJson: true,
|
||||
});
|
||||
return { data: null, error: null };
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return { data: null, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sends an invite link to an email address.
|
||||
* @param email The email address of the user.
|
||||
* @param options Additional options to be included when inviting.
|
||||
*/
|
||||
async inviteUserByEmail(email, options = {}) {
|
||||
try {
|
||||
return await (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/invite`, {
|
||||
body: { email, data: options.data },
|
||||
headers: this.headers,
|
||||
redirectTo: options.redirectTo,
|
||||
xform: fetch_1._userResponse,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return { data: { user: null }, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Generates email links and OTPs to be sent via a custom email provider.
|
||||
* @param email The user's email.
|
||||
* @param options.password User password. For signup only.
|
||||
* @param options.data Optional user metadata. For signup only.
|
||||
* @param options.redirectTo The redirect url which should be appended to the generated link
|
||||
*/
|
||||
async generateLink(params) {
|
||||
try {
|
||||
const { options } = params, rest = __rest(params, ["options"]);
|
||||
const body = Object.assign(Object.assign({}, rest), options);
|
||||
if ('newEmail' in rest) {
|
||||
// replace newEmail with new_email in request body
|
||||
body.new_email = rest === null || rest === void 0 ? void 0 : rest.newEmail;
|
||||
delete body['newEmail'];
|
||||
}
|
||||
return await (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/generate_link`, {
|
||||
body: body,
|
||||
headers: this.headers,
|
||||
xform: fetch_1._generateLinkResponse,
|
||||
redirectTo: options === null || options === void 0 ? void 0 : options.redirectTo,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return {
|
||||
data: {
|
||||
properties: null,
|
||||
user: null,
|
||||
},
|
||||
error,
|
||||
};
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
// User Admin API
|
||||
/**
|
||||
* Creates a new user.
|
||||
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
||||
*/
|
||||
async createUser(attributes) {
|
||||
try {
|
||||
return await (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/users`, {
|
||||
body: attributes,
|
||||
headers: this.headers,
|
||||
xform: fetch_1._userResponse,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return { data: { user: null }, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get a list of users.
|
||||
*
|
||||
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
||||
* @param params An object which supports `page` and `perPage` as numbers, to alter the paginated results.
|
||||
*/
|
||||
async listUsers(params) {
|
||||
var _a, _b, _c, _d, _e, _f, _g;
|
||||
try {
|
||||
const pagination = { nextPage: null, lastPage: 0, total: 0 };
|
||||
const response = await (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users`, {
|
||||
headers: this.headers,
|
||||
noResolveJson: true,
|
||||
query: {
|
||||
page: (_b = (_a = params === null || params === void 0 ? void 0 : params.page) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '',
|
||||
per_page: (_d = (_c = params === null || params === void 0 ? void 0 : params.perPage) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : '',
|
||||
},
|
||||
xform: fetch_1._noResolveJsonResponse,
|
||||
});
|
||||
if (response.error)
|
||||
throw response.error;
|
||||
const users = await response.json();
|
||||
const total = (_e = response.headers.get('x-total-count')) !== null && _e !== void 0 ? _e : 0;
|
||||
const links = (_g = (_f = response.headers.get('link')) === null || _f === void 0 ? void 0 : _f.split(',')) !== null && _g !== void 0 ? _g : [];
|
||||
if (links.length > 0) {
|
||||
links.forEach((link) => {
|
||||
const page = parseInt(link.split(';')[0].split('=')[1].substring(0, 1));
|
||||
const rel = JSON.parse(link.split(';')[1].split('=')[1]);
|
||||
pagination[`${rel}Page`] = page;
|
||||
});
|
||||
pagination.total = parseInt(total);
|
||||
}
|
||||
return { data: Object.assign(Object.assign({}, users), pagination), error: null };
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return { data: { users: [] }, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get user by id.
|
||||
*
|
||||
* @param uid The user's unique identifier
|
||||
*
|
||||
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
||||
*/
|
||||
async getUserById(uid) {
|
||||
(0, helpers_1.validateUUID)(uid);
|
||||
try {
|
||||
return await (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users/${uid}`, {
|
||||
headers: this.headers,
|
||||
xform: fetch_1._userResponse,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return { data: { user: null }, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Updates the user data.
|
||||
*
|
||||
* @param attributes The data you want to update.
|
||||
*
|
||||
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
||||
*/
|
||||
async updateUserById(uid, attributes) {
|
||||
(0, helpers_1.validateUUID)(uid);
|
||||
try {
|
||||
return await (0, fetch_1._request)(this.fetch, 'PUT', `${this.url}/admin/users/${uid}`, {
|
||||
body: attributes,
|
||||
headers: this.headers,
|
||||
xform: fetch_1._userResponse,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return { data: { user: null }, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Delete a user. Requires a `service_role` key.
|
||||
*
|
||||
* @param id The user id you want to remove.
|
||||
* @param shouldSoftDelete If true, then the user will be soft-deleted from the auth schema. Soft deletion allows user identification from the hashed user ID but is not reversible.
|
||||
* Defaults to false for backward compatibility.
|
||||
*
|
||||
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
||||
*/
|
||||
async deleteUser(id, shouldSoftDelete = false) {
|
||||
(0, helpers_1.validateUUID)(id);
|
||||
try {
|
||||
return await (0, fetch_1._request)(this.fetch, 'DELETE', `${this.url}/admin/users/${id}`, {
|
||||
headers: this.headers,
|
||||
body: {
|
||||
should_soft_delete: shouldSoftDelete,
|
||||
},
|
||||
xform: fetch_1._userResponse,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return { data: { user: null }, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async _listFactors(params) {
|
||||
(0, helpers_1.validateUUID)(params.userId);
|
||||
try {
|
||||
const { data, error } = await (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users/${params.userId}/factors`, {
|
||||
headers: this.headers,
|
||||
xform: (factors) => {
|
||||
return { data: { factors }, error: null };
|
||||
},
|
||||
});
|
||||
return { data, error };
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return { data: null, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async _deleteFactor(params) {
|
||||
(0, helpers_1.validateUUID)(params.userId);
|
||||
(0, helpers_1.validateUUID)(params.id);
|
||||
try {
|
||||
const data = await (0, fetch_1._request)(this.fetch, 'DELETE', `${this.url}/admin/users/${params.userId}/factors/${params.id}`, {
|
||||
headers: this.headers,
|
||||
});
|
||||
return { data, error: null };
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, errors_1.isAuthError)(error)) {
|
||||
return { data: null, error };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.default = GoTrueAdminApi;
|
||||
//# sourceMappingURL=GoTrueAdminApi.js.map
|
||||
-2371
File diff suppressed because it is too large
Load Diff
-36
@@ -1,36 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.processLock = exports.lockInternals = exports.NavigatorLockAcquireTimeoutError = exports.navigatorLock = exports.AuthClient = exports.AuthAdminApi = exports.GoTrueClient = exports.GoTrueAdminApi = void 0;
|
||||
const GoTrueAdminApi_1 = __importDefault(require("./GoTrueAdminApi"));
|
||||
exports.GoTrueAdminApi = GoTrueAdminApi_1.default;
|
||||
const GoTrueClient_1 = __importDefault(require("./GoTrueClient"));
|
||||
exports.GoTrueClient = GoTrueClient_1.default;
|
||||
const AuthAdminApi_1 = __importDefault(require("./AuthAdminApi"));
|
||||
exports.AuthAdminApi = AuthAdminApi_1.default;
|
||||
const AuthClient_1 = __importDefault(require("./AuthClient"));
|
||||
exports.AuthClient = AuthClient_1.default;
|
||||
__exportStar(require("./lib/types"), exports);
|
||||
__exportStar(require("./lib/errors"), exports);
|
||||
var locks_1 = require("./lib/locks");
|
||||
Object.defineProperty(exports, "navigatorLock", { enumerable: true, get: function () { return locks_1.navigatorLock; } });
|
||||
Object.defineProperty(exports, "NavigatorLockAcquireTimeoutError", { enumerable: true, get: function () { return locks_1.NavigatorLockAcquireTimeoutError; } });
|
||||
Object.defineProperty(exports, "lockInternals", { enumerable: true, get: function () { return locks_1.internals; } });
|
||||
Object.defineProperty(exports, "processLock", { enumerable: true, get: function () { return locks_1.processLock; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
-270
@@ -1,270 +0,0 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Avoid modifying this file. It's part of
|
||||
* https://github.com/supabase-community/base64url-js. Submit all fixes on
|
||||
* that repo!
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.bytesToBase64URL = exports.stringToUint8Array = exports.base64UrlToUint8Array = exports.stringFromUTF8 = exports.stringToUTF8 = exports.codepointToUTF8 = exports.stringFromBase64URL = exports.stringToBase64URL = exports.byteFromBase64URL = exports.byteToBase64URL = void 0;
|
||||
/**
|
||||
* An array of characters that encode 6 bits into a Base64-URL alphabet
|
||||
* character.
|
||||
*/
|
||||
const TO_BASE64URL = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'.split('');
|
||||
/**
|
||||
* An array of characters that can appear in a Base64-URL encoded string but
|
||||
* should be ignored.
|
||||
*/
|
||||
const IGNORE_BASE64URL = ' \t\n\r='.split('');
|
||||
/**
|
||||
* An array of 128 numbers that map a Base64-URL character to 6 bits, or if -2
|
||||
* used to skip the character, or if -1 used to error out.
|
||||
*/
|
||||
const FROM_BASE64URL = (() => {
|
||||
const charMap = new Array(128);
|
||||
for (let i = 0; i < charMap.length; i += 1) {
|
||||
charMap[i] = -1;
|
||||
}
|
||||
for (let i = 0; i < IGNORE_BASE64URL.length; i += 1) {
|
||||
charMap[IGNORE_BASE64URL[i].charCodeAt(0)] = -2;
|
||||
}
|
||||
for (let i = 0; i < TO_BASE64URL.length; i += 1) {
|
||||
charMap[TO_BASE64URL[i].charCodeAt(0)] = i;
|
||||
}
|
||||
return charMap;
|
||||
})();
|
||||
/**
|
||||
* Converts a byte to a Base64-URL string.
|
||||
*
|
||||
* @param byte The byte to convert, or null to flush at the end of the byte sequence.
|
||||
* @param state The Base64 conversion state. Pass an initial value of `{ queue: 0, queuedBits: 0 }`.
|
||||
* @param emit A function called with the next Base64 character when ready.
|
||||
*/
|
||||
function byteToBase64URL(byte, state, emit) {
|
||||
if (byte !== null) {
|
||||
state.queue = (state.queue << 8) | byte;
|
||||
state.queuedBits += 8;
|
||||
while (state.queuedBits >= 6) {
|
||||
const pos = (state.queue >> (state.queuedBits - 6)) & 63;
|
||||
emit(TO_BASE64URL[pos]);
|
||||
state.queuedBits -= 6;
|
||||
}
|
||||
}
|
||||
else if (state.queuedBits > 0) {
|
||||
state.queue = state.queue << (6 - state.queuedBits);
|
||||
state.queuedBits = 6;
|
||||
while (state.queuedBits >= 6) {
|
||||
const pos = (state.queue >> (state.queuedBits - 6)) & 63;
|
||||
emit(TO_BASE64URL[pos]);
|
||||
state.queuedBits -= 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.byteToBase64URL = byteToBase64URL;
|
||||
/**
|
||||
* Converts a String char code (extracted using `string.charCodeAt(position)`) to a sequence of Base64-URL characters.
|
||||
*
|
||||
* @param charCode The char code of the JavaScript string.
|
||||
* @param state The Base64 state. Pass an initial value of `{ queue: 0, queuedBits: 0 }`.
|
||||
* @param emit A function called with the next byte.
|
||||
*/
|
||||
function byteFromBase64URL(charCode, state, emit) {
|
||||
const bits = FROM_BASE64URL[charCode];
|
||||
if (bits > -1) {
|
||||
// valid Base64-URL character
|
||||
state.queue = (state.queue << 6) | bits;
|
||||
state.queuedBits += 6;
|
||||
while (state.queuedBits >= 8) {
|
||||
emit((state.queue >> (state.queuedBits - 8)) & 0xff);
|
||||
state.queuedBits -= 8;
|
||||
}
|
||||
}
|
||||
else if (bits === -2) {
|
||||
// ignore spaces, tabs, newlines, =
|
||||
return;
|
||||
}
|
||||
else {
|
||||
throw new Error(`Invalid Base64-URL character "${String.fromCharCode(charCode)}"`);
|
||||
}
|
||||
}
|
||||
exports.byteFromBase64URL = byteFromBase64URL;
|
||||
/**
|
||||
* Converts a JavaScript string (which may include any valid character) into a
|
||||
* Base64-URL encoded string. The string is first encoded in UTF-8 which is
|
||||
* then encoded as Base64-URL.
|
||||
*
|
||||
* @param str The string to convert.
|
||||
*/
|
||||
function stringToBase64URL(str) {
|
||||
const base64 = [];
|
||||
const emitter = (char) => {
|
||||
base64.push(char);
|
||||
};
|
||||
const state = { queue: 0, queuedBits: 0 };
|
||||
stringToUTF8(str, (byte) => {
|
||||
byteToBase64URL(byte, state, emitter);
|
||||
});
|
||||
byteToBase64URL(null, state, emitter);
|
||||
return base64.join('');
|
||||
}
|
||||
exports.stringToBase64URL = stringToBase64URL;
|
||||
/**
|
||||
* Converts a Base64-URL encoded string into a JavaScript string. It is assumed
|
||||
* that the underlying string has been encoded as UTF-8.
|
||||
*
|
||||
* @param str The Base64-URL encoded string.
|
||||
*/
|
||||
function stringFromBase64URL(str) {
|
||||
const conv = [];
|
||||
const utf8Emit = (codepoint) => {
|
||||
conv.push(String.fromCodePoint(codepoint));
|
||||
};
|
||||
const utf8State = {
|
||||
utf8seq: 0,
|
||||
codepoint: 0,
|
||||
};
|
||||
const b64State = { queue: 0, queuedBits: 0 };
|
||||
const byteEmit = (byte) => {
|
||||
stringFromUTF8(byte, utf8State, utf8Emit);
|
||||
};
|
||||
for (let i = 0; i < str.length; i += 1) {
|
||||
byteFromBase64URL(str.charCodeAt(i), b64State, byteEmit);
|
||||
}
|
||||
return conv.join('');
|
||||
}
|
||||
exports.stringFromBase64URL = stringFromBase64URL;
|
||||
/**
|
||||
* Converts a Unicode codepoint to a multi-byte UTF-8 sequence.
|
||||
*
|
||||
* @param codepoint The Unicode codepoint.
|
||||
* @param emit Function which will be called for each UTF-8 byte that represents the codepoint.
|
||||
*/
|
||||
function codepointToUTF8(codepoint, emit) {
|
||||
if (codepoint <= 0x7f) {
|
||||
emit(codepoint);
|
||||
return;
|
||||
}
|
||||
else if (codepoint <= 0x7ff) {
|
||||
emit(0xc0 | (codepoint >> 6));
|
||||
emit(0x80 | (codepoint & 0x3f));
|
||||
return;
|
||||
}
|
||||
else if (codepoint <= 0xffff) {
|
||||
emit(0xe0 | (codepoint >> 12));
|
||||
emit(0x80 | ((codepoint >> 6) & 0x3f));
|
||||
emit(0x80 | (codepoint & 0x3f));
|
||||
return;
|
||||
}
|
||||
else if (codepoint <= 0x10ffff) {
|
||||
emit(0xf0 | (codepoint >> 18));
|
||||
emit(0x80 | ((codepoint >> 12) & 0x3f));
|
||||
emit(0x80 | ((codepoint >> 6) & 0x3f));
|
||||
emit(0x80 | (codepoint & 0x3f));
|
||||
return;
|
||||
}
|
||||
throw new Error(`Unrecognized Unicode codepoint: ${codepoint.toString(16)}`);
|
||||
}
|
||||
exports.codepointToUTF8 = codepointToUTF8;
|
||||
/**
|
||||
* Converts a JavaScript string to a sequence of UTF-8 bytes.
|
||||
*
|
||||
* @param str The string to convert to UTF-8.
|
||||
* @param emit Function which will be called for each UTF-8 byte of the string.
|
||||
*/
|
||||
function stringToUTF8(str, emit) {
|
||||
for (let i = 0; i < str.length; i += 1) {
|
||||
let codepoint = str.charCodeAt(i);
|
||||
if (codepoint > 0xd7ff && codepoint <= 0xdbff) {
|
||||
// most UTF-16 codepoints are Unicode codepoints, except values in this
|
||||
// range where the next UTF-16 codepoint needs to be combined with the
|
||||
// current one to get the Unicode codepoint
|
||||
const highSurrogate = ((codepoint - 0xd800) * 0x400) & 0xffff;
|
||||
const lowSurrogate = (str.charCodeAt(i + 1) - 0xdc00) & 0xffff;
|
||||
codepoint = (lowSurrogate | highSurrogate) + 0x10000;
|
||||
i += 1;
|
||||
}
|
||||
codepointToUTF8(codepoint, emit);
|
||||
}
|
||||
}
|
||||
exports.stringToUTF8 = stringToUTF8;
|
||||
/**
|
||||
* Converts a UTF-8 byte to a Unicode codepoint.
|
||||
*
|
||||
* @param byte The UTF-8 byte next in the sequence.
|
||||
* @param state The shared state between consecutive UTF-8 bytes in the
|
||||
* sequence, an object with the shape `{ utf8seq: 0, codepoint: 0 }`.
|
||||
* @param emit Function which will be called for each codepoint.
|
||||
*/
|
||||
function stringFromUTF8(byte, state, emit) {
|
||||
if (state.utf8seq === 0) {
|
||||
if (byte <= 0x7f) {
|
||||
emit(byte);
|
||||
return;
|
||||
}
|
||||
// count the number of 1 leading bits until you reach 0
|
||||
for (let leadingBit = 1; leadingBit < 6; leadingBit += 1) {
|
||||
if (((byte >> (7 - leadingBit)) & 1) === 0) {
|
||||
state.utf8seq = leadingBit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (state.utf8seq === 2) {
|
||||
state.codepoint = byte & 31;
|
||||
}
|
||||
else if (state.utf8seq === 3) {
|
||||
state.codepoint = byte & 15;
|
||||
}
|
||||
else if (state.utf8seq === 4) {
|
||||
state.codepoint = byte & 7;
|
||||
}
|
||||
else {
|
||||
throw new Error('Invalid UTF-8 sequence');
|
||||
}
|
||||
state.utf8seq -= 1;
|
||||
}
|
||||
else if (state.utf8seq > 0) {
|
||||
if (byte <= 0x7f) {
|
||||
throw new Error('Invalid UTF-8 sequence');
|
||||
}
|
||||
state.codepoint = (state.codepoint << 6) | (byte & 63);
|
||||
state.utf8seq -= 1;
|
||||
if (state.utf8seq === 0) {
|
||||
emit(state.codepoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.stringFromUTF8 = stringFromUTF8;
|
||||
/**
|
||||
* Helper functions to convert different types of strings to Uint8Array
|
||||
*/
|
||||
function base64UrlToUint8Array(str) {
|
||||
const result = [];
|
||||
const state = { queue: 0, queuedBits: 0 };
|
||||
const onByte = (byte) => {
|
||||
result.push(byte);
|
||||
};
|
||||
for (let i = 0; i < str.length; i += 1) {
|
||||
byteFromBase64URL(str.charCodeAt(i), state, onByte);
|
||||
}
|
||||
return new Uint8Array(result);
|
||||
}
|
||||
exports.base64UrlToUint8Array = base64UrlToUint8Array;
|
||||
function stringToUint8Array(str) {
|
||||
const result = [];
|
||||
stringToUTF8(str, (byte) => result.push(byte));
|
||||
return new Uint8Array(result);
|
||||
}
|
||||
exports.stringToUint8Array = stringToUint8Array;
|
||||
function bytesToBase64URL(bytes) {
|
||||
const result = [];
|
||||
const state = { queue: 0, queuedBits: 0 };
|
||||
const onChar = (char) => {
|
||||
result.push(char);
|
||||
};
|
||||
bytes.forEach((byte) => byteToBase64URL(byte, state, onChar));
|
||||
// always call with `null` after processing all bytes
|
||||
byteToBase64URL(null, state, onChar);
|
||||
return result.join('');
|
||||
}
|
||||
exports.bytesToBase64URL = bytesToBase64URL;
|
||||
//# sourceMappingURL=base64url.js.map
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JWKS_TTL = exports.BASE64URL_REGEX = exports.API_VERSIONS = exports.API_VERSION_HEADER_NAME = exports.NETWORK_FAILURE = exports.DEFAULT_HEADERS = exports.AUDIENCE = exports.STORAGE_KEY = exports.GOTRUE_URL = exports.EXPIRY_MARGIN_MS = exports.AUTO_REFRESH_TICK_THRESHOLD = exports.AUTO_REFRESH_TICK_DURATION_MS = void 0;
|
||||
const version_1 = require("./version");
|
||||
/** Current session will be checked for refresh at this interval. */
|
||||
exports.AUTO_REFRESH_TICK_DURATION_MS = 30 * 1000;
|
||||
/**
|
||||
* A token refresh will be attempted this many ticks before the current session expires. */
|
||||
exports.AUTO_REFRESH_TICK_THRESHOLD = 3;
|
||||
/*
|
||||
* Earliest time before an access token expires that the session should be refreshed.
|
||||
*/
|
||||
exports.EXPIRY_MARGIN_MS = exports.AUTO_REFRESH_TICK_THRESHOLD * exports.AUTO_REFRESH_TICK_DURATION_MS;
|
||||
exports.GOTRUE_URL = 'http://localhost:9999';
|
||||
exports.STORAGE_KEY = 'supabase.auth.token';
|
||||
exports.AUDIENCE = '';
|
||||
exports.DEFAULT_HEADERS = { 'X-Client-Info': `gotrue-js/${version_1.version}` };
|
||||
exports.NETWORK_FAILURE = {
|
||||
MAX_RETRIES: 10,
|
||||
RETRY_INTERVAL: 2, // in deciseconds
|
||||
};
|
||||
exports.API_VERSION_HEADER_NAME = 'X-Supabase-Api-Version';
|
||||
exports.API_VERSIONS = {
|
||||
'2024-01-01': {
|
||||
timestamp: Date.parse('2024-01-01T00:00:00.0Z'),
|
||||
name: '2024-01-01',
|
||||
},
|
||||
};
|
||||
exports.BASE64URL_REGEX = /^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$/i;
|
||||
exports.JWKS_TTL = 10 * 60 * 1000; // 10 minutes
|
||||
//# sourceMappingURL=constants.js.map
|
||||
-137
@@ -1,137 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthInvalidJwtError = exports.isAuthWeakPasswordError = exports.AuthWeakPasswordError = exports.isAuthRetryableFetchError = exports.AuthRetryableFetchError = exports.AuthPKCEGrantCodeExchangeError = exports.isAuthImplicitGrantRedirectError = exports.AuthImplicitGrantRedirectError = exports.AuthInvalidCredentialsError = exports.AuthInvalidTokenResponseError = exports.isAuthSessionMissingError = exports.AuthSessionMissingError = exports.CustomAuthError = exports.AuthUnknownError = exports.isAuthApiError = exports.AuthApiError = exports.isAuthError = exports.AuthError = void 0;
|
||||
class AuthError extends Error {
|
||||
constructor(message, status, code) {
|
||||
super(message);
|
||||
this.__isAuthError = true;
|
||||
this.name = 'AuthError';
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
exports.AuthError = AuthError;
|
||||
function isAuthError(error) {
|
||||
return typeof error === 'object' && error !== null && '__isAuthError' in error;
|
||||
}
|
||||
exports.isAuthError = isAuthError;
|
||||
class AuthApiError extends AuthError {
|
||||
constructor(message, status, code) {
|
||||
super(message, status, code);
|
||||
this.name = 'AuthApiError';
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
exports.AuthApiError = AuthApiError;
|
||||
function isAuthApiError(error) {
|
||||
return isAuthError(error) && error.name === 'AuthApiError';
|
||||
}
|
||||
exports.isAuthApiError = isAuthApiError;
|
||||
class AuthUnknownError extends AuthError {
|
||||
constructor(message, originalError) {
|
||||
super(message);
|
||||
this.name = 'AuthUnknownError';
|
||||
this.originalError = originalError;
|
||||
}
|
||||
}
|
||||
exports.AuthUnknownError = AuthUnknownError;
|
||||
class CustomAuthError extends AuthError {
|
||||
constructor(message, name, status, code) {
|
||||
super(message, status, code);
|
||||
this.name = name;
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
exports.CustomAuthError = CustomAuthError;
|
||||
class AuthSessionMissingError extends CustomAuthError {
|
||||
constructor() {
|
||||
super('Auth session missing!', 'AuthSessionMissingError', 400, undefined);
|
||||
}
|
||||
}
|
||||
exports.AuthSessionMissingError = AuthSessionMissingError;
|
||||
function isAuthSessionMissingError(error) {
|
||||
return isAuthError(error) && error.name === 'AuthSessionMissingError';
|
||||
}
|
||||
exports.isAuthSessionMissingError = isAuthSessionMissingError;
|
||||
class AuthInvalidTokenResponseError extends CustomAuthError {
|
||||
constructor() {
|
||||
super('Auth session or user missing', 'AuthInvalidTokenResponseError', 500, undefined);
|
||||
}
|
||||
}
|
||||
exports.AuthInvalidTokenResponseError = AuthInvalidTokenResponseError;
|
||||
class AuthInvalidCredentialsError extends CustomAuthError {
|
||||
constructor(message) {
|
||||
super(message, 'AuthInvalidCredentialsError', 400, undefined);
|
||||
}
|
||||
}
|
||||
exports.AuthInvalidCredentialsError = AuthInvalidCredentialsError;
|
||||
class AuthImplicitGrantRedirectError extends CustomAuthError {
|
||||
constructor(message, details = null) {
|
||||
super(message, 'AuthImplicitGrantRedirectError', 500, undefined);
|
||||
this.details = null;
|
||||
this.details = details;
|
||||
}
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
message: this.message,
|
||||
status: this.status,
|
||||
details: this.details,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.AuthImplicitGrantRedirectError = AuthImplicitGrantRedirectError;
|
||||
function isAuthImplicitGrantRedirectError(error) {
|
||||
return isAuthError(error) && error.name === 'AuthImplicitGrantRedirectError';
|
||||
}
|
||||
exports.isAuthImplicitGrantRedirectError = isAuthImplicitGrantRedirectError;
|
||||
class AuthPKCEGrantCodeExchangeError extends CustomAuthError {
|
||||
constructor(message, details = null) {
|
||||
super(message, 'AuthPKCEGrantCodeExchangeError', 500, undefined);
|
||||
this.details = null;
|
||||
this.details = details;
|
||||
}
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
message: this.message,
|
||||
status: this.status,
|
||||
details: this.details,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.AuthPKCEGrantCodeExchangeError = AuthPKCEGrantCodeExchangeError;
|
||||
class AuthRetryableFetchError extends CustomAuthError {
|
||||
constructor(message, status) {
|
||||
super(message, 'AuthRetryableFetchError', status, undefined);
|
||||
}
|
||||
}
|
||||
exports.AuthRetryableFetchError = AuthRetryableFetchError;
|
||||
function isAuthRetryableFetchError(error) {
|
||||
return isAuthError(error) && error.name === 'AuthRetryableFetchError';
|
||||
}
|
||||
exports.isAuthRetryableFetchError = isAuthRetryableFetchError;
|
||||
/**
|
||||
* This error is thrown on certain methods when the password used is deemed
|
||||
* weak. Inspect the reasons to identify what password strength rules are
|
||||
* inadequate.
|
||||
*/
|
||||
class AuthWeakPasswordError extends CustomAuthError {
|
||||
constructor(message, status, reasons) {
|
||||
super(message, 'AuthWeakPasswordError', status, 'weak_password');
|
||||
this.reasons = reasons;
|
||||
}
|
||||
}
|
||||
exports.AuthWeakPasswordError = AuthWeakPasswordError;
|
||||
function isAuthWeakPasswordError(error) {
|
||||
return isAuthError(error) && error.name === 'AuthWeakPasswordError';
|
||||
}
|
||||
exports.isAuthWeakPasswordError = isAuthWeakPasswordError;
|
||||
class AuthInvalidJwtError extends CustomAuthError {
|
||||
constructor(message) {
|
||||
super(message, 'AuthInvalidJwtError', 400, 'invalid_jwt');
|
||||
}
|
||||
}
|
||||
exports.AuthInvalidJwtError = AuthInvalidJwtError;
|
||||
//# sourceMappingURL=errors.js.map
|
||||
-195
@@ -1,195 +0,0 @@
|
||||
"use strict";
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports._noResolveJsonResponse = exports._generateLinkResponse = exports._ssoResponse = exports._userResponse = exports._sessionResponsePassword = exports._sessionResponse = exports._request = exports.handleError = void 0;
|
||||
const constants_1 = require("./constants");
|
||||
const helpers_1 = require("./helpers");
|
||||
const errors_1 = require("./errors");
|
||||
const _getErrorMessage = (err) => err.msg || err.message || err.error_description || err.error || JSON.stringify(err);
|
||||
const NETWORK_ERROR_CODES = [502, 503, 504];
|
||||
async function handleError(error) {
|
||||
var _a;
|
||||
if (!(0, helpers_1.looksLikeFetchResponse)(error)) {
|
||||
throw new errors_1.AuthRetryableFetchError(_getErrorMessage(error), 0);
|
||||
}
|
||||
if (NETWORK_ERROR_CODES.includes(error.status)) {
|
||||
// status in 500...599 range - server had an error, request might be retryed.
|
||||
throw new errors_1.AuthRetryableFetchError(_getErrorMessage(error), error.status);
|
||||
}
|
||||
let data;
|
||||
try {
|
||||
data = await error.json();
|
||||
}
|
||||
catch (e) {
|
||||
throw new errors_1.AuthUnknownError(_getErrorMessage(e), e);
|
||||
}
|
||||
let errorCode = undefined;
|
||||
const responseAPIVersion = (0, helpers_1.parseResponseAPIVersion)(error);
|
||||
if (responseAPIVersion &&
|
||||
responseAPIVersion.getTime() >= constants_1.API_VERSIONS['2024-01-01'].timestamp &&
|
||||
typeof data === 'object' &&
|
||||
data &&
|
||||
typeof data.code === 'string') {
|
||||
errorCode = data.code;
|
||||
}
|
||||
else if (typeof data === 'object' && data && typeof data.error_code === 'string') {
|
||||
errorCode = data.error_code;
|
||||
}
|
||||
if (!errorCode) {
|
||||
// Legacy support for weak password errors, when there were no error codes
|
||||
if (typeof data === 'object' &&
|
||||
data &&
|
||||
typeof data.weak_password === 'object' &&
|
||||
data.weak_password &&
|
||||
Array.isArray(data.weak_password.reasons) &&
|
||||
data.weak_password.reasons.length &&
|
||||
data.weak_password.reasons.reduce((a, i) => a && typeof i === 'string', true)) {
|
||||
throw new errors_1.AuthWeakPasswordError(_getErrorMessage(data), error.status, data.weak_password.reasons);
|
||||
}
|
||||
}
|
||||
else if (errorCode === 'weak_password') {
|
||||
throw new errors_1.AuthWeakPasswordError(_getErrorMessage(data), error.status, ((_a = data.weak_password) === null || _a === void 0 ? void 0 : _a.reasons) || []);
|
||||
}
|
||||
else if (errorCode === 'session_not_found') {
|
||||
// The `session_id` inside the JWT does not correspond to a row in the
|
||||
// `sessions` table. This usually means the user has signed out, has been
|
||||
// deleted, or their session has somehow been terminated.
|
||||
throw new errors_1.AuthSessionMissingError();
|
||||
}
|
||||
throw new errors_1.AuthApiError(_getErrorMessage(data), error.status || 500, errorCode);
|
||||
}
|
||||
exports.handleError = handleError;
|
||||
const _getRequestParams = (method, options, parameters, body) => {
|
||||
const params = { method, headers: (options === null || options === void 0 ? void 0 : options.headers) || {} };
|
||||
if (method === 'GET') {
|
||||
return params;
|
||||
}
|
||||
params.headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8' }, options === null || options === void 0 ? void 0 : options.headers);
|
||||
params.body = JSON.stringify(body);
|
||||
return Object.assign(Object.assign({}, params), parameters);
|
||||
};
|
||||
async function _request(fetcher, method, url, options) {
|
||||
var _a;
|
||||
const headers = Object.assign({}, options === null || options === void 0 ? void 0 : options.headers);
|
||||
if (!headers[constants_1.API_VERSION_HEADER_NAME]) {
|
||||
headers[constants_1.API_VERSION_HEADER_NAME] = constants_1.API_VERSIONS['2024-01-01'].name;
|
||||
}
|
||||
if (options === null || options === void 0 ? void 0 : options.jwt) {
|
||||
headers['Authorization'] = `Bearer ${options.jwt}`;
|
||||
}
|
||||
const qs = (_a = options === null || options === void 0 ? void 0 : options.query) !== null && _a !== void 0 ? _a : {};
|
||||
if (options === null || options === void 0 ? void 0 : options.redirectTo) {
|
||||
qs['redirect_to'] = options.redirectTo;
|
||||
}
|
||||
const queryString = Object.keys(qs).length ? '?' + new URLSearchParams(qs).toString() : '';
|
||||
const data = await _handleRequest(fetcher, method, url + queryString, {
|
||||
headers,
|
||||
noResolveJson: options === null || options === void 0 ? void 0 : options.noResolveJson,
|
||||
}, {}, options === null || options === void 0 ? void 0 : options.body);
|
||||
return (options === null || options === void 0 ? void 0 : options.xform) ? options === null || options === void 0 ? void 0 : options.xform(data) : { data: Object.assign({}, data), error: null };
|
||||
}
|
||||
exports._request = _request;
|
||||
async function _handleRequest(fetcher, method, url, options, parameters, body) {
|
||||
const requestParams = _getRequestParams(method, options, parameters, body);
|
||||
let result;
|
||||
try {
|
||||
result = await fetcher(url, Object.assign({}, requestParams));
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
// fetch failed, likely due to a network or CORS error
|
||||
throw new errors_1.AuthRetryableFetchError(_getErrorMessage(e), 0);
|
||||
}
|
||||
if (!result.ok) {
|
||||
await handleError(result);
|
||||
}
|
||||
if (options === null || options === void 0 ? void 0 : options.noResolveJson) {
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
return await result.json();
|
||||
}
|
||||
catch (e) {
|
||||
await handleError(e);
|
||||
}
|
||||
}
|
||||
function _sessionResponse(data) {
|
||||
var _a;
|
||||
let session = null;
|
||||
if (hasSession(data)) {
|
||||
session = Object.assign({}, data);
|
||||
if (!data.expires_at) {
|
||||
session.expires_at = (0, helpers_1.expiresAt)(data.expires_in);
|
||||
}
|
||||
}
|
||||
const user = (_a = data.user) !== null && _a !== void 0 ? _a : data;
|
||||
return { data: { session, user }, error: null };
|
||||
}
|
||||
exports._sessionResponse = _sessionResponse;
|
||||
function _sessionResponsePassword(data) {
|
||||
const response = _sessionResponse(data);
|
||||
if (!response.error &&
|
||||
data.weak_password &&
|
||||
typeof data.weak_password === 'object' &&
|
||||
Array.isArray(data.weak_password.reasons) &&
|
||||
data.weak_password.reasons.length &&
|
||||
data.weak_password.message &&
|
||||
typeof data.weak_password.message === 'string' &&
|
||||
data.weak_password.reasons.reduce((a, i) => a && typeof i === 'string', true)) {
|
||||
response.data.weak_password = data.weak_password;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
exports._sessionResponsePassword = _sessionResponsePassword;
|
||||
function _userResponse(data) {
|
||||
var _a;
|
||||
const user = (_a = data.user) !== null && _a !== void 0 ? _a : data;
|
||||
return { data: { user }, error: null };
|
||||
}
|
||||
exports._userResponse = _userResponse;
|
||||
function _ssoResponse(data) {
|
||||
return { data, error: null };
|
||||
}
|
||||
exports._ssoResponse = _ssoResponse;
|
||||
function _generateLinkResponse(data) {
|
||||
const { action_link, email_otp, hashed_token, redirect_to, verification_type } = data, rest = __rest(data, ["action_link", "email_otp", "hashed_token", "redirect_to", "verification_type"]);
|
||||
const properties = {
|
||||
action_link,
|
||||
email_otp,
|
||||
hashed_token,
|
||||
redirect_to,
|
||||
verification_type,
|
||||
};
|
||||
const user = Object.assign({}, rest);
|
||||
return {
|
||||
data: {
|
||||
properties,
|
||||
user,
|
||||
},
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
exports._generateLinkResponse = _generateLinkResponse;
|
||||
function _noResolveJsonResponse(data) {
|
||||
return data;
|
||||
}
|
||||
exports._noResolveJsonResponse = _noResolveJsonResponse;
|
||||
/**
|
||||
* hasSession checks if the response object contains a valid session
|
||||
* @param data A response object
|
||||
* @returns true if a session is in the response
|
||||
*/
|
||||
function hasSession(data) {
|
||||
return data.access_token && data.refresh_token && data.expires_in;
|
||||
}
|
||||
//# sourceMappingURL=fetch.js.map
|
||||
-378
@@ -1,378 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.deepClone = exports.userNotAvailableProxy = exports.validateUUID = exports.getAlgorithm = exports.validateExp = exports.parseResponseAPIVersion = exports.getCodeChallengeAndMethod = exports.generatePKCEChallenge = exports.generatePKCEVerifier = exports.retryable = exports.sleep = exports.decodeJWT = exports.Deferred = exports.removeItemAsync = exports.getItemAsync = exports.setItemAsync = exports.looksLikeFetchResponse = exports.resolveFetch = exports.parseParametersFromURL = exports.supportsLocalStorage = exports.isBrowser = exports.uuid = exports.expiresAt = void 0;
|
||||
const constants_1 = require("./constants");
|
||||
const errors_1 = require("./errors");
|
||||
const base64url_1 = require("./base64url");
|
||||
function expiresAt(expiresIn) {
|
||||
const timeNow = Math.round(Date.now() / 1000);
|
||||
return timeNow + expiresIn;
|
||||
}
|
||||
exports.expiresAt = expiresAt;
|
||||
function uuid() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
exports.uuid = uuid;
|
||||
const isBrowser = () => typeof window !== 'undefined' && typeof document !== 'undefined';
|
||||
exports.isBrowser = isBrowser;
|
||||
const localStorageWriteTests = {
|
||||
tested: false,
|
||||
writable: false,
|
||||
};
|
||||
/**
|
||||
* Checks whether localStorage is supported on this browser.
|
||||
*/
|
||||
const supportsLocalStorage = () => {
|
||||
if (!(0, exports.isBrowser)()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (typeof globalThis.localStorage !== 'object') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// DOM exception when accessing `localStorage`
|
||||
return false;
|
||||
}
|
||||
if (localStorageWriteTests.tested) {
|
||||
return localStorageWriteTests.writable;
|
||||
}
|
||||
const randomKey = `lswt-${Math.random()}${Math.random()}`;
|
||||
try {
|
||||
globalThis.localStorage.setItem(randomKey, randomKey);
|
||||
globalThis.localStorage.removeItem(randomKey);
|
||||
localStorageWriteTests.tested = true;
|
||||
localStorageWriteTests.writable = true;
|
||||
}
|
||||
catch (e) {
|
||||
// localStorage can't be written to
|
||||
// https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document
|
||||
localStorageWriteTests.tested = true;
|
||||
localStorageWriteTests.writable = false;
|
||||
}
|
||||
return localStorageWriteTests.writable;
|
||||
};
|
||||
exports.supportsLocalStorage = supportsLocalStorage;
|
||||
/**
|
||||
* Extracts parameters encoded in the URL both in the query and fragment.
|
||||
*/
|
||||
function parseParametersFromURL(href) {
|
||||
const result = {};
|
||||
const url = new URL(href);
|
||||
if (url.hash && url.hash[0] === '#') {
|
||||
try {
|
||||
const hashSearchParams = new URLSearchParams(url.hash.substring(1));
|
||||
hashSearchParams.forEach((value, key) => {
|
||||
result[key] = value;
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
// hash is not a query string
|
||||
}
|
||||
}
|
||||
// search parameters take precedence over hash parameters
|
||||
url.searchParams.forEach((value, key) => {
|
||||
result[key] = value;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
exports.parseParametersFromURL = parseParametersFromURL;
|
||||
const resolveFetch = (customFetch) => {
|
||||
let _fetch;
|
||||
if (customFetch) {
|
||||
_fetch = customFetch;
|
||||
}
|
||||
else if (typeof fetch === 'undefined') {
|
||||
_fetch = (...args) => Promise.resolve().then(() => __importStar(require('@supabase/node-fetch'))).then(({ default: fetch }) => fetch(...args));
|
||||
}
|
||||
else {
|
||||
_fetch = fetch;
|
||||
}
|
||||
return (...args) => _fetch(...args);
|
||||
};
|
||||
exports.resolveFetch = resolveFetch;
|
||||
const looksLikeFetchResponse = (maybeResponse) => {
|
||||
return (typeof maybeResponse === 'object' &&
|
||||
maybeResponse !== null &&
|
||||
'status' in maybeResponse &&
|
||||
'ok' in maybeResponse &&
|
||||
'json' in maybeResponse &&
|
||||
typeof maybeResponse.json === 'function');
|
||||
};
|
||||
exports.looksLikeFetchResponse = looksLikeFetchResponse;
|
||||
// Storage helpers
|
||||
const setItemAsync = async (storage, key, data) => {
|
||||
await storage.setItem(key, JSON.stringify(data));
|
||||
};
|
||||
exports.setItemAsync = setItemAsync;
|
||||
const getItemAsync = async (storage, key) => {
|
||||
const value = await storage.getItem(key);
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
catch (_a) {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
exports.getItemAsync = getItemAsync;
|
||||
const removeItemAsync = async (storage, key) => {
|
||||
await storage.removeItem(key);
|
||||
};
|
||||
exports.removeItemAsync = removeItemAsync;
|
||||
/**
|
||||
* A deferred represents some asynchronous work that is not yet finished, which
|
||||
* may or may not culminate in a value.
|
||||
* Taken from: https://github.com/mike-north/types/blob/master/src/async.ts
|
||||
*/
|
||||
class Deferred {
|
||||
constructor() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
||||
;
|
||||
this.promise = new Deferred.promiseConstructor((res, rej) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
||||
;
|
||||
this.resolve = res;
|
||||
this.reject = rej;
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Deferred = Deferred;
|
||||
Deferred.promiseConstructor = Promise;
|
||||
function decodeJWT(token) {
|
||||
const parts = token.split('.');
|
||||
if (parts.length !== 3) {
|
||||
throw new errors_1.AuthInvalidJwtError('Invalid JWT structure');
|
||||
}
|
||||
// Regex checks for base64url format
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (!constants_1.BASE64URL_REGEX.test(parts[i])) {
|
||||
throw new errors_1.AuthInvalidJwtError('JWT not in base64url format');
|
||||
}
|
||||
}
|
||||
const data = {
|
||||
// using base64url lib
|
||||
header: JSON.parse((0, base64url_1.stringFromBase64URL)(parts[0])),
|
||||
payload: JSON.parse((0, base64url_1.stringFromBase64URL)(parts[1])),
|
||||
signature: (0, base64url_1.base64UrlToUint8Array)(parts[2]),
|
||||
raw: {
|
||||
header: parts[0],
|
||||
payload: parts[1],
|
||||
},
|
||||
};
|
||||
return data;
|
||||
}
|
||||
exports.decodeJWT = decodeJWT;
|
||||
/**
|
||||
* Creates a promise that resolves to null after some time.
|
||||
*/
|
||||
async function sleep(time) {
|
||||
return await new Promise((accept) => {
|
||||
setTimeout(() => accept(null), time);
|
||||
});
|
||||
}
|
||||
exports.sleep = sleep;
|
||||
/**
|
||||
* Converts the provided async function into a retryable function. Each result
|
||||
* or thrown error is sent to the isRetryable function which should return true
|
||||
* if the function should run again.
|
||||
*/
|
||||
function retryable(fn, isRetryable) {
|
||||
const promise = new Promise((accept, reject) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
||||
;
|
||||
(async () => {
|
||||
for (let attempt = 0; attempt < Infinity; attempt++) {
|
||||
try {
|
||||
const result = await fn(attempt);
|
||||
if (!isRetryable(attempt, null, result)) {
|
||||
accept(result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
if (!isRetryable(attempt, e)) {
|
||||
reject(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
exports.retryable = retryable;
|
||||
function dec2hex(dec) {
|
||||
return ('0' + dec.toString(16)).substr(-2);
|
||||
}
|
||||
// Functions below taken from: https://stackoverflow.com/questions/63309409/creating-a-code-verifier-and-challenge-for-pkce-auth-on-spotify-api-in-reactjs
|
||||
function generatePKCEVerifier() {
|
||||
const verifierLength = 56;
|
||||
const array = new Uint32Array(verifierLength);
|
||||
if (typeof crypto === 'undefined') {
|
||||
const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
|
||||
const charSetLen = charSet.length;
|
||||
let verifier = '';
|
||||
for (let i = 0; i < verifierLength; i++) {
|
||||
verifier += charSet.charAt(Math.floor(Math.random() * charSetLen));
|
||||
}
|
||||
return verifier;
|
||||
}
|
||||
crypto.getRandomValues(array);
|
||||
return Array.from(array, dec2hex).join('');
|
||||
}
|
||||
exports.generatePKCEVerifier = generatePKCEVerifier;
|
||||
async function sha256(randomString) {
|
||||
const encoder = new TextEncoder();
|
||||
const encodedData = encoder.encode(randomString);
|
||||
const hash = await crypto.subtle.digest('SHA-256', encodedData);
|
||||
const bytes = new Uint8Array(hash);
|
||||
return Array.from(bytes)
|
||||
.map((c) => String.fromCharCode(c))
|
||||
.join('');
|
||||
}
|
||||
async function generatePKCEChallenge(verifier) {
|
||||
const hasCryptoSupport = typeof crypto !== 'undefined' &&
|
||||
typeof crypto.subtle !== 'undefined' &&
|
||||
typeof TextEncoder !== 'undefined';
|
||||
if (!hasCryptoSupport) {
|
||||
console.warn('WebCrypto API is not supported. Code challenge method will default to use plain instead of sha256.');
|
||||
return verifier;
|
||||
}
|
||||
const hashed = await sha256(verifier);
|
||||
return btoa(hashed).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
||||
}
|
||||
exports.generatePKCEChallenge = generatePKCEChallenge;
|
||||
async function getCodeChallengeAndMethod(storage, storageKey, isPasswordRecovery = false) {
|
||||
const codeVerifier = generatePKCEVerifier();
|
||||
let storedCodeVerifier = codeVerifier;
|
||||
if (isPasswordRecovery) {
|
||||
storedCodeVerifier += '/PASSWORD_RECOVERY';
|
||||
}
|
||||
await (0, exports.setItemAsync)(storage, `${storageKey}-code-verifier`, storedCodeVerifier);
|
||||
const codeChallenge = await generatePKCEChallenge(codeVerifier);
|
||||
const codeChallengeMethod = codeVerifier === codeChallenge ? 'plain' : 's256';
|
||||
return [codeChallenge, codeChallengeMethod];
|
||||
}
|
||||
exports.getCodeChallengeAndMethod = getCodeChallengeAndMethod;
|
||||
/** Parses the API version which is 2YYY-MM-DD. */
|
||||
const API_VERSION_REGEX = /^2[0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1])$/i;
|
||||
function parseResponseAPIVersion(response) {
|
||||
const apiVersion = response.headers.get(constants_1.API_VERSION_HEADER_NAME);
|
||||
if (!apiVersion) {
|
||||
return null;
|
||||
}
|
||||
if (!apiVersion.match(API_VERSION_REGEX)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const date = new Date(`${apiVersion}T00:00:00.0Z`);
|
||||
return date;
|
||||
}
|
||||
catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.parseResponseAPIVersion = parseResponseAPIVersion;
|
||||
function validateExp(exp) {
|
||||
if (!exp) {
|
||||
throw new Error('Missing exp claim');
|
||||
}
|
||||
const timeNow = Math.floor(Date.now() / 1000);
|
||||
if (exp <= timeNow) {
|
||||
throw new Error('JWT has expired');
|
||||
}
|
||||
}
|
||||
exports.validateExp = validateExp;
|
||||
function getAlgorithm(alg) {
|
||||
switch (alg) {
|
||||
case 'RS256':
|
||||
return {
|
||||
name: 'RSASSA-PKCS1-v1_5',
|
||||
hash: { name: 'SHA-256' },
|
||||
};
|
||||
case 'ES256':
|
||||
return {
|
||||
name: 'ECDSA',
|
||||
namedCurve: 'P-256',
|
||||
hash: { name: 'SHA-256' },
|
||||
};
|
||||
default:
|
||||
throw new Error('Invalid alg claim');
|
||||
}
|
||||
}
|
||||
exports.getAlgorithm = getAlgorithm;
|
||||
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
||||
function validateUUID(str) {
|
||||
if (!UUID_REGEX.test(str)) {
|
||||
throw new Error('@supabase/auth-js: Expected parameter to be UUID but is not');
|
||||
}
|
||||
}
|
||||
exports.validateUUID = validateUUID;
|
||||
function userNotAvailableProxy() {
|
||||
const proxyTarget = {};
|
||||
return new Proxy(proxyTarget, {
|
||||
get: (target, prop) => {
|
||||
if (prop === '__isUserNotAvailableProxy') {
|
||||
return true;
|
||||
}
|
||||
// Preventative check for common problematic symbols during cloning/inspection
|
||||
// These symbols might be accessed by structuredClone or other internal mechanisms.
|
||||
if (typeof prop === 'symbol') {
|
||||
const sProp = prop.toString();
|
||||
if (sProp === 'Symbol(Symbol.toPrimitive)' ||
|
||||
sProp === 'Symbol(Symbol.toStringTag)' ||
|
||||
sProp === 'Symbol(util.inspect.custom)') {
|
||||
// Node.js util.inspect
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
throw new Error(`@supabase/auth-js: client was created with userStorage option and there was no user stored in the user storage. Accessing the "${prop}" property of the session object is not supported. Please use getUser() instead.`);
|
||||
},
|
||||
set: (_target, prop) => {
|
||||
throw new Error(`@supabase/auth-js: client was created with userStorage option and there was no user stored in the user storage. Setting the "${prop}" property of the session object is not supported. Please use getUser() to fetch a user object you can manipulate.`);
|
||||
},
|
||||
deleteProperty: (_target, prop) => {
|
||||
throw new Error(`@supabase/auth-js: client was created with userStorage option and there was no user stored in the user storage. Deleting the "${prop}" property of the session object is not supported. Please use getUser() to fetch a user object you can manipulate.`);
|
||||
},
|
||||
});
|
||||
}
|
||||
exports.userNotAvailableProxy = userNotAvailableProxy;
|
||||
/**
|
||||
* Deep clones a JSON-serializable object using JSON.parse(JSON.stringify(obj)).
|
||||
* Note: Only works for JSON-safe data.
|
||||
*/
|
||||
function deepClone(obj) {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
}
|
||||
exports.deepClone = deepClone;
|
||||
//# sourceMappingURL=helpers.js.map
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.memoryLocalStorageAdapter = void 0;
|
||||
/**
|
||||
* Returns a localStorage-like object that stores the key-value pairs in
|
||||
* memory.
|
||||
*/
|
||||
function memoryLocalStorageAdapter(store = {}) {
|
||||
return {
|
||||
getItem: (key) => {
|
||||
return store[key] || null;
|
||||
},
|
||||
setItem: (key, value) => {
|
||||
store[key] = value;
|
||||
},
|
||||
removeItem: (key) => {
|
||||
delete store[key];
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.memoryLocalStorageAdapter = memoryLocalStorageAdapter;
|
||||
//# sourceMappingURL=local-storage.js.map
|
||||
-187
@@ -1,187 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.processLock = exports.navigatorLock = exports.ProcessLockAcquireTimeoutError = exports.NavigatorLockAcquireTimeoutError = exports.LockAcquireTimeoutError = exports.internals = void 0;
|
||||
const helpers_1 = require("./helpers");
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
exports.internals = {
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
debug: !!(globalThis &&
|
||||
(0, helpers_1.supportsLocalStorage)() &&
|
||||
globalThis.localStorage &&
|
||||
globalThis.localStorage.getItem('supabase.gotrue-js.locks.debug') === 'true'),
|
||||
};
|
||||
/**
|
||||
* An error thrown when a lock cannot be acquired after some amount of time.
|
||||
*
|
||||
* Use the {@link #isAcquireTimeout} property instead of checking with `instanceof`.
|
||||
*/
|
||||
class LockAcquireTimeoutError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.isAcquireTimeout = true;
|
||||
}
|
||||
}
|
||||
exports.LockAcquireTimeoutError = LockAcquireTimeoutError;
|
||||
class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
||||
}
|
||||
exports.NavigatorLockAcquireTimeoutError = NavigatorLockAcquireTimeoutError;
|
||||
class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
||||
}
|
||||
exports.ProcessLockAcquireTimeoutError = ProcessLockAcquireTimeoutError;
|
||||
/**
|
||||
* Implements a global exclusive lock using the Navigator LockManager API. It
|
||||
* is available on all browsers released after 2022-03-15 with Safari being the
|
||||
* last one to release support. If the API is not available, this function will
|
||||
* throw. Make sure you check availablility before configuring {@link
|
||||
* GoTrueClient}.
|
||||
*
|
||||
* You can turn on debugging by setting the `supabase.gotrue-js.locks.debug`
|
||||
* local storage item to `true`.
|
||||
*
|
||||
* Internals:
|
||||
*
|
||||
* Since the LockManager API does not preserve stack traces for the async
|
||||
* function passed in the `request` method, a trick is used where acquiring the
|
||||
* lock releases a previously started promise to run the operation in the `fn`
|
||||
* function. The lock waits for that promise to finish (with or without error),
|
||||
* while the function will finally wait for the result anyway.
|
||||
*
|
||||
* @param name Name of the lock to be acquired.
|
||||
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
||||
* the lock can't be acquired without waiting. If positive, the lock acquire
|
||||
* will time out after so many milliseconds. An error is
|
||||
* a timeout if it has `isAcquireTimeout` set to true.
|
||||
* @param fn The operation to run once the lock is acquired.
|
||||
*/
|
||||
async function navigatorLock(name, acquireTimeout, fn) {
|
||||
if (exports.internals.debug) {
|
||||
console.log('@supabase/gotrue-js: navigatorLock: acquire lock', name, acquireTimeout);
|
||||
}
|
||||
const abortController = new globalThis.AbortController();
|
||||
if (acquireTimeout > 0) {
|
||||
setTimeout(() => {
|
||||
abortController.abort();
|
||||
if (exports.internals.debug) {
|
||||
console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name);
|
||||
}
|
||||
}, acquireTimeout);
|
||||
}
|
||||
// MDN article: https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request
|
||||
// Wrapping navigator.locks.request() with a plain Promise is done as some
|
||||
// libraries like zone.js patch the Promise object to track the execution
|
||||
// context. However, it appears that most browsers use an internal promise
|
||||
// implementation when using the navigator.locks.request() API causing them
|
||||
// to lose context and emit confusing log messages or break certain features.
|
||||
// This wrapping is believed to help zone.js track the execution context
|
||||
// better.
|
||||
return await Promise.resolve().then(() => 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, lock.name);
|
||||
}
|
||||
try {
|
||||
return await fn();
|
||||
}
|
||||
finally {
|
||||
if (exports.internals.debug) {
|
||||
console.log('@supabase/gotrue-js: navigatorLock: released', name, lock.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (acquireTimeout === 0) {
|
||||
if (exports.internals.debug) {
|
||||
console.log('@supabase/gotrue-js: navigatorLock: not immediately available', name);
|
||||
}
|
||||
throw new NavigatorLockAcquireTimeoutError(`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`);
|
||||
}
|
||||
else {
|
||||
if (exports.internals.debug) {
|
||||
try {
|
||||
const result = await globalThis.navigator.locks.query();
|
||||
console.log('@supabase/gotrue-js: Navigator LockManager state', JSON.stringify(result, null, ' '));
|
||||
}
|
||||
catch (e) {
|
||||
console.warn('@supabase/gotrue-js: Error when querying Navigator LockManager state', e);
|
||||
}
|
||||
}
|
||||
// Browser is not following the Navigator LockManager spec, it
|
||||
// returned a null lock when we didn't use ifAvailable. So we can
|
||||
// pretend the lock is acquired in the name of backward compatibility
|
||||
// and user experience and just run the function.
|
||||
console.warn('@supabase/gotrue-js: Navigator LockManager returned a null lock when using #request without ifAvailable set to true, it appears this browser is not following the LockManager spec https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request');
|
||||
return await fn();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
exports.navigatorLock = navigatorLock;
|
||||
const PROCESS_LOCKS = {};
|
||||
/**
|
||||
* Implements a global exclusive lock that works only in the current process.
|
||||
* Useful for environments like React Native or other non-browser
|
||||
* single-process (i.e. no concept of "tabs") environments.
|
||||
*
|
||||
* Use {@link #navigatorLock} in browser environments.
|
||||
*
|
||||
* @param name Name of the lock to be acquired.
|
||||
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
||||
* the lock can't be acquired without waiting. If positive, the lock acquire
|
||||
* will time out after so many milliseconds. An error is
|
||||
* a timeout if it has `isAcquireTimeout` set to true.
|
||||
* @param fn The operation to run once the lock is acquired.
|
||||
*/
|
||||
async function processLock(name, acquireTimeout, fn) {
|
||||
var _a;
|
||||
const previousOperation = (_a = PROCESS_LOCKS[name]) !== null && _a !== void 0 ? _a : Promise.resolve();
|
||||
const currentOperation = Promise.race([
|
||||
previousOperation.catch(() => {
|
||||
// ignore error of previous operation that we're waiting to finish
|
||||
return null;
|
||||
}),
|
||||
acquireTimeout >= 0
|
||||
? new Promise((_, reject) => {
|
||||
setTimeout(() => {
|
||||
reject(new ProcessLockAcquireTimeoutError(`Acquring process lock with name "${name}" timed out`));
|
||||
}, acquireTimeout);
|
||||
})
|
||||
: null,
|
||||
].filter((x) => x))
|
||||
.catch((e) => {
|
||||
if (e && e.isAcquireTimeout) {
|
||||
throw e;
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.then(async () => {
|
||||
// previous operations finished and we didn't get a race on the acquire
|
||||
// timeout, so the current operation can finally start
|
||||
return await fn();
|
||||
});
|
||||
PROCESS_LOCKS[name] = currentOperation.catch(async (e) => {
|
||||
if (e && e.isAcquireTimeout) {
|
||||
// if the current operation timed out, it doesn't mean that the previous
|
||||
// operation finished, so we need contnue waiting for it to finish
|
||||
await previousOperation;
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
// finally wait for the current operation to finish successfully, with an
|
||||
// error or with an acquire timeout error
|
||||
return await currentOperation;
|
||||
}
|
||||
exports.processLock = processLock;
|
||||
//# sourceMappingURL=locks.js.map
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.polyfillGlobalThis = void 0;
|
||||
/**
|
||||
* https://mathiasbynens.be/notes/globalthis
|
||||
*/
|
||||
function polyfillGlobalThis() {
|
||||
if (typeof globalThis === 'object')
|
||||
return;
|
||||
try {
|
||||
Object.defineProperty(Object.prototype, '__magic__', {
|
||||
get: function () {
|
||||
return this;
|
||||
},
|
||||
configurable: true,
|
||||
});
|
||||
// @ts-expect-error 'Allow access to magic'
|
||||
__magic__.globalThis = __magic__;
|
||||
// @ts-expect-error 'Allow access to magic'
|
||||
delete Object.prototype.__magic__;
|
||||
}
|
||||
catch (e) {
|
||||
if (typeof self !== 'undefined') {
|
||||
// @ts-expect-error 'Allow access to globals'
|
||||
self.globalThis = self;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.polyfillGlobalThis = polyfillGlobalThis;
|
||||
//# sourceMappingURL=polyfills.js.map
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SIGN_OUT_SCOPES = void 0;
|
||||
exports.SIGN_OUT_SCOPES = ['global', 'local', 'others'];
|
||||
//# sourceMappingURL=types.js.map
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = void 0;
|
||||
exports.version = '2.71.1';
|
||||
//# sourceMappingURL=version.js.map
|
||||
-69
@@ -1,69 +0,0 @@
|
||||
{
|
||||
"name": "@supabase/auth-js",
|
||||
"version": "2.71.1",
|
||||
"private": false,
|
||||
"description": "Official client library for Supabase Auth",
|
||||
"keywords": [
|
||||
"auth",
|
||||
"supabase",
|
||||
"auth",
|
||||
"authentication"
|
||||
],
|
||||
"homepage": "https://github.com/supabase/auth-js",
|
||||
"bugs": "https://github.com/supabase/auth-js/issues",
|
||||
"license": "MIT",
|
||||
"author": "Supabase",
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"main": "dist/main/index.js",
|
||||
"module": "dist/module/index.js",
|
||||
"types": "dist/module/index.d.ts",
|
||||
"repository": "github:supabase/auth-js",
|
||||
"scripts": {
|
||||
"clean": "rimraf dist docs",
|
||||
"coverage": "echo \"run npm test\"",
|
||||
"format": "prettier --write \"{src,test}/**/*.ts\"",
|
||||
"build": "genversion src/lib/version.ts --es6 && run-s clean format build:* && run-s lint",
|
||||
"build:main": "tsc -p tsconfig.json",
|
||||
"build:module": "tsc -p tsconfig.module.json",
|
||||
"lint": "eslint ./src/**/* test/**/*.test.ts",
|
||||
"test": "run-s test:clean test:infra test:suite test:clean",
|
||||
"test:suite": "npm --prefix ./test run test",
|
||||
"test:infra": "cd infra && docker compose down && docker compose pull && docker compose up -d && sleep 30",
|
||||
"test:clean": "cd infra && docker compose down",
|
||||
"docs": "typedoc src/index.ts --out docs/v2 --excludePrivate --excludeProtected",
|
||||
"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals --excludePrivate --excludeProtected src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@supabase/node-fetch": "^2.6.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/faker": "^5.1.6",
|
||||
"@types/jest": "^28.1.6",
|
||||
"@types/jsonwebtoken": "^8.5.6",
|
||||
"@types/node": "^18.16.19",
|
||||
"@types/node-fetch": "^2.6.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.30.7",
|
||||
"@typescript-eslint/parser": "^5.30.7",
|
||||
"eslint": "^8.20.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-config-standard": "^17.0.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^6.0.0",
|
||||
"faker": "^5.3.1",
|
||||
"genversion": "^3.1.1",
|
||||
"jest": "^28.1.3",
|
||||
"jest-mock-server": "^0.1.0",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "2.7.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"semantic-release-plugin-update-version-in-files": "^1.1.0",
|
||||
"ts-jest": "^28.0.7",
|
||||
"typedoc": "^0.22.16",
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user