@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
|
@@ -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/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.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.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;
|
|
4
4
|
const errors_js_1 = require("./errors.js");
|
|
5
5
|
/**
|
|
6
6
|
* Base error type for all Koolbase auth errors. Catchable via
|
|
@@ -41,8 +41,14 @@ class UserDisabledError extends KoolbaseAuthError {
|
|
|
41
41
|
}
|
|
42
42
|
exports.UserDisabledError = UserDisabledError;
|
|
43
43
|
class WeakPasswordError extends KoolbaseAuthError {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
/**
|
|
45
|
+
* The message is optional so the server's own rule can be carried through.
|
|
46
|
+
* The SDK checks length before sending; a project may require more than
|
|
47
|
+
* that, and "must be at least 8 characters" would then be wrong as well as
|
|
48
|
+
* unhelpful.
|
|
49
|
+
*/
|
|
50
|
+
constructor(message) {
|
|
51
|
+
super(message ?? 'Password must be at least 8 characters', 'weak_password');
|
|
46
52
|
this.name = 'WeakPasswordError';
|
|
47
53
|
Object.setPrototypeOf(this, WeakPasswordError.prototype);
|
|
48
54
|
}
|
|
@@ -271,6 +277,139 @@ exports.GoogleSignInNotConfiguredError = GoogleSignInNotConfiguredError;
|
|
|
271
277
|
* from it is what produced a signed-in user whose every request went out as
|
|
272
278
|
* `Bearer undefined`, so the SDK refuses instead.
|
|
273
279
|
*/
|
|
280
|
+
/**
|
|
281
|
+
* Sign-in refused because the account has not verified its email or phone.
|
|
282
|
+
*
|
|
283
|
+
* In a project with require_verified_contact on, this is the most common auth
|
|
284
|
+
* error there is — the user registered, did not click the link, and came back.
|
|
285
|
+
* It arrived untyped until 11.1.0, so apps showed "something went wrong" for
|
|
286
|
+
* the one case with an obvious remedy: offer to resend.
|
|
287
|
+
*/
|
|
288
|
+
class ContactNotVerifiedError extends KoolbaseAuthError {
|
|
289
|
+
constructor(message) {
|
|
290
|
+
super(message ?? 'Verify your email or phone before signing in', 'contact_not_verified');
|
|
291
|
+
this.name = 'ContactNotVerifiedError';
|
|
292
|
+
Object.setPrototypeOf(this, ContactNotVerifiedError.prototype);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
exports.ContactNotVerifiedError = ContactNotVerifiedError;
|
|
296
|
+
/** The project has registration turned off. Not a credential problem. */
|
|
297
|
+
class SignupsDisabledError extends KoolbaseAuthError {
|
|
298
|
+
constructor(message) {
|
|
299
|
+
super(message ?? 'Registration is disabled for this project', 'signups_disabled');
|
|
300
|
+
this.name = 'SignupsDisabledError';
|
|
301
|
+
Object.setPrototypeOf(this, SignupsDisabledError.prototype);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.SignupsDisabledError = SignupsDisabledError;
|
|
305
|
+
/**
|
|
306
|
+
* A verification or reset link that has expired.
|
|
307
|
+
*
|
|
308
|
+
* Distinct from TokenAlreadyUsedError because the remedy differs: expired
|
|
309
|
+
* means request another, used means it already worked and they may simply be
|
|
310
|
+
* clicking an old email.
|
|
311
|
+
*/
|
|
312
|
+
class TokenExpiredError extends KoolbaseAuthError {
|
|
313
|
+
constructor(message) {
|
|
314
|
+
super(message ?? 'This link has expired — request a new one', 'token_expired');
|
|
315
|
+
this.name = 'TokenExpiredError';
|
|
316
|
+
Object.setPrototypeOf(this, TokenExpiredError.prototype);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
exports.TokenExpiredError = TokenExpiredError;
|
|
320
|
+
/** A one-shot link clicked twice. Often means it already succeeded. */
|
|
321
|
+
class TokenAlreadyUsedError extends KoolbaseAuthError {
|
|
322
|
+
constructor(message) {
|
|
323
|
+
super(message ?? 'This link has already been used', 'token_used');
|
|
324
|
+
this.name = 'TokenAlreadyUsedError';
|
|
325
|
+
Object.setPrototypeOf(this, TokenAlreadyUsedError.prototype);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
exports.TokenAlreadyUsedError = TokenAlreadyUsedError;
|
|
329
|
+
/**
|
|
330
|
+
* The current password given for a password change was wrong.
|
|
331
|
+
*
|
|
332
|
+
* Named for the operation rather than the code: the server calls this
|
|
333
|
+
* `invalid_password`, which reads like a rejected new password and is not.
|
|
334
|
+
*/
|
|
335
|
+
class CurrentPasswordIncorrectError extends KoolbaseAuthError {
|
|
336
|
+
constructor(message) {
|
|
337
|
+
super(message ?? 'Current password is incorrect', 'invalid_password');
|
|
338
|
+
this.name = 'CurrentPasswordIncorrectError';
|
|
339
|
+
Object.setPrototypeOf(this, CurrentPasswordIncorrectError.prototype);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
exports.CurrentPasswordIncorrectError = CurrentPasswordIncorrectError;
|
|
343
|
+
/**
|
|
344
|
+
* An OAuth sign-in for an email that already has an account by another
|
|
345
|
+
* method. The remedy is to sign in the original way and connect the provider
|
|
346
|
+
* afterwards, which the server's message says.
|
|
347
|
+
*/
|
|
348
|
+
class AccountExistsError extends KoolbaseAuthError {
|
|
349
|
+
constructor(message) {
|
|
350
|
+
super(message ?? 'An account with this email already exists — sign in with your existing method first', 'account_exists');
|
|
351
|
+
this.name = 'AccountExistsError';
|
|
352
|
+
Object.setPrototypeOf(this, AccountExistsError.prototype);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
exports.AccountExistsError = AccountExistsError;
|
|
356
|
+
/** A password attempt against an account that only has Google or Apple. */
|
|
357
|
+
class OAuthOnlyAccountError extends KoolbaseAuthError {
|
|
358
|
+
constructor(message) {
|
|
359
|
+
super(message ?? 'This account uses Google or Apple sign-in and has no password', 'oauth_only_account');
|
|
360
|
+
this.name = 'OAuthOnlyAccountError';
|
|
361
|
+
Object.setPrototypeOf(this, OAuthOnlyAccountError.prototype);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
exports.OAuthOnlyAccountError = OAuthOnlyAccountError;
|
|
365
|
+
/** A provider the project has not enabled. */
|
|
366
|
+
class UnsupportedOAuthProviderError extends KoolbaseAuthError {
|
|
367
|
+
constructor(message) {
|
|
368
|
+
super(message ?? 'That sign-in provider is not supported', 'unsupported_oauth_provider');
|
|
369
|
+
this.name = 'UnsupportedOAuthProviderError';
|
|
370
|
+
Object.setPrototypeOf(this, UnsupportedOAuthProviderError.prototype);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
exports.UnsupportedOAuthProviderError = UnsupportedOAuthProviderError;
|
|
374
|
+
/** The call needs a signed-in user and did not have one. */
|
|
375
|
+
class SessionRequiredError extends KoolbaseAuthError {
|
|
376
|
+
constructor(message) {
|
|
377
|
+
super(message ?? 'This action requires a signed-in user', 'session_required');
|
|
378
|
+
this.name = 'SessionRequiredError';
|
|
379
|
+
Object.setPrototypeOf(this, SessionRequiredError.prototype);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
exports.SessionRequiredError = SessionRequiredError;
|
|
383
|
+
/** The caller is authenticated but not permitted to do this. */
|
|
384
|
+
class InsufficientAuthorityError extends KoolbaseAuthError {
|
|
385
|
+
constructor(message) {
|
|
386
|
+
super(message ?? 'You do not have permission to do that', 'insufficient_authority');
|
|
387
|
+
this.name = 'InsufficientAuthorityError';
|
|
388
|
+
Object.setPrototypeOf(this, InsufficientAuthorityError.prototype);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
exports.InsufficientAuthorityError = InsufficientAuthorityError;
|
|
392
|
+
/**
|
|
393
|
+
* Refused because it would remove the account's last way of signing in —
|
|
394
|
+
* unlinking the only provider, or clearing the only password.
|
|
395
|
+
*/
|
|
396
|
+
class LastCredentialError extends KoolbaseAuthError {
|
|
397
|
+
constructor(message) {
|
|
398
|
+
super(message ?? 'This is the account\'s only sign-in method and cannot be removed', 'last_credential');
|
|
399
|
+
this.name = 'LastCredentialError';
|
|
400
|
+
Object.setPrototypeOf(this, LastCredentialError.prototype);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
exports.LastCredentialError = LastCredentialError;
|
|
404
|
+
/** Hiding account existence needs verification on; the project has it off. */
|
|
405
|
+
class HideRequiresVerificationError extends KoolbaseAuthError {
|
|
406
|
+
constructor(message) {
|
|
407
|
+
super(message ?? 'Hiding account existence requires verified contact to be enabled', 'hide_requires_verification');
|
|
408
|
+
this.name = 'HideRequiresVerificationError';
|
|
409
|
+
Object.setPrototypeOf(this, HideRequiresVerificationError.prototype);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
exports.HideRequiresVerificationError = HideRequiresVerificationError;
|
|
274
413
|
class MalformedSessionResponseError extends KoolbaseAuthError {
|
|
275
414
|
constructor(missing) {
|
|
276
415
|
super(`The server returned a session without ${missing}. This is a protocol error, not a credential problem.`, 'malformed_session_response');
|
package/dist/cjs/auth.js
CHANGED
|
@@ -797,6 +797,49 @@ class KoolbaseAuth {
|
|
|
797
797
|
throw new auth_errors_js_1.UnlockTokenInvalidError();
|
|
798
798
|
case 'rate_limit':
|
|
799
799
|
throw new auth_errors_js_1.RateLimitError(msg || undefined);
|
|
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
|
+
// Verification state. Two codes, one situation — projectauth and the
|
|
804
|
+
// dashboard's auth package name it differently and an app should not
|
|
805
|
+
// have to know which spoke.
|
|
806
|
+
case 'contact_not_verified':
|
|
807
|
+
case 'email_not_verified':
|
|
808
|
+
throw new auth_errors_js_1.ContactNotVerifiedError(msg || undefined);
|
|
809
|
+
// Registration
|
|
810
|
+
case 'signups_disabled':
|
|
811
|
+
throw new auth_errors_js_1.SignupsDisabledError(msg || undefined);
|
|
812
|
+
case 'weak_password':
|
|
813
|
+
// The class existed and was only ever thrown client-side for length.
|
|
814
|
+
// The server has its own rules, and a password that passes ours and
|
|
815
|
+
// fails theirs deserves the same error, not a generic one.
|
|
816
|
+
throw new auth_errors_js_1.WeakPasswordError(msg || undefined);
|
|
817
|
+
case 'account_exists':
|
|
818
|
+
throw new auth_errors_js_1.AccountExistsError(msg || undefined);
|
|
819
|
+
// Link tokens — verification and password reset
|
|
820
|
+
case 'token_expired':
|
|
821
|
+
throw new auth_errors_js_1.TokenExpiredError(msg || undefined);
|
|
822
|
+
case 'token_used':
|
|
823
|
+
throw new auth_errors_js_1.TokenAlreadyUsedError(msg || undefined);
|
|
824
|
+
case 'invalid_token':
|
|
825
|
+
throw new auth_errors_js_1.UnlockTokenInvalidError();
|
|
826
|
+
// Password change
|
|
827
|
+
case 'invalid_password':
|
|
828
|
+
throw new auth_errors_js_1.CurrentPasswordIncorrectError(msg || undefined);
|
|
829
|
+
// OAuth
|
|
830
|
+
case 'oauth_only_account':
|
|
831
|
+
throw new auth_errors_js_1.OAuthOnlyAccountError(msg || undefined);
|
|
832
|
+
case 'unsupported_oauth_provider':
|
|
833
|
+
throw new auth_errors_js_1.UnsupportedOAuthProviderError(msg || undefined);
|
|
834
|
+
// Authority
|
|
835
|
+
case 'session_required':
|
|
836
|
+
throw new auth_errors_js_1.SessionRequiredError(msg || undefined);
|
|
837
|
+
case 'insufficient_authority':
|
|
838
|
+
throw new auth_errors_js_1.InsufficientAuthorityError(msg || undefined);
|
|
839
|
+
case 'last_credential':
|
|
840
|
+
throw new auth_errors_js_1.LastCredentialError(msg || undefined);
|
|
841
|
+
case 'hide_requires_verification':
|
|
842
|
+
throw new auth_errors_js_1.HideRequiresVerificationError(msg || undefined);
|
|
800
843
|
case 'resend_cooldown':
|
|
801
844
|
throw new auth_errors_js_1.VerificationResendCooldownError(body.cooldown_until ? new Date(body.cooldown_until) : null, msg || undefined);
|
|
802
845
|
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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseVectorDimensionMismatchError = exports.KoolbaseRateLimitError = exports.KoolbasePermissionError = exports.KoolbaseValidationError = exports.KoolbaseNotFoundError = exports.KoolbaseConflictError = exports.KoolbaseDataError = void 0;
|
|
3
|
+
exports.KoolbaseVectorDimensionMismatchError = exports.KoolbaseRateLimitError = exports.KoolbasePermissionError = exports.KoolbaseInsufficientAuthorityError = exports.KoolbaseValidationError = exports.KoolbaseNotFoundError = exports.KoolbaseConflictError = exports.KoolbaseConstraintNotFoundError = exports.KoolbaseConstraintExistsError = exports.KoolbaseAmbiguousMatchError = exports.KoolbaseDataError = void 0;
|
|
4
4
|
exports.koolbaseDataError = koolbaseDataError;
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
6
|
/**
|
|
@@ -44,6 +44,40 @@ exports.KoolbaseDataError = KoolbaseDataError;
|
|
|
44
44
|
* }
|
|
45
45
|
* }
|
|
46
46
|
*/
|
|
47
|
+
/**
|
|
48
|
+
* An upsert whose filter matched more than one record.
|
|
49
|
+
*
|
|
50
|
+
* Refused rather than resolved: picking one of several would be a silent
|
|
51
|
+
* guess about which row the caller meant, and the wrong guess overwrites data
|
|
52
|
+
* nobody asked to change. Narrow the filter, or add a unique constraint over
|
|
53
|
+
* the fields you are matching on so the ambiguity cannot arise.
|
|
54
|
+
*/
|
|
55
|
+
class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message ?? 'Upsert match resolved to more than one record', 'ambiguous_match');
|
|
58
|
+
this.name = 'KoolbaseAmbiguousMatchError';
|
|
59
|
+
Object.setPrototypeOf(this, KoolbaseAmbiguousMatchError.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.KoolbaseAmbiguousMatchError = KoolbaseAmbiguousMatchError;
|
|
63
|
+
/** A unique constraint already covers those fields. */
|
|
64
|
+
class KoolbaseConstraintExistsError extends KoolbaseDataError {
|
|
65
|
+
constructor(message) {
|
|
66
|
+
super(message ?? 'A unique constraint already exists for these fields', 'constraint_exists');
|
|
67
|
+
this.name = 'KoolbaseConstraintExistsError';
|
|
68
|
+
Object.setPrototypeOf(this, KoolbaseConstraintExistsError.prototype);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.KoolbaseConstraintExistsError = KoolbaseConstraintExistsError;
|
|
72
|
+
/** No such unique constraint. */
|
|
73
|
+
class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
|
|
74
|
+
constructor(message) {
|
|
75
|
+
super(message ?? 'Unique constraint not found', 'constraint_not_found');
|
|
76
|
+
this.name = 'KoolbaseConstraintNotFoundError';
|
|
77
|
+
Object.setPrototypeOf(this, KoolbaseConstraintNotFoundError.prototype);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.KoolbaseConstraintNotFoundError = KoolbaseConstraintNotFoundError;
|
|
47
81
|
class KoolbaseConflictError extends KoolbaseDataError {
|
|
48
82
|
constructor(message, field) {
|
|
49
83
|
super(message ?? 'Value violates a unique constraint', 'unique_violation');
|
|
@@ -59,8 +93,15 @@ exports.KoolbaseConflictError = KoolbaseConflictError;
|
|
|
59
93
|
* `collection_not_found`.
|
|
60
94
|
*/
|
|
61
95
|
class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
62
|
-
|
|
63
|
-
|
|
96
|
+
/**
|
|
97
|
+
* The code is carried rather than fixed, because the server distinguishes
|
|
98
|
+
* what was missing — a record, a collection, a vector field — and an app
|
|
99
|
+
* reading e.code should get that answer rather than the category. Catching
|
|
100
|
+
* the class still works for anyone who only cares that something was
|
|
101
|
+
* absent.
|
|
102
|
+
*/
|
|
103
|
+
constructor(message, code = 'not_found') {
|
|
104
|
+
super(message ?? 'The requested resource was not found', code);
|
|
64
105
|
this.name = 'KoolbaseNotFoundError';
|
|
65
106
|
Object.setPrototypeOf(this, KoolbaseNotFoundError.prototype);
|
|
66
107
|
}
|
|
@@ -71,8 +112,14 @@ exports.KoolbaseNotFoundError = KoolbaseNotFoundError;
|
|
|
71
112
|
* 400 and code `validation_error`.
|
|
72
113
|
*/
|
|
73
114
|
class KoolbaseValidationError extends KoolbaseDataError {
|
|
74
|
-
|
|
75
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Carries its code for the same reason KoolbaseNotFoundError does: a
|
|
117
|
+
* dimension the platform does not support and a vector pointed at the wrong
|
|
118
|
+
* collection are both validation failures, and an app should still be able
|
|
119
|
+
* to tell which without reading the message.
|
|
120
|
+
*/
|
|
121
|
+
constructor(message, code = 'validation_error') {
|
|
122
|
+
super(message ?? 'The request was invalid', code);
|
|
76
123
|
this.name = 'KoolbaseValidationError';
|
|
77
124
|
Object.setPrototypeOf(this, KoolbaseValidationError.prototype);
|
|
78
125
|
}
|
|
@@ -83,6 +130,21 @@ exports.KoolbaseValidationError = KoolbaseValidationError;
|
|
|
83
130
|
* operation — the server responds with 403 and code `permission_denied`
|
|
84
131
|
* (typically a collection access rule rejecting the read/write).
|
|
85
132
|
*/
|
|
133
|
+
/**
|
|
134
|
+
* Authenticated, and not permitted to do this — distinct from a rule denying
|
|
135
|
+
* access to a record. Its own class rather than folding into
|
|
136
|
+
* KoolbasePermissionError, which hardcodes permission_denied: an error
|
|
137
|
+
* reporting a code the server did not send is a small lie, and apps that
|
|
138
|
+
* branch on e.code rather than instanceof would act on it.
|
|
139
|
+
*/
|
|
140
|
+
class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
|
|
141
|
+
constructor(message) {
|
|
142
|
+
super(message ?? 'You do not have the authority to perform this action', 'insufficient_authority');
|
|
143
|
+
this.name = 'KoolbaseInsufficientAuthorityError';
|
|
144
|
+
Object.setPrototypeOf(this, KoolbaseInsufficientAuthorityError.prototype);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.KoolbaseInsufficientAuthorityError = KoolbaseInsufficientAuthorityError;
|
|
86
148
|
class KoolbasePermissionError extends KoolbaseDataError {
|
|
87
149
|
constructor(message) {
|
|
88
150
|
super(message ?? 'You do not have permission to perform this action', 'permission_denied');
|
|
@@ -155,12 +217,20 @@ function koolbaseDataError(status, body, fallbackMessage = 'Request failed') {
|
|
|
155
217
|
switch (code) {
|
|
156
218
|
case 'unique_violation':
|
|
157
219
|
return attach(new KoolbaseConflictError(message, field));
|
|
220
|
+
case 'ambiguous_match':
|
|
221
|
+
return attach(new KoolbaseAmbiguousMatchError(message));
|
|
222
|
+
case 'constraint_exists':
|
|
223
|
+
return attach(new KoolbaseConstraintExistsError(message));
|
|
224
|
+
case 'constraint_not_found':
|
|
225
|
+
return attach(new KoolbaseConstraintNotFoundError(message));
|
|
226
|
+
case 'insufficient_authority':
|
|
227
|
+
return attach(new KoolbaseInsufficientAuthorityError(message));
|
|
158
228
|
case 'not_found':
|
|
159
229
|
case 'record_not_found':
|
|
160
230
|
case 'collection_not_found':
|
|
161
231
|
case 'vector_not_found':
|
|
162
232
|
case 'vector_field_not_found':
|
|
163
|
-
return attach(new KoolbaseNotFoundError(message));
|
|
233
|
+
return attach(new KoolbaseNotFoundError(message, code));
|
|
164
234
|
case 'unauthenticated':
|
|
165
235
|
case 'session_expired':
|
|
166
236
|
case 'invalid_token':
|
|
@@ -172,7 +242,7 @@ function koolbaseDataError(status, body, fallbackMessage = 'Request failed') {
|
|
|
172
242
|
case 'validation_error':
|
|
173
243
|
case 'vector_collection_mismatch':
|
|
174
244
|
case 'unsupported_dimension':
|
|
175
|
-
return attach(new KoolbaseValidationError(message));
|
|
245
|
+
return attach(new KoolbaseValidationError(message, code));
|
|
176
246
|
case 'vector_dimension_mismatch':
|
|
177
247
|
return attach(new KoolbaseVectorDimensionMismatchError(message));
|
|
178
248
|
}
|
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FunctionExecutionError = exports.FunctionQuotaExceededError = exports.FunctionValidationError = exports.FunctionPermissionError = exports.FunctionNotFoundError = exports.FunctionInvokeError = void 0;
|
|
3
|
+
exports.FunctionRateLimitError = exports.FunctionTimeoutError = exports.FunctionExecutionError = exports.FunctionQuotaExceededError = exports.FunctionValidationError = exports.FunctionPermissionError = exports.FunctionNotFoundError = exports.FunctionInvokeError = void 0;
|
|
4
4
|
exports.functionInvokeError = functionInvokeError;
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
6
|
/**
|
|
@@ -81,6 +81,35 @@ class FunctionExecutionError extends FunctionInvokeError {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
exports.FunctionExecutionError = FunctionExecutionError;
|
|
84
|
+
/**
|
|
85
|
+
* The function ran past its timeout and was killed.
|
|
86
|
+
*
|
|
87
|
+
* Its own type because the remedy is different from a function that threw:
|
|
88
|
+
* a timeout means retry, or raise the function's timeout at deploy, or move
|
|
89
|
+
* the slow part elsewhere. Without this it arrived as FunctionExecutionError
|
|
90
|
+
* — indistinguishable from an exception, which is the one thing it is not.
|
|
91
|
+
* The server already tells them apart; it logs 504 as "timeout".
|
|
92
|
+
*/
|
|
93
|
+
class FunctionTimeoutError extends FunctionInvokeError {
|
|
94
|
+
constructor(message) {
|
|
95
|
+
super(message, 504, 'timeout');
|
|
96
|
+
this.name = 'FunctionTimeoutError';
|
|
97
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.FunctionTimeoutError = FunctionTimeoutError;
|
|
101
|
+
/**
|
|
102
|
+
* Too many invocations, too fast. Distinct from a quota being spent: this one
|
|
103
|
+
* clears by waiting.
|
|
104
|
+
*/
|
|
105
|
+
class FunctionRateLimitError extends FunctionInvokeError {
|
|
106
|
+
constructor(message) {
|
|
107
|
+
super(message, 429, 'rate_limit');
|
|
108
|
+
this.name = 'FunctionRateLimitError';
|
|
109
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.FunctionRateLimitError = FunctionRateLimitError;
|
|
84
113
|
/** Builds the right error for a failed invocation. */
|
|
85
114
|
function functionInvokeError(status, message) {
|
|
86
115
|
switch (status) {
|
|
@@ -96,6 +125,11 @@ function functionInvokeError(status, message) {
|
|
|
96
125
|
return new FunctionValidationError(message);
|
|
97
126
|
case 402:
|
|
98
127
|
return new FunctionQuotaExceededError(message);
|
|
128
|
+
case 429:
|
|
129
|
+
return new FunctionRateLimitError(message);
|
|
130
|
+
case 504:
|
|
131
|
+
// Before the generic 5xx branch: a timeout is not an exception.
|
|
132
|
+
return new FunctionTimeoutError(message);
|
|
99
133
|
}
|
|
100
134
|
if (status >= 500)
|
|
101
135
|
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
|
}
|