@koolbase/core 12.33.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/aggregate.d.ts +9 -0
- package/dist/cjs/aggregate.js +0 -24
- 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 +7 -0
- package/dist/esm/aggregate.d.ts +9 -0
- package/dist/esm/aggregate.js +0 -24
- 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 +7 -0
- package/package.json +1 -1
package/dist/cjs/aggregate.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KbWhereNode } from './query-builder.js';
|
|
1
2
|
/**
|
|
2
3
|
* Asking "how many" and "how much" over a collection, correctly.
|
|
3
4
|
*
|
|
@@ -67,6 +68,14 @@ export interface KoolbaseAggregateRequest {
|
|
|
67
68
|
collection: string;
|
|
68
69
|
/** AND-ed record filters on top of the read rule. */
|
|
69
70
|
where?: KoolbaseAggregateFilter[];
|
|
71
|
+
/**
|
|
72
|
+
* The typed filter a list's query takes (#165): and/or groups, ranges,
|
|
73
|
+
* dates, relative times -- so "upcoming events" counts what the list
|
|
74
|
+
* shows. Not with `where`.
|
|
75
|
+
*/
|
|
76
|
+
filter?: KbWhereNode;
|
|
77
|
+
/** The IANA zone the filter's relative times resolve in; the server's default if unset. */
|
|
78
|
+
timezone?: string;
|
|
70
79
|
/** Absent means one group: the measures over everything. */
|
|
71
80
|
groupBy?: KoolbaseGroupBy;
|
|
72
81
|
/** At least one. */
|
package/dist/cjs/aggregate.js
CHANGED
|
@@ -1,26 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Asking "how many" and "how much" over a collection, correctly.
|
|
4
|
-
*
|
|
5
|
-
* Correct means the whole authorized set — never the first page — with the
|
|
6
|
-
* caller's read rule applied inside the query, and never a bare number:
|
|
7
|
-
* collections are schemaless, so a total that quietly excluded three
|
|
8
|
-
* malformed rows would be a wrong number that looks right. Every result
|
|
9
|
-
* carries its accounting.
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const r = await Koolbase.db.aggregate({
|
|
13
|
-
* collection: 'orders',
|
|
14
|
-
* groupBy: { field: 'created_at', bucket: 'month', timezone: 'Africa/Accra' },
|
|
15
|
-
* measures: [{ aggregate: 'sum', field: 'total', as: 'revenue' }],
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* for (const g of r.groups) {
|
|
19
|
-
* console.log(g.category, g.values.revenue);
|
|
20
|
-
* }
|
|
21
|
-
* if (r.accounting.revenue.skipped > 0) {
|
|
22
|
-
* // some orders had a total that was not a number — say so
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -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
|
@@ -596,9 +596,16 @@ class KoolbaseDatabase {
|
|
|
596
596
|
* 23:30 sale belongs to.
|
|
597
597
|
*/
|
|
598
598
|
async aggregate(request) {
|
|
599
|
+
if (request.filter && request.where?.length) {
|
|
600
|
+
throw new TypeError('aggregate: provide filter or where, not both.');
|
|
601
|
+
}
|
|
599
602
|
const raw = await this.request('POST', '/v1/sdk/db/aggregate', {
|
|
600
603
|
collection: request.collection,
|
|
601
604
|
...(request.where?.length ? { where: request.where } : {}),
|
|
605
|
+
// The typed filter, as a list sends it: `where` as an object.
|
|
606
|
+
...(request.filter
|
|
607
|
+
? { where: request.filter, ...(request.timezone ? { timezone: request.timezone } : {}) }
|
|
608
|
+
: {}),
|
|
602
609
|
...(request.groupBy
|
|
603
610
|
? {
|
|
604
611
|
group_by: {
|
package/dist/esm/aggregate.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KbWhereNode } from './query-builder.js';
|
|
1
2
|
/**
|
|
2
3
|
* Asking "how many" and "how much" over a collection, correctly.
|
|
3
4
|
*
|
|
@@ -67,6 +68,14 @@ export interface KoolbaseAggregateRequest {
|
|
|
67
68
|
collection: string;
|
|
68
69
|
/** AND-ed record filters on top of the read rule. */
|
|
69
70
|
where?: KoolbaseAggregateFilter[];
|
|
71
|
+
/**
|
|
72
|
+
* The typed filter a list's query takes (#165): and/or groups, ranges,
|
|
73
|
+
* dates, relative times -- so "upcoming events" counts what the list
|
|
74
|
+
* shows. Not with `where`.
|
|
75
|
+
*/
|
|
76
|
+
filter?: KbWhereNode;
|
|
77
|
+
/** The IANA zone the filter's relative times resolve in; the server's default if unset. */
|
|
78
|
+
timezone?: string;
|
|
70
79
|
/** Absent means one group: the measures over everything. */
|
|
71
80
|
groupBy?: KoolbaseGroupBy;
|
|
72
81
|
/** At least one. */
|
package/dist/esm/aggregate.js
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asking "how many" and "how much" over a collection, correctly.
|
|
3
|
-
*
|
|
4
|
-
* Correct means the whole authorized set — never the first page — with the
|
|
5
|
-
* caller's read rule applied inside the query, and never a bare number:
|
|
6
|
-
* collections are schemaless, so a total that quietly excluded three
|
|
7
|
-
* malformed rows would be a wrong number that looks right. Every result
|
|
8
|
-
* carries its accounting.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const r = await Koolbase.db.aggregate({
|
|
12
|
-
* collection: 'orders',
|
|
13
|
-
* groupBy: { field: 'created_at', bucket: 'month', timezone: 'Africa/Accra' },
|
|
14
|
-
* measures: [{ aggregate: 'sum', field: 'total', as: 'revenue' }],
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* for (const g of r.groups) {
|
|
18
|
-
* console.log(g.category, g.values.revenue);
|
|
19
|
-
* }
|
|
20
|
-
* if (r.accounting.revenue.skipped > 0) {
|
|
21
|
-
* // some orders had a total that was not a number — say so
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
1
|
export {};
|
|
@@ -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
|
@@ -593,9 +593,16 @@ export class KoolbaseDatabase {
|
|
|
593
593
|
* 23:30 sale belongs to.
|
|
594
594
|
*/
|
|
595
595
|
async aggregate(request) {
|
|
596
|
+
if (request.filter && request.where?.length) {
|
|
597
|
+
throw new TypeError('aggregate: provide filter or where, not both.');
|
|
598
|
+
}
|
|
596
599
|
const raw = await this.request('POST', '/v1/sdk/db/aggregate', {
|
|
597
600
|
collection: request.collection,
|
|
598
601
|
...(request.where?.length ? { where: request.where } : {}),
|
|
602
|
+
// The typed filter, as a list sends it: `where` as an object.
|
|
603
|
+
...(request.filter
|
|
604
|
+
? { where: request.filter, ...(request.timezone ? { timezone: request.timezone } : {}) }
|
|
605
|
+
: {}),
|
|
599
606
|
...(request.groupBy
|
|
600
607
|
? {
|
|
601
608
|
group_by: {
|
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",
|