@tinycloud/operations 0.7.0-beta.34 → 0.7.0-beta.36

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.
@@ -125,4 +125,4 @@ interface InvocationTarget {
125
125
  readonly privateKey?: string;
126
126
  }
127
127
 
128
- export { type InvocationTarget as I, type OperationOperatorType as O, type StoredGrantSkipReason as S, type TinyCloudPosture as T, type OperationResult as a, type OperationWarning as b, STORED_GRANT_SKIP_REASONS as c, type OperationContextSummary as d };
128
+ export { type InvocationTarget as I, type OperationOperatorType as O, type RetryDescriptor as R, type StoredGrantSkipReason as S, type TinyCloudPosture as T, type OperationResult as a, type OperationContextSummary as b, type OperationWarning as c, STORED_GRANT_SKIP_REASONS as d, type OperationRef as e };
@@ -125,4 +125,4 @@ interface InvocationTarget {
125
125
  readonly privateKey?: string;
126
126
  }
127
127
 
128
- export { type InvocationTarget as I, type OperationOperatorType as O, type StoredGrantSkipReason as S, type TinyCloudPosture as T, type OperationResult as a, type OperationWarning as b, STORED_GRANT_SKIP_REASONS as c, type OperationContextSummary as d };
128
+ export { type InvocationTarget as I, type OperationOperatorType as O, type RetryDescriptor as R, type StoredGrantSkipReason as S, type TinyCloudPosture as T, type OperationResult as a, type OperationContextSummary as b, type OperationWarning as c, STORED_GRANT_SKIP_REASONS as d, type OperationRef as e };
@@ -1,7 +1,7 @@
1
1
  import { PermissionEntry, ValidatedRuntimeDelegation, RuntimeDelegationActivator, PortableDelegation } from '@tinycloud/node-sdk';
2
2
  import { O as OperationSpaceResolver } from './authority-ofwbEqmj.cjs';
3
- import { S as StoredGrantSkipReason, b as OperationWarning } from './contract-zRklonbR.cjs';
4
- export { c as STORED_GRANT_SKIP_REASONS } from './contract-zRklonbR.cjs';
3
+ import { S as StoredGrantSkipReason, c as OperationWarning } from './contract-DrtFhVsg.cjs';
4
+ export { d as STORED_GRANT_SKIP_REASONS } from './contract-DrtFhVsg.cjs';
5
5
  import '@tinycloud/sdk-core';
6
6
 
7
7
  /** Creates the one owner-aware resolver shared by operation matching paths. */
@@ -1,7 +1,7 @@
1
1
  import { PermissionEntry, ValidatedRuntimeDelegation, RuntimeDelegationActivator, PortableDelegation } from '@tinycloud/node-sdk';
2
2
  import { O as OperationSpaceResolver } from './authority-ofwbEqmj.js';
3
- import { S as StoredGrantSkipReason, b as OperationWarning } from './contract-zRklonbR.js';
4
- export { c as STORED_GRANT_SKIP_REASONS } from './contract-zRklonbR.js';
3
+ import { S as StoredGrantSkipReason, c as OperationWarning } from './contract-DrtFhVsg.js';
4
+ export { d as STORED_GRANT_SKIP_REASONS } from './contract-DrtFhVsg.js';
5
5
  import '@tinycloud/sdk-core';
6
6
 
7
7
  /** Creates the one owner-aware resolver shared by operation matching paths. */
@@ -0,0 +1,12 @@
1
+ import { I as InvocationTarget, a as OperationResult, e as OperationRef, R as RetryDescriptor } from './contract-DrtFhVsg.cjs';
2
+
3
+ /** Value-free counters; the caller owns this optional diagnostic sink. */
4
+ interface OperationMetrics {
5
+ replayedGrants: number;
6
+ }
7
+ /** The sole projection-facing execution API. */
8
+ declare function invokeOperation(operationId: string, operationVersion: number, invocationTarget: InvocationTarget, unknownInput: unknown, metrics?: OperationMetrics): Promise<OperationResult<unknown>>;
9
+ /** Build the same canonical retry identity used by operation authority results. */
10
+ declare function operationRetryDescriptor(operation: OperationRef, input: unknown, requiresCallerInput?: boolean): RetryDescriptor;
11
+
12
+ export { invokeOperation as i, operationRetryDescriptor as o };
@@ -0,0 +1,12 @@
1
+ import { I as InvocationTarget, a as OperationResult, e as OperationRef, R as RetryDescriptor } from './contract-DrtFhVsg.js';
2
+
3
+ /** Value-free counters; the caller owns this optional diagnostic sink. */
4
+ interface OperationMetrics {
5
+ replayedGrants: number;
6
+ }
7
+ /** The sole projection-facing execution API. */
8
+ declare function invokeOperation(operationId: string, operationVersion: number, invocationTarget: InvocationTarget, unknownInput: unknown, metrics?: OperationMetrics): Promise<OperationResult<unknown>>;
9
+ /** Build the same canonical retry identity used by operation authority results. */
10
+ declare function operationRetryDescriptor(operation: OperationRef, input: unknown, requiresCallerInput?: boolean): RetryDescriptor;
11
+
12
+ export { invokeOperation as i, operationRetryDescriptor as o };
package/dist/index.cjs CHANGED
@@ -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) {
@@ -11021,7 +11063,7 @@ async function executePreparedInvocation(prepared, options = {}) {
11021
11063
  operation,
11022
11064
  context: runtimeResolution.context.summary,
11023
11065
  setup: outcome.setup,
11024
- retry: retryDescriptor(
11066
+ retry: operationRetryDescriptor(
11025
11067
  operation,
11026
11068
  parsedInput.data,
11027
11069
  outcome.requiresCallerInput ?? false
@@ -11096,7 +11138,7 @@ function unresolvedContextSummary(target = {}) {
11096
11138
  function errorResult(operation, context, error) {
11097
11139
  return { status: "error", operation, context, error };
11098
11140
  }
11099
- function retryDescriptor(operation, input, requiresCallerInput) {
11141
+ function operationRetryDescriptor(operation, input, requiresCallerInput = false) {
11100
11142
  return {
11101
11143
  operationId: operation.operationId,
11102
11144
  operationVersion: operation.operationVersion,
@@ -11166,7 +11208,7 @@ function authorityRequiredResult(operation, context, input, request, missing, no
11166
11208
  missing,
11167
11209
  request,
11168
11210
  approval: approvalAction(request, node),
11169
- retry: retryDescriptor(operation, input, requiresCallerInput)
11211
+ retry: operationRetryDescriptor(operation, input, requiresCallerInput)
11170
11212
  };
11171
11213
  }
11172
11214
  function approvalAction(request, node) {