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

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.
@@ -7282,7 +7282,7 @@ var KVService = class extends BaseService {
7282
7282
  return err(
7283
7283
  storageQuotaExceededError(
7284
7284
  "kv",
7285
- `Storage quota exceeded for key "${key}": ${errorText}`,
7285
+ `Storage quota exceeded for key ${JSON.stringify(key)}: ${errorText}`,
7286
7286
  {
7287
7287
  status: response.status,
7288
7288
  ...quotaInfo ? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes } : {}
@@ -7295,7 +7295,7 @@ var KVService = class extends BaseService {
7295
7295
  return err(
7296
7296
  storageLimitReachedError(
7297
7297
  "kv",
7298
- `Storage limit reached for key "${key}": ${errorText}`,
7298
+ `Storage limit reached for key ${JSON.stringify(key)}: ${errorText}`,
7299
7299
  {
7300
7300
  status: response.status,
7301
7301
  ...quotaInfo ? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes } : {}
@@ -7581,12 +7581,11 @@ var KVService = class extends BaseService {
7581
7581
  if (!response.ok) {
7582
7582
  const errorText = await response.text();
7583
7583
  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
- }));
7584
+ return this.authorizationFailure(
7585
+ `Failed to batch read ${keys.length} key(s)`,
7586
+ response,
7587
+ errorText
7588
+ );
7590
7589
  }
7591
7590
  if (response.status === 413) {
7592
7591
  return err(serviceError(
@@ -7685,23 +7684,39 @@ var KVService = class extends BaseService {
7685
7684
  } catch {
7686
7685
  }
7687
7686
  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
- }));
7687
+ return this.authorizationFailure(
7688
+ `Failed to create signed read URL for key ${JSON.stringify(key)}`,
7689
+ response,
7690
+ errorText
7691
+ );
7694
7692
  }
7695
7693
  const code2 = response.status === 400 ? ErrorCodes.INVALID_INPUT : ErrorCodes.NETWORK_ERROR;
7696
7694
  return err(
7697
7695
  serviceError(
7698
7696
  code2,
7699
- `Failed to create signed read URL for key "${key}": ${response.status} - ${errorText}`,
7697
+ `Failed to create signed read URL for key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
7700
7698
  "kv",
7701
7699
  { meta: { status: response.status, statusText: response.statusText } }
7702
7700
  )
7703
7701
  );
7704
7702
  }
7703
+ /**
7704
+ * AUTH_UNAUTHORIZED for a 401/403 response. The message keeps the HTTP
7705
+ * status and the server text (`<context>: <status> - <text>`, the same
7706
+ * shape as every other KV failure) so callers that rethrow only the message
7707
+ * still see the status; `meta.status` carries it for typed callers.
7708
+ * Resource/ability hints are parsed from the raw body, never the message.
7709
+ */
7710
+ authorizationFailure(context, response, errorText, extraMeta = {}) {
7711
+ const { resource, action } = parseAuthError(errorText);
7712
+ const detail = errorText.trim().length > 0 ? errorText : response.statusText || "authorization failed";
7713
+ return err(authUnauthorizedError("kv", `${context}: ${response.status} - ${detail}`, {
7714
+ status: response.status,
7715
+ ...action && { requiredAction: action },
7716
+ ...resource && { resource },
7717
+ ...extraMeta
7718
+ }));
7719
+ }
7705
7720
  normalizeSignedReadUrlResponse(data) {
7706
7721
  if (!data || typeof data !== "object") {
7707
7722
  return void 0;
@@ -7744,14 +7759,13 @@ var KVService = class extends BaseService {
7744
7759
  if (!response.ok) {
7745
7760
  if (response.status === 401 || response.status === 403) {
7746
7761
  const errorText2 = await response.text();
7747
- const { resource, action } = parseAuthError(errorText2);
7748
7762
  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
- }));
7763
+ return this.authorizationFailure(
7764
+ `Failed to get key ${JSON.stringify(key)}`,
7765
+ response,
7766
+ errorText2,
7767
+ permissionHint === void 0 ? {} : { permissionHint }
7768
+ );
7755
7769
  }
7756
7770
  if (response.status === 404) {
7757
7771
  return this.classifyNotFound(response, key);
@@ -7760,7 +7774,7 @@ var KVService = class extends BaseService {
7760
7774
  if (response.status === 413) {
7761
7775
  return err(serviceError(
7762
7776
  ErrorCodes.KV_RESPONSE_TOO_LARGE,
7763
- `KV value at key "${key}" exceeds the requested response limit`,
7777
+ `KV value at key ${JSON.stringify(key)} exceeds the requested response limit`,
7764
7778
  "kv",
7765
7779
  { meta: { status: response.status, statusText: response.statusText } }
7766
7780
  ));
@@ -7768,7 +7782,7 @@ var KVService = class extends BaseService {
7768
7782
  return err(
7769
7783
  serviceError(
7770
7784
  ErrorCodes.NETWORK_ERROR,
7771
- `Failed to get key "${key}": ${response.status} - ${errorText}`,
7785
+ `Failed to get key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
7772
7786
  "kv",
7773
7787
  { meta: { status: response.status, statusText: response.statusText } }
7774
7788
  )
@@ -7824,21 +7838,18 @@ var KVService = class extends BaseService {
7824
7838
  }
7825
7839
  );
7826
7840
  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
- }));
7841
+ return this.authorizationFailure(
7842
+ `Failed to put key ${JSON.stringify(key)}`,
7843
+ response,
7844
+ await response.text()
7845
+ );
7835
7846
  }
7836
7847
  if (!response.ok) {
7837
7848
  const errorText = await response.text();
7838
7849
  if (response.status === 412) {
7839
7850
  return err(serviceError(
7840
7851
  ErrorCodes.KV_PRECONDITION_FAILED,
7841
- `KV precondition failed for key "${key}"`,
7852
+ `KV precondition failed for key ${JSON.stringify(key)}`,
7842
7853
  "kv",
7843
7854
  { meta: { status: response.status, statusText: response.statusText } }
7844
7855
  ));
@@ -7846,7 +7857,7 @@ var KVService = class extends BaseService {
7846
7857
  if (response.status === 503 && (options?.ifMatch !== void 0 || options?.ifNoneMatch !== void 0)) {
7847
7858
  return err(serviceError(
7848
7859
  ErrorCodes.KV_CONFLICT,
7849
- `Concurrent KV update conflicted for key "${key}"`,
7860
+ `Concurrent KV update conflicted for key ${JSON.stringify(key)}`,
7850
7861
  "kv",
7851
7862
  { meta: { status: response.status, statusText: response.statusText } }
7852
7863
  ));
@@ -7862,7 +7873,7 @@ var KVService = class extends BaseService {
7862
7873
  return err(
7863
7874
  serviceError(
7864
7875
  ErrorCodes.KV_WRITE_FAILED,
7865
- `Failed to put key "${key}": ${response.status} - ${errorText}`,
7876
+ `Failed to put key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
7866
7877
  "kv",
7867
7878
  { meta: { status: response.status, statusText: response.statusText } }
7868
7879
  )
@@ -7956,12 +7967,11 @@ var KVService = class extends BaseService {
7956
7967
  );
7957
7968
  }
7958
7969
  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
- }));
7970
+ return this.authorizationFailure(
7971
+ `Failed to batch put ${items.length} key(s)`,
7972
+ response,
7973
+ errorText
7974
+ );
7965
7975
  }
7966
7976
  const quotaError = this.handleQuotaErrorResponse(
7967
7977
  response,
@@ -8082,13 +8092,11 @@ var KVService = class extends BaseService {
8082
8092
  );
8083
8093
  if (!response.ok) {
8084
8094
  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
- }));
8095
+ return this.authorizationFailure(
8096
+ "Failed to list keys",
8097
+ response,
8098
+ await response.text()
8099
+ );
8092
8100
  }
8093
8101
  const errorText = await response.text();
8094
8102
  return err(
@@ -8137,13 +8145,11 @@ var KVService = class extends BaseService {
8137
8145
  );
8138
8146
  if (!response.ok) {
8139
8147
  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
- }));
8148
+ return this.authorizationFailure(
8149
+ `Failed to delete key ${JSON.stringify(key)}`,
8150
+ response,
8151
+ await response.text()
8152
+ );
8147
8153
  }
8148
8154
  if (response.status === 404) {
8149
8155
  return this.classifyNotFound(response, key);
@@ -8152,7 +8158,7 @@ var KVService = class extends BaseService {
8152
8158
  if (response.status === 412) {
8153
8159
  return err(serviceError(
8154
8160
  ErrorCodes.KV_PRECONDITION_FAILED,
8155
- `KV precondition failed for key "${key}"`,
8161
+ `KV precondition failed for key ${JSON.stringify(key)}`,
8156
8162
  "kv",
8157
8163
  { meta: { status: response.status, statusText: response.statusText } }
8158
8164
  ));
@@ -8160,7 +8166,7 @@ var KVService = class extends BaseService {
8160
8166
  if (response.status === 503 && options?.ifMatch !== void 0) {
8161
8167
  return err(serviceError(
8162
8168
  ErrorCodes.KV_CONFLICT,
8163
- `Concurrent KV delete conflicted for key "${key}"`,
8169
+ `Concurrent KV delete conflicted for key ${JSON.stringify(key)}`,
8164
8170
  "kv",
8165
8171
  { meta: { status: response.status, statusText: response.statusText } }
8166
8172
  ));
@@ -8168,7 +8174,7 @@ var KVService = class extends BaseService {
8168
8174
  return err(
8169
8175
  serviceError(
8170
8176
  ErrorCodes.NETWORK_ERROR,
8171
- `Failed to delete key "${key}": ${response.status} - ${errorText}`,
8177
+ `Failed to delete key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
8172
8178
  "kv",
8173
8179
  { meta: { status: response.status, statusText: response.statusText } }
8174
8180
  )
@@ -8201,13 +8207,11 @@ var KVService = class extends BaseService {
8201
8207
  );
8202
8208
  if (!response.ok) {
8203
8209
  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
- }));
8210
+ return this.authorizationFailure(
8211
+ `Failed to get metadata for key ${JSON.stringify(key)}`,
8212
+ response,
8213
+ await response.text()
8214
+ );
8211
8215
  }
8212
8216
  if (response.status === 404) {
8213
8217
  return this.classifyNotFound(response, key);
@@ -8216,7 +8220,7 @@ var KVService = class extends BaseService {
8216
8220
  return err(
8217
8221
  serviceError(
8218
8222
  ErrorCodes.NETWORK_ERROR,
8219
- `Failed to get metadata for key "${key}": ${response.status} - ${errorText}`,
8223
+ `Failed to get metadata for key ${JSON.stringify(key)}: ${response.status} - ${errorText}`,
8220
8224
  "kv",
8221
8225
  { meta: { status: response.status, statusText: response.statusText } }
8222
8226
  )
@@ -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";