@koolbase/core 11.4.0 → 12.1.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 +115 -0
- package/dist/cjs/aggregate.js +26 -0
- package/dist/cjs/auth-errors.d.ts +8 -0
- package/dist/cjs/auth-errors.js +27 -14
- package/dist/cjs/auth.d.ts +130 -7
- package/dist/cjs/auth.js +252 -10
- package/dist/cjs/database-errors.d.ts +46 -0
- package/dist/cjs/database-errors.js +71 -1
- package/dist/cjs/database.d.ts +23 -0
- package/dist/cjs/database.js +64 -0
- package/dist/cjs/device-metadata.js +7 -1
- package/dist/cjs/fiscal.d.ts +114 -0
- package/dist/cjs/fiscal.js +167 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/types.d.ts +58 -0
- package/dist/esm/aggregate.d.ts +115 -0
- package/dist/esm/aggregate.js +25 -0
- package/dist/esm/auth-errors.d.ts +8 -0
- package/dist/esm/auth-errors.js +25 -13
- package/dist/esm/auth.d.ts +130 -7
- package/dist/esm/auth.js +253 -11
- package/dist/esm/database-errors.d.ts +46 -0
- package/dist/esm/database-errors.js +66 -0
- package/dist/esm/database.d.ts +23 -0
- package/dist/esm/database.js +64 -0
- package/dist/esm/device-metadata.js +7 -1
- package/dist/esm/fiscal.d.ts +114 -0
- package/dist/esm/fiscal.js +159 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/types.d.ts +58 -0
- package/package.json +1 -1
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
/** A record filter, AND-ed on top of the read rule. */
|
|
26
|
+
export interface KoolbaseAggregateFilter {
|
|
27
|
+
field: string;
|
|
28
|
+
op: 'eq' | 'neq' | 'in' | 'gt' | 'gte' | 'lt' | 'lte';
|
|
29
|
+
value: unknown;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The category axis: a field's value, or a calendar bucket of a timestamp
|
|
33
|
+
* field.
|
|
34
|
+
*
|
|
35
|
+
* A bucket REQUIRES a timezone, and the union makes omitting it a type
|
|
36
|
+
* error. "Midnight" means nothing without one — Africa/Accra and UTC
|
|
37
|
+
* disagree about which day a 23:30 sale belongs to — and the API refuses a
|
|
38
|
+
* bucket that arrives without one.
|
|
39
|
+
*/
|
|
40
|
+
export type KoolbaseGroupBy = {
|
|
41
|
+
field: string;
|
|
42
|
+
bucket?: never;
|
|
43
|
+
timezone?: never;
|
|
44
|
+
} | {
|
|
45
|
+
field: string;
|
|
46
|
+
bucket: 'day' | 'week' | 'month' | 'year';
|
|
47
|
+
timezone: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* One number per group.
|
|
51
|
+
*
|
|
52
|
+
* `count` counts RECORDS, so it takes no field and skips nothing. The others
|
|
53
|
+
* read a field, and a record whose value is missing or not a number is
|
|
54
|
+
* skipped and reported in the result's accounting.
|
|
55
|
+
*/
|
|
56
|
+
export type KoolbaseMeasure = {
|
|
57
|
+
aggregate: 'count';
|
|
58
|
+
field?: never;
|
|
59
|
+
as: string;
|
|
60
|
+
} | {
|
|
61
|
+
aggregate: 'sum' | 'avg' | 'min' | 'max';
|
|
62
|
+
field: string;
|
|
63
|
+
as: string;
|
|
64
|
+
};
|
|
65
|
+
/** One aggregation request. */
|
|
66
|
+
export interface KoolbaseAggregateRequest {
|
|
67
|
+
collection: string;
|
|
68
|
+
/** AND-ed record filters on top of the read rule. */
|
|
69
|
+
where?: KoolbaseAggregateFilter[];
|
|
70
|
+
/** Absent means one group: the measures over everything. */
|
|
71
|
+
groupBy?: KoolbaseGroupBy;
|
|
72
|
+
/** At least one. */
|
|
73
|
+
measures: KoolbaseMeasure[];
|
|
74
|
+
}
|
|
75
|
+
/** One category and its numbers. */
|
|
76
|
+
export interface KoolbaseAggregateGroup {
|
|
77
|
+
/** Empty string for the single group when there was no groupBy. */
|
|
78
|
+
category: string;
|
|
79
|
+
/** Keyed by each measure's `as`. Null where a group had nothing to measure. */
|
|
80
|
+
values: Record<string, number | null>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* How a measure arrived at its number.
|
|
84
|
+
*
|
|
85
|
+
* `skipped` is not an error. It is what you need to decide whether the
|
|
86
|
+
* number means what it appears to mean — a revenue total over 900 of 903
|
|
87
|
+
* orders is a different fact from one over all of them, and only this says
|
|
88
|
+
* which you are looking at.
|
|
89
|
+
*/
|
|
90
|
+
export interface KoolbaseAggregateAccounting {
|
|
91
|
+
counted: number;
|
|
92
|
+
skipped: number;
|
|
93
|
+
/** Present when skipped > 0. */
|
|
94
|
+
skippedReason?: 'missing' | 'not_numeric' | 'mixed';
|
|
95
|
+
}
|
|
96
|
+
/** The whole answer, including what could not be counted. */
|
|
97
|
+
export interface KoolbaseAggregateResult {
|
|
98
|
+
/**
|
|
99
|
+
* One per category, sorted — or exactly one with an empty category when
|
|
100
|
+
* there was no groupBy.
|
|
101
|
+
*/
|
|
102
|
+
groups: KoolbaseAggregateGroup[];
|
|
103
|
+
/** Records that matched the read rule and filters: the denominator. */
|
|
104
|
+
matched: number;
|
|
105
|
+
/** Per measure name, keyed by its `as`. */
|
|
106
|
+
accounting: Record<string, KoolbaseAggregateAccounting>;
|
|
107
|
+
/**
|
|
108
|
+
* True when the groupBy produced more categories than allowed and the
|
|
109
|
+
* whole request was refused.
|
|
110
|
+
*
|
|
111
|
+
* `groups` is EMPTY when this is set: a partial set drawn as the whole
|
|
112
|
+
* would be exactly the wrong number this API exists to prevent.
|
|
113
|
+
*/
|
|
114
|
+
tooManyGroups: boolean;
|
|
115
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -101,6 +101,14 @@ export declare class NetworkError extends KoolbaseAuthError {
|
|
|
101
101
|
export declare class InvalidPhoneNumberError extends KoolbaseAuthError {
|
|
102
102
|
constructor();
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* The project has switched off signing in with an emailed code — 403
|
|
106
|
+
* `email_code_disabled`. Applies to every address alike, so it reveals
|
|
107
|
+
* nothing about which accounts exist.
|
|
108
|
+
*/
|
|
109
|
+
export declare class EmailCodeDisabledError extends KoolbaseAuthError {
|
|
110
|
+
constructor();
|
|
111
|
+
}
|
|
104
112
|
export declare class OtpExpiredError extends KoolbaseAuthError {
|
|
105
113
|
constructor();
|
|
106
114
|
}
|
package/dist/cjs/auth-errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.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;
|
|
3
|
+
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
4
|
const errors_js_1 = require("./errors.js");
|
|
5
5
|
/**
|
|
6
6
|
* Base error type for all Koolbase auth errors. Catchable via
|
|
@@ -26,7 +26,7 @@ class InvalidCredentialsError extends KoolbaseAuthError {
|
|
|
26
26
|
exports.InvalidCredentialsError = InvalidCredentialsError;
|
|
27
27
|
class EmailAlreadyInUseError extends KoolbaseAuthError {
|
|
28
28
|
constructor() {
|
|
29
|
-
super('Email is already in use', '
|
|
29
|
+
super('Email is already in use', 'email_in_use');
|
|
30
30
|
this.name = 'EmailAlreadyInUseError';
|
|
31
31
|
Object.setPrototypeOf(this, EmailAlreadyInUseError.prototype);
|
|
32
32
|
}
|
|
@@ -34,7 +34,7 @@ class EmailAlreadyInUseError extends KoolbaseAuthError {
|
|
|
34
34
|
exports.EmailAlreadyInUseError = EmailAlreadyInUseError;
|
|
35
35
|
class UserDisabledError extends KoolbaseAuthError {
|
|
36
36
|
constructor() {
|
|
37
|
-
super('This account has been disabled', '
|
|
37
|
+
super('This account has been disabled', 'account_disabled');
|
|
38
38
|
this.name = 'UserDisabledError';
|
|
39
39
|
Object.setPrototypeOf(this, UserDisabledError.prototype);
|
|
40
40
|
}
|
|
@@ -57,7 +57,7 @@ exports.WeakPasswordError = WeakPasswordError;
|
|
|
57
57
|
// ─── Session lifecycle ─────────────────────────────────────────────────────
|
|
58
58
|
class SessionExpiredError extends KoolbaseAuthError {
|
|
59
59
|
constructor() {
|
|
60
|
-
super('Session expired, please log in again', '
|
|
60
|
+
super('Session expired, please log in again', 'invalid_refresh_token');
|
|
61
61
|
this.name = 'SessionExpiredError';
|
|
62
62
|
Object.setPrototypeOf(this, SessionExpiredError.prototype);
|
|
63
63
|
}
|
|
@@ -106,7 +106,7 @@ exports.AccountLockedError = AccountLockedError;
|
|
|
106
106
|
*/
|
|
107
107
|
class UnlockTokenInvalidError extends KoolbaseAuthError {
|
|
108
108
|
constructor() {
|
|
109
|
-
super('Unlock link is invalid or has expired', '
|
|
109
|
+
super('Unlock link is invalid or has expired', 'invalid_unlock_token');
|
|
110
110
|
this.name = 'UnlockTokenInvalidError';
|
|
111
111
|
Object.setPrototypeOf(this, UnlockTokenInvalidError.prototype);
|
|
112
112
|
}
|
|
@@ -179,6 +179,19 @@ class InvalidPhoneNumberError extends KoolbaseAuthError {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
exports.InvalidPhoneNumberError = InvalidPhoneNumberError;
|
|
182
|
+
/**
|
|
183
|
+
* The project has switched off signing in with an emailed code — 403
|
|
184
|
+
* `email_code_disabled`. Applies to every address alike, so it reveals
|
|
185
|
+
* nothing about which accounts exist.
|
|
186
|
+
*/
|
|
187
|
+
class EmailCodeDisabledError extends KoolbaseAuthError {
|
|
188
|
+
constructor() {
|
|
189
|
+
super('Signing in with an emailed code is switched off for this project', 'email_code_disabled');
|
|
190
|
+
this.name = 'EmailCodeDisabledError';
|
|
191
|
+
Object.setPrototypeOf(this, EmailCodeDisabledError.prototype);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.EmailCodeDisabledError = EmailCodeDisabledError;
|
|
182
195
|
class OtpExpiredError extends KoolbaseAuthError {
|
|
183
196
|
constructor() {
|
|
184
197
|
super('OTP has expired, please request a new code', 'otp_expired');
|
|
@@ -205,7 +218,7 @@ class OtpMaxAttemptsError extends KoolbaseAuthError {
|
|
|
205
218
|
exports.OtpMaxAttemptsError = OtpMaxAttemptsError;
|
|
206
219
|
class OtpRateLimitError extends KoolbaseAuthError {
|
|
207
220
|
constructor() {
|
|
208
|
-
super('Too many OTP requests, please wait before trying again', '
|
|
221
|
+
super('Too many OTP requests, please wait before trying again', 'rate_limit');
|
|
209
222
|
this.name = 'OtpRateLimitError';
|
|
210
223
|
Object.setPrototypeOf(this, OtpRateLimitError.prototype);
|
|
211
224
|
}
|
|
@@ -213,7 +226,7 @@ class OtpRateLimitError extends KoolbaseAuthError {
|
|
|
213
226
|
exports.OtpRateLimitError = OtpRateLimitError;
|
|
214
227
|
class PhoneAlreadyLinkedError extends KoolbaseAuthError {
|
|
215
228
|
constructor() {
|
|
216
|
-
super('Phone number is already associated with another account', '
|
|
229
|
+
super('Phone number is already associated with another account', 'phone_in_use');
|
|
217
230
|
this.name = 'PhoneAlreadyLinkedError';
|
|
218
231
|
Object.setPrototypeOf(this, PhoneAlreadyLinkedError.prototype);
|
|
219
232
|
}
|
|
@@ -221,7 +234,7 @@ class PhoneAlreadyLinkedError extends KoolbaseAuthError {
|
|
|
221
234
|
exports.PhoneAlreadyLinkedError = PhoneAlreadyLinkedError;
|
|
222
235
|
class SmsConfigMissingError extends KoolbaseAuthError {
|
|
223
236
|
constructor() {
|
|
224
|
-
super('SMS provider not configured for this project', '
|
|
237
|
+
super('SMS provider not configured for this project', 'sms_not_configured');
|
|
225
238
|
this.name = 'SmsConfigMissingError';
|
|
226
239
|
Object.setPrototypeOf(this, SmsConfigMissingError.prototype);
|
|
227
240
|
}
|
|
@@ -229,7 +242,7 @@ class SmsConfigMissingError extends KoolbaseAuthError {
|
|
|
229
242
|
exports.SmsConfigMissingError = SmsConfigMissingError;
|
|
230
243
|
class AppleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
231
244
|
constructor() {
|
|
232
|
-
super('Apple Sign-In is not configured for this environment', '
|
|
245
|
+
super('Apple Sign-In is not configured for this environment', 'oauth_not_configured');
|
|
233
246
|
this.name = 'AppleSignInNotConfiguredError';
|
|
234
247
|
Object.setPrototypeOf(this, AppleSignInNotConfiguredError.prototype);
|
|
235
248
|
}
|
|
@@ -237,7 +250,7 @@ class AppleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
|
237
250
|
exports.AppleSignInNotConfiguredError = AppleSignInNotConfiguredError;
|
|
238
251
|
class InvalidAppleTokenError extends KoolbaseAuthError {
|
|
239
252
|
constructor() {
|
|
240
|
-
super('Invalid Apple identity token', '
|
|
253
|
+
super('Invalid Apple identity token', 'invalid_oauth_token');
|
|
241
254
|
this.name = 'InvalidAppleTokenError';
|
|
242
255
|
Object.setPrototypeOf(this, InvalidAppleTokenError.prototype);
|
|
243
256
|
}
|
|
@@ -245,7 +258,7 @@ class InvalidAppleTokenError extends KoolbaseAuthError {
|
|
|
245
258
|
exports.InvalidAppleTokenError = InvalidAppleTokenError;
|
|
246
259
|
class AppleEmailRequiredError extends KoolbaseAuthError {
|
|
247
260
|
constructor() {
|
|
248
|
-
super('Apple did not return email for this sign-in. Revoke this app in iOS Settings → Apple ID and retry.', '
|
|
261
|
+
super('Apple did not return email for this sign-in. Revoke this app in iOS Settings → Apple ID and retry.', 'oauth_email_required');
|
|
249
262
|
this.name = 'AppleEmailRequiredError';
|
|
250
263
|
Object.setPrototypeOf(this, AppleEmailRequiredError.prototype);
|
|
251
264
|
}
|
|
@@ -261,7 +274,7 @@ class OAuthEmailConflictError extends KoolbaseAuthError {
|
|
|
261
274
|
exports.OAuthEmailConflictError = OAuthEmailConflictError;
|
|
262
275
|
class GoogleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
263
276
|
constructor() {
|
|
264
|
-
super('Google Sign-In is not configured for this environment', '
|
|
277
|
+
super('Google Sign-In is not configured for this environment', 'oauth_not_configured');
|
|
265
278
|
this.name = 'GoogleSignInNotConfiguredError';
|
|
266
279
|
Object.setPrototypeOf(this, GoogleSignInNotConfiguredError.prototype);
|
|
267
280
|
}
|
|
@@ -458,7 +471,7 @@ class MalformedSessionResponseError extends KoolbaseAuthError {
|
|
|
458
471
|
exports.MalformedSessionResponseError = MalformedSessionResponseError;
|
|
459
472
|
class InvalidGoogleTokenError extends KoolbaseAuthError {
|
|
460
473
|
constructor() {
|
|
461
|
-
super('Invalid Google identity token', '
|
|
474
|
+
super('Invalid Google identity token', 'invalid_oauth_token');
|
|
462
475
|
this.name = 'InvalidGoogleTokenError';
|
|
463
476
|
Object.setPrototypeOf(this, InvalidGoogleTokenError.prototype);
|
|
464
477
|
}
|
|
@@ -466,7 +479,7 @@ class InvalidGoogleTokenError extends KoolbaseAuthError {
|
|
|
466
479
|
exports.InvalidGoogleTokenError = InvalidGoogleTokenError;
|
|
467
480
|
class GoogleEmailRequiredError extends KoolbaseAuthError {
|
|
468
481
|
constructor() {
|
|
469
|
-
super('Google did not return email for this sign-in. Ensure the email scope is requested in the native flow.', '
|
|
482
|
+
super('Google did not return email for this sign-in. Ensure the email scope is requested in the native flow.', 'oauth_email_required');
|
|
470
483
|
this.name = 'GoogleEmailRequiredError';
|
|
471
484
|
Object.setPrototypeOf(this, GoogleEmailRequiredError.prototype);
|
|
472
485
|
}
|
package/dist/cjs/auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, ResendVerificationResult, SendOtpParams, SignUpResult, SignInWithAppleParams, VerifyOtpParams } from './types.js';
|
|
1
|
+
import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, KoolbaseAuditPage, KoolbaseSessionInfo, ResendVerificationResult, SendOtpParams, SignUpResult, SignInWithAppleParams, VerifyOtpParams } from './types.js';
|
|
2
2
|
import type { SignInWithGoogleParams } from './types.js';
|
|
3
3
|
export declare class KoolbaseAuth {
|
|
4
4
|
private config;
|
|
@@ -55,6 +55,18 @@ export declare class KoolbaseAuth {
|
|
|
55
55
|
* delegates to {@link authRequest} with includeAuth=true.
|
|
56
56
|
*/
|
|
57
57
|
private authedRequest;
|
|
58
|
+
/**
|
|
59
|
+
* Replace the user inside the current session and persist it.
|
|
60
|
+
*
|
|
61
|
+
* A profile update or a fresh fetch changes the user, not the tokens.
|
|
62
|
+
* Without this the new values live only in the returned object: the cached
|
|
63
|
+
* `currentUser` stays stale, anything bound to `onAuthStateChange` never
|
|
64
|
+
* hears about the change, and a reload restores the old name.
|
|
65
|
+
*
|
|
66
|
+
* No session means nobody is signed in, and there is nothing to update —
|
|
67
|
+
* the caller's own request would have failed first.
|
|
68
|
+
*/
|
|
69
|
+
private updateUserAndPersist;
|
|
58
70
|
private setSessionInternal;
|
|
59
71
|
/**
|
|
60
72
|
* Discards the stored session without contacting the server.
|
|
@@ -191,6 +203,92 @@ export declare class KoolbaseAuth {
|
|
|
191
203
|
* taking an email address — otherwise this would be an open mail relay.
|
|
192
204
|
*/
|
|
193
205
|
resendVerificationEmail(): Promise<ResendVerificationResult>;
|
|
206
|
+
/**
|
|
207
|
+
* The signed-in user, fetched fresh from the server.
|
|
208
|
+
*
|
|
209
|
+
* `currentUser` returns what was cached at sign-in; this asks. Use it when
|
|
210
|
+
* something may have changed the user server-side — a verification
|
|
211
|
+
* completing, a profile updated from another device — and persist the
|
|
212
|
+
* result so the cached copy stops being stale.
|
|
213
|
+
*/
|
|
214
|
+
getCurrentUser(): Promise<KoolbaseUser>;
|
|
215
|
+
/**
|
|
216
|
+
* Update the signed-in user's profile.
|
|
217
|
+
*
|
|
218
|
+
* Only the fields given are sent, so passing one leaves the other
|
|
219
|
+
* untouched. The updated user is persisted, so `currentUser` reflects it
|
|
220
|
+
* without a refetch.
|
|
221
|
+
*/
|
|
222
|
+
updateProfile(params: {
|
|
223
|
+
fullName?: string;
|
|
224
|
+
avatarUrl?: string;
|
|
225
|
+
}): Promise<KoolbaseUser>;
|
|
226
|
+
/**
|
|
227
|
+
* Change the signed-in user's password.
|
|
228
|
+
*
|
|
229
|
+
* The current password is required: a stolen session should not be enough
|
|
230
|
+
* to lock the real owner out. A wrong one throws
|
|
231
|
+
* CurrentPasswordIncorrectError — the server returns `invalid_password`,
|
|
232
|
+
* which reads like a rejected new password and means the opposite.
|
|
233
|
+
*
|
|
234
|
+
* An account that signed up through Google or Apple has no password to
|
|
235
|
+
* change and gets the same error, deliberately, so a caller cannot probe
|
|
236
|
+
* which sign-in methods an account has.
|
|
237
|
+
*/
|
|
238
|
+
changePassword(params: {
|
|
239
|
+
currentPassword: string;
|
|
240
|
+
newPassword: string;
|
|
241
|
+
}): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* Delete the signed-in user's account, and sign out.
|
|
244
|
+
*
|
|
245
|
+
* Deletes the caller only — there is no user id to pass, which is the
|
|
246
|
+
* security property. The server removes the auth record and every session
|
|
247
|
+
* on every device, then fires an `auth.user.deleted` trigger.
|
|
248
|
+
*
|
|
249
|
+
* It does NOT delete the account's records in your collections. Koolbase
|
|
250
|
+
* cannot know whether a row should be deleted, anonymised, or kept for a
|
|
251
|
+
* statutory retention period. Subscribe a Function to `auth.user.deleted`
|
|
252
|
+
* and clean up there — it runs server-side, so a tab closing mid-flow
|
|
253
|
+
* cannot strand anything.
|
|
254
|
+
*/
|
|
255
|
+
deleteAccount(): Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* Every session the signed-in user has — a "where you're signed in" list.
|
|
258
|
+
*
|
|
259
|
+
* Newest first is not guaranteed; sort by createdAt if the order matters.
|
|
260
|
+
* The entry with `isCurrent` is this device.
|
|
261
|
+
*/
|
|
262
|
+
listSessions(): Promise<KoolbaseSessionInfo[]>;
|
|
263
|
+
/**
|
|
264
|
+
* Sign out one session by id.
|
|
265
|
+
*
|
|
266
|
+
* Revoking the current one ends this session too — the server does not
|
|
267
|
+
* refuse it, and the local session is cleared here so the app does not keep
|
|
268
|
+
* a token the server has dropped. Use logout() when that is what you mean.
|
|
269
|
+
*/
|
|
270
|
+
revokeSession(sessionId: string): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Sign out every OTHER session, keeping this one.
|
|
273
|
+
*
|
|
274
|
+
* What "sign out my other devices" means after a lost phone. Returns how
|
|
275
|
+
* many were ended, so an app can say so rather than guess.
|
|
276
|
+
*/
|
|
277
|
+
revokeAllOtherSessions(): Promise<number>;
|
|
278
|
+
/**
|
|
279
|
+
* What has happened to this account — sign-ins, failures, lockouts,
|
|
280
|
+
* password changes.
|
|
281
|
+
*
|
|
282
|
+
* For a "recent security activity" screen. The server sanitizes each
|
|
283
|
+
* event, so this carries what that event type is allowed to say and
|
|
284
|
+
* nothing more.
|
|
285
|
+
*
|
|
286
|
+
* @param limit up to 200; the server caps it there.
|
|
287
|
+
*/
|
|
288
|
+
auditLog(options?: {
|
|
289
|
+
limit?: number;
|
|
290
|
+
offset?: number;
|
|
291
|
+
}): Promise<KoolbaseAuditPage>;
|
|
194
292
|
unlock(token: string): Promise<void>;
|
|
195
293
|
get currentUser(): KoolbaseUser | null;
|
|
196
294
|
get accessToken(): string | null;
|
|
@@ -204,12 +302,10 @@ export declare class KoolbaseAuth {
|
|
|
204
302
|
validAccessToken(): Promise<string | null>;
|
|
205
303
|
setSession(session: KoolbaseSession | null): Promise<void>;
|
|
206
304
|
/**
|
|
207
|
-
* @deprecated
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* server endpoints under /v1/sdk/auth/oauth/{apple,google,github}.
|
|
212
|
-
* Use email/password sign-in for now.
|
|
305
|
+
* @deprecated Never implemented; kept only so existing code compiles.
|
|
306
|
+
* Google and Apple sign-in are supported — use signInWithGoogle() or
|
|
307
|
+
* signInWithApple(). This used to say OAuth was not yet shipped and to
|
|
308
|
+
* use email and password instead, which stopped being true long ago.
|
|
213
309
|
*
|
|
214
310
|
* @throws Always throws KoolbaseAuthError('not_implemented').
|
|
215
311
|
*/
|
|
@@ -220,6 +316,33 @@ export declare class KoolbaseAuth {
|
|
|
220
316
|
name?: string;
|
|
221
317
|
avatarUrl?: string;
|
|
222
318
|
}): Promise<never>;
|
|
319
|
+
/**
|
|
320
|
+
* Emails a six-digit sign-in code.
|
|
321
|
+
*
|
|
322
|
+
* Resolves the same way whether or not the address has an account, so it
|
|
323
|
+
* cannot be used to check who is registered. A new address receives a code
|
|
324
|
+
* only while the project accepts sign-ups; a disabled account receives
|
|
325
|
+
* nothing.
|
|
326
|
+
*
|
|
327
|
+
* @throws EmailCodeDisabledError if the project has switched this off
|
|
328
|
+
* @throws RateLimitError after too many requests for one address
|
|
329
|
+
*/
|
|
330
|
+
requestEmailCode(params: {
|
|
331
|
+
email: string;
|
|
332
|
+
}): Promise<void>;
|
|
333
|
+
/**
|
|
334
|
+
* Signs in with a code from requestEmailCode(), storing the session exactly
|
|
335
|
+
* as login() does. An unknown address becomes an account only if the
|
|
336
|
+
* project still accepts sign-ups at this moment. Each code works once and
|
|
337
|
+
* allows three attempts.
|
|
338
|
+
*
|
|
339
|
+
* @throws OtpInvalidError, OtpExpiredError, OtpMaxAttemptsError
|
|
340
|
+
* @throws EmailCodeDisabledError if the project has switched this off
|
|
341
|
+
*/
|
|
342
|
+
signInWithEmailCode(params: {
|
|
343
|
+
email: string;
|
|
344
|
+
code: string;
|
|
345
|
+
}): Promise<KoolbaseSession>;
|
|
223
346
|
sendOtp(params: SendOtpParams): Promise<OtpSendResult>;
|
|
224
347
|
verifyOtp(params: VerifyOtpParams): Promise<PhoneVerifyResult>;
|
|
225
348
|
linkPhone(params: LinkPhoneParams): Promise<void>;
|