@tinycloud/sdk-core 3.0.0-beta.13 → 3.0.0-beta.15

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
@@ -127,6 +127,7 @@ __export(index_exports, {
127
127
  LOCAL_LINK_PROBE_TIMEOUT_MS: () => LOCAL_LINK_PROBE_TIMEOUT_MS,
128
128
  LOCAL_LOOPBACK_PROBE_TIMEOUT_MS: () => LOCAL_LOOPBACK_PROBE_TIMEOUT_MS,
129
129
  LocationRecordValidationError: () => LocationRecordValidationError,
130
+ LocationRegistryHttpError: () => LocationRegistryHttpError,
130
131
  MAX_CONTENT_BYTES: () => MAX_CONTENT_BYTES,
131
132
  MAX_LEGACY_ENVELOPE_EXPIRES_AT: () => MAX_LEGACY_ENVELOPE_EXPIRES_AT,
132
133
  MAX_SEALED_SHARE_CONTENT_BYTES: () => MAX_SEALED_SHARE_CONTENT_BYTES,
@@ -246,10 +247,10 @@ __export(index_exports, {
246
247
  buildPolicyCredentialPresentationV4: () => buildPolicyCredentialPresentationV4,
247
248
  buildSpaceUri: () => buildSpaceUri,
248
249
  canonicalDigest: () => canonicalDigest,
249
- canonicalEmailDomain: () => canonicalEmailDomain,
250
+ canonicalEmailDomain: () => import_share_envelope.canonicalEmailDomain,
250
251
  canonicalHashHex: () => import_sdk_services8.canonicalHashHex,
251
252
  canonicalLocationPayload: () => canonicalLocationPayload,
252
- canonicalMailbox: () => canonicalMailbox,
253
+ canonicalMailbox: () => import_share_envelope.canonicalMailbox,
253
254
  canonicalOwnerSharePolicy: () => canonicalOwnerSharePolicy,
254
255
  canonicalSignedResponse: () => import_sdk_services8.canonicalSignedResponse,
255
256
  canonicalizeAddress: () => canonicalizeAddress,
@@ -350,7 +351,7 @@ __export(index_exports, {
350
351
  importPortableDelegation: () => importPortableDelegation,
351
352
  installTinyCloudDebugGlobals: () => import_sdk_services8.installTinyCloudDebugGlobals,
352
353
  intersectShareCapabilities: () => intersectShareCapabilities,
353
- isCanonicalEmailDomain: () => isCanonicalEmailDomain,
354
+ isCanonicalEmailDomain: () => import_share_envelope.isCanonicalEmailDomain,
354
355
  isCapabilitySubset: () => isCapabilitySubset,
355
356
  isDigest: () => isDigest,
356
357
  isEvmAddress: () => isEvmAddress,
@@ -361,7 +362,7 @@ __export(index_exports, {
361
362
  jcsCanonicalize: () => jcsCanonicalize,
362
363
  loadManifest: () => loadManifest,
363
364
  locationPayloadForRecord: () => locationPayloadForRecord,
364
- mailboxBelongsToDomain: () => mailboxBelongsToDomain,
365
+ mailboxBelongsToDomain: () => import_share_envelope.mailboxBelongsToDomain,
365
366
  makePkhSpaceId: () => makePkhSpaceId,
366
367
  makePublicSpaceId: () => makePublicSpaceId,
367
368
  manifestAbilitiesUnion: () => manifestAbilitiesUnion,
@@ -1030,29 +1031,7 @@ function isDigest(value) {
1030
1031
  }
1031
1032
 
1032
1033
  // src/credentials/email-domain.ts
1033
- var LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
1034
- function isCanonicalEmailDomain(value) {
1035
- if (value.length === 0 || value.length > 253) return false;
1036
- const labels = value.split(".");
1037
- return labels.length >= 2 && labels.every((label) => LABEL.test(label)) && !/^[0-9]+$/.test(labels.at(-1));
1038
- }
1039
- function canonicalEmailDomain(value) {
1040
- const domain = value.trim().replace(/^@/, "").toLowerCase();
1041
- if (!/^[\x21-\x7e]+$/.test(domain) || !isCanonicalEmailDomain(domain)) throw new TypeError("email domain must be lowercase ASCII DNS labels (use the xn-- form for international domains)");
1042
- return domain;
1043
- }
1044
- function canonicalMailbox(value) {
1045
- const email = value.trim().toLowerCase();
1046
- const at = email.indexOf("@");
1047
- if (at <= 0 || at !== email.lastIndexOf("@")) return void 0;
1048
- const local = email.slice(0, at);
1049
- const domain = email.slice(at + 1);
1050
- if (local.length > 64 || !/^[a-z0-9#$&'*+/=?^_`{|}~-]+(?:\.[a-z0-9#$&'*+/=?^_`{|}~-]+)*$/.test(local) || !isCanonicalEmailDomain(domain)) return void 0;
1051
- return Object.freeze({ email, domain });
1052
- }
1053
- function mailboxBelongsToDomain(mailbox, domain) {
1054
- return canonicalMailbox(mailbox)?.domain === domain && isCanonicalEmailDomain(domain);
1055
- }
1034
+ var import_share_envelope = require("@tinycloud/share-envelope");
1056
1035
 
1057
1036
  // src/credentials/requirement.ts
1058
1037
  var ID2 = /^[a-z0-9][a-z0-9._-]{0,127}(?:\/v1)?$/;
@@ -1070,7 +1049,7 @@ function createEmailCredentialRequirement(input) {
1070
1049
  });
1071
1050
  }
1072
1051
  function createEmailDomainCredentialRequirement(input) {
1073
- if (!isCanonicalEmailDomain(input.domain)) throw new CredentialError("UNSUPPORTED_PROFILE", "Email domain is not canonical");
1052
+ if (!(0, import_share_envelope.isCanonicalEmailDomain)(input.domain)) throw new CredentialError("UNSUPPORTED_PROFILE", "Email domain is not canonical");
1074
1053
  return validateCredentialRequirement({
1075
1054
  type: "TinyCloudCredentialRequirement",
1076
1055
  version: 1,
@@ -6546,6 +6525,7 @@ var DelegationErrorSchema = import_zod4.z.object({
6546
6525
  });
6547
6526
  var DelegationErrorCodes = {
6548
6527
  AUTH_REQUIRED: "AUTH_REQUIRED",
6528
+ AUTH_UNAUTHORIZED: "AUTH_UNAUTHORIZED",
6549
6529
  AUTH_EXPIRED: "AUTH_EXPIRED",
6550
6530
  NOT_INITIALIZED: "NOT_INITIALIZED",
6551
6531
  NOT_FOUND: "NOT_FOUND",
@@ -10928,6 +10908,13 @@ var ShareRecipientClient = class {
10928
10908
  };
10929
10909
 
10930
10910
  // src/delegations/SharingService.ts
10911
+ function spaceIdsEqual(left, right) {
10912
+ const normalizeOwnerAddress = (space) => {
10913
+ const match = /^(tinycloud:pkh:eip155:\d+:)(0x[0-9a-fA-F]{40})(:.+)$/.exec(space);
10914
+ return match === null ? space : `${match[1]}${match[2].toLowerCase()}${match[3]}`;
10915
+ };
10916
+ return normalizeOwnerAddress(left) === normalizeOwnerAddress(right);
10917
+ }
10931
10918
  function inferShortServiceFromActionUrns(actions) {
10932
10919
  let short;
10933
10920
  for (const action of actions) {
@@ -11250,7 +11237,7 @@ var SharingService = class {
11250
11237
  for (const key of allKeys) {
11251
11238
  const delegations = this.registry.getDelegationsForKey(key.id);
11252
11239
  for (const delegation of delegations) {
11253
- if (delegation.spaceId !== this.session?.spaceId) {
11240
+ if (delegation.spaceId === void 0 || !spaceIdsEqual(delegation.spaceId, this.session?.spaceId ?? "")) {
11254
11241
  continue;
11255
11242
  }
11256
11243
  if ((delegation.caveats?.length ?? 0) > 0) {
@@ -11378,11 +11365,23 @@ var SharingService = class {
11378
11365
  const errorText = await registerRes.text();
11379
11366
  const registrationTextActiveError = this.retiredGraphError();
11380
11367
  if (registrationTextActiveError) return { ok: false, error: registrationTextActiveError };
11368
+ const message = `Failed to register delegation with server: ${registerRes.status} ${errorText}`;
11369
+ if (registerRes.status === 401 || registerRes.status === 403) {
11370
+ return {
11371
+ ok: false,
11372
+ error: createError2(
11373
+ DelegationErrorCodes.AUTH_UNAUTHORIZED,
11374
+ message,
11375
+ void 0,
11376
+ { status: registerRes.status }
11377
+ )
11378
+ };
11379
+ }
11381
11380
  return {
11382
11381
  ok: false,
11383
11382
  error: createError2(
11384
11383
  DelegationErrorCodes.CREATION_FAILED,
11385
- `Failed to register delegation with server: ${registerRes.status} ${errorText}`
11384
+ message
11386
11385
  )
11387
11386
  };
11388
11387
  }
@@ -17982,6 +17981,13 @@ var LocationRecordValidationError = class extends Error {
17982
17981
  this.name = "LocationRecordValidationError";
17983
17982
  }
17984
17983
  };
17984
+ var LocationRegistryHttpError = class extends Error {
17985
+ constructor(message, status) {
17986
+ super(message);
17987
+ this.status = status;
17988
+ this.name = "LocationRegistryHttpError";
17989
+ }
17990
+ };
17985
17991
  var CloudLocationResolutionError = class extends Error {
17986
17992
  constructor(subject, attempts) {
17987
17993
  super(`Unable to resolve TinyCloud location for ${subject}`);
@@ -18075,7 +18081,7 @@ async function fetchLocationRecord(registryUrl, subject, fetchFn = globalThis.fe
18075
18081
  return null;
18076
18082
  }
18077
18083
  if (!response.ok) {
18078
- throw new Error(`location registry returned HTTP ${response.status}`);
18084
+ throw new LocationRegistryHttpError(`location registry returned HTTP ${response.status}`, response.status);
18079
18085
  }
18080
18086
  const text2 = await boundedResponseText(response, "location registry", 64 * 1024);
18081
18087
  let body;
@@ -18120,7 +18126,7 @@ async function publishLocationRecord(options2) {
18120
18126
  }
18121
18127
  );
18122
18128
  if (!response.ok) {
18123
- throw new Error(`location registry publish returned HTTP ${response.status}`);
18129
+ throw new LocationRegistryHttpError(`location registry publish returned HTTP ${response.status}`, response.status);
18124
18130
  }
18125
18131
  const text2 = await boundedResponseText(response, "location registry", 64 * 1024);
18126
18132
  let body;