@tinycloud/node-sdk 3.2.0-beta.1 → 3.2.0-beta.2

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.
@@ -886,7 +886,7 @@ interface VerifiedSessionGrant {
886
886
  * delegation for. The error message is for the caller and may quote
887
887
  * transport fields or a node's response; the reason is safe to publish.
888
888
  */
889
- declare const RUNTIME_DELEGATION_REJECTIONS: readonly ["host_mismatch", "expired", "cid_mismatch", "authority_invalid", "proof_missing", "proof_invalid", "owner_mismatch", "audience_mismatch", "resources_mismatch", "unsupported", "activation_rejected"];
889
+ declare const RUNTIME_DELEGATION_REJECTIONS: readonly ["host_mismatch", "expired", "cid_mismatch", "authority_invalid", "proof_missing", "proof_invalid", "owner_mismatch", "audience_mismatch", "resources_mismatch", "unsupported", "activation_rejected", "activation_unavailable", "activation_unauthenticated"];
890
890
  type RuntimeDelegationRejection = typeof RUNTIME_DELEGATION_REJECTIONS[number];
891
891
  declare class RuntimeDelegationRejectedError extends Error {
892
892
  readonly reason: RuntimeDelegationRejection;
@@ -886,7 +886,7 @@ interface VerifiedSessionGrant {
886
886
  * delegation for. The error message is for the caller and may quote
887
887
  * transport fields or a node's response; the reason is safe to publish.
888
888
  */
889
- declare const RUNTIME_DELEGATION_REJECTIONS: readonly ["host_mismatch", "expired", "cid_mismatch", "authority_invalid", "proof_missing", "proof_invalid", "owner_mismatch", "audience_mismatch", "resources_mismatch", "unsupported", "activation_rejected"];
889
+ declare const RUNTIME_DELEGATION_REJECTIONS: readonly ["host_mismatch", "expired", "cid_mismatch", "authority_invalid", "proof_missing", "proof_invalid", "owner_mismatch", "audience_mismatch", "resources_mismatch", "unsupported", "activation_rejected", "activation_unavailable", "activation_unauthenticated"];
890
890
  type RuntimeDelegationRejection = typeof RUNTIME_DELEGATION_REJECTIONS[number];
891
891
  declare class RuntimeDelegationRejectedError extends Error {
892
892
  readonly reason: RuntimeDelegationRejection;
package/dist/core.cjs CHANGED
@@ -1761,6 +1761,18 @@ var RuntimeDelegationRejectedError = class extends Error {
1761
1761
  this.reason = reason;
1762
1762
  }
1763
1763
  };
1764
+ function activationRejectionReason(error) {
1765
+ if (typeof error !== "object" || error === null) return "activation_rejected";
1766
+ if ("code" in error && error.code === "ACTIVATION_TRANSPORT_FAILED") {
1767
+ return "activation_unavailable";
1768
+ }
1769
+ const cause = "cause" in error ? error.cause : void 0;
1770
+ const status = typeof cause === "object" && cause !== null && "status" in cause ? cause.status : void 0;
1771
+ if (typeof status !== "number") return "activation_rejected";
1772
+ if (status === 408 || status === 429 || status >= 500) return "activation_unavailable";
1773
+ if (status === 401) return "activation_unauthenticated";
1774
+ return "activation_rejected";
1775
+ }
1764
1776
  function reject(reason, message) {
1765
1777
  throw new RuntimeDelegationRejectedError(reason, message);
1766
1778
  }
@@ -2145,7 +2157,10 @@ async function activateValidatedRuntimeDelegation(node, delegation, options) {
2145
2157
  await node.useRuntimeDelegation(installedCandidate);
2146
2158
  }
2147
2159
  } catch (error) {
2148
- reject("activation_rejected", error instanceof Error ? error.message : String(error));
2160
+ reject(
2161
+ activationRejectionReason(error),
2162
+ error instanceof Error ? error.message : String(error)
2163
+ );
2149
2164
  }
2150
2165
  const installed = node.getRuntimePermissionDelegations().find((candidate) => candidate.cid === cid);
2151
2166
  if (!installed) {
@@ -6419,10 +6434,18 @@ var _TinyCloudNode = class _TinyCloudNode {
6419
6434
  );
6420
6435
  }
6421
6436
  const targetHost = delegation.host ?? this.config.host;
6422
- const activateResult = await (0, import_sdk_core9.activateSessionWithHost)(
6423
- targetHost,
6424
- delegation.delegationHeader
6425
- );
6437
+ let activateResult;
6438
+ try {
6439
+ activateResult = await (0, import_sdk_core9.activateSessionWithHost)(
6440
+ targetHost,
6441
+ delegation.delegationHeader
6442
+ );
6443
+ } catch (cause) {
6444
+ throw Object.assign(
6445
+ new Error("The TinyCloud host could not be reached to activate the delegation."),
6446
+ { code: "ACTIVATION_TRANSPORT_FAILED", cause }
6447
+ );
6448
+ }
6426
6449
  if (!activateResult.success) {
6427
6450
  if (this.operationsFromDelegation(delegation).some(
6428
6451
  (operation) => operation.resource?.startsWith("urn:cid:") === true && operation.service === "delegation" && operation.action === "tinycloud.delegation/revoke"