@tinycloud/cli 1.0.1-beta.1 → 1.0.1-beta.3

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.
@@ -6888,6 +6888,20 @@ function storageLimitReachedError(service, message, meta) {
6888
6888
  meta
6889
6889
  };
6890
6890
  }
6891
+ var STORAGE_FULL_MESSAGE = "TinyCloud storage is full, so this change was not saved. Reading still works. Free up space or upgrade your plan to save again.";
6892
+ var STORAGE_WRITE_TOO_LARGE_MESSAGE = "This change is larger than the TinyCloud storage you have left, so it was not saved. Reading still works. Free up space or upgrade your plan to save it.";
6893
+ function parseStorageQuotaBytes(responseText) {
6894
+ const match = responseText.match(/Used:\s*(\d+)\s*bytes,\s*Limit:\s*(\d+)\s*bytes/i);
6895
+ if (!match) return void 0;
6896
+ return {
6897
+ usedBytes: parseInt(match[1], 10),
6898
+ limitBytes: parseInt(match[2], 10)
6899
+ };
6900
+ }
6901
+ function storageRejectionError(service, status, meta, responseText) {
6902
+ const quotaMeta = { ...meta, ...parseStorageQuotaBytes(responseText) };
6903
+ return status === 402 ? storageQuotaExceededError(service, STORAGE_FULL_MESSAGE, quotaMeta) : storageLimitReachedError(service, STORAGE_WRITE_TOO_LARGE_MESSAGE, quotaMeta);
6904
+ }
6891
6905
  function wrapError2(service, error, defaultCode = ErrorCodes.NETWORK_ERROR) {
6892
6906
  if (error instanceof Error) {
6893
6907
  if (error.name === "AbortError") {
@@ -7263,47 +7277,21 @@ var KVService = class extends BaseService {
7263
7277
  get config() {
7264
7278
  return this._config;
7265
7279
  }
7266
- // Parses "Used: X bytes, Limit: Y bytes" from tinycloud-node error responses
7267
- parseQuotaInfo(errorText) {
7268
- const match = errorText.match(
7269
- /Used:\s*(\d+)\s*bytes,\s*Limit:\s*(\d+)\s*bytes/i
7270
- );
7271
- if (match) {
7272
- return {
7273
- usedBytes: parseInt(match[1], 10),
7274
- limitBytes: parseInt(match[2], 10)
7275
- };
7276
- }
7277
- return void 0;
7278
- }
7279
7280
  handleQuotaErrorResponse(response, errorText, key) {
7280
- if (response.status === 402) {
7281
- const quotaInfo = this.parseQuotaInfo(errorText);
7282
- return err(
7283
- storageQuotaExceededError(
7284
- "kv",
7285
- `Storage quota exceeded for key "${key}": ${errorText}`,
7286
- {
7287
- status: response.status,
7288
- ...quotaInfo ? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes } : {}
7289
- }
7290
- )
7291
- );
7281
+ if (response.status !== 402 && response.status !== 413) {
7282
+ return void 0;
7292
7283
  }
7293
- if (response.status === 413) {
7294
- const quotaInfo = this.parseQuotaInfo(errorText);
7295
- return err(
7296
- storageLimitReachedError(
7297
- "kv",
7298
- `Storage limit reached for key "${key}": ${errorText}`,
7299
- {
7300
- status: response.status,
7301
- ...quotaInfo ? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes } : {}
7302
- }
7303
- )
7304
- );
7284
+ if (response.status === 413 && !parseStorageQuotaBytes(errorText)) {
7285
+ return void 0;
7305
7286
  }
7306
- return void 0;
7287
+ return err(
7288
+ storageRejectionError(
7289
+ "kv",
7290
+ response.status,
7291
+ { status: response.status, statusText: response.statusText, key },
7292
+ errorText
7293
+ )
7294
+ );
7307
7295
  }
7308
7296
  /**
7309
7297
  * Classify a KV 404 by reading the response body once.
@@ -7581,12 +7569,11 @@ var KVService = class extends BaseService {
7581
7569
  if (!response.ok) {
7582
7570
  const errorText = await response.text();
7583
7571
  if (response.status === 401 || response.status === 403) {
7584
- const { resource, action: requiredAction } = parseAuthError(errorText);
7585
- return err(authUnauthorizedError("kv", errorText, {
7586
- status: response.status,
7587
- ...requiredAction && { requiredAction },
7588
- ...resource && { resource }
7589
- }));
7572
+ return this.authorizationFailure(
7573
+ `Failed to batch read ${keys.length} key(s)`,
7574
+ response,
7575
+ errorText
7576
+ );
7590
7577
  }
7591
7578
  if (response.status === 413) {
7592
7579
  return err(serviceError(
@@ -7685,23 +7672,39 @@ var KVService = class extends BaseService {
7685
7672
  } catch {
7686
7673
  }
7687
7674
  if (response.status === 401 || response.status === 403) {
7688
- const { resource, action } = parseAuthError(errorText);
7689
- return err(authUnauthorizedError("kv", errorText, {
7690
- status: response.status,
7691
- ...action && { requiredAction: action },
7692
- ...resource && { resource }
7693
- }));
7675
+ return this.authorizationFailure(
7676
+ `Failed to create signed read URL for key ${JSON.stringify(key)}`,
7677
+ response,
7678
+ errorText
7679
+ );
7694
7680
  }
7695
7681
  const code2 = response.status === 400 ? ErrorCodes.INVALID_INPUT : ErrorCodes.NETWORK_ERROR;
7696
7682
  return err(
7697
7683
  serviceError(
7698
7684
  code2,
7699
- `Failed to create signed read URL for key "${key}": ${response.status} - ${errorText}`,
7685
+ `Failed to create signed read URL for key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
7700
7686
  "kv",
7701
7687
  { meta: { status: response.status, statusText: response.statusText } }
7702
7688
  )
7703
7689
  );
7704
7690
  }
7691
+ /**
7692
+ * AUTH_UNAUTHORIZED for a 401/403 response. The message keeps the HTTP
7693
+ * status and the server text (`<context>: <status> - <text>`, the same
7694
+ * shape as every other KV failure) so callers that rethrow only the message
7695
+ * still see the status; `meta.status` carries it for typed callers.
7696
+ * Resource/ability hints are parsed from the raw body, never the message.
7697
+ */
7698
+ authorizationFailure(context, response, errorText, extraMeta = {}) {
7699
+ const { resource, action } = parseAuthError(errorText);
7700
+ const detail = errorText.trim().length > 0 ? errorText : response.statusText || "authorization failed";
7701
+ return err(authUnauthorizedError("kv", `${context}: ${response.status} - ${detail}`, {
7702
+ status: response.status,
7703
+ ...action && { requiredAction: action },
7704
+ ...resource && { resource },
7705
+ ...extraMeta
7706
+ }));
7707
+ }
7705
7708
  normalizeSignedReadUrlResponse(data) {
7706
7709
  if (!data || typeof data !== "object") {
7707
7710
  return void 0;
@@ -7744,14 +7747,13 @@ var KVService = class extends BaseService {
7744
7747
  if (!response.ok) {
7745
7748
  if (response.status === 401 || response.status === 403) {
7746
7749
  const errorText2 = await response.text();
7747
- const { resource, action } = parseAuthError(errorText2);
7748
7750
  const permissionHint = parsePermissionHintFromErrorText(errorText2);
7749
- return err(authUnauthorizedError("kv", errorText2, {
7750
- status: response.status,
7751
- ...action && { requiredAction: action },
7752
- ...resource && { resource },
7753
- ...permissionHint === void 0 ? {} : { permissionHint }
7754
- }));
7751
+ return this.authorizationFailure(
7752
+ `Failed to get key ${JSON.stringify(key)}`,
7753
+ response,
7754
+ errorText2,
7755
+ permissionHint === void 0 ? {} : { permissionHint }
7756
+ );
7755
7757
  }
7756
7758
  if (response.status === 404) {
7757
7759
  return this.classifyNotFound(response, key);
@@ -7760,7 +7762,7 @@ var KVService = class extends BaseService {
7760
7762
  if (response.status === 413) {
7761
7763
  return err(serviceError(
7762
7764
  ErrorCodes.KV_RESPONSE_TOO_LARGE,
7763
- `KV value at key "${key}" exceeds the requested response limit`,
7765
+ `KV value at key ${JSON.stringify(key)} exceeds the requested response limit`,
7764
7766
  "kv",
7765
7767
  { meta: { status: response.status, statusText: response.statusText } }
7766
7768
  ));
@@ -7768,7 +7770,7 @@ var KVService = class extends BaseService {
7768
7770
  return err(
7769
7771
  serviceError(
7770
7772
  ErrorCodes.NETWORK_ERROR,
7771
- `Failed to get key "${key}": ${response.status} - ${errorText}`,
7773
+ `Failed to get key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
7772
7774
  "kv",
7773
7775
  { meta: { status: response.status, statusText: response.statusText } }
7774
7776
  )
@@ -7824,21 +7826,18 @@ var KVService = class extends BaseService {
7824
7826
  }
7825
7827
  );
7826
7828
  if (response.status === 401 || response.status === 403) {
7827
- const errorText = await response.text();
7828
- const message = errorText.trim().length > 0 ? errorText : `Failed to put key "${key}": ${response.status} - ${response.statusText || "authorization failed"}`;
7829
- const { resource, action: requiredAction } = parseAuthError(errorText);
7830
- return err(authUnauthorizedError("kv", message, {
7831
- status: response.status,
7832
- ...requiredAction && { requiredAction },
7833
- ...resource && { resource }
7834
- }));
7829
+ return this.authorizationFailure(
7830
+ `Failed to put key ${JSON.stringify(key)}`,
7831
+ response,
7832
+ await response.text()
7833
+ );
7835
7834
  }
7836
7835
  if (!response.ok) {
7837
7836
  const errorText = await response.text();
7838
7837
  if (response.status === 412) {
7839
7838
  return err(serviceError(
7840
7839
  ErrorCodes.KV_PRECONDITION_FAILED,
7841
- `KV precondition failed for key "${key}"`,
7840
+ `KV precondition failed for key ${JSON.stringify(key)}`,
7842
7841
  "kv",
7843
7842
  { meta: { status: response.status, statusText: response.statusText } }
7844
7843
  ));
@@ -7846,7 +7845,7 @@ var KVService = class extends BaseService {
7846
7845
  if (response.status === 503 && (options?.ifMatch !== void 0 || options?.ifNoneMatch !== void 0)) {
7847
7846
  return err(serviceError(
7848
7847
  ErrorCodes.KV_CONFLICT,
7849
- `Concurrent KV update conflicted for key "${key}"`,
7848
+ `Concurrent KV update conflicted for key ${JSON.stringify(key)}`,
7850
7849
  "kv",
7851
7850
  { meta: { status: response.status, statusText: response.statusText } }
7852
7851
  ));
@@ -7862,7 +7861,7 @@ var KVService = class extends BaseService {
7862
7861
  return err(
7863
7862
  serviceError(
7864
7863
  ErrorCodes.KV_WRITE_FAILED,
7865
- `Failed to put key "${key}": ${response.status} - ${errorText}`,
7864
+ `Failed to put key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
7866
7865
  "kv",
7867
7866
  { meta: { status: response.status, statusText: response.statusText } }
7868
7867
  )
@@ -7956,12 +7955,11 @@ var KVService = class extends BaseService {
7956
7955
  );
7957
7956
  }
7958
7957
  if (response.status === 401 || response.status === 403) {
7959
- const { resource, action } = parseAuthError(errorText);
7960
- return err(authUnauthorizedError("kv", errorText, {
7961
- status: response.status,
7962
- ...action && { requiredAction: action },
7963
- ...resource && { resource }
7964
- }));
7958
+ return this.authorizationFailure(
7959
+ `Failed to batch put ${items.length} key(s)`,
7960
+ response,
7961
+ errorText
7962
+ );
7965
7963
  }
7966
7964
  const quotaError = this.handleQuotaErrorResponse(
7967
7965
  response,
@@ -8082,13 +8080,11 @@ var KVService = class extends BaseService {
8082
8080
  );
8083
8081
  if (!response.ok) {
8084
8082
  if (response.status === 401) {
8085
- const errorText2 = await response.text();
8086
- const { resource, action } = parseAuthError(errorText2);
8087
- return err(authUnauthorizedError("kv", errorText2, {
8088
- status: response.status,
8089
- ...action && { requiredAction: action },
8090
- ...resource && { resource }
8091
- }));
8083
+ return this.authorizationFailure(
8084
+ "Failed to list keys",
8085
+ response,
8086
+ await response.text()
8087
+ );
8092
8088
  }
8093
8089
  const errorText = await response.text();
8094
8090
  return err(
@@ -8137,13 +8133,11 @@ var KVService = class extends BaseService {
8137
8133
  );
8138
8134
  if (!response.ok) {
8139
8135
  if (response.status === 401) {
8140
- const errorText2 = await response.text();
8141
- const { resource, action } = parseAuthError(errorText2);
8142
- return err(authUnauthorizedError("kv", errorText2, {
8143
- status: response.status,
8144
- ...action && { requiredAction: action },
8145
- ...resource && { resource }
8146
- }));
8136
+ return this.authorizationFailure(
8137
+ `Failed to delete key ${JSON.stringify(key)}`,
8138
+ response,
8139
+ await response.text()
8140
+ );
8147
8141
  }
8148
8142
  if (response.status === 404) {
8149
8143
  return this.classifyNotFound(response, key);
@@ -8152,7 +8146,7 @@ var KVService = class extends BaseService {
8152
8146
  if (response.status === 412) {
8153
8147
  return err(serviceError(
8154
8148
  ErrorCodes.KV_PRECONDITION_FAILED,
8155
- `KV precondition failed for key "${key}"`,
8149
+ `KV precondition failed for key ${JSON.stringify(key)}`,
8156
8150
  "kv",
8157
8151
  { meta: { status: response.status, statusText: response.statusText } }
8158
8152
  ));
@@ -8160,7 +8154,7 @@ var KVService = class extends BaseService {
8160
8154
  if (response.status === 503 && options?.ifMatch !== void 0) {
8161
8155
  return err(serviceError(
8162
8156
  ErrorCodes.KV_CONFLICT,
8163
- `Concurrent KV delete conflicted for key "${key}"`,
8157
+ `Concurrent KV delete conflicted for key ${JSON.stringify(key)}`,
8164
8158
  "kv",
8165
8159
  { meta: { status: response.status, statusText: response.statusText } }
8166
8160
  ));
@@ -8168,7 +8162,7 @@ var KVService = class extends BaseService {
8168
8162
  return err(
8169
8163
  serviceError(
8170
8164
  ErrorCodes.NETWORK_ERROR,
8171
- `Failed to delete key "${key}": ${response.status} - ${errorText}`,
8165
+ `Failed to delete key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
8172
8166
  "kv",
8173
8167
  { meta: { status: response.status, statusText: response.statusText } }
8174
8168
  )
@@ -8201,13 +8195,11 @@ var KVService = class extends BaseService {
8201
8195
  );
8202
8196
  if (!response.ok) {
8203
8197
  if (response.status === 401) {
8204
- const errorText2 = await response.text();
8205
- const { resource, action } = parseAuthError(errorText2);
8206
- return err(authUnauthorizedError("kv", errorText2, {
8207
- status: response.status,
8208
- ...action && { requiredAction: action },
8209
- ...resource && { resource }
8210
- }));
8198
+ return this.authorizationFailure(
8199
+ `Failed to get metadata for key ${JSON.stringify(key)}`,
8200
+ response,
8201
+ await response.text()
8202
+ );
8211
8203
  }
8212
8204
  if (response.status === 404) {
8213
8205
  return this.classifyNotFound(response, key);
@@ -8216,7 +8208,7 @@ var KVService = class extends BaseService {
8216
8208
  return err(
8217
8209
  serviceError(
8218
8210
  ErrorCodes.NETWORK_ERROR,
8219
- `Failed to get metadata for key "${key}": ${response.status} - ${errorText}`,
8211
+ `Failed to get metadata for key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
8220
8212
  "kv",
8221
8213
  { meta: { status: response.status, statusText: response.statusText } }
8222
8214
  )
@@ -8622,21 +8614,24 @@ var SQLService = class extends BaseService {
8622
8614
  }
8623
8615
  async applyMigrationsOnDbUnlocked(dbName, options) {
8624
8616
  return this.withTelemetry("migrations.apply", dbName, async () => {
8625
- const created = await this.ensureMigrationsTable(dbName, options.signal);
8626
- if (!created.ok) return created;
8627
8617
  const listed = await this.queryOnDb(
8628
8618
  dbName,
8629
8619
  `SELECT id FROM ${MIGRATIONS_TABLE} WHERE namespace = ? ORDER BY applied_at, id`,
8630
8620
  [options.namespace],
8631
8621
  { signal: options.signal }
8632
8622
  );
8633
- if (!listed.ok) return listed;
8623
+ const tableMissing = !listed.ok && (listed.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(listed.error.message));
8624
+ if (!listed.ok && !tableMissing) return listed;
8634
8625
  const appliedIds = new Set(
8635
- listed.data.rows.map((row) => rowValue(row, 0)).filter((id) => typeof id === "string")
8626
+ (listed.ok ? listed.data.rows : []).map((row) => rowValue(row, 0)).filter((id) => typeof id === "string")
8636
8627
  );
8637
8628
  const skipped = options.migrations.filter((migration) => appliedIds.has(migration.id)).map((migration) => migration.id);
8638
8629
  const pending = options.migrations.filter((migration) => !appliedIds.has(migration.id));
8639
8630
  const applied = [];
8631
+ if (pending.length > 0 && tableMissing) {
8632
+ const created = await this.ensureMigrationsTable(dbName, options.signal);
8633
+ if (!created.ok) return created;
8634
+ }
8640
8635
  for (const migration of pending) {
8641
8636
  const result = await this.applyOneMigration(dbName, options.namespace, migration, options.signal);
8642
8637
  if (!result.ok) return result;
@@ -8739,6 +8734,10 @@ var SQLService = class extends BaseService {
8739
8734
  }
8740
8735
  async handleErrorResponse(response, operation) {
8741
8736
  const errorText = await response.text();
8737
+ const meta = responseErrorMeta(response.status, response.statusText, errorText);
8738
+ if (response.status === 402) {
8739
+ return err(storageRejectionError("sql", 402, meta, errorText));
8740
+ }
8742
8741
  const errorBody = parseServiceErrorBody(errorText);
8743
8742
  const errorCode2 = this.mapHttpStatusToErrorCode(
8744
8743
  response.status,
@@ -8751,7 +8750,6 @@ var SQLService = class extends BaseService {
8751
8750
  errorText,
8752
8751
  errorBody
8753
8752
  );
8754
- const meta = responseErrorMeta(response.status, response.statusText, errorText);
8755
8753
  if (response.status === 401) {
8756
8754
  const { resource, action } = parseAuthError(errorText);
8757
8755
  if (action) meta.requiredAction = action;
@@ -8852,6 +8850,9 @@ function serializeSqlValues(values) {
8852
8850
  (value) => value instanceof Uint8Array ? Array.from(value) : value
8853
8851
  );
8854
8852
  }
8853
+ function isMissingTableError(message) {
8854
+ return /no such table/i.test(message);
8855
+ }
8855
8856
  function migrationKey(namespace, id) {
8856
8857
  return `${encodeURIComponent(namespace)}:${encodeURIComponent(id)}`;
8857
8858
  }
@@ -9166,6 +9167,10 @@ var DuckDbService = class extends BaseService {
9166
9167
  }
9167
9168
  async handleErrorResponse(response, operation) {
9168
9169
  const errorText = await response.text();
9170
+ const meta = responseErrorMeta(response.status, response.statusText, errorText);
9171
+ if (response.status === 402) {
9172
+ return err(storageRejectionError("duckdb", 402, meta, errorText));
9173
+ }
9169
9174
  const errorBody = parseServiceErrorBody(errorText);
9170
9175
  const errorCode2 = this.mapHttpStatusToErrorCode(
9171
9176
  response.status,
@@ -9178,7 +9183,6 @@ var DuckDbService = class extends BaseService {
9178
9183
  errorText,
9179
9184
  errorBody
9180
9185
  );
9181
- const meta = responseErrorMeta(response.status, response.statusText, errorText);
9182
9186
  if (response.status === 401) {
9183
9187
  const { resource, action } = parseAuthError(errorText);
9184
9188
  if (action) meta.requiredAction = action;
@@ -9675,10 +9679,14 @@ async function responseError(service, message, response) {
9675
9679
  }
9676
9680
  } catch {
9677
9681
  }
9678
- return wrapError2(
9682
+ const error = wrapError2(
9679
9683
  service,
9680
9684
  new Error(`${message}: ${response.status} ${detail}`)
9681
9685
  );
9686
+ return {
9687
+ ...error,
9688
+ meta: { ...error.meta, status: response.status, statusText: response.statusText }
9689
+ };
9682
9690
  }
9683
9691
  function isAbortError(error) {
9684
9692
  return error instanceof DOMException && error.name === "AbortError";
@@ -10101,6 +10109,9 @@ function defaultVaultMessage(input) {
10101
10109
  return input.message ?? `Public key not found for ${input.did}`;
10102
10110
  case "STORAGE_ERROR":
10103
10111
  return input.message ?? input.cause.message;
10112
+ case "STORAGE_QUOTA_EXCEEDED":
10113
+ case "STORAGE_LIMIT_REACHED":
10114
+ return input.message;
10104
10115
  }
10105
10116
  }
10106
10117
  function vaultError(input) {
@@ -10111,6 +10122,15 @@ function vaultError(input) {
10111
10122
  };
10112
10123
  return { ok: false, error };
10113
10124
  }
10125
+ function kvWriteError(context, error) {
10126
+ if (error.code === ErrorCodes.STORAGE_QUOTA_EXCEEDED || error.code === ErrorCodes.STORAGE_LIMIT_REACHED) {
10127
+ return vaultError({ code: error.code, message: error.message, meta: error.meta });
10128
+ }
10129
+ return vaultError({
10130
+ code: "STORAGE_ERROR",
10131
+ cause: new Error(`${context}: ${error.message}`)
10132
+ });
10133
+ }
10114
10134
  var DataVaultService = class extends BaseService {
10115
10135
  /**
10116
10136
  * Create a new DataVaultService instance.
@@ -10393,12 +10413,7 @@ var DataVaultService = class extends BaseService {
10393
10413
  JSON.stringify(envelopeResult.data)
10394
10414
  );
10395
10415
  if (!valuePutResult.ok) {
10396
- return vaultError({
10397
- code: "STORAGE_ERROR",
10398
- cause: new Error(
10399
- `Failed to store encrypted value: ${valuePutResult.error.message}`
10400
- )
10401
- });
10416
+ return kvWriteError("Failed to store encrypted value", valuePutResult.error);
10402
10417
  }
10403
10418
  return { ok: true, data: void 0 };
10404
10419
  } catch (error) {
@@ -10616,12 +10631,7 @@ var DataVaultService = class extends BaseService {
10616
10631
  keyPayload
10617
10632
  );
10618
10633
  if (!keyPutResult.ok) {
10619
- return vaultError({
10620
- code: "STORAGE_ERROR",
10621
- cause: new Error(
10622
- `Failed to store key blob: ${keyPutResult.error.message}`
10623
- )
10624
- });
10634
+ return kvWriteError("Failed to store key blob", keyPutResult.error);
10625
10635
  }
10626
10636
  const valuePayload = JSON.stringify({
10627
10637
  data: base64Encode(encrypted),
@@ -10632,12 +10642,7 @@ var DataVaultService = class extends BaseService {
10632
10642
  valuePayload
10633
10643
  );
10634
10644
  if (!valuePutResult.ok) {
10635
- return vaultError({
10636
- code: "STORAGE_ERROR",
10637
- cause: new Error(
10638
- `Failed to store encrypted value: ${valuePutResult.error.message}`
10639
- )
10640
- });
10645
+ return kvWriteError("Failed to store encrypted value", valuePutResult.error);
10641
10646
  }
10642
10647
  return ok(void 0);
10643
10648
  } catch (error) {
@@ -10968,12 +10973,7 @@ var DataVaultService = class extends BaseService {
10968
10973
  grantPayload
10969
10974
  );
10970
10975
  if (!grantPutResult.ok) {
10971
- return vaultError({
10972
- code: "STORAGE_ERROR",
10973
- cause: new Error(
10974
- `Failed to store grant: ${grantPutResult.error.message}`
10975
- )
10976
- });
10976
+ return kvWriteError("Failed to store grant", grantPutResult.error);
10977
10977
  }
10978
10978
  return ok(void 0);
10979
10979
  } catch (error) {
@@ -11318,12 +11318,7 @@ var DataVaultService = class extends BaseService {
11318
11318
  keyPayload
11319
11319
  );
11320
11320
  if (!keyPutResult.ok) {
11321
- return vaultError({
11322
- code: "STORAGE_ERROR",
11323
- cause: new Error(
11324
- `Failed to store rotated key blob: ${keyPutResult.error.message}`
11325
- )
11326
- });
11321
+ return kvWriteError("Failed to store rotated key blob", keyPutResult.error);
11327
11322
  }
11328
11323
  const valuePayload = JSON.stringify({
11329
11324
  data: base64Encode(encrypted),
@@ -11334,12 +11329,7 @@ var DataVaultService = class extends BaseService {
11334
11329
  valuePayload
11335
11330
  );
11336
11331
  if (!valuePutResult.ok) {
11337
- return vaultError({
11338
- code: "STORAGE_ERROR",
11339
- cause: new Error(
11340
- `Failed to store re-encrypted value: ${valuePutResult.error.message}`
11341
- )
11342
- });
11332
+ return kvWriteError("Failed to store re-encrypted value", valuePutResult.error);
11343
11333
  }
11344
11334
  for (const did of remainingGrantees) {
11345
11335
  const grantResult = await this.reencrypt(key, did);