@koolbase/core 11.0.0 → 11.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.
@@ -17,7 +17,13 @@ export declare class UserDisabledError extends KoolbaseAuthError {
17
17
  constructor();
18
18
  }
19
19
  export declare class WeakPasswordError extends KoolbaseAuthError {
20
- constructor();
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
  }
@@ -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
- constructor() {
45
- super('Password must be at least 8 characters', 'weak_password');
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':
@@ -17,7 +17,13 @@ export declare class UserDisabledError extends KoolbaseAuthError {
17
17
  constructor();
18
18
  }
19
19
  export declare class WeakPasswordError extends KoolbaseAuthError {
20
- constructor();
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
  }
@@ -34,8 +34,14 @@ export class UserDisabledError extends KoolbaseAuthError {
34
34
  }
35
35
  }
36
36
  export class WeakPasswordError extends KoolbaseAuthError {
37
- constructor() {
38
- super('Password must be at least 8 characters', 'weak_password');
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':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/esm/index.d.ts",