@tinycloud/share-sdk 1.0.0-beta.4 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -6099,6 +6099,7 @@ function redactPublishedShare(result) {
6099
6099
  target: { ...result.metadata.target },
6100
6100
  resource: { ...result.metadata.resource },
6101
6101
  actions: [...result.metadata.actions],
6102
+ ...result.metadata.expiryClamped === void 0 ? {} : { expiryClamped: result.metadata.expiryClamped },
6102
6103
  expiresAt: result.metadata.expiresAt,
6103
6104
  display: { ...result.metadata.display }
6104
6105
  }
@@ -6611,6 +6612,7 @@ async function publishTargetShare(input) {
6611
6612
  ...input.actions === void 0 ? {} : { actions: input.actions },
6612
6613
  target,
6613
6614
  expiresAt,
6615
+ expiryWasExplicit: input.expiryWasExplicit ?? input.expiresAt !== void 0,
6614
6616
  origin: input.origin,
6615
6617
  ...input.notify === void 0 ? {} : { notify: input.notify }
6616
6618
  });
@@ -6729,10 +6731,23 @@ function publicationResult(input) {
6729
6731
  Object.defineProperty(result, "deliveryMaterial", { enumerable: false, value: input.deliveryMaterial });
6730
6732
  return result;
6731
6733
  }
6734
+ var EMAIL_DOMAIN_PROFILE = { id: "tinycloud.email-domain-proof/v1", version: 1 };
6735
+ var EMAIL_CREDENTIAL_TYPE = { id: "opencredentials.email/v1", version: 1 };
6736
+ var EMAIL_DOMAIN_DESCRIPTOR_DIGEST = "33X5mAkZZgApdD3xh_T-3KS5moop0J2Nloi2nqWsdWY";
6737
+ function assertEmailDomainPolicy(options, domain) {
6738
+ if (!options.actions.every((action) => action === "read" || action === "list") || !options.policyActions.every((action) => action === "tinycloud.kv/get" || action === "tinycloud.kv/list" || action === "tinycloud.kv/metadata")) throw new TypeError("email-domain shares are view-only");
6739
+ if (options.deliveryEmail !== void 0) throw new TypeError("email-domain shares are not emailed");
6740
+ const commitment = options.credentialRequirement;
6741
+ if (commitment === void 0) throw new TypeError("email-domain shares require a credential requirement");
6742
+ if (canonicalize(commitment.profile) !== canonicalize(EMAIL_DOMAIN_PROFILE) || canonicalize(commitment.credentialType) !== canonicalize(EMAIL_CREDENTIAL_TYPE) || commitment.descriptorDigest !== EMAIL_DOMAIN_DESCRIPTOR_DIGEST) throw new TypeError("email-domain shares require the email-domain credential profile");
6743
+ const expected = { type: "TinyCloudCredentialRequirement", version: 1, profile: EMAIL_DOMAIN_PROFILE, credentialType: EMAIL_CREDENTIAL_TYPE, claims: { emailDomain: domain }, maxAgeSeconds: 300 };
6744
+ if (toBase64Url((0, import_sha2562.sha256)(textEncoder.encode(canonicalize(expected)))) !== commitment.requirementDigest) throw new TypeError("credential requirement is not bound to the email domain");
6745
+ }
6732
6746
  async function publishAddressedShare(options) {
6733
6747
  assertSafeInput(options);
6734
6748
  const target = normalizeShareTarget(options.target);
6735
6749
  if (target.kind === "bearer") throw new TypeError("addressed target is required");
6750
+ if (target.kind === "emailDomain") assertEmailDomainPolicy(options, target.domain);
6736
6751
  const expiry = rfc3339Seconds(options.expiresAt);
6737
6752
  const matcher = targetMatcher(target);
6738
6753
  const capabilities = sortCanonical([
@@ -8545,7 +8560,11 @@ function canonicalViewerUrl(viewerOrigin) {
8545
8560
  async function createNativeShare(sharing, input) {
8546
8561
  if (!input.path || input.path.startsWith("/") || input.path.endsWith("/") || input.path.includes("..") || input.path.includes("//")) throw new TypeError("native share path must be one canonical TinyCloud KV key");
8547
8562
  const generated = await sharing.generate({ path: input.path, actions: ["tinycloud.kv/get"], expiry: input.expiresAt });
8548
- if (generated.ok !== true) throw new Error(typeof generated.error?.message === "string" ? generated.error.message : "TinyCloud sharing service rejected delegation generation");
8563
+ if (generated.ok !== true) {
8564
+ const error = new Error(typeof generated.error?.message === "string" ? generated.error.message : "TinyCloud sharing service rejected delegation generation");
8565
+ if (typeof generated.error?.code === "string") Object.assign(error, { code: generated.error.code });
8566
+ throw error;
8567
+ }
8549
8568
  if (typeof generated.data?.token !== "string" || typeof generated.data.delegation?.cid !== "string" || !(generated.data.expiresAt instanceof Date)) throw new Error("TinyCloud sharing service returned incomplete delegation metadata");
8550
8569
  const delegation = sharing.decodeLink(generated.data.token);
8551
8570
  if (typeof delegation.spaceId !== "string" || delegation.spaceId.length === 0 || typeof delegation.path !== "string" || delegation.path.length === 0) throw new Error("TinyCloud sharing service returned a non-canonical delegation authority");