@supabase/auth-js 2.58.1-canary.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.
Files changed (192) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -0
  3. package/dist/main/AuthAdminApi.d.ts +4 -0
  4. package/dist/main/AuthAdminApi.d.ts.map +1 -0
  5. package/dist/main/AuthAdminApi.js +9 -0
  6. package/dist/main/AuthAdminApi.js.map +1 -0
  7. package/dist/main/AuthClient.d.ts +4 -0
  8. package/dist/main/AuthClient.d.ts.map +1 -0
  9. package/dist/main/AuthClient.js +9 -0
  10. package/dist/main/AuthClient.js.map +1 -0
  11. package/dist/main/GoTrueAdminApi.d.ts +99 -0
  12. package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
  13. package/dist/main/GoTrueAdminApi.js +278 -0
  14. package/dist/main/GoTrueAdminApi.js.map +1 -0
  15. package/dist/main/GoTrueClient.d.ts +531 -0
  16. package/dist/main/GoTrueClient.d.ts.map +1 -0
  17. package/dist/main/GoTrueClient.js +2564 -0
  18. package/dist/main/GoTrueClient.js.map +1 -0
  19. package/dist/main/index.d.ts +9 -0
  20. package/dist/main/index.d.ts.map +1 -0
  21. package/dist/main/index.js +36 -0
  22. package/dist/main/index.js.map +1 -0
  23. package/dist/main/lib/base64url.d.ts +76 -0
  24. package/dist/main/lib/base64url.d.ts.map +1 -0
  25. package/dist/main/lib/base64url.js +269 -0
  26. package/dist/main/lib/base64url.js.map +1 -0
  27. package/dist/main/lib/constants.d.ts +26 -0
  28. package/dist/main/lib/constants.d.ts.map +1 -0
  29. package/dist/main/lib/constants.js +31 -0
  30. package/dist/main/lib/constants.js.map +1 -0
  31. package/dist/main/lib/error-codes.d.ts +7 -0
  32. package/dist/main/lib/error-codes.d.ts.map +1 -0
  33. package/dist/main/lib/error-codes.js +3 -0
  34. package/dist/main/lib/error-codes.js.map +1 -0
  35. package/dist/main/lib/errors.d.ts +100 -0
  36. package/dist/main/lib/errors.d.ts.map +1 -0
  37. package/dist/main/lib/errors.js +137 -0
  38. package/dist/main/lib/errors.js.map +1 -0
  39. package/dist/main/lib/fetch.d.ts +34 -0
  40. package/dist/main/lib/fetch.d.ts.map +1 -0
  41. package/dist/main/lib/fetch.js +194 -0
  42. package/dist/main/lib/fetch.js.map +1 -0
  43. package/dist/main/lib/helpers.d.ts +67 -0
  44. package/dist/main/lib/helpers.d.ts.map +1 -0
  45. package/dist/main/lib/helpers.js +388 -0
  46. package/dist/main/lib/helpers.js.map +1 -0
  47. package/dist/main/lib/local-storage.d.ts +9 -0
  48. package/dist/main/lib/local-storage.d.ts.map +1 -0
  49. package/dist/main/lib/local-storage.js +21 -0
  50. package/dist/main/lib/local-storage.js.map +1 -0
  51. package/dist/main/lib/locks.d.ts +64 -0
  52. package/dist/main/lib/locks.d.ts.map +1 -0
  53. package/dist/main/lib/locks.js +187 -0
  54. package/dist/main/lib/locks.js.map +1 -0
  55. package/dist/main/lib/polyfills.d.ts +5 -0
  56. package/dist/main/lib/polyfills.d.ts.map +1 -0
  57. package/dist/main/lib/polyfills.js +29 -0
  58. package/dist/main/lib/polyfills.js.map +1 -0
  59. package/dist/main/lib/types.d.ts +1130 -0
  60. package/dist/main/lib/types.d.ts.map +1 -0
  61. package/dist/main/lib/types.js +22 -0
  62. package/dist/main/lib/types.js.map +1 -0
  63. package/dist/main/lib/version.d.ts +2 -0
  64. package/dist/main/lib/version.d.ts.map +1 -0
  65. package/dist/main/lib/version.js +11 -0
  66. package/dist/main/lib/version.js.map +1 -0
  67. package/dist/main/lib/web3/ethereum.d.ts +96 -0
  68. package/dist/main/lib/web3/ethereum.d.ts.map +1 -0
  69. package/dist/main/lib/web3/ethereum.js +66 -0
  70. package/dist/main/lib/web3/ethereum.js.map +1 -0
  71. package/dist/main/lib/web3/solana.d.ts +160 -0
  72. package/dist/main/lib/web3/solana.d.ts.map +1 -0
  73. package/dist/main/lib/web3/solana.js +4 -0
  74. package/dist/main/lib/web3/solana.js.map +1 -0
  75. package/dist/main/lib/webauthn.d.ts +274 -0
  76. package/dist/main/lib/webauthn.d.ts.map +1 -0
  77. package/dist/main/lib/webauthn.dom.d.ts +583 -0
  78. package/dist/main/lib/webauthn.dom.d.ts.map +1 -0
  79. package/dist/main/lib/webauthn.dom.js +4 -0
  80. package/dist/main/lib/webauthn.dom.js.map +1 -0
  81. package/dist/main/lib/webauthn.errors.d.ts +80 -0
  82. package/dist/main/lib/webauthn.errors.d.ts.map +1 -0
  83. package/dist/main/lib/webauthn.errors.js +265 -0
  84. package/dist/main/lib/webauthn.errors.js.map +1 -0
  85. package/dist/main/lib/webauthn.js +702 -0
  86. package/dist/main/lib/webauthn.js.map +1 -0
  87. package/dist/module/AuthAdminApi.d.ts +4 -0
  88. package/dist/module/AuthAdminApi.d.ts.map +1 -0
  89. package/dist/module/AuthAdminApi.js +4 -0
  90. package/dist/module/AuthAdminApi.js.map +1 -0
  91. package/dist/module/AuthClient.d.ts +4 -0
  92. package/dist/module/AuthClient.d.ts.map +1 -0
  93. package/dist/module/AuthClient.js +4 -0
  94. package/dist/module/AuthClient.js.map +1 -0
  95. package/dist/module/GoTrueAdminApi.d.ts +99 -0
  96. package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
  97. package/dist/module/GoTrueAdminApi.js +275 -0
  98. package/dist/module/GoTrueAdminApi.js.map +1 -0
  99. package/dist/module/GoTrueClient.d.ts +531 -0
  100. package/dist/module/GoTrueClient.d.ts.map +1 -0
  101. package/dist/module/GoTrueClient.js +2559 -0
  102. package/dist/module/GoTrueClient.js.map +1 -0
  103. package/dist/module/index.d.ts +9 -0
  104. package/dist/module/index.d.ts.map +1 -0
  105. package/dist/module/index.js +9 -0
  106. package/dist/module/index.js.map +1 -0
  107. package/dist/module/lib/base64url.d.ts +76 -0
  108. package/dist/module/lib/base64url.d.ts.map +1 -0
  109. package/dist/module/lib/base64url.js +257 -0
  110. package/dist/module/lib/base64url.js.map +1 -0
  111. package/dist/module/lib/constants.d.ts +26 -0
  112. package/dist/module/lib/constants.d.ts.map +1 -0
  113. package/dist/module/lib/constants.js +28 -0
  114. package/dist/module/lib/constants.js.map +1 -0
  115. package/dist/module/lib/error-codes.d.ts +7 -0
  116. package/dist/module/lib/error-codes.d.ts.map +1 -0
  117. package/dist/module/lib/error-codes.js +2 -0
  118. package/dist/module/lib/error-codes.js.map +1 -0
  119. package/dist/module/lib/errors.d.ts +100 -0
  120. package/dist/module/lib/errors.d.ts.map +1 -0
  121. package/dist/module/lib/errors.js +116 -0
  122. package/dist/module/lib/errors.js.map +1 -0
  123. package/dist/module/lib/fetch.d.ts +34 -0
  124. package/dist/module/lib/fetch.d.ts.map +1 -0
  125. package/dist/module/lib/fetch.js +184 -0
  126. package/dist/module/lib/fetch.js.map +1 -0
  127. package/dist/module/lib/helpers.d.ts +67 -0
  128. package/dist/module/lib/helpers.d.ts.map +1 -0
  129. package/dist/module/lib/helpers.js +329 -0
  130. package/dist/module/lib/helpers.js.map +1 -0
  131. package/dist/module/lib/local-storage.d.ts +9 -0
  132. package/dist/module/lib/local-storage.d.ts.map +1 -0
  133. package/dist/module/lib/local-storage.js +18 -0
  134. package/dist/module/lib/local-storage.js.map +1 -0
  135. package/dist/module/lib/locks.d.ts +64 -0
  136. package/dist/module/lib/locks.d.ts.map +1 -0
  137. package/dist/module/lib/locks.js +179 -0
  138. package/dist/module/lib/locks.js.map +1 -0
  139. package/dist/module/lib/polyfills.d.ts +5 -0
  140. package/dist/module/lib/polyfills.d.ts.map +1 -0
  141. package/dist/module/lib/polyfills.js +26 -0
  142. package/dist/module/lib/polyfills.js.map +1 -0
  143. package/dist/module/lib/types.d.ts +1130 -0
  144. package/dist/module/lib/types.d.ts.map +1 -0
  145. package/dist/module/lib/types.js +19 -0
  146. package/dist/module/lib/types.js.map +1 -0
  147. package/dist/module/lib/version.d.ts +2 -0
  148. package/dist/module/lib/version.d.ts.map +1 -0
  149. package/dist/module/lib/version.js +8 -0
  150. package/dist/module/lib/version.js.map +1 -0
  151. package/dist/module/lib/web3/ethereum.d.ts +96 -0
  152. package/dist/module/lib/web3/ethereum.d.ts.map +1 -0
  153. package/dist/module/lib/web3/ethereum.js +60 -0
  154. package/dist/module/lib/web3/ethereum.js.map +1 -0
  155. package/dist/module/lib/web3/solana.d.ts +160 -0
  156. package/dist/module/lib/web3/solana.d.ts.map +1 -0
  157. package/dist/module/lib/web3/solana.js +3 -0
  158. package/dist/module/lib/web3/solana.js.map +1 -0
  159. package/dist/module/lib/webauthn.d.ts +274 -0
  160. package/dist/module/lib/webauthn.d.ts.map +1 -0
  161. package/dist/module/lib/webauthn.dom.d.ts +583 -0
  162. package/dist/module/lib/webauthn.dom.d.ts.map +1 -0
  163. package/dist/module/lib/webauthn.dom.js +3 -0
  164. package/dist/module/lib/webauthn.dom.js.map +1 -0
  165. package/dist/module/lib/webauthn.errors.d.ts +80 -0
  166. package/dist/module/lib/webauthn.errors.d.ts.map +1 -0
  167. package/dist/module/lib/webauthn.errors.js +257 -0
  168. package/dist/module/lib/webauthn.errors.js.map +1 -0
  169. package/dist/module/lib/webauthn.js +685 -0
  170. package/dist/module/lib/webauthn.js.map +1 -0
  171. package/package.json +49 -0
  172. package/src/AuthAdminApi.ts +5 -0
  173. package/src/AuthClient.ts +5 -0
  174. package/src/GoTrueAdminApi.ts +352 -0
  175. package/src/GoTrueClient.ts +3483 -0
  176. package/src/index.ts +13 -0
  177. package/src/lib/base64url.ts +308 -0
  178. package/src/lib/constants.ts +34 -0
  179. package/src/lib/error-codes.ts +90 -0
  180. package/src/lib/errors.ts +165 -0
  181. package/src/lib/fetch.ts +283 -0
  182. package/src/lib/helpers.ts +416 -0
  183. package/src/lib/local-storage.ts +21 -0
  184. package/src/lib/locks.ts +225 -0
  185. package/src/lib/polyfills.ts +23 -0
  186. package/src/lib/types.ts +1450 -0
  187. package/src/lib/version.ts +7 -0
  188. package/src/lib/web3/ethereum.ts +184 -0
  189. package/src/lib/web3/solana.ts +186 -0
  190. package/src/lib/webauthn.dom.ts +636 -0
  191. package/src/lib/webauthn.errors.ts +317 -0
  192. package/src/lib/webauthn.ts +929 -0
@@ -0,0 +1,225 @@
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
+ /**
19
+ * An error thrown when a lock cannot be acquired after some amount of time.
20
+ *
21
+ * Use the {@link #isAcquireTimeout} property instead of checking with `instanceof`.
22
+ */
23
+ export abstract class LockAcquireTimeoutError extends Error {
24
+ public readonly isAcquireTimeout = true
25
+
26
+ constructor(message: string) {
27
+ super(message)
28
+ }
29
+ }
30
+
31
+ export class NavigatorLockAcquireTimeoutError extends LockAcquireTimeoutError {}
32
+ export class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {}
33
+
34
+ /**
35
+ * Implements a global exclusive lock using the Navigator LockManager API. It
36
+ * is available on all browsers released after 2022-03-15 with Safari being the
37
+ * last one to release support. If the API is not available, this function will
38
+ * throw. Make sure you check availablility before configuring {@link
39
+ * GoTrueClient}.
40
+ *
41
+ * You can turn on debugging by setting the `supabase.gotrue-js.locks.debug`
42
+ * local storage item to `true`.
43
+ *
44
+ * Internals:
45
+ *
46
+ * Since the LockManager API does not preserve stack traces for the async
47
+ * function passed in the `request` method, a trick is used where acquiring the
48
+ * lock releases a previously started promise to run the operation in the `fn`
49
+ * function. The lock waits for that promise to finish (with or without error),
50
+ * while the function will finally wait for the result anyway.
51
+ *
52
+ * @param name Name of the lock to be acquired.
53
+ * @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
54
+ * the lock can't be acquired without waiting. If positive, the lock acquire
55
+ * will time out after so many milliseconds. An error is
56
+ * a timeout if it has `isAcquireTimeout` set to true.
57
+ * @param fn The operation to run once the lock is acquired.
58
+ */
59
+ export async function navigatorLock<R>(
60
+ name: string,
61
+ acquireTimeout: number,
62
+ fn: () => Promise<R>
63
+ ): Promise<R> {
64
+ if (internals.debug) {
65
+ console.log('@supabase/gotrue-js: navigatorLock: acquire lock', name, acquireTimeout)
66
+ }
67
+
68
+ const abortController = new globalThis.AbortController()
69
+
70
+ if (acquireTimeout > 0) {
71
+ setTimeout(() => {
72
+ abortController.abort()
73
+ if (internals.debug) {
74
+ console.log('@supabase/gotrue-js: navigatorLock acquire timed out', name)
75
+ }
76
+ }, acquireTimeout)
77
+ }
78
+
79
+ // MDN article: https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request
80
+
81
+ // Wrapping navigator.locks.request() with a plain Promise is done as some
82
+ // libraries like zone.js patch the Promise object to track the execution
83
+ // context. However, it appears that most browsers use an internal promise
84
+ // implementation when using the navigator.locks.request() API causing them
85
+ // to lose context and emit confusing log messages or break certain features.
86
+ // This wrapping is believed to help zone.js track the execution context
87
+ // better.
88
+ return await Promise.resolve().then(() =>
89
+ globalThis.navigator.locks.request(
90
+ name,
91
+ acquireTimeout === 0
92
+ ? {
93
+ mode: 'exclusive',
94
+ ifAvailable: true,
95
+ }
96
+ : {
97
+ mode: 'exclusive',
98
+ signal: abortController.signal,
99
+ },
100
+ async (lock) => {
101
+ if (lock) {
102
+ if (internals.debug) {
103
+ console.log('@supabase/gotrue-js: navigatorLock: acquired', name, lock.name)
104
+ }
105
+
106
+ try {
107
+ return await fn()
108
+ } finally {
109
+ if (internals.debug) {
110
+ console.log('@supabase/gotrue-js: navigatorLock: released', name, lock.name)
111
+ }
112
+ }
113
+ } else {
114
+ if (acquireTimeout === 0) {
115
+ if (internals.debug) {
116
+ console.log('@supabase/gotrue-js: navigatorLock: not immediately available', name)
117
+ }
118
+
119
+ throw new NavigatorLockAcquireTimeoutError(
120
+ `Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`
121
+ )
122
+ } else {
123
+ if (internals.debug) {
124
+ try {
125
+ const result = await globalThis.navigator.locks.query()
126
+
127
+ console.log(
128
+ '@supabase/gotrue-js: Navigator LockManager state',
129
+ JSON.stringify(result, null, ' ')
130
+ )
131
+ } catch (e: any) {
132
+ console.warn(
133
+ '@supabase/gotrue-js: Error when querying Navigator LockManager state',
134
+ e
135
+ )
136
+ }
137
+ }
138
+
139
+ // Browser is not following the Navigator LockManager spec, it
140
+ // returned a null lock when we didn't use ifAvailable. So we can
141
+ // pretend the lock is acquired in the name of backward compatibility
142
+ // and user experience and just run the function.
143
+ console.warn(
144
+ '@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'
145
+ )
146
+
147
+ return await fn()
148
+ }
149
+ }
150
+ }
151
+ )
152
+ )
153
+ }
154
+
155
+ const PROCESS_LOCKS: { [name: string]: Promise<any> } = {}
156
+
157
+ /**
158
+ * Implements a global exclusive lock that works only in the current process.
159
+ * Useful for environments like React Native or other non-browser
160
+ * single-process (i.e. no concept of "tabs") environments.
161
+ *
162
+ * Use {@link #navigatorLock} in browser environments.
163
+ *
164
+ * @param name Name of the lock to be acquired.
165
+ * @param acquireTimeout If negative, no timeout. If 0 an error is thrown if
166
+ * the lock can't be acquired without waiting. If positive, the lock acquire
167
+ * will time out after so many milliseconds. An error is
168
+ * a timeout if it has `isAcquireTimeout` set to true.
169
+ * @param fn The operation to run once the lock is acquired.
170
+ */
171
+ export async function processLock<R>(
172
+ name: string,
173
+ acquireTimeout: number,
174
+ fn: () => Promise<R>
175
+ ): Promise<R> {
176
+ const previousOperation = PROCESS_LOCKS[name] ?? Promise.resolve()
177
+
178
+ const currentOperation = Promise.race(
179
+ [
180
+ previousOperation.catch(() => {
181
+ // ignore error of previous operation that we're waiting to finish
182
+ return null
183
+ }),
184
+ acquireTimeout >= 0
185
+ ? new Promise((_, reject) => {
186
+ setTimeout(() => {
187
+ reject(
188
+ new ProcessLockAcquireTimeoutError(
189
+ `Acquring process lock with name "${name}" timed out`
190
+ )
191
+ )
192
+ }, acquireTimeout)
193
+ })
194
+ : null,
195
+ ].filter((x) => x)
196
+ )
197
+ .catch((e: any) => {
198
+ if (e && e.isAcquireTimeout) {
199
+ throw e
200
+ }
201
+
202
+ return null
203
+ })
204
+ .then(async () => {
205
+ // previous operations finished and we didn't get a race on the acquire
206
+ // timeout, so the current operation can finally start
207
+ return await fn()
208
+ })
209
+
210
+ PROCESS_LOCKS[name] = currentOperation.catch(async (e: any) => {
211
+ if (e && e.isAcquireTimeout) {
212
+ // if the current operation timed out, it doesn't mean that the previous
213
+ // operation finished, so we need contnue waiting for it to finish
214
+ await previousOperation
215
+
216
+ return null
217
+ }
218
+
219
+ throw e
220
+ })
221
+
222
+ // finally wait for the current operation to finish successfully, with an
223
+ // error or with an acquire timeout error
224
+ return await currentOperation
225
+ }
@@ -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
+ }