@tinycloud/sdk-core 3.2.6-beta.4 → 3.3.0-beta.10

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.
@@ -439,6 +439,8 @@ var DelegationManagerConfigSchema = import_zod.z.object({
439
439
  (val) => val === void 0 || typeof val === "function",
440
440
  { message: "Expected an invokeAny function or undefined" }
441
441
  ).optional(),
442
+ /** Optional owner-signed authorization for direct CID revocation */
443
+ signOwnerRevocation: import_zod.z.custom().optional(),
442
444
  /** Optional custom fetch implementation */
443
445
  fetch: import_zod.z.unknown().refine(
444
446
  (val) => val === void 0 || typeof val === "function",
@@ -578,6 +580,7 @@ var DelegationManager = class {
578
580
  this.session = config.session;
579
581
  this.invoke = config.invoke;
580
582
  this.invokeAny = config.invokeAny;
583
+ this.signOwnerRevocation = config.signOwnerRevocation;
581
584
  this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
582
585
  this.accountSpaceId = config.accountSpaceId;
583
586
  }
@@ -720,6 +723,9 @@ var DelegationManager = class {
720
723
  * Once revoked, the delegation can no longer be used to access resources.
721
724
  * This also invalidates any sub-delegations derived from this delegation.
722
725
  *
726
+ * Explicit target-space or authority options keep the delegated session
727
+ * signing path even when an owner signer is available.
728
+ *
723
729
  * @param cid - The CID of the delegation to revoke
724
730
  * @returns Result indicating success or an error
725
731
  *
@@ -742,29 +748,35 @@ var DelegationManager = class {
742
748
  };
743
749
  }
744
750
  try {
745
- if (!this.invokeAny) {
751
+ const ownerSigner = options?.targetSpaceId === void 0 && options?.authorityCid === void 0 ? this.signOwnerRevocation : void 0;
752
+ if (!ownerSigner && !this.invokeAny) {
746
753
  return {
747
754
  ok: false,
748
755
  error: createError(
749
756
  DelegationErrorCodes.NOT_INITIALIZED,
750
- "Revocation requires an invokeAny function that can sign the target CID"
757
+ "Revocation requires an owner signer or invokeAny function that can sign the target CID"
751
758
  )
752
759
  };
753
760
  }
754
- const entry = {
755
- resource: `urn:cid:${cid2}`,
756
- ...options?.targetSpaceId === void 0 ? {} : { spaceId: options.targetSpaceId },
757
- service: "delegation",
758
- path: "",
759
- action: DelegationAction.REVOKE
760
- };
761
- if (options?.authorityCid !== void 0) {
762
- Object.defineProperty(entry, "revokeAuthorityCid", {
763
- value: options.authorityCid,
764
- enumerable: false
765
- });
761
+ let headers;
762
+ if (ownerSigner) {
763
+ headers = { Authorization: await ownerSigner(cid2) };
764
+ } else {
765
+ const entry = {
766
+ resource: `urn:cid:${cid2}`,
767
+ ...options?.targetSpaceId === void 0 ? {} : { spaceId: options.targetSpaceId },
768
+ service: "delegation",
769
+ path: "",
770
+ action: DelegationAction.REVOKE
771
+ };
772
+ if (options?.authorityCid !== void 0) {
773
+ Object.defineProperty(entry, "revokeAuthorityCid", {
774
+ value: options.authorityCid,
775
+ enumerable: false
776
+ });
777
+ }
778
+ headers = this.invokeAny(this.session, [entry]);
766
779
  }
767
- const headers = this.invokeAny(this.session, [entry]);
768
780
  const response = await this.fetchFn(`${this.host}/revoke`, {
769
781
  method: "POST",
770
782
  headers
@@ -4324,7 +4336,9 @@ function redactedCode(error) {
4324
4336
  if (error instanceof ShareConflict) return error.code;
4325
4337
  const code3 = error && typeof error === "object" && "code" in error ? error.code : void 0;
4326
4338
  if (typeof code3 !== "string") return "SHARE_INVALID";
4327
- if (code3 === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || code3 === import_sdk_services3.ErrorCodes.KV_CONFLICT || code3 === "412") return "SHARE_CONFLICT";
4339
+ if (code3 === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || code3 === "412") return "SHARE_CONFLICT";
4340
+ if (code3 === import_sdk_services3.ErrorCodes.NODE_BUSY || code3 === import_sdk_services3.ErrorCodes.REQUEST_TIMEOUT) return "SHARE_OFFLINE";
4341
+ if (code3 === import_sdk_services3.ErrorCodes.OUTCOME_UNKNOWN) return "SHARE_WRITE_FAILED";
4328
4342
  if (code3 === "KV_NOT_FOUND" || code3 === "NOT_FOUND" || code3 === "404") return "SHARE_NOT_FOUND";
4329
4343
  if (code3.includes("EXPIRED") || code3 === "expired") return "SHARE_EXPIRED";
4330
4344
  if (code3.includes("REVOK")) return "SHARE_REVOKED";
@@ -4563,7 +4577,7 @@ var ShareRecipientClient = class {
4563
4577
  if (portableDelegation !== void 0 && kv !== void 0) {
4564
4578
  const result2 = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
4565
4579
  if (!result2.ok) {
4566
- 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);
4580
+ if (result2.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
4567
4581
  throw result2.error;
4568
4582
  }
4569
4583
  return { etag: result2.data.headers.etag };
@@ -4571,7 +4585,7 @@ var ShareRecipientClient = class {
4571
4585
  if (policySession !== void 0) return this.nativeSave(envelope, policySession, resolvedPath, bytes2, input);
4572
4586
  const result = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
4573
4587
  if (!result.ok) {
4574
- 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);
4588
+ if (result.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
4575
4589
  throw result.error;
4576
4590
  }
4577
4591
  return { etag: result.data.headers.etag };