@decionis/agentsafe 0.2.5 → 0.4.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 (299) hide show
  1. package/README.md +264 -89
  2. package/dist/Cli.js +24 -0
  3. package/dist/Cli.js.map +1 -1
  4. package/dist/Index.d.ts +10 -4
  5. package/dist/Index.d.ts.map +1 -1
  6. package/dist/Index.js +8 -2
  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/AdapterActionHandler.d.ts.map +1 -1
  12. package/dist/adapters/AdapterActionHandler.js +8 -4
  13. package/dist/adapters/AdapterActionHandler.js.map +1 -1
  14. package/dist/adapters/EffectAdapter.d.ts +6 -1
  15. package/dist/adapters/EffectAdapter.d.ts.map +1 -1
  16. package/dist/adapters/EffectAdapter.js +7 -1
  17. package/dist/adapters/EffectAdapter.js.map +1 -1
  18. package/dist/adapters/EffectAwareGrantVerifier.d.ts +5 -2
  19. package/dist/adapters/EffectAwareGrantVerifier.d.ts.map +1 -1
  20. package/dist/adapters/EffectAwareGrantVerifier.js +9 -0
  21. package/dist/adapters/EffectAwareGrantVerifier.js.map +1 -1
  22. package/dist/adapters/banking/BankingAction.d.ts +2 -2
  23. package/dist/adapters/banking/CoreBankingHttpAdapter.d.ts.map +1 -1
  24. package/dist/adapters/banking/CoreBankingHttpAdapter.js +4 -4
  25. package/dist/adapters/banking/CoreBankingHttpAdapter.js.map +1 -1
  26. package/dist/adapters/cards/CardAuthorizationMatcher.d.ts +44 -0
  27. package/dist/adapters/cards/CardAuthorizationMatcher.d.ts.map +1 -0
  28. package/dist/adapters/cards/CardAuthorizationMatcher.js +39 -0
  29. package/dist/adapters/cards/CardAuthorizationMatcher.js.map +1 -0
  30. package/dist/adapters/cards/CardEffect.d.ts +52 -0
  31. package/dist/adapters/cards/CardEffect.d.ts.map +1 -0
  32. package/dist/adapters/cards/CardEffect.js +117 -0
  33. package/dist/adapters/cards/CardEffect.js.map +1 -0
  34. package/dist/adapters/cards/CardHandlers.d.ts +15 -0
  35. package/dist/adapters/cards/CardHandlers.d.ts.map +1 -0
  36. package/dist/adapters/cards/CardHandlers.js +26 -0
  37. package/dist/adapters/cards/CardHandlers.js.map +1 -0
  38. package/dist/adapters/cards/CardHoldSeal.d.ts +29 -0
  39. package/dist/adapters/cards/CardHoldSeal.d.ts.map +1 -0
  40. package/dist/adapters/cards/CardHoldSeal.js +87 -0
  41. package/dist/adapters/cards/CardHoldSeal.js.map +1 -0
  42. package/dist/adapters/cards/CardHoldStore.d.ts +102 -0
  43. package/dist/adapters/cards/CardHoldStore.d.ts.map +1 -0
  44. package/dist/adapters/cards/CardHoldStore.js +9 -0
  45. package/dist/adapters/cards/CardHoldStore.js.map +1 -0
  46. package/dist/adapters/cards/CardHolds.d.ts +19 -0
  47. package/dist/adapters/cards/CardHolds.d.ts.map +1 -0
  48. package/dist/adapters/cards/CardHolds.js +57 -0
  49. package/dist/adapters/cards/CardHolds.js.map +1 -0
  50. package/dist/adapters/cards/CardPurchase.d.ts +61 -0
  51. package/dist/adapters/cards/CardPurchase.d.ts.map +1 -0
  52. package/dist/adapters/cards/CardPurchase.js +116 -0
  53. package/dist/adapters/cards/CardPurchase.js.map +1 -0
  54. package/dist/adapters/cards/HeldCardGrants.d.ts +69 -0
  55. package/dist/adapters/cards/HeldCardGrants.d.ts.map +1 -0
  56. package/dist/adapters/cards/HeldCardGrants.js +169 -0
  57. package/dist/adapters/cards/HeldCardGrants.js.map +1 -0
  58. package/dist/adapters/cards/Pan.d.ts +17 -0
  59. package/dist/adapters/cards/Pan.d.ts.map +1 -0
  60. package/dist/adapters/cards/Pan.js +52 -0
  61. package/dist/adapters/cards/Pan.js.map +1 -0
  62. package/dist/adapters/cards/PostgresCardHolds.d.ts +95 -0
  63. package/dist/adapters/cards/PostgresCardHolds.d.ts.map +1 -0
  64. package/dist/adapters/cards/PostgresCardHolds.js +411 -0
  65. package/dist/adapters/cards/PostgresCardHolds.js.map +1 -0
  66. package/dist/adapters/mcp/McpGuard.d.ts.map +1 -1
  67. package/dist/adapters/mcp/McpGuard.js +9 -4
  68. package/dist/adapters/mcp/McpGuard.js.map +1 -1
  69. package/dist/audit/HashChain.d.ts +8 -2
  70. package/dist/audit/HashChain.d.ts.map +1 -1
  71. package/dist/audit/HashChain.js +14 -2
  72. package/dist/audit/HashChain.js.map +1 -1
  73. package/dist/cli/Cards.d.ts +5 -0
  74. package/dist/cli/Cards.d.ts.map +1 -0
  75. package/dist/cli/Cards.js +48 -0
  76. package/dist/cli/Cards.js.map +1 -0
  77. package/dist/cli/Commands.d.ts +1 -1
  78. package/dist/cli/Commands.d.ts.map +1 -1
  79. package/dist/cli/Commands.js +5 -0
  80. package/dist/cli/Commands.js.map +1 -1
  81. package/dist/cli/Edge.d.ts +4 -0
  82. package/dist/cli/Edge.d.ts.map +1 -0
  83. package/dist/cli/Edge.js +250 -0
  84. package/dist/cli/Edge.js.map +1 -0
  85. package/dist/cli/Help.d.ts.map +1 -1
  86. package/dist/cli/Help.js +9 -0
  87. package/dist/cli/Help.js.map +1 -1
  88. package/dist/cli/Host.d.ts +36 -0
  89. package/dist/cli/Host.d.ts.map +1 -0
  90. package/dist/cli/Host.js +247 -0
  91. package/dist/cli/Host.js.map +1 -0
  92. package/dist/cli/TcpBrokerCli.d.ts +4 -0
  93. package/dist/cli/TcpBrokerCli.d.ts.map +1 -0
  94. package/dist/cli/TcpBrokerCli.js +93 -0
  95. package/dist/cli/TcpBrokerCli.js.map +1 -0
  96. package/dist/cli/TcpClientCli.d.ts +16 -0
  97. package/dist/cli/TcpClientCli.d.ts.map +1 -0
  98. package/dist/cli/TcpClientCli.js +175 -0
  99. package/dist/cli/TcpClientCli.js.map +1 -0
  100. package/dist/config/ConfigKeys.d.ts +2 -2
  101. package/dist/config/ConfigKeys.d.ts.map +1 -1
  102. package/dist/config/ConfigKeys.js +31 -0
  103. package/dist/config/ConfigKeys.js.map +1 -1
  104. package/dist/config/ExecutorConfig.d.ts +115 -0
  105. package/dist/config/ExecutorConfig.d.ts.map +1 -1
  106. package/dist/config/ExecutorConfig.js +212 -0
  107. package/dist/config/ExecutorConfig.js.map +1 -1
  108. package/dist/edge/EdgeLicence.d.ts +25 -0
  109. package/dist/edge/EdgeLicence.d.ts.map +1 -0
  110. package/dist/edge/EdgeLicence.js +42 -0
  111. package/dist/edge/EdgeLicence.js.map +1 -0
  112. package/dist/edge/EdgeReplay.d.ts +45 -0
  113. package/dist/edge/EdgeReplay.d.ts.map +1 -0
  114. package/dist/edge/EdgeReplay.js +69 -0
  115. package/dist/edge/EdgeReplay.js.map +1 -0
  116. package/dist/edge/Entitlement.d.ts +57 -0
  117. package/dist/edge/Entitlement.d.ts.map +1 -0
  118. package/dist/edge/Entitlement.js +139 -0
  119. package/dist/edge/Entitlement.js.map +1 -0
  120. package/dist/edge/EntitlementEvaluation.d.ts +66 -0
  121. package/dist/edge/EntitlementEvaluation.d.ts.map +1 -0
  122. package/dist/edge/EntitlementEvaluation.js +74 -0
  123. package/dist/edge/EntitlementEvaluation.js.map +1 -0
  124. package/dist/edge/UsageCount.d.ts +40 -0
  125. package/dist/edge/UsageCount.d.ts.map +1 -0
  126. package/dist/edge/UsageCount.js +140 -0
  127. package/dist/edge/UsageCount.js.map +1 -0
  128. package/dist/edge/UsageKeyRegistration.d.ts +34 -0
  129. package/dist/edge/UsageKeyRegistration.d.ts.map +1 -0
  130. package/dist/edge/UsageKeyRegistration.js +74 -0
  131. package/dist/edge/UsageKeyRegistration.js.map +1 -0
  132. package/dist/edge/UsageMeter.d.ts +89 -0
  133. package/dist/edge/UsageMeter.d.ts.map +1 -0
  134. package/dist/edge/UsageMeter.js +275 -0
  135. package/dist/edge/UsageMeter.js.map +1 -0
  136. package/dist/edge/UsagePeriod.d.ts +23 -0
  137. package/dist/edge/UsagePeriod.d.ts.map +1 -0
  138. package/dist/edge/UsagePeriod.js +31 -0
  139. package/dist/edge/UsagePeriod.js.map +1 -0
  140. package/dist/edge/UsageReport.d.ts +92 -0
  141. package/dist/edge/UsageReport.d.ts.map +1 -0
  142. package/dist/edge/UsageReport.js +153 -0
  143. package/dist/edge/UsageReport.js.map +1 -0
  144. package/dist/edge/UsageTally.d.ts +63 -0
  145. package/dist/edge/UsageTally.d.ts.map +1 -0
  146. package/dist/edge/UsageTally.js +89 -0
  147. package/dist/edge/UsageTally.js.map +1 -0
  148. package/dist/egress/EgressError.d.ts +7 -1
  149. package/dist/egress/EgressError.d.ts.map +1 -1
  150. package/dist/egress/EgressError.js.map +1 -1
  151. package/dist/egress/EgressPolicy.d.ts +16 -3
  152. package/dist/egress/EgressPolicy.d.ts.map +1 -1
  153. package/dist/egress/EgressPolicy.js +33 -3
  154. package/dist/egress/EgressPolicy.js.map +1 -1
  155. package/dist/egress/GuardedFetch.d.ts +38 -1
  156. package/dist/egress/GuardedFetch.d.ts.map +1 -1
  157. package/dist/egress/GuardedFetch.js +52 -7
  158. package/dist/egress/GuardedFetch.js.map +1 -1
  159. package/dist/egress/TcpClient.d.ts +103 -0
  160. package/dist/egress/TcpClient.d.ts.map +1 -0
  161. package/dist/egress/TcpClient.js +490 -0
  162. package/dist/egress/TcpClient.js.map +1 -0
  163. package/dist/egress/TcpControlClient.d.ts +49 -0
  164. package/dist/egress/TcpControlClient.d.ts.map +1 -0
  165. package/dist/egress/TcpControlClient.js +186 -0
  166. package/dist/egress/TcpControlClient.js.map +1 -0
  167. package/dist/gateway/ForwardHandler.d.ts.map +1 -1
  168. package/dist/gateway/ForwardHandler.js +7 -4
  169. package/dist/gateway/ForwardHandler.js.map +1 -1
  170. package/dist/gateway/Gateway.d.ts +190 -10
  171. package/dist/gateway/Gateway.d.ts.map +1 -1
  172. package/dist/gateway/Gateway.js +465 -62
  173. package/dist/gateway/Gateway.js.map +1 -1
  174. package/dist/gateway/GatewayConfig.d.ts +67 -0
  175. package/dist/gateway/GatewayConfig.d.ts.map +1 -1
  176. package/dist/gateway/GatewayConfig.js +149 -2
  177. package/dist/gateway/GatewayConfig.js.map +1 -1
  178. package/dist/gateway/InterceptedRequest.d.ts +9 -2
  179. package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
  180. package/dist/gateway/InterceptedRequest.js +41 -9
  181. package/dist/gateway/InterceptedRequest.js.map +1 -1
  182. package/dist/gateway/RateLimit.d.ts +29 -0
  183. package/dist/gateway/RateLimit.d.ts.map +1 -0
  184. package/dist/gateway/RateLimit.js +33 -0
  185. package/dist/gateway/RateLimit.js.map +1 -0
  186. package/dist/gateway/RefusalSampler.d.ts +28 -0
  187. package/dist/gateway/RefusalSampler.d.ts.map +1 -0
  188. package/dist/gateway/RefusalSampler.js +52 -0
  189. package/dist/gateway/RefusalSampler.js.map +1 -0
  190. package/dist/gateway/RouteTable.d.ts +3 -0
  191. package/dist/gateway/RouteTable.d.ts.map +1 -1
  192. package/dist/gateway/RouteTable.js +44 -7
  193. package/dist/gateway/RouteTable.js.map +1 -1
  194. package/dist/gateway/Upstream.d.ts +26 -0
  195. package/dist/gateway/Upstream.d.ts.map +1 -1
  196. package/dist/gateway/Upstream.js +41 -2
  197. package/dist/gateway/Upstream.js.map +1 -1
  198. package/dist/gateway/UpstreamProof.d.ts +235 -0
  199. package/dist/gateway/UpstreamProof.d.ts.map +1 -0
  200. package/dist/gateway/UpstreamProof.js +375 -0
  201. package/dist/gateway/UpstreamProof.js.map +1 -0
  202. package/dist/handlers/ForwardRequestHandler.d.ts +5 -1
  203. package/dist/handlers/ForwardRequestHandler.d.ts.map +1 -1
  204. package/dist/handlers/ForwardRequestHandler.js +12 -2
  205. package/dist/handlers/ForwardRequestHandler.js.map +1 -1
  206. package/dist/hosted/TenantHost.d.ts +180 -0
  207. package/dist/hosted/TenantHost.d.ts.map +1 -0
  208. package/dist/hosted/TenantHost.js +432 -0
  209. package/dist/hosted/TenantHost.js.map +1 -0
  210. package/dist/hosted/TenantRegistry.d.ts +73 -0
  211. package/dist/hosted/TenantRegistry.d.ts.map +1 -0
  212. package/dist/hosted/TenantRegistry.js +123 -0
  213. package/dist/hosted/TenantRegistry.js.map +1 -0
  214. package/dist/http/ExecutorHttpServer.d.ts +7 -0
  215. package/dist/http/ExecutorHttpServer.d.ts.map +1 -1
  216. package/dist/http/ExecutorHttpServer.js +30 -5
  217. package/dist/http/ExecutorHttpServer.js.map +1 -1
  218. package/dist/http/GatewayHttpServer.d.ts +55 -3
  219. package/dist/http/GatewayHttpServer.d.ts.map +1 -1
  220. package/dist/http/GatewayHttpServer.js +157 -17
  221. package/dist/http/GatewayHttpServer.js.map +1 -1
  222. package/dist/http/RedirectServer.d.ts +26 -0
  223. package/dist/http/RedirectServer.d.ts.map +1 -0
  224. package/dist/http/RedirectServer.js +62 -0
  225. package/dist/http/RedirectServer.js.map +1 -0
  226. package/dist/http/Routes.d.ts +24 -0
  227. package/dist/http/Routes.d.ts.map +1 -1
  228. package/dist/http/Routes.js +28 -1
  229. package/dist/http/Routes.js.map +1 -1
  230. package/dist/http/TcpBroker.d.ts +57 -0
  231. package/dist/http/TcpBroker.d.ts.map +1 -0
  232. package/dist/http/TcpBroker.js +299 -0
  233. package/dist/http/TcpBroker.js.map +1 -0
  234. package/dist/http/TcpHostRelay.d.ts +24 -0
  235. package/dist/http/TcpHostRelay.d.ts.map +1 -0
  236. package/dist/http/TcpHostRelay.js +194 -0
  237. package/dist/http/TcpHostRelay.js.map +1 -0
  238. package/dist/http/TcpRelayStreams.d.ts +24 -0
  239. package/dist/http/TcpRelayStreams.d.ts.map +1 -0
  240. package/dist/http/TcpRelayStreams.js +128 -0
  241. package/dist/http/TcpRelayStreams.js.map +1 -0
  242. package/dist/http/TlsListener.d.ts +3 -1
  243. package/dist/http/TlsListener.d.ts.map +1 -1
  244. package/dist/http/TlsListener.js +7 -2
  245. package/dist/http/TlsListener.js.map +1 -1
  246. package/dist/identity/Authenticator.d.ts.map +1 -1
  247. package/dist/identity/Authenticator.js +5 -2
  248. package/dist/identity/Authenticator.js.map +1 -1
  249. package/dist/identity/PrincipalsFile.d.ts +5 -1
  250. package/dist/identity/PrincipalsFile.d.ts.map +1 -1
  251. package/dist/identity/PrincipalsFile.js +2 -0
  252. package/dist/identity/PrincipalsFile.js.map +1 -1
  253. package/dist/incident/Metrics.d.ts +2 -0
  254. package/dist/incident/Metrics.d.ts.map +1 -1
  255. package/dist/incident/Metrics.js +10 -0
  256. package/dist/incident/Metrics.js.map +1 -1
  257. package/dist/incident/SecurityEvents.d.ts +98 -0
  258. package/dist/incident/SecurityEvents.d.ts.map +1 -1
  259. package/dist/incident/SecurityEvents.js +96 -2
  260. package/dist/incident/SecurityEvents.js.map +1 -1
  261. package/dist/journal/ExecutionJournal.d.ts +27 -0
  262. package/dist/journal/ExecutionJournal.d.ts.map +1 -1
  263. package/dist/journal/ExecutionJournal.js +28 -0
  264. package/dist/journal/ExecutionJournal.js.map +1 -1
  265. package/dist/journal/FileExecutionJournal.d.ts +2 -1
  266. package/dist/journal/FileExecutionJournal.d.ts.map +1 -1
  267. package/dist/journal/FileExecutionJournal.js +4 -1
  268. package/dist/journal/FileExecutionJournal.js.map +1 -1
  269. package/dist/journal/InMemoryExecutionJournal.d.ts +2 -1
  270. package/dist/journal/InMemoryExecutionJournal.d.ts.map +1 -1
  271. package/dist/journal/InMemoryExecutionJournal.js +4 -1
  272. package/dist/journal/InMemoryExecutionJournal.js.map +1 -1
  273. package/dist/service/AuthorityClients.d.ts +8 -1
  274. package/dist/service/AuthorityClients.d.ts.map +1 -1
  275. package/dist/service/AuthorityClients.js +33 -5
  276. package/dist/service/AuthorityClients.js.map +1 -1
  277. package/dist/service/EdgeRuntime.d.ts +73 -0
  278. package/dist/service/EdgeRuntime.d.ts.map +1 -0
  279. package/dist/service/EdgeRuntime.js +209 -0
  280. package/dist/service/EdgeRuntime.js.map +1 -0
  281. package/dist/service/EscalationResolver.d.ts +109 -5
  282. package/dist/service/EscalationResolver.d.ts.map +1 -1
  283. package/dist/service/EscalationResolver.js +41 -3
  284. package/dist/service/EscalationResolver.js.map +1 -1
  285. package/dist/service/Requests.d.ts +45 -2
  286. package/dist/service/Requests.d.ts.map +1 -1
  287. package/dist/service/TrustedExecutorService.d.ts +144 -1
  288. package/dist/service/TrustedExecutorService.d.ts.map +1 -1
  289. package/dist/service/TrustedExecutorService.js +866 -37
  290. package/dist/service/TrustedExecutorService.js.map +1 -1
  291. package/dist/tcp/TcpWire.d.ts +18 -0
  292. package/dist/tcp/TcpWire.d.ts.map +1 -0
  293. package/dist/tcp/TcpWire.js +114 -0
  294. package/dist/tcp/TcpWire.js.map +1 -0
  295. package/dist/verify/VerifyAuditChain.d.ts +5 -0
  296. package/dist/verify/VerifyAuditChain.d.ts.map +1 -1
  297. package/dist/verify/VerifyAuditChain.js +20 -4
  298. package/dist/verify/VerifyAuditChain.js.map +1 -1
  299. package/package.json +7 -3
@@ -0,0 +1,44 @@
1
+ /** A held grant, as the matcher sees it: what was authorised, until when, and whether it is spent. */
2
+ export interface HeldCardGrantView {
3
+ readonly cardTokenRef: string;
4
+ readonly amountMinor: number;
5
+ readonly currency: string;
6
+ readonly merchantId: string;
7
+ /** The merchant category the purchase named, or null when it named none. */
8
+ readonly mcc: string | null;
9
+ readonly expiresAtMs: number;
10
+ /** True once an authorization has matched it, whatever happened next. */
11
+ readonly used: boolean;
12
+ }
13
+ /** An authorization, as the matcher sees it. */
14
+ export interface CardAuthorizationView {
15
+ readonly cardTokenRef: string;
16
+ readonly amountMinor: number;
17
+ readonly currency: string;
18
+ readonly merchantId: string;
19
+ readonly mcc: string | null;
20
+ }
21
+ export type CardNoMatchCode = "NO_GRANT" | "GRANT_ALREADY_USED" | "GRANT_EXPIRED" | "CARD_TOKEN_MISMATCH" | "CURRENCY_MISMATCH" | "MERCHANT_MISMATCH" | "MCC_MISMATCH" | "AMOUNT_EXCEEDS_GRANT";
22
+ export type CardMatch = {
23
+ readonly decision: "MATCHED";
24
+ } | {
25
+ readonly decision: "NO_MATCH";
26
+ readonly code: CardNoMatchCode;
27
+ };
28
+ /**
29
+ * Whether an issuer's authorization is the purchase a held grant authorised.
30
+ * Pure and synchronous, because it runs inside a card authorization's
31
+ * millisecond budget: it reaches nothing and reads no clock of its own.
32
+ *
33
+ * Every rule is an equality or a ceiling over what the authority bound, and
34
+ * the first that fails names the answer, in a fixed order: whether there is
35
+ * a grant at all, whether it is still spendable, and then the purchase field
36
+ * by field. An amount at or below the grant matches, because an issuer may
37
+ * authorise less than was approved and never more. A merchant category is
38
+ * only compared when the purchase named one.
39
+ *
40
+ * `NO_MATCH` is a statement, not a decline: what it means for the
41
+ * authorization is the issuer's own policy.
42
+ */
43
+ export declare function matchCardAuthorization(grant: HeldCardGrantView | undefined, authorization: CardAuthorizationView, nowMs: number): CardMatch;
44
+ //# sourceMappingURL=CardAuthorizationMatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardAuthorizationMatcher.d.ts","sourceRoot":"","sources":["../../../src/adapters/cards/CardAuthorizationMatcher.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,gDAAgD;AAChD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,oBAAoB,GACpB,eAAe,GACf,qBAAqB,GACrB,mBAAmB,GACnB,mBAAmB,GACnB,cAAc,GACd,sBAAsB,CAAC;AAE3B,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,GAChC;IAAE,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;CAAE,CAAC;AAEtE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,iBAAiB,GAAG,SAAS,EACpC,aAAa,EAAE,qBAAqB,EACpC,KAAK,EAAE,MAAM,GACZ,SAAS,CAGX"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Whether an issuer's authorization is the purchase a held grant authorised.
3
+ * Pure and synchronous, because it runs inside a card authorization's
4
+ * millisecond budget: it reaches nothing and reads no clock of its own.
5
+ *
6
+ * Every rule is an equality or a ceiling over what the authority bound, and
7
+ * the first that fails names the answer, in a fixed order: whether there is
8
+ * a grant at all, whether it is still spendable, and then the purchase field
9
+ * by field. An amount at or below the grant matches, because an issuer may
10
+ * authorise less than was approved and never more. A merchant category is
11
+ * only compared when the purchase named one.
12
+ *
13
+ * `NO_MATCH` is a statement, not a decline: what it means for the
14
+ * authorization is the issuer's own policy.
15
+ */
16
+ export function matchCardAuthorization(grant, authorization, nowMs) {
17
+ const code = mismatch(grant, authorization, nowMs);
18
+ return code === null ? { decision: "MATCHED" } : { decision: "NO_MATCH", code };
19
+ }
20
+ function mismatch(grant, authorization, nowMs) {
21
+ if (grant === undefined)
22
+ return "NO_GRANT";
23
+ if (grant.used)
24
+ return "GRANT_ALREADY_USED";
25
+ if (nowMs >= grant.expiresAtMs)
26
+ return "GRANT_EXPIRED";
27
+ if (authorization.cardTokenRef !== grant.cardTokenRef)
28
+ return "CARD_TOKEN_MISMATCH";
29
+ if (authorization.currency !== grant.currency)
30
+ return "CURRENCY_MISMATCH";
31
+ if (authorization.merchantId !== grant.merchantId)
32
+ return "MERCHANT_MISMATCH";
33
+ if (grant.mcc !== null && authorization.mcc !== grant.mcc)
34
+ return "MCC_MISMATCH";
35
+ if (authorization.amountMinor > grant.amountMinor)
36
+ return "AMOUNT_EXCEEDS_GRANT";
37
+ return null;
38
+ }
39
+ //# sourceMappingURL=CardAuthorizationMatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardAuthorizationMatcher.js","sourceRoot":"","sources":["../../../src/adapters/cards/CardAuthorizationMatcher.ts"],"names":[],"mappings":"AAoCA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAoC,EACpC,aAAoC,EACpC,KAAa;IAEb,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAClF,CAAC;AAED,SAAS,QAAQ,CACf,KAAoC,EACpC,aAAoC,EACpC,KAAa;IAEb,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,UAAU,CAAC;IAC3C,IAAI,KAAK,CAAC,IAAI;QAAE,OAAO,oBAAoB,CAAC;IAC5C,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW;QAAE,OAAO,eAAe,CAAC;IACvD,IAAI,aAAa,CAAC,YAAY,KAAK,KAAK,CAAC,YAAY;QAAE,OAAO,qBAAqB,CAAC;IACpF,IAAI,aAAa,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ;QAAE,OAAO,mBAAmB,CAAC;IAC1E,IAAI,aAAa,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU;QAAE,OAAO,mBAAmB,CAAC;IAC9E,IAAI,KAAK,CAAC,GAAG,KAAK,IAAI,IAAI,aAAa,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;QAAE,OAAO,cAAc,CAAC;IACjF,IAAI,aAAa,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW;QAAE,OAAO,sBAAsB,CAAC;IACjF,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { JsonObject } from "@decionis/agent-safe-pipeline";
2
+ import type { AdapterExecutionResult } from "../AdapterActionHandler.js";
3
+ import type { PreparedAction } from "../EffectAdapter.js";
4
+ import type { RegisteredEffect } from "../EffectEvidenceRegister.js";
5
+ import { type CardAuthorizationRequest, type CardAuthorizationResult, type CardPurchase } from "./CardPurchase.js";
6
+ export declare const CARD_EFFECT_TYPE = "CARD_PURCHASE_AUTHORIZATION";
7
+ /**
8
+ * What a card purchase asks for, as a projection the authority binds its
9
+ * grant to: this card, at this merchant (and category, when one was named),
10
+ * in this currency, for at most this amount. The amount is a ceiling, which
11
+ * is why the field says so: an issuer may authorise less than was approved,
12
+ * and an authorization that stayed inside the ceiling is the authorised
13
+ * effect, exactly.
14
+ */
15
+ export declare function cardExpectedEffect(purchase: CardPurchase): JsonObject;
16
+ /** The family's `prepare`: pure, reaching nothing, and the digests the intent is bound to. */
17
+ export declare function prepareCardPurchase(purchase: CardPurchase): PreparedAction;
18
+ export interface CardResultInput {
19
+ readonly purchase: CardPurchase;
20
+ readonly prepared: PreparedAction;
21
+ readonly authorization: CardAuthorizationRequest;
22
+ readonly result: CardAuthorizationResult;
23
+ /** The claim's lease had closed when the result arrived: nothing about it can be recorded as known. */
24
+ readonly leaseExpired: boolean;
25
+ readonly observer: {
26
+ readonly id: string;
27
+ readonly version: string;
28
+ };
29
+ readonly correlationId: string;
30
+ readonly idempotencyKey: string;
31
+ readonly observedAt: string;
32
+ }
33
+ /**
34
+ * The effect record for one card authorization, from what the issuer said
35
+ * about it. An approval is observed as the issuer stated it: the card,
36
+ * merchant, category and currency of the authorization it matched, and the
37
+ * ceiling, which held if the approved amount is at or below it and is the
38
+ * approved amount itself if it is not, so an issuer that approved more than
39
+ * was authorised is a mismatch on exactly that field. A decline is a
40
+ * refusal, and a result after the lease is indeterminate whatever it says,
41
+ * because the authority stopped accepting a commit for this claim.
42
+ */
43
+ export declare function cardResultRecord(input: CardResultInput): RegisteredEffect;
44
+ /**
45
+ * The record in the shape the response's effect block is read from, the
46
+ * same shape an adapter's handler returns; its outcome may also be
47
+ * `INDETERMINATE`, which a handler reports by throwing instead.
48
+ */
49
+ export declare function cardExecutionResult(record: RegisteredEffect): Omit<AdapterExecutionResult, "outcome"> & {
50
+ readonly outcome: RegisteredEffect["outcome"];
51
+ };
52
+ //# sourceMappingURL=CardEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardEffect.d.ts","sourceRoot":"","sources":["../../../src/adapters/cards/CardEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,qBAAqB,CAAC;AAE1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAE3B,eAAO,MAAM,gBAAgB,gCAAgC,CAAC;AAE9D;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,GAAG,UAAU,CAQrE;AAED,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,cAAc,CAY1E;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,wBAAwB,CAAC;IACjD,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,uGAAuG;IACvG,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACrE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CAgDzE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,GACvB,IAAI,CAAC,sBAAsB,EAAE,SAAS,CAAC,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAA;CAAE,CAgB7F"}
@@ -0,0 +1,117 @@
1
+ import { buildEffectRecord } from "../EffectEvidenceBuilder.js";
2
+ import { jcsDigest } from "../JcsDigest.js";
3
+ import { CARD_PURCHASE_ACTION, cardTarget, } from "./CardPurchase.js";
4
+ export const CARD_EFFECT_TYPE = "CARD_PURCHASE_AUTHORIZATION";
5
+ /**
6
+ * What a card purchase asks for, as a projection the authority binds its
7
+ * grant to: this card, at this merchant (and category, when one was named),
8
+ * in this currency, for at most this amount. The amount is a ceiling, which
9
+ * is why the field says so: an issuer may authorise less than was approved,
10
+ * and an authorization that stayed inside the ceiling is the authorised
11
+ * effect, exactly.
12
+ */
13
+ export function cardExpectedEffect(purchase) {
14
+ return {
15
+ card_token_ref: purchase.cardTokenRef,
16
+ merchant_id: purchase.merchantId,
17
+ ...(purchase.mcc === undefined ? {} : { mcc: purchase.mcc }),
18
+ currency: purchase.currency,
19
+ amount_minor_ceiling: purchase.amountMinor,
20
+ };
21
+ }
22
+ /** The family's `prepare`: pure, reaching nothing, and the digests the intent is bound to. */
23
+ export function prepareCardPurchase(purchase) {
24
+ const expectedEffect = cardExpectedEffect(purchase);
25
+ return {
26
+ expectedEffect,
27
+ expectedEffectDigest: jcsDigest(expectedEffect),
28
+ intentDigest: jcsDigest(purchase),
29
+ requestDigest: jcsDigest(purchase),
30
+ resourceRef: cardTarget(purchase),
31
+ effectType: CARD_EFFECT_TYPE,
32
+ domain: "CARDS",
33
+ actionType: CARD_PURCHASE_ACTION,
34
+ };
35
+ }
36
+ /**
37
+ * The effect record for one card authorization, from what the issuer said
38
+ * about it. An approval is observed as the issuer stated it: the card,
39
+ * merchant, category and currency of the authorization it matched, and the
40
+ * ceiling, which held if the approved amount is at or below it and is the
41
+ * approved amount itself if it is not, so an issuer that approved more than
42
+ * was authorised is a mismatch on exactly that field. A decline is a
43
+ * refusal, and a result after the lease is indeterminate whatever it says,
44
+ * because the authority stopped accepting a commit for this claim.
45
+ */
46
+ export function cardResultRecord(input) {
47
+ const { purchase, authorization, result } = input;
48
+ const responseDigest = jcsDigest(result);
49
+ const common = {
50
+ observer: input.observer,
51
+ correlationId: input.correlationId,
52
+ idempotencyKey: input.idempotencyKey,
53
+ observedAt: input.observedAt,
54
+ prepared: input.prepared,
55
+ };
56
+ if (input.leaseExpired) {
57
+ return buildEffectRecord({
58
+ ...common,
59
+ result: null,
60
+ indeterminate: { reason: "CLAIM_LEASE_EXPIRED", providerStatus: result.status },
61
+ });
62
+ }
63
+ const answered = {
64
+ providerStatus: result.status,
65
+ providerReference: authorization.authorization_id,
66
+ responseDigest,
67
+ observationMethod: "EVENT_CONFIRMATION",
68
+ providerGenerated: true,
69
+ source: "ISSUER_AUTHORIZATION_RESULT",
70
+ };
71
+ if (result.status === "DECLINED") {
72
+ const declined = {
73
+ ...answered,
74
+ status: "FAILED",
75
+ failureReason: "ISSUER_DECLINED",
76
+ observed: null,
77
+ };
78
+ return buildEffectRecord({ ...common, result: declined });
79
+ }
80
+ const approved = result.approved_amount_minor ?? authorization.amount_minor;
81
+ const approval = {
82
+ ...answered,
83
+ status: "COMMITTED",
84
+ failureReason: null,
85
+ observed: {
86
+ card_token_ref: authorization.card_token_ref,
87
+ merchant_id: authorization.merchant_id,
88
+ ...(purchase.mcc === undefined ? {} : { mcc: authorization.mcc ?? null }),
89
+ currency: authorization.currency,
90
+ amount_minor_ceiling: approved <= purchase.amountMinor ? purchase.amountMinor : approved,
91
+ },
92
+ };
93
+ return buildEffectRecord({ ...common, result: approval });
94
+ }
95
+ /**
96
+ * The record in the shape the response's effect block is read from, the
97
+ * same shape an adapter's handler returns; its outcome may also be
98
+ * `INDETERMINATE`, which a handler reports by throwing instead.
99
+ */
100
+ export function cardExecutionResult(record) {
101
+ return {
102
+ outcome: record.outcome,
103
+ confirmation: record.confirmation,
104
+ comparison: record.comparison,
105
+ mismatchedFields: record.mismatched,
106
+ observationMethod: record.observationMethod,
107
+ expectedEffectDigest: record.expectedEffectDigest,
108
+ observedEffectDigest: record.observedEffectDigest,
109
+ responseDigest: record.responseDigest,
110
+ providerReference: record.providerReference,
111
+ evidenceDigest: record.evidenceDigest,
112
+ reasonCodes: record.reasonCodes,
113
+ receiptComparison: record.receipt.comparison,
114
+ receiptStatus: record.receipt.status,
115
+ };
116
+ }
117
+ //# sourceMappingURL=CardEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardEffect.js","sourceRoot":"","sources":["../../../src/adapters/cards/CardEffect.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,oBAAoB,EACpB,UAAU,GAIX,MAAM,mBAAmB,CAAC;AAE3B,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AQ,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ;SACzF;KACF,CAAC;IACF,OAAO,iBAAiB,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAwB;IAExB,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,gBAAgB,EAAE,MAAM,CAAC,UAAU;QACnC,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAC3C,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAC3C,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,UAAU;QAC5C,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM;KACrC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { HandlerRegistration } from "../../handlers/HandlerRegistration.js";
2
+ /**
3
+ * The registration for the cards family: `card.purchase`, whose grant the
4
+ * executor holds on an `ALLOW` instead of running anything. The issuer
5
+ * performs the effect, when its authorization hook asks; so this handler is
6
+ * never dispatched, and one that somehow were would fail before dispatch
7
+ * with the grant finalized as `FAILED`. Its parameters schema is what the
8
+ * executor's admission checks the intent against.
9
+ *
10
+ * Reconciliation has no one to ask: the issuer is the system of record and
11
+ * the executor has no read path into it, so an attempt whose result never
12
+ * arrived stays unknown until someone who can see the issuer's ledger says.
13
+ */
14
+ export declare function cardHandlers(): HandlerRegistration;
15
+ //# sourceMappingURL=CardHandlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardHandlers.d.ts","sourceRoot":"","sources":["../../../src/adapters/cards/CardHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAGjF;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,IAAI,mBAAmB,CAWlD"}
@@ -0,0 +1,26 @@
1
+ import { CARD_PURCHASE_ACTION, CardPurchaseSchema } from "./CardPurchase.js";
2
+ /**
3
+ * The registration for the cards family: `card.purchase`, whose grant the
4
+ * executor holds on an `ALLOW` instead of running anything. The issuer
5
+ * performs the effect, when its authorization hook asks; so this handler is
6
+ * never dispatched, and one that somehow were would fail before dispatch
7
+ * with the grant finalized as `FAILED`. Its parameters schema is what the
8
+ * executor's admission checks the intent against.
9
+ *
10
+ * Reconciliation has no one to ask: the issuer is the system of record and
11
+ * the executor has no read path into it, so an attempt whose result never
12
+ * arrived stays unknown until someone who can see the issuer's ledger says.
13
+ */
14
+ export function cardHandlers() {
15
+ return (context) => {
16
+ context.registry.register(CARD_PURCHASE_ACTION, {
17
+ parametersSchema: CardPurchaseSchema,
18
+ execute: () => {
19
+ throw new Error("CARD_PURCHASE_IS_HELD_NOT_RUN");
20
+ },
21
+ reconcile: () => ({ status: "UNKNOWN" }),
22
+ });
23
+ return [CARD_PURCHASE_ACTION];
24
+ };
25
+ }
26
+ //# sourceMappingURL=CardHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardHandlers.js","sourceRoot":"","sources":["../../../src/adapters/cards/CardHandlers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE7E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,EAAE;YAC9C,gBAAgB,EAAE,kBAAkB;YACpC,OAAO,EAAE,GAAG,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACnD,CAAC;YACD,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;SACzC,CAAC,CAAC;QACH,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * What a shared hold store keeps of a grant at rest, sealed: the captured
3
+ * intent and the decision, which carries the authority's grant token, and
4
+ * later the authorization a claim returned. The database then holds no
5
+ * bearer credential in clear, and a row copied out of it opens nowhere but
6
+ * in a process that holds the deployment's hold key.
7
+ *
8
+ * AES-256-GCM under a 256-bit key, a fresh 96-bit nonce per seal, and the
9
+ * row's own identity as associated data, so a sealed value moved to another
10
+ * row, or to another table or namespace, does not open. The key is read
11
+ * from the secret store at the moment of use and never written anywhere.
12
+ */
13
+ export declare class CardHoldSeal {
14
+ private readonly key;
15
+ static readonly VERSION = "v1";
16
+ private constructor();
17
+ /** A key of exactly 32 bytes; anything else is refused by name, never echoed. */
18
+ static fromKey(key: Buffer): CardHoldSeal;
19
+ /**
20
+ * The key as a secret file carries it: 32 bytes as base64 or as 64 hex
21
+ * characters, surrounding whitespace ignored. Raw bytes are not accepted,
22
+ * so a key file is always text an operator can inspect for shape.
23
+ */
24
+ static fromText(text: string): CardHoldSeal;
25
+ seal(plaintext: string, associated: string): string;
26
+ /** The plaintext, or null for anything that does not open under this key and this identity. */
27
+ open(sealed: string, associated: string): string | null;
28
+ }
29
+ //# sourceMappingURL=CardHoldSeal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardHoldSeal.d.ts","sourceRoot":"","sources":["../../../src/adapters/cards/CardHoldSeal.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;GAWG;AACH,qBAAa,YAAY;IAGH,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFxC,gBAAuB,OAAO,QAAQ;IAEtC,OAAO;IAEP,iFAAiF;WACnE,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IAKhD;;;;OAIG;WACW,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY;IAW3C,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IAc1D,+FAA+F;IACxF,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAmB/D"}
@@ -0,0 +1,87 @@
1
+ import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
2
+ const CIPHER = "aes-256-gcm";
3
+ const KEY_BYTES = 32;
4
+ const NONCE_BYTES = 12;
5
+ const TAG_BYTES = 16;
6
+ /** How the nonce, the body and the tag are written into the sealed value. */
7
+ const WIRE_ENCODING = "base64url";
8
+ const TEXT_ENCODING = "utf8";
9
+ const KEY_INVALID = "CARD_HOLDS_KEY_INVALID";
10
+ /**
11
+ * What a shared hold store keeps of a grant at rest, sealed: the captured
12
+ * intent and the decision, which carries the authority's grant token, and
13
+ * later the authorization a claim returned. The database then holds no
14
+ * bearer credential in clear, and a row copied out of it opens nowhere but
15
+ * in a process that holds the deployment's hold key.
16
+ *
17
+ * AES-256-GCM under a 256-bit key, a fresh 96-bit nonce per seal, and the
18
+ * row's own identity as associated data, so a sealed value moved to another
19
+ * row, or to another table or namespace, does not open. The key is read
20
+ * from the secret store at the moment of use and never written anywhere.
21
+ */
22
+ export class CardHoldSeal {
23
+ key;
24
+ static VERSION = "v1";
25
+ constructor(key) {
26
+ this.key = key;
27
+ }
28
+ /** A key of exactly 32 bytes; anything else is refused by name, never echoed. */
29
+ static fromKey(key) {
30
+ if (key.length !== KEY_BYTES)
31
+ throw new Error(KEY_INVALID);
32
+ return new CardHoldSeal(Buffer.from(key));
33
+ }
34
+ /**
35
+ * The key as a secret file carries it: 32 bytes as base64 or as 64 hex
36
+ * characters, surrounding whitespace ignored. Raw bytes are not accepted,
37
+ * so a key file is always text an operator can inspect for shape.
38
+ */
39
+ static fromText(text) {
40
+ const trimmed = text.trim();
41
+ if (/^[0-9a-f]{64}$/i.test(trimmed))
42
+ return CardHoldSeal.fromKey(Buffer.from(trimmed, "hex"));
43
+ if (/^[a-z0-9+/]{43}=?$/i.test(trimmed)) {
44
+ return CardHoldSeal.fromKey(Buffer.from(trimmed, "base64"));
45
+ }
46
+ if (/^[\w-]{43}$/.test(trimmed))
47
+ return CardHoldSeal.fromKey(Buffer.from(trimmed, WIRE_ENCODING));
48
+ throw new Error(KEY_INVALID);
49
+ }
50
+ seal(plaintext, associated) {
51
+ const nonce = randomBytes(NONCE_BYTES);
52
+ const cipher = createCipheriv(CIPHER, this.key, nonce);
53
+ cipher.setAAD(Buffer.from(associated, TEXT_ENCODING));
54
+ const body = Buffer.concat([cipher.update(plaintext, TEXT_ENCODING), cipher.final()]);
55
+ const tag = cipher.getAuthTag();
56
+ return [
57
+ CardHoldSeal.VERSION,
58
+ nonce.toString(WIRE_ENCODING),
59
+ body.toString(WIRE_ENCODING),
60
+ tag.toString(WIRE_ENCODING),
61
+ ].join(".");
62
+ }
63
+ /** The plaintext, or null for anything that does not open under this key and this identity. */
64
+ open(sealed, associated) {
65
+ const parts = sealed.split(".");
66
+ if (parts.length !== 4 || parts[0] !== CardHoldSeal.VERSION)
67
+ return null;
68
+ const [, nonceText, bodyText, tagText] = parts;
69
+ const nonce = Buffer.from(nonceText, WIRE_ENCODING);
70
+ const tag = Buffer.from(tagText, WIRE_ENCODING);
71
+ if (nonce.length !== NONCE_BYTES || tag.length !== TAG_BYTES)
72
+ return null;
73
+ try {
74
+ const decipher = createDecipheriv(CIPHER, this.key, nonce);
75
+ decipher.setAAD(Buffer.from(associated, TEXT_ENCODING));
76
+ decipher.setAuthTag(tag);
77
+ return Buffer.concat([
78
+ decipher.update(Buffer.from(bodyText, WIRE_ENCODING)),
79
+ decipher.final(),
80
+ ]).toString(TEXT_ENCODING);
81
+ }
82
+ catch {
83
+ return null;
84
+ }
85
+ }
86
+ }
87
+ //# sourceMappingURL=CardHoldSeal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardHoldSeal.js","sourceRoot":"","sources":["../../../src/adapters/cards/CardHoldSeal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,MAAM,GAAG,aAAa,CAAC;AAC7B,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,6EAA6E;AAC7E,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,YAAY;IAGc;IAF9B,MAAM,CAAU,OAAO,GAAG,IAAI,CAAC;IAEtC,YAAqC,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;IAEpD,iFAAiF;IAC1E,MAAM,CAAC,OAAO,CAAC,GAAW;QAC/B,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;QAC3D,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,IAAY;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;QAC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AAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QACzE,MAAM,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,KAAyC,CAAC;QACnF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QACpD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAChD,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QAC1E,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC3D,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;YACxD,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACzB,OAAO,MAAM,CAAC,MAAM,CAAC;gBACnB,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;gBACrD,QAAQ,CAAC,KAAK,EAAE;aACjB,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC"}
@@ -0,0 +1,102 @@
1
+ import type { CapturedIntent, DecisionGate, HeldExecution, JsonObject, SafeExecutor, VerifiedAuthorization } from "@decionis/agent-safe-pipeline";
2
+ import type { CardAuthorizationAnswer } from "../../service/Requests.js";
3
+ import type { PreparedAction } from "../EffectAdapter.js";
4
+ import type { HeldCardGrantView } from "./CardAuthorizationMatcher.js";
5
+ import type { CardAuthorizationRequest, CardPurchase } from "./CardPurchase.js";
6
+ /** What a hold is keyed by: one card at one merchant. A burst across merchants holds in parallel. */
7
+ export interface CardHoldKey {
8
+ readonly cardTokenRef: string;
9
+ readonly merchantId: string;
10
+ }
11
+ /** Between the parts of a key or a row's identity: a character no reference can contain. */
12
+ export declare const CARD_KEY_SEPARATOR = "\0";
13
+ /** The key as one string. */
14
+ export declare function cardHoldKey(key: CardHoldKey): string;
15
+ /** One held grant: the purchase, the executor's handle on it, and whether it is spent. */
16
+ export interface HeldCardGrant extends HeldCardGrantView {
17
+ readonly purchase: CardPurchase;
18
+ readonly prepared: PreparedAction;
19
+ readonly held: HeldExecution;
20
+ /** The executor that holds the handle; only it can claim and settle it. */
21
+ readonly executor: SafeExecutor;
22
+ used: boolean;
23
+ }
24
+ /**
25
+ * A hold as the store finds it: what the matcher reads, the intent it was
26
+ * made for, and `open`, which yields the grant with a handle this process
27
+ * can claim, admitting it here first when another replica made it. Null
28
+ * from `open` means this process cannot admit it, and nothing was spent.
29
+ */
30
+ export interface HeldCardGrantRecord extends HeldCardGrantView {
31
+ readonly intentId: string;
32
+ open(): Promise<HeldCardGrant | null>;
33
+ }
34
+ /** What the issuer was answered when an authorization matched, kept for a retry of the same one. */
35
+ export type CardApproval = Extract<CardAuthorizationAnswer, {
36
+ readonly decision: "APPROVE";
37
+ }>;
38
+ /** An authorization that claimed a grant, until its result is recorded or it is forgotten. */
39
+ export interface ClaimedCardAuthorization {
40
+ readonly grant: HeldCardGrant;
41
+ request: CardAuthorizationRequest;
42
+ readonly authorization: VerifiedAuthorization;
43
+ readonly leaseExpiresAtMs: number;
44
+ readonly answer: CardApproval;
45
+ readonly retainUntilMs: number;
46
+ settled: boolean;
47
+ }
48
+ /** What `recordClaim` is given: the claim, and what a replica needs to finalize it elsewhere. */
49
+ export interface CardClaimInput extends Omit<ClaimedCardAuthorization, "retainUntilMs" | "settled"> {
50
+ /** The verifier's claim material, sealed by a shared store and never written in clear. */
51
+ readonly material: JsonObject | null;
52
+ }
53
+ /** How far back a card's holds and claims are counted for policy. */
54
+ export declare const CARD_VELOCITY_WINDOW_MS: number;
55
+ /** How often one card was held for and claimed lately: counts for policy, never a reference. */
56
+ export interface CardVelocity {
57
+ readonly window_seconds: number;
58
+ readonly holds: number;
59
+ readonly claims: number;
60
+ }
61
+ /** What a store needs from the process to admit a hold or a claim another replica made. */
62
+ export interface CardHoldAdoption {
63
+ hold(captured: CapturedIntent, decision: DecisionGate): Promise<{
64
+ readonly held: HeldExecution;
65
+ readonly executor: SafeExecutor;
66
+ } | null>;
67
+ claim(captured: CapturedIntent, decision: DecisionGate, authorization: VerifiedAuthorization, material: JsonObject | null): {
68
+ readonly held: HeldExecution;
69
+ readonly executor: SafeExecutor;
70
+ } | null;
71
+ }
72
+ /**
73
+ * Where held grants and the authorizations that claimed them live. One key
74
+ * (a card at a merchant) has at most one spendable hold, and a hold is spent
75
+ * once, whichever replica the authorization reaches: `spend` is the race
76
+ * rule, and it is the same rule in memory and in the shared store.
77
+ */
78
+ export interface CardHoldStore {
79
+ readonly kind: "memory" | "postgres";
80
+ /** Whether the key has a hold an authorization could still match. */
81
+ spendable(key: CardHoldKey): Promise<boolean>;
82
+ /** Keeps a hold; false when the key already has a spendable one or the store is full. */
83
+ hold(grant: HeldCardGrant): Promise<boolean>;
84
+ /** The hold for a key, spent, expired or neither, until it is forgotten. */
85
+ grant(key: CardHoldKey): Promise<HeldCardGrantRecord | undefined>;
86
+ /** Spends a hold once: true for the one caller that did, false for every other. */
87
+ spend(grant: HeldCardGrant): Promise<boolean>;
88
+ claimed(authorizationId: string): Promise<ClaimedCardAuthorization | undefined>;
89
+ /** Remembers a claim for its result. */
90
+ recordClaim(authorizationId: string, claim: CardClaimInput): Promise<ClaimedCardAuthorization>;
91
+ /** An incremental authorization: the same claim, re-presented for more; false when unknown. */
92
+ amend(authorizationId: string, request: CardAuthorizationRequest): Promise<boolean>;
93
+ /** Marks a claim settled once: false when it was already, or is unknown. */
94
+ settle(authorizationId: string): Promise<boolean>;
95
+ velocity(cardTokenRef: string, windowMs?: number): Promise<CardVelocity>;
96
+ /** Throws unless the store can be used; for the shared store, the tables are reachable. */
97
+ ready(): Promise<void>;
98
+ /** Forgets what lapsed; nothing to do in memory, which sweeps as it goes. */
99
+ cleanup(): Promise<void>;
100
+ close(): Promise<void>;
101
+ }
102
+ //# sourceMappingURL=CardHoldStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardHoldStore.d.ts","sourceRoot":"","sources":["../../../src/adapters/cards/CardHoldStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,EACZ,qBAAqB,EACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEhF,qGAAqG;AACrG,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,4FAA4F;AAC5F,eAAO,MAAM,kBAAkB,OAAW,CAAC;AAE3C,6BAA6B;AAC7B,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CAEpD;AAED,0FAA0F;AAC1F,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,IAAI,EAAE,OAAO,CA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EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACzE,2FAA2F;IAC3F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,6EAA6E;IAC7E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
@@ -0,0 +1,9 @@
1
+ /** Between the parts of a key or a row's identity: a character no reference can contain. */
2
+ export const CARD_KEY_SEPARATOR = "\u0000";
3
+ /** The key as one string. */
4
+ export function cardHoldKey(key) {
5
+ return `${key.cardTokenRef}${CARD_KEY_SEPARATOR}${key.merchantId}`;
6
+ }
7
+ /** How far back a card's holds and claims are counted for policy. */
8
+ export const CARD_VELOCITY_WINDOW_MS = 10 * 60_000;
9
+ //# sourceMappingURL=CardHoldStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardHoldStore.js","sourceRoot":"","sources":["../../../src/adapters/cards/CardHoldStore.ts"],"names":[],"mappings":"AAmBA,4FAA4F;AAC5F,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAE3C,6BAA6B;AAC7B,MAAM,UAAU,WAAW,CAAC,GAAgB;IAC1C,OAAO,GAAG,GAAG,CAAC,YAAY,GAAG,kBAAkB,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;AACrE,CAAC;AA8CD,qEAAqE;AACrE,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,MAAM,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { type LoadPg } from "../../edge/EdgeReplay.js";
2
+ import type { CardHoldSeal } from "./CardHoldSeal.js";
3
+ import type { CardHoldAdoption, CardHoldStore } from "./CardHoldStore.js";
4
+ /**
5
+ * The shared hold store over one `pg` pool, opened on first use: the
6
+ * connection string and the hold key are secrets, read when the pool is
7
+ * opened and when a row is sealed, and never held as strings here.
8
+ */
9
+ export declare function postgresCardHolds(options: {
10
+ readonly databaseUrl: () => string;
11
+ readonly seal: () => CardHoldSeal;
12
+ readonly namespace: string;
13
+ readonly table: string;
14
+ readonly adopt: CardHoldAdoption;
15
+ readonly load?: LoadPg;
16
+ readonly clock?: () => number;
17
+ readonly claimRetentionMs?: number;
18
+ }): CardHoldStore;
19
+ //# sourceMappingURL=CardHolds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CardHolds.d.ts","sourceRoot":"","sources":["../../../src/adapters/cards/CardHolds.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,KAAK,MAAM,EAAe,MAAM,0BAA0B,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAEV,gBAAgB,EAEhB,aAAa,EAKd,MAAM,oBAAoB,CAAC;AAI5B;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,QAAQ,CAAC,WAAW,EAAE,MAAM,MAAM,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,YAAY,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC,GAAG,aAAa,CAqDhB"}