@koolbase/core 11.0.0 → 11.2.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 +80 -1
- package/dist/cjs/auth-errors.js +142 -3
- package/dist/cjs/auth.js +43 -0
- package/dist/cjs/database-errors.d.ts +44 -2
- package/dist/cjs/database-errors.js +77 -7
- package/dist/cjs/function-errors.d.ts +19 -0
- package/dist/cjs/function-errors.js +35 -1
- package/dist/cjs/storage-errors.d.ts +18 -0
- package/dist/cjs/storage-errors.js +33 -1
- package/dist/esm/auth-errors.d.ts +80 -1
- package/dist/esm/auth-errors.js +129 -2
- package/dist/esm/auth.js +44 -1
- package/dist/esm/database-errors.d.ts +44 -2
- package/dist/esm/database-errors.js +72 -6
- package/dist/esm/function-errors.d.ts +19 -0
- package/dist/esm/function-errors.js +32 -0
- package/dist/esm/storage-errors.d.ts +18 -0
- package/dist/esm/storage-errors.js +30 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseStorageMetadataInvalidError = exports.KoolbaseStorageMimeTypeError = exports.KoolbaseStorageFileTooLargeError = exports.KoolbaseStorageQuotaError = exports.KoolbaseStoragePermissionError = exports.KoolbaseStorageValidationError = exports.KoolbaseStorageNotFoundError = exports.KoolbaseStorageConflictError = exports.KoolbaseStorageError = void 0;
|
|
3
|
+
exports.KoolbaseStorageMetadataInvalidError = exports.KoolbaseStorageMimeTypeError = exports.KoolbaseStorageFileTooLargeError = exports.KoolbaseStorageQuotaError = exports.KoolbaseCapBelowUsageError = exports.KoolbaseUploadExpiredError = exports.KoolbaseStoragePermissionError = exports.KoolbaseStorageValidationError = exports.KoolbaseStorageNotFoundError = exports.KoolbaseStorageConflictError = exports.KoolbaseStorageError = void 0;
|
|
4
4
|
exports.koolbaseStorageError = koolbaseStorageError;
|
|
5
5
|
exports.koolbaseStorageErrorFromResponse = koolbaseStorageErrorFromResponse;
|
|
6
6
|
const errors_js_1 = require("./errors.js");
|
|
@@ -106,6 +106,34 @@ exports.KoolbaseStoragePermissionError = KoolbaseStoragePermissionError;
|
|
|
106
106
|
* 409 but means "path collides"); branch on the error type via
|
|
107
107
|
* `instanceof`, not on status.
|
|
108
108
|
*/
|
|
109
|
+
/**
|
|
110
|
+
* The presigned upload was confirmed after its window closed.
|
|
111
|
+
*
|
|
112
|
+
* An upload URL has a lifetime. A user who picks a file, gets distracted and
|
|
113
|
+
* comes back twenty minutes later hits this — so it is a retry, not a
|
|
114
|
+
* failure: presign again and send the same bytes. Worth catching rather than
|
|
115
|
+
* showing "upload failed" to someone whose file was fine.
|
|
116
|
+
*/
|
|
117
|
+
class KoolbaseUploadExpiredError extends KoolbaseStorageError {
|
|
118
|
+
constructor(message) {
|
|
119
|
+
super(message ?? 'This upload is past the confirmation window — please re-upload', 'upload_expired');
|
|
120
|
+
this.name = 'KoolbaseUploadExpiredError';
|
|
121
|
+
Object.setPrototypeOf(this, KoolbaseUploadExpiredError.prototype);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.KoolbaseUploadExpiredError = KoolbaseUploadExpiredError;
|
|
125
|
+
/**
|
|
126
|
+
* A bucket cap set below what the bucket already holds. A dashboard
|
|
127
|
+
* operation rather than an app one, mapped so it does not arrive untyped.
|
|
128
|
+
*/
|
|
129
|
+
class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
|
|
130
|
+
constructor(message) {
|
|
131
|
+
super(message ?? 'The cap is below the bucket\'s current usage', 'cap_below_usage');
|
|
132
|
+
this.name = 'KoolbaseCapBelowUsageError';
|
|
133
|
+
Object.setPrototypeOf(this, KoolbaseCapBelowUsageError.prototype);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.KoolbaseCapBelowUsageError = KoolbaseCapBelowUsageError;
|
|
109
137
|
class KoolbaseStorageQuotaError extends KoolbaseStorageError {
|
|
110
138
|
constructor(message) {
|
|
111
139
|
super(message ?? 'Bucket quota exceeded', 'quota_exceeded');
|
|
@@ -209,6 +237,10 @@ function koolbaseStorageError(status, body, fallbackMessage = 'Storage request f
|
|
|
209
237
|
return new KoolbaseStorageConflictError(message, body?.path);
|
|
210
238
|
case 'quota_exceeded':
|
|
211
239
|
return new KoolbaseStorageQuotaError(message);
|
|
240
|
+
case 'upload_expired':
|
|
241
|
+
return new KoolbaseUploadExpiredError(message);
|
|
242
|
+
case 'cap_below_usage':
|
|
243
|
+
return new KoolbaseCapBelowUsageError(message);
|
|
212
244
|
case 'file_too_large':
|
|
213
245
|
return new KoolbaseStorageFileTooLargeError(message);
|
|
214
246
|
case 'mime_not_allowed':
|
|
@@ -17,7 +17,13 @@ export declare class UserDisabledError extends KoolbaseAuthError {
|
|
|
17
17
|
constructor();
|
|
18
18
|
}
|
|
19
19
|
export declare class WeakPasswordError extends KoolbaseAuthError {
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The message is optional so the server's own rule can be carried through.
|
|
22
|
+
* The SDK checks length before sending; a project may require more than
|
|
23
|
+
* that, and "must be at least 8 characters" would then be wrong as well as
|
|
24
|
+
* unhelpful.
|
|
25
|
+
*/
|
|
26
|
+
constructor(message?: string);
|
|
21
27
|
}
|
|
22
28
|
export declare class SessionExpiredError extends KoolbaseAuthError {
|
|
23
29
|
constructor();
|
|
@@ -138,6 +144,79 @@ export declare class GoogleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
|
138
144
|
* from it is what produced a signed-in user whose every request went out as
|
|
139
145
|
* `Bearer undefined`, so the SDK refuses instead.
|
|
140
146
|
*/
|
|
147
|
+
/**
|
|
148
|
+
* Sign-in refused because the account has not verified its email or phone.
|
|
149
|
+
*
|
|
150
|
+
* In a project with require_verified_contact on, this is the most common auth
|
|
151
|
+
* error there is — the user registered, did not click the link, and came back.
|
|
152
|
+
* It arrived untyped until 11.1.0, so apps showed "something went wrong" for
|
|
153
|
+
* the one case with an obvious remedy: offer to resend.
|
|
154
|
+
*/
|
|
155
|
+
export declare class ContactNotVerifiedError extends KoolbaseAuthError {
|
|
156
|
+
constructor(message?: string);
|
|
157
|
+
}
|
|
158
|
+
/** The project has registration turned off. Not a credential problem. */
|
|
159
|
+
export declare class SignupsDisabledError extends KoolbaseAuthError {
|
|
160
|
+
constructor(message?: string);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* A verification or reset link that has expired.
|
|
164
|
+
*
|
|
165
|
+
* Distinct from TokenAlreadyUsedError because the remedy differs: expired
|
|
166
|
+
* means request another, used means it already worked and they may simply be
|
|
167
|
+
* clicking an old email.
|
|
168
|
+
*/
|
|
169
|
+
export declare class TokenExpiredError extends KoolbaseAuthError {
|
|
170
|
+
constructor(message?: string);
|
|
171
|
+
}
|
|
172
|
+
/** A one-shot link clicked twice. Often means it already succeeded. */
|
|
173
|
+
export declare class TokenAlreadyUsedError extends KoolbaseAuthError {
|
|
174
|
+
constructor(message?: string);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The current password given for a password change was wrong.
|
|
178
|
+
*
|
|
179
|
+
* Named for the operation rather than the code: the server calls this
|
|
180
|
+
* `invalid_password`, which reads like a rejected new password and is not.
|
|
181
|
+
*/
|
|
182
|
+
export declare class CurrentPasswordIncorrectError extends KoolbaseAuthError {
|
|
183
|
+
constructor(message?: string);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* An OAuth sign-in for an email that already has an account by another
|
|
187
|
+
* method. The remedy is to sign in the original way and connect the provider
|
|
188
|
+
* afterwards, which the server's message says.
|
|
189
|
+
*/
|
|
190
|
+
export declare class AccountExistsError extends KoolbaseAuthError {
|
|
191
|
+
constructor(message?: string);
|
|
192
|
+
}
|
|
193
|
+
/** A password attempt against an account that only has Google or Apple. */
|
|
194
|
+
export declare class OAuthOnlyAccountError extends KoolbaseAuthError {
|
|
195
|
+
constructor(message?: string);
|
|
196
|
+
}
|
|
197
|
+
/** A provider the project has not enabled. */
|
|
198
|
+
export declare class UnsupportedOAuthProviderError extends KoolbaseAuthError {
|
|
199
|
+
constructor(message?: string);
|
|
200
|
+
}
|
|
201
|
+
/** The call needs a signed-in user and did not have one. */
|
|
202
|
+
export declare class SessionRequiredError extends KoolbaseAuthError {
|
|
203
|
+
constructor(message?: string);
|
|
204
|
+
}
|
|
205
|
+
/** The caller is authenticated but not permitted to do this. */
|
|
206
|
+
export declare class InsufficientAuthorityError extends KoolbaseAuthError {
|
|
207
|
+
constructor(message?: string);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Refused because it would remove the account's last way of signing in —
|
|
211
|
+
* unlinking the only provider, or clearing the only password.
|
|
212
|
+
*/
|
|
213
|
+
export declare class LastCredentialError extends KoolbaseAuthError {
|
|
214
|
+
constructor(message?: string);
|
|
215
|
+
}
|
|
216
|
+
/** Hiding account existence needs verification on; the project has it off. */
|
|
217
|
+
export declare class HideRequiresVerificationError extends KoolbaseAuthError {
|
|
218
|
+
constructor(message?: string);
|
|
219
|
+
}
|
|
141
220
|
export declare class MalformedSessionResponseError extends KoolbaseAuthError {
|
|
142
221
|
constructor(missing: string);
|
|
143
222
|
}
|
package/dist/esm/auth-errors.js
CHANGED
|
@@ -34,8 +34,14 @@ export class UserDisabledError extends KoolbaseAuthError {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
export class WeakPasswordError extends KoolbaseAuthError {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The message is optional so the server's own rule can be carried through.
|
|
39
|
+
* The SDK checks length before sending; a project may require more than
|
|
40
|
+
* that, and "must be at least 8 characters" would then be wrong as well as
|
|
41
|
+
* unhelpful.
|
|
42
|
+
*/
|
|
43
|
+
constructor(message) {
|
|
44
|
+
super(message ?? 'Password must be at least 8 characters', 'weak_password');
|
|
39
45
|
this.name = 'WeakPasswordError';
|
|
40
46
|
Object.setPrototypeOf(this, WeakPasswordError.prototype);
|
|
41
47
|
}
|
|
@@ -243,6 +249,127 @@ export class GoogleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
|
243
249
|
* from it is what produced a signed-in user whose every request went out as
|
|
244
250
|
* `Bearer undefined`, so the SDK refuses instead.
|
|
245
251
|
*/
|
|
252
|
+
/**
|
|
253
|
+
* Sign-in refused because the account has not verified its email or phone.
|
|
254
|
+
*
|
|
255
|
+
* In a project with require_verified_contact on, this is the most common auth
|
|
256
|
+
* error there is — the user registered, did not click the link, and came back.
|
|
257
|
+
* It arrived untyped until 11.1.0, so apps showed "something went wrong" for
|
|
258
|
+
* the one case with an obvious remedy: offer to resend.
|
|
259
|
+
*/
|
|
260
|
+
export class ContactNotVerifiedError extends KoolbaseAuthError {
|
|
261
|
+
constructor(message) {
|
|
262
|
+
super(message ?? 'Verify your email or phone before signing in', 'contact_not_verified');
|
|
263
|
+
this.name = 'ContactNotVerifiedError';
|
|
264
|
+
Object.setPrototypeOf(this, ContactNotVerifiedError.prototype);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/** The project has registration turned off. Not a credential problem. */
|
|
268
|
+
export class SignupsDisabledError extends KoolbaseAuthError {
|
|
269
|
+
constructor(message) {
|
|
270
|
+
super(message ?? 'Registration is disabled for this project', 'signups_disabled');
|
|
271
|
+
this.name = 'SignupsDisabledError';
|
|
272
|
+
Object.setPrototypeOf(this, SignupsDisabledError.prototype);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* A verification or reset link that has expired.
|
|
277
|
+
*
|
|
278
|
+
* Distinct from TokenAlreadyUsedError because the remedy differs: expired
|
|
279
|
+
* means request another, used means it already worked and they may simply be
|
|
280
|
+
* clicking an old email.
|
|
281
|
+
*/
|
|
282
|
+
export class TokenExpiredError extends KoolbaseAuthError {
|
|
283
|
+
constructor(message) {
|
|
284
|
+
super(message ?? 'This link has expired — request a new one', 'token_expired');
|
|
285
|
+
this.name = 'TokenExpiredError';
|
|
286
|
+
Object.setPrototypeOf(this, TokenExpiredError.prototype);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/** A one-shot link clicked twice. Often means it already succeeded. */
|
|
290
|
+
export class TokenAlreadyUsedError extends KoolbaseAuthError {
|
|
291
|
+
constructor(message) {
|
|
292
|
+
super(message ?? 'This link has already been used', 'token_used');
|
|
293
|
+
this.name = 'TokenAlreadyUsedError';
|
|
294
|
+
Object.setPrototypeOf(this, TokenAlreadyUsedError.prototype);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The current password given for a password change was wrong.
|
|
299
|
+
*
|
|
300
|
+
* Named for the operation rather than the code: the server calls this
|
|
301
|
+
* `invalid_password`, which reads like a rejected new password and is not.
|
|
302
|
+
*/
|
|
303
|
+
export class CurrentPasswordIncorrectError extends KoolbaseAuthError {
|
|
304
|
+
constructor(message) {
|
|
305
|
+
super(message ?? 'Current password is incorrect', 'invalid_password');
|
|
306
|
+
this.name = 'CurrentPasswordIncorrectError';
|
|
307
|
+
Object.setPrototypeOf(this, CurrentPasswordIncorrectError.prototype);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* An OAuth sign-in for an email that already has an account by another
|
|
312
|
+
* method. The remedy is to sign in the original way and connect the provider
|
|
313
|
+
* afterwards, which the server's message says.
|
|
314
|
+
*/
|
|
315
|
+
export class AccountExistsError extends KoolbaseAuthError {
|
|
316
|
+
constructor(message) {
|
|
317
|
+
super(message ?? 'An account with this email already exists — sign in with your existing method first', 'account_exists');
|
|
318
|
+
this.name = 'AccountExistsError';
|
|
319
|
+
Object.setPrototypeOf(this, AccountExistsError.prototype);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
/** A password attempt against an account that only has Google or Apple. */
|
|
323
|
+
export class OAuthOnlyAccountError extends KoolbaseAuthError {
|
|
324
|
+
constructor(message) {
|
|
325
|
+
super(message ?? 'This account uses Google or Apple sign-in and has no password', 'oauth_only_account');
|
|
326
|
+
this.name = 'OAuthOnlyAccountError';
|
|
327
|
+
Object.setPrototypeOf(this, OAuthOnlyAccountError.prototype);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/** A provider the project has not enabled. */
|
|
331
|
+
export class UnsupportedOAuthProviderError extends KoolbaseAuthError {
|
|
332
|
+
constructor(message) {
|
|
333
|
+
super(message ?? 'That sign-in provider is not supported', 'unsupported_oauth_provider');
|
|
334
|
+
this.name = 'UnsupportedOAuthProviderError';
|
|
335
|
+
Object.setPrototypeOf(this, UnsupportedOAuthProviderError.prototype);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/** The call needs a signed-in user and did not have one. */
|
|
339
|
+
export class SessionRequiredError extends KoolbaseAuthError {
|
|
340
|
+
constructor(message) {
|
|
341
|
+
super(message ?? 'This action requires a signed-in user', 'session_required');
|
|
342
|
+
this.name = 'SessionRequiredError';
|
|
343
|
+
Object.setPrototypeOf(this, SessionRequiredError.prototype);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/** The caller is authenticated but not permitted to do this. */
|
|
347
|
+
export class InsufficientAuthorityError extends KoolbaseAuthError {
|
|
348
|
+
constructor(message) {
|
|
349
|
+
super(message ?? 'You do not have permission to do that', 'insufficient_authority');
|
|
350
|
+
this.name = 'InsufficientAuthorityError';
|
|
351
|
+
Object.setPrototypeOf(this, InsufficientAuthorityError.prototype);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Refused because it would remove the account's last way of signing in —
|
|
356
|
+
* unlinking the only provider, or clearing the only password.
|
|
357
|
+
*/
|
|
358
|
+
export class LastCredentialError extends KoolbaseAuthError {
|
|
359
|
+
constructor(message) {
|
|
360
|
+
super(message ?? 'This is the account\'s only sign-in method and cannot be removed', 'last_credential');
|
|
361
|
+
this.name = 'LastCredentialError';
|
|
362
|
+
Object.setPrototypeOf(this, LastCredentialError.prototype);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/** Hiding account existence needs verification on; the project has it off. */
|
|
366
|
+
export class HideRequiresVerificationError extends KoolbaseAuthError {
|
|
367
|
+
constructor(message) {
|
|
368
|
+
super(message ?? 'Hiding account existence requires verified contact to be enabled', 'hide_requires_verification');
|
|
369
|
+
this.name = 'HideRequiresVerificationError';
|
|
370
|
+
Object.setPrototypeOf(this, HideRequiresVerificationError.prototype);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
246
373
|
export class MalformedSessionResponseError extends KoolbaseAuthError {
|
|
247
374
|
constructor(missing) {
|
|
248
375
|
super(`The server returned a session without ${missing}. This is a protocol error, not a credential problem.`, 'malformed_session_response');
|
package/dist/esm/auth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RestoreResult, } from './types.js';
|
|
2
|
-
import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, MalformedSessionResponseError, RateLimitError, VerificationResendCooldownError, VerificationResendDailyCapError, SessionExpiredError, SmsConfigMissingError, TokenRevokedError, UnlockTokenInvalidError, UserDisabledError, WeakPasswordError, AppleEmailRequiredError, AppleSignInNotConfiguredError, InvalidAppleTokenError, OAuthEmailConflictError, GoogleEmailRequiredError, GoogleSignInNotConfiguredError, InvalidGoogleTokenError, } from './auth-errors.js';
|
|
2
|
+
import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, MalformedSessionResponseError, 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, } from './auth-errors.js';
|
|
3
3
|
import { getPlatform } from './platform.js';
|
|
4
4
|
import { DeviceMetadata } from './device-metadata.js';
|
|
5
5
|
export class KoolbaseAuth {
|
|
@@ -794,6 +794,49 @@ export class KoolbaseAuth {
|
|
|
794
794
|
throw new UnlockTokenInvalidError();
|
|
795
795
|
case 'rate_limit':
|
|
796
796
|
throw new RateLimitError(msg || undefined);
|
|
797
|
+
// Verification state. Two codes, one situation — projectauth and the
|
|
798
|
+
// dashboard's auth package name it differently and an app should not
|
|
799
|
+
// have to know which spoke.
|
|
800
|
+
// Verification state. Two codes, one situation — projectauth and the
|
|
801
|
+
// dashboard's auth package name it differently and an app should not
|
|
802
|
+
// have to know which spoke.
|
|
803
|
+
case 'contact_not_verified':
|
|
804
|
+
case 'email_not_verified':
|
|
805
|
+
throw new ContactNotVerifiedError(msg || undefined);
|
|
806
|
+
// Registration
|
|
807
|
+
case 'signups_disabled':
|
|
808
|
+
throw new SignupsDisabledError(msg || undefined);
|
|
809
|
+
case 'weak_password':
|
|
810
|
+
// The class existed and was only ever thrown client-side for length.
|
|
811
|
+
// The server has its own rules, and a password that passes ours and
|
|
812
|
+
// fails theirs deserves the same error, not a generic one.
|
|
813
|
+
throw new WeakPasswordError(msg || undefined);
|
|
814
|
+
case 'account_exists':
|
|
815
|
+
throw new AccountExistsError(msg || undefined);
|
|
816
|
+
// Link tokens — verification and password reset
|
|
817
|
+
case 'token_expired':
|
|
818
|
+
throw new TokenExpiredError(msg || undefined);
|
|
819
|
+
case 'token_used':
|
|
820
|
+
throw new TokenAlreadyUsedError(msg || undefined);
|
|
821
|
+
case 'invalid_token':
|
|
822
|
+
throw new UnlockTokenInvalidError();
|
|
823
|
+
// Password change
|
|
824
|
+
case 'invalid_password':
|
|
825
|
+
throw new CurrentPasswordIncorrectError(msg || undefined);
|
|
826
|
+
// OAuth
|
|
827
|
+
case 'oauth_only_account':
|
|
828
|
+
throw new OAuthOnlyAccountError(msg || undefined);
|
|
829
|
+
case 'unsupported_oauth_provider':
|
|
830
|
+
throw new UnsupportedOAuthProviderError(msg || undefined);
|
|
831
|
+
// Authority
|
|
832
|
+
case 'session_required':
|
|
833
|
+
throw new SessionRequiredError(msg || undefined);
|
|
834
|
+
case 'insufficient_authority':
|
|
835
|
+
throw new InsufficientAuthorityError(msg || undefined);
|
|
836
|
+
case 'last_credential':
|
|
837
|
+
throw new LastCredentialError(msg || undefined);
|
|
838
|
+
case 'hide_requires_verification':
|
|
839
|
+
throw new HideRequiresVerificationError(msg || undefined);
|
|
797
840
|
case 'resend_cooldown':
|
|
798
841
|
throw new VerificationResendCooldownError(body.cooldown_until ? new Date(body.cooldown_until) : null, msg || undefined);
|
|
799
842
|
case 'resend_daily_cap':
|
|
@@ -41,6 +41,25 @@ export declare class KoolbaseDataError extends KoolbaseError {
|
|
|
41
41
|
* }
|
|
42
42
|
* }
|
|
43
43
|
*/
|
|
44
|
+
/**
|
|
45
|
+
* An upsert whose filter matched more than one record.
|
|
46
|
+
*
|
|
47
|
+
* Refused rather than resolved: picking one of several would be a silent
|
|
48
|
+
* guess about which row the caller meant, and the wrong guess overwrites data
|
|
49
|
+
* nobody asked to change. Narrow the filter, or add a unique constraint over
|
|
50
|
+
* the fields you are matching on so the ambiguity cannot arise.
|
|
51
|
+
*/
|
|
52
|
+
export declare class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
|
|
53
|
+
constructor(message?: string);
|
|
54
|
+
}
|
|
55
|
+
/** A unique constraint already covers those fields. */
|
|
56
|
+
export declare class KoolbaseConstraintExistsError extends KoolbaseDataError {
|
|
57
|
+
constructor(message?: string);
|
|
58
|
+
}
|
|
59
|
+
/** No such unique constraint. */
|
|
60
|
+
export declare class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
|
|
61
|
+
constructor(message?: string);
|
|
62
|
+
}
|
|
44
63
|
export declare class KoolbaseConflictError extends KoolbaseDataError {
|
|
45
64
|
field?: string;
|
|
46
65
|
constructor(message?: string, field?: string);
|
|
@@ -51,20 +70,43 @@ export declare class KoolbaseConflictError extends KoolbaseDataError {
|
|
|
51
70
|
* `collection_not_found`.
|
|
52
71
|
*/
|
|
53
72
|
export declare class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
54
|
-
|
|
73
|
+
/**
|
|
74
|
+
* The code is carried rather than fixed, because the server distinguishes
|
|
75
|
+
* what was missing — a record, a collection, a vector field — and an app
|
|
76
|
+
* reading e.code should get that answer rather than the category. Catching
|
|
77
|
+
* the class still works for anyone who only cares that something was
|
|
78
|
+
* absent.
|
|
79
|
+
*/
|
|
80
|
+
constructor(message?: string, code?: string);
|
|
55
81
|
}
|
|
56
82
|
/**
|
|
57
83
|
* Thrown when the request is rejected as invalid — the server responds with
|
|
58
84
|
* 400 and code `validation_error`.
|
|
59
85
|
*/
|
|
60
86
|
export declare class KoolbaseValidationError extends KoolbaseDataError {
|
|
61
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Carries its code for the same reason KoolbaseNotFoundError does: a
|
|
89
|
+
* dimension the platform does not support and a vector pointed at the wrong
|
|
90
|
+
* collection are both validation failures, and an app should still be able
|
|
91
|
+
* to tell which without reading the message.
|
|
92
|
+
*/
|
|
93
|
+
constructor(message?: string, code?: string);
|
|
62
94
|
}
|
|
63
95
|
/**
|
|
64
96
|
* Thrown when the caller is authenticated but not allowed to perform the
|
|
65
97
|
* operation — the server responds with 403 and code `permission_denied`
|
|
66
98
|
* (typically a collection access rule rejecting the read/write).
|
|
67
99
|
*/
|
|
100
|
+
/**
|
|
101
|
+
* Authenticated, and not permitted to do this — distinct from a rule denying
|
|
102
|
+
* access to a record. Its own class rather than folding into
|
|
103
|
+
* KoolbasePermissionError, which hardcodes permission_denied: an error
|
|
104
|
+
* reporting a code the server did not send is a small lie, and apps that
|
|
105
|
+
* branch on e.code rather than instanceof would act on it.
|
|
106
|
+
*/
|
|
107
|
+
export declare class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
|
|
108
|
+
constructor(message?: string);
|
|
109
|
+
}
|
|
68
110
|
export declare class KoolbasePermissionError extends KoolbaseDataError {
|
|
69
111
|
constructor(message?: string);
|
|
70
112
|
}
|
|
@@ -39,6 +39,37 @@ export class KoolbaseDataError extends KoolbaseError {
|
|
|
39
39
|
* }
|
|
40
40
|
* }
|
|
41
41
|
*/
|
|
42
|
+
/**
|
|
43
|
+
* An upsert whose filter matched more than one record.
|
|
44
|
+
*
|
|
45
|
+
* Refused rather than resolved: picking one of several would be a silent
|
|
46
|
+
* guess about which row the caller meant, and the wrong guess overwrites data
|
|
47
|
+
* nobody asked to change. Narrow the filter, or add a unique constraint over
|
|
48
|
+
* the fields you are matching on so the ambiguity cannot arise.
|
|
49
|
+
*/
|
|
50
|
+
export class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
|
|
51
|
+
constructor(message) {
|
|
52
|
+
super(message ?? 'Upsert match resolved to more than one record', 'ambiguous_match');
|
|
53
|
+
this.name = 'KoolbaseAmbiguousMatchError';
|
|
54
|
+
Object.setPrototypeOf(this, KoolbaseAmbiguousMatchError.prototype);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** A unique constraint already covers those fields. */
|
|
58
|
+
export class KoolbaseConstraintExistsError extends KoolbaseDataError {
|
|
59
|
+
constructor(message) {
|
|
60
|
+
super(message ?? 'A unique constraint already exists for these fields', 'constraint_exists');
|
|
61
|
+
this.name = 'KoolbaseConstraintExistsError';
|
|
62
|
+
Object.setPrototypeOf(this, KoolbaseConstraintExistsError.prototype);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** No such unique constraint. */
|
|
66
|
+
export class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
|
|
67
|
+
constructor(message) {
|
|
68
|
+
super(message ?? 'Unique constraint not found', 'constraint_not_found');
|
|
69
|
+
this.name = 'KoolbaseConstraintNotFoundError';
|
|
70
|
+
Object.setPrototypeOf(this, KoolbaseConstraintNotFoundError.prototype);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
42
73
|
export class KoolbaseConflictError extends KoolbaseDataError {
|
|
43
74
|
constructor(message, field) {
|
|
44
75
|
super(message ?? 'Value violates a unique constraint', 'unique_violation');
|
|
@@ -53,8 +84,15 @@ export class KoolbaseConflictError extends KoolbaseDataError {
|
|
|
53
84
|
* `collection_not_found`.
|
|
54
85
|
*/
|
|
55
86
|
export class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
56
|
-
|
|
57
|
-
|
|
87
|
+
/**
|
|
88
|
+
* The code is carried rather than fixed, because the server distinguishes
|
|
89
|
+
* what was missing — a record, a collection, a vector field — and an app
|
|
90
|
+
* reading e.code should get that answer rather than the category. Catching
|
|
91
|
+
* the class still works for anyone who only cares that something was
|
|
92
|
+
* absent.
|
|
93
|
+
*/
|
|
94
|
+
constructor(message, code = 'not_found') {
|
|
95
|
+
super(message ?? 'The requested resource was not found', code);
|
|
58
96
|
this.name = 'KoolbaseNotFoundError';
|
|
59
97
|
Object.setPrototypeOf(this, KoolbaseNotFoundError.prototype);
|
|
60
98
|
}
|
|
@@ -64,8 +102,14 @@ export class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
|
64
102
|
* 400 and code `validation_error`.
|
|
65
103
|
*/
|
|
66
104
|
export class KoolbaseValidationError extends KoolbaseDataError {
|
|
67
|
-
|
|
68
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Carries its code for the same reason KoolbaseNotFoundError does: a
|
|
107
|
+
* dimension the platform does not support and a vector pointed at the wrong
|
|
108
|
+
* collection are both validation failures, and an app should still be able
|
|
109
|
+
* to tell which without reading the message.
|
|
110
|
+
*/
|
|
111
|
+
constructor(message, code = 'validation_error') {
|
|
112
|
+
super(message ?? 'The request was invalid', code);
|
|
69
113
|
this.name = 'KoolbaseValidationError';
|
|
70
114
|
Object.setPrototypeOf(this, KoolbaseValidationError.prototype);
|
|
71
115
|
}
|
|
@@ -75,6 +119,20 @@ export class KoolbaseValidationError extends KoolbaseDataError {
|
|
|
75
119
|
* operation — the server responds with 403 and code `permission_denied`
|
|
76
120
|
* (typically a collection access rule rejecting the read/write).
|
|
77
121
|
*/
|
|
122
|
+
/**
|
|
123
|
+
* Authenticated, and not permitted to do this — distinct from a rule denying
|
|
124
|
+
* access to a record. Its own class rather than folding into
|
|
125
|
+
* KoolbasePermissionError, which hardcodes permission_denied: an error
|
|
126
|
+
* reporting a code the server did not send is a small lie, and apps that
|
|
127
|
+
* branch on e.code rather than instanceof would act on it.
|
|
128
|
+
*/
|
|
129
|
+
export class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
|
|
130
|
+
constructor(message) {
|
|
131
|
+
super(message ?? 'You do not have the authority to perform this action', 'insufficient_authority');
|
|
132
|
+
this.name = 'KoolbaseInsufficientAuthorityError';
|
|
133
|
+
Object.setPrototypeOf(this, KoolbaseInsufficientAuthorityError.prototype);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
78
136
|
export class KoolbasePermissionError extends KoolbaseDataError {
|
|
79
137
|
constructor(message) {
|
|
80
138
|
super(message ?? 'You do not have permission to perform this action', 'permission_denied');
|
|
@@ -144,12 +202,20 @@ export function koolbaseDataError(status, body, fallbackMessage = 'Request faile
|
|
|
144
202
|
switch (code) {
|
|
145
203
|
case 'unique_violation':
|
|
146
204
|
return attach(new KoolbaseConflictError(message, field));
|
|
205
|
+
case 'ambiguous_match':
|
|
206
|
+
return attach(new KoolbaseAmbiguousMatchError(message));
|
|
207
|
+
case 'constraint_exists':
|
|
208
|
+
return attach(new KoolbaseConstraintExistsError(message));
|
|
209
|
+
case 'constraint_not_found':
|
|
210
|
+
return attach(new KoolbaseConstraintNotFoundError(message));
|
|
211
|
+
case 'insufficient_authority':
|
|
212
|
+
return attach(new KoolbaseInsufficientAuthorityError(message));
|
|
147
213
|
case 'not_found':
|
|
148
214
|
case 'record_not_found':
|
|
149
215
|
case 'collection_not_found':
|
|
150
216
|
case 'vector_not_found':
|
|
151
217
|
case 'vector_field_not_found':
|
|
152
|
-
return attach(new KoolbaseNotFoundError(message));
|
|
218
|
+
return attach(new KoolbaseNotFoundError(message, code));
|
|
153
219
|
case 'unauthenticated':
|
|
154
220
|
case 'session_expired':
|
|
155
221
|
case 'invalid_token':
|
|
@@ -161,7 +227,7 @@ export function koolbaseDataError(status, body, fallbackMessage = 'Request faile
|
|
|
161
227
|
case 'validation_error':
|
|
162
228
|
case 'vector_collection_mismatch':
|
|
163
229
|
case 'unsupported_dimension':
|
|
164
|
-
return attach(new KoolbaseValidationError(message));
|
|
230
|
+
return attach(new KoolbaseValidationError(message, code));
|
|
165
231
|
case 'vector_dimension_mismatch':
|
|
166
232
|
return attach(new KoolbaseVectorDimensionMismatchError(message));
|
|
167
233
|
}
|
|
@@ -47,5 +47,24 @@ export declare class FunctionQuotaExceededError extends FunctionInvokeError {
|
|
|
47
47
|
export declare class FunctionExecutionError extends FunctionInvokeError {
|
|
48
48
|
constructor(message: string, statusCode?: number);
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* The function ran past its timeout and was killed.
|
|
52
|
+
*
|
|
53
|
+
* Its own type because the remedy is different from a function that threw:
|
|
54
|
+
* a timeout means retry, or raise the function's timeout at deploy, or move
|
|
55
|
+
* the slow part elsewhere. Without this it arrived as FunctionExecutionError
|
|
56
|
+
* — indistinguishable from an exception, which is the one thing it is not.
|
|
57
|
+
* The server already tells them apart; it logs 504 as "timeout".
|
|
58
|
+
*/
|
|
59
|
+
export declare class FunctionTimeoutError extends FunctionInvokeError {
|
|
60
|
+
constructor(message: string);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Too many invocations, too fast. Distinct from a quota being spent: this one
|
|
64
|
+
* clears by waiting.
|
|
65
|
+
*/
|
|
66
|
+
export declare class FunctionRateLimitError extends FunctionInvokeError {
|
|
67
|
+
constructor(message: string);
|
|
68
|
+
}
|
|
50
69
|
/** Builds the right error for a failed invocation. */
|
|
51
70
|
export declare function functionInvokeError(status: number, message: string): KoolbaseError;
|
|
@@ -71,6 +71,33 @@ export class FunctionExecutionError extends FunctionInvokeError {
|
|
|
71
71
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* The function ran past its timeout and was killed.
|
|
76
|
+
*
|
|
77
|
+
* Its own type because the remedy is different from a function that threw:
|
|
78
|
+
* a timeout means retry, or raise the function's timeout at deploy, or move
|
|
79
|
+
* the slow part elsewhere. Without this it arrived as FunctionExecutionError
|
|
80
|
+
* — indistinguishable from an exception, which is the one thing it is not.
|
|
81
|
+
* The server already tells them apart; it logs 504 as "timeout".
|
|
82
|
+
*/
|
|
83
|
+
export class FunctionTimeoutError extends FunctionInvokeError {
|
|
84
|
+
constructor(message) {
|
|
85
|
+
super(message, 504, 'timeout');
|
|
86
|
+
this.name = 'FunctionTimeoutError';
|
|
87
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Too many invocations, too fast. Distinct from a quota being spent: this one
|
|
92
|
+
* clears by waiting.
|
|
93
|
+
*/
|
|
94
|
+
export class FunctionRateLimitError extends FunctionInvokeError {
|
|
95
|
+
constructor(message) {
|
|
96
|
+
super(message, 429, 'rate_limit');
|
|
97
|
+
this.name = 'FunctionRateLimitError';
|
|
98
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
74
101
|
/** Builds the right error for a failed invocation. */
|
|
75
102
|
export function functionInvokeError(status, message) {
|
|
76
103
|
switch (status) {
|
|
@@ -86,6 +113,11 @@ export function functionInvokeError(status, message) {
|
|
|
86
113
|
return new FunctionValidationError(message);
|
|
87
114
|
case 402:
|
|
88
115
|
return new FunctionQuotaExceededError(message);
|
|
116
|
+
case 429:
|
|
117
|
+
return new FunctionRateLimitError(message);
|
|
118
|
+
case 504:
|
|
119
|
+
// Before the generic 5xx branch: a timeout is not an exception.
|
|
120
|
+
return new FunctionTimeoutError(message);
|
|
89
121
|
}
|
|
90
122
|
if (status >= 500)
|
|
91
123
|
return new FunctionExecutionError(message, status);
|
|
@@ -76,6 +76,24 @@ export declare class KoolbaseStoragePermissionError extends KoolbaseStorageError
|
|
|
76
76
|
* 409 but means "path collides"); branch on the error type via
|
|
77
77
|
* `instanceof`, not on status.
|
|
78
78
|
*/
|
|
79
|
+
/**
|
|
80
|
+
* The presigned upload was confirmed after its window closed.
|
|
81
|
+
*
|
|
82
|
+
* An upload URL has a lifetime. A user who picks a file, gets distracted and
|
|
83
|
+
* comes back twenty minutes later hits this — so it is a retry, not a
|
|
84
|
+
* failure: presign again and send the same bytes. Worth catching rather than
|
|
85
|
+
* showing "upload failed" to someone whose file was fine.
|
|
86
|
+
*/
|
|
87
|
+
export declare class KoolbaseUploadExpiredError extends KoolbaseStorageError {
|
|
88
|
+
constructor(message?: string);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A bucket cap set below what the bucket already holds. A dashboard
|
|
92
|
+
* operation rather than an app one, mapped so it does not arrive untyped.
|
|
93
|
+
*/
|
|
94
|
+
export declare class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
|
|
95
|
+
constructor(message?: string);
|
|
96
|
+
}
|
|
79
97
|
export declare class KoolbaseStorageQuotaError extends KoolbaseStorageError {
|
|
80
98
|
constructor(message?: string);
|
|
81
99
|
}
|