@tinycloud/operations 0.3.4-beta.1 → 0.3.4-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.
package/dist/artifacts.js CHANGED
@@ -1242,6 +1242,20 @@ function storageLimitReachedError(service, message, meta) {
1242
1242
  meta
1243
1243
  };
1244
1244
  }
1245
+ 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.";
1246
+ 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.";
1247
+ function parseStorageQuotaBytes(responseText) {
1248
+ const match = responseText.match(/Used:\s*(\d+)\s*bytes,\s*Limit:\s*(\d+)\s*bytes/i);
1249
+ if (!match) return void 0;
1250
+ return {
1251
+ usedBytes: parseInt(match[1], 10),
1252
+ limitBytes: parseInt(match[2], 10)
1253
+ };
1254
+ }
1255
+ function storageRejectionError(service, status, meta, responseText) {
1256
+ const quotaMeta = { ...meta, ...parseStorageQuotaBytes(responseText) };
1257
+ return status === 402 ? storageQuotaExceededError(service, STORAGE_FULL_MESSAGE, quotaMeta) : storageLimitReachedError(service, STORAGE_WRITE_TOO_LARGE_MESSAGE, quotaMeta);
1258
+ }
1245
1259
  function wrapError(service, error, defaultCode = ErrorCodes.NETWORK_ERROR) {
1246
1260
  if (error instanceof Error) {
1247
1261
  if (error.name === "AbortError") {
@@ -1617,47 +1631,21 @@ var KVService = class extends BaseService {
1617
1631
  get config() {
1618
1632
  return this._config;
1619
1633
  }
1620
- // Parses "Used: X bytes, Limit: Y bytes" from tinycloud-node error responses
1621
- parseQuotaInfo(errorText) {
1622
- const match = errorText.match(
1623
- /Used:\s*(\d+)\s*bytes,\s*Limit:\s*(\d+)\s*bytes/i
1624
- );
1625
- if (match) {
1626
- return {
1627
- usedBytes: parseInt(match[1], 10),
1628
- limitBytes: parseInt(match[2], 10)
1629
- };
1630
- }
1631
- return void 0;
1632
- }
1633
1634
  handleQuotaErrorResponse(response, errorText, key) {
1634
- if (response.status === 402) {
1635
- const quotaInfo = this.parseQuotaInfo(errorText);
1636
- return err(
1637
- storageQuotaExceededError(
1638
- "kv",
1639
- `Storage quota exceeded for key "${key}": ${errorText}`,
1640
- {
1641
- status: response.status,
1642
- ...quotaInfo ? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes } : {}
1643
- }
1644
- )
1645
- );
1635
+ if (response.status !== 402 && response.status !== 413) {
1636
+ return void 0;
1646
1637
  }
1647
- if (response.status === 413) {
1648
- const quotaInfo = this.parseQuotaInfo(errorText);
1649
- return err(
1650
- storageLimitReachedError(
1651
- "kv",
1652
- `Storage limit reached for key "${key}": ${errorText}`,
1653
- {
1654
- status: response.status,
1655
- ...quotaInfo ? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes } : {}
1656
- }
1657
- )
1658
- );
1638
+ if (response.status === 413 && !parseStorageQuotaBytes(errorText)) {
1639
+ return void 0;
1659
1640
  }
1660
- return void 0;
1641
+ return err(
1642
+ storageRejectionError(
1643
+ "kv",
1644
+ response.status,
1645
+ { status: response.status, statusText: response.statusText, key },
1646
+ errorText
1647
+ )
1648
+ );
1661
1649
  }
1662
1650
  /**
1663
1651
  * Classify a KV 404 by reading the response body once.
@@ -1935,12 +1923,11 @@ var KVService = class extends BaseService {
1935
1923
  if (!response.ok) {
1936
1924
  const errorText = await response.text();
1937
1925
  if (response.status === 401 || response.status === 403) {
1938
- const { resource, action: requiredAction } = parseAuthError(errorText);
1939
- return err(authUnauthorizedError("kv", errorText, {
1940
- status: response.status,
1941
- ...requiredAction && { requiredAction },
1942
- ...resource && { resource }
1943
- }));
1926
+ return this.authorizationFailure(
1927
+ `Failed to batch read ${keys.length} key(s)`,
1928
+ response,
1929
+ errorText
1930
+ );
1944
1931
  }
1945
1932
  if (response.status === 413) {
1946
1933
  return err(serviceError(
@@ -2039,23 +2026,39 @@ var KVService = class extends BaseService {
2039
2026
  } catch {
2040
2027
  }
2041
2028
  if (response.status === 401 || response.status === 403) {
2042
- const { resource, action } = parseAuthError(errorText);
2043
- return err(authUnauthorizedError("kv", errorText, {
2044
- status: response.status,
2045
- ...action && { requiredAction: action },
2046
- ...resource && { resource }
2047
- }));
2029
+ return this.authorizationFailure(
2030
+ `Failed to create signed read URL for key ${JSON.stringify(key)}`,
2031
+ response,
2032
+ errorText
2033
+ );
2048
2034
  }
2049
2035
  const code = response.status === 400 ? ErrorCodes.INVALID_INPUT : ErrorCodes.NETWORK_ERROR;
2050
2036
  return err(
2051
2037
  serviceError(
2052
2038
  code,
2053
- `Failed to create signed read URL for key "${key}": ${response.status} - ${errorText}`,
2039
+ `Failed to create signed read URL for key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
2054
2040
  "kv",
2055
2041
  { meta: { status: response.status, statusText: response.statusText } }
2056
2042
  )
2057
2043
  );
2058
2044
  }
2045
+ /**
2046
+ * AUTH_UNAUTHORIZED for a 401/403 response. The message keeps the HTTP
2047
+ * status and the server text (`<context>: <status> - <text>`, the same
2048
+ * shape as every other KV failure) so callers that rethrow only the message
2049
+ * still see the status; `meta.status` carries it for typed callers.
2050
+ * Resource/ability hints are parsed from the raw body, never the message.
2051
+ */
2052
+ authorizationFailure(context, response, errorText, extraMeta = {}) {
2053
+ const { resource, action } = parseAuthError(errorText);
2054
+ const detail = errorText.trim().length > 0 ? errorText : response.statusText || "authorization failed";
2055
+ return err(authUnauthorizedError("kv", `${context}: ${response.status} - ${detail}`, {
2056
+ status: response.status,
2057
+ ...action && { requiredAction: action },
2058
+ ...resource && { resource },
2059
+ ...extraMeta
2060
+ }));
2061
+ }
2059
2062
  normalizeSignedReadUrlResponse(data) {
2060
2063
  if (!data || typeof data !== "object") {
2061
2064
  return void 0;
@@ -2098,14 +2101,13 @@ var KVService = class extends BaseService {
2098
2101
  if (!response.ok) {
2099
2102
  if (response.status === 401 || response.status === 403) {
2100
2103
  const errorText2 = await response.text();
2101
- const { resource, action } = parseAuthError(errorText2);
2102
2104
  const permissionHint = parsePermissionHintFromErrorText(errorText2);
2103
- return err(authUnauthorizedError("kv", errorText2, {
2104
- status: response.status,
2105
- ...action && { requiredAction: action },
2106
- ...resource && { resource },
2107
- ...permissionHint === void 0 ? {} : { permissionHint }
2108
- }));
2105
+ return this.authorizationFailure(
2106
+ `Failed to get key ${JSON.stringify(key)}`,
2107
+ response,
2108
+ errorText2,
2109
+ permissionHint === void 0 ? {} : { permissionHint }
2110
+ );
2109
2111
  }
2110
2112
  if (response.status === 404) {
2111
2113
  return this.classifyNotFound(response, key);
@@ -2114,7 +2116,7 @@ var KVService = class extends BaseService {
2114
2116
  if (response.status === 413) {
2115
2117
  return err(serviceError(
2116
2118
  ErrorCodes.KV_RESPONSE_TOO_LARGE,
2117
- `KV value at key "${key}" exceeds the requested response limit`,
2119
+ `KV value at key ${JSON.stringify(key)} exceeds the requested response limit`,
2118
2120
  "kv",
2119
2121
  { meta: { status: response.status, statusText: response.statusText } }
2120
2122
  ));
@@ -2122,7 +2124,7 @@ var KVService = class extends BaseService {
2122
2124
  return err(
2123
2125
  serviceError(
2124
2126
  ErrorCodes.NETWORK_ERROR,
2125
- `Failed to get key "${key}": ${response.status} - ${errorText}`,
2127
+ `Failed to get key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
2126
2128
  "kv",
2127
2129
  { meta: { status: response.status, statusText: response.statusText } }
2128
2130
  )
@@ -2178,21 +2180,18 @@ var KVService = class extends BaseService {
2178
2180
  }
2179
2181
  );
2180
2182
  if (response.status === 401 || response.status === 403) {
2181
- const errorText = await response.text();
2182
- const message = errorText.trim().length > 0 ? errorText : `Failed to put key "${key}": ${response.status} - ${response.statusText || "authorization failed"}`;
2183
- const { resource, action: requiredAction } = parseAuthError(errorText);
2184
- return err(authUnauthorizedError("kv", message, {
2185
- status: response.status,
2186
- ...requiredAction && { requiredAction },
2187
- ...resource && { resource }
2188
- }));
2183
+ return this.authorizationFailure(
2184
+ `Failed to put key ${JSON.stringify(key)}`,
2185
+ response,
2186
+ await response.text()
2187
+ );
2189
2188
  }
2190
2189
  if (!response.ok) {
2191
2190
  const errorText = await response.text();
2192
2191
  if (response.status === 412) {
2193
2192
  return err(serviceError(
2194
2193
  ErrorCodes.KV_PRECONDITION_FAILED,
2195
- `KV precondition failed for key "${key}"`,
2194
+ `KV precondition failed for key ${JSON.stringify(key)}`,
2196
2195
  "kv",
2197
2196
  { meta: { status: response.status, statusText: response.statusText } }
2198
2197
  ));
@@ -2200,7 +2199,7 @@ var KVService = class extends BaseService {
2200
2199
  if (response.status === 503 && (options?.ifMatch !== void 0 || options?.ifNoneMatch !== void 0)) {
2201
2200
  return err(serviceError(
2202
2201
  ErrorCodes.KV_CONFLICT,
2203
- `Concurrent KV update conflicted for key "${key}"`,
2202
+ `Concurrent KV update conflicted for key ${JSON.stringify(key)}`,
2204
2203
  "kv",
2205
2204
  { meta: { status: response.status, statusText: response.statusText } }
2206
2205
  ));
@@ -2216,7 +2215,7 @@ var KVService = class extends BaseService {
2216
2215
  return err(
2217
2216
  serviceError(
2218
2217
  ErrorCodes.KV_WRITE_FAILED,
2219
- `Failed to put key "${key}": ${response.status} - ${errorText}`,
2218
+ `Failed to put key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
2220
2219
  "kv",
2221
2220
  { meta: { status: response.status, statusText: response.statusText } }
2222
2221
  )
@@ -2310,12 +2309,11 @@ var KVService = class extends BaseService {
2310
2309
  );
2311
2310
  }
2312
2311
  if (response.status === 401 || response.status === 403) {
2313
- const { resource, action } = parseAuthError(errorText);
2314
- return err(authUnauthorizedError("kv", errorText, {
2315
- status: response.status,
2316
- ...action && { requiredAction: action },
2317
- ...resource && { resource }
2318
- }));
2312
+ return this.authorizationFailure(
2313
+ `Failed to batch put ${items.length} key(s)`,
2314
+ response,
2315
+ errorText
2316
+ );
2319
2317
  }
2320
2318
  const quotaError = this.handleQuotaErrorResponse(
2321
2319
  response,
@@ -2436,13 +2434,11 @@ var KVService = class extends BaseService {
2436
2434
  );
2437
2435
  if (!response.ok) {
2438
2436
  if (response.status === 401) {
2439
- const errorText2 = await response.text();
2440
- const { resource, action } = parseAuthError(errorText2);
2441
- return err(authUnauthorizedError("kv", errorText2, {
2442
- status: response.status,
2443
- ...action && { requiredAction: action },
2444
- ...resource && { resource }
2445
- }));
2437
+ return this.authorizationFailure(
2438
+ "Failed to list keys",
2439
+ response,
2440
+ await response.text()
2441
+ );
2446
2442
  }
2447
2443
  const errorText = await response.text();
2448
2444
  return err(
@@ -2491,13 +2487,11 @@ var KVService = class extends BaseService {
2491
2487
  );
2492
2488
  if (!response.ok) {
2493
2489
  if (response.status === 401) {
2494
- const errorText2 = await response.text();
2495
- const { resource, action } = parseAuthError(errorText2);
2496
- return err(authUnauthorizedError("kv", errorText2, {
2497
- status: response.status,
2498
- ...action && { requiredAction: action },
2499
- ...resource && { resource }
2500
- }));
2490
+ return this.authorizationFailure(
2491
+ `Failed to delete key ${JSON.stringify(key)}`,
2492
+ response,
2493
+ await response.text()
2494
+ );
2501
2495
  }
2502
2496
  if (response.status === 404) {
2503
2497
  return this.classifyNotFound(response, key);
@@ -2506,7 +2500,7 @@ var KVService = class extends BaseService {
2506
2500
  if (response.status === 412) {
2507
2501
  return err(serviceError(
2508
2502
  ErrorCodes.KV_PRECONDITION_FAILED,
2509
- `KV precondition failed for key "${key}"`,
2503
+ `KV precondition failed for key ${JSON.stringify(key)}`,
2510
2504
  "kv",
2511
2505
  { meta: { status: response.status, statusText: response.statusText } }
2512
2506
  ));
@@ -2514,7 +2508,7 @@ var KVService = class extends BaseService {
2514
2508
  if (response.status === 503 && options?.ifMatch !== void 0) {
2515
2509
  return err(serviceError(
2516
2510
  ErrorCodes.KV_CONFLICT,
2517
- `Concurrent KV delete conflicted for key "${key}"`,
2511
+ `Concurrent KV delete conflicted for key ${JSON.stringify(key)}`,
2518
2512
  "kv",
2519
2513
  { meta: { status: response.status, statusText: response.statusText } }
2520
2514
  ));
@@ -2522,7 +2516,7 @@ var KVService = class extends BaseService {
2522
2516
  return err(
2523
2517
  serviceError(
2524
2518
  ErrorCodes.NETWORK_ERROR,
2525
- `Failed to delete key "${key}": ${response.status} - ${errorText}`,
2519
+ `Failed to delete key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
2526
2520
  "kv",
2527
2521
  { meta: { status: response.status, statusText: response.statusText } }
2528
2522
  )
@@ -2555,13 +2549,11 @@ var KVService = class extends BaseService {
2555
2549
  );
2556
2550
  if (!response.ok) {
2557
2551
  if (response.status === 401) {
2558
- const errorText2 = await response.text();
2559
- const { resource, action } = parseAuthError(errorText2);
2560
- return err(authUnauthorizedError("kv", errorText2, {
2561
- status: response.status,
2562
- ...action && { requiredAction: action },
2563
- ...resource && { resource }
2564
- }));
2552
+ return this.authorizationFailure(
2553
+ `Failed to get metadata for key ${JSON.stringify(key)}`,
2554
+ response,
2555
+ await response.text()
2556
+ );
2565
2557
  }
2566
2558
  if (response.status === 404) {
2567
2559
  return this.classifyNotFound(response, key);
@@ -2570,7 +2562,7 @@ var KVService = class extends BaseService {
2570
2562
  return err(
2571
2563
  serviceError(
2572
2564
  ErrorCodes.NETWORK_ERROR,
2573
- `Failed to get metadata for key "${key}": ${response.status} - ${errorText}`,
2565
+ `Failed to get metadata for key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
2574
2566
  "kv",
2575
2567
  { meta: { status: response.status, statusText: response.statusText } }
2576
2568
  )
@@ -2976,21 +2968,24 @@ var SQLService = class extends BaseService {
2976
2968
  }
2977
2969
  async applyMigrationsOnDbUnlocked(dbName, options) {
2978
2970
  return this.withTelemetry("migrations.apply", dbName, async () => {
2979
- const created = await this.ensureMigrationsTable(dbName, options.signal);
2980
- if (!created.ok) return created;
2981
2971
  const listed = await this.queryOnDb(
2982
2972
  dbName,
2983
2973
  `SELECT id FROM ${MIGRATIONS_TABLE} WHERE namespace = ? ORDER BY applied_at, id`,
2984
2974
  [options.namespace],
2985
2975
  { signal: options.signal }
2986
2976
  );
2987
- if (!listed.ok) return listed;
2977
+ const tableMissing = !listed.ok && (listed.error.code === ErrorCodes.SQL_DATABASE_NOT_FOUND || isMissingTableError(listed.error.message));
2978
+ if (!listed.ok && !tableMissing) return listed;
2988
2979
  const appliedIds = new Set(
2989
- listed.data.rows.map((row) => rowValue(row, 0)).filter((id) => typeof id === "string")
2980
+ (listed.ok ? listed.data.rows : []).map((row) => rowValue(row, 0)).filter((id) => typeof id === "string")
2990
2981
  );
2991
2982
  const skipped = options.migrations.filter((migration) => appliedIds.has(migration.id)).map((migration) => migration.id);
2992
2983
  const pending = options.migrations.filter((migration) => !appliedIds.has(migration.id));
2993
2984
  const applied = [];
2985
+ if (pending.length > 0 && tableMissing) {
2986
+ const created = await this.ensureMigrationsTable(dbName, options.signal);
2987
+ if (!created.ok) return created;
2988
+ }
2994
2989
  for (const migration of pending) {
2995
2990
  const result = await this.applyOneMigration(dbName, options.namespace, migration, options.signal);
2996
2991
  if (!result.ok) return result;
@@ -3093,6 +3088,10 @@ var SQLService = class extends BaseService {
3093
3088
  }
3094
3089
  async handleErrorResponse(response, operation) {
3095
3090
  const errorText = await response.text();
3091
+ const meta = responseErrorMeta(response.status, response.statusText, errorText);
3092
+ if (response.status === 402) {
3093
+ return err(storageRejectionError("sql", 402, meta, errorText));
3094
+ }
3096
3095
  const errorBody = parseServiceErrorBody(errorText);
3097
3096
  const errorCode = this.mapHttpStatusToErrorCode(
3098
3097
  response.status,
@@ -3105,7 +3104,6 @@ var SQLService = class extends BaseService {
3105
3104
  errorText,
3106
3105
  errorBody
3107
3106
  );
3108
- const meta = responseErrorMeta(response.status, response.statusText, errorText);
3109
3107
  if (response.status === 401) {
3110
3108
  const { resource, action } = parseAuthError(errorText);
3111
3109
  if (action) meta.requiredAction = action;
@@ -3206,6 +3204,9 @@ function serializeSqlValues(values) {
3206
3204
  (value) => value instanceof Uint8Array ? Array.from(value) : value
3207
3205
  );
3208
3206
  }
3207
+ function isMissingTableError(message) {
3208
+ return /no such table/i.test(message);
3209
+ }
3209
3210
  function migrationKey(namespace, id) {
3210
3211
  return `${encodeURIComponent(namespace)}:${encodeURIComponent(id)}`;
3211
3212
  }
@@ -3520,6 +3521,10 @@ var DuckDbService = class extends BaseService {
3520
3521
  }
3521
3522
  async handleErrorResponse(response, operation) {
3522
3523
  const errorText = await response.text();
3524
+ const meta = responseErrorMeta(response.status, response.statusText, errorText);
3525
+ if (response.status === 402) {
3526
+ return err(storageRejectionError("duckdb", 402, meta, errorText));
3527
+ }
3523
3528
  const errorBody = parseServiceErrorBody(errorText);
3524
3529
  const errorCode = this.mapHttpStatusToErrorCode(
3525
3530
  response.status,
@@ -3532,7 +3537,6 @@ var DuckDbService = class extends BaseService {
3532
3537
  errorText,
3533
3538
  errorBody
3534
3539
  );
3535
- const meta = responseErrorMeta(response.status, response.statusText, errorText);
3536
3540
  if (response.status === 401) {
3537
3541
  const { resource, action } = parseAuthError(errorText);
3538
3542
  if (action) meta.requiredAction = action;
@@ -4029,10 +4033,14 @@ async function responseError(service, message, response) {
4029
4033
  }
4030
4034
  } catch {
4031
4035
  }
4032
- return wrapError(
4036
+ const error = wrapError(
4033
4037
  service,
4034
4038
  new Error(`${message}: ${response.status} ${detail}`)
4035
4039
  );
4040
+ return {
4041
+ ...error,
4042
+ meta: { ...error.meta, status: response.status, statusText: response.statusText }
4043
+ };
4036
4044
  }
4037
4045
  function isAbortError(error) {
4038
4046
  return error instanceof DOMException && error.name === "AbortError";
@@ -4455,6 +4463,9 @@ function defaultVaultMessage(input) {
4455
4463
  return input.message ?? `Public key not found for ${input.did}`;
4456
4464
  case "STORAGE_ERROR":
4457
4465
  return input.message ?? input.cause.message;
4466
+ case "STORAGE_QUOTA_EXCEEDED":
4467
+ case "STORAGE_LIMIT_REACHED":
4468
+ return input.message;
4458
4469
  }
4459
4470
  }
4460
4471
  function vaultError(input) {
@@ -4465,6 +4476,15 @@ function vaultError(input) {
4465
4476
  };
4466
4477
  return { ok: false, error };
4467
4478
  }
4479
+ function kvWriteError(context, error) {
4480
+ if (error.code === ErrorCodes.STORAGE_QUOTA_EXCEEDED || error.code === ErrorCodes.STORAGE_LIMIT_REACHED) {
4481
+ return vaultError({ code: error.code, message: error.message, meta: error.meta });
4482
+ }
4483
+ return vaultError({
4484
+ code: "STORAGE_ERROR",
4485
+ cause: new Error(`${context}: ${error.message}`)
4486
+ });
4487
+ }
4468
4488
  var DataVaultService = class extends BaseService {
4469
4489
  /**
4470
4490
  * Create a new DataVaultService instance.
@@ -4747,12 +4767,7 @@ var DataVaultService = class extends BaseService {
4747
4767
  JSON.stringify(envelopeResult.data)
4748
4768
  );
4749
4769
  if (!valuePutResult.ok) {
4750
- return vaultError({
4751
- code: "STORAGE_ERROR",
4752
- cause: new Error(
4753
- `Failed to store encrypted value: ${valuePutResult.error.message}`
4754
- )
4755
- });
4770
+ return kvWriteError("Failed to store encrypted value", valuePutResult.error);
4756
4771
  }
4757
4772
  return { ok: true, data: void 0 };
4758
4773
  } catch (error) {
@@ -4970,12 +4985,7 @@ var DataVaultService = class extends BaseService {
4970
4985
  keyPayload
4971
4986
  );
4972
4987
  if (!keyPutResult.ok) {
4973
- return vaultError({
4974
- code: "STORAGE_ERROR",
4975
- cause: new Error(
4976
- `Failed to store key blob: ${keyPutResult.error.message}`
4977
- )
4978
- });
4988
+ return kvWriteError("Failed to store key blob", keyPutResult.error);
4979
4989
  }
4980
4990
  const valuePayload = JSON.stringify({
4981
4991
  data: base64Encode(encrypted),
@@ -4986,12 +4996,7 @@ var DataVaultService = class extends BaseService {
4986
4996
  valuePayload
4987
4997
  );
4988
4998
  if (!valuePutResult.ok) {
4989
- return vaultError({
4990
- code: "STORAGE_ERROR",
4991
- cause: new Error(
4992
- `Failed to store encrypted value: ${valuePutResult.error.message}`
4993
- )
4994
- });
4999
+ return kvWriteError("Failed to store encrypted value", valuePutResult.error);
4995
5000
  }
4996
5001
  return ok(void 0);
4997
5002
  } catch (error) {
@@ -5322,12 +5327,7 @@ var DataVaultService = class extends BaseService {
5322
5327
  grantPayload
5323
5328
  );
5324
5329
  if (!grantPutResult.ok) {
5325
- return vaultError({
5326
- code: "STORAGE_ERROR",
5327
- cause: new Error(
5328
- `Failed to store grant: ${grantPutResult.error.message}`
5329
- )
5330
- });
5330
+ return kvWriteError("Failed to store grant", grantPutResult.error);
5331
5331
  }
5332
5332
  return ok(void 0);
5333
5333
  } catch (error) {
@@ -5672,12 +5672,7 @@ var DataVaultService = class extends BaseService {
5672
5672
  keyPayload
5673
5673
  );
5674
5674
  if (!keyPutResult.ok) {
5675
- return vaultError({
5676
- code: "STORAGE_ERROR",
5677
- cause: new Error(
5678
- `Failed to store rotated key blob: ${keyPutResult.error.message}`
5679
- )
5680
- });
5675
+ return kvWriteError("Failed to store rotated key blob", keyPutResult.error);
5681
5676
  }
5682
5677
  const valuePayload = JSON.stringify({
5683
5678
  data: base64Encode(encrypted),
@@ -5688,12 +5683,7 @@ var DataVaultService = class extends BaseService {
5688
5683
  valuePayload
5689
5684
  );
5690
5685
  if (!valuePutResult.ok) {
5691
- return vaultError({
5692
- code: "STORAGE_ERROR",
5693
- cause: new Error(
5694
- `Failed to store re-encrypted value: ${valuePutResult.error.message}`
5695
- )
5696
- });
5686
+ return kvWriteError("Failed to store re-encrypted value", valuePutResult.error);
5697
5687
  }
5698
5688
  for (const did of remainingGrantees) {
5699
5689
  const grantResult = await this.reencrypt(key, did);