@supabase/auth-js 2.61.0
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/LICENSE +21 -0
- package/README.md +50 -0
- 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 +432 -0
- package/dist/main/GoTrueClient.d.ts.map +1 -0
- package/dist/main/GoTrueClient.js +1889 -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/constants.d.ts +12 -0
- package/dist/main/lib/constants.d.ts.map +1 -0
- package/dist/main/lib/constants.js +14 -0
- package/dist/main/lib/constants.js.map +1 -0
- package/dist/main/lib/errors.d.ts +96 -0
- package/dist/main/lib/errors.d.ts.map +1 -0
- package/dist/main/lib/errors.js +135 -0
- package/dist/main/lib/errors.js.map +1 -0
- package/dist/main/lib/fetch.d.ts +33 -0
- package/dist/main/lib/fetch.d.ts.map +1 -0
- package/dist/main/lib/fetch.js +162 -0
- package/dist/main/lib/fetch.js.map +1 -0
- package/dist/main/lib/helpers.d.ts +48 -0
- package/dist/main/lib/helpers.d.ts.map +1 -0
- package/dist/main/lib/helpers.js +292 -0
- package/dist/main/lib/helpers.js.map +1 -0
- package/dist/main/lib/local-storage.d.ts +13 -0
- package/dist/main/lib/local-storage.d.ts.map +1 -0
- package/dist/main/lib/local-storage.js +46 -0
- package/dist/main/lib/local-storage.js.map +1 -0
- package/dist/main/lib/locks.d.ts +44 -0
- package/dist/main/lib/locks.d.ts.map +1 -0
- package/dist/main/lib/locks.js +118 -0
- package/dist/main/lib/locks.js.map +1 -0
- package/dist/main/lib/polyfills.d.ts +5 -0
- package/dist/main/lib/polyfills.d.ts.map +1 -0
- package/dist/main/lib/polyfills.js +30 -0
- package/dist/main/lib/polyfills.js.map +1 -0
- package/dist/main/lib/types.d.ts +948 -0
- package/dist/main/lib/types.d.ts.map +1 -0
- package/dist/main/lib/types.js +3 -0
- package/dist/main/lib/types.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/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 +432 -0
- package/dist/module/GoTrueClient.d.ts.map +1 -0
- package/dist/module/GoTrueClient.js +1883 -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/constants.d.ts +12 -0
- package/dist/module/lib/constants.d.ts.map +1 -0
- package/dist/module/lib/constants.js +11 -0
- package/dist/module/lib/constants.js.map +1 -0
- package/dist/module/lib/errors.d.ts +96 -0
- package/dist/module/lib/errors.d.ts.map +1 -0
- package/dist/module/lib/errors.js +117 -0
- package/dist/module/lib/errors.js.map +1 -0
- package/dist/module/lib/fetch.d.ts +33 -0
- package/dist/module/lib/fetch.d.ts.map +1 -0
- package/dist/module/lib/fetch.js +152 -0
- package/dist/module/lib/fetch.js.map +1 -0
- package/dist/module/lib/helpers.d.ts +48 -0
- package/dist/module/lib/helpers.d.ts.map +1 -0
- package/dist/module/lib/helpers.js +249 -0
- package/dist/module/lib/helpers.js.map +1 -0
- package/dist/module/lib/local-storage.d.ts +13 -0
- package/dist/module/lib/local-storage.d.ts.map +1 -0
- package/dist/module/lib/local-storage.js +42 -0
- package/dist/module/lib/local-storage.js.map +1 -0
- package/dist/module/lib/locks.d.ts +44 -0
- package/dist/module/lib/locks.d.ts.map +1 -0
- package/dist/module/lib/locks.js +112 -0
- package/dist/module/lib/locks.js.map +1 -0
- package/dist/module/lib/polyfills.d.ts +5 -0
- package/dist/module/lib/polyfills.d.ts.map +1 -0
- package/dist/module/lib/polyfills.js +26 -0
- package/dist/module/lib/polyfills.js.map +1 -0
- package/dist/module/lib/types.d.ts +948 -0
- package/dist/module/lib/types.d.ts.map +1 -0
- package/dist/module/lib/types.js +2 -0
- package/dist/module/lib/types.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/package.json +69 -0
- package/src/AuthAdminApi.ts +5 -0
- package/src/AuthClient.ts +5 -0
- package/src/GoTrueAdminApi.ts +333 -0
- package/src/GoTrueClient.ts +2470 -0
- package/src/index.ts +12 -0
- package/src/lib/constants.ts +10 -0
- package/src/lib/errors.ts +150 -0
- package/src/lib/fetch.ts +238 -0
- package/src/lib/helpers.ts +306 -0
- package/src/lib/local-storage.ts +49 -0
- package/src/lib/locks.ts +140 -0
- package/src/lib/polyfills.ts +23 -0
- package/src/lib/types.ts +1120 -0
- package/src/lib/version.ts +2 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { supportsLocalStorage } from './helpers'
|
|
2
|
+
import { SupportedStorage } from './types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Provides safe access to the globalThis.localStorage property.
|
|
6
|
+
*/
|
|
7
|
+
export const localStorageAdapter: SupportedStorage = {
|
|
8
|
+
getItem: (key) => {
|
|
9
|
+
if (!supportsLocalStorage()) {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return globalThis.localStorage.getItem(key)
|
|
14
|
+
},
|
|
15
|
+
setItem: (key, value) => {
|
|
16
|
+
if (!supportsLocalStorage()) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
globalThis.localStorage.setItem(key, value)
|
|
21
|
+
},
|
|
22
|
+
removeItem: (key) => {
|
|
23
|
+
if (!supportsLocalStorage()) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
globalThis.localStorage.removeItem(key)
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns a localStorage-like object that stores the key-value pairs in
|
|
33
|
+
* memory.
|
|
34
|
+
*/
|
|
35
|
+
export function memoryLocalStorageAdapter(store: { [key: string]: string } = {}): SupportedStorage {
|
|
36
|
+
return {
|
|
37
|
+
getItem: (key) => {
|
|
38
|
+
return store[key] || null
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
setItem: (key, value) => {
|
|
42
|
+
store[key] = value
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
removeItem: (key) => {
|
|
46
|
+
delete store[key]
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/lib/locks.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { supportsLocalStorage } from './helpers'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @experimental
|
|
5
|
+
*/
|
|
6
|
+
export const internals = {
|
|
7
|
+
/**
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
debug: !!(
|
|
11
|
+
globalThis &&
|
|
12
|
+
supportsLocalStorage() &&
|
|
13
|
+
globalThis.localStorage &&
|
|
14
|
+
globalThis.localStorage.getItem('supabase.gotrue-js.locks.debug') === 'true'
|
|
15
|
+
),
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export abstract class LockAcquireTimeoutError extends Error {
|
|
19
|
+
public readonly isAcquireTimeout = true
|
|
20
|
+
|
|
21
|
+
constructor(message: string) {
|
|
22
|
+
super(message)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Implements a global exclusive lock using the Navigator LockManager API. It
|
|
30
|
+
* is available on all browsers released after 2022-03-15 with Safari being the
|
|
31
|
+
* last one to release support. If the API is not available, this function will
|
|
32
|
+
* throw. Make sure you check availablility before configuring {@link
|
|
33
|
+
* GoTrueClient}.
|
|
34
|
+
*
|
|
35
|
+
* You can turn on debugging by setting the `supabase.gotrue-js.locks.debug`
|
|
36
|
+
* local storage item to `true`.
|
|
37
|
+
*
|
|
38
|
+
* Internals:
|
|
39
|
+
*
|
|
40
|
+
* Since the LockManager API does not preserve stack traces for the async
|
|
41
|
+
* function passed in the `request` method, a trick is used where acquiring the
|
|
42
|
+
* lock releases a previously started promise to run the operation in the `fn`
|
|
43
|
+
* function. The lock waits for that promise to finish (with or without error),
|
|
44
|
+
* while the function will finally wait for the result anyway.
|
|
45
|
+
*
|
|
46
|
+
* @experimental
|
|
47
|
+
*
|
|
48
|
+
* @param name Name of the lock to be acquired.
|
|
49
|
+
* @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
|
|
50
|
+
* the lock can't be acquired without waiting. If positive, the lock acquire
|
|
51
|
+
* will time out after so many milliseconds. An error is
|
|
52
|
+
* a timeout if it has `isAcquireTimeout` set to true.
|
|
53
|
+
* @param fn The operation to run once the lock is acquired.
|
|
54
|
+
*/
|
|
55
|
+
export async function navigatorLock<R>(
|
|
56
|
+
name: string,
|
|
57
|
+
acquireTimeout: number,
|
|
58
|
+
fn: () => Promise<R>
|
|
59
|
+
): Promise<R> {
|
|
60
|
+
if (internals.debug) {
|
|
61
|
+
console.log('@supabase/gotrue-js: navigatorLock: acquire lock', name, acquireTimeout)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const abortController = new globalThis.AbortController()
|
|
65
|
+
|
|
66
|
+
if (acquireTimeout > 0) {
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
abortController.abort()
|
|
69
|
+
if (internals.debug) {
|
|
70
|
+
console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name)
|
|
71
|
+
}
|
|
72
|
+
}, acquireTimeout)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// MDN article: https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request
|
|
76
|
+
|
|
77
|
+
return await globalThis.navigator.locks.request(
|
|
78
|
+
name,
|
|
79
|
+
acquireTimeout === 0
|
|
80
|
+
? {
|
|
81
|
+
mode: 'exclusive',
|
|
82
|
+
ifAvailable: true,
|
|
83
|
+
}
|
|
84
|
+
: {
|
|
85
|
+
mode: 'exclusive',
|
|
86
|
+
signal: abortController.signal,
|
|
87
|
+
},
|
|
88
|
+
async (lock) => {
|
|
89
|
+
if (lock) {
|
|
90
|
+
if (internals.debug) {
|
|
91
|
+
console.log('@supabase/gotrue-js: navigatorLock: acquired', name, lock.name)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
return await fn()
|
|
96
|
+
} finally {
|
|
97
|
+
if (internals.debug) {
|
|
98
|
+
console.log('@supabase/gotrue-js: navigatorLock: released', name, lock.name)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
if (acquireTimeout === 0) {
|
|
103
|
+
if (internals.debug) {
|
|
104
|
+
console.log('@supabase/gotrue-js: navigatorLock: not immediately available', name)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
throw new NavigatorLockAcquireTimeoutError(
|
|
108
|
+
`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`
|
|
109
|
+
)
|
|
110
|
+
} else {
|
|
111
|
+
if (internals.debug) {
|
|
112
|
+
try {
|
|
113
|
+
const result = await globalThis.navigator.locks.query()
|
|
114
|
+
|
|
115
|
+
console.log(
|
|
116
|
+
'@supabase/gotrue-js: Navigator LockManager state',
|
|
117
|
+
JSON.stringify(result, null, ' ')
|
|
118
|
+
)
|
|
119
|
+
} catch (e: any) {
|
|
120
|
+
console.warn(
|
|
121
|
+
'@supabase/gotrue-js: Error when querying Navigator LockManager state',
|
|
122
|
+
e
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Browser is not following the Navigator LockManager spec, it
|
|
128
|
+
// returned a null lock when we didn't use ifAvailable. So we can
|
|
129
|
+
// pretend the lock is acquired in the name of backward compatibility
|
|
130
|
+
// and user experience and just run the function.
|
|
131
|
+
console.warn(
|
|
132
|
+
'@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'
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
return await fn()
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://mathiasbynens.be/notes/globalthis
|
|
3
|
+
*/
|
|
4
|
+
export function polyfillGlobalThis() {
|
|
5
|
+
if (typeof globalThis === 'object') return
|
|
6
|
+
try {
|
|
7
|
+
Object.defineProperty(Object.prototype, '__magic__', {
|
|
8
|
+
get: function () {
|
|
9
|
+
return this
|
|
10
|
+
},
|
|
11
|
+
configurable: true,
|
|
12
|
+
})
|
|
13
|
+
// @ts-expect-error 'Allow access to magic'
|
|
14
|
+
__magic__.globalThis = __magic__
|
|
15
|
+
// @ts-expect-error 'Allow access to magic'
|
|
16
|
+
delete Object.prototype.__magic__
|
|
17
|
+
} catch (e) {
|
|
18
|
+
if (typeof self !== 'undefined') {
|
|
19
|
+
// @ts-expect-error 'Allow access to globals'
|
|
20
|
+
self.globalThis = self
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|