@tinycloud/operations 0.7.0-beta.33 → 0.7.0-beta.35

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.
@@ -1,4 +1,4 @@
1
- import { I as InvocationTarget, a as OperationResult } from './contract-zRklonbR.cjs';
1
+ import { I as InvocationTarget, a as OperationResult } from './contract-DrtFhVsg.cjs';
2
2
 
3
3
  /**
4
4
  * The only published CLI acquisition helper. Its fixed operation identity is
@@ -1,4 +1,4 @@
1
- import { I as InvocationTarget, a as OperationResult } from './contract-zRklonbR.js';
1
+ import { I as InvocationTarget, a as OperationResult } from './contract-DrtFhVsg.js';
2
2
 
3
3
  /**
4
4
  * The only published CLI acquisition helper. Its fixed operation identity is
@@ -5668,6 +5668,34 @@ var init_artifacts = __esm({
5668
5668
  }
5669
5669
  });
5670
5670
 
5671
+ // src/contract.ts
5672
+ var STORED_GRANT_SKIP_REASONS, DELEGATION_CID_PATTERN;
5673
+ var init_contract = __esm({
5674
+ "src/contract.ts"() {
5675
+ "use strict";
5676
+ STORED_GRANT_SKIP_REASONS = [
5677
+ "malformed",
5678
+ "unbound",
5679
+ "outside_request",
5680
+ "host_mismatch",
5681
+ "expired",
5682
+ "cid_mismatch",
5683
+ "authority_invalid",
5684
+ "proof_missing",
5685
+ "proof_invalid",
5686
+ "owner_mismatch",
5687
+ "audience_mismatch",
5688
+ "resources_mismatch",
5689
+ "unsupported",
5690
+ "activation_rejected",
5691
+ "activation_unavailable",
5692
+ "activation_unauthenticated",
5693
+ "invalid"
5694
+ ];
5695
+ DELEGATION_CID_PATTERN = "^bafkr4i[a-z2-7]{52}$";
5696
+ }
5697
+ });
5698
+
5671
5699
  // src/recovery.ts
5672
5700
  function signInRecovery(profile, posture) {
5673
5701
  if (!SAFE_PROFILE_TOKEN.test(profile)) return { action: "sign_in" };
@@ -5889,6 +5917,26 @@ var init_revoked_grant = __esm({
5889
5917
 
5890
5918
  // src/kv-failure.ts
5891
5919
  import { authorizationVerdictOf as authorizationVerdictOf2, validatedCapabilityOf } from "@tinycloud/sdk-services";
5920
+ function nodeRevocationOf(error) {
5921
+ if (typeof error !== "object" || error === null || !("service" in error) || error.service !== "kv" || !("code" in error) || error.code !== "AUTH_UNAUTHORIZED" && error.code !== "AUTH_DELEGATION_REVOKED" && error.code !== "AUTH_DELEGATION_ANCESTOR_REVOKED" || !("message" in error) || typeof error.message !== "string" || !("meta" in error) || typeof error.meta !== "object" || error.meta === null || !("status" in error.meta) || error.meta.status !== 401 || authorizationVerdictOf2(error) !== "unauthenticated") return void 0;
5922
+ const { code, message } = error;
5923
+ const separator = ": 401 - ";
5924
+ const start = message.indexOf(separator);
5925
+ if (start < 0) return void 0;
5926
+ const body = message.slice(start + separator.length);
5927
+ const match = NODE_REVOCATION_BODY.exec(body);
5928
+ if (match === null || match[0] !== body) return void 0;
5929
+ if (match[1] !== void 0 && code !== "AUTH_DELEGATION_ANCESTOR_REVOKED") {
5930
+ const revokedCid = match[2];
5931
+ return DELEGATION_CID2.test(revokedCid) ? { reason: "delegation_revoked", revokedCid } : void 0;
5932
+ }
5933
+ if (match[3] !== void 0 && code !== "AUTH_DELEGATION_REVOKED") {
5934
+ const ancestorCid = match[4];
5935
+ const revokedCid = match[5];
5936
+ return DELEGATION_CID2.test(ancestorCid) && DELEGATION_CID2.test(revokedCid) ? { reason: "delegation_ancestor_revoked", revokedCid, ancestorCid } : void 0;
5937
+ }
5938
+ return void 0;
5939
+ }
5892
5940
  function kvRefusal(error) {
5893
5941
  const verdict = authorizationVerdictOf2(error);
5894
5942
  if (verdict === "unauthenticated") {
@@ -5898,22 +5946,30 @@ function kvRefusal(error) {
5898
5946
  }
5899
5947
  function authorizationFailure(error, action) {
5900
5948
  switch (kvRefusal(error)) {
5901
- case "auth_required":
5902
- if (isRevokedGrantRefusal(error)) {
5903
- return { status: "error", error: operationError("AUTH_REQUIRED", REVOKED_GRANT_MESSAGE) };
5904
- }
5905
- return { status: "error", error: operationError("AUTH_REQUIRED", `Authentication is required to ${action}.`) };
5949
+ case "auth_required": {
5950
+ const revocation = nodeRevocationOf(error);
5951
+ return {
5952
+ status: "error",
5953
+ error: operationError("AUTH_REQUIRED", isRevokedGrantRefusal(error) ? REVOKED_GRANT_MESSAGE : `Authentication is required to ${action}.`, {
5954
+ ...revocation === void 0 ? {} : { details: revocation }
5955
+ })
5956
+ };
5957
+ }
5906
5958
  case "permission_denied":
5907
5959
  return { status: "error", error: operationError("PERMISSION_DENIED", `Permission is denied to ${action}.`) };
5908
5960
  case void 0:
5909
5961
  return void 0;
5910
5962
  }
5911
5963
  }
5964
+ var DELEGATION_CID2, NODE_REVOCATION_BODY;
5912
5965
  var init_kv_failure = __esm({
5913
5966
  "src/kv-failure.ts"() {
5914
5967
  "use strict";
5968
+ init_contract();
5915
5969
  init_errors2();
5916
5970
  init_revoked_grant();
5971
+ DELEGATION_CID2 = new RegExp(DELEGATION_CID_PATTERN);
5972
+ NODE_REVOCATION_BODY = /^(?:Invalid invocation: )?delegation-(?:(revoked): ([A-Za-z0-9]+)|(ancestor-revoked): ancestor=([A-Za-z0-9]+) invoked=([A-Za-z0-9]+))$/;
5917
5973
  }
5918
5974
  });
5919
5975
 
@@ -9500,34 +9556,6 @@ var init_secrets_status = __esm({
9500
9556
  }
9501
9557
  });
9502
9558
 
9503
- // src/contract.ts
9504
- var STORED_GRANT_SKIP_REASONS, DELEGATION_CID_PATTERN;
9505
- var init_contract = __esm({
9506
- "src/contract.ts"() {
9507
- "use strict";
9508
- STORED_GRANT_SKIP_REASONS = [
9509
- "malformed",
9510
- "unbound",
9511
- "outside_request",
9512
- "host_mismatch",
9513
- "expired",
9514
- "cid_mismatch",
9515
- "authority_invalid",
9516
- "proof_missing",
9517
- "proof_invalid",
9518
- "owner_mismatch",
9519
- "audience_mismatch",
9520
- "resources_mismatch",
9521
- "unsupported",
9522
- "activation_rejected",
9523
- "activation_unavailable",
9524
- "activation_unauthenticated",
9525
- "invalid"
9526
- ];
9527
- DELEGATION_CID_PATTERN = "^bafkr4i[a-z2-7]{52}$";
9528
- }
9529
- });
9530
-
9531
9559
  // src/delegation-binding.ts
9532
9560
  import { join as join3 } from "path";
9533
9561
  import * as nodeSdk5 from "@tinycloud/node-sdk";
@@ -9680,7 +9708,7 @@ function verifiedStoredCid(node, entry) {
9680
9708
  const cid = delegation?.cid;
9681
9709
  if (typeof cid !== "string" || typeof header?.Authorization !== "string" || typeof node.computeDelegationCid !== "function") return void 0;
9682
9710
  try {
9683
- return node.computeDelegationCid(header.Authorization) === cid && DELEGATION_CID.test(cid) ? cid : void 0;
9711
+ return node.computeDelegationCid(header.Authorization) === cid && DELEGATION_CID3.test(cid) ? cid : void 0;
9684
9712
  } catch {
9685
9713
  return void 0;
9686
9714
  }
@@ -9787,7 +9815,7 @@ function recordKey(entry) {
9787
9815
  function isRecord4(value) {
9788
9816
  return typeof value === "object" && value !== null && !Array.isArray(value);
9789
9817
  }
9790
- var REQUEST_ID_PREFIX, BINDING_NOTES, MIGRATION_LOCK_TIMEOUT_MS, NOT_REPLAYED, DELEGATION_CID;
9818
+ var REQUEST_ID_PREFIX, BINDING_NOTES, MIGRATION_LOCK_TIMEOUT_MS, NOT_REPLAYED, DELEGATION_CID3;
9791
9819
  var init_delegation_binding = __esm({
9792
9820
  "src/delegation-binding.ts"() {
9793
9821
  "use strict";
@@ -9810,7 +9838,7 @@ var init_delegation_binding = __esm({
9810
9838
  };
9811
9839
  MIGRATION_LOCK_TIMEOUT_MS = 250;
9812
9840
  NOT_REPLAYED = { status: "not-replayed" };
9813
- DELEGATION_CID = new RegExp(DELEGATION_CID_PATTERN);
9841
+ DELEGATION_CID3 = new RegExp(DELEGATION_CID_PATTERN);
9814
9842
  }
9815
9843
  });
9816
9844
 
@@ -10491,6 +10519,7 @@ import {
10491
10519
  } from "@tinycloud/node-sdk";
10492
10520
 
10493
10521
  // src/redaction.ts
10522
+ init_contract();
10494
10523
  init_recovery();
10495
10524
  import { RUNTIME_DELEGATION_REJECTIONS } from "@tinycloud/node-sdk";
10496
10525
 
@@ -10557,6 +10586,7 @@ function decodeBase58(value) {
10557
10586
  }
10558
10587
 
10559
10588
  // src/redaction.ts
10589
+ var DELEGATION_CID = new RegExp(DELEGATION_CID_PATTERN);
10560
10590
  function redactOperationError(_definition, error) {
10561
10591
  const details = error.details === void 0 ? void 0 : redactSafeErrorDetails(error.code, error.details);
10562
10592
  return {
@@ -10629,6 +10659,19 @@ function redactSafeErrorDetails(code, details) {
10629
10659
  const value = sanitize(details[key]);
10630
10660
  if (value !== void 0) safeDetails[key] = value;
10631
10661
  }
10662
+ if (code === "AUTH_REQUIRED") {
10663
+ const { reason, revokedCid, ancestorCid } = details;
10664
+ if (typeof revokedCid === "string" && DELEGATION_CID.exec(revokedCid)?.[0] === revokedCid) {
10665
+ if (reason === "delegation_revoked") {
10666
+ safeDetails.reason = reason;
10667
+ safeDetails.revokedCid = revokedCid;
10668
+ } else if (reason === "delegation_ancestor_revoked" && typeof ancestorCid === "string" && DELEGATION_CID.exec(ancestorCid)?.[0] === ancestorCid) {
10669
+ safeDetails.reason = reason;
10670
+ safeDetails.revokedCid = revokedCid;
10671
+ safeDetails.ancestorCid = ancestorCid;
10672
+ }
10673
+ }
10674
+ }
10632
10675
  return Object.keys(safeDetails).length === 0 ? void 0 : safeDetails;
10633
10676
  }
10634
10677
  function safeIssueCodes(value) {
@@ -11115,7 +11158,7 @@ async function executePreparedInvocation(prepared, options = {}) {
11115
11158
  operation,
11116
11159
  context: runtimeResolution.context.summary,
11117
11160
  setup: outcome.setup,
11118
- retry: retryDescriptor(
11161
+ retry: operationRetryDescriptor(
11119
11162
  operation,
11120
11163
  parsedInput.data,
11121
11164
  outcome.requiresCallerInput ?? false
@@ -11190,7 +11233,7 @@ function unresolvedContextSummary(target = {}) {
11190
11233
  function errorResult(operation, context, error) {
11191
11234
  return { status: "error", operation, context, error };
11192
11235
  }
11193
- function retryDescriptor(operation, input, requiresCallerInput) {
11236
+ function operationRetryDescriptor(operation, input, requiresCallerInput = false) {
11194
11237
  return {
11195
11238
  operationId: operation.operationId,
11196
11239
  operationVersion: operation.operationVersion,
@@ -11260,7 +11303,7 @@ function authorityRequiredResult(operation, context, input, request, missing, no
11260
11303
  missing,
11261
11304
  request,
11262
11305
  approval: approvalAction(request, node),
11263
- retry: retryDescriptor(operation, input, requiresCallerInput)
11306
+ retry: operationRetryDescriptor(operation, input, requiresCallerInput)
11264
11307
  };
11265
11308
  }
11266
11309
  function approvalAction(request, node) {