@tinycloud/share-sdk 1.4.3 → 1.4.4-beta.1

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/index.cjs CHANGED
@@ -55,6 +55,7 @@ __export(src_exports, {
55
55
  SharePublishError: () => SharePublishError,
56
56
  ShareReceiveError: () => ShareReceiveError,
57
57
  ShareRecipientClient: () => ShareRecipientClient,
58
+ ShareRevocationIncompleteError: () => ShareRevocationIncompleteError,
58
59
  addressedCredentialRequirement: () => addressedCredentialRequirement,
59
60
  addressedShareBodyUpperBound: () => addressedShareBodyUpperBound,
60
61
  artifactBindingView: () => artifactBindingView,
@@ -8918,6 +8919,14 @@ async function deliverCredentialInvitation(input) {
8918
8919
  }
8919
8920
 
8920
8921
  // src/lifecycle.ts
8922
+ var ShareRevocationIncompleteError = class extends Error {
8923
+ constructor(revoked, failed) {
8924
+ super(`share revocation incomplete: ${failed.map((failure) => failure.targetRole).join(", ")} not revoked`);
8925
+ this.revoked = revoked;
8926
+ this.failed = failed;
8927
+ this.name = "ShareRevocationIncompleteError";
8928
+ }
8929
+ };
8921
8930
  function targetKind2(record) {
8922
8931
  if (record.targetKind !== void 0) return record.targetKind;
8923
8932
  return record.recipientMatcher.kind === "exactEmail" ? "email" : record.recipientMatcher.kind === "emailDomain" ? "emailDomain" : record.recipientMatcher.kind === "recipientDid" ? "recipientDid" : "bearer";
@@ -8933,22 +8942,49 @@ function policyNodeAudience(record) {
8933
8942
  async function revokeShare(input) {
8934
8943
  const target = targetKind2(input.record);
8935
8944
  if (input.adapter === void 0) return { state: "unsupported", target, reason: "node revocation authority is required", code: "unsupported-target" };
8936
- const scope = input.scope ?? "direct";
8937
- const delegationCid = scope === "ancestor" ? input.record.ownerDelegationCid : input.record.enforcementDelegationCid;
8938
- if (delegationCid === void 0) return { state: "unsupported", target, reason: "share has no node-enforced delegation receipt", code: "unsupported-target" };
8945
+ let delegationCid;
8946
+ let roots;
8939
8947
  if (target === "bearer") {
8948
+ const scope = input.scope ?? "direct";
8949
+ const selected = scope === "ancestor" ? input.record.ownerDelegationCid : input.record.enforcementDelegationCid;
8950
+ if (selected === void 0) return { state: "unsupported", target, reason: "share has no node-enforced delegation receipt", code: "unsupported-target" };
8940
8951
  if (input.adapter.revokeDelegation === void 0) return { state: "unsupported", target, reason: "native delegation revocation authority is required", code: "unsupported-target" };
8941
- await input.adapter.revokeDelegation({ delegationCid, scope, record: input.record });
8952
+ await input.adapter.revokeDelegation({ delegationCid: selected, scope, record: input.record });
8953
+ delegationCid = selected;
8942
8954
  } else {
8943
- if (input.record.ownerDid === void 0) return { state: "unsupported", target, reason: "share has no Policy/v3 owner receipt", code: "unsupported-target" };
8944
- if (input.adapter.revokePolicyRoot === void 0) return { state: "unsupported", target, reason: "Policy/v3 root revocation authority is required", code: "unsupported-target" };
8945
- await input.adapter.revokePolicyRoot({
8946
- rootCid: delegationCid,
8947
- targetRole: scope === "ancestor" ? "policy-authority" : "policy-enforcement",
8948
- ownerDid: input.record.ownerDid,
8949
- nodeOrigin: input.record.target.origin,
8950
- nodeAudience: policyNodeAudience(input.record)
8951
- });
8955
+ const requests = [
8956
+ [input.record.enforcementDelegationCid, "policy-enforcement"],
8957
+ [input.record.ownerDelegationCid, "policy-authority"]
8958
+ ].flatMap(([rootCid, targetRole]) => rootCid === void 0 ? [] : [{ rootCid, targetRole }]);
8959
+ const first = requests[0];
8960
+ if (first === void 0) return { state: "unsupported", target, reason: "share has no node-enforced delegation receipt", code: "unsupported-target" };
8961
+ const ownerDid = input.record.ownerDid;
8962
+ if (ownerDid === void 0) return { state: "unsupported", target, reason: "share has no Policy/v3 owner receipt", code: "unsupported-target" };
8963
+ const revokePolicyRoot = input.adapter.revokePolicyRoot;
8964
+ if (revokePolicyRoot === void 0) return { state: "unsupported", target, reason: "Policy/v3 root revocation authority is required", code: "unsupported-target" };
8965
+ const nodeAudience = policyNodeAudience(input.record);
8966
+ roots = [];
8967
+ const failed = [];
8968
+ for (const request of requests) {
8969
+ try {
8970
+ const outcome = await revokePolicyRoot({ ...request, ownerDid, nodeOrigin: input.record.target.origin, nodeAudience });
8971
+ if (outcome === "left-live") {
8972
+ if (request.targetRole !== "policy-authority") throw new Error("the enforcement root cannot be left live");
8973
+ roots.push({ rootCid: request.rootCid, targetRole: "policy-authority", state: "left-live", expiresAt: input.record.expiresAt });
8974
+ } else if (outcome === void 0) {
8975
+ roots.push({ ...request, state: "revoked" });
8976
+ } else {
8977
+ throw new Error("root revocation returned an unknown outcome");
8978
+ }
8979
+ } catch (error) {
8980
+ failed.push({ ...request, error });
8981
+ }
8982
+ }
8983
+ const revoked = roots.flatMap((root) => root.state === "revoked" ? [root.rootCid] : []);
8984
+ if (failed.length > 0 || revoked.length === 0) {
8985
+ throw new ShareRevocationIncompleteError(revoked, failed.length > 0 ? failed : roots.map((root) => ({ rootCid: root.rootCid, targetRole: root.targetRole, error: new Error("no root was revoked") })));
8986
+ }
8987
+ delegationCid = first.rootCid;
8952
8988
  }
8953
8989
  let revokedAt = input.record.revokedAt ?? (input.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
8954
8990
  if (input.records?.update !== void 0) {
@@ -8959,7 +8995,7 @@ async function revokeShare(input) {
8959
8995
  revokedAt = latest?.revokedAt ?? revokedAt;
8960
8996
  await input.records.put({ ...latest ?? input.record, revokedAt });
8961
8997
  }
8962
- return { state: "revoked", target, delegationCid, revokedAt };
8998
+ return { state: "revoked", target, delegationCid, ...roots === void 0 ? {} : { roots }, revokedAt };
8963
8999
  }
8964
9000
  function redactRecord(record, revealLink, link) {
8965
9001
  const matcher = record.recipientMatcher;
@@ -9549,6 +9585,7 @@ async function openNativeShare(sharing, link) {
9549
9585
  SharePublishError,
9550
9586
  ShareReceiveError,
9551
9587
  ShareRecipientClient,
9588
+ ShareRevocationIncompleteError,
9552
9589
  addressedCredentialRequirement,
9553
9590
  addressedShareBodyUpperBound,
9554
9591
  artifactBindingView,