@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,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JWKS_TTL = exports.BASE64URL_REGEX = exports.API_VERSIONS = exports.API_VERSION_HEADER_NAME = exports.NETWORK_FAILURE = exports.DEFAULT_HEADERS = exports.AUDIENCE = exports.STORAGE_KEY = exports.GOTRUE_URL = exports.EXPIRY_MARGIN_MS = exports.AUTO_REFRESH_TICK_THRESHOLD = exports.AUTO_REFRESH_TICK_DURATION_MS = void 0;
|
|
4
|
+
const version_1 = require("./version");
|
|
5
|
+
/** Current session will be checked for refresh at this interval. */
|
|
6
|
+
exports.AUTO_REFRESH_TICK_DURATION_MS = 30 * 1000;
|
|
7
|
+
/**
|
|
8
|
+
* A token refresh will be attempted this many ticks before the current session expires. */
|
|
9
|
+
exports.AUTO_REFRESH_TICK_THRESHOLD = 3;
|
|
10
|
+
/*
|
|
11
|
+
* Earliest time before an access token expires that the session should be refreshed.
|
|
12
|
+
*/
|
|
13
|
+
exports.EXPIRY_MARGIN_MS = exports.AUTO_REFRESH_TICK_THRESHOLD * exports.AUTO_REFRESH_TICK_DURATION_MS;
|
|
14
|
+
exports.GOTRUE_URL = 'http://localhost:9999';
|
|
15
|
+
exports.STORAGE_KEY = 'supabase.auth.token';
|
|
16
|
+
exports.AUDIENCE = '';
|
|
17
|
+
exports.DEFAULT_HEADERS = { 'X-Client-Info': `gotrue-js/${version_1.version}` };
|
|
18
|
+
exports.NETWORK_FAILURE = {
|
|
19
|
+
MAX_RETRIES: 10,
|
|
20
|
+
RETRY_INTERVAL: 2, // in deciseconds
|
|
21
|
+
};
|
|
22
|
+
exports.API_VERSION_HEADER_NAME = 'X-Supabase-Api-Version';
|
|
23
|
+
exports.API_VERSIONS = {
|
|
24
|
+
'2024-01-01': {
|
|
25
|
+
timestamp: Date.parse('2024-01-01T00:00:00.0Z'),
|
|
26
|
+
name: '2024-01-01',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
exports.BASE64URL_REGEX = /^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$/i;
|
|
30
|
+
exports.JWKS_TTL = 600000; // 10 minutes
|
|
31
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAEnC,oEAAoE;AACvD,QAAA,6BAA6B,GAAG,EAAE,GAAG,IAAI,CAAA;AAEtD;2FAC2F;AAC9E,QAAA,2BAA2B,GAAG,CAAC,CAAA;AAE5C;;GAEG;AACU,QAAA,gBAAgB,GAAG,mCAA2B,GAAG,qCAA6B,CAAA;AAE9E,QAAA,UAAU,GAAG,uBAAuB,CAAA;AACpC,QAAA,WAAW,GAAG,qBAAqB,CAAA;AACnC,QAAA,QAAQ,GAAG,EAAE,CAAA;AACb,QAAA,eAAe,GAAG,EAAE,eAAe,EAAE,aAAa,iBAAO,EAAE,EAAE,CAAA;AAC7D,QAAA,eAAe,GAAG;IAC7B,WAAW,EAAE,EAAE;IACf,cAAc,EAAE,CAAC,EAAE,iBAAiB;CACrC,CAAA;AAEY,QAAA,uBAAuB,GAAG,wBAAwB,CAAA;AAClD,QAAA,YAAY,GAAG;IAC1B,YAAY,EAAE;QACZ,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC;QAC/C,IAAI,EAAE,YAAY;KACnB;CACF,CAAA;AAEY,QAAA,eAAe,GAAG,sDAAsD,CAAA;AAExE,QAAA,QAAQ,GAAG,MAAM,CAAA,CAAC,aAAa"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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 = 'unexpected_failure' | 'validation_failed' | 'bad_json' | 'email_exists' | 'phone_exists' | 'bad_jwt' | 'not_admin' | 'no_authorization' | 'user_not_found' | 'session_not_found' | 'session_expired' | 'refresh_token_not_found' | 'refresh_token_already_used' | 'flow_state_not_found' | 'flow_state_expired' | 'signup_disabled' | 'user_banned' | 'provider_email_needs_verification' | 'invite_not_found' | 'bad_oauth_state' | 'bad_oauth_callback' | 'oauth_provider_not_supported' | 'unexpected_audience' | 'single_identity_not_deletable' | 'email_conflict_identity_not_deletable' | 'identity_already_exists' | 'email_provider_disabled' | 'phone_provider_disabled' | 'too_many_enrolled_mfa_factors' | 'mfa_factor_name_conflict' | 'mfa_factor_not_found' | 'mfa_ip_address_mismatch' | 'mfa_challenge_expired' | 'mfa_verification_failed' | 'mfa_verification_rejected' | 'insufficient_aal' | 'captcha_failed' | 'saml_provider_disabled' | 'manual_linking_disabled' | 'sms_send_failed' | 'email_not_confirmed' | 'phone_not_confirmed' | 'reauth_nonce_missing' | 'saml_relay_state_not_found' | 'saml_relay_state_expired' | 'saml_idp_not_found' | 'saml_assertion_no_user_id' | 'saml_assertion_no_email' | 'user_already_exists' | 'sso_provider_not_found' | 'saml_metadata_fetch_failed' | 'saml_idp_already_exists' | 'sso_domain_already_exists' | 'saml_entity_id_mismatch' | 'conflict' | 'provider_disabled' | 'user_sso_managed' | 'reauthentication_needed' | 'same_password' | 'reauthentication_not_valid' | 'otp_expired' | 'otp_disabled' | 'identity_not_found' | 'weak_password' | 'over_request_rate_limit' | 'over_email_send_rate_limit' | 'over_sms_send_rate_limit' | 'bad_code_verifier' | 'anonymous_provider_disabled' | 'hook_timeout' | 'hook_timeout_after_retry' | 'hook_payload_over_size_limit' | 'hook_payload_invalid_content_type' | 'request_timeout' | 'mfa_phone_enroll_not_enabled' | 'mfa_phone_verify_not_enabled' | 'mfa_totp_enroll_not_enabled' | 'mfa_totp_verify_not_enabled' | 'mfa_webauthn_enroll_not_enabled' | 'mfa_webauthn_verify_not_enabled' | 'mfa_verified_factor_exists' | 'invalid_credentials' | 'email_address_not_authorized' | 'email_address_invalid';
|
|
7
|
+
//# sourceMappingURL=error-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../../src/utils/error-codes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB,oBAAoB,GACpB,mBAAmB,GACnB,UAAU,GACV,cAAc,GACd,cAAc,GACd,SAAS,GACT,WAAW,GACX,kBAAkB,GAClB,gBAAgB,GAChB,mBAAmB,GACnB,iBAAiB,GACjB,yBAAyB,GACzB,4BAA4B,GAC5B,sBAAsB,GACtB,oBAAoB,GACpB,iBAAiB,GACjB,aAAa,GACb,mCAAmC,GACnC,kBAAkB,GAClB,iBAAiB,GACjB,oBAAoB,GACpB,8BAA8B,GAC9B,qBAAqB,GACrB,+BAA+B,GAC/B,uCAAuC,GACvC,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,+BAA+B,GAC/B,0BAA0B,GAC1B,sBAAsB,GACtB,yBAAyB,GACzB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,GAC3B,kBAAkB,GAClB,gBAAgB,GAChB,wBAAwB,GACxB,yBAAyB,GACzB,iBAAiB,GACjB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,4BAA4B,GAC5B,0BAA0B,GAC1B,oBAAoB,GACpB,2BAA2B,GAC3B,yBAAyB,GACzB,qBAAqB,GACrB,wBAAwB,GACxB,4BAA4B,GAC5B,yBAAyB,GACzB,2BAA2B,GAC3B,yBAAyB,GACzB,UAAU,GACV,mBAAmB,GACnB,kBAAkB,GAClB,yBAAyB,GACzB,eAAe,GACf,4BAA4B,GAC5B,aAAa,GACb,cAAc,GACd,oBAAoB,GACpB,eAAe,GACf,yBAAyB,GACzB,4BAA4B,GAC5B,0BAA0B,GAC1B,mBAAmB,GACnB,6BAA6B,GAC7B,cAAc,GACd,0BAA0B,GAC1B,8BAA8B,GAC9B,mCAAmC,GACnC,iBAAiB,GACjB,8BAA8B,GAC9B,8BAA8B,GAC9B,6BAA6B,GAC7B,6BAA6B,GAC7B,iCAAiC,GACjC,iCAAiC,GACjC,4BAA4B,GAC5B,qBAAqB,GACrB,8BAA8B,GAC9B,uBAAuB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes.js","sourceRoot":"","sources":["../../../src/utils/error-codes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { WeakPasswordReasons } from './types';
|
|
2
|
+
import { ErrorCode } from './error-codes';
|
|
3
|
+
export declare class AuthError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* Error code associated with the error. Most errors coming from
|
|
6
|
+
* HTTP responses will have a code, though some errors that occur
|
|
7
|
+
* before a response is received will not have one present. In that
|
|
8
|
+
* case {@link #status} will also be undefined.
|
|
9
|
+
*/
|
|
10
|
+
code: ErrorCode | (string & {}) | undefined;
|
|
11
|
+
/** HTTP status code that caused the error. */
|
|
12
|
+
status: number | undefined;
|
|
13
|
+
protected __isAuthError: boolean;
|
|
14
|
+
constructor(message: string, status?: number, code?: string);
|
|
15
|
+
}
|
|
16
|
+
export declare function isAuthError(error: unknown): error is AuthError;
|
|
17
|
+
export declare class AuthApiError extends AuthError {
|
|
18
|
+
status: number;
|
|
19
|
+
constructor(message: string, status: number, code: string | undefined);
|
|
20
|
+
}
|
|
21
|
+
export declare function isAuthApiError(error: unknown): error is AuthApiError;
|
|
22
|
+
export declare class AuthUnknownError extends AuthError {
|
|
23
|
+
originalError: unknown;
|
|
24
|
+
constructor(message: string, originalError: unknown);
|
|
25
|
+
}
|
|
26
|
+
export declare class CustomAuthError extends AuthError {
|
|
27
|
+
name: string;
|
|
28
|
+
status: number;
|
|
29
|
+
constructor(message: string, name: string, status: number, code: string | undefined);
|
|
30
|
+
}
|
|
31
|
+
export declare class AuthSessionMissingError extends CustomAuthError {
|
|
32
|
+
constructor();
|
|
33
|
+
}
|
|
34
|
+
export declare function isAuthSessionMissingError(error: any): error is AuthSessionMissingError;
|
|
35
|
+
export declare class AuthInvalidTokenResponseError extends CustomAuthError {
|
|
36
|
+
constructor();
|
|
37
|
+
}
|
|
38
|
+
export declare class AuthInvalidCredentialsError extends CustomAuthError {
|
|
39
|
+
constructor(message: string);
|
|
40
|
+
}
|
|
41
|
+
export declare class AuthImplicitGrantRedirectError extends CustomAuthError {
|
|
42
|
+
details: {
|
|
43
|
+
error: string;
|
|
44
|
+
code: string;
|
|
45
|
+
} | null;
|
|
46
|
+
constructor(message: string, details?: {
|
|
47
|
+
error: string;
|
|
48
|
+
code: string;
|
|
49
|
+
} | null);
|
|
50
|
+
toJSON(): {
|
|
51
|
+
name: string;
|
|
52
|
+
message: string;
|
|
53
|
+
status: number;
|
|
54
|
+
details: {
|
|
55
|
+
error: string;
|
|
56
|
+
code: string;
|
|
57
|
+
} | null;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export declare function isAuthImplicitGrantRedirectError(error: any): error is AuthImplicitGrantRedirectError;
|
|
61
|
+
export declare class AuthPKCEGrantCodeExchangeError extends CustomAuthError {
|
|
62
|
+
details: {
|
|
63
|
+
error: string;
|
|
64
|
+
code: string;
|
|
65
|
+
} | null;
|
|
66
|
+
constructor(message: string, details?: {
|
|
67
|
+
error: string;
|
|
68
|
+
code: string;
|
|
69
|
+
} | null);
|
|
70
|
+
toJSON(): {
|
|
71
|
+
name: string;
|
|
72
|
+
message: string;
|
|
73
|
+
status: number;
|
|
74
|
+
details: {
|
|
75
|
+
error: string;
|
|
76
|
+
code: string;
|
|
77
|
+
} | null;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export declare class AuthRetryableFetchError extends CustomAuthError {
|
|
81
|
+
constructor(message: string, status: number);
|
|
82
|
+
}
|
|
83
|
+
export declare function isAuthRetryableFetchError(error: unknown): error is AuthRetryableFetchError;
|
|
84
|
+
/**
|
|
85
|
+
* This error is thrown on certain methods when the password used is deemed
|
|
86
|
+
* weak. Inspect the reasons to identify what password strength rules are
|
|
87
|
+
* inadequate.
|
|
88
|
+
*/
|
|
89
|
+
export declare class AuthWeakPasswordError extends CustomAuthError {
|
|
90
|
+
/**
|
|
91
|
+
* Reasons why the password is deemed weak.
|
|
92
|
+
*/
|
|
93
|
+
reasons: WeakPasswordReasons[];
|
|
94
|
+
constructor(message: string, status: number, reasons: string[]);
|
|
95
|
+
}
|
|
96
|
+
export declare function isAuthWeakPasswordError(error: unknown): error is AuthWeakPasswordError;
|
|
97
|
+
export declare class AuthInvalidJwtError extends CustomAuthError {
|
|
98
|
+
constructor(message: string);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,qBAAa,SAAU,SAAQ,KAAK;IAClC;;;;;OAKG;IACH,IAAI,EAAE,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,SAAS,CAAA;IAE3C,8CAA8C;IAC9C,M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C;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAW;IAKnF,MAAM;;;;;;;;;CAQP;AAED,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,GAAG,GACT,KAAK,IAAI,8BAA8B,CAEzC;AAED,qBAAa,8BAA+B,SAAQ,eAAe;IACjE,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAO;gBAE1C,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAW;IAKnF,MAAM;;;;;;;;;CAQP;AAED,qBAAa,uBAAwB,SAAQ,eAAe;gBAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAG5C;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,uBAAuB,CAE1F;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,eAAe;IACxD;;OAEG;IACH,OAAO,EAAE,mBAAmB,EAAE,CAAA;gBAElB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;CAK/D;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAEtF;AAED,qBAAa,mBAAoB,SAAQ,eAAe;gBAC1C,OAAO,EAAE,MAAM;CAG5B"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthInvalidJwtError = exports.isAuthWeakPasswordError = exports.AuthWeakPasswordError = exports.isAuthRetryableFetchError = exports.AuthRetryableFetchError = exports.AuthPKCEGrantCodeExchangeError = exports.isAuthImplicitGrantRedirectError = exports.AuthImplicitGrantRedirectError = exports.AuthInvalidCredentialsError = exports.AuthInvalidTokenResponseError = exports.isAuthSessionMissingError = exports.AuthSessionMissingError = exports.CustomAuthError = exports.AuthUnknownError = exports.isAuthApiError = exports.AuthApiError = exports.isAuthError = exports.AuthError = void 0;
|
|
4
|
+
class AuthError extends Error {
|
|
5
|
+
constructor(message, status, code) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.__isAuthError = true;
|
|
8
|
+
this.name = 'AuthError';
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.AuthError = AuthError;
|
|
14
|
+
function isAuthError(error) {
|
|
15
|
+
return typeof error === 'object' && error !== null && '__isAuthError' in error;
|
|
16
|
+
}
|
|
17
|
+
exports.isAuthError = isAuthError;
|
|
18
|
+
class AuthApiError extends AuthError {
|
|
19
|
+
constructor(message, status, code) {
|
|
20
|
+
super(message, status, code);
|
|
21
|
+
this.name = 'AuthApiError';
|
|
22
|
+
this.status = status;
|
|
23
|
+
this.code = code;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.AuthApiError = AuthApiError;
|
|
27
|
+
function isAuthApiError(error) {
|
|
28
|
+
return isAuthError(error) && error.name === 'AuthApiError';
|
|
29
|
+
}
|
|
30
|
+
exports.isAuthApiError = isAuthApiError;
|
|
31
|
+
class AuthUnknownError extends AuthError {
|
|
32
|
+
constructor(message, originalError) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = 'AuthUnknownError';
|
|
35
|
+
this.originalError = originalError;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.AuthUnknownError = AuthUnknownError;
|
|
39
|
+
class CustomAuthError extends AuthError {
|
|
40
|
+
constructor(message, name, status, code) {
|
|
41
|
+
super(message, status, code);
|
|
42
|
+
this.name = name;
|
|
43
|
+
this.status = status;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.CustomAuthError = CustomAuthError;
|
|
47
|
+
class AuthSessionMissingError extends CustomAuthError {
|
|
48
|
+
constructor() {
|
|
49
|
+
super('Auth session missing!', 'AuthSessionMissingError', 400, undefined);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.AuthSessionMissingError = AuthSessionMissingError;
|
|
53
|
+
function isAuthSessionMissingError(error) {
|
|
54
|
+
return isAuthError(error) && error.name === 'AuthSessionMissingError';
|
|
55
|
+
}
|
|
56
|
+
exports.isAuthSessionMissingError = isAuthSessionMissingError;
|
|
57
|
+
class AuthInvalidTokenResponseError extends CustomAuthError {
|
|
58
|
+
constructor() {
|
|
59
|
+
super('Auth session or user missing', 'AuthInvalidTokenResponseError', 500, undefined);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.AuthInvalidTokenResponseError = AuthInvalidTokenResponseError;
|
|
63
|
+
class AuthInvalidCredentialsError extends CustomAuthError {
|
|
64
|
+
constructor(message) {
|
|
65
|
+
super(message, 'AuthInvalidCredentialsError', 400, undefined);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.AuthInvalidCredentialsError = AuthInvalidCredentialsError;
|
|
69
|
+
class AuthImplicitGrantRedirectError extends CustomAuthError {
|
|
70
|
+
constructor(message, details = null) {
|
|
71
|
+
super(message, 'AuthImplicitGrantRedirectError', 500, undefined);
|
|
72
|
+
this.details = null;
|
|
73
|
+
this.details = details;
|
|
74
|
+
}
|
|
75
|
+
toJSON() {
|
|
76
|
+
return {
|
|
77
|
+
name: this.name,
|
|
78
|
+
message: this.message,
|
|
79
|
+
status: this.status,
|
|
80
|
+
details: this.details,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.AuthImplicitGrantRedirectError = AuthImplicitGrantRedirectError;
|
|
85
|
+
function isAuthImplicitGrantRedirectError(error) {
|
|
86
|
+
return isAuthError(error) && error.name === 'AuthImplicitGrantRedirectError';
|
|
87
|
+
}
|
|
88
|
+
exports.isAuthImplicitGrantRedirectError = isAuthImplicitGrantRedirectError;
|
|
89
|
+
class AuthPKCEGrantCodeExchangeError extends CustomAuthError {
|
|
90
|
+
constructor(message, details = null) {
|
|
91
|
+
super(message, 'AuthPKCEGrantCodeExchangeError', 500, undefined);
|
|
92
|
+
this.details = null;
|
|
93
|
+
this.details = details;
|
|
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
|
+
exports.AuthPKCEGrantCodeExchangeError = AuthPKCEGrantCodeExchangeError;
|
|
105
|
+
class AuthRetryableFetchError extends CustomAuthError {
|
|
106
|
+
constructor(message, status) {
|
|
107
|
+
super(message, 'AuthRetryableFetchError', status, undefined);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.AuthRetryableFetchError = AuthRetryableFetchError;
|
|
111
|
+
function isAuthRetryableFetchError(error) {
|
|
112
|
+
return isAuthError(error) && error.name === 'AuthRetryableFetchError';
|
|
113
|
+
}
|
|
114
|
+
exports.isAuthRetryableFetchError = isAuthRetryableFetchError;
|
|
115
|
+
/**
|
|
116
|
+
* This error is thrown on certain methods when the password used is deemed
|
|
117
|
+
* weak. Inspect the reasons to identify what password strength rules are
|
|
118
|
+
* inadequate.
|
|
119
|
+
*/
|
|
120
|
+
class AuthWeakPasswordError extends CustomAuthError {
|
|
121
|
+
constructor(message, status, reasons) {
|
|
122
|
+
super(message, 'AuthWeakPasswordError', status, 'weak_password');
|
|
123
|
+
this.reasons = reasons;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.AuthWeakPasswordError = AuthWeakPasswordError;
|
|
127
|
+
function isAuthWeakPasswordError(error) {
|
|
128
|
+
return isAuthError(error) && error.name === 'AuthWeakPasswordError';
|
|
129
|
+
}
|
|
130
|
+
exports.isAuthWeakPasswordError = isAuthWeakPasswordError;
|
|
131
|
+
class AuthInvalidJwtError extends CustomAuthError {
|
|
132
|
+
constructor(message) {
|
|
133
|
+
super(message, 'AuthInvalidJwtError', 400, 'invalid_jwt');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.AuthInvalidJwtError = AuthInvalidJwtError;
|
|
137
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":";;;AAGA,MAAa,SAAU,SAAQ,KAAK;IAclC,YAAY,OAAe,EAAE,MAAe,EAAE,IAAa;QACzD,KAAK,CAAC,OAAO,CAAC,CAAA;QAHN,kBAAa,GAAG,IAAI,CAAA;QAI5B,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AApBD,8BAoBC;AAED,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,eAAe,IAAI,KAAK,CAAA;AAChF,CAAC;AAFD,kCAEC;AAED,MAAa,YAAa,SAAQ,SAAS;IAGzC,YAAY,OAAe,EAAE,MAAc,EAAE,IAAwB;QACnE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AATD,oCASC;AAED,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,CAAA;AAC5D,CAAC;AAFD,wCAEC;AAED,MAAa,gBAAiB,SAAQ,SAAS;IAG7C,YAAY,OAAe,EAAE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AuB,EAAE,MAAM,EAAE,eAAe,CAAC,CAAA;QAEhE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AAXD,sDAWC;AAED,SAAgB,uBAAuB,CAAC,KAAc;IACpD,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,uBAAuB,CAAA;AACrE,CAAC;AAFD,0DAEC;AAED,MAAa,mBAAoB,SAAQ,eAAe;IACtD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,GAAG,EAAE,aAAa,CAAC,CAAA;IAC3D,CAAC;CACF;AAJD,kDAIC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AuthResponse, AuthResponsePassword, SSOResponse, GenerateLinkResponse, UserResponse } from './types';
|
|
2
|
+
export type Fetch = typeof fetch;
|
|
3
|
+
export interface FetchOptions {
|
|
4
|
+
headers?: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
7
|
+
noResolveJson?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface FetchParameters {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
export type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
13
|
+
export declare function handleError(error: unknown): Promise<void>;
|
|
14
|
+
interface GotrueRequestOptions extends FetchOptions {
|
|
15
|
+
jwt?: string;
|
|
16
|
+
redirectTo?: string;
|
|
17
|
+
body?: object;
|
|
18
|
+
query?: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Function that transforms api response from gotrue into a desirable / standardised format
|
|
23
|
+
*/
|
|
24
|
+
xform?: (data: any) => any;
|
|
25
|
+
}
|
|
26
|
+
export declare function _request(fetcher: Fetch, method: RequestMethodType, url: string, options?: GotrueRequestOptions): Promise<any>;
|
|
27
|
+
export declare function _sessionResponse(data: any): AuthResponse;
|
|
28
|
+
export declare function _sessionResponsePassword(data: any): AuthResponsePassword;
|
|
29
|
+
export declare function _userResponse(data: any): UserResponse;
|
|
30
|
+
export declare function _ssoResponse(data: any): SSOResponse;
|
|
31
|
+
export declare function _generateLinkResponse(data: any): GenerateLinkResponse;
|
|
32
|
+
export declare function _noResolveJsonResponse(data: any): Response;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/utils/fetch.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,WAAW,EAEX,oBAAoB,EAEpB,YAAY,EACb,MAAM,SAAS,CAAA;AAShB,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KACtB,CAAA;IACD,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAA;AAOjE,wBAAsB,WAAW,CAAC,KAAK,EAAE,OAAO,iBA+D/C;AAmBD,UAAU,oBAAqB,SAAQ,YAAY;IACjD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACjC;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;CAC3B;AAED,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,KAAK,EACd,MAAM,EAAE,iBAAiB,EACzB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,oBAAoB,gBAgC/B;AAwCD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,YAAY,CAYxD;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,GAAG,GAAG,oBAAoB,CAiBxE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,GAAG,YAAY,CAGrD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,WAAW,CAEnD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,oBAAoB,CAmBrE;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,GAAG,GAAG,QAAQ,CAE1D"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports._noResolveJsonResponse = exports._generateLinkResponse = exports._ssoResponse = exports._userResponse = exports._sessionResponsePassword = exports._sessionResponse = exports._request = exports.handleError = void 0;
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
const helpers_1 = require("./helpers");
|
|
17
|
+
const errors_1 = require("./errors");
|
|
18
|
+
const _getErrorMessage = (err) => err.msg || err.message || err.error_description || err.error || JSON.stringify(err);
|
|
19
|
+
const NETWORK_ERROR_CODES = [502, 503, 504];
|
|
20
|
+
async function handleError(error) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (!(0, helpers_1.looksLikeFetchResponse)(error)) {
|
|
23
|
+
throw new errors_1.AuthRetryableFetchError(_getErrorMessage(error), 0);
|
|
24
|
+
}
|
|
25
|
+
if (NETWORK_ERROR_CODES.includes(error.status)) {
|
|
26
|
+
// status in 500...599 range - server had an error, request might be retryed.
|
|
27
|
+
throw new errors_1.AuthRetryableFetchError(_getErrorMessage(error), error.status);
|
|
28
|
+
}
|
|
29
|
+
let data;
|
|
30
|
+
try {
|
|
31
|
+
data = await error.json();
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new errors_1.AuthUnknownError(_getErrorMessage(e), e);
|
|
35
|
+
}
|
|
36
|
+
let errorCode = undefined;
|
|
37
|
+
const responseAPIVersion = (0, helpers_1.parseResponseAPIVersion)(error);
|
|
38
|
+
if (responseAPIVersion &&
|
|
39
|
+
responseAPIVersion.getTime() >= constants_1.API_VERSIONS['2024-01-01'].timestamp &&
|
|
40
|
+
typeof data === 'object' &&
|
|
41
|
+
data &&
|
|
42
|
+
typeof data.code === 'string') {
|
|
43
|
+
errorCode = data.code;
|
|
44
|
+
}
|
|
45
|
+
else if (typeof data === 'object' && data && typeof data.error_code === 'string') {
|
|
46
|
+
errorCode = data.error_code;
|
|
47
|
+
}
|
|
48
|
+
if (!errorCode) {
|
|
49
|
+
// Legacy support for weak password errors, when there were no error codes
|
|
50
|
+
if (typeof data === 'object' &&
|
|
51
|
+
data &&
|
|
52
|
+
typeof data.weak_password === 'object' &&
|
|
53
|
+
data.weak_password &&
|
|
54
|
+
Array.isArray(data.weak_password.reasons) &&
|
|
55
|
+
data.weak_password.reasons.length &&
|
|
56
|
+
data.weak_password.reasons.reduce((a, i) => a && typeof i === 'string', true)) {
|
|
57
|
+
throw new errors_1.AuthWeakPasswordError(_getErrorMessage(data), error.status, data.weak_password.reasons);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (errorCode === 'weak_password') {
|
|
61
|
+
throw new errors_1.AuthWeakPasswordError(_getErrorMessage(data), error.status, ((_a = data.weak_password) === null || _a === void 0 ? void 0 : _a.reasons) || []);
|
|
62
|
+
}
|
|
63
|
+
else if (errorCode === 'session_not_found') {
|
|
64
|
+
// The `session_id` inside the JWT does not correspond to a row in the
|
|
65
|
+
// `sessions` table. This usually means the user has signed out, has been
|
|
66
|
+
// deleted, or their session has somehow been terminated.
|
|
67
|
+
throw new errors_1.AuthSessionMissingError();
|
|
68
|
+
}
|
|
69
|
+
throw new errors_1.AuthApiError(_getErrorMessage(data), error.status || 500, errorCode);
|
|
70
|
+
}
|
|
71
|
+
exports.handleError = handleError;
|
|
72
|
+
const _getRequestParams = (method, options, parameters, body) => {
|
|
73
|
+
const params = { method, headers: (options === null || options === void 0 ? void 0 : options.headers) || {} };
|
|
74
|
+
if (method === 'GET') {
|
|
75
|
+
return params;
|
|
76
|
+
}
|
|
77
|
+
params.headers = Object.assign({ 'Content-Type': 'application/json;charset=UTF-8' }, options === null || options === void 0 ? void 0 : options.headers);
|
|
78
|
+
params.body = JSON.stringify(body);
|
|
79
|
+
return Object.assign(Object.assign({}, params), parameters);
|
|
80
|
+
};
|
|
81
|
+
async function _request(fetcher, method, url, options) {
|
|
82
|
+
var _a;
|
|
83
|
+
const headers = Object.assign({}, options === null || options === void 0 ? void 0 : options.headers);
|
|
84
|
+
if (!headers[constants_1.API_VERSION_HEADER_NAME]) {
|
|
85
|
+
headers[constants_1.API_VERSION_HEADER_NAME] = constants_1.API_VERSIONS['2024-01-01'].name;
|
|
86
|
+
}
|
|
87
|
+
if (options === null || options === void 0 ? void 0 : options.jwt) {
|
|
88
|
+
headers['Authorization'] = `Bearer ${options.jwt}`;
|
|
89
|
+
}
|
|
90
|
+
const qs = (_a = options === null || options === void 0 ? void 0 : options.query) !== null && _a !== void 0 ? _a : {};
|
|
91
|
+
if (options === null || options === void 0 ? void 0 : options.redirectTo) {
|
|
92
|
+
qs['redirect_to'] = options.redirectTo;
|
|
93
|
+
}
|
|
94
|
+
const queryString = Object.keys(qs).length ? '?' + new URLSearchParams(qs).toString() : '';
|
|
95
|
+
const data = await _handleRequest(fetcher, method, url + queryString, {
|
|
96
|
+
headers,
|
|
97
|
+
noResolveJson: options === null || options === void 0 ? void 0 : options.noResolveJson,
|
|
98
|
+
}, {}, options === null || options === void 0 ? void 0 : options.body);
|
|
99
|
+
return (options === null || options === void 0 ? void 0 : options.xform) ? options === null || options === void 0 ? void 0 : options.xform(data) : { data: Object.assign({}, data), error: null };
|
|
100
|
+
}
|
|
101
|
+
exports._request = _request;
|
|
102
|
+
async function _handleRequest(fetcher, method, url, options, parameters, body) {
|
|
103
|
+
const requestParams = _getRequestParams(method, options, parameters, body);
|
|
104
|
+
let result;
|
|
105
|
+
try {
|
|
106
|
+
result = await fetcher(url, Object.assign({}, requestParams));
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.error(e);
|
|
110
|
+
// fetch failed, likely due to a network or CORS error
|
|
111
|
+
throw new errors_1.AuthRetryableFetchError(_getErrorMessage(e), 0);
|
|
112
|
+
}
|
|
113
|
+
if (!result.ok) {
|
|
114
|
+
await handleError(result);
|
|
115
|
+
}
|
|
116
|
+
if (options === null || options === void 0 ? void 0 : options.noResolveJson) {
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
return await result.json();
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
await handleError(e);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function _sessionResponse(data) {
|
|
127
|
+
var _a;
|
|
128
|
+
let session = null;
|
|
129
|
+
if (hasSession(data)) {
|
|
130
|
+
session = Object.assign({}, data);
|
|
131
|
+
if (!data.expires_at) {
|
|
132
|
+
session.expires_at = (0, helpers_1.expiresAt)(data.expires_in);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const user = (_a = data.user) !== null && _a !== void 0 ? _a : data;
|
|
136
|
+
return { data: { session, user }, error: null };
|
|
137
|
+
}
|
|
138
|
+
exports._sessionResponse = _sessionResponse;
|
|
139
|
+
function _sessionResponsePassword(data) {
|
|
140
|
+
const response = _sessionResponse(data);
|
|
141
|
+
if (!response.error &&
|
|
142
|
+
data.weak_password &&
|
|
143
|
+
typeof data.weak_password === 'object' &&
|
|
144
|
+
Array.isArray(data.weak_password.reasons) &&
|
|
145
|
+
data.weak_password.reasons.length &&
|
|
146
|
+
data.weak_password.message &&
|
|
147
|
+
typeof data.weak_password.message === 'string' &&
|
|
148
|
+
data.weak_password.reasons.reduce((a, i) => a && typeof i === 'string', true)) {
|
|
149
|
+
response.data.weak_password = data.weak_password;
|
|
150
|
+
}
|
|
151
|
+
return response;
|
|
152
|
+
}
|
|
153
|
+
exports._sessionResponsePassword = _sessionResponsePassword;
|
|
154
|
+
function _userResponse(data) {
|
|
155
|
+
var _a;
|
|
156
|
+
const user = (_a = data.user) !== null && _a !== void 0 ? _a : data;
|
|
157
|
+
return { data: { user }, error: null };
|
|
158
|
+
}
|
|
159
|
+
exports._userResponse = _userResponse;
|
|
160
|
+
function _ssoResponse(data) {
|
|
161
|
+
return { data, error: null };
|
|
162
|
+
}
|
|
163
|
+
exports._ssoResponse = _ssoResponse;
|
|
164
|
+
function _generateLinkResponse(data) {
|
|
165
|
+
const { action_link, email_otp, hashed_token, redirect_to, verification_type } = data, rest = __rest(data, ["action_link", "email_otp", "hashed_token", "redirect_to", "verification_type"]);
|
|
166
|
+
const properties = {
|
|
167
|
+
action_link,
|
|
168
|
+
email_otp,
|
|
169
|
+
hashed_token,
|
|
170
|
+
redirect_to,
|
|
171
|
+
verification_type,
|
|
172
|
+
};
|
|
173
|
+
const user = Object.assign({}, rest);
|
|
174
|
+
return {
|
|
175
|
+
data: {
|
|
176
|
+
properties,
|
|
177
|
+
user,
|
|
178
|
+
},
|
|
179
|
+
error: null,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
exports._generateLinkResponse = _generateLinkResponse;
|
|
183
|
+
function _noResolveJsonResponse(data) {
|
|
184
|
+
return data;
|
|
185
|
+
}
|
|
186
|
+
exports._noResolveJsonResponse = _noResolveJsonResponse;
|
|
187
|
+
/**
|
|
188
|
+
* hasSession checks if the response object contains a valid session
|
|
189
|
+
* @param data A response object
|
|
190
|
+
* @returns true if a session is in the response
|
|
191
|
+
*/
|
|
192
|
+
function hasSession(data) {
|
|
193
|
+
return data.access_token && data.refresh_token && data.expires_in;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/utils/fetch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,uCAAsF;AAUtF,qCAMiB;AAiBjB,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAU,EAAE,CAC5C,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,iBAAiB,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;AAErF,MAAM,mBAAmB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEpC,KAAK,UAAU,WAAW,CAAC,KAAc;;IAC9C,IAAI,CAAC,IAAA,gCAAsB,EAAC,KAAK,CAAC,EAAE;QAClC,MAAM,IAAI,gCAAuB,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;KAC9D;IAED,IAAI,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;QAC9C,6EAA6E;QAC7E,MAAM,IAAI,gCAAuB,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KACzE;IAED,IAAI,IAAS,CAAA;IACb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AAO;QACL,IAAI,EAAE;YACJ,UAAU;YACV,IAAI;SACL;QACD,KAAK,EAAE,IAAI;KACZ,CAAA;AACH,CAAC;AAnBD,sDAmBC;AAED,SAAgB,sBAAsB,CAAC,IAAS;IAC9C,OAAO,IAAI,CAAA;AACb,CAAC;AAFD,wDAEC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,IAAS;IAC3B,OAAO,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,UAAU,CAAA;AACnE,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { JwtHeader, JwtPayload, SupportedStorage } from './types';
|
|
2
|
+
export declare function expiresAt(expiresIn: number): number;
|
|
3
|
+
export declare function uuid(): string;
|
|
4
|
+
export declare const isBrowser: () => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether localStorage is supported on this browser.
|
|
7
|
+
*/
|
|
8
|
+
export declare const supportsLocalStorage: () => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Extracts parameters encoded in the URL both in the query and fragment.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseParametersFromURL(href: string): {
|
|
13
|
+
[parameter: string]: string;
|
|
14
|
+
};
|
|
15
|
+
type Fetch = typeof fetch;
|
|
16
|
+
export declare const resolveFetch: (customFetch?: Fetch) => Fetch;
|
|
17
|
+
export declare const looksLikeFetchResponse: (maybeResponse: unknown) => maybeResponse is Response;
|
|
18
|
+
export declare const setItemAsync: (storage: SupportedStorage, key: string, data: any) => Promise<void>;
|
|
19
|
+
export declare const getItemAsync: (storage: SupportedStorage, key: string) => Promise<unknown>;
|
|
20
|
+
export declare const removeItemAsync: (storage: SupportedStorage, key: string) => Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* A deferred represents some asynchronous work that is not yet finished, which
|
|
23
|
+
* may or may not culminate in a value.
|
|
24
|
+
* Taken from: https://github.com/mike-north/types/blob/master/src/async.ts
|
|
25
|
+
*/
|
|
26
|
+
export declare class Deferred<T = any> {
|
|
27
|
+
static promiseConstructor: PromiseConstructor;
|
|
28
|
+
readonly promise: PromiseLike<T>;
|
|
29
|
+
readonly resolve: (value?: T | PromiseLike<T>) => void;
|
|
30
|
+
readonly reject: (reason?: any) => any;
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
33
|
+
export declare function decodeJWT(token: string): {
|
|
34
|
+
header: JwtHeader;
|
|
35
|
+
payload: JwtPayload;
|
|
36
|
+
signature: Uint8Array;
|
|
37
|
+
raw: {
|
|
38
|
+
header: string;
|
|
39
|
+
payload: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Creates a promise that resolves to null after some time.
|
|
44
|
+
*/
|
|
45
|
+
export declare function sleep(time: number): Promise<null>;
|
|
46
|
+
/**
|
|
47
|
+
* Converts the provided async function into a retryable function. Each result
|
|
48
|
+
* or thrown error is sent to the isRetryable function which should return true
|
|
49
|
+
* if the function should run again.
|
|
50
|
+
*/
|
|
51
|
+
export declare function retryable<T>(fn: (attempt: number) => Promise<T>, isRetryable: (attempt: number, error: any | null, result?: T) => boolean): Promise<T>;
|
|
52
|
+
export declare function generatePKCEVerifier(): string;
|
|
53
|
+
export declare function generatePKCEChallenge(verifier: string): Promise<string>;
|
|
54
|
+
export declare function getCodeChallengeAndMethod(storage: SupportedStorage, storageKey: string, isPasswordRecovery?: boolean): Promise<string[]>;
|
|
55
|
+
export declare function parseResponseAPIVersion(response: Response): Date | null;
|
|
56
|
+
export declare function validateExp(exp: number): void;
|
|
57
|
+
export declare function getAlgorithm(alg: 'RS256' | 'ES256'): RsaHashedImportParams | EcKeyImportParams;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,gBA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