@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.
- package/LICENSE +21 -0
- package/README.md +148 -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 +278 -0
- package/dist/main/GoTrueAdminApi.js.map +1 -0
- package/dist/main/GoTrueClient.d.ts +531 -0
- package/dist/main/GoTrueClient.d.ts.map +1 -0
- package/dist/main/GoTrueClient.js +2564 -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 +36 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/lib/base64url.d.ts +76 -0
- package/dist/main/lib/base64url.d.ts.map +1 -0
- package/dist/main/lib/base64url.js +269 -0
- package/dist/main/lib/base64url.js.map +1 -0
- package/dist/main/lib/constants.d.ts +26 -0
- package/dist/main/lib/constants.d.ts.map +1 -0
- package/dist/main/lib/constants.js +31 -0
- package/dist/main/lib/constants.js.map +1 -0
- package/dist/main/lib/error-codes.d.ts +7 -0
- package/dist/main/lib/error-codes.d.ts.map +1 -0
- package/dist/main/lib/error-codes.js +3 -0
- package/dist/main/lib/error-codes.js.map +1 -0
- package/dist/main/lib/errors.d.ts +100 -0
- package/dist/main/lib/errors.d.ts.map +1 -0
- package/dist/main/lib/errors.js +137 -0
- package/dist/main/lib/errors.js.map +1 -0
- package/dist/main/lib/fetch.d.ts +34 -0
- package/dist/main/lib/fetch.d.ts.map +1 -0
- package/dist/main/lib/fetch.js +194 -0
- package/dist/main/lib/fetch.js.map +1 -0
- package/dist/main/lib/helpers.d.ts +67 -0
- package/dist/main/lib/helpers.d.ts.map +1 -0
- package/dist/main/lib/helpers.js +388 -0
- package/dist/main/lib/helpers.js.map +1 -0
- package/dist/main/lib/local-storage.d.ts +9 -0
- package/dist/main/lib/local-storage.d.ts.map +1 -0
- package/dist/main/lib/local-storage.js +21 -0
- package/dist/main/lib/local-storage.js.map +1 -0
- package/dist/main/lib/locks.d.ts +64 -0
- package/dist/main/lib/locks.d.ts.map +1 -0
- package/dist/main/lib/locks.js +187 -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 +29 -0
- package/dist/main/lib/polyfills.js.map +1 -0
- package/dist/main/lib/types.d.ts +1130 -0
- package/dist/main/lib/types.d.ts.map +1 -0
- package/dist/main/lib/types.js +22 -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 +11 -0
- package/dist/main/lib/version.js.map +1 -0
- package/dist/main/lib/web3/ethereum.d.ts +96 -0
- package/dist/main/lib/web3/ethereum.d.ts.map +1 -0
- package/dist/main/lib/web3/ethereum.js +66 -0
- package/dist/main/lib/web3/ethereum.js.map +1 -0
- package/dist/main/lib/web3/solana.d.ts +160 -0
- package/dist/main/lib/web3/solana.d.ts.map +1 -0
- package/dist/main/lib/web3/solana.js +4 -0
- package/dist/main/lib/web3/solana.js.map +1 -0
- package/dist/main/lib/webauthn.d.ts +274 -0
- package/dist/main/lib/webauthn.d.ts.map +1 -0
- package/dist/main/lib/webauthn.dom.d.ts +583 -0
- package/dist/main/lib/webauthn.dom.d.ts.map +1 -0
- package/dist/main/lib/webauthn.dom.js +4 -0
- package/dist/main/lib/webauthn.dom.js.map +1 -0
- package/dist/main/lib/webauthn.errors.d.ts +80 -0
- package/dist/main/lib/webauthn.errors.d.ts.map +1 -0
- package/dist/main/lib/webauthn.errors.js +265 -0
- package/dist/main/lib/webauthn.errors.js.map +1 -0
- package/dist/main/lib/webauthn.js +702 -0
- package/dist/main/lib/webauthn.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 +275 -0
- package/dist/module/GoTrueAdminApi.js.map +1 -0
- package/dist/module/GoTrueClient.d.ts +531 -0
- package/dist/module/GoTrueClient.d.ts.map +1 -0
- package/dist/module/GoTrueClient.js +2559 -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/base64url.d.ts +76 -0
- package/dist/module/lib/base64url.d.ts.map +1 -0
- package/dist/module/lib/base64url.js +257 -0
- package/dist/module/lib/base64url.js.map +1 -0
- package/dist/module/lib/constants.d.ts +26 -0
- package/dist/module/lib/constants.d.ts.map +1 -0
- package/dist/module/lib/constants.js +28 -0
- package/dist/module/lib/constants.js.map +1 -0
- package/dist/module/lib/error-codes.d.ts +7 -0
- package/dist/module/lib/error-codes.d.ts.map +1 -0
- package/dist/module/lib/error-codes.js +2 -0
- package/dist/module/lib/error-codes.js.map +1 -0
- package/dist/module/lib/errors.d.ts +100 -0
- package/dist/module/lib/errors.d.ts.map +1 -0
- package/dist/module/lib/errors.js +116 -0
- package/dist/module/lib/errors.js.map +1 -0
- package/dist/module/lib/fetch.d.ts +34 -0
- package/dist/module/lib/fetch.d.ts.map +1 -0
- package/dist/module/lib/fetch.js +184 -0
- package/dist/module/lib/fetch.js.map +1 -0
- package/dist/module/lib/helpers.d.ts +67 -0
- package/dist/module/lib/helpers.d.ts.map +1 -0
- package/dist/module/lib/helpers.js +329 -0
- package/dist/module/lib/helpers.js.map +1 -0
- package/dist/module/lib/local-storage.d.ts +9 -0
- package/dist/module/lib/local-storage.d.ts.map +1 -0
- package/dist/module/lib/local-storage.js +18 -0
- package/dist/module/lib/local-storage.js.map +1 -0
- package/dist/module/lib/locks.d.ts +64 -0
- package/dist/module/lib/locks.d.ts.map +1 -0
- package/dist/module/lib/locks.js +179 -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 +1130 -0
- package/dist/module/lib/types.d.ts.map +1 -0
- package/dist/module/lib/types.js +19 -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 +8 -0
- package/dist/module/lib/version.js.map +1 -0
- package/dist/module/lib/web3/ethereum.d.ts +96 -0
- package/dist/module/lib/web3/ethereum.d.ts.map +1 -0
- package/dist/module/lib/web3/ethereum.js +60 -0
- package/dist/module/lib/web3/ethereum.js.map +1 -0
- package/dist/module/lib/web3/solana.d.ts +160 -0
- package/dist/module/lib/web3/solana.d.ts.map +1 -0
- package/dist/module/lib/web3/solana.js +3 -0
- package/dist/module/lib/web3/solana.js.map +1 -0
- package/dist/module/lib/webauthn.d.ts +274 -0
- package/dist/module/lib/webauthn.d.ts.map +1 -0
- package/dist/module/lib/webauthn.dom.d.ts +583 -0
- package/dist/module/lib/webauthn.dom.d.ts.map +1 -0
- package/dist/module/lib/webauthn.dom.js +3 -0
- package/dist/module/lib/webauthn.dom.js.map +1 -0
- package/dist/module/lib/webauthn.errors.d.ts +80 -0
- package/dist/module/lib/webauthn.errors.d.ts.map +1 -0
- package/dist/module/lib/webauthn.errors.js +257 -0
- package/dist/module/lib/webauthn.errors.js.map +1 -0
- package/dist/module/lib/webauthn.js +685 -0
- package/dist/module/lib/webauthn.js.map +1 -0
- package/package.json +49 -0
- package/src/AuthAdminApi.ts +5 -0
- package/src/AuthClient.ts +5 -0
- package/src/GoTrueAdminApi.ts +352 -0
- package/src/GoTrueClient.ts +3483 -0
- package/src/index.ts +13 -0
- package/src/lib/base64url.ts +308 -0
- package/src/lib/constants.ts +34 -0
- package/src/lib/error-codes.ts +90 -0
- package/src/lib/errors.ts +165 -0
- package/src/lib/fetch.ts +283 -0
- package/src/lib/helpers.ts +416 -0
- package/src/lib/local-storage.ts +21 -0
- package/src/lib/locks.ts +225 -0
- package/src/lib/polyfills.ts +23 -0
- package/src/lib/types.ts +1450 -0
- package/src/lib/version.ts +7 -0
- package/src/lib/web3/ethereum.ts +184 -0
- package/src/lib/web3/solana.ts +186 -0
- package/src/lib/webauthn.dom.ts +636 -0
- package/src/lib/webauthn.errors.ts +317 -0
- package/src/lib/webauthn.ts +929 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import GoTrueAdminApi from './GoTrueAdminApi'
|
|
2
|
+
import GoTrueClient from './GoTrueClient'
|
|
3
|
+
import AuthAdminApi from './AuthAdminApi'
|
|
4
|
+
import AuthClient from './AuthClient'
|
|
5
|
+
export { GoTrueAdminApi, GoTrueClient, AuthAdminApi, AuthClient }
|
|
6
|
+
export * from './lib/types'
|
|
7
|
+
export * from './lib/errors'
|
|
8
|
+
export {
|
|
9
|
+
navigatorLock,
|
|
10
|
+
NavigatorLockAcquireTimeoutError,
|
|
11
|
+
internals as lockInternals,
|
|
12
|
+
processLock,
|
|
13
|
+
} from './lib/locks'
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Avoid modifying this file. It's part of
|
|
3
|
+
* https://github.com/supabase-community/base64url-js. Submit all fixes on
|
|
4
|
+
* that repo!
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint8Array_ } from './webauthn.dom'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An array of characters that encode 6 bits into a Base64-URL alphabet
|
|
11
|
+
* character.
|
|
12
|
+
*/
|
|
13
|
+
const TO_BASE64URL = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'.split('')
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* An array of characters that can appear in a Base64-URL encoded string but
|
|
17
|
+
* should be ignored.
|
|
18
|
+
*/
|
|
19
|
+
const IGNORE_BASE64URL = ' \t\n\r='.split('')
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An array of 128 numbers that map a Base64-URL character to 6 bits, or if -2
|
|
23
|
+
* used to skip the character, or if -1 used to error out.
|
|
24
|
+
*/
|
|
25
|
+
const FROM_BASE64URL = (() => {
|
|
26
|
+
const charMap: number[] = new Array(128)
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < charMap.length; i += 1) {
|
|
29
|
+
charMap[i] = -1
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < IGNORE_BASE64URL.length; i += 1) {
|
|
33
|
+
charMap[IGNORE_BASE64URL[i].charCodeAt(0)] = -2
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < TO_BASE64URL.length; i += 1) {
|
|
37
|
+
charMap[TO_BASE64URL[i].charCodeAt(0)] = i
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return charMap
|
|
41
|
+
})()
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Converts a byte to a Base64-URL string.
|
|
45
|
+
*
|
|
46
|
+
* @param byte The byte to convert, or null to flush at the end of the byte sequence.
|
|
47
|
+
* @param state The Base64 conversion state. Pass an initial value of `{ queue: 0, queuedBits: 0 }`.
|
|
48
|
+
* @param emit A function called with the next Base64 character when ready.
|
|
49
|
+
*/
|
|
50
|
+
export function byteToBase64URL(
|
|
51
|
+
byte: number | null,
|
|
52
|
+
state: { queue: number; queuedBits: number },
|
|
53
|
+
emit: (char: string) => void
|
|
54
|
+
) {
|
|
55
|
+
if (byte !== null) {
|
|
56
|
+
state.queue = (state.queue << 8) | byte
|
|
57
|
+
state.queuedBits += 8
|
|
58
|
+
|
|
59
|
+
while (state.queuedBits >= 6) {
|
|
60
|
+
const pos = (state.queue >> (state.queuedBits - 6)) & 63
|
|
61
|
+
emit(TO_BASE64URL[pos])
|
|
62
|
+
state.queuedBits -= 6
|
|
63
|
+
}
|
|
64
|
+
} else if (state.queuedBits > 0) {
|
|
65
|
+
state.queue = state.queue << (6 - state.queuedBits)
|
|
66
|
+
state.queuedBits = 6
|
|
67
|
+
|
|
68
|
+
while (state.queuedBits >= 6) {
|
|
69
|
+
const pos = (state.queue >> (state.queuedBits - 6)) & 63
|
|
70
|
+
emit(TO_BASE64URL[pos])
|
|
71
|
+
state.queuedBits -= 6
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Converts a String char code (extracted using `string.charCodeAt(position)`) to a sequence of Base64-URL characters.
|
|
78
|
+
*
|
|
79
|
+
* @param charCode The char code of the JavaScript string.
|
|
80
|
+
* @param state The Base64 state. Pass an initial value of `{ queue: 0, queuedBits: 0 }`.
|
|
81
|
+
* @param emit A function called with the next byte.
|
|
82
|
+
*/
|
|
83
|
+
export function byteFromBase64URL(
|
|
84
|
+
charCode: number,
|
|
85
|
+
state: { queue: number; queuedBits: number },
|
|
86
|
+
emit: (byte: number) => void
|
|
87
|
+
) {
|
|
88
|
+
const bits = FROM_BASE64URL[charCode]
|
|
89
|
+
|
|
90
|
+
if (bits > -1) {
|
|
91
|
+
// valid Base64-URL character
|
|
92
|
+
state.queue = (state.queue << 6) | bits
|
|
93
|
+
state.queuedBits += 6
|
|
94
|
+
|
|
95
|
+
while (state.queuedBits >= 8) {
|
|
96
|
+
emit((state.queue >> (state.queuedBits - 8)) & 0xff)
|
|
97
|
+
state.queuedBits -= 8
|
|
98
|
+
}
|
|
99
|
+
} else if (bits === -2) {
|
|
100
|
+
// ignore spaces, tabs, newlines, =
|
|
101
|
+
return
|
|
102
|
+
} else {
|
|
103
|
+
throw new Error(`Invalid Base64-URL character "${String.fromCharCode(charCode)}"`)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Converts a JavaScript string (which may include any valid character) into a
|
|
109
|
+
* Base64-URL encoded string. The string is first encoded in UTF-8 which is
|
|
110
|
+
* then encoded as Base64-URL.
|
|
111
|
+
*
|
|
112
|
+
* @param str The string to convert.
|
|
113
|
+
*/
|
|
114
|
+
export function stringToBase64URL(str: string) {
|
|
115
|
+
const base64: string[] = []
|
|
116
|
+
|
|
117
|
+
const emitter = (char: string) => {
|
|
118
|
+
base64.push(char)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const state = { queue: 0, queuedBits: 0 }
|
|
122
|
+
|
|
123
|
+
stringToUTF8(str, (byte: number) => {
|
|
124
|
+
byteToBase64URL(byte, state, emitter)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
byteToBase64URL(null, state, emitter)
|
|
128
|
+
|
|
129
|
+
return base64.join('')
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Converts a Base64-URL encoded string into a JavaScript string. It is assumed
|
|
134
|
+
* that the underlying string has been encoded as UTF-8.
|
|
135
|
+
*
|
|
136
|
+
* @param str The Base64-URL encoded string.
|
|
137
|
+
*/
|
|
138
|
+
export function stringFromBase64URL(str: string) {
|
|
139
|
+
const conv: string[] = []
|
|
140
|
+
|
|
141
|
+
const utf8Emit = (codepoint: number) => {
|
|
142
|
+
conv.push(String.fromCodePoint(codepoint))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const utf8State = {
|
|
146
|
+
utf8seq: 0,
|
|
147
|
+
codepoint: 0,
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const b64State = { queue: 0, queuedBits: 0 }
|
|
151
|
+
|
|
152
|
+
const byteEmit = (byte: number) => {
|
|
153
|
+
stringFromUTF8(byte, utf8State, utf8Emit)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
157
|
+
byteFromBase64URL(str.charCodeAt(i), b64State, byteEmit)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return conv.join('')
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Converts a Unicode codepoint to a multi-byte UTF-8 sequence.
|
|
165
|
+
*
|
|
166
|
+
* @param codepoint The Unicode codepoint.
|
|
167
|
+
* @param emit Function which will be called for each UTF-8 byte that represents the codepoint.
|
|
168
|
+
*/
|
|
169
|
+
export function codepointToUTF8(codepoint: number, emit: (byte: number) => void) {
|
|
170
|
+
if (codepoint <= 0x7f) {
|
|
171
|
+
emit(codepoint)
|
|
172
|
+
return
|
|
173
|
+
} else if (codepoint <= 0x7ff) {
|
|
174
|
+
emit(0xc0 | (codepoint >> 6))
|
|
175
|
+
emit(0x80 | (codepoint & 0x3f))
|
|
176
|
+
return
|
|
177
|
+
} else if (codepoint <= 0xffff) {
|
|
178
|
+
emit(0xe0 | (codepoint >> 12))
|
|
179
|
+
emit(0x80 | ((codepoint >> 6) & 0x3f))
|
|
180
|
+
emit(0x80 | (codepoint & 0x3f))
|
|
181
|
+
return
|
|
182
|
+
} else if (codepoint <= 0x10ffff) {
|
|
183
|
+
emit(0xf0 | (codepoint >> 18))
|
|
184
|
+
emit(0x80 | ((codepoint >> 12) & 0x3f))
|
|
185
|
+
emit(0x80 | ((codepoint >> 6) & 0x3f))
|
|
186
|
+
emit(0x80 | (codepoint & 0x3f))
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
throw new Error(`Unrecognized Unicode codepoint: ${codepoint.toString(16)}`)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Converts a JavaScript string to a sequence of UTF-8 bytes.
|
|
195
|
+
*
|
|
196
|
+
* @param str The string to convert to UTF-8.
|
|
197
|
+
* @param emit Function which will be called for each UTF-8 byte of the string.
|
|
198
|
+
*/
|
|
199
|
+
export function stringToUTF8(str: string, emit: (byte: number) => void) {
|
|
200
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
201
|
+
let codepoint = str.charCodeAt(i)
|
|
202
|
+
|
|
203
|
+
if (codepoint > 0xd7ff && codepoint <= 0xdbff) {
|
|
204
|
+
// most UTF-16 codepoints are Unicode codepoints, except values in this
|
|
205
|
+
// range where the next UTF-16 codepoint needs to be combined with the
|
|
206
|
+
// current one to get the Unicode codepoint
|
|
207
|
+
const highSurrogate = ((codepoint - 0xd800) * 0x400) & 0xffff
|
|
208
|
+
const lowSurrogate = (str.charCodeAt(i + 1) - 0xdc00) & 0xffff
|
|
209
|
+
codepoint = (lowSurrogate | highSurrogate) + 0x10000
|
|
210
|
+
i += 1
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
codepointToUTF8(codepoint, emit)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Converts a UTF-8 byte to a Unicode codepoint.
|
|
219
|
+
*
|
|
220
|
+
* @param byte The UTF-8 byte next in the sequence.
|
|
221
|
+
* @param state The shared state between consecutive UTF-8 bytes in the
|
|
222
|
+
* sequence, an object with the shape `{ utf8seq: 0, codepoint: 0 }`.
|
|
223
|
+
* @param emit Function which will be called for each codepoint.
|
|
224
|
+
*/
|
|
225
|
+
export function stringFromUTF8(
|
|
226
|
+
byte: number,
|
|
227
|
+
state: { utf8seq: number; codepoint: number },
|
|
228
|
+
emit: (codepoint: number) => void
|
|
229
|
+
) {
|
|
230
|
+
if (state.utf8seq === 0) {
|
|
231
|
+
if (byte <= 0x7f) {
|
|
232
|
+
emit(byte)
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// count the number of 1 leading bits until you reach 0
|
|
237
|
+
for (let leadingBit = 1; leadingBit < 6; leadingBit += 1) {
|
|
238
|
+
if (((byte >> (7 - leadingBit)) & 1) === 0) {
|
|
239
|
+
state.utf8seq = leadingBit
|
|
240
|
+
break
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (state.utf8seq === 2) {
|
|
245
|
+
state.codepoint = byte & 31
|
|
246
|
+
} else if (state.utf8seq === 3) {
|
|
247
|
+
state.codepoint = byte & 15
|
|
248
|
+
} else if (state.utf8seq === 4) {
|
|
249
|
+
state.codepoint = byte & 7
|
|
250
|
+
} else {
|
|
251
|
+
throw new Error('Invalid UTF-8 sequence')
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
state.utf8seq -= 1
|
|
255
|
+
} else if (state.utf8seq > 0) {
|
|
256
|
+
if (byte <= 0x7f) {
|
|
257
|
+
throw new Error('Invalid UTF-8 sequence')
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
state.codepoint = (state.codepoint << 6) | (byte & 63)
|
|
261
|
+
state.utf8seq -= 1
|
|
262
|
+
|
|
263
|
+
if (state.utf8seq === 0) {
|
|
264
|
+
emit(state.codepoint)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Helper functions to convert different types of strings to Uint8Array
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
export function base64UrlToUint8Array(str: string): Uint8Array_ {
|
|
274
|
+
const result: number[] = []
|
|
275
|
+
const state = { queue: 0, queuedBits: 0 }
|
|
276
|
+
|
|
277
|
+
const onByte = (byte: number) => {
|
|
278
|
+
result.push(byte)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
282
|
+
byteFromBase64URL(str.charCodeAt(i), state, onByte)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return new Uint8Array(result)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function stringToUint8Array(str: string): Uint8Array_ {
|
|
289
|
+
const result: number[] = []
|
|
290
|
+
stringToUTF8(str, (byte: number) => result.push(byte))
|
|
291
|
+
return new Uint8Array(result)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function bytesToBase64URL(bytes: Uint8Array) {
|
|
295
|
+
const result: string[] = []
|
|
296
|
+
const state = { queue: 0, queuedBits: 0 }
|
|
297
|
+
|
|
298
|
+
const onChar = (char: string) => {
|
|
299
|
+
result.push(char)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
bytes.forEach((byte) => byteToBase64URL(byte, state, onChar))
|
|
303
|
+
|
|
304
|
+
// always call with `null` after processing all bytes
|
|
305
|
+
byteToBase64URL(null, state, onChar)
|
|
306
|
+
|
|
307
|
+
return result.join('')
|
|
308
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { version } from './version'
|
|
2
|
+
|
|
3
|
+
/** Current session will be checked for refresh at this interval. */
|
|
4
|
+
export const AUTO_REFRESH_TICK_DURATION_MS = 30 * 1000
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A token refresh will be attempted this many ticks before the current session expires. */
|
|
8
|
+
export const AUTO_REFRESH_TICK_THRESHOLD = 3
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Earliest time before an access token expires that the session should be refreshed.
|
|
12
|
+
*/
|
|
13
|
+
export const EXPIRY_MARGIN_MS = AUTO_REFRESH_TICK_THRESHOLD * AUTO_REFRESH_TICK_DURATION_MS
|
|
14
|
+
|
|
15
|
+
export const GOTRUE_URL = 'http://localhost:9999'
|
|
16
|
+
export const STORAGE_KEY = 'supabase.auth.token'
|
|
17
|
+
export const AUDIENCE = ''
|
|
18
|
+
export const DEFAULT_HEADERS = { 'X-Client-Info': `gotrue-js/${version}` }
|
|
19
|
+
export const NETWORK_FAILURE = {
|
|
20
|
+
MAX_RETRIES: 10,
|
|
21
|
+
RETRY_INTERVAL: 2, // in deciseconds
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const API_VERSION_HEADER_NAME = 'X-Supabase-Api-Version'
|
|
25
|
+
export const API_VERSIONS = {
|
|
26
|
+
'2024-01-01': {
|
|
27
|
+
timestamp: Date.parse('2024-01-01T00:00:00.0Z'),
|
|
28
|
+
name: '2024-01-01',
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const BASE64URL_REGEX = /^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$/i
|
|
33
|
+
|
|
34
|
+
export const JWKS_TTL = 10 * 60 * 1000 // 10 minutes
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Known error codes. Note that the server may also return other error codes
|
|
3
|
+
* not included in this list (if the client library is older than the version
|
|
4
|
+
* on the server).
|
|
5
|
+
*/
|
|
6
|
+
export type ErrorCode =
|
|
7
|
+
| 'unexpected_failure'
|
|
8
|
+
| 'validation_failed'
|
|
9
|
+
| 'bad_json'
|
|
10
|
+
| 'email_exists'
|
|
11
|
+
| 'phone_exists'
|
|
12
|
+
| 'bad_jwt'
|
|
13
|
+
| 'not_admin'
|
|
14
|
+
| 'no_authorization'
|
|
15
|
+
| 'user_not_found'
|
|
16
|
+
| 'session_not_found'
|
|
17
|
+
| 'session_expired'
|
|
18
|
+
| 'refresh_token_not_found'
|
|
19
|
+
| 'refresh_token_already_used'
|
|
20
|
+
| 'flow_state_not_found'
|
|
21
|
+
| 'flow_state_expired'
|
|
22
|
+
| 'signup_disabled'
|
|
23
|
+
| 'user_banned'
|
|
24
|
+
| 'provider_email_needs_verification'
|
|
25
|
+
| 'invite_not_found'
|
|
26
|
+
| 'bad_oauth_state'
|
|
27
|
+
| 'bad_oauth_callback'
|
|
28
|
+
| 'oauth_provider_not_supported'
|
|
29
|
+
| 'unexpected_audience'
|
|
30
|
+
| 'single_identity_not_deletable'
|
|
31
|
+
| 'email_conflict_identity_not_deletable'
|
|
32
|
+
| 'identity_already_exists'
|
|
33
|
+
| 'email_provider_disabled'
|
|
34
|
+
| 'phone_provider_disabled'
|
|
35
|
+
| 'too_many_enrolled_mfa_factors'
|
|
36
|
+
| 'mfa_factor_name_conflict'
|
|
37
|
+
| 'mfa_factor_not_found'
|
|
38
|
+
| 'mfa_ip_address_mismatch'
|
|
39
|
+
| 'mfa_challenge_expired'
|
|
40
|
+
| 'mfa_verification_failed'
|
|
41
|
+
| 'mfa_verification_rejected'
|
|
42
|
+
| 'insufficient_aal'
|
|
43
|
+
| 'captcha_failed'
|
|
44
|
+
| 'saml_provider_disabled'
|
|
45
|
+
| 'manual_linking_disabled'
|
|
46
|
+
| 'sms_send_failed'
|
|
47
|
+
| 'email_not_confirmed'
|
|
48
|
+
| 'phone_not_confirmed'
|
|
49
|
+
| 'reauth_nonce_missing'
|
|
50
|
+
| 'saml_relay_state_not_found'
|
|
51
|
+
| 'saml_relay_state_expired'
|
|
52
|
+
| 'saml_idp_not_found'
|
|
53
|
+
| 'saml_assertion_no_user_id'
|
|
54
|
+
| 'saml_assertion_no_email'
|
|
55
|
+
| 'user_already_exists'
|
|
56
|
+
| 'sso_provider_not_found'
|
|
57
|
+
| 'saml_metadata_fetch_failed'
|
|
58
|
+
| 'saml_idp_already_exists'
|
|
59
|
+
| 'sso_domain_already_exists'
|
|
60
|
+
| 'saml_entity_id_mismatch'
|
|
61
|
+
| 'conflict'
|
|
62
|
+
| 'provider_disabled'
|
|
63
|
+
| 'user_sso_managed'
|
|
64
|
+
| 'reauthentication_needed'
|
|
65
|
+
| 'same_password'
|
|
66
|
+
| 'reauthentication_not_valid'
|
|
67
|
+
| 'otp_expired'
|
|
68
|
+
| 'otp_disabled'
|
|
69
|
+
| 'identity_not_found'
|
|
70
|
+
| 'weak_password'
|
|
71
|
+
| 'over_request_rate_limit'
|
|
72
|
+
| 'over_email_send_rate_limit'
|
|
73
|
+
| 'over_sms_send_rate_limit'
|
|
74
|
+
| 'bad_code_verifier'
|
|
75
|
+
| 'anonymous_provider_disabled'
|
|
76
|
+
| 'hook_timeout'
|
|
77
|
+
| 'hook_timeout_after_retry'
|
|
78
|
+
| 'hook_payload_over_size_limit'
|
|
79
|
+
| 'hook_payload_invalid_content_type'
|
|
80
|
+
| 'request_timeout'
|
|
81
|
+
| 'mfa_phone_enroll_not_enabled'
|
|
82
|
+
| 'mfa_phone_verify_not_enabled'
|
|
83
|
+
| 'mfa_totp_enroll_not_enabled'
|
|
84
|
+
| 'mfa_totp_verify_not_enabled'
|
|
85
|
+
| 'mfa_webauthn_enroll_not_enabled'
|
|
86
|
+
| 'mfa_webauthn_verify_not_enabled'
|
|
87
|
+
| 'mfa_verified_factor_exists'
|
|
88
|
+
| 'invalid_credentials'
|
|
89
|
+
| 'email_address_not_authorized'
|
|
90
|
+
| 'email_address_invalid'
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { WeakPasswordReasons } from './types'
|
|
2
|
+
import { ErrorCode } from './error-codes'
|
|
3
|
+
|
|
4
|
+
export class AuthError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Error code associated with the error. Most errors coming from
|
|
7
|
+
* HTTP responses will have a code, though some errors that occur
|
|
8
|
+
* before a response is received will not have one present. In that
|
|
9
|
+
* case {@link #status} will also be undefined.
|
|
10
|
+
*/
|
|
11
|
+
code: ErrorCode | (string & {}) | undefined
|
|
12
|
+
|
|
13
|
+
/** HTTP status code that caused the error. */
|
|
14
|
+
status: number | undefined
|
|
15
|
+
|
|
16
|
+
protected __isAuthError = true
|
|
17
|
+
|
|
18
|
+
constructor(message: string, status?: number, code?: string) {
|
|
19
|
+
super(message)
|
|
20
|
+
this.name = 'AuthError'
|
|
21
|
+
this.status = status
|
|
22
|
+
this.code = code
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isAuthError(error: unknown): error is AuthError {
|
|
27
|
+
return typeof error === 'object' && error !== null && '__isAuthError' in error
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class AuthApiError extends AuthError {
|
|
31
|
+
status: number
|
|
32
|
+
|
|
33
|
+
constructor(message: string, status: number, code: string | undefined) {
|
|
34
|
+
super(message, status, code)
|
|
35
|
+
this.name = 'AuthApiError'
|
|
36
|
+
this.status = status
|
|
37
|
+
this.code = code
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function isAuthApiError(error: unknown): error is AuthApiError {
|
|
42
|
+
return isAuthError(error) && error.name === 'AuthApiError'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class AuthUnknownError extends AuthError {
|
|
46
|
+
originalError: unknown
|
|
47
|
+
|
|
48
|
+
constructor(message: string, originalError: unknown) {
|
|
49
|
+
super(message)
|
|
50
|
+
this.name = 'AuthUnknownError'
|
|
51
|
+
this.originalError = originalError
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class CustomAuthError extends AuthError {
|
|
56
|
+
name: string
|
|
57
|
+
status: number
|
|
58
|
+
|
|
59
|
+
constructor(message: string, name: string, status: number, code: string | undefined) {
|
|
60
|
+
super(message, status, code)
|
|
61
|
+
this.name = name
|
|
62
|
+
this.status = status
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class AuthSessionMissingError extends CustomAuthError {
|
|
67
|
+
constructor() {
|
|
68
|
+
super('Auth session missing!', 'AuthSessionMissingError', 400, undefined)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function isAuthSessionMissingError(error: any): error is AuthSessionMissingError {
|
|
73
|
+
return isAuthError(error) && error.name === 'AuthSessionMissingError'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class AuthInvalidTokenResponseError extends CustomAuthError {
|
|
77
|
+
constructor() {
|
|
78
|
+
super('Auth session or user missing', 'AuthInvalidTokenResponseError', 500, undefined)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class AuthInvalidCredentialsError extends CustomAuthError {
|
|
83
|
+
constructor(message: string) {
|
|
84
|
+
super(message, 'AuthInvalidCredentialsError', 400, undefined)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class AuthImplicitGrantRedirectError extends CustomAuthError {
|
|
89
|
+
details: { error: string; code: string } | null = null
|
|
90
|
+
constructor(message: string, details: { error: string; code: string } | null = null) {
|
|
91
|
+
super(message, 'AuthImplicitGrantRedirectError', 500, undefined)
|
|
92
|
+
this.details = details
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
toJSON() {
|
|
96
|
+
return {
|
|
97
|
+
name: this.name,
|
|
98
|
+
message: this.message,
|
|
99
|
+
status: this.status,
|
|
100
|
+
details: this.details,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function isAuthImplicitGrantRedirectError(
|
|
106
|
+
error: any
|
|
107
|
+
): error is AuthImplicitGrantRedirectError {
|
|
108
|
+
return isAuthError(error) && error.name === 'AuthImplicitGrantRedirectError'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export class AuthPKCEGrantCodeExchangeError extends CustomAuthError {
|
|
112
|
+
details: { error: string; code: string } | null = null
|
|
113
|
+
|
|
114
|
+
constructor(message: string, details: { error: string; code: string } | null = null) {
|
|
115
|
+
super(message, 'AuthPKCEGrantCodeExchangeError', 500, undefined)
|
|
116
|
+
this.details = details
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
toJSON() {
|
|
120
|
+
return {
|
|
121
|
+
name: this.name,
|
|
122
|
+
message: this.message,
|
|
123
|
+
status: this.status,
|
|
124
|
+
details: this.details,
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export class AuthRetryableFetchError extends CustomAuthError {
|
|
130
|
+
constructor(message: string, status: number) {
|
|
131
|
+
super(message, 'AuthRetryableFetchError', status, undefined)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function isAuthRetryableFetchError(error: unknown): error is AuthRetryableFetchError {
|
|
136
|
+
return isAuthError(error) && error.name === 'AuthRetryableFetchError'
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* This error is thrown on certain methods when the password used is deemed
|
|
141
|
+
* weak. Inspect the reasons to identify what password strength rules are
|
|
142
|
+
* inadequate.
|
|
143
|
+
*/
|
|
144
|
+
export class AuthWeakPasswordError extends CustomAuthError {
|
|
145
|
+
/**
|
|
146
|
+
* Reasons why the password is deemed weak.
|
|
147
|
+
*/
|
|
148
|
+
reasons: WeakPasswordReasons[]
|
|
149
|
+
|
|
150
|
+
constructor(message: string, status: number, reasons: WeakPasswordReasons[]) {
|
|
151
|
+
super(message, 'AuthWeakPasswordError', status, 'weak_password')
|
|
152
|
+
|
|
153
|
+
this.reasons = reasons
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function isAuthWeakPasswordError(error: unknown): error is AuthWeakPasswordError {
|
|
158
|
+
return isAuthError(error) && error.name === 'AuthWeakPasswordError'
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export class AuthInvalidJwtError extends CustomAuthError {
|
|
162
|
+
constructor(message: string) {
|
|
163
|
+
super(message, 'AuthInvalidJwtError', 400, 'invalid_jwt')
|
|
164
|
+
}
|
|
165
|
+
}
|