@data-loom/auth-js 0.0.2-alpha.2 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/AuthAdminApi.d.ts +4 -0
- package/dist/main/AuthAdminApi.d.ts.map +1 -0
- package/dist/main/AuthAdminApi.js +9 -0
- package/dist/main/AuthAdminApi.js.map +1 -0
- package/dist/main/AuthClient.d.ts +4 -0
- package/dist/main/AuthClient.d.ts.map +1 -0
- package/dist/main/AuthClient.js +9 -0
- package/dist/main/AuthClient.js.map +1 -0
- package/dist/main/GoTrueAdminApi.d.ts +99 -0
- package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
- package/dist/main/GoTrueAdminApi.js +268 -0
- package/dist/main/GoTrueAdminApi.js.map +1 -0
- package/dist/main/GoTrueClient.d.ts +492 -0
- package/dist/main/GoTrueClient.d.ts.map +1 -0
- package/dist/main/GoTrueClient.js +2227 -0
- package/dist/main/GoTrueClient.js.map +1 -0
- package/dist/main/index.d.ts +9 -0
- package/dist/main/index.d.ts.map +1 -0
- package/dist/main/index.js +35 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/lib/version.d.ts +2 -0
- package/dist/main/lib/version.d.ts.map +1 -0
- package/dist/main/lib/version.js +6 -0
- package/dist/main/lib/version.js.map +1 -0
- package/dist/main/utils/base64url.d.ts +75 -0
- package/dist/main/utils/base64url.d.ts.map +1 -0
- package/dist/main/utils/base64url.js +270 -0
- package/dist/main/utils/base64url.js.map +1 -0
- package/dist/main/utils/constants.d.ts +26 -0
- package/dist/main/utils/constants.d.ts.map +1 -0
- package/dist/main/utils/constants.js +31 -0
- package/dist/main/utils/constants.js.map +1 -0
- package/dist/main/utils/error-codes.d.ts +7 -0
- package/dist/main/utils/error-codes.d.ts.map +1 -0
- package/dist/main/utils/error-codes.js +3 -0
- package/dist/main/utils/error-codes.js.map +1 -0
- package/dist/main/utils/errors.d.ts +100 -0
- package/dist/main/utils/errors.d.ts.map +1 -0
- package/dist/main/utils/errors.js +137 -0
- package/dist/main/utils/errors.js.map +1 -0
- package/dist/main/utils/fetch.d.ts +34 -0
- package/dist/main/utils/fetch.d.ts.map +1 -0
- package/dist/main/utils/fetch.js +195 -0
- package/dist/main/utils/fetch.js.map +1 -0
- package/dist/main/utils/helpers.d.ts +59 -0
- package/dist/main/utils/helpers.d.ts.map +1 -0
- package/dist/main/utils/helpers.js +334 -0
- package/dist/main/utils/helpers.js.map +1 -0
- package/dist/main/utils/local-storage.d.ts +13 -0
- package/dist/main/utils/local-storage.d.ts.map +1 -0
- package/dist/main/utils/local-storage.js +46 -0
- package/dist/main/utils/local-storage.js.map +1 -0
- package/dist/main/utils/locks.d.ts +64 -0
- package/dist/main/utils/locks.d.ts.map +1 -0
- package/dist/main/utils/locks.js +187 -0
- package/dist/main/utils/locks.js.map +1 -0
- package/dist/main/utils/polyfills.d.ts +5 -0
- package/dist/main/utils/polyfills.d.ts.map +1 -0
- package/dist/main/utils/polyfills.js +30 -0
- package/dist/main/utils/polyfills.js.map +1 -0
- package/dist/main/utils/types.d.ts +1074 -0
- package/dist/main/utils/types.d.ts.map +1 -0
- package/dist/main/utils/types.js +3 -0
- package/dist/main/utils/types.js.map +1 -0
- package/dist/main/utils/version.d.ts +2 -0
- package/dist/main/utils/version.d.ts.map +1 -0
- package/dist/main/utils/version.js +6 -0
- package/dist/main/utils/version.js.map +1 -0
- package/dist/module/AuthAdminApi.d.ts +4 -0
- package/dist/module/AuthAdminApi.d.ts.map +1 -0
- package/dist/module/AuthAdminApi.js +4 -0
- package/dist/module/AuthAdminApi.js.map +1 -0
- package/dist/module/AuthClient.d.ts +4 -0
- package/dist/module/AuthClient.d.ts.map +1 -0
- package/dist/module/AuthClient.js +4 -0
- package/dist/module/AuthClient.js.map +1 -0
- package/dist/module/GoTrueAdminApi.d.ts +99 -0
- package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
- package/dist/module/GoTrueAdminApi.js +265 -0
- package/dist/module/GoTrueAdminApi.js.map +1 -0
- package/dist/module/GoTrueClient.d.ts +492 -0
- package/dist/module/GoTrueClient.d.ts.map +1 -0
- package/dist/module/GoTrueClient.js +2221 -0
- package/dist/module/GoTrueClient.js.map +1 -0
- package/dist/module/index.d.ts +9 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +9 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/lib/version.d.ts +2 -0
- package/dist/module/lib/version.d.ts.map +1 -0
- package/dist/module/lib/version.js +3 -0
- package/dist/module/lib/version.js.map +1 -0
- package/dist/module/utils/base64url.d.ts +75 -0
- package/dist/module/utils/base64url.d.ts.map +1 -0
- package/dist/module/utils/base64url.js +257 -0
- package/dist/module/utils/base64url.js.map +1 -0
- package/dist/module/utils/constants.d.ts +26 -0
- package/dist/module/utils/constants.d.ts.map +1 -0
- package/dist/module/utils/constants.js +28 -0
- package/dist/module/utils/constants.js.map +1 -0
- package/dist/module/utils/error-codes.d.ts +7 -0
- package/dist/module/utils/error-codes.d.ts.map +1 -0
- package/dist/module/utils/error-codes.js +2 -0
- package/dist/module/utils/error-codes.js.map +1 -0
- package/dist/module/utils/errors.d.ts +100 -0
- package/dist/module/utils/errors.d.ts.map +1 -0
- package/dist/module/utils/errors.js +116 -0
- package/dist/module/utils/errors.js.map +1 -0
- package/dist/module/utils/fetch.d.ts +34 -0
- package/dist/module/utils/fetch.d.ts.map +1 -0
- package/dist/module/utils/fetch.js +184 -0
- package/dist/module/utils/fetch.js.map +1 -0
- package/dist/module/utils/helpers.d.ts +59 -0
- package/dist/module/utils/helpers.d.ts.map +1 -0
- package/dist/module/utils/helpers.js +288 -0
- package/dist/module/utils/helpers.js.map +1 -0
- package/dist/module/utils/local-storage.d.ts +13 -0
- package/dist/module/utils/local-storage.d.ts.map +1 -0
- package/dist/module/utils/local-storage.js +42 -0
- package/dist/module/utils/local-storage.js.map +1 -0
- package/dist/module/utils/locks.d.ts +64 -0
- package/dist/module/utils/locks.d.ts.map +1 -0
- package/dist/module/utils/locks.js +179 -0
- package/dist/module/utils/locks.js.map +1 -0
- package/dist/module/utils/polyfills.d.ts +5 -0
- package/dist/module/utils/polyfills.d.ts.map +1 -0
- package/dist/module/utils/polyfills.js +26 -0
- package/dist/module/utils/polyfills.js.map +1 -0
- package/dist/module/utils/types.d.ts +1074 -0
- package/dist/module/utils/types.d.ts.map +1 -0
- package/dist/module/utils/types.js +2 -0
- package/dist/module/utils/types.js.map +1 -0
- package/dist/module/utils/version.d.ts +2 -0
- package/dist/module/utils/version.d.ts.map +1 -0
- package/dist/module/utils/version.js +3 -0
- package/dist/module/utils/version.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
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;
|
|
27
|
+
const constants_1 = require("./constants");
|
|
28
|
+
const errors_1 = require("./errors");
|
|
29
|
+
const base64url_1 = require("./base64url");
|
|
30
|
+
function expiresAt(expiresIn) {
|
|
31
|
+
const timeNow = Math.round(Date.now() / 1000);
|
|
32
|
+
return timeNow + expiresIn;
|
|
33
|
+
}
|
|
34
|
+
exports.expiresAt = expiresAt;
|
|
35
|
+
function uuid() {
|
|
36
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
37
|
+
const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
38
|
+
return v.toString(16);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.uuid = uuid;
|
|
42
|
+
const isBrowser = () => typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
43
|
+
exports.isBrowser = isBrowser;
|
|
44
|
+
const localStorageWriteTests = {
|
|
45
|
+
tested: false,
|
|
46
|
+
writable: false,
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether localStorage is supported on this browser.
|
|
50
|
+
*/
|
|
51
|
+
const supportsLocalStorage = () => {
|
|
52
|
+
if (!(0, exports.isBrowser)()) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
if (typeof globalThis.localStorage !== 'object') {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
// DOM exception when accessing `localStorage`
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (localStorageWriteTests.tested) {
|
|
65
|
+
return localStorageWriteTests.writable;
|
|
66
|
+
}
|
|
67
|
+
const randomKey = `lswt-${Math.random()}${Math.random()}`;
|
|
68
|
+
try {
|
|
69
|
+
globalThis.localStorage.setItem(randomKey, randomKey);
|
|
70
|
+
globalThis.localStorage.removeItem(randomKey);
|
|
71
|
+
localStorageWriteTests.tested = true;
|
|
72
|
+
localStorageWriteTests.writable = true;
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
// localStorage can't be written to
|
|
76
|
+
// 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
|
|
77
|
+
localStorageWriteTests.tested = true;
|
|
78
|
+
localStorageWriteTests.writable = false;
|
|
79
|
+
}
|
|
80
|
+
return localStorageWriteTests.writable;
|
|
81
|
+
};
|
|
82
|
+
exports.supportsLocalStorage = supportsLocalStorage;
|
|
83
|
+
/**
|
|
84
|
+
* Extracts parameters encoded in the URL both in the query and fragment.
|
|
85
|
+
*/
|
|
86
|
+
function parseParametersFromURL(href) {
|
|
87
|
+
const result = {};
|
|
88
|
+
const url = new URL(href);
|
|
89
|
+
if (url.hash && url.hash[0] === '#') {
|
|
90
|
+
try {
|
|
91
|
+
const hashSearchParams = new URLSearchParams(url.hash.substring(1));
|
|
92
|
+
hashSearchParams.forEach((value, key) => {
|
|
93
|
+
result[key] = value;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
// hash is not a query string
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// search parameters take precedence over hash parameters
|
|
101
|
+
url.searchParams.forEach((value, key) => {
|
|
102
|
+
result[key] = value;
|
|
103
|
+
});
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
exports.parseParametersFromURL = parseParametersFromURL;
|
|
107
|
+
const resolveFetch = (customFetch) => {
|
|
108
|
+
let _fetch;
|
|
109
|
+
if (customFetch) {
|
|
110
|
+
_fetch = customFetch;
|
|
111
|
+
}
|
|
112
|
+
else if (typeof fetch === 'undefined') {
|
|
113
|
+
_fetch = (...args) => { var _a; return (_a = '@data-loom/node-fetch', Promise.resolve().then(() => __importStar(require(_a)))).then(({ default: fetch }) => fetch(...args)); };
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
_fetch = fetch;
|
|
117
|
+
}
|
|
118
|
+
return (...args) => _fetch(...args);
|
|
119
|
+
};
|
|
120
|
+
exports.resolveFetch = resolveFetch;
|
|
121
|
+
const looksLikeFetchResponse = (maybeResponse) => {
|
|
122
|
+
return (typeof maybeResponse === 'object' &&
|
|
123
|
+
maybeResponse !== null &&
|
|
124
|
+
'status' in maybeResponse &&
|
|
125
|
+
'ok' in maybeResponse &&
|
|
126
|
+
'json' in maybeResponse &&
|
|
127
|
+
typeof maybeResponse.json === 'function');
|
|
128
|
+
};
|
|
129
|
+
exports.looksLikeFetchResponse = looksLikeFetchResponse;
|
|
130
|
+
// Storage helpers
|
|
131
|
+
const setItemAsync = async (storage, key, data) => {
|
|
132
|
+
await storage.setItem(key, JSON.stringify(data));
|
|
133
|
+
};
|
|
134
|
+
exports.setItemAsync = setItemAsync;
|
|
135
|
+
const getItemAsync = async (storage, key) => {
|
|
136
|
+
const value = await storage.getItem(key);
|
|
137
|
+
if (!value) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(value);
|
|
142
|
+
}
|
|
143
|
+
catch (_a) {
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
exports.getItemAsync = getItemAsync;
|
|
148
|
+
const removeItemAsync = async (storage, key) => {
|
|
149
|
+
await storage.removeItem(key);
|
|
150
|
+
};
|
|
151
|
+
exports.removeItemAsync = removeItemAsync;
|
|
152
|
+
/**
|
|
153
|
+
* A deferred represents some asynchronous work that is not yet finished, which
|
|
154
|
+
* may or may not culminate in a value.
|
|
155
|
+
* Taken from: https://github.com/mike-north/types/blob/master/src/async.ts
|
|
156
|
+
*/
|
|
157
|
+
class Deferred {
|
|
158
|
+
constructor() {
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
160
|
+
;
|
|
161
|
+
this.promise = new Deferred.promiseConstructor((res, rej) => {
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
163
|
+
;
|
|
164
|
+
this.resolve = res;
|
|
165
|
+
this.reject = rej;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.Deferred = Deferred;
|
|
170
|
+
Deferred.promiseConstructor = Promise;
|
|
171
|
+
function decodeJWT(token) {
|
|
172
|
+
const parts = token.split('.');
|
|
173
|
+
if (parts.length !== 3) {
|
|
174
|
+
throw new errors_1.AuthInvalidJwtError('Invalid JWT structure');
|
|
175
|
+
}
|
|
176
|
+
// Regex checks for base64url format
|
|
177
|
+
for (let i = 0; i < parts.length; i++) {
|
|
178
|
+
if (!constants_1.BASE64URL_REGEX.test(parts[i])) {
|
|
179
|
+
throw new errors_1.AuthInvalidJwtError('JWT not in base64url format');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const data = {
|
|
183
|
+
// using base64url lib
|
|
184
|
+
header: JSON.parse((0, base64url_1.stringFromBase64URL)(parts[0])),
|
|
185
|
+
payload: JSON.parse((0, base64url_1.stringFromBase64URL)(parts[1])),
|
|
186
|
+
signature: (0, base64url_1.base64UrlToUint8Array)(parts[2]),
|
|
187
|
+
raw: {
|
|
188
|
+
header: parts[0],
|
|
189
|
+
payload: parts[1],
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
return data;
|
|
193
|
+
}
|
|
194
|
+
exports.decodeJWT = decodeJWT;
|
|
195
|
+
/**
|
|
196
|
+
* Creates a promise that resolves to null after some time.
|
|
197
|
+
*/
|
|
198
|
+
async function sleep(time) {
|
|
199
|
+
return await new Promise((accept) => {
|
|
200
|
+
setTimeout(() => accept(null), time);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
exports.sleep = sleep;
|
|
204
|
+
/**
|
|
205
|
+
* Converts the provided async function into a retryable function. Each result
|
|
206
|
+
* or thrown error is sent to the isRetryable function which should return true
|
|
207
|
+
* if the function should run again.
|
|
208
|
+
*/
|
|
209
|
+
function retryable(fn, isRetryable) {
|
|
210
|
+
const promise = new Promise((accept, reject) => {
|
|
211
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
212
|
+
;
|
|
213
|
+
(async () => {
|
|
214
|
+
for (let attempt = 0; attempt < Infinity; attempt++) {
|
|
215
|
+
try {
|
|
216
|
+
const result = await fn(attempt);
|
|
217
|
+
if (!isRetryable(attempt, null, result)) {
|
|
218
|
+
accept(result);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
if (!isRetryable(attempt, e)) {
|
|
224
|
+
reject(e);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
})();
|
|
230
|
+
});
|
|
231
|
+
return promise;
|
|
232
|
+
}
|
|
233
|
+
exports.retryable = retryable;
|
|
234
|
+
function dec2hex(dec) {
|
|
235
|
+
return ('0' + dec.toString(16)).substr(-2);
|
|
236
|
+
}
|
|
237
|
+
// Functions below taken from: https://stackoverflow.com/questions/63309409/creating-a-code-verifier-and-challenge-for-pkce-auth-on-spotify-api-in-reactjs
|
|
238
|
+
function generatePKCEVerifier() {
|
|
239
|
+
const verifierLength = 56;
|
|
240
|
+
const array = new Uint32Array(verifierLength);
|
|
241
|
+
if (typeof crypto === 'undefined') {
|
|
242
|
+
const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
|
|
243
|
+
const charSetLen = charSet.length;
|
|
244
|
+
let verifier = '';
|
|
245
|
+
for (let i = 0; i < verifierLength; i++) {
|
|
246
|
+
verifier += charSet.charAt(Math.floor(Math.random() * charSetLen));
|
|
247
|
+
}
|
|
248
|
+
return verifier;
|
|
249
|
+
}
|
|
250
|
+
crypto.getRandomValues(array);
|
|
251
|
+
return Array.from(array, dec2hex).join('');
|
|
252
|
+
}
|
|
253
|
+
exports.generatePKCEVerifier = generatePKCEVerifier;
|
|
254
|
+
async function sha256(randomString) {
|
|
255
|
+
const encoder = new TextEncoder();
|
|
256
|
+
const encodedData = encoder.encode(randomString);
|
|
257
|
+
const hash = await crypto.subtle.digest('SHA-256', encodedData);
|
|
258
|
+
const bytes = new Uint8Array(hash);
|
|
259
|
+
return Array.from(bytes)
|
|
260
|
+
.map((c) => String.fromCharCode(c))
|
|
261
|
+
.join('');
|
|
262
|
+
}
|
|
263
|
+
async function generatePKCEChallenge(verifier) {
|
|
264
|
+
const hasCryptoSupport = typeof crypto !== 'undefined' &&
|
|
265
|
+
typeof crypto.subtle !== 'undefined' &&
|
|
266
|
+
typeof TextEncoder !== 'undefined';
|
|
267
|
+
if (!hasCryptoSupport) {
|
|
268
|
+
console.warn('WebCrypto API is not supported. Code challenge method will default to use plain instead of sha256.');
|
|
269
|
+
return verifier;
|
|
270
|
+
}
|
|
271
|
+
const hashed = await sha256(verifier);
|
|
272
|
+
return btoa(hashed).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
273
|
+
}
|
|
274
|
+
exports.generatePKCEChallenge = generatePKCEChallenge;
|
|
275
|
+
async function getCodeChallengeAndMethod(storage, storageKey, isPasswordRecovery = false) {
|
|
276
|
+
const codeVerifier = generatePKCEVerifier();
|
|
277
|
+
let storedCodeVerifier = codeVerifier;
|
|
278
|
+
if (isPasswordRecovery) {
|
|
279
|
+
storedCodeVerifier += '/PASSWORD_RECOVERY';
|
|
280
|
+
}
|
|
281
|
+
await (0, exports.setItemAsync)(storage, `${storageKey}-code-verifier`, storedCodeVerifier);
|
|
282
|
+
const codeChallenge = await generatePKCEChallenge(codeVerifier);
|
|
283
|
+
const codeChallengeMethod = codeVerifier === codeChallenge ? 'plain' : 's256';
|
|
284
|
+
return [codeChallenge, codeChallengeMethod];
|
|
285
|
+
}
|
|
286
|
+
exports.getCodeChallengeAndMethod = getCodeChallengeAndMethod;
|
|
287
|
+
/** Parses the API version which is 2YYY-MM-DD. */
|
|
288
|
+
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;
|
|
289
|
+
function parseResponseAPIVersion(response) {
|
|
290
|
+
const apiVersion = response.headers.get(constants_1.API_VERSION_HEADER_NAME);
|
|
291
|
+
if (!apiVersion) {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
if (!apiVersion.match(API_VERSION_REGEX)) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
const date = new Date(`${apiVersion}T00:00:00.0Z`);
|
|
299
|
+
return date;
|
|
300
|
+
}
|
|
301
|
+
catch (e) {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
exports.parseResponseAPIVersion = parseResponseAPIVersion;
|
|
306
|
+
function validateExp(exp) {
|
|
307
|
+
if (!exp) {
|
|
308
|
+
throw new Error('Missing exp claim');
|
|
309
|
+
}
|
|
310
|
+
const timeNow = Math.floor(Date.now() / 1000);
|
|
311
|
+
if (exp <= timeNow) {
|
|
312
|
+
throw new Error('JWT has expired');
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
exports.validateExp = validateExp;
|
|
316
|
+
function getAlgorithm(alg) {
|
|
317
|
+
switch (alg) {
|
|
318
|
+
case 'RS256':
|
|
319
|
+
return {
|
|
320
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
321
|
+
hash: { name: 'SHA-256' },
|
|
322
|
+
};
|
|
323
|
+
case 'ES256':
|
|
324
|
+
return {
|
|
325
|
+
name: 'ECDSA',
|
|
326
|
+
namedCurve: 'P-256',
|
|
327
|
+
hash: { name: 'SHA-256' },
|
|
328
|
+
};
|
|
329
|
+
default:
|
|
330
|
+
throw new Error('Invalid alg claim');
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
exports.getAlgorithm = getAlgorithm;
|
|
334
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAsE;AACtE,qCAA8C;AAC9C,2CAA2F;AAG3F,SAAgB,SAAS,CAAC,SAAiB;IACzC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IAC7C,OAAO,OAAO,GAAG,SAAS,CAAA;AAC5B,CAAC;AAHD,8BAGC;AAED,SAAgB,IAAI;IAClB,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC;QACxE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAChC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;QACpC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC;AAND,oBAMC;AAEM,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,CAAA;AAAlF,QAAA,SAAS,aAAyE;AAE/F,MAAM,sBAAsB,GAAG;IAC7B,MAAM,EAAE,KAAK;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CAAC,GAAW;IACrC,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACrC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IAC7C,IAAI,GAAG,IAAI,OAAO,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;KACnC;AACH,CAAC;AARD,kCAQC;AAED,SAAgB,YAAY,CAAC,GAAsB;IACjD,QAAQ,GAAG,EAAE;QACX,KAAK,OAAO;YACV,OAAO;gBACL,IAAI,EAAE,mBAAmB;gBACzB,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;aAC1B,CAAA;QACH,KAAK,OAAO;YACV,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,UAAU,EAAE,OAAO;gBACnB,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;aAC1B,CAAA;QACH;YACE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACvC;AACH,CAAC;AAhBD,oCAgBC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SupportedStorage } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Provides safe access to the globalThis.localStorage property.
|
|
4
|
+
*/
|
|
5
|
+
export declare const localStorageAdapter: SupportedStorage;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a localStorage-like object that stores the key-value pairs in
|
|
8
|
+
* memory.
|
|
9
|
+
*/
|
|
10
|
+
export declare function memoryLocalStorageAdapter(store?: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
}): SupportedStorage;
|
|
13
|
+
//# sourceMappingURL=local-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../../src/utils/local-storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAsBjC,CAAA;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,GAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAO,GAAG,gBAAgB,CAcjG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.memoryLocalStorageAdapter = exports.localStorageAdapter = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
/**
|
|
6
|
+
* Provides safe access to the globalThis.localStorage property.
|
|
7
|
+
*/
|
|
8
|
+
exports.localStorageAdapter = {
|
|
9
|
+
getItem: (key) => {
|
|
10
|
+
if (!(0, helpers_1.supportsLocalStorage)()) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return globalThis.localStorage.getItem(key);
|
|
14
|
+
},
|
|
15
|
+
setItem: (key, value) => {
|
|
16
|
+
if (!(0, helpers_1.supportsLocalStorage)()) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
globalThis.localStorage.setItem(key, value);
|
|
20
|
+
},
|
|
21
|
+
removeItem: (key) => {
|
|
22
|
+
if (!(0, helpers_1.supportsLocalStorage)()) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
globalThis.localStorage.removeItem(key);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Returns a localStorage-like object that stores the key-value pairs in
|
|
30
|
+
* memory.
|
|
31
|
+
*/
|
|
32
|
+
function memoryLocalStorageAdapter(store = {}) {
|
|
33
|
+
return {
|
|
34
|
+
getItem: (key) => {
|
|
35
|
+
return store[key] || null;
|
|
36
|
+
},
|
|
37
|
+
setItem: (key, value) => {
|
|
38
|
+
store[key] = value;
|
|
39
|
+
},
|
|
40
|
+
removeItem: (key) => {
|
|
41
|
+
delete store[key];
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.memoryLocalStorageAdapter = memoryLocalStorageAdapter;
|
|
46
|
+
//# sourceMappingURL=local-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage.js","sourceRoot":"","sources":["../../../src/utils/local-storage.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAGhD;;GAEG;AACU,QAAA,mBAAmB,GAAqB;IACnD,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACf,IAAI,CAAC,IAAA,8BAAoB,GAAE,EAAE;YAC3B,OAAO,IAAI,CAAA;SACZ;QAED,OAAO,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC7C,CAAC;IACD,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACtB,IAAI,CAAC,IAAA,8BAAoB,GAAE,EAAE;YAC3B,OAAM;SACP;QAED,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC7C,CAAC;IACD,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;QAClB,IAAI,CAAC,IAAA,8BAAoB,GAAE,EAAE;YAC3B,OAAM;SACP;QAED,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;CACF,CAAA;AAED;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,QAAmC,EAAE;IAC7E,OAAO;QACL,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACf,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,CAAA;QAC3B,CAAC;QAED,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACtB,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACpB,CAAC;QAED,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;YAClB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC;KACF,CAAA;AACH,CAAC;AAdD,8DAcC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @experimental
|
|
3
|
+
*/
|
|
4
|
+
export declare const internals: {
|
|
5
|
+
/**
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
debug: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* An error thrown when a lock cannot be acquired after some amount of time.
|
|
12
|
+
*
|
|
13
|
+
* Use the {@link #isAcquireTimeout} property instead of checking with `instanceof`.
|
|
14
|
+
*/
|
|
15
|
+
export declare abstract class LockAcquireTimeoutError extends Error {
|
|
16
|
+
readonly isAcquireTimeout = true;
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
20
|
+
}
|
|
21
|
+
export declare class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Implements a global exclusive lock using the Navigator LockManager API. It
|
|
25
|
+
* is available on all browsers released after 2022-03-15 with Safari being the
|
|
26
|
+
* last one to release support. If the API is not available, this function will
|
|
27
|
+
* throw. Make sure you check availablility before configuring {@link
|
|
28
|
+
* GoTrueClient}.
|
|
29
|
+
*
|
|
30
|
+
* You can turn on debugging by setting the `supabase.gotrue-js.locks.debug`
|
|
31
|
+
* local storage item to `true`.
|
|
32
|
+
*
|
|
33
|
+
* Internals:
|
|
34
|
+
*
|
|
35
|
+
* Since the LockManager API does not preserve stack traces for the async
|
|
36
|
+
* function passed in the `request` method, a trick is used where acquiring the
|
|
37
|
+
* lock releases a previously started promise to run the operation in the `fn`
|
|
38
|
+
* function. The lock waits for that promise to finish (with or without error),
|
|
39
|
+
* while the function will finally wait for the result anyway.
|
|
40
|
+
*
|
|
41
|
+
* @param name Name of the lock to be acquired.
|
|
42
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
43
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
44
|
+
* will time out after so many milliseconds. An error is
|
|
45
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
46
|
+
* @param fn The operation to run once the lock is acquired.
|
|
47
|
+
*/
|
|
48
|
+
export declare function navigatorLock<R>(name: string, acquireTimeout: number, fn: () => Promise<R>): Promise<R>;
|
|
49
|
+
/**
|
|
50
|
+
* Implements a global exclusive lock that works only in the current process.
|
|
51
|
+
* Useful for environments like React Native or other non-browser
|
|
52
|
+
* single-process (i.e. no concept of "tabs") environments.
|
|
53
|
+
*
|
|
54
|
+
* Use {@link #navigatorLock} in browser environments.
|
|
55
|
+
*
|
|
56
|
+
* @param name Name of the lock to be acquired.
|
|
57
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
58
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
59
|
+
* will time out after so many milliseconds. An error is
|
|
60
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
61
|
+
* @param fn The operation to run once the lock is acquired.
|
|
62
|
+
*/
|
|
63
|
+
export declare function processLock<R>(name: string, acquireTimeout: number, fn: () => Promise<R>): Promise<R>;
|
|
64
|
+
//# sourceMappingURL=locks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../../src/utils/locks.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS;IACpB;;OAEG;;CAOJ,CAAA;AAED;;;;GAIG;AACH,8BAAsB,uBAAwB,SAAQ,KAAK;IACzD,SAAgB,gBAAgB,QAAO;gBAE3B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,gCAAiC,SAAQ,uBAAuB;CAAG;AAChF,qBAAa,8BAA+B,SAAQ,uBAAuB;CAAG;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CA0FZ;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAkDZ"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processLock = exports.navigatorLock = exports.ProcessLockAcquireTimeoutError = exports.NavigatorLockAcquireTimeoutError = exports.LockAcquireTimeoutError = exports.internals = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
/**
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
exports.internals = {
|
|
9
|
+
/**
|
|
10
|
+
* @experimental
|
|
11
|
+
*/
|
|
12
|
+
debug: !!(globalThis &&
|
|
13
|
+
(0, helpers_1.supportsLocalStorage)() &&
|
|
14
|
+
globalThis.localStorage &&
|
|
15
|
+
globalThis.localStorage.getItem('supabase.gotrue-js.locks.debug') === 'true'),
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* An error thrown when a lock cannot be acquired after some amount of time.
|
|
19
|
+
*
|
|
20
|
+
* Use the {@link #isAcquireTimeout} property instead of checking with `instanceof`.
|
|
21
|
+
*/
|
|
22
|
+
class LockAcquireTimeoutError extends Error {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.isAcquireTimeout = true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.LockAcquireTimeoutError = LockAcquireTimeoutError;
|
|
29
|
+
class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
30
|
+
}
|
|
31
|
+
exports.NavigatorLockAcquireTimeoutError = NavigatorLockAcquireTimeoutError;
|
|
32
|
+
class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {
|
|
33
|
+
}
|
|
34
|
+
exports.ProcessLockAcquireTimeoutError = ProcessLockAcquireTimeoutError;
|
|
35
|
+
/**
|
|
36
|
+
* Implements a global exclusive lock using the Navigator LockManager API. It
|
|
37
|
+
* is available on all browsers released after 2022-03-15 with Safari being the
|
|
38
|
+
* last one to release support. If the API is not available, this function will
|
|
39
|
+
* throw. Make sure you check availablility before configuring {@link
|
|
40
|
+
* GoTrueClient}.
|
|
41
|
+
*
|
|
42
|
+
* You can turn on debugging by setting the `supabase.gotrue-js.locks.debug`
|
|
43
|
+
* local storage item to `true`.
|
|
44
|
+
*
|
|
45
|
+
* Internals:
|
|
46
|
+
*
|
|
47
|
+
* Since the LockManager API does not preserve stack traces for the async
|
|
48
|
+
* function passed in the `request` method, a trick is used where acquiring the
|
|
49
|
+
* lock releases a previously started promise to run the operation in the `fn`
|
|
50
|
+
* function. The lock waits for that promise to finish (with or without error),
|
|
51
|
+
* while the function will finally wait for the result anyway.
|
|
52
|
+
*
|
|
53
|
+
* @param name Name of the lock to be acquired.
|
|
54
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
55
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
56
|
+
* will time out after so many milliseconds. An error is
|
|
57
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
58
|
+
* @param fn The operation to run once the lock is acquired.
|
|
59
|
+
*/
|
|
60
|
+
async function navigatorLock(name, acquireTimeout, fn) {
|
|
61
|
+
if (exports.internals.debug) {
|
|
62
|
+
console.log('@supabase/gotrue-js: navigatorLock: acquire lock', name, acquireTimeout);
|
|
63
|
+
}
|
|
64
|
+
const abortController = new globalThis.AbortController();
|
|
65
|
+
if (acquireTimeout > 0) {
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
abortController.abort();
|
|
68
|
+
if (exports.internals.debug) {
|
|
69
|
+
console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name);
|
|
70
|
+
}
|
|
71
|
+
}, acquireTimeout);
|
|
72
|
+
}
|
|
73
|
+
// MDN article: https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request
|
|
74
|
+
// Wrapping navigator.locks.request() with a plain Promise is done as some
|
|
75
|
+
// libraries like zone.js patch the Promise object to track the execution
|
|
76
|
+
// context. However, it appears that most browsers use an internal promise
|
|
77
|
+
// implementation when using the navigator.locks.request() API causing them
|
|
78
|
+
// to lose context and emit confusing log messages or break certain features.
|
|
79
|
+
// This wrapping is believed to help zone.js track the execution context
|
|
80
|
+
// better.
|
|
81
|
+
return await Promise.resolve().then(() => globalThis.navigator.locks.request(name, acquireTimeout === 0
|
|
82
|
+
? {
|
|
83
|
+
mode: 'exclusive',
|
|
84
|
+
ifAvailable: true,
|
|
85
|
+
}
|
|
86
|
+
: {
|
|
87
|
+
mode: 'exclusive',
|
|
88
|
+
signal: abortController.signal,
|
|
89
|
+
}, async (lock) => {
|
|
90
|
+
if (lock) {
|
|
91
|
+
if (exports.internals.debug) {
|
|
92
|
+
console.log('@supabase/gotrue-js: navigatorLock: acquired', name, lock.name);
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
return await fn();
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
if (exports.internals.debug) {
|
|
99
|
+
console.log('@supabase/gotrue-js: navigatorLock: released', name, lock.name);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (acquireTimeout === 0) {
|
|
105
|
+
if (exports.internals.debug) {
|
|
106
|
+
console.log('@supabase/gotrue-js: navigatorLock: not immediately available', name);
|
|
107
|
+
}
|
|
108
|
+
throw new NavigatorLockAcquireTimeoutError(`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
if (exports.internals.debug) {
|
|
112
|
+
try {
|
|
113
|
+
const result = await globalThis.navigator.locks.query();
|
|
114
|
+
console.log('@supabase/gotrue-js: Navigator LockManager state', JSON.stringify(result, null, ' '));
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
console.warn('@supabase/gotrue-js: Error when querying Navigator LockManager state', e);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Browser is not following the Navigator LockManager spec, it
|
|
121
|
+
// returned a null lock when we didn't use ifAvailable. So we can
|
|
122
|
+
// pretend the lock is acquired in the name of backward compatibility
|
|
123
|
+
// and user experience and just run the function.
|
|
124
|
+
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');
|
|
125
|
+
return await fn();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
exports.navigatorLock = navigatorLock;
|
|
131
|
+
const PROCESS_LOCKS = {};
|
|
132
|
+
/**
|
|
133
|
+
* Implements a global exclusive lock that works only in the current process.
|
|
134
|
+
* Useful for environments like React Native or other non-browser
|
|
135
|
+
* single-process (i.e. no concept of "tabs") environments.
|
|
136
|
+
*
|
|
137
|
+
* Use {@link #navigatorLock} in browser environments.
|
|
138
|
+
*
|
|
139
|
+
* @param name Name of the lock to be acquired.
|
|
140
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
141
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
142
|
+
* will time out after so many milliseconds. An error is
|
|
143
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
144
|
+
* @param fn The operation to run once the lock is acquired.
|
|
145
|
+
*/
|
|
146
|
+
async function processLock(name, acquireTimeout, fn) {
|
|
147
|
+
var _a;
|
|
148
|
+
const previousOperation = (_a = PROCESS_LOCKS[name]) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
149
|
+
const currentOperation = Promise.race([
|
|
150
|
+
previousOperation.catch(() => {
|
|
151
|
+
// ignore error of previous operation that we're waiting to finish
|
|
152
|
+
return null;
|
|
153
|
+
}),
|
|
154
|
+
acquireTimeout >= 0
|
|
155
|
+
? new Promise((_, reject) => {
|
|
156
|
+
setTimeout(() => {
|
|
157
|
+
reject(new ProcessLockAcquireTimeoutError(`Acquring process lock with name "${name}" timed out`));
|
|
158
|
+
}, acquireTimeout);
|
|
159
|
+
})
|
|
160
|
+
: null,
|
|
161
|
+
].filter((x) => x))
|
|
162
|
+
.catch((e) => {
|
|
163
|
+
if (e && e.isAcquireTimeout) {
|
|
164
|
+
throw e;
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
})
|
|
168
|
+
.then(async () => {
|
|
169
|
+
// previous operations finished and we didn't get a race on the acquire
|
|
170
|
+
// timeout, so the current operation can finally start
|
|
171
|
+
return await fn();
|
|
172
|
+
});
|
|
173
|
+
PROCESS_LOCKS[name] = currentOperation.catch(async (e) => {
|
|
174
|
+
if (e && e.isAcquireTimeout) {
|
|
175
|
+
// if the current operation timed out, it doesn't mean that the previous
|
|
176
|
+
// operation finished, so we need contnue waiting for it to finish
|
|
177
|
+
await previousOperation;
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
throw e;
|
|
181
|
+
});
|
|
182
|
+
// finally wait for the current operation to finish successfully, with an
|
|
183
|
+
// error or with an acquire timeout error
|
|
184
|
+
return await currentOperation;
|
|
185
|
+
}
|
|
186
|
+
exports.processLock = processLock;
|
|
187
|
+
//# sourceMappingURL=locks.js.map
|