@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.
@@ -1,4 +1,4 @@
1
- import { KoolbaseError, KoolbaseUnauthenticatedError } from './errors.js';
1
+ import { KoolbaseError, KoolbasePlanLimitError, KoolbaseUnauthenticatedError } from './errors.js';
2
2
  /**
3
3
  * Base class for errors surfaced by the Koolbase data layer (database reads
4
4
  * and writes). Every data error carries a `message` and, when the server
@@ -39,6 +39,231 @@ export class KoolbaseDataError extends KoolbaseError {
39
39
  * }
40
40
  * }
41
41
  */
42
+ /**
43
+ * An upsert whose filter matched more than one record.
44
+ *
45
+ * Refused rather than resolved: picking one of several would be a silent
46
+ * guess about which row the caller meant, and the wrong guess overwrites data
47
+ * nobody asked to change. Narrow the filter, or add a unique constraint over
48
+ * the fields you are matching on so the ambiguity cannot arise.
49
+ */
50
+ /**
51
+ * The record changed between reading it and writing it.
52
+ *
53
+ * Optimistic concurrency: a write carrying a revision is refused when the
54
+ * server has moved on, rather than overwriting whatever happened in between.
55
+ * The refusal carries the server's current record and both revisions, so
56
+ * resolving needs no second fetch — and cannot race one.
57
+ *
58
+ * Distinct from KoolbaseConflict, which models a queued OFFLINE write and
59
+ * carries a baseline as well, because a change composed hours ago needs its
60
+ * original context to be resolvable. Here the caller still has their data in
61
+ * hand.
62
+ *
63
+ * Until 11.3.0 this arrived as a generic data error and the details had to be
64
+ * dug out of an untyped bag — the information the server went to the trouble
65
+ * of attaching, unreachable in practice.
66
+ */
67
+ /** A vector field with that name already exists on the collection. */
68
+ /**
69
+ * A seed or import operation was refused. The code says which stage:
70
+ * invalid_seed_file (the file itself, with a "problems" list in details),
71
+ * seed_key_not_unique (the key does not identify rows uniquely),
72
+ * seed_needs_decision (conflicts need a choice before proceeding), or
73
+ * seed_conflicts_require_force (overwriting would discard the target's
74
+ * version of rows that changed on both sides — details carry the rows).
75
+ *
76
+ * One class with the code distinguishing them, rather than four: these are
77
+ * dashboard and CLI operations, and a caller handling one handles them the
78
+ * same way — show the reason and let a human decide.
79
+ */
80
+ export class KoolbaseSeedError extends KoolbaseDataError {
81
+ constructor(message, code) {
82
+ super(message, code);
83
+ this.name = 'KoolbaseSeedError';
84
+ Object.setPrototypeOf(this, KoolbaseSeedError.prototype);
85
+ }
86
+ }
87
+ /** A project slug that another project already holds. */
88
+ export class KoolbaseSlugTakenError extends KoolbaseDataError {
89
+ constructor(message) {
90
+ super(message ?? 'A project with this slug already exists', 'slug_taken');
91
+ this.name = 'KoolbaseSlugTakenError';
92
+ Object.setPrototypeOf(this, KoolbaseSlugTakenError.prototype);
93
+ }
94
+ }
95
+ /** An invitation that has been revoked or has expired. */
96
+ export class KoolbaseInvitationInvalidError extends KoolbaseDataError {
97
+ constructor(message) {
98
+ super(message ?? 'This invitation has been revoked or expired', 'invitation_invalid');
99
+ this.name = 'KoolbaseInvitationInvalidError';
100
+ Object.setPrototypeOf(this, KoolbaseInvitationInvalidError.prototype);
101
+ }
102
+ }
103
+ /** The project id in the request is not valid. */
104
+ export class KoolbaseProjectInvalidError extends KoolbaseDataError {
105
+ constructor(message) {
106
+ super(message ?? 'Invalid project id', 'project_invalid');
107
+ this.name = 'KoolbaseProjectInvalidError';
108
+ Object.setPrototypeOf(this, KoolbaseProjectInvalidError.prototype);
109
+ }
110
+ }
111
+ /** The request body could not be decoded. */
112
+ export class KoolbaseInvalidBodyError extends KoolbaseDataError {
113
+ constructor(message) {
114
+ super(message ?? 'Could not decode the request body', 'invalid_body');
115
+ this.name = 'KoolbaseInvalidBodyError';
116
+ Object.setPrototypeOf(this, KoolbaseInvalidBodyError.prototype);
117
+ }
118
+ }
119
+ /**
120
+ * The request asked for no change — an update with nothing to update.
121
+ */
122
+ export class KoolbaseNoChangesError extends KoolbaseDataError {
123
+ constructor(message) {
124
+ super(message ?? 'The request contains no changes', 'no_changes');
125
+ this.name = 'KoolbaseNoChangesError';
126
+ Object.setPrototypeOf(this, KoolbaseNoChangesError.prototype);
127
+ }
128
+ }
129
+ /**
130
+ * Something already exists, or something is in the wrong state, where the
131
+ * server did not say more than that.
132
+ *
133
+ * Carries whichever generic code arrived — conflict, duplicate,
134
+ * state_conflict — rather than four classes for codes that differ only in
135
+ * spelling. A caller who needs to branch finely is being underserved by the
136
+ * server, not by this.
137
+ */
138
+ export class KoolbaseStateConflictError extends KoolbaseDataError {
139
+ constructor(message, code) {
140
+ super(message, code);
141
+ this.name = 'KoolbaseStateConflictError';
142
+ Object.setPrototypeOf(this, KoolbaseStateConflictError.prototype);
143
+ }
144
+ }
145
+ export class KoolbaseVectorFieldExistsError extends KoolbaseDataError {
146
+ constructor(message) {
147
+ super(message ?? 'A vector field with that name already exists on this collection', 'vector_field_exists');
148
+ this.name = 'KoolbaseVectorFieldExistsError';
149
+ Object.setPrototypeOf(this, KoolbaseVectorFieldExistsError.prototype);
150
+ }
151
+ }
152
+ /**
153
+ * A backfill was asked for on a field that embeds nothing automatically.
154
+ * Set provider, model and source_field on the field first.
155
+ */
156
+ export class KoolbaseFieldNotAutoEmbedError extends KoolbaseDataError {
157
+ constructor(message) {
158
+ super(message ?? 'This vector field has no auto-embedding config; set provider, model and source_field first', 'field_not_auto_embed');
159
+ this.name = 'KoolbaseFieldNotAutoEmbedError';
160
+ Object.setPrototypeOf(this, KoolbaseFieldNotAutoEmbedError.prototype);
161
+ }
162
+ }
163
+ /**
164
+ * Embedding config is partial. Provider, model and source_field are set
165
+ * together or cleared together — half a configuration is refused rather than
166
+ * half-applied, which would embed against a model nobody chose.
167
+ */
168
+ export class KoolbaseInvalidEmbeddingConfigError extends KoolbaseDataError {
169
+ constructor(message) {
170
+ super(message ?? 'Embedding config requires provider, model and source_field together, or all cleared', 'invalid_embedding_config');
171
+ this.name = 'KoolbaseInvalidEmbeddingConfigError';
172
+ Object.setPrototypeOf(this, KoolbaseInvalidEmbeddingConfigError.prototype);
173
+ }
174
+ }
175
+ /**
176
+ * The project has no embedding provider configured. Embedding runs on the
177
+ * project's own Gemini or OpenAI key.
178
+ */
179
+ export class KoolbaseProviderNotConfiguredError extends KoolbaseDataError {
180
+ constructor(message) {
181
+ super(message ?? 'No embedding provider is configured for this project', 'provider_not_configured');
182
+ this.name = 'KoolbaseProviderNotConfiguredError';
183
+ Object.setPrototypeOf(this, KoolbaseProviderNotConfiguredError.prototype);
184
+ }
185
+ }
186
+ /** The configured provider's credentials were rejected by the provider. */
187
+ export class KoolbaseProviderInvalidError extends KoolbaseDataError {
188
+ constructor(message) {
189
+ super(message ?? 'The embedding provider credentials are not valid', 'provider_invalid');
190
+ this.name = 'KoolbaseProviderInvalidError';
191
+ Object.setPrototypeOf(this, KoolbaseProviderInvalidError.prototype);
192
+ }
193
+ }
194
+ export class KoolbaseRevisionMismatchError extends KoolbaseDataError {
195
+ constructor(message, expectedRevision, currentRevision,
196
+ /** The record as the server holds it now. */
197
+ current) {
198
+ super(message ?? 'The record has changed since you read it', 'revision_mismatch');
199
+ this.expectedRevision = expectedRevision;
200
+ this.currentRevision = currentRevision;
201
+ this.current = current;
202
+ this.name = 'KoolbaseRevisionMismatchError';
203
+ Object.setPrototypeOf(this, KoolbaseRevisionMismatchError.prototype);
204
+ }
205
+ }
206
+ /**
207
+ * The same idempotency key sent with different data.
208
+ *
209
+ * Refused rather than replayed: the two requests do not agree, so neither
210
+ * answer is safe. Usually a key reused by accident across two operations.
211
+ */
212
+ export class KoolbaseIdempotencyKeyReusedError extends KoolbaseDataError {
213
+ /**
214
+ * Carries its code: the database package calls this idempotency_key_reused
215
+ * and fiscal calls it idempotency_conflict, and an error reporting a code
216
+ * the server did not send is a small lie that apps branching on e.code act
217
+ * on.
218
+ */
219
+ constructor(message, code = 'idempotency_key_reused') {
220
+ super(message ?? 'Idempotency key reused with different data', code);
221
+ this.name = 'KoolbaseIdempotencyKeyReusedError';
222
+ Object.setPrototypeOf(this, KoolbaseIdempotencyKeyReusedError.prototype);
223
+ }
224
+ }
225
+ /** A batch write failed for a reason the server did not classify further. */
226
+ export class KoolbaseBatchFailedError extends KoolbaseDataError {
227
+ constructor(message) {
228
+ super(message ?? 'The batch write failed', 'batch_failed');
229
+ this.name = 'KoolbaseBatchFailedError';
230
+ Object.setPrototypeOf(this, KoolbaseBatchFailedError.prototype);
231
+ }
232
+ }
233
+ /**
234
+ * Creating a unique constraint over data that already breaks it. details
235
+ * carry the offending values, so they can be shown rather than hunted for.
236
+ */
237
+ export class KoolbaseDuplicateValuesError extends KoolbaseDataError {
238
+ constructor(message) {
239
+ super(message ?? 'The collection has duplicate values for these fields', 'duplicate_values');
240
+ this.name = 'KoolbaseDuplicateValuesError';
241
+ Object.setPrototypeOf(this, KoolbaseDuplicateValuesError.prototype);
242
+ }
243
+ }
244
+ export class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
245
+ constructor(message) {
246
+ super(message ?? 'Upsert match resolved to more than one record', 'ambiguous_match');
247
+ this.name = 'KoolbaseAmbiguousMatchError';
248
+ Object.setPrototypeOf(this, KoolbaseAmbiguousMatchError.prototype);
249
+ }
250
+ }
251
+ /** A unique constraint already covers those fields. */
252
+ export class KoolbaseConstraintExistsError extends KoolbaseDataError {
253
+ constructor(message) {
254
+ super(message ?? 'A unique constraint already exists for these fields', 'constraint_exists');
255
+ this.name = 'KoolbaseConstraintExistsError';
256
+ Object.setPrototypeOf(this, KoolbaseConstraintExistsError.prototype);
257
+ }
258
+ }
259
+ /** No such unique constraint. */
260
+ export class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
261
+ constructor(message) {
262
+ super(message ?? 'Unique constraint not found', 'constraint_not_found');
263
+ this.name = 'KoolbaseConstraintNotFoundError';
264
+ Object.setPrototypeOf(this, KoolbaseConstraintNotFoundError.prototype);
265
+ }
266
+ }
42
267
  export class KoolbaseConflictError extends KoolbaseDataError {
43
268
  constructor(message, field) {
44
269
  super(message ?? 'Value violates a unique constraint', 'unique_violation');
@@ -53,8 +278,15 @@ export class KoolbaseConflictError extends KoolbaseDataError {
53
278
  * `collection_not_found`.
54
279
  */
55
280
  export class KoolbaseNotFoundError extends KoolbaseDataError {
56
- constructor(message) {
57
- super(message ?? 'The requested resource was not found', 'not_found');
281
+ /**
282
+ * The code is carried rather than fixed, because the server distinguishes
283
+ * what was missing — a record, a collection, a vector field — and an app
284
+ * reading e.code should get that answer rather than the category. Catching
285
+ * the class still works for anyone who only cares that something was
286
+ * absent.
287
+ */
288
+ constructor(message, code = 'not_found') {
289
+ super(message ?? 'The requested resource was not found', code);
58
290
  this.name = 'KoolbaseNotFoundError';
59
291
  Object.setPrototypeOf(this, KoolbaseNotFoundError.prototype);
60
292
  }
@@ -64,8 +296,14 @@ export class KoolbaseNotFoundError extends KoolbaseDataError {
64
296
  * 400 and code `validation_error`.
65
297
  */
66
298
  export class KoolbaseValidationError extends KoolbaseDataError {
67
- constructor(message) {
68
- super(message ?? 'The request was invalid', 'validation_error');
299
+ /**
300
+ * Carries its code for the same reason KoolbaseNotFoundError does: a
301
+ * dimension the platform does not support and a vector pointed at the wrong
302
+ * collection are both validation failures, and an app should still be able
303
+ * to tell which without reading the message.
304
+ */
305
+ constructor(message, code = 'validation_error') {
306
+ super(message ?? 'The request was invalid', code);
69
307
  this.name = 'KoolbaseValidationError';
70
308
  Object.setPrototypeOf(this, KoolbaseValidationError.prototype);
71
309
  }
@@ -75,6 +313,20 @@ export class KoolbaseValidationError extends KoolbaseDataError {
75
313
  * operation — the server responds with 403 and code `permission_denied`
76
314
  * (typically a collection access rule rejecting the read/write).
77
315
  */
316
+ /**
317
+ * Authenticated, and not permitted to do this — distinct from a rule denying
318
+ * access to a record. Its own class rather than folding into
319
+ * KoolbasePermissionError, which hardcodes permission_denied: an error
320
+ * reporting a code the server did not send is a small lie, and apps that
321
+ * branch on e.code rather than instanceof would act on it.
322
+ */
323
+ export class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
324
+ constructor(message) {
325
+ super(message ?? 'You do not have the authority to perform this action', 'insufficient_authority');
326
+ this.name = 'KoolbaseInsufficientAuthorityError';
327
+ Object.setPrototypeOf(this, KoolbaseInsufficientAuthorityError.prototype);
328
+ }
329
+ }
78
330
  export class KoolbasePermissionError extends KoolbaseDataError {
79
331
  constructor(message) {
80
332
  super(message ?? 'You do not have permission to perform this action', 'permission_denied');
@@ -144,14 +396,70 @@ export function koolbaseDataError(status, body, fallbackMessage = 'Request faile
144
396
  switch (code) {
145
397
  case 'unique_violation':
146
398
  return attach(new KoolbaseConflictError(message, field));
399
+ case 'plan_limit_reached': {
400
+ const d = (body?.details ?? {});
401
+ return new KoolbasePlanLimitError(message, d.resource, d.limit, d.plan);
402
+ }
403
+ case 'invalid_seed_file':
404
+ case 'seed_key_not_unique':
405
+ case 'seed_needs_decision':
406
+ case 'seed_conflicts_require_force':
407
+ return attach(new KoolbaseSeedError(message, code));
408
+ case 'slug_taken':
409
+ return attach(new KoolbaseSlugTakenError(message));
410
+ case 'invitation_invalid':
411
+ return attach(new KoolbaseInvitationInvalidError(message));
412
+ case 'project_invalid':
413
+ return attach(new KoolbaseProjectInvalidError(message));
414
+ case 'invalid_body':
415
+ return attach(new KoolbaseInvalidBodyError(message));
416
+ case 'no_changes':
417
+ return attach(new KoolbaseNoChangesError(message));
418
+ case 'conflict':
419
+ case 'duplicate':
420
+ case 'state_conflict':
421
+ return attach(new KoolbaseStateConflictError(message, code));
422
+ case 'vector_field_exists':
423
+ return attach(new KoolbaseVectorFieldExistsError(message));
424
+ case 'field_not_auto_embed':
425
+ return attach(new KoolbaseFieldNotAutoEmbedError(message));
426
+ case 'invalid_embedding_config':
427
+ return attach(new KoolbaseInvalidEmbeddingConfigError(message));
428
+ case 'provider_not_configured':
429
+ return attach(new KoolbaseProviderNotConfiguredError(message));
430
+ case 'provider_invalid':
431
+ return attach(new KoolbaseProviderInvalidError(message));
432
+ case 'revision_mismatch': {
433
+ // The typed fields come off details, which the server attaches for
434
+ // exactly this. attach() still puts the whole bag on the error, so
435
+ // nothing is lost for a caller reading it directly.
436
+ const d = (body?.details ?? {});
437
+ return attach(new KoolbaseRevisionMismatchError(message, d.expected_revision, d.current_revision, d.record));
438
+ }
439
+ // Two codes, one situation — the database and fiscal packages name it
440
+ // differently and a caller should not have to know which spoke.
441
+ case 'idempotency_key_reused':
442
+ case 'idempotency_conflict':
443
+ return attach(new KoolbaseIdempotencyKeyReusedError(message, code));
444
+ case 'batch_failed':
445
+ return attach(new KoolbaseBatchFailedError(message));
446
+ case 'duplicate_values':
447
+ return attach(new KoolbaseDuplicateValuesError(message));
448
+ case 'ambiguous_match':
449
+ return attach(new KoolbaseAmbiguousMatchError(message));
450
+ case 'constraint_exists':
451
+ return attach(new KoolbaseConstraintExistsError(message));
452
+ case 'constraint_not_found':
453
+ return attach(new KoolbaseConstraintNotFoundError(message));
454
+ case 'insufficient_authority':
455
+ return attach(new KoolbaseInsufficientAuthorityError(message));
147
456
  case 'not_found':
148
457
  case 'record_not_found':
149
458
  case 'collection_not_found':
150
459
  case 'vector_not_found':
151
460
  case 'vector_field_not_found':
152
- return attach(new KoolbaseNotFoundError(message));
461
+ return attach(new KoolbaseNotFoundError(message, code));
153
462
  case 'unauthenticated':
154
- case 'session_expired':
155
463
  case 'invalid_token':
156
464
  return attach(new KoolbaseUnauthenticatedError(message));
157
465
  case 'permission_denied':
@@ -161,7 +469,7 @@ export function koolbaseDataError(status, body, fallbackMessage = 'Request faile
161
469
  case 'validation_error':
162
470
  case 'vector_collection_mismatch':
163
471
  case 'unsupported_dimension':
164
- return attach(new KoolbaseValidationError(message));
472
+ return attach(new KoolbaseValidationError(message, code));
165
473
  case 'vector_dimension_mismatch':
166
474
  return attach(new KoolbaseVectorDimensionMismatchError(message));
167
475
  }
@@ -59,6 +59,20 @@ export declare class KoolbaseUnauthenticatedError extends KoolbaseError {
59
59
  * updates are conflict-safe and some quietly are not, which is a worse guarantee
60
60
  * than a clear refusal.
61
61
  */
62
+ /**
63
+ * The project's plan does not allow this — a 402 carrying which resource, the
64
+ * limit, and the plan.
65
+ *
66
+ * Shared rather than per-domain: creating a collection, uploading an object
67
+ * and deploying a function can all hit it, and an app showing an upgrade
68
+ * prompt wants one type to catch.
69
+ */
70
+ export declare class KoolbasePlanLimitError extends KoolbaseError {
71
+ readonly resource?: string | undefined;
72
+ readonly limit?: number | undefined;
73
+ readonly plan?: string | undefined;
74
+ constructor(message?: string, resource?: string | undefined, limit?: number | undefined, plan?: string | undefined);
75
+ }
62
76
  export declare class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
63
77
  constructor(message: string);
64
78
  }
@@ -70,6 +70,24 @@ export class KoolbaseUnauthenticatedError extends KoolbaseError {
70
70
  * updates are conflict-safe and some quietly are not, which is a worse guarantee
71
71
  * than a clear refusal.
72
72
  */
73
+ /**
74
+ * The project's plan does not allow this — a 402 carrying which resource, the
75
+ * limit, and the plan.
76
+ *
77
+ * Shared rather than per-domain: creating a collection, uploading an object
78
+ * and deploying a function can all hit it, and an app showing an upgrade
79
+ * prompt wants one type to catch.
80
+ */
81
+ export class KoolbasePlanLimitError extends KoolbaseError {
82
+ constructor(message, resource, limit, plan) {
83
+ super(message ?? 'This exceeds your plan limit', 'plan_limit_reached');
84
+ this.resource = resource;
85
+ this.limit = limit;
86
+ this.plan = plan;
87
+ this.name = 'KoolbasePlanLimitError';
88
+ Object.setPrototypeOf(this, KoolbasePlanLimitError.prototype);
89
+ }
90
+ }
73
91
  export class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
74
92
  constructor(message) {
75
93
  super(message, 'offline_baseline_unavailable');
@@ -47,5 +47,24 @@ export declare class FunctionQuotaExceededError extends FunctionInvokeError {
47
47
  export declare class FunctionExecutionError extends FunctionInvokeError {
48
48
  constructor(message: string, statusCode?: number);
49
49
  }
50
+ /**
51
+ * The function ran past its timeout and was killed.
52
+ *
53
+ * Its own type because the remedy is different from a function that threw:
54
+ * a timeout means retry, or raise the function's timeout at deploy, or move
55
+ * the slow part elsewhere. Without this it arrived as FunctionExecutionError
56
+ * — indistinguishable from an exception, which is the one thing it is not.
57
+ * The server already tells them apart; it logs 504 as "timeout".
58
+ */
59
+ export declare class FunctionTimeoutError extends FunctionInvokeError {
60
+ constructor(message: string);
61
+ }
62
+ /**
63
+ * Too many invocations, too fast. Distinct from a quota being spent: this one
64
+ * clears by waiting.
65
+ */
66
+ export declare class FunctionRateLimitError extends FunctionInvokeError {
67
+ constructor(message: string);
68
+ }
50
69
  /** Builds the right error for a failed invocation. */
51
70
  export declare function functionInvokeError(status: number, message: string): KoolbaseError;
@@ -71,6 +71,33 @@ export class FunctionExecutionError extends FunctionInvokeError {
71
71
  Object.setPrototypeOf(this, new.target.prototype);
72
72
  }
73
73
  }
74
+ /**
75
+ * The function ran past its timeout and was killed.
76
+ *
77
+ * Its own type because the remedy is different from a function that threw:
78
+ * a timeout means retry, or raise the function's timeout at deploy, or move
79
+ * the slow part elsewhere. Without this it arrived as FunctionExecutionError
80
+ * — indistinguishable from an exception, which is the one thing it is not.
81
+ * The server already tells them apart; it logs 504 as "timeout".
82
+ */
83
+ export class FunctionTimeoutError extends FunctionInvokeError {
84
+ constructor(message) {
85
+ super(message, 504, 'timeout');
86
+ this.name = 'FunctionTimeoutError';
87
+ Object.setPrototypeOf(this, new.target.prototype);
88
+ }
89
+ }
90
+ /**
91
+ * Too many invocations, too fast. Distinct from a quota being spent: this one
92
+ * clears by waiting.
93
+ */
94
+ export class FunctionRateLimitError extends FunctionInvokeError {
95
+ constructor(message) {
96
+ super(message, 429, 'rate_limit');
97
+ this.name = 'FunctionRateLimitError';
98
+ Object.setPrototypeOf(this, new.target.prototype);
99
+ }
100
+ }
74
101
  /** Builds the right error for a failed invocation. */
75
102
  export function functionInvokeError(status, message) {
76
103
  switch (status) {
@@ -86,6 +113,11 @@ export function functionInvokeError(status, message) {
86
113
  return new FunctionValidationError(message);
87
114
  case 402:
88
115
  return new FunctionQuotaExceededError(message);
116
+ case 429:
117
+ return new FunctionRateLimitError(message);
118
+ case 504:
119
+ // Before the generic 5xx branch: a timeout is not an exception.
120
+ return new FunctionTimeoutError(message);
89
121
  }
90
122
  if (status >= 500)
91
123
  return new FunctionExecutionError(message, status);
@@ -76,6 +76,34 @@ 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
+ /**
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
+ }
97
+ export declare class KoolbaseUploadExpiredError extends KoolbaseStorageError {
98
+ constructor(message?: string);
99
+ }
100
+ /**
101
+ * A bucket cap set below what the bucket already holds. A dashboard
102
+ * operation rather than an app one, mapped so it does not arrive untyped.
103
+ */
104
+ export declare class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
105
+ constructor(message?: string);
106
+ }
79
107
  export declare class KoolbaseStorageQuotaError extends KoolbaseStorageError {
80
108
  constructor(message?: string);
81
109
  }
@@ -1,4 +1,4 @@
1
- import { KoolbaseError, KoolbaseUnauthenticatedError } from './errors.js';
1
+ import { KoolbaseError, KoolbasePlanLimitError, KoolbaseUnauthenticatedError } from './errors.js';
2
2
  /**
3
3
  * Base error type for all Koolbase storage errors. Catchable via
4
4
  * `instanceof KoolbaseStorageError` to handle any storage-related failure
@@ -96,6 +96,46 @@ export class KoolbaseStoragePermissionError extends KoolbaseStorageError {
96
96
  * 409 but means "path collides"); branch on the error type via
97
97
  * `instanceof`, not on status.
98
98
  */
99
+ /**
100
+ * The presigned upload was confirmed after its window closed.
101
+ *
102
+ * An upload URL has a lifetime. A user who picks a file, gets distracted and
103
+ * comes back twenty minutes later hits this — so it is a retry, not a
104
+ * failure: presign again and send the same bytes. Worth catching rather than
105
+ * showing "upload failed" to someone whose file was fine.
106
+ */
107
+ /**
108
+ * Minting a presigned upload URL failed. The message carries the underlying
109
+ * reason — a misconfigured bucket, or the object store refusing.
110
+ *
111
+ * Not the user's doing, and not a retry they can fix: distinct from
112
+ * KoolbaseUploadExpiredError, which is a retry that will work.
113
+ */
114
+ export class KoolbaseUploadURLFailedError extends KoolbaseStorageError {
115
+ constructor(message) {
116
+ super(message ?? 'Could not create an upload URL', 'upload_url_failed');
117
+ this.name = 'KoolbaseUploadURLFailedError';
118
+ Object.setPrototypeOf(this, KoolbaseUploadURLFailedError.prototype);
119
+ }
120
+ }
121
+ export class KoolbaseUploadExpiredError extends KoolbaseStorageError {
122
+ constructor(message) {
123
+ super(message ?? 'This upload is past the confirmation window — please re-upload', 'upload_expired');
124
+ this.name = 'KoolbaseUploadExpiredError';
125
+ Object.setPrototypeOf(this, KoolbaseUploadExpiredError.prototype);
126
+ }
127
+ }
128
+ /**
129
+ * A bucket cap set below what the bucket already holds. A dashboard
130
+ * operation rather than an app one, mapped so it does not arrive untyped.
131
+ */
132
+ export class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
133
+ constructor(message) {
134
+ super(message ?? 'The cap is below the bucket\'s current usage', 'cap_below_usage');
135
+ this.name = 'KoolbaseCapBelowUsageError';
136
+ Object.setPrototypeOf(this, KoolbaseCapBelowUsageError.prototype);
137
+ }
138
+ }
99
139
  export class KoolbaseStorageQuotaError extends KoolbaseStorageError {
100
140
  constructor(message) {
101
141
  super(message ?? 'Bucket quota exceeded', 'quota_exceeded');
@@ -193,14 +233,24 @@ export function koolbaseStorageError(status, body, fallbackMessage = 'Storage re
193
233
  switch (code) {
194
234
  case 'path_conflict':
195
235
  return new KoolbaseStorageConflictError(message, body?.path);
236
+ case 'plan_limit_reached': {
237
+ const d = (body?.details ?? {});
238
+ return new KoolbasePlanLimitError(message, d.resource, d.limit, d.plan);
239
+ }
196
240
  case 'quota_exceeded':
197
241
  return new KoolbaseStorageQuotaError(message);
242
+ case 'upload_expired':
243
+ return new KoolbaseUploadExpiredError(message);
244
+ case 'cap_below_usage':
245
+ return new KoolbaseCapBelowUsageError(message);
198
246
  case 'file_too_large':
199
247
  return new KoolbaseStorageFileTooLargeError(message);
200
248
  case 'mime_not_allowed':
201
249
  return new KoolbaseStorageMimeTypeError(message);
202
250
  case 'metadata_invalid':
203
251
  return new KoolbaseStorageMetadataInvalidError(message, body?.detail);
252
+ case 'upload_url_failed':
253
+ return new KoolbaseUploadURLFailedError(message);
204
254
  }
205
255
  // ─── status fallback (pre-code servers or uncoded paths) ───
206
256
  switch (status) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "11.1.0",
3
+ "version": "11.3.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",