@koolbase/core 12.34.0 → 12.36.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/aggregate.d.ts +13 -0
- 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/cjs/database.js +5 -0
- package/dist/esm/aggregate.d.ts +13 -0
- 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/dist/esm/database.js +5 -0
- package/package.json +1 -1
package/dist/cjs/aggregate.d.ts
CHANGED
|
@@ -87,6 +87,12 @@ export interface KoolbaseAggregateGroup {
|
|
|
87
87
|
category: string;
|
|
88
88
|
/** Keyed by each measure's `as`. Null where a group had nothing to measure. */
|
|
89
89
|
values: Record<string, number | null>;
|
|
90
|
+
/**
|
|
91
|
+
* The collection's count minimum (#299), when this group's count was below
|
|
92
|
+
* it: every value is null, and what to show is "Fewer than N" -- never 0,
|
|
93
|
+
* and never nothing.
|
|
94
|
+
*/
|
|
95
|
+
fewerThan?: number;
|
|
90
96
|
}
|
|
91
97
|
/**
|
|
92
98
|
* How a measure arrived at its number.
|
|
@@ -121,4 +127,11 @@ export interface KoolbaseAggregateResult {
|
|
|
121
127
|
* would be exactly the wrong number this API exists to prevent.
|
|
122
128
|
*/
|
|
123
129
|
tooManyGroups: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* The collection's count minimum (#299), when `matched` was below it: the
|
|
132
|
+
* number is not said. `matched` is then 0 and `accounting` empty, and what
|
|
133
|
+
* to show is "Fewer than N" -- never 0. Only a count that sees beyond what
|
|
134
|
+
* the caller may read, under the collection's Count rule.
|
|
135
|
+
*/
|
|
136
|
+
fewerThan?: number;
|
|
124
137
|
}
|
|
@@ -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')) {
|
package/dist/cjs/database.js
CHANGED
|
@@ -637,12 +637,17 @@ class KoolbaseDatabase {
|
|
|
637
637
|
groups: (raw.groups ?? []).map((g) => ({
|
|
638
638
|
category: String(g.category ?? ''),
|
|
639
639
|
values: g.values ?? {},
|
|
640
|
+
// Below the collection's count minimum (#299): "Fewer than N".
|
|
641
|
+
...(typeof g.fewer_than === 'number' ? { fewerThan: g.fewer_than } : {}),
|
|
640
642
|
})),
|
|
641
643
|
matched: Number(raw.matched ?? 0),
|
|
642
644
|
accounting,
|
|
643
645
|
// Explicitly boolean: a missing field must read as false, not
|
|
644
646
|
// undefined, or `if (!r.tooManyGroups)` passes on a refused request.
|
|
645
647
|
tooManyGroups: raw.too_many_groups === true,
|
|
648
|
+
// Below the collection's count minimum (#299): matched is 0 and the
|
|
649
|
+
// number is not said -- show "Fewer than N", never 0.
|
|
650
|
+
...(typeof raw.fewer_than === 'number' ? { fewerThan: raw.fewer_than } : {}),
|
|
646
651
|
};
|
|
647
652
|
}
|
|
648
653
|
async conflicts() {
|
package/dist/esm/aggregate.d.ts
CHANGED
|
@@ -87,6 +87,12 @@ export interface KoolbaseAggregateGroup {
|
|
|
87
87
|
category: string;
|
|
88
88
|
/** Keyed by each measure's `as`. Null where a group had nothing to measure. */
|
|
89
89
|
values: Record<string, number | null>;
|
|
90
|
+
/**
|
|
91
|
+
* The collection's count minimum (#299), when this group's count was below
|
|
92
|
+
* it: every value is null, and what to show is "Fewer than N" -- never 0,
|
|
93
|
+
* and never nothing.
|
|
94
|
+
*/
|
|
95
|
+
fewerThan?: number;
|
|
90
96
|
}
|
|
91
97
|
/**
|
|
92
98
|
* How a measure arrived at its number.
|
|
@@ -121,4 +127,11 @@ export interface KoolbaseAggregateResult {
|
|
|
121
127
|
* would be exactly the wrong number this API exists to prevent.
|
|
122
128
|
*/
|
|
123
129
|
tooManyGroups: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* The collection's count minimum (#299), when `matched` was below it: the
|
|
132
|
+
* number is not said. `matched` is then 0 and `accounting` empty, and what
|
|
133
|
+
* to show is "Fewer than N" -- never 0. Only a count that sees beyond what
|
|
134
|
+
* the caller may read, under the collection's Count rule.
|
|
135
|
+
*/
|
|
136
|
+
fewerThan?: number;
|
|
124
137
|
}
|
|
@@ -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/dist/esm/database.js
CHANGED
|
@@ -634,12 +634,17 @@ export class KoolbaseDatabase {
|
|
|
634
634
|
groups: (raw.groups ?? []).map((g) => ({
|
|
635
635
|
category: String(g.category ?? ''),
|
|
636
636
|
values: g.values ?? {},
|
|
637
|
+
// Below the collection's count minimum (#299): "Fewer than N".
|
|
638
|
+
...(typeof g.fewer_than === 'number' ? { fewerThan: g.fewer_than } : {}),
|
|
637
639
|
})),
|
|
638
640
|
matched: Number(raw.matched ?? 0),
|
|
639
641
|
accounting,
|
|
640
642
|
// Explicitly boolean: a missing field must read as false, not
|
|
641
643
|
// undefined, or `if (!r.tooManyGroups)` passes on a refused request.
|
|
642
644
|
tooManyGroups: raw.too_many_groups === true,
|
|
645
|
+
// Below the collection's count minimum (#299): matched is 0 and the
|
|
646
|
+
// number is not said -- show "Fewer than N", never 0.
|
|
647
|
+
...(typeof raw.fewer_than === 'number' ? { fewerThan: raw.fewer_than } : {}),
|
|
643
648
|
};
|
|
644
649
|
}
|
|
645
650
|
async conflicts() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.36.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",
|