@decionis/agentsafe 0.6.0 → 0.7.0

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.
Files changed (169) hide show
  1. package/README.md +62 -19
  2. package/dist/Cli.js +18 -1
  3. package/dist/Cli.js.map +1 -1
  4. package/dist/Index.d.ts +5 -3
  5. package/dist/Index.d.ts.map +1 -1
  6. package/dist/Index.js +3 -1
  7. package/dist/Index.js.map +1 -1
  8. package/dist/TrustedExecutor.d.ts.map +1 -1
  9. package/dist/TrustedExecutor.js +2 -0
  10. package/dist/TrustedExecutor.js.map +1 -1
  11. package/dist/adapters/mcp/McpGuard.d.ts +32 -3
  12. package/dist/adapters/mcp/McpGuard.d.ts.map +1 -1
  13. package/dist/adapters/mcp/McpGuard.js +29 -5
  14. package/dist/adapters/mcp/McpGuard.js.map +1 -1
  15. package/dist/adapters/mcp/McpIntentBinder.d.ts +18 -3
  16. package/dist/adapters/mcp/McpIntentBinder.d.ts.map +1 -1
  17. package/dist/adapters/mcp/McpIntentBinder.js +48 -1
  18. package/dist/adapters/mcp/McpIntentBinder.js.map +1 -1
  19. package/dist/adapters/mcp/McpInvocation.d.ts +9 -2
  20. package/dist/adapters/mcp/McpInvocation.d.ts.map +1 -1
  21. package/dist/adapters/mcp/McpInvocation.js.map +1 -1
  22. package/dist/cli/Actions.d.ts +14 -0
  23. package/dist/cli/Actions.d.ts.map +1 -0
  24. package/dist/cli/Actions.js +168 -0
  25. package/dist/cli/Actions.js.map +1 -0
  26. package/dist/cli/Arguments.d.ts +4 -0
  27. package/dist/cli/Arguments.d.ts.map +1 -1
  28. package/dist/cli/Arguments.js +12 -3
  29. package/dist/cli/Arguments.js.map +1 -1
  30. package/dist/cli/ConfigCommand.d.ts.map +1 -1
  31. package/dist/cli/ConfigCommand.js +5 -0
  32. package/dist/cli/ConfigCommand.js.map +1 -1
  33. package/dist/cli/Help.d.ts.map +1 -1
  34. package/dist/cli/Help.js +13 -1
  35. package/dist/cli/Help.js.map +1 -1
  36. package/dist/cli/Host.d.ts +5 -2
  37. package/dist/cli/Host.d.ts.map +1 -1
  38. package/dist/cli/Host.js +24 -2
  39. package/dist/cli/Host.js.map +1 -1
  40. package/dist/cli/Profile.d.ts +24 -0
  41. package/dist/cli/Profile.d.ts.map +1 -0
  42. package/dist/cli/Profile.js +168 -0
  43. package/dist/cli/Profile.js.map +1 -0
  44. package/dist/cli/Records.d.ts +15 -0
  45. package/dist/cli/Records.d.ts.map +1 -0
  46. package/dist/cli/Records.js +205 -0
  47. package/dist/cli/Records.js.map +1 -0
  48. package/dist/config/ConfigKeys.d.ts +2 -2
  49. package/dist/config/ConfigKeys.d.ts.map +1 -1
  50. package/dist/config/ConfigKeys.js +6 -0
  51. package/dist/config/ConfigKeys.js.map +1 -1
  52. package/dist/config/ExecutorConfig.d.ts +29 -0
  53. package/dist/config/ExecutorConfig.d.ts.map +1 -1
  54. package/dist/config/ExecutorConfig.js +53 -1
  55. package/dist/config/ExecutorConfig.js.map +1 -1
  56. package/dist/gateway/ForwardHandler.d.ts +22 -4
  57. package/dist/gateway/ForwardHandler.d.ts.map +1 -1
  58. package/dist/gateway/ForwardHandler.js +27 -10
  59. package/dist/gateway/ForwardHandler.js.map +1 -1
  60. package/dist/gateway/Gateway.d.ts +123 -3
  61. package/dist/gateway/Gateway.d.ts.map +1 -1
  62. package/dist/gateway/Gateway.js +513 -16
  63. package/dist/gateway/Gateway.js.map +1 -1
  64. package/dist/gateway/GatewayConfig.d.ts +109 -0
  65. package/dist/gateway/GatewayConfig.d.ts.map +1 -1
  66. package/dist/gateway/GatewayConfig.js +267 -9
  67. package/dist/gateway/GatewayConfig.js.map +1 -1
  68. package/dist/gateway/GatewayReport.d.ts +6 -2
  69. package/dist/gateway/GatewayReport.d.ts.map +1 -1
  70. package/dist/gateway/GatewayReport.js +3 -0
  71. package/dist/gateway/GatewayReport.js.map +1 -1
  72. package/dist/gateway/InterceptedRequest.d.ts +45 -1
  73. package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
  74. package/dist/gateway/InterceptedRequest.js +43 -1
  75. package/dist/gateway/InterceptedRequest.js.map +1 -1
  76. package/dist/gateway/PolicySelector.d.ts +5 -0
  77. package/dist/gateway/PolicySelector.d.ts.map +1 -0
  78. package/dist/gateway/PolicySelector.js +9 -0
  79. package/dist/gateway/PolicySelector.js.map +1 -0
  80. package/dist/gateway/RouteTable.d.ts +44 -7
  81. package/dist/gateway/RouteTable.d.ts.map +1 -1
  82. package/dist/gateway/RouteTable.js +58 -9
  83. package/dist/gateway/RouteTable.js.map +1 -1
  84. package/dist/gateway/SubjectSessions.d.ts +113 -0
  85. package/dist/gateway/SubjectSessions.d.ts.map +1 -0
  86. package/dist/gateway/SubjectSessions.js +219 -0
  87. package/dist/gateway/SubjectSessions.js.map +1 -0
  88. package/dist/gateway/Upstream.d.ts +11 -0
  89. package/dist/gateway/Upstream.d.ts.map +1 -1
  90. package/dist/gateway/Upstream.js +19 -2
  91. package/dist/gateway/Upstream.js.map +1 -1
  92. package/dist/hosted/TenantHost.d.ts +24 -5
  93. package/dist/hosted/TenantHost.d.ts.map +1 -1
  94. package/dist/hosted/TenantHost.js +39 -10
  95. package/dist/hosted/TenantHost.js.map +1 -1
  96. package/dist/hosted/TenantRegistry.d.ts +20 -0
  97. package/dist/hosted/TenantRegistry.d.ts.map +1 -1
  98. package/dist/hosted/TenantRegistry.js +47 -1
  99. package/dist/hosted/TenantRegistry.js.map +1 -1
  100. package/dist/http/GatewayHttpServer.d.ts.map +1 -1
  101. package/dist/http/GatewayHttpServer.js +46 -2
  102. package/dist/http/GatewayHttpServer.js.map +1 -1
  103. package/dist/identity/WorkloadJwtVerifier.d.ts +13 -0
  104. package/dist/identity/WorkloadJwtVerifier.d.ts.map +1 -1
  105. package/dist/identity/WorkloadJwtVerifier.js +40 -8
  106. package/dist/identity/WorkloadJwtVerifier.js.map +1 -1
  107. package/dist/incident/HaltSwitch.d.ts +10 -2
  108. package/dist/incident/HaltSwitch.d.ts.map +1 -1
  109. package/dist/incident/HaltSwitch.js +22 -2
  110. package/dist/incident/HaltSwitch.js.map +1 -1
  111. package/dist/incident/SecurityEvents.d.ts +18 -0
  112. package/dist/incident/SecurityEvents.d.ts.map +1 -1
  113. package/dist/incident/SecurityEvents.js +17 -0
  114. package/dist/incident/SecurityEvents.js.map +1 -1
  115. package/dist/limits/HardLimits.d.ts.map +1 -1
  116. package/dist/limits/HardLimits.js.map +1 -1
  117. package/dist/outcomes/CardOutcomeEvidence.d.ts +56 -0
  118. package/dist/outcomes/CardOutcomeEvidence.d.ts.map +1 -0
  119. package/dist/outcomes/CardOutcomeEvidence.js +211 -0
  120. package/dist/outcomes/CardOutcomeEvidence.js.map +1 -0
  121. package/dist/outcomes/CardOutcomeFact.d.ts +90 -0
  122. package/dist/outcomes/CardOutcomeFact.d.ts.map +1 -0
  123. package/dist/outcomes/CardOutcomeFact.js +76 -0
  124. package/dist/outcomes/CardOutcomeFact.js.map +1 -0
  125. package/dist/outcomes/CardOutcomeLedger.d.ts +26 -0
  126. package/dist/outcomes/CardOutcomeLedger.d.ts.map +1 -0
  127. package/dist/outcomes/CardOutcomeLedger.js +31 -0
  128. package/dist/outcomes/CardOutcomeLedger.js.map +1 -0
  129. package/dist/outcomes/CardOutcomeRecorder.d.ts +35 -0
  130. package/dist/outcomes/CardOutcomeRecorder.d.ts.map +1 -0
  131. package/dist/outcomes/CardOutcomeRecorder.js +84 -0
  132. package/dist/outcomes/CardOutcomeRecorder.js.map +1 -0
  133. package/dist/outcomes/CardOutcomes.d.ts +68 -0
  134. package/dist/outcomes/CardOutcomes.d.ts.map +1 -0
  135. package/dist/outcomes/CardOutcomes.js +191 -0
  136. package/dist/outcomes/CardOutcomes.js.map +1 -0
  137. package/dist/outcomes/CoreOutcomeEvidenceClient.d.ts +54 -0
  138. package/dist/outcomes/CoreOutcomeEvidenceClient.d.ts.map +1 -0
  139. package/dist/outcomes/CoreOutcomeEvidenceClient.js +116 -0
  140. package/dist/outcomes/CoreOutcomeEvidenceClient.js.map +1 -0
  141. package/dist/outcomes/FileCardOutcomeLedger.d.ts +36 -0
  142. package/dist/outcomes/FileCardOutcomeLedger.d.ts.map +1 -0
  143. package/dist/outcomes/FileCardOutcomeLedger.js +152 -0
  144. package/dist/outcomes/FileCardOutcomeLedger.js.map +1 -0
  145. package/dist/outcomes/OutcomeEvidence.d.ts +238 -0
  146. package/dist/outcomes/OutcomeEvidence.d.ts.map +1 -0
  147. package/dist/outcomes/OutcomeEvidence.js +130 -0
  148. package/dist/outcomes/OutcomeEvidence.js.map +1 -0
  149. package/dist/outcomes/OutcomeEvidencePublisher.d.ts +81 -0
  150. package/dist/outcomes/OutcomeEvidencePublisher.d.ts.map +1 -0
  151. package/dist/outcomes/OutcomeEvidencePublisher.js +189 -0
  152. package/dist/outcomes/OutcomeEvidencePublisher.js.map +1 -0
  153. package/dist/outcomes/OutcomeEvidenceStore.d.ts +57 -0
  154. package/dist/outcomes/OutcomeEvidenceStore.d.ts.map +1 -0
  155. package/dist/outcomes/OutcomeEvidenceStore.js +191 -0
  156. package/dist/outcomes/OutcomeEvidenceStore.js.map +1 -0
  157. package/dist/service/Requests.d.ts +6 -0
  158. package/dist/service/Requests.d.ts.map +1 -1
  159. package/dist/service/Requests.js +9 -1
  160. package/dist/service/Requests.js.map +1 -1
  161. package/dist/service/TrustedExecutorService.d.ts +21 -1
  162. package/dist/service/TrustedExecutorService.d.ts.map +1 -1
  163. package/dist/service/TrustedExecutorService.js +54 -13
  164. package/dist/service/TrustedExecutorService.js.map +1 -1
  165. package/dist/verify/VerifyingProvider.d.ts +32 -6
  166. package/dist/verify/VerifyingProvider.d.ts.map +1 -1
  167. package/dist/verify/VerifyingProvider.js +16 -2
  168. package/dist/verify/VerifyingProvider.js.map +1 -1
  169. package/package.json +6 -5
@@ -0,0 +1,31 @@
1
+ /** A refusal by a ledger: the code, never a path or a value. */
2
+ export class CardOutcomeLedgerError extends Error {
3
+ code;
4
+ constructor(code) {
5
+ super(code);
6
+ this.code = code;
7
+ this.name = "CardOutcomeLedgerError";
8
+ }
9
+ }
10
+ /** The ledger in memory: for tests, and for a process that records without a directory. */
11
+ export class InMemoryCardOutcomeLedger {
12
+ facts = [];
13
+ get all() {
14
+ return this.facts;
15
+ }
16
+ async append(facts) {
17
+ this.facts.push(...facts);
18
+ await Promise.resolve();
19
+ }
20
+ async since(from) {
21
+ return await Promise.resolve(oldestFirst(this.facts, from));
22
+ }
23
+ }
24
+ /** The facts at or after `from`, by time; a stable sort keeps the recorded order within one instant. */
25
+ export function oldestFirst(facts, from) {
26
+ const floor = from.getTime();
27
+ return facts
28
+ .filter((fact) => Date.parse(fact.at) >= floor)
29
+ .sort((a, b) => Date.parse(a.at) - Date.parse(b.at));
30
+ }
31
+ //# sourceMappingURL=CardOutcomeLedger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardOutcomeLedger.js","sourceRoot":"","sources":["../../src/outcomes/CardOutcomeLedger.ts"],"names":[],"mappings":"AAEA,gEAAgE;AAChE,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACZ;IAAnC,YAAmC,IAAY;QAC7C,KAAK,CAAC,IAAI,CAAC,CAAC;QADqB,SAAI,GAAJ,IAAI,CAAQ;QAE7C,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAaD,2FAA2F;AAC3F,MAAM,OAAO,yBAAyB;IACnB,KAAK,GAAsB,EAAE,CAAC;IAE/C,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,KAAiC;QACnD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QAC1B,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,IAAU;QAC3B,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AAED,wGAAwG;AACxG,MAAM,UAAU,WAAW,CAAC,KAAiC,EAAE,IAAU;IACvE,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,OAAO,KAAK;SACT,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC;SAC9C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { type CardOutcomeFact } from "./CardOutcomeFact.js";
2
+ import type { CardOutcomeLedger } from "./CardOutcomeLedger.js";
3
+ /** How many facts may wait to be written; beyond it a fact is dropped and counted. */
4
+ export declare const CARD_OUTCOME_QUEUE_CAPACITY = 10000;
5
+ export interface CardOutcomeRecorderOptions {
6
+ readonly ledger: CardOutcomeLedger;
7
+ /** Told when facts could not be kept: how many, and the code that says why. */
8
+ readonly onDropped?: (count: number, code: string) => void;
9
+ readonly capacity?: number;
10
+ }
11
+ /**
12
+ * The cards family's outcome facts, kept after the fact. `note` is what the request path
13
+ * calls, once its answer is decided: it queues the fact and returns, never awaits anything and
14
+ * never throws, so recording can neither slow, fail nor change an authorization. The facts are
15
+ * checked and written after the current turn of the event loop, in order, one append per batch.
16
+ *
17
+ * What is lost is counted, never retried into the request path: a full queue, a fact that does
18
+ * not fit its schema, and a ledger that refuses a write each drop their facts and report how
19
+ * many. The evidence such a purchase leads to is then incomplete, and stays at what the facts
20
+ * that were kept establish.
21
+ */
22
+ export declare class CardOutcomeRecorder {
23
+ private readonly options;
24
+ private readonly queue;
25
+ private readonly capacity;
26
+ private writing;
27
+ constructor(options: CardOutcomeRecorderOptions);
28
+ /** Queues one fact. Returns at once; nothing here can reach the caller. */
29
+ note(fact: CardOutcomeFact): void;
30
+ /** Resolves once every fact queued so far has been written or dropped. */
31
+ flush(): Promise<void>;
32
+ private drain;
33
+ private dropped;
34
+ }
35
+ //# sourceMappingURL=CardOutcomeRecorder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardOutcomeRecorder.d.ts","sourceRoot":"","sources":["../../src/outcomes/CardOutcomeRecorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,sFAAsF;AACtF,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAElD,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,+EAA+E;IAC/E,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,mBAAmB;IAKX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,OAAO,CAA8B;gBAET,OAAO,EAAE,0BAA0B;IAIvE,2EAA2E;IACpE,IAAI,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;IAaxC,0EAA0E;IAC7D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAIrB,KAAK;IA8BnB,OAAO,CAAC,OAAO;CAOhB"}
@@ -0,0 +1,84 @@
1
+ import { CardOutcomeFactSchema } from "./CardOutcomeFact.js";
2
+ /** How many facts may wait to be written; beyond it a fact is dropped and counted. */
3
+ export const CARD_OUTCOME_QUEUE_CAPACITY = 10_000;
4
+ /**
5
+ * The cards family's outcome facts, kept after the fact. `note` is what the request path
6
+ * calls, once its answer is decided: it queues the fact and returns, never awaits anything and
7
+ * never throws, so recording can neither slow, fail nor change an authorization. The facts are
8
+ * checked and written after the current turn of the event loop, in order, one append per batch.
9
+ *
10
+ * What is lost is counted, never retried into the request path: a full queue, a fact that does
11
+ * not fit its schema, and a ledger that refuses a write each drop their facts and report how
12
+ * many. The evidence such a purchase leads to is then incomplete, and stays at what the facts
13
+ * that were kept establish.
14
+ */
15
+ export class CardOutcomeRecorder {
16
+ options;
17
+ queue = [];
18
+ capacity;
19
+ writing = null;
20
+ constructor(options) {
21
+ this.options = options;
22
+ this.capacity = options.capacity ?? CARD_OUTCOME_QUEUE_CAPACITY;
23
+ }
24
+ /** Queues one fact. Returns at once; nothing here can reach the caller. */
25
+ note(fact) {
26
+ try {
27
+ if (this.queue.length >= this.capacity) {
28
+ this.dropped(1, "CARD_OUTCOMES_QUEUE_FULL");
29
+ return;
30
+ }
31
+ this.queue.push(fact);
32
+ this.writing ??= this.drain();
33
+ }
34
+ catch {
35
+ // Recording is evidence after the fact; it never becomes the request's failure.
36
+ }
37
+ }
38
+ /** Resolves once every fact queued so far has been written or dropped. */
39
+ async flush() {
40
+ while (this.writing !== null)
41
+ await this.writing;
42
+ }
43
+ async drain() {
44
+ try {
45
+ // The answer goes out first: nothing is checked or written in the turn that queued it.
46
+ await new Promise((resolve) => setImmediate(resolve));
47
+ while (this.queue.length > 0) {
48
+ const batch = this.queue.splice(0, this.queue.length);
49
+ const facts = [];
50
+ for (const fact of batch) {
51
+ const parsed = CardOutcomeFactSchema.safeParse(fact);
52
+ if (parsed.success)
53
+ facts.push(parsed.data);
54
+ }
55
+ if (facts.length < batch.length) {
56
+ this.dropped(batch.length - facts.length, "CARD_OUTCOMES_FACT_INVALID");
57
+ }
58
+ if (facts.length === 0)
59
+ continue;
60
+ try {
61
+ await this.options.ledger.append(facts);
62
+ }
63
+ catch (error) {
64
+ const code = error instanceof Error && /^CARD_OUTCOMES_[A-Z_]{1,40}$/.test(error.message)
65
+ ? error.message
66
+ : "CARD_OUTCOMES_WRITE_FAILED";
67
+ this.dropped(facts.length, code);
68
+ }
69
+ }
70
+ }
71
+ finally {
72
+ this.writing = null;
73
+ }
74
+ }
75
+ dropped(count, code) {
76
+ try {
77
+ this.options.onDropped?.(count, code);
78
+ }
79
+ catch {
80
+ // A reporter that throws loses the report, not the process.
81
+ }
82
+ }
83
+ }
84
+ //# sourceMappingURL=CardOutcomeRecorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardOutcomeRecorder.js","sourceRoot":"","sources":["../../src/outcomes/CardOutcomeRecorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAwB,MAAM,sBAAsB,CAAC;AAGnF,sFAAsF;AACtF,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC;AASlD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,mBAAmB;IAKM;IAJnB,KAAK,GAAsB,EAAE,CAAC;IAC9B,QAAQ,CAAS;IAC1B,OAAO,GAAyB,IAAI,CAAC;IAE7C,YAAoC,OAAmC;QAAnC,YAAO,GAAP,OAAO,CAA4B;QACrE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,2BAA2B,CAAC;IAClE,CAAC;IAED,2EAA2E;IACpE,IAAI,CAAC,IAAqB;QAC/B,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACvC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,0BAA0B,CAAC,CAAC;gBAC5C,OAAO;YACT,CAAC;YACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACtB,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;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C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;wBAC1E,CAAC,CAAC,KAAK,CAAC,OAAO;wBACf,CAAC,CAAC,4BAA4B,CAAC;oBACnC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;IAEO,OAAO,CAAC,KAAa,EAAE,IAAY;QACzC,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACxC,CAAC;QAAC,MAAM,CAAC;YACP,4DAA4D;QAC9D,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,68 @@
1
+ import type { CapturedIntent } from "@decionis/agent-safe-pipeline";
2
+ import type { CardOutcomesConfig } from "../config/ExecutorConfig.js";
3
+ import type { FetchLike } from "../handlers/HandlerRegistration.js";
4
+ import type { SecurityEvents } from "../incident/SecurityEvents.js";
5
+ import type { ActionResponse } from "../service/Requests.js";
6
+ import type { CardOutcomeLedger } from "./CardOutcomeLedger.js";
7
+ import { type OutcomeEvidenceSink } from "./CoreOutcomeEvidenceClient.js";
8
+ import { type OutcomePublishSummary } from "./OutcomeEvidencePublisher.js";
9
+ /** The state file the publisher keeps beside the facts. */
10
+ export declare const CARD_OUTCOMES_STATE_FILE = "card-outcomes-state.json";
11
+ export interface CardOutcomesOptions {
12
+ readonly config: CardOutcomesConfig;
13
+ /** The authority's normalized base URL: Core serves the meter beside it. */
14
+ readonly authorityUrl: string;
15
+ /** The producer token, read from its secret handle at each request. */
16
+ readonly token: () => string;
17
+ /** The guarded fetch. */
18
+ readonly fetch: FetchLike;
19
+ readonly events: SecurityEvents;
20
+ /** Test seams: the ledger, Core's resource, the clock and this replica's name. */
21
+ readonly ledger?: CardOutcomeLedger;
22
+ readonly sink?: OutcomeEvidenceSink;
23
+ readonly clock?: () => Date;
24
+ readonly replica?: string;
25
+ }
26
+ /**
27
+ * The card purchases' outcome evidence, as the executor runs it: a recorder the card path
28
+ * tells what each purchase came to once its answer is decided, and, when publishing, the
29
+ * publisher that states it to Decionis on its own timer. Every method the request path calls
30
+ * returns at once and never throws; none of them is awaited, so with outcomes on or off every
31
+ * authorization is answered exactly the same.
32
+ *
33
+ * What is recorded is read from what the path already holds (the captured intent, the answer,
34
+ * the claim, the issuer's result), and only identifiers, codes, times and the purchase's amount
35
+ * are kept: the card reference, the merchant and the authorization id stay where they are.
36
+ */
37
+ export declare class CardOutcomes {
38
+ private readonly recorder;
39
+ private readonly publisher;
40
+ private constructor();
41
+ /** Null when the configuration leaves outcomes off. */
42
+ static create(options: CardOutcomesOptions): CardOutcomes | null;
43
+ /** Starts publishing, when this deployment publishes. */
44
+ start(): void;
45
+ stop(): void;
46
+ /** Resolves once every fact recorded so far is written or dropped. */
47
+ flush(): Promise<void>;
48
+ /** One run now, for an operator or a test; never throws. */
49
+ publish(): Promise<OutcomePublishSummary | null>;
50
+ /**
51
+ * The first decision a card purchase was given: in enforcement the held grant or the hold, in
52
+ * shadow what would have been decided. A decision the authority never took (it did not
53
+ * answer, and the boundary refused on its own) is not a decision to measure.
54
+ */
55
+ decided(captured: CapturedIntent, answer: ActionResponse): void;
56
+ /**
57
+ * A fresh decision on an open escalation. Only an `ALLOW` or a `BLOCK` is a resolution: an
58
+ * answer still pending, or a hold that is still escalated, changes nothing yet.
59
+ */
60
+ resumed(captured: CapturedIntent, answer: ActionResponse, via: "ATTESTATION" | "PRESENCE"): void;
61
+ /** The issuer's authorization matched the hold and claimed its grant. */
62
+ claimed(intentId: string, grantId: string): void;
63
+ /** What the issuer said it did with the authorization that claimed the grant. */
64
+ settled(intentId: string, outcome: "COMMITTED" | "FAILED" | "INDETERMINATE", receiptDigest: string): void;
65
+ /** The held grant's expiry, when the answer held one for the issuer. */
66
+ private static heldUntil;
67
+ }
68
+ //# sour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AAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAF5B,OAAO;IAKP,uDAAuD;WACzC,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,GAAG,IAAI;IAkDvE,yDAAyD;IAClD,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,IAAI;IAInB,sEAAsE;IACzD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC,4DAA4D;IAC/C,OAAO,IAAI,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAI7D;;;;OAIG;IACI,OAAO,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI;IA0BtE;;;OAGG;IACI,OAAO,CACZ,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,aAAa,GAAG,UAAU,GAC9B,IAAI;IAqBP,yEAAyE;IAClE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAcvD,iFAAiF;IAC1E,OAAO,CACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,WAAW,GAAG,QAAQ,GAAG,eAAe,EACjD,aAAa,EAAE,MAAM,GACpB,IAAI;IAeP,wEAAwE;IACxE,OAAO,CAAC,MAAM,CAAC,SAAS;CAKzB"}
@@ -0,0 +1,191 @@
1
+ import { join } from "node:path";
2
+ import { cardPurchaseOf, isCardActionName } from "../adapters/cards/CardPurchase.js";
3
+ import { CardOutcomeEvidenceProvider } from "./CardOutcomeEvidence.js";
4
+ import { CARD_OUTCOME_FACT_VERSION } from "./CardOutcomeFact.js";
5
+ import { CardOutcomeRecorder } from "./CardOutcomeRecorder.js";
6
+ import { CoreOutcomeEvidenceClient, } from "./CoreOutcomeEvidenceClient.js";
7
+ import { FileCardOutcomeLedger } from "./FileCardOutcomeLedger.js";
8
+ import { OutcomeEvidencePublisher, } from "./OutcomeEvidencePublisher.js";
9
+ import { OutcomeEvidenceStore } from "./OutcomeEvidenceStore.js";
10
+ /** The state file the publisher keeps beside the facts. */
11
+ export const CARD_OUTCOMES_STATE_FILE = "card-outcomes-state.json";
12
+ /**
13
+ * The card purchases' outcome evidence, as the executor runs it: a recorder the card path
14
+ * tells what each purchase came to once its answer is decided, and, when publishing, the
15
+ * publisher that states it to Decionis on its own timer. Every method the request path calls
16
+ * returns at once and never throws; none of them is awaited, so with outcomes on or off every
17
+ * authorization is answered exactly the same.
18
+ *
19
+ * What is recorded is read from what the path already holds (the captured intent, the answer,
20
+ * the claim, the issuer's result), and only identifiers, codes, times and the purchase's amount
21
+ * are kept: the card reference, the merchant and the authorization id stay where they are.
22
+ */
23
+ export class CardOutcomes {
24
+ recorder;
25
+ publisher;
26
+ constructor(recorder, publisher) {
27
+ this.recorder = recorder;
28
+ this.publisher = publisher;
29
+ }
30
+ /** Null when the configuration leaves outcomes off. */
31
+ static create(options) {
32
+ const { config, events } = options;
33
+ if (config.mode === "off")
34
+ return null;
35
+ const ledger = options.ledger ??
36
+ new FileCardOutcomeLedger(config.dir, options.replica === undefined ? {} : { replica: options.replica });
37
+ const recorder = new CardOutcomeRecorder({
38
+ ledger,
39
+ onDropped: (count, code) => events.emit({ event: "CARD_OUTCOMES_DROPPED", count, code }),
40
+ });
41
+ if (config.mode === "record")
42
+ return new CardOutcomes(recorder, null);
43
+ const publisher = new OutcomeEvidencePublisher({
44
+ ledger,
45
+ provider: new CardOutcomeEvidenceProvider(),
46
+ store: new OutcomeEvidenceStore(join(config.dir, CARD_OUTCOMES_STATE_FILE)),
47
+ sink: options.sink ??
48
+ new CoreOutcomeEvidenceClient({
49
+ baseUrl: options.authorityUrl,
50
+ token: options.token,
51
+ fetch: options.fetch,
52
+ }),
53
+ orgId: config.orgId,
54
+ intervalMs: config.intervalSeconds * 1_000,
55
+ ...(options.clock === undefined ? {} : { clock: options.clock }),
56
+ report: (summary) => {
57
+ if (summary.submitted > 0) {
58
+ events.emit({
59
+ event: "CARD_OUTCOMES_PUBLISHED",
60
+ submitted: summary.submitted,
61
+ accepted: summary.accepted,
62
+ duplicates: summary.duplicates,
63
+ conflicts: summary.conflicts,
64
+ });
65
+ }
66
+ if (summary.refused !== null) {
67
+ events.emit({
68
+ event: "CARD_OUTCOMES_REFUSED",
69
+ code: summary.refused,
70
+ retry: summary.retry,
71
+ });
72
+ }
73
+ },
74
+ });
75
+ return new CardOutcomes(recorder, publisher);
76
+ }
77
+ /** Starts publishing, when this deployment publishes. */
78
+ start() {
79
+ this.publisher?.start();
80
+ }
81
+ stop() {
82
+ this.publisher?.stop();
83
+ }
84
+ /** Resolves once every fact recorded so far is written or dropped. */
85
+ async flush() {
86
+ await this.recorder.flush();
87
+ }
88
+ /** One run now, for an operator or a test; never throws. */
89
+ async publish() {
90
+ return this.publisher === null ? null : await this.publisher.publish();
91
+ }
92
+ /**
93
+ * The first decision a card purchase was given: in enforcement the held grant or the hold, in
94
+ * shadow what would have been decided. A decision the authority never took (it did not
95
+ * answer, and the boundary refused on its own) is not a decision to measure.
96
+ */
97
+ decided(captured, answer) {
98
+ try {
99
+ if (!isCardActionName(captured.intent.action))
100
+ return;
101
+ if (answer.verdict === null || answer.fail_closed)
102
+ return;
103
+ const purchase = cardPurchaseOf(captured.intent.parameters);
104
+ this.recorder.note({
105
+ version: CARD_OUTCOME_FACT_VERSION,
106
+ kind: "DECIDED",
107
+ at: new Date().toISOString(),
108
+ intent_id: captured.intent.intentId,
109
+ tenant_id: captured.intent.tenantId,
110
+ mode: answer.mode,
111
+ verdict: answer.verdict,
112
+ decision_id: answer.decision_id,
113
+ dossier_id: answer.dossier_id,
114
+ reason_codes: answer.reason_codes.slice(0, 50),
115
+ held_until: CardOutcomes.heldUntil(answer),
116
+ expires_at: captured.intent.expiresAt,
117
+ currency: purchase.currency,
118
+ amount_minor: purchase.amountMinor,
119
+ });
120
+ }
121
+ catch {
122
+ // Evidence after the fact; never the request's failure.
123
+ }
124
+ }
125
+ /**
126
+ * A fresh decision on an open escalation. Only an `ALLOW` or a `BLOCK` is a resolution: an
127
+ * answer still pending, or a hold that is still escalated, changes nothing yet.
128
+ */
129
+ resumed(captured, answer, via) {
130
+ try {
131
+ if (!isCardActionName(captured.intent.action))
132
+ return;
133
+ if (answer.verdict !== "ALLOW" && answer.verdict !== "BLOCK")
134
+ return;
135
+ this.recorder.note({
136
+ version: CARD_OUTCOME_FACT_VERSION,
137
+ kind: "RESUMED",
138
+ at: new Date().toISOString(),
139
+ intent_id: captured.intent.intentId,
140
+ via,
141
+ verdict: answer.verdict,
142
+ decision_id: answer.decision_id,
143
+ dossier_id: answer.dossier_id,
144
+ reason_codes: answer.reason_codes.slice(0, 50),
145
+ held_until: CardOutcomes.heldUntil(answer),
146
+ });
147
+ }
148
+ catch {
149
+ // Evidence after the fact; never the request's failure.
150
+ }
151
+ }
152
+ /** The issuer's authorization matched the hold and claimed its grant. */
153
+ claimed(intentId, grantId) {
154
+ try {
155
+ this.recorder.note({
156
+ version: CARD_OUTCOME_FACT_VERSION,
157
+ kind: "CLAIMED",
158
+ at: new Date().toISOString(),
159
+ intent_id: intentId,
160
+ grant_id: grantId,
161
+ });
162
+ }
163
+ catch {
164
+ // Evidence after the fact; never the request's failure.
165
+ }
166
+ }
167
+ /** What the issuer said it did with the authorization that claimed the grant. */
168
+ settled(intentId, outcome, receiptDigest) {
169
+ try {
170
+ this.recorder.note({
171
+ version: CARD_OUTCOME_FACT_VERSION,
172
+ kind: "SETTLED",
173
+ at: new Date().toISOString(),
174
+ intent_id: intentId,
175
+ outcome,
176
+ receipt_digest: /^sha256:[0-9a-f]{64}$/.test(receiptDigest) ? receiptDigest : null,
177
+ });
178
+ }
179
+ catch {
180
+ // Evidence after the fact; never the request's failure.
181
+ }
182
+ }
183
+ /** The held grant's expiry, when the answer held one for the issuer. */
184
+ static heldUntil(answer) {
185
+ if (answer.outcome !== "HELD_FOR_AUTHORIZATION")
186
+ return null;
187
+ const expires = answer.result?.expires_at;
188
+ return typeof expires === "string" ? expires : null;
189
+ }
190
+ }
191
+ //# sourceMappingURL=CardOutcomes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardOutcomes.js","sourceRoot":"","sources":["../../src/outcomes/CardOutcomes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAKrF,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACL,yBAAyB,GAE1B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EACL,wBAAwB,GAEzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,2DAA2D;AAC3D,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAkBnE;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YAAY;IAEJ;IACA;IAFnB,YACmB,QAA6B,EAC7B,SAA0C;QAD1C,aAAQ,GAAR,QAAQ,CAAqB;QAC7B,cAAS,GAAT,SAAS,CAAiC;IAC1D,CAAC;IAEJ,uDAAuD;IAChD,MAAM,CAAC,MAAM,CAAC,OAA4B;QAC/C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QACnC,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK;YAAE,OAAO,IAAI,CAAC;QACvC,MAAM,MAAM,GACV,OAAO,CAAC,MAAM;YACd,IAAI,qBAAqB,CACvB,MAAM,CAAC,GAAG,EACV,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAA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QAC7D,MAAM,OAAO,GAAI,MAAM,CAAC,MAAmD,EAAE,UAAU,CAAC;QACxF,OAAO,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACtD,CAAC;CACF"}
@@ -0,0 +1,54 @@
1
+ import type { FetchLike } from "../handlers/HandlerRegistration.js";
2
+ import { type OutcomeEvidenceSubmission } from "./OutcomeEvidence.js";
3
+ export declare const CORE_OUTCOME_EVIDENCE_PATH = "/v1/outcomes/evidence";
4
+ /** Submissions carry up to a thousand subjects; Core's answer is two counts. */
5
+ export declare const OUTCOME_SUBMIT_TIMEOUT_MS = 15000;
6
+ /** Core's evidence resource, as the publisher sees it. */
7
+ export interface OutcomeEvidenceSink {
8
+ submit(submission: OutcomeEvidenceSubmission): Promise<{
9
+ readonly accepted: number;
10
+ readonly duplicates: number;
11
+ }>;
12
+ }
13
+ /**
14
+ * A refused submission. A `permanent` refusal is one the same submission cannot get past by
15
+ * being sent again (evidence Core refuses, a producer it does not know or does not allow); any
16
+ * other is retried later. `conflict` names a subject Core already holds at that revision with
17
+ * other content, which the next attempt states under a higher revision.
18
+ */
19
+ export declare class OutcomeEvidenceRefusal extends Error {
20
+ readonly code: string;
21
+ readonly permanent: boolean;
22
+ readonly conflict: string | null;
23
+ constructor(code: string, permanent: boolean, conflict?: string | null);
24
+ }
25
+ export interface CoreOutcomeEvidenceClientOptions {
26
+ /** The authority's base URL, already normalized: Core serves the meter beside it. */
27
+ readonly baseUrl: string;
28
+ /** The producer token, read at the moment of each request and never held. */
29
+ readonly token: () => string;
30
+ /** The guarded fetch: the authority's origin and trust anchors, and nothing else. */
31
+ readonly fetch: FetchLike;
32
+ readonly timeoutMs?: number;
33
+ }
34
+ /**
35
+ * `POST {DECIONIS_API_URL}/v1/outcomes/evidence` with AgentSafe's producer token, the credential
36
+ * Core's producer registry names with `outcomes: "agentsafe"`; a customer's own key is never a
37
+ * producer, so the bank's API key cannot feed the meter that measures it. A 503
38
+ * (`outcomes_disabled`, `outcomes_unavailable`), a timeout or an outage is retried later; a 409
39
+ * names the subject Core already holds at that revision. Core's body, the URL and the token
40
+ * never leave this class.
41
+ */
42
+ export declare class CoreOutcomeEvidenceClient implements OutcomeEvidenceSink {
43
+ private readonly options;
44
+ private readonly url;
45
+ private readonly timeoutMs;
46
+ constructor(options: CoreOutcomeEvidenceClientOptions);
47
+ submit(submission: OutcomeEvidenceSubmission): Promise<{
48
+ readonly accepted: number;
49
+ readonly duplicates: number;
50
+ }>;
51
+ /** Core's answer as an object, or an empty one when it is not one. */
52
+ private static object;
53
+ }
54
+ //# sourceMappingURL=CoreOutcomeEvidenceClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoreOutcomeEvidenceClient.d.ts","sourceRoot":"","sources":["../../src/outcomes/CoreOutcomeEvidenceClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAmB,KAAK,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEvF,eAAO,MAAM,0BAA0B,0BAA0B,CAAC;AAClE,gFAAgF;AAChF,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAEhD,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IAClC,MAAM,CACJ,UAAU,EAAE,yBAAyB,GACpC,OAAO,CAAC;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACxE;AAED;;;;;GAKG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;aAE7B,IAAI,EAAE,MAAM;aACZ,SAAS,EAAE,OAAO;aAClB,QAAQ,EAAE,MAAM,GAAG,IAAI;gBAFvB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,OAAO,EAClB,QAAQ,GAAE,MAAM,GAAG,IAAW;CAKjD;AAiBD,MAAM,WAAW,gCAAgC;IAC/C,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,MAAM,MAAM,CAAC;IAC7B,qFAAqF;IACrF,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,qBAAa,yBAA0B,YAAW,mBAAmB;IAIhD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAH3C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEC,OAAO,EAAE,gCAAgC;IAKhE,MAAM,CACjB,UAAU,EAAE,yBAAyB,GACpC,OAAO,CAAC;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IA+CtE,sEAAsE;IACtE,OAAO,CAAC,MAAM,CAAC,MAAM;CAUtB"}
@@ -0,0 +1,116 @@
1
+ import { isOutcomeDigest } from "./OutcomeEvidence.js";
2
+ export const CORE_OUTCOME_EVIDENCE_PATH = "/v1/outcomes/evidence";
3
+ /** Submissions carry up to a thousand subjects; Core's answer is two counts. */
4
+ export const OUTCOME_SUBMIT_TIMEOUT_MS = 15_000;
5
+ /**
6
+ * A refused submission. A `permanent` refusal is one the same submission cannot get past by
7
+ * being sent again (evidence Core refuses, a producer it does not know or does not allow); any
8
+ * other is retried later. `conflict` names a subject Core already holds at that revision with
9
+ * other content, which the next attempt states under a higher revision.
10
+ */
11
+ export class OutcomeEvidenceRefusal extends Error {
12
+ code;
13
+ permanent;
14
+ conflict;
15
+ constructor(code, permanent, conflict = null) {
16
+ super(code);
17
+ this.code = code;
18
+ this.permanent = permanent;
19
+ this.conflict = conflict;
20
+ this.name = "OutcomeEvidenceRefusal";
21
+ }
22
+ }
23
+ /** Core's refusals a retry of the same submission cannot fix. */
24
+ const PERMANENT = {
25
+ 400: "OUTCOME_EVIDENCE_REFUSED",
26
+ 401: "OUTCOME_PRODUCER_REQUIRED",
27
+ 403: "OUTCOME_PRODUCER_NOT_ALLOWED",
28
+ 404: "OUTCOME_ROUTE_OR_ORGANIZATION_MISSING",
29
+ 413: "OUTCOME_EVIDENCE_REFUSED",
30
+ 422: "OUTCOME_EVIDENCE_REFUSED",
31
+ };
32
+ /** What Core's producer registry accepts as a token: printable ASCII, 32 to 512 characters. */
33
+ const TOKEN = /^[\x21-\x7e]{32,512}$/;
34
+ const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
35
+ /**
36
+ * `POST {DECIONIS_API_URL}/v1/outcomes/evidence` with AgentSafe's producer token, the credential
37
+ * Core's producer registry names with `outcomes: "agentsafe"`; a customer's own key is never a
38
+ * producer, so the bank's API key cannot feed the meter that measures it. A 503
39
+ * (`outcomes_disabled`, `outcomes_unavailable`), a timeout or an outage is retried later; a 409
40
+ * names the subject Core already holds at that revision. Core's body, the URL and the token
41
+ * never leave this class.
42
+ */
43
+ export class CoreOutcomeEvidenceClient {
44
+ options;
45
+ url;
46
+ timeoutMs;
47
+ constructor(options) {
48
+ this.options = options;
49
+ this.url = `${options.baseUrl}${CORE_OUTCOME_EVIDENCE_PATH}`;
50
+ this.timeoutMs = options.timeoutMs ?? OUTCOME_SUBMIT_TIMEOUT_MS;
51
+ }
52
+ async submit(submission) {
53
+ let token;
54
+ try {
55
+ token = this.options.token();
56
+ }
57
+ catch {
58
+ throw new OutcomeEvidenceRefusal("OUTCOME_PRODUCER_TOKEN_UNAVAILABLE", false);
59
+ }
60
+ if (!TOKEN.test(token))
61
+ throw new OutcomeEvidenceRefusal("OUTCOME_PRODUCER_TOKEN_INVALID", true);
62
+ const controller = new AbortController();
63
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
64
+ let status;
65
+ let text;
66
+ try {
67
+ const response = await this.options.fetch(this.url, {
68
+ method: "POST",
69
+ headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
70
+ body: JSON.stringify(submission),
71
+ redirect: "error",
72
+ signal: controller.signal,
73
+ });
74
+ status = response.status;
75
+ text = await response.text();
76
+ }
77
+ catch {
78
+ throw new OutcomeEvidenceRefusal("OUTCOME_EVIDENCE_UNAVAILABLE", false);
79
+ }
80
+ finally {
81
+ clearTimeout(timer);
82
+ }
83
+ const answer = CoreOutcomeEvidenceClient.object(text);
84
+ if (status === 409) {
85
+ const subject = answer["subject_digest"];
86
+ if (answer["error"] === "evidence_revision_conflict" && isOutcomeDigest(subject)) {
87
+ throw new OutcomeEvidenceRefusal("OUTCOME_EVIDENCE_REVISION_CONFLICT", false, subject);
88
+ }
89
+ throw new OutcomeEvidenceRefusal("OUTCOME_EVIDENCE_CONFLICT", true);
90
+ }
91
+ const permanent = PERMANENT[status];
92
+ if (permanent !== undefined)
93
+ throw new OutcomeEvidenceRefusal(permanent, true);
94
+ if (status !== 200)
95
+ throw new OutcomeEvidenceRefusal("OUTCOME_EVIDENCE_UNAVAILABLE", false);
96
+ const accepted = answer["accepted"];
97
+ const duplicates = answer["duplicates"];
98
+ if (!count(accepted) || !count(duplicates)) {
99
+ throw new OutcomeEvidenceRefusal("OUTCOME_EVIDENCE_RESPONSE_INVALID", false);
100
+ }
101
+ return { accepted, duplicates };
102
+ }
103
+ /** Core's answer as an object, or an empty one when it is not one. */
104
+ static object(text) {
105
+ try {
106
+ const value = JSON.parse(text);
107
+ return value !== null && typeof value === "object" && !Array.isArray(value)
108
+ ? value
109
+ : {};
110
+ }
111
+ catch {
112
+ return {};
113
+ }
114
+ }
115
+ }
116
+ //# sourceMappingURL=CoreOutcomeEvidenceClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoreOutcomeEvidenceClient.js","sourceRoot":"","sources":["../../src/outcomes/CoreOutcomeEvidenceClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAkC,MAAM,sBAAsB,CAAC;A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