@tinycloud/sdk-core 3.1.0-beta.4 → 3.1.0-beta.6

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.
@@ -2681,7 +2681,7 @@ var hashes = { ...sha2_browser_exports, ...identity_exports2 };
2681
2681
  var import_ed255194 = require("@noble/curves/ed25519");
2682
2682
 
2683
2683
  // src/delegations/ShareRecipientClient.ts
2684
- var import_sdk_services2 = require("@tinycloud/sdk-services");
2684
+ var import_sdk_services3 = require("@tinycloud/sdk-services");
2685
2685
  var import_ed255193 = require("@noble/curves/ed25519");
2686
2686
  var import_sha2564 = require("@noble/hashes/sha256");
2687
2687
 
@@ -3959,6 +3959,21 @@ function assertUnicodeScalarString(value, path) {
3959
3959
  }
3960
3960
  }
3961
3961
 
3962
+ // src/http-error.ts
3963
+ var import_sdk_services2 = require("@tinycloud/sdk-services");
3964
+ async function httpResponseError(response, context) {
3965
+ let body;
3966
+ try {
3967
+ body = await response.text();
3968
+ } catch {
3969
+ body = response.statusText;
3970
+ }
3971
+ body = body.trim().slice(0, 512);
3972
+ return Object.assign(new Error(`${context}: HTTP ${response.status}${body ? ` - ${body}` : ""}`), {
3973
+ status: response.status
3974
+ });
3975
+ }
3976
+
3962
3977
  // src/policy/unified.ts
3963
3978
  var POLICY_SESSION_UCAN_V1_PROFILE = "policy-session-ucan/v1";
3964
3979
  var POLICY_SESSION_FACT_KEYS = [
@@ -4223,7 +4238,7 @@ async function importPortableDelegation(fetchFn, host, delegation) {
4223
4238
  headers: { Authorization: parsed.delegationHeader.Authorization }
4224
4239
  });
4225
4240
  if (!response.ok)
4226
- throw new Error(`node rejected delegation import (${response.status})`);
4241
+ throw await httpResponseError(response, "node rejected delegation import");
4227
4242
  const body = await response.json().catch(() => ({}));
4228
4243
  if (body === null || typeof body !== "object" || Array.isArray(body))
4229
4244
  return {};
@@ -4292,7 +4307,7 @@ function redactedCode(error) {
4292
4307
  if (error instanceof ShareConflict) return error.code;
4293
4308
  const code3 = error && typeof error === "object" && "code" in error ? error.code : void 0;
4294
4309
  if (typeof code3 !== "string") return "SHARE_INVALID";
4295
- if (code3 === import_sdk_services2.ErrorCodes.KV_PRECONDITION_FAILED || code3 === import_sdk_services2.ErrorCodes.KV_CONFLICT || code3 === "412") return "SHARE_CONFLICT";
4310
+ if (code3 === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || code3 === import_sdk_services3.ErrorCodes.KV_CONFLICT || code3 === "412") return "SHARE_CONFLICT";
4296
4311
  if (code3 === "KV_NOT_FOUND" || code3 === "NOT_FOUND" || code3 === "404") return "SHARE_NOT_FOUND";
4297
4312
  if (code3.includes("EXPIRED") || code3 === "expired") return "SHARE_EXPIRED";
4298
4313
  if (code3.includes("REVOK")) return "SHARE_REVOKED";
@@ -4531,7 +4546,7 @@ var ShareRecipientClient = class {
4531
4546
  if (portableDelegation !== void 0 && kv !== void 0) {
4532
4547
  const result2 = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
4533
4548
  if (!result2.ok) {
4534
- if (result2.error.code === import_sdk_services2.ErrorCodes.KV_PRECONDITION_FAILED || result2.error.code === import_sdk_services2.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
4549
+ if (result2.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || result2.error.code === import_sdk_services3.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
4535
4550
  throw result2.error;
4536
4551
  }
4537
4552
  return { etag: result2.data.headers.etag };
@@ -4539,7 +4554,7 @@ var ShareRecipientClient = class {
4539
4554
  if (policySession !== void 0) return this.nativeSave(envelope, policySession, resolvedPath, bytes2, input);
4540
4555
  const result = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
4541
4556
  if (!result.ok) {
4542
- if (result.error.code === import_sdk_services2.ErrorCodes.KV_PRECONDITION_FAILED || result.error.code === import_sdk_services2.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
4557
+ if (result.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || result.error.code === import_sdk_services3.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
4543
4558
  throw result.error;
4544
4559
  }
4545
4560
  return { etag: result.data.headers.etag };
@@ -4623,8 +4638,8 @@ var ShareRecipientClient = class {
4623
4638
  if (this.options.createKVService !== void 0) {
4624
4639
  return this.options.createKVService({ hosts: [origin], session, invoke, fetch: this.fetchFn });
4625
4640
  }
4626
- const context = new import_sdk_services2.ServiceContext({ hosts: [origin], session, invoke, fetch: this.fetchFn });
4627
- const service = new import_sdk_services2.KVService({ prefix: "" });
4641
+ const context = new import_sdk_services3.ServiceContext({ hosts: [origin], session, invoke, fetch: this.fetchFn });
4642
+ const service = new import_sdk_services3.KVService({ prefix: "" });
4628
4643
  context.registerService("kv", service);
4629
4644
  service.initialize(context);
4630
4645
  return service;