@koolbase/core 11.1.0 → 11.3.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.
@@ -217,6 +217,29 @@ export declare class LastCredentialError extends KoolbaseAuthError {
217
217
  export declare class HideRequiresVerificationError extends KoolbaseAuthError {
218
218
  constructor(message?: string);
219
219
  }
220
+ /**
221
+ * The API key's scope is below what the operation requires.
222
+ *
223
+ * Scopes rank read < write < admin. Not a credential problem — the key is
224
+ * valid, and a different key or a dashboard session is needed. Worth its own
225
+ * type so an app does not tell someone to sign in again when signing in will
226
+ * not help.
227
+ */
228
+ export declare class InsufficientScopeError extends KoolbaseAuthError {
229
+ constructor(message?: string);
230
+ }
231
+ /** The provider is not connected to this account. */
232
+ export declare class IdentityNotFoundError extends KoolbaseAuthError {
233
+ constructor(message?: string);
234
+ }
235
+ /**
236
+ * Connecting a Google or Apple identity that another account already holds.
237
+ * Distinct from AccountExistsError, which is about the email; this is about
238
+ * the provider identity itself.
239
+ */
240
+ export declare class ProviderIdentityAlreadyLinkedError extends KoolbaseAuthError {
241
+ constructor(message?: string);
242
+ }
220
243
  export declare class MalformedSessionResponseError extends KoolbaseAuthError {
221
244
  constructor(missing: string);
222
245
  }
@@ -370,6 +370,41 @@ export class HideRequiresVerificationError extends KoolbaseAuthError {
370
370
  Object.setPrototypeOf(this, HideRequiresVerificationError.prototype);
371
371
  }
372
372
  }
373
+ /**
374
+ * The API key's scope is below what the operation requires.
375
+ *
376
+ * Scopes rank read < write < admin. Not a credential problem — the key is
377
+ * valid, and a different key or a dashboard session is needed. Worth its own
378
+ * type so an app does not tell someone to sign in again when signing in will
379
+ * not help.
380
+ */
381
+ export class InsufficientScopeError extends KoolbaseAuthError {
382
+ constructor(message) {
383
+ super(message ?? "This key's scope does not permit this operation", 'insufficient_scope');
384
+ this.name = 'InsufficientScopeError';
385
+ Object.setPrototypeOf(this, InsufficientScopeError.prototype);
386
+ }
387
+ }
388
+ /** The provider is not connected to this account. */
389
+ export class IdentityNotFoundError extends KoolbaseAuthError {
390
+ constructor(message) {
391
+ super(message ?? 'That provider is not connected to your account', 'identity_not_found');
392
+ this.name = 'IdentityNotFoundError';
393
+ Object.setPrototypeOf(this, IdentityNotFoundError.prototype);
394
+ }
395
+ }
396
+ /**
397
+ * Connecting a Google or Apple identity that another account already holds.
398
+ * Distinct from AccountExistsError, which is about the email; this is about
399
+ * the provider identity itself.
400
+ */
401
+ export class ProviderIdentityAlreadyLinkedError extends KoolbaseAuthError {
402
+ constructor(message) {
403
+ super(message ?? 'That provider identity is already linked to another account', 'provider_identity_already_linked');
404
+ this.name = 'ProviderIdentityAlreadyLinkedError';
405
+ Object.setPrototypeOf(this, ProviderIdentityAlreadyLinkedError.prototype);
406
+ }
407
+ }
373
408
  export class MalformedSessionResponseError extends KoolbaseAuthError {
374
409
  constructor(missing) {
375
410
  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, 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';
2
+ import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, IdentityNotFoundError, InsufficientScopeError, MalformedSessionResponseError, ProviderIdentityAlreadyLinkedError, AccountExistsError, ContactNotVerifiedError, CurrentPasswordIncorrectError, HideRequiresVerificationError, InsufficientAuthorityError, LastCredentialError, OAuthOnlyAccountError, SessionRequiredError, SignupsDisabledError, TokenAlreadyUsedError, TokenExpiredError, UnsupportedOAuthProviderError, RateLimitError, VerificationResendCooldownError, VerificationResendDailyCapError, SessionExpiredError, SmsConfigMissingError, 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 {
@@ -195,9 +195,16 @@ export class KoolbaseAuth {
195
195
  return RestoreResult.Restored;
196
196
  }
197
197
  catch (e) {
198
- if (e instanceof SessionExpiredError ||
199
- e instanceof TokenRevokedError ||
200
- e instanceof InvalidCredentialsError) {
198
+ // Only a refresh the server refused clears the stored session, and
199
+ // only because the refresh token is the last credential there is — once
200
+ // it is rejected there is nothing left to try.
201
+ //
202
+ // InvalidCredentialsError used to be in this list. It means "these
203
+ // credentials are wrong", which during a restore points at the project
204
+ // key or the request rather than the user's session — and deleting the
205
+ // refresh token on that reading signs someone out with no way back.
206
+ // Nothing reaches here with it today; it stays out so nothing does.
207
+ if (e instanceof SessionExpiredError) {
201
208
  await this.clearSessionInternal();
202
209
  return RestoreResult.Expired;
203
210
  }
@@ -788,8 +795,6 @@ export class KoolbaseAuth {
788
795
  case 'invalid_refresh_token':
789
796
  // Refresh token rejected — the session is unrecoverable; re-login.
790
797
  throw new SessionExpiredError();
791
- case 'token_revoked':
792
- throw new TokenRevokedError();
793
798
  case 'invalid_unlock_token':
794
799
  throw new UnlockTokenInvalidError();
795
800
  case 'rate_limit':
@@ -828,6 +833,12 @@ export class KoolbaseAuth {
828
833
  throw new OAuthOnlyAccountError(msg || undefined);
829
834
  case 'unsupported_oauth_provider':
830
835
  throw new UnsupportedOAuthProviderError(msg || undefined);
836
+ case 'identity_not_found':
837
+ throw new IdentityNotFoundError(msg || undefined);
838
+ case 'provider_identity_already_linked':
839
+ throw new ProviderIdentityAlreadyLinkedError(msg || undefined);
840
+ case 'insufficient_scope':
841
+ throw new InsufficientScopeError(msg || undefined);
831
842
  // Authority
832
843
  case 'session_required':
833
844
  throw new SessionRequiredError(msg || undefined);
@@ -860,11 +871,6 @@ export class KoolbaseAuth {
860
871
  if (msg.includes('invalid or expired unlock token')) {
861
872
  throw new UnlockTokenInvalidError();
862
873
  }
863
- if (msg.includes('session revoked') ||
864
- msg.includes('token revoked') ||
865
- msg.includes('session has been revoked')) {
866
- throw new TokenRevokedError();
867
- }
868
874
  throw new KoolbaseAuthError(msg || `Request failed: ${res.status}`, code || `http_${res.status}`);
869
875
  }
870
876
  /**
@@ -41,6 +41,156 @@ 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
+ /**
53
+ * The record changed between reading it and writing it.
54
+ *
55
+ * Optimistic concurrency: a write carrying a revision is refused when the
56
+ * server has moved on, rather than overwriting whatever happened in between.
57
+ * The refusal carries the server's current record and both revisions, so
58
+ * resolving needs no second fetch — and cannot race one.
59
+ *
60
+ * Distinct from KoolbaseConflict, which models a queued OFFLINE write and
61
+ * carries a baseline as well, because a change composed hours ago needs its
62
+ * original context to be resolvable. Here the caller still has their data in
63
+ * hand.
64
+ *
65
+ * Until 11.3.0 this arrived as a generic data error and the details had to be
66
+ * dug out of an untyped bag — the information the server went to the trouble
67
+ * of attaching, unreachable in practice.
68
+ */
69
+ /** A vector field with that name already exists on the collection. */
70
+ /**
71
+ * A seed or import operation was refused. The code says which stage:
72
+ * invalid_seed_file (the file itself, with a "problems" list in details),
73
+ * seed_key_not_unique (the key does not identify rows uniquely),
74
+ * seed_needs_decision (conflicts need a choice before proceeding), or
75
+ * seed_conflicts_require_force (overwriting would discard the target's
76
+ * version of rows that changed on both sides — details carry the rows).
77
+ *
78
+ * One class with the code distinguishing them, rather than four: these are
79
+ * dashboard and CLI operations, and a caller handling one handles them the
80
+ * same way — show the reason and let a human decide.
81
+ */
82
+ export declare class KoolbaseSeedError extends KoolbaseDataError {
83
+ constructor(message: string, code: string);
84
+ }
85
+ /** A project slug that another project already holds. */
86
+ export declare class KoolbaseSlugTakenError extends KoolbaseDataError {
87
+ constructor(message?: string);
88
+ }
89
+ /** An invitation that has been revoked or has expired. */
90
+ export declare class KoolbaseInvitationInvalidError extends KoolbaseDataError {
91
+ constructor(message?: string);
92
+ }
93
+ /** The project id in the request is not valid. */
94
+ export declare class KoolbaseProjectInvalidError extends KoolbaseDataError {
95
+ constructor(message?: string);
96
+ }
97
+ /** The request body could not be decoded. */
98
+ export declare class KoolbaseInvalidBodyError extends KoolbaseDataError {
99
+ constructor(message?: string);
100
+ }
101
+ /**
102
+ * The request asked for no change — an update with nothing to update.
103
+ */
104
+ export declare class KoolbaseNoChangesError extends KoolbaseDataError {
105
+ constructor(message?: string);
106
+ }
107
+ /**
108
+ * Something already exists, or something is in the wrong state, where the
109
+ * server did not say more than that.
110
+ *
111
+ * Carries whichever generic code arrived — conflict, duplicate,
112
+ * state_conflict — rather than four classes for codes that differ only in
113
+ * spelling. A caller who needs to branch finely is being underserved by the
114
+ * server, not by this.
115
+ */
116
+ export declare class KoolbaseStateConflictError extends KoolbaseDataError {
117
+ constructor(message: string, code: string);
118
+ }
119
+ export declare class KoolbaseVectorFieldExistsError extends KoolbaseDataError {
120
+ constructor(message?: string);
121
+ }
122
+ /**
123
+ * A backfill was asked for on a field that embeds nothing automatically.
124
+ * Set provider, model and source_field on the field first.
125
+ */
126
+ export declare class KoolbaseFieldNotAutoEmbedError extends KoolbaseDataError {
127
+ constructor(message?: string);
128
+ }
129
+ /**
130
+ * Embedding config is partial. Provider, model and source_field are set
131
+ * together or cleared together — half a configuration is refused rather than
132
+ * half-applied, which would embed against a model nobody chose.
133
+ */
134
+ export declare class KoolbaseInvalidEmbeddingConfigError extends KoolbaseDataError {
135
+ constructor(message?: string);
136
+ }
137
+ /**
138
+ * The project has no embedding provider configured. Embedding runs on the
139
+ * project's own Gemini or OpenAI key.
140
+ */
141
+ export declare class KoolbaseProviderNotConfiguredError extends KoolbaseDataError {
142
+ constructor(message?: string);
143
+ }
144
+ /** The configured provider's credentials were rejected by the provider. */
145
+ export declare class KoolbaseProviderInvalidError extends KoolbaseDataError {
146
+ constructor(message?: string);
147
+ }
148
+ export declare class KoolbaseRevisionMismatchError extends KoolbaseDataError {
149
+ readonly expectedRevision?: number | undefined;
150
+ readonly currentRevision?: number | undefined;
151
+ /** The record as the server holds it now. */
152
+ readonly current?: Record<string, unknown> | undefined;
153
+ constructor(message?: string, expectedRevision?: number | undefined, currentRevision?: number | undefined,
154
+ /** The record as the server holds it now. */
155
+ current?: Record<string, unknown> | undefined);
156
+ }
157
+ /**
158
+ * The same idempotency key sent with different data.
159
+ *
160
+ * Refused rather than replayed: the two requests do not agree, so neither
161
+ * answer is safe. Usually a key reused by accident across two operations.
162
+ */
163
+ export declare class KoolbaseIdempotencyKeyReusedError extends KoolbaseDataError {
164
+ /**
165
+ * Carries its code: the database package calls this idempotency_key_reused
166
+ * and fiscal calls it idempotency_conflict, and an error reporting a code
167
+ * the server did not send is a small lie that apps branching on e.code act
168
+ * on.
169
+ */
170
+ constructor(message?: string, code?: string);
171
+ }
172
+ /** A batch write failed for a reason the server did not classify further. */
173
+ export declare class KoolbaseBatchFailedError extends KoolbaseDataError {
174
+ constructor(message?: string);
175
+ }
176
+ /**
177
+ * Creating a unique constraint over data that already breaks it. details
178
+ * carry the offending values, so they can be shown rather than hunted for.
179
+ */
180
+ export declare class KoolbaseDuplicateValuesError extends KoolbaseDataError {
181
+ constructor(message?: string);
182
+ }
183
+ export declare class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
184
+ constructor(message?: string);
185
+ }
186
+ /** A unique constraint already covers those fields. */
187
+ export declare class KoolbaseConstraintExistsError extends KoolbaseDataError {
188
+ constructor(message?: string);
189
+ }
190
+ /** No such unique constraint. */
191
+ export declare class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
192
+ constructor(message?: string);
193
+ }
44
194
  export declare class KoolbaseConflictError extends KoolbaseDataError {
45
195
  field?: string;
46
196
  constructor(message?: string, field?: string);
@@ -51,20 +201,43 @@ export declare class KoolbaseConflictError extends KoolbaseDataError {
51
201
  * `collection_not_found`.
52
202
  */
53
203
  export declare class KoolbaseNotFoundError extends KoolbaseDataError {
54
- constructor(message?: string);
204
+ /**
205
+ * The code is carried rather than fixed, because the server distinguishes
206
+ * what was missing — a record, a collection, a vector field — and an app
207
+ * reading e.code should get that answer rather than the category. Catching
208
+ * the class still works for anyone who only cares that something was
209
+ * absent.
210
+ */
211
+ constructor(message?: string, code?: string);
55
212
  }
56
213
  /**
57
214
  * Thrown when the request is rejected as invalid — the server responds with
58
215
  * 400 and code `validation_error`.
59
216
  */
60
217
  export declare class KoolbaseValidationError extends KoolbaseDataError {
61
- constructor(message?: string);
218
+ /**
219
+ * Carries its code for the same reason KoolbaseNotFoundError does: a
220
+ * dimension the platform does not support and a vector pointed at the wrong
221
+ * collection are both validation failures, and an app should still be able
222
+ * to tell which without reading the message.
223
+ */
224
+ constructor(message?: string, code?: string);
62
225
  }
63
226
  /**
64
227
  * Thrown when the caller is authenticated but not allowed to perform the
65
228
  * operation — the server responds with 403 and code `permission_denied`
66
229
  * (typically a collection access rule rejecting the read/write).
67
230
  */
231
+ /**
232
+ * Authenticated, and not permitted to do this — distinct from a rule denying
233
+ * access to a record. Its own class rather than folding into
234
+ * KoolbasePermissionError, which hardcodes permission_denied: an error
235
+ * reporting a code the server did not send is a small lie, and apps that
236
+ * branch on e.code rather than instanceof would act on it.
237
+ */
238
+ export declare class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
239
+ constructor(message?: string);
240
+ }
68
241
  export declare class KoolbasePermissionError extends KoolbaseDataError {
69
242
  constructor(message?: string);
70
243
  }