@supabase/gotrue-js 2.63.0-rc.rc.rc.rc.rc.11 → 2.63.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/dist/main/lib/constants.d.ts +7 -0
- package/dist/main/lib/constants.d.ts.map +1 -1
- package/dist/main/lib/constants.js +8 -1
- package/dist/main/lib/constants.js.map +1 -1
- 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 +12 -13
- package/dist/main/lib/errors.d.ts.map +1 -1
- package/dist/main/lib/errors.js +14 -26
- package/dist/main/lib/errors.js.map +1 -1
- package/dist/main/lib/fetch.d.ts +1 -0
- package/dist/main/lib/fetch.d.ts.map +1 -1
- package/dist/main/lib/fetch.js +33 -9
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/helpers.d.ts +1 -0
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +21 -1
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/version.js.map +1 -1
- package/dist/module/lib/constants.d.ts +7 -0
- package/dist/module/lib/constants.d.ts.map +1 -1
- package/dist/module/lib/constants.js +7 -0
- package/dist/module/lib/constants.js.map +1 -1
- 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 +12 -13
- package/dist/module/lib/errors.d.ts.map +1 -1
- package/dist/module/lib/errors.js +14 -26
- package/dist/module/lib/errors.js.map +1 -1
- package/dist/module/lib/fetch.d.ts +1 -0
- package/dist/module/lib/fetch.d.ts.map +1 -1
- package/dist/module/lib/fetch.js +33 -10
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/helpers.d.ts +1 -0
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +19 -0
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/version.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/constants.ts +8 -0
- package/src/lib/error-codes.ts +71 -0
- package/src/lib/errors.ts +27 -28
- package/src/lib/fetch.ts +44 -10
- package/src/lib/helpers.ts +24 -0
- package/src/lib/version.ts +1 -1
package/src/lib/fetch.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { API_VERSIONS, API_VERSION_HEADER_NAME } from './constants'
|
|
2
|
+
import { expiresAt, looksLikeFetchResponse, parseResponseAPIVersion } from './helpers'
|
|
2
3
|
import {
|
|
3
4
|
AuthResponse,
|
|
4
5
|
AuthResponsePassword,
|
|
@@ -35,7 +36,7 @@ const _getErrorMessage = (err: any): string =>
|
|
|
35
36
|
|
|
36
37
|
const NETWORK_ERROR_CODES = [502, 503, 504]
|
|
37
38
|
|
|
38
|
-
async function handleError(error: unknown) {
|
|
39
|
+
export async function handleError(error: unknown) {
|
|
39
40
|
if (!looksLikeFetchResponse(error)) {
|
|
40
41
|
throw new AuthRetryableFetchError(_getErrorMessage(error), 0)
|
|
41
42
|
}
|
|
@@ -52,23 +53,47 @@ async function handleError(error: unknown) {
|
|
|
52
53
|
throw new AuthUnknownError(_getErrorMessage(e), e)
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
let errorCode: string | undefined = undefined
|
|
57
|
+
|
|
58
|
+
const responseAPIVersion = parseResponseAPIVersion(error)
|
|
55
59
|
if (
|
|
60
|
+
responseAPIVersion &&
|
|
61
|
+
responseAPIVersion.getTime() >= API_VERSIONS['2024-01-01'].timestamp &&
|
|
56
62
|
typeof data === 'object' &&
|
|
57
63
|
data &&
|
|
58
|
-
typeof data.
|
|
59
|
-
data.weak_password &&
|
|
60
|
-
Array.isArray(data.weak_password.reasons) &&
|
|
61
|
-
data.weak_password.reasons.length &&
|
|
62
|
-
data.weak_password.reasons.reduce((a: boolean, i: any) => a && typeof i === 'string', true)
|
|
64
|
+
typeof data.code === 'string'
|
|
63
65
|
) {
|
|
66
|
+
errorCode = data.code
|
|
67
|
+
} else if (typeof data === 'object' && data && typeof data.error_code === 'string') {
|
|
68
|
+
errorCode = data.error_code
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!errorCode) {
|
|
72
|
+
// Legacy support for weak password errors, when there were no error codes
|
|
73
|
+
if (
|
|
74
|
+
typeof data === 'object' &&
|
|
75
|
+
data &&
|
|
76
|
+
typeof data.weak_password === 'object' &&
|
|
77
|
+
data.weak_password &&
|
|
78
|
+
Array.isArray(data.weak_password.reasons) &&
|
|
79
|
+
data.weak_password.reasons.length &&
|
|
80
|
+
data.weak_password.reasons.reduce((a: boolean, i: any) => a && typeof i === 'string', true)
|
|
81
|
+
) {
|
|
82
|
+
throw new AuthWeakPasswordError(
|
|
83
|
+
_getErrorMessage(data),
|
|
84
|
+
error.status,
|
|
85
|
+
data.weak_password.reasons
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
} else if (errorCode === 'weak_password') {
|
|
64
89
|
throw new AuthWeakPasswordError(
|
|
65
90
|
_getErrorMessage(data),
|
|
66
91
|
error.status,
|
|
67
|
-
data.weak_password
|
|
92
|
+
data.weak_password?.reasons || []
|
|
68
93
|
)
|
|
69
94
|
}
|
|
70
95
|
|
|
71
|
-
throw new AuthApiError(_getErrorMessage(data), error.status || 500)
|
|
96
|
+
throw new AuthApiError(_getErrorMessage(data), error.status || 500, errorCode)
|
|
72
97
|
}
|
|
73
98
|
|
|
74
99
|
const _getRequestParams = (
|
|
@@ -105,14 +130,23 @@ export async function _request(
|
|
|
105
130
|
url: string,
|
|
106
131
|
options?: GotrueRequestOptions
|
|
107
132
|
) {
|
|
108
|
-
const headers = {
|
|
133
|
+
const headers = {
|
|
134
|
+
...options?.headers,
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!headers[API_VERSION_HEADER_NAME]) {
|
|
138
|
+
headers[API_VERSION_HEADER_NAME] = API_VERSIONS['2024-01-01'].name
|
|
139
|
+
}
|
|
140
|
+
|
|
109
141
|
if (options?.jwt) {
|
|
110
142
|
headers['Authorization'] = `Bearer ${options.jwt}`
|
|
111
143
|
}
|
|
144
|
+
|
|
112
145
|
const qs = options?.query ?? {}
|
|
113
146
|
if (options?.redirectTo) {
|
|
114
147
|
qs['redirect_to'] = options.redirectTo
|
|
115
148
|
}
|
|
149
|
+
|
|
116
150
|
const queryString = Object.keys(qs).length ? '?' + new URLSearchParams(qs).toString() : ''
|
|
117
151
|
const data = await _handleRequest(
|
|
118
152
|
fetcher,
|
package/src/lib/helpers.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { API_VERSION_HEADER_NAME } from './constants'
|
|
1
2
|
import { SupportedStorage } from './types'
|
|
3
|
+
|
|
2
4
|
export function expiresAt(expiresIn: number) {
|
|
3
5
|
const timeNow = Math.round(Date.now() / 1000)
|
|
4
6
|
return timeNow + expiresIn
|
|
@@ -320,3 +322,25 @@ export async function getCodeChallengeAndMethod(
|
|
|
320
322
|
const codeChallengeMethod = codeVerifier === codeChallenge ? 'plain' : 's256'
|
|
321
323
|
return [codeChallenge, codeChallengeMethod]
|
|
322
324
|
}
|
|
325
|
+
|
|
326
|
+
/** Parses the API version which is 2YYY-MM-DD. */
|
|
327
|
+
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
|
|
328
|
+
|
|
329
|
+
export function parseResponseAPIVersion(response: Response) {
|
|
330
|
+
const apiVersion = response.headers.get(API_VERSION_HEADER_NAME)
|
|
331
|
+
|
|
332
|
+
if (!apiVersion) {
|
|
333
|
+
return null
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (!apiVersion.match(API_VERSION_REGEX)) {
|
|
337
|
+
return null
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
const date = new Date(`${apiVersion}T00:00:00.0Z`)
|
|
342
|
+
return date
|
|
343
|
+
} catch (e: any) {
|
|
344
|
+
return null
|
|
345
|
+
}
|
|
346
|
+
}
|
package/src/lib/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.63.0
|
|
1
|
+
export const version = '2.63.0'
|