@koolbase/core 11.2.0 → 11.4.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KoolbaseOfflineBaselineUnavailableError = exports.KoolbaseUnauthenticatedError = exports.KoolbaseError = void 0;
3
+ exports.KoolbaseOfflineBaselineUnavailableError = exports.KoolbasePlanLimitError = exports.KoolbaseUnauthenticatedError = exports.KoolbaseError = void 0;
4
4
  /**
5
5
  * The root of every error the SDK raises.
6
6
  *
@@ -75,6 +75,25 @@ exports.KoolbaseUnauthenticatedError = KoolbaseUnauthenticatedError;
75
75
  * updates are conflict-safe and some quietly are not, which is a worse guarantee
76
76
  * than a clear refusal.
77
77
  */
78
+ /**
79
+ * The project's plan does not allow this — a 402 carrying which resource, the
80
+ * limit, and the plan.
81
+ *
82
+ * Shared rather than per-domain: creating a collection, uploading an object
83
+ * and deploying a function can all hit it, and an app showing an upgrade
84
+ * prompt wants one type to catch.
85
+ */
86
+ class KoolbasePlanLimitError extends KoolbaseError {
87
+ constructor(message, resource, limit, plan) {
88
+ super(message ?? 'This exceeds your plan limit', 'plan_limit_reached');
89
+ this.resource = resource;
90
+ this.limit = limit;
91
+ this.plan = plan;
92
+ this.name = 'KoolbasePlanLimitError';
93
+ Object.setPrototypeOf(this, KoolbasePlanLimitError.prototype);
94
+ }
95
+ }
96
+ exports.KoolbasePlanLimitError = KoolbasePlanLimitError;
78
97
  class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
79
98
  constructor(message) {
80
99
  super(message, 'offline_baseline_unavailable');
@@ -84,6 +84,16 @@ export declare class KoolbaseStoragePermissionError extends KoolbaseStorageError
84
84
  * failure: presign again and send the same bytes. Worth catching rather than
85
85
  * showing "upload failed" to someone whose file was fine.
86
86
  */
87
+ /**
88
+ * Minting a presigned upload URL failed. The message carries the underlying
89
+ * reason — a misconfigured bucket, or the object store refusing.
90
+ *
91
+ * Not the user's doing, and not a retry they can fix: distinct from
92
+ * KoolbaseUploadExpiredError, which is a retry that will work.
93
+ */
94
+ export declare class KoolbaseUploadURLFailedError extends KoolbaseStorageError {
95
+ constructor(message?: string);
96
+ }
87
97
  export declare class KoolbaseUploadExpiredError extends KoolbaseStorageError {
88
98
  constructor(message?: string);
89
99
  }
@@ -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.KoolbaseCapBelowUsageError = exports.KoolbaseUploadExpiredError = 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.KoolbaseUploadURLFailedError = 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");
@@ -114,6 +114,21 @@ exports.KoolbaseStoragePermissionError = KoolbaseStoragePermissionError;
114
114
  * failure: presign again and send the same bytes. Worth catching rather than
115
115
  * showing "upload failed" to someone whose file was fine.
116
116
  */
117
+ /**
118
+ * Minting a presigned upload URL failed. The message carries the underlying
119
+ * reason — a misconfigured bucket, or the object store refusing.
120
+ *
121
+ * Not the user's doing, and not a retry they can fix: distinct from
122
+ * KoolbaseUploadExpiredError, which is a retry that will work.
123
+ */
124
+ class KoolbaseUploadURLFailedError extends KoolbaseStorageError {
125
+ constructor(message) {
126
+ super(message ?? 'Could not create an upload URL', 'upload_url_failed');
127
+ this.name = 'KoolbaseUploadURLFailedError';
128
+ Object.setPrototypeOf(this, KoolbaseUploadURLFailedError.prototype);
129
+ }
130
+ }
131
+ exports.KoolbaseUploadURLFailedError = KoolbaseUploadURLFailedError;
117
132
  class KoolbaseUploadExpiredError extends KoolbaseStorageError {
118
133
  constructor(message) {
119
134
  super(message ?? 'This upload is past the confirmation window — please re-upload', 'upload_expired');
@@ -235,6 +250,10 @@ function koolbaseStorageError(status, body, fallbackMessage = 'Storage request f
235
250
  switch (code) {
236
251
  case 'path_conflict':
237
252
  return new KoolbaseStorageConflictError(message, body?.path);
253
+ case 'plan_limit_reached': {
254
+ const d = (body?.details ?? {});
255
+ return new errors_js_1.KoolbasePlanLimitError(message, d.resource, d.limit, d.plan);
256
+ }
238
257
  case 'quota_exceeded':
239
258
  return new KoolbaseStorageQuotaError(message);
240
259
  case 'upload_expired':
@@ -247,6 +266,8 @@ function koolbaseStorageError(status, body, fallbackMessage = 'Storage request f
247
266
  return new KoolbaseStorageMimeTypeError(message);
248
267
  case 'metadata_invalid':
249
268
  return new KoolbaseStorageMetadataInvalidError(message, body?.detail);
269
+ case 'upload_url_failed':
270
+ return new KoolbaseUploadURLFailedError(message);
250
271
  }
251
272
  // ─── status fallback (pre-code servers or uncoded paths) ───
252
273
  switch (status) {
@@ -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');
@@ -154,6 +154,21 @@ export declare class KoolbaseAuth {
154
154
  private _doRefresh;
155
155
  logout(): Promise<boolean>;
156
156
  forgotPassword(email: string): Promise<void>;
157
+ /**
158
+ * Ask for a new verification email, with no session.
159
+ *
160
+ * For the state a project with verified contact required creates:
161
+ * registered, unverified, refused at login, and holding a link that may
162
+ * never have arrived or has since expired. `resendVerificationEmail()`
163
+ * cannot help there — it needs a session the user cannot get.
164
+ *
165
+ * Returns nothing, and throws only on a malformed request, because the
166
+ * server answers identically whether the address has an account, has none,
167
+ * or is already verified. Anything else would let anyone discover who has
168
+ * signed up. So there is no "we sent it" to report: show the same "check
169
+ * your email" either way.
170
+ */
171
+ resendVerificationEmailToAddress(email: string): Promise<void>;
157
172
  resetPassword(token: string, password: string): Promise<void>;
158
173
  /**
159
174
  * Complete email verification with a token from a verification link.
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
  }
@@ -509,6 +516,27 @@ export class KoolbaseAuth {
509
516
  });
510
517
  await this.checkResponse(res);
511
518
  }
519
+ /**
520
+ * Ask for a new verification email, with no session.
521
+ *
522
+ * For the state a project with verified contact required creates:
523
+ * registered, unverified, refused at login, and holding a link that may
524
+ * never have arrived or has since expired. `resendVerificationEmail()`
525
+ * cannot help there — it needs a session the user cannot get.
526
+ *
527
+ * Returns nothing, and throws only on a malformed request, because the
528
+ * server answers identically whether the address has an account, has none,
529
+ * or is already verified. Anything else would let anyone discover who has
530
+ * signed up. So there is no "we sent it" to report: show the same "check
531
+ * your email" either way.
532
+ */
533
+ async resendVerificationEmailToAddress(email) {
534
+ const res = await this.authRequest('/v1/sdk/auth/resend-verification/by-email', {
535
+ method: 'POST',
536
+ body: { email },
537
+ });
538
+ await this.checkResponse(res);
539
+ }
512
540
  async resetPassword(token, password) {
513
541
  const res = await this.authRequest('/v1/sdk/auth/password-reset/confirm', {
514
542
  method: 'POST',
@@ -788,8 +816,6 @@ export class KoolbaseAuth {
788
816
  case 'invalid_refresh_token':
789
817
  // Refresh token rejected — the session is unrecoverable; re-login.
790
818
  throw new SessionExpiredError();
791
- case 'token_revoked':
792
- throw new TokenRevokedError();
793
819
  case 'invalid_unlock_token':
794
820
  throw new UnlockTokenInvalidError();
795
821
  case 'rate_limit':
@@ -828,6 +854,12 @@ export class KoolbaseAuth {
828
854
  throw new OAuthOnlyAccountError(msg || undefined);
829
855
  case 'unsupported_oauth_provider':
830
856
  throw new UnsupportedOAuthProviderError(msg || undefined);
857
+ case 'identity_not_found':
858
+ throw new IdentityNotFoundError(msg || undefined);
859
+ case 'provider_identity_already_linked':
860
+ throw new ProviderIdentityAlreadyLinkedError(msg || undefined);
861
+ case 'insufficient_scope':
862
+ throw new InsufficientScopeError(msg || undefined);
831
863
  // Authority
832
864
  case 'session_required':
833
865
  throw new SessionRequiredError(msg || undefined);
@@ -860,11 +892,6 @@ export class KoolbaseAuth {
860
892
  if (msg.includes('invalid or expired unlock token')) {
861
893
  throw new UnlockTokenInvalidError();
862
894
  }
863
- if (msg.includes('session revoked') ||
864
- msg.includes('token revoked') ||
865
- msg.includes('session has been revoked')) {
866
- throw new TokenRevokedError();
867
- }
868
895
  throw new KoolbaseAuthError(msg || `Request failed: ${res.status}`, code || `http_${res.status}`);
869
896
  }
870
897
  /**
@@ -49,6 +49,137 @@ export declare class KoolbaseDataError extends KoolbaseError {
49
49
  * nobody asked to change. Narrow the filter, or add a unique constraint over
50
50
  * the fields you are matching on so the ambiguity cannot arise.
51
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
+ }
52
183
  export declare class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
53
184
  constructor(message?: string);
54
185
  }