@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.
@@ -2,7 +2,7 @@ import { PermissionEntry } from '@tinycloud/sdk-core';
2
2
  import { z } from 'zod';
3
3
  import { O as OperationSpaceResolver } from './authority-ofwbEqmj.cjs';
4
4
  export { e as evaluateAuthority } from './authority-ofwbEqmj.cjs';
5
- import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-zRklonbR.cjs';
5
+ import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-DrtFhVsg.cjs';
6
6
 
7
7
  /** The shared wire schema for SDK PermissionEntry values, including signed ReCap caveats. */
8
8
  declare const PermissionEntrySchema: z.ZodObject<{
@@ -2,7 +2,7 @@ import { PermissionEntry } from '@tinycloud/sdk-core';
2
2
  import { z } from 'zod';
3
3
  import { O as OperationSpaceResolver } from './authority-ofwbEqmj.js';
4
4
  export { e as evaluateAuthority } from './authority-ofwbEqmj.js';
5
- import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-zRklonbR.js';
5
+ import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-DrtFhVsg.js';
6
6
 
7
7
  /** The shared wire schema for SDK PermissionEntry values, including signed ReCap caveats. */
8
8
  declare const PermissionEntrySchema: z.ZodObject<{
@@ -5655,6 +5655,34 @@ var init_artifacts = __esm({
5655
5655
  }
5656
5656
  });
5657
5657
 
5658
+ // src/contract.ts
5659
+ var STORED_GRANT_SKIP_REASONS, DELEGATION_CID_PATTERN;
5660
+ var init_contract = __esm({
5661
+ "src/contract.ts"() {
5662
+ "use strict";
5663
+ STORED_GRANT_SKIP_REASONS = [
5664
+ "malformed",
5665
+ "unbound",
5666
+ "outside_request",
5667
+ "host_mismatch",
5668
+ "expired",
5669
+ "cid_mismatch",
5670
+ "authority_invalid",
5671
+ "proof_missing",
5672
+ "proof_invalid",
5673
+ "owner_mismatch",
5674
+ "audience_mismatch",
5675
+ "resources_mismatch",
5676
+ "unsupported",
5677
+ "activation_rejected",
5678
+ "activation_unavailable",
5679
+ "activation_unauthenticated",
5680
+ "invalid"
5681
+ ];
5682
+ DELEGATION_CID_PATTERN = "^bafkr4i[a-z2-7]{52}$";
5683
+ }
5684
+ });
5685
+
5658
5686
  // src/recovery.ts
5659
5687
  function signInRecovery(profile, posture) {
5660
5688
  if (!SAFE_PROFILE_TOKEN.test(profile)) return { action: "sign_in" };
@@ -5875,6 +5903,26 @@ var init_revoked_grant = __esm({
5875
5903
  });
5876
5904
 
5877
5905
  // src/kv-failure.ts
5906
+ function nodeRevocationOf(error) {
5907
+ 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 || (0, import_sdk_services3.authorizationVerdictOf)(error) !== "unauthenticated") return void 0;
5908
+ const { code, message } = error;
5909
+ const separator = ": 401 - ";
5910
+ const start = message.indexOf(separator);
5911
+ if (start < 0) return void 0;
5912
+ const body = message.slice(start + separator.length);
5913
+ const match = NODE_REVOCATION_BODY.exec(body);
5914
+ if (match === null || match[0] !== body) return void 0;
5915
+ if (match[1] !== void 0 && code !== "AUTH_DELEGATION_ANCESTOR_REVOKED") {
5916
+ const revokedCid = match[2];
5917
+ return DELEGATION_CID2.test(revokedCid) ? { reason: "delegation_revoked", revokedCid } : void 0;
5918
+ }
5919
+ if (match[3] !== void 0 && code !== "AUTH_DELEGATION_REVOKED") {
5920
+ const ancestorCid = match[4];
5921
+ const revokedCid = match[5];
5922
+ return DELEGATION_CID2.test(ancestorCid) && DELEGATION_CID2.test(revokedCid) ? { reason: "delegation_ancestor_revoked", revokedCid, ancestorCid } : void 0;
5923
+ }
5924
+ return void 0;
5925
+ }
5878
5926
  function kvRefusal(error) {
5879
5927
  const verdict = (0, import_sdk_services3.authorizationVerdictOf)(error);
5880
5928
  if (verdict === "unauthenticated") {
@@ -5884,24 +5932,31 @@ function kvRefusal(error) {
5884
5932
  }
5885
5933
  function authorizationFailure(error, action) {
5886
5934
  switch (kvRefusal(error)) {
5887
- case "auth_required":
5888
- if (isRevokedGrantRefusal(error)) {
5889
- return { status: "error", error: operationError("AUTH_REQUIRED", REVOKED_GRANT_MESSAGE) };
5890
- }
5891
- return { status: "error", error: operationError("AUTH_REQUIRED", `Authentication is required to ${action}.`) };
5935
+ case "auth_required": {
5936
+ const revocation = nodeRevocationOf(error);
5937
+ return {
5938
+ status: "error",
5939
+ error: operationError("AUTH_REQUIRED", isRevokedGrantRefusal(error) ? REVOKED_GRANT_MESSAGE : `Authentication is required to ${action}.`, {
5940
+ ...revocation === void 0 ? {} : { details: revocation }
5941
+ })
5942
+ };
5943
+ }
5892
5944
  case "permission_denied":
5893
5945
  return { status: "error", error: operationError("PERMISSION_DENIED", `Permission is denied to ${action}.`) };
5894
5946
  case void 0:
5895
5947
  return void 0;
5896
5948
  }
5897
5949
  }
5898
- var import_sdk_services3;
5950
+ var import_sdk_services3, DELEGATION_CID2, NODE_REVOCATION_BODY;
5899
5951
  var init_kv_failure = __esm({
5900
5952
  "src/kv-failure.ts"() {
5901
5953
  "use strict";
5902
5954
  import_sdk_services3 = require("@tinycloud/sdk-services");
5955
+ init_contract();
5903
5956
  init_errors2();
5904
5957
  init_revoked_grant();
5958
+ DELEGATION_CID2 = new RegExp(DELEGATION_CID_PATTERN);
5959
+ NODE_REVOCATION_BODY = /^(?:Invalid invocation: )?delegation-(?:(revoked): ([A-Za-z0-9]+)|(ancestor-revoked): ancestor=([A-Za-z0-9]+) invoked=([A-Za-z0-9]+))$/;
5905
5960
  }
5906
5961
  });
5907
5962
 
@@ -9489,34 +9544,6 @@ var init_secrets_status = __esm({
9489
9544
  }
9490
9545
  });
9491
9546
 
9492
- // src/contract.ts
9493
- var STORED_GRANT_SKIP_REASONS, DELEGATION_CID_PATTERN;
9494
- var init_contract = __esm({
9495
- "src/contract.ts"() {
9496
- "use strict";
9497
- STORED_GRANT_SKIP_REASONS = [
9498
- "malformed",
9499
- "unbound",
9500
- "outside_request",
9501
- "host_mismatch",
9502
- "expired",
9503
- "cid_mismatch",
9504
- "authority_invalid",
9505
- "proof_missing",
9506
- "proof_invalid",
9507
- "owner_mismatch",
9508
- "audience_mismatch",
9509
- "resources_mismatch",
9510
- "unsupported",
9511
- "activation_rejected",
9512
- "activation_unavailable",
9513
- "activation_unauthenticated",
9514
- "invalid"
9515
- ];
9516
- DELEGATION_CID_PATTERN = "^bafkr4i[a-z2-7]{52}$";
9517
- }
9518
- });
9519
-
9520
9547
  // src/delegation-binding.ts
9521
9548
  function bindingMigrationPath(profile) {
9522
9549
  return (0, import_node_path4.join)(profilePath(profile), "delegation-binding-migration.json");
@@ -9667,7 +9694,7 @@ function verifiedStoredCid(node, entry) {
9667
9694
  const cid = delegation?.cid;
9668
9695
  if (typeof cid !== "string" || typeof header?.Authorization !== "string" || typeof node.computeDelegationCid !== "function") return void 0;
9669
9696
  try {
9670
- return node.computeDelegationCid(header.Authorization) === cid && DELEGATION_CID.test(cid) ? cid : void 0;
9697
+ return node.computeDelegationCid(header.Authorization) === cid && DELEGATION_CID3.test(cid) ? cid : void 0;
9671
9698
  } catch {
9672
9699
  return void 0;
9673
9700
  }
@@ -9774,7 +9801,7 @@ function recordKey(entry) {
9774
9801
  function isRecord4(value) {
9775
9802
  return typeof value === "object" && value !== null && !Array.isArray(value);
9776
9803
  }
9777
- var import_node_path4, nodeSdk5, REQUEST_ID_PREFIX, BINDING_NOTES, MIGRATION_LOCK_TIMEOUT_MS, NOT_REPLAYED, DELEGATION_CID;
9804
+ var import_node_path4, nodeSdk5, REQUEST_ID_PREFIX, BINDING_NOTES, MIGRATION_LOCK_TIMEOUT_MS, NOT_REPLAYED, DELEGATION_CID3;
9778
9805
  var init_delegation_binding = __esm({
9779
9806
  "src/delegation-binding.ts"() {
9780
9807
  "use strict";
@@ -9799,7 +9826,7 @@ var init_delegation_binding = __esm({
9799
9826
  };
9800
9827
  MIGRATION_LOCK_TIMEOUT_MS = 250;
9801
9828
  NOT_REPLAYED = { status: "not-replayed" };
9802
- DELEGATION_CID = new RegExp(DELEGATION_CID_PATTERN);
9829
+ DELEGATION_CID3 = new RegExp(DELEGATION_CID_PATTERN);
9803
9830
  }
9804
9831
  });
9805
9832
 
@@ -10485,6 +10512,7 @@ init_artifacts();
10485
10512
 
10486
10513
  // src/redaction.ts
10487
10514
  var import_node_sdk = require("@tinycloud/node-sdk");
10515
+ init_contract();
10488
10516
  init_recovery();
10489
10517
 
10490
10518
  // src/safe-values.ts
@@ -10550,6 +10578,7 @@ function decodeBase58(value) {
10550
10578
  }
10551
10579
 
10552
10580
  // src/redaction.ts
10581
+ var DELEGATION_CID = new RegExp(DELEGATION_CID_PATTERN);
10553
10582
  function redactOperationError(_definition, error) {
10554
10583
  const details = error.details === void 0 ? void 0 : redactSafeErrorDetails(error.code, error.details);
10555
10584
  return {
@@ -10622,6 +10651,19 @@ function redactSafeErrorDetails(code, details) {
10622
10651
  const value = sanitize(details[key]);
10623
10652
  if (value !== void 0) safeDetails[key] = value;
10624
10653
  }
10654
+ if (code === "AUTH_REQUIRED") {
10655
+ const { reason, revokedCid, ancestorCid } = details;
10656
+ if (typeof revokedCid === "string" && DELEGATION_CID.exec(revokedCid)?.[0] === revokedCid) {
10657
+ if (reason === "delegation_revoked") {
10658
+ safeDetails.reason = reason;
10659
+ safeDetails.revokedCid = revokedCid;
10660
+ } else if (reason === "delegation_ancestor_revoked" && typeof ancestorCid === "string" && DELEGATION_CID.exec(ancestorCid)?.[0] === ancestorCid) {
10661
+ safeDetails.reason = reason;
10662
+ safeDetails.revokedCid = revokedCid;
10663
+ safeDetails.ancestorCid = ancestorCid;
10664
+ }
10665
+ }
10666
+ }
10625
10667
  return Object.keys(safeDetails).length === 0 ? void 0 : safeDetails;
10626
10668
  }
10627
10669
  function safeIssueCodes(value) {
@@ -11108,7 +11150,7 @@ async function executePreparedInvocation(prepared, options = {}) {
11108
11150
  operation,
11109
11151
  context: runtimeResolution.context.summary,
11110
11152
  setup: outcome.setup,
11111
- retry: retryDescriptor(
11153
+ retry: operationRetryDescriptor(
11112
11154
  operation,
11113
11155
  parsedInput.data,
11114
11156
  outcome.requiresCallerInput ?? false
@@ -11183,7 +11225,7 @@ function unresolvedContextSummary(target = {}) {
11183
11225
  function errorResult(operation, context, error) {
11184
11226
  return { status: "error", operation, context, error };
11185
11227
  }
11186
- function retryDescriptor(operation, input, requiresCallerInput) {
11228
+ function operationRetryDescriptor(operation, input, requiresCallerInput = false) {
11187
11229
  return {
11188
11230
  operationId: operation.operationId,
11189
11231
  operationVersion: operation.operationVersion,
@@ -11253,7 +11295,7 @@ function authorityRequiredResult(operation, context, input, request, missing, no
11253
11295
  missing,
11254
11296
  request,
11255
11297
  approval: approvalAction(request, node),
11256
- retry: retryDescriptor(operation, input, requiresCallerInput)
11298
+ retry: operationRetryDescriptor(operation, input, requiresCallerInput)
11257
11299
  };
11258
11300
  }
11259
11301
  function approvalAction(request, node) {