@koolbase/core 12.34.0 → 12.35.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/cjs/auth-errors.d.ts +17 -1
- package/dist/cjs/auth-errors.js +15 -1
- package/dist/cjs/auth.js +2 -2
- package/dist/esm/auth-errors.d.ts +17 -1
- package/dist/esm/auth-errors.js +14 -1
- package/dist/esm/auth.js +3 -3
- package/package.json +1 -1
|
@@ -68,8 +68,24 @@ export declare class UnlockTokenInvalidError extends KoolbaseAuthError {
|
|
|
68
68
|
* separate server-side rate-limiter.
|
|
69
69
|
*/
|
|
70
70
|
export declare class RateLimitError extends KoolbaseAuthError {
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* How long until the server would take the request again, in whole
|
|
73
|
+
* seconds -- its `retry_after`, or its Retry-After header -- so an app can
|
|
74
|
+
* count down to it ("Resend in 7:42"). Null when the server did not say.
|
|
75
|
+
*/
|
|
76
|
+
readonly retryAfter: number | null;
|
|
77
|
+
constructor(message?: string, retryAfter?: number | null);
|
|
72
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* When a 429 says to try again, in whole seconds: its body's `retry_after`,
|
|
81
|
+
* else its Retry-After header; null when it says neither. A web app on
|
|
82
|
+
* another origin sees only the body, which is why the server sends both.
|
|
83
|
+
*/
|
|
84
|
+
export declare function retryAfterOf(res: {
|
|
85
|
+
headers?: {
|
|
86
|
+
get(name: string): string | null;
|
|
87
|
+
};
|
|
88
|
+
}, body: unknown): number | null;
|
|
73
89
|
/**
|
|
74
90
|
* The verification email was refused because one was sent too recently.
|
|
75
91
|
*
|
package/dist/cjs/auth-errors.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MfaNotEnabledError = exports.MfaEnrollmentNotFoundError = exports.MfaAlreadyEnabledError = exports.RecentMfaRequiredError = exports.RecentAuthRequiredError = exports.MfaRequiredError = exports.GoogleEmailRequiredError = exports.InvalidGoogleTokenError = exports.MalformedSessionResponseError = exports.ProviderIdentityAlreadyLinkedError = exports.IdentityNotFoundError = exports.InsufficientScopeError = exports.HideRequiresVerificationError = exports.LastCredentialError = exports.InsufficientAuthorityError = exports.SessionRequiredError = exports.UnsupportedOAuthProviderError = exports.OAuthOnlyAccountError = exports.AccountExistsError = exports.CurrentPasswordIncorrectError = exports.TokenAlreadyUsedError = exports.TokenExpiredError = exports.SignupsDisabledError = exports.ContactNotVerifiedError = exports.GoogleSignInNotConfiguredError = exports.OAuthEmailConflictError = exports.AppleEmailRequiredError = exports.InvalidAppleTokenError = exports.AppleSignInNotConfiguredError = exports.SmsConfigMissingError = exports.PhoneAlreadyLinkedError = exports.OtpRateLimitError = exports.OtpMaxAttemptsError = exports.OtpInvalidError = exports.OtpExpiredError = exports.EmailCodeDisabledError = exports.InvalidPhoneNumberError = exports.NetworkError = exports.VerificationResendDailyCapError = exports.VerificationResendCooldownError = exports.RateLimitError = exports.UnlockTokenInvalidError = exports.AccountLockedError = exports.TokenRevokedError = exports.SessionExpiredError = exports.WeakPasswordError = exports.UserDisabledError = exports.EmailAlreadyInUseError = exports.InvalidCredentialsError = exports.KoolbaseAuthError = void 0;
|
|
4
|
+
exports.retryAfterOf = retryAfterOf;
|
|
4
5
|
const errors_js_1 = require("./errors.js");
|
|
5
6
|
/**
|
|
6
7
|
* Base error type for all Koolbase auth errors. Catchable via
|
|
@@ -119,13 +120,26 @@ exports.UnlockTokenInvalidError = UnlockTokenInvalidError;
|
|
|
119
120
|
* separate server-side rate-limiter.
|
|
120
121
|
*/
|
|
121
122
|
class RateLimitError extends KoolbaseAuthError {
|
|
122
|
-
constructor(message) {
|
|
123
|
+
constructor(message, retryAfter) {
|
|
123
124
|
super(message ?? 'Too many requests, please wait before trying again', 'rate_limit');
|
|
124
125
|
this.name = 'RateLimitError';
|
|
126
|
+
this.retryAfter = retryAfter ?? null;
|
|
125
127
|
Object.setPrototypeOf(this, RateLimitError.prototype);
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
exports.RateLimitError = RateLimitError;
|
|
131
|
+
/**
|
|
132
|
+
* When a 429 says to try again, in whole seconds: its body's `retry_after`,
|
|
133
|
+
* else its Retry-After header; null when it says neither. A web app on
|
|
134
|
+
* another origin sees only the body, which is why the server sends both.
|
|
135
|
+
*/
|
|
136
|
+
function retryAfterOf(res, body) {
|
|
137
|
+
const b = body?.retry_after;
|
|
138
|
+
if (typeof b === 'number' && Number.isFinite(b) && b >= 0)
|
|
139
|
+
return Math.ceil(b);
|
|
140
|
+
const h = Number.parseInt((res.headers?.get('retry-after') ?? '').trim(), 10);
|
|
141
|
+
return Number.isFinite(h) && h >= 0 ? h : null;
|
|
142
|
+
}
|
|
129
143
|
/**
|
|
130
144
|
* The verification email was refused because one was sent too recently.
|
|
131
145
|
*
|
package/dist/cjs/auth.js
CHANGED
|
@@ -1335,7 +1335,7 @@ class KoolbaseAuth {
|
|
|
1335
1335
|
case 'invalid_unlock_token':
|
|
1336
1336
|
throw new auth_errors_js_1.UnlockTokenInvalidError();
|
|
1337
1337
|
case 'rate_limit':
|
|
1338
|
-
throw new auth_errors_js_1.RateLimitError(msg || undefined);
|
|
1338
|
+
throw new auth_errors_js_1.RateLimitError(msg || undefined, (0, auth_errors_js_1.retryAfterOf)(res, body));
|
|
1339
1339
|
// Verification state. Two codes, one situation — projectauth and the
|
|
1340
1340
|
// dashboard's auth package name it differently and an app should not
|
|
1341
1341
|
// have to know which spoke.
|
|
@@ -1417,7 +1417,7 @@ class KoolbaseAuth {
|
|
|
1417
1417
|
if (msg.includes('account temporarily locked')) {
|
|
1418
1418
|
throw new auth_errors_js_1.AccountLockedError();
|
|
1419
1419
|
}
|
|
1420
|
-
throw new auth_errors_js_1.RateLimitError(msg || undefined);
|
|
1420
|
+
throw new auth_errors_js_1.RateLimitError(msg || undefined, (0, auth_errors_js_1.retryAfterOf)(res, body));
|
|
1421
1421
|
}
|
|
1422
1422
|
// ─── legacy message fallback ───
|
|
1423
1423
|
if (msg.includes('invalid or expired unlock token')) {
|
|
@@ -68,8 +68,24 @@ export declare class UnlockTokenInvalidError extends KoolbaseAuthError {
|
|
|
68
68
|
* separate server-side rate-limiter.
|
|
69
69
|
*/
|
|
70
70
|
export declare class RateLimitError extends KoolbaseAuthError {
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* How long until the server would take the request again, in whole
|
|
73
|
+
* seconds -- its `retry_after`, or its Retry-After header -- so an app can
|
|
74
|
+
* count down to it ("Resend in 7:42"). Null when the server did not say.
|
|
75
|
+
*/
|
|
76
|
+
readonly retryAfter: number | null;
|
|
77
|
+
constructor(message?: string, retryAfter?: number | null);
|
|
72
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* When a 429 says to try again, in whole seconds: its body's `retry_after`,
|
|
81
|
+
* else its Retry-After header; null when it says neither. A web app on
|
|
82
|
+
* another origin sees only the body, which is why the server sends both.
|
|
83
|
+
*/
|
|
84
|
+
export declare function retryAfterOf(res: {
|
|
85
|
+
headers?: {
|
|
86
|
+
get(name: string): string | null;
|
|
87
|
+
};
|
|
88
|
+
}, body: unknown): number | null;
|
|
73
89
|
/**
|
|
74
90
|
* The verification email was refused because one was sent too recently.
|
|
75
91
|
*
|
package/dist/esm/auth-errors.js
CHANGED
|
@@ -107,12 +107,25 @@ export class UnlockTokenInvalidError extends KoolbaseAuthError {
|
|
|
107
107
|
* separate server-side rate-limiter.
|
|
108
108
|
*/
|
|
109
109
|
export class RateLimitError extends KoolbaseAuthError {
|
|
110
|
-
constructor(message) {
|
|
110
|
+
constructor(message, retryAfter) {
|
|
111
111
|
super(message ?? 'Too many requests, please wait before trying again', 'rate_limit');
|
|
112
112
|
this.name = 'RateLimitError';
|
|
113
|
+
this.retryAfter = retryAfter ?? null;
|
|
113
114
|
Object.setPrototypeOf(this, RateLimitError.prototype);
|
|
114
115
|
}
|
|
115
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* When a 429 says to try again, in whole seconds: its body's `retry_after`,
|
|
119
|
+
* else its Retry-After header; null when it says neither. A web app on
|
|
120
|
+
* another origin sees only the body, which is why the server sends both.
|
|
121
|
+
*/
|
|
122
|
+
export function retryAfterOf(res, body) {
|
|
123
|
+
const b = body?.retry_after;
|
|
124
|
+
if (typeof b === 'number' && Number.isFinite(b) && b >= 0)
|
|
125
|
+
return Math.ceil(b);
|
|
126
|
+
const h = Number.parseInt((res.headers?.get('retry-after') ?? '').trim(), 10);
|
|
127
|
+
return Number.isFinite(h) && h >= 0 ? h : null;
|
|
128
|
+
}
|
|
116
129
|
/**
|
|
117
130
|
* The verification email was refused because one was sent too recently.
|
|
118
131
|
*
|
package/dist/esm/auth.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { KoolbaseInvalidPublicKeyError } from './errors';
|
|
2
2
|
import { koolbaseFetch } from './network.js';
|
|
3
3
|
import { RestoreResult, } from './types.js';
|
|
4
|
-
import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, IdentityNotFoundError, InsufficientScopeError, MalformedSessionResponseError, ProviderIdentityAlreadyLinkedError, AccountExistsError, ContactNotVerifiedError, CurrentPasswordIncorrectError, HideRequiresVerificationError, InsufficientAuthorityError, LastCredentialError, OAuthOnlyAccountError, SessionRequiredError, SignupsDisabledError, TokenAlreadyUsedError, TokenExpiredError, UnsupportedOAuthProviderError, RateLimitError, VerificationResendCooldownError, VerificationResendDailyCapError, SessionExpiredError, SmsConfigMissingError, TokenRevokedError, UnlockTokenInvalidError, UserDisabledError, WeakPasswordError, AppleEmailRequiredError, AppleSignInNotConfiguredError, InvalidAppleTokenError, OAuthEmailConflictError, GoogleEmailRequiredError, GoogleSignInNotConfiguredError, InvalidGoogleTokenError, EmailCodeDisabledError, MfaRequiredError, RecentAuthRequiredError, RecentMfaRequiredError, MfaAlreadyEnabledError, MfaEnrollmentNotFoundError, MfaNotEnabledError, } from './auth-errors.js';
|
|
4
|
+
import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, IdentityNotFoundError, InsufficientScopeError, MalformedSessionResponseError, ProviderIdentityAlreadyLinkedError, AccountExistsError, ContactNotVerifiedError, CurrentPasswordIncorrectError, HideRequiresVerificationError, InsufficientAuthorityError, LastCredentialError, OAuthOnlyAccountError, SessionRequiredError, SignupsDisabledError, TokenAlreadyUsedError, TokenExpiredError, UnsupportedOAuthProviderError, RateLimitError, retryAfterOf, VerificationResendCooldownError, VerificationResendDailyCapError, SessionExpiredError, SmsConfigMissingError, TokenRevokedError, UnlockTokenInvalidError, UserDisabledError, WeakPasswordError, AppleEmailRequiredError, AppleSignInNotConfiguredError, InvalidAppleTokenError, OAuthEmailConflictError, GoogleEmailRequiredError, GoogleSignInNotConfiguredError, InvalidGoogleTokenError, EmailCodeDisabledError, MfaRequiredError, RecentAuthRequiredError, RecentMfaRequiredError, MfaAlreadyEnabledError, MfaEnrollmentNotFoundError, MfaNotEnabledError, } from './auth-errors.js';
|
|
5
5
|
import { KoolbaseServiceUnavailableError } from './errors.js';
|
|
6
6
|
import { getPlatform } from './platform.js';
|
|
7
7
|
import { DeviceMetadata } from './device-metadata.js';
|
|
@@ -1332,7 +1332,7 @@ export class KoolbaseAuth {
|
|
|
1332
1332
|
case 'invalid_unlock_token':
|
|
1333
1333
|
throw new UnlockTokenInvalidError();
|
|
1334
1334
|
case 'rate_limit':
|
|
1335
|
-
throw new RateLimitError(msg || undefined);
|
|
1335
|
+
throw new RateLimitError(msg || undefined, retryAfterOf(res, body));
|
|
1336
1336
|
// Verification state. Two codes, one situation — projectauth and the
|
|
1337
1337
|
// dashboard's auth package name it differently and an app should not
|
|
1338
1338
|
// have to know which spoke.
|
|
@@ -1414,7 +1414,7 @@ export class KoolbaseAuth {
|
|
|
1414
1414
|
if (msg.includes('account temporarily locked')) {
|
|
1415
1415
|
throw new AccountLockedError();
|
|
1416
1416
|
}
|
|
1417
|
-
throw new RateLimitError(msg || undefined);
|
|
1417
|
+
throw new RateLimitError(msg || undefined, retryAfterOf(res, body));
|
|
1418
1418
|
}
|
|
1419
1419
|
// ─── legacy message fallback ───
|
|
1420
1420
|
if (msg.includes('invalid or expired unlock token')) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.35.0",
|
|
4
4
|
"description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|