@devlab.group/agent-commerce 2.5.0 → 2.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 (129) hide show
  1. package/README.md +78 -21
  2. package/dist/ap2.d.ts +19 -6
  3. package/dist/ap2.js +56 -18
  4. package/dist/ap2.js.map +1 -1
  5. package/dist/{chunk-ES3V6ECS.js → chunk-77HLISG4.js} +3 -2
  6. package/dist/chunk-77HLISG4.js.map +1 -0
  7. package/dist/{chunk-5ZYXBCDX.js → chunk-D7FPSGUQ.js} +25 -4
  8. package/dist/chunk-D7FPSGUQ.js.map +1 -0
  9. package/dist/{chunk-VUCMBGUR.js → chunk-DJRWYDKJ.js} +3 -3
  10. package/dist/{chunk-VUCMBGUR.js.map → chunk-DJRWYDKJ.js.map} +1 -1
  11. package/dist/{chunk-4K7FIBJM.js → chunk-EMKITGVV.js} +4 -4
  12. package/dist/chunk-EMKITGVV.js.map +1 -0
  13. package/dist/chunk-IWXVQYG5.js +6 -0
  14. package/dist/chunk-IWXVQYG5.js.map +1 -0
  15. package/dist/chunk-O3ACF45K.js +8 -0
  16. package/dist/chunk-O3ACF45K.js.map +1 -0
  17. package/dist/chunk-WDD2ZUR3.js +20 -0
  18. package/dist/chunk-WDD2ZUR3.js.map +1 -0
  19. package/dist/{chunk-3OTCFFFT.js → chunk-YHNTTMED.js} +7 -7
  20. package/dist/chunk-YHNTTMED.js.map +1 -0
  21. package/dist/{chunk-FKQK5XZA.js → chunk-ZSIUZPNB.js} +183 -80
  22. package/dist/chunk-ZSIUZPNB.js.map +1 -0
  23. package/dist/cli/{ap2-YAPLERSC.js → ap2-5FFGSW6F.js} +61 -25
  24. package/dist/cli/ap2-5FFGSW6F.js.map +1 -0
  25. package/dist/cli/{chunk-5K4XEAZV.js → chunk-3IEXJ7I3.js} +25 -4
  26. package/dist/cli/chunk-3IEXJ7I3.js.map +1 -0
  27. package/dist/cli/{chunk-NIU5EMSB.js → chunk-3NVJAQRO.js} +5 -5
  28. package/dist/cli/{chunk-NIU5EMSB.js.map → chunk-3NVJAQRO.js.map} +1 -1
  29. package/dist/cli/{chunk-IDY2735M.js → chunk-55AI6CLW.js} +6 -4
  30. package/dist/cli/chunk-55AI6CLW.js.map +1 -0
  31. package/dist/cli/{chunk-QA2OPHBF.js → chunk-5K2JDM4G.js} +185 -83
  32. package/dist/cli/chunk-5K2JDM4G.js.map +1 -0
  33. package/dist/cli/{chunk-QLUCNPRT.js → chunk-5TID36YG.js} +860 -170
  34. package/dist/cli/chunk-5TID36YG.js.map +1 -0
  35. package/dist/cli/{chunk-5R7DM5LM.js → chunk-66NTYSXI.js} +27 -27
  36. package/dist/cli/chunk-66NTYSXI.js.map +1 -0
  37. package/dist/cli/{chunk-VJ4EO4LE.js → chunk-6EBDOH37.js} +3 -3
  38. package/dist/cli/{chunk-VJ4EO4LE.js.map → chunk-6EBDOH37.js.map} +1 -1
  39. package/dist/cli/{chunk-4H2QLHQI.js → chunk-AGQ4U7IN.js} +5 -5
  40. package/dist/cli/chunk-AGQ4U7IN.js.map +1 -0
  41. package/dist/cli/chunk-APC5BTQM.js +6 -0
  42. package/dist/cli/chunk-APC5BTQM.js.map +1 -0
  43. package/dist/cli/{chunk-SYQLJXIU.js → chunk-C5YISPT6.js} +3 -3
  44. package/dist/cli/chunk-C5YISPT6.js.map +1 -0
  45. package/dist/cli/chunk-DKWO6LLX.js +34 -0
  46. package/dist/cli/chunk-DKWO6LLX.js.map +1 -0
  47. package/dist/cli/{chunk-SPAYKVUP.js → chunk-FL4HPCD4.js} +3 -2
  48. package/dist/cli/chunk-FL4HPCD4.js.map +1 -0
  49. package/dist/cli/{chunk-3EQBCFZY.js → chunk-H7EBJ4I3.js} +3 -3
  50. package/dist/cli/{chunk-3EQBCFZY.js.map → chunk-H7EBJ4I3.js.map} +1 -1
  51. package/dist/cli/{chunk-Z34UMZBB.js → chunk-OETKXDGA.js} +546 -175
  52. package/dist/cli/chunk-OETKXDGA.js.map +1 -0
  53. package/dist/cli/{chunk-JFVRG2HH.js → chunk-PLHPKXAT.js} +8 -8
  54. package/dist/cli/chunk-PLHPKXAT.js.map +1 -0
  55. package/dist/cli/{chunk-2UPPX3FJ.js → chunk-VSSSU4AU.js} +76 -14
  56. package/dist/cli/chunk-VSSSU4AU.js.map +1 -0
  57. package/dist/cli/chunk-ZCW56PZ3.js +8 -0
  58. package/dist/cli/{chunk-M7NXVRU5.js.map → chunk-ZCW56PZ3.js.map} +1 -1
  59. package/dist/cli/{chunk-2J2IQQ4X.js → chunk-ZFVQWOGG.js} +95 -42
  60. package/dist/cli/chunk-ZFVQWOGG.js.map +1 -0
  61. package/dist/cli/config-WT5HHDRR.js +13 -0
  62. package/dist/cli/{config-BWFMN2ZB.js.map → config-WT5HHDRR.js.map} +1 -1
  63. package/dist/cli/index.js +560 -252
  64. package/dist/cli/index.js.map +1 -1
  65. package/dist/cli/{mcp-KZEMXLHR.js → mcp-HHGNOUKE.js} +7 -7
  66. package/dist/cli/{mcp-KZEMXLHR.js.map → mcp-HHGNOUKE.js.map} +1 -1
  67. package/dist/cli/payment-providers-EWXZFBIE.js +6 -0
  68. package/dist/cli/{payment-providers-SZL36H3Y.js.map → payment-providers-EWXZFBIE.js.map} +1 -1
  69. package/dist/cli/{provider-6TKB5ADJ.js → provider-XUPLYNQ7.js} +36 -18
  70. package/dist/cli/provider-XUPLYNQ7.js.map +1 -0
  71. package/dist/cli/receipts-3DSV4DIK.js +9 -0
  72. package/dist/cli/{receipts-ZGLJWMQG.js.map → receipts-3DSV4DIK.js.map} +1 -1
  73. package/dist/cli/reconcile-GS25MQ42.js +4 -0
  74. package/dist/cli/{reconcile-IC22MJD5.js.map → reconcile-GS25MQ42.js.map} +1 -1
  75. package/dist/cli/{run-ZTYPQI4D.js → run-7KLKW3HE.js} +310 -91
  76. package/dist/cli/run-7KLKW3HE.js.map +1 -0
  77. package/dist/cli/{x402-WLYBLODI.js → x402-HP4E3QET.js} +11 -10
  78. package/dist/cli/x402-HP4E3QET.js.map +1 -0
  79. package/dist/{guardrails-CX_jYXvZ.d.ts → guardrails-CeyLS1ou.d.ts} +2 -2
  80. package/dist/index.d.ts +119 -206
  81. package/dist/index.js +1703 -427
  82. package/dist/index.js.map +1 -1
  83. package/dist/logger-CllGwQ8i.d.ts +19 -0
  84. package/dist/mcp.d.ts +3 -1
  85. package/dist/mcp.js +4 -3
  86. package/dist/mcp.js.map +1 -1
  87. package/dist/mpp.d.ts +2 -1
  88. package/dist/mpp.js +32 -13
  89. package/dist/mpp.js.map +1 -1
  90. package/dist/{protocol-adapter-DEXpdp8m.d.ts → protocol-adapter-DdFL5LBU.d.ts} +15 -132
  91. package/dist/{runtime-Dz2fSO-P.d.ts → runtime-BmaSp2Ce.d.ts} +36 -23
  92. package/dist/store-BVvMzpuV.d.ts +389 -0
  93. package/dist/testing.d.ts +51 -0
  94. package/dist/testing.js +2050 -0
  95. package/dist/testing.js.map +1 -0
  96. package/dist/transaction-BXXJltZ-.d.ts +129 -0
  97. package/dist/{types-j7MnUXYN.d.ts → types-DWqjz81-.d.ts} +5 -2
  98. package/dist/x402.d.ts +9 -3
  99. package/dist/x402.js +7 -5
  100. package/dist/x402.js.map +1 -1
  101. package/package.json +17 -29
  102. package/dist/chunk-3OTCFFFT.js.map +0 -1
  103. package/dist/chunk-4K7FIBJM.js.map +0 -1
  104. package/dist/chunk-5ZYXBCDX.js.map +0 -1
  105. package/dist/chunk-ES3V6ECS.js.map +0 -1
  106. package/dist/chunk-FKQK5XZA.js.map +0 -1
  107. package/dist/cli/ap2-YAPLERSC.js.map +0 -1
  108. package/dist/cli/chunk-2J2IQQ4X.js.map +0 -1
  109. package/dist/cli/chunk-2UPPX3FJ.js.map +0 -1
  110. package/dist/cli/chunk-4H2QLHQI.js.map +0 -1
  111. package/dist/cli/chunk-5K4XEAZV.js.map +0 -1
  112. package/dist/cli/chunk-5R7DM5LM.js.map +0 -1
  113. package/dist/cli/chunk-FHCFR2GS.js +0 -17
  114. package/dist/cli/chunk-FHCFR2GS.js.map +0 -1
  115. package/dist/cli/chunk-IDY2735M.js.map +0 -1
  116. package/dist/cli/chunk-JFVRG2HH.js.map +0 -1
  117. package/dist/cli/chunk-M7NXVRU5.js +0 -8
  118. package/dist/cli/chunk-QA2OPHBF.js.map +0 -1
  119. package/dist/cli/chunk-QLUCNPRT.js.map +0 -1
  120. package/dist/cli/chunk-SPAYKVUP.js.map +0 -1
  121. package/dist/cli/chunk-SYQLJXIU.js.map +0 -1
  122. package/dist/cli/chunk-Z34UMZBB.js.map +0 -1
  123. package/dist/cli/config-BWFMN2ZB.js +0 -12
  124. package/dist/cli/payment-providers-SZL36H3Y.js +0 -6
  125. package/dist/cli/provider-6TKB5ADJ.js.map +0 -1
  126. package/dist/cli/receipts-ZGLJWMQG.js +0 -8
  127. package/dist/cli/reconcile-IC22MJD5.js +0 -4
  128. package/dist/cli/run-ZTYPQI4D.js.map +0 -1
  129. package/dist/cli/x402-WLYBLODI.js.map +0 -1
@@ -0,0 +1,389 @@
1
+ import { k as AuthorizationMethodName, I as IsoTimestamp, K as ProtocolName, l as AuthorizationRecord, t as PaymentAttempt, p as CommerceReceipt, u as PaymentAttemptResolution, g as AdapterDescriptor, h as AdapterHealth } from './runtime-BmaSp2Ce.js';
2
+ import { A as AuthorizationHoldState, a as CommerceEvent, P as PersistenceFailure, c as Transaction, e as TransactionState } from './transaction-BXXJltZ-.js';
3
+
4
+ /**
5
+ * Protocol-neutral records for the receipt store's optional methods:
6
+ * idempotency claims, authorization holds and pending tasks. Adapters and
7
+ * authorization providers map their own data to these types at their boundaries.
8
+ */
9
+
10
+ /** Experimental: may change in a minor release */
11
+ interface IdempotencyScope {
12
+ /** The gateway's public base URL, which survives a credential rotation */
13
+ readonly deployment: string;
14
+ /** The concrete endpoint path, so a client may reuse one key across operations */
15
+ readonly endpoint: string;
16
+ readonly key: string;
17
+ }
18
+ /**
19
+ * Result of claiming an idempotency key. `owner` is the tag the claim was
20
+ * created with, if any. Experimental: may change in a minor release.
21
+ */
22
+ type IdempotencyClaim =
23
+ /** The caller owns the key and must perform the operation */
24
+ {
25
+ readonly kind: 'reserved';
26
+ }
27
+ /** Same fingerprint; an earlier claim is still in flight */
28
+ | {
29
+ readonly kind: 'in-flight';
30
+ readonly owner?: string;
31
+ }
32
+ /** Same fingerprint; an earlier attempt's outcome is unknown */
33
+ | {
34
+ readonly kind: 'unresolved';
35
+ readonly owner?: string;
36
+ }
37
+ /** A different fingerprint, regardless of the claim's state */
38
+ | {
39
+ readonly kind: 'conflict';
40
+ }
41
+ /** Same fingerprint; replay the stored response */
42
+ | {
43
+ readonly kind: 'replay';
44
+ readonly status: number;
45
+ readonly body: unknown;
46
+ };
47
+ /**
48
+ * An idempotency claim's outcome. `body` must be JSON-serializable.
49
+ * Experimental: may change in a minor release.
50
+ */
51
+ type IdempotencyUpdate =
52
+ /** Store the response for later claims with the same fingerprint to replay */
53
+ {
54
+ readonly kind: 'completed';
55
+ readonly status: number;
56
+ readonly body: unknown;
57
+ }
58
+ /** Keep the claim without a response and refuse retries: the operation may have run */
59
+ | {
60
+ readonly kind: 'unresolved';
61
+ }
62
+ /** Delete only if no backend call ran or the backend deduplicates by this key */
63
+ | {
64
+ readonly kind: 'released';
65
+ };
66
+ /** Experimental: may change in a minor release */
67
+ interface AuthorizationHoldReservation {
68
+ readonly method: AuthorizationMethodName;
69
+ /** Identifies one authorization, unique across the store. AP2: the issuer-signed token's digest */
70
+ readonly reference: string;
71
+ /** Identifies a binding with at most one unreleased hold. AP2: the checkout JWT's `jti` */
72
+ readonly bindingReference: string;
73
+ readonly resourceId: string;
74
+ readonly requestId: string;
75
+ /** Non-secret operator identifiers, such as issuers; never presentations or signatures */
76
+ readonly metadata?: Readonly<Record<string, string>>;
77
+ }
78
+ /** Experimental: may change in a minor release */
79
+ type AuthorizationHoldResult = {
80
+ readonly kind: 'reserved';
81
+ }
82
+ /** The reference or its binding is already held; refuse the authorization */
83
+ | {
84
+ readonly kind: 'replayed';
85
+ readonly state: AuthorizationHoldState;
86
+ };
87
+ /** Experimental: may change in a minor release */
88
+ interface AuthorizationHold extends AuthorizationHoldReservation {
89
+ readonly state: AuthorizationHoldState;
90
+ readonly createdAt: IsoTimestamp;
91
+ readonly updatedAt: IsoTimestamp;
92
+ }
93
+ /**
94
+ * A purchase awaiting its payment message. Experimental: may change in a
95
+ * minor release.
96
+ */
97
+ interface PendingTask {
98
+ /** Unique across the store */
99
+ readonly id: string;
100
+ readonly protocol: ProtocolName;
101
+ readonly resourceId: string;
102
+ /**
103
+ * JSON-serializable purchase input with reserved fields removed. Must not
104
+ * contain payment proofs or authorization presentations.
105
+ */
106
+ readonly input: Readonly<Record<string, unknown>>;
107
+ /** JSON-serializable data that only the adapter interprets */
108
+ readonly adapterData?: Readonly<Record<string, unknown>>;
109
+ /** Set and bounded by the caller */
110
+ readonly expiresAt: IsoTimestamp;
111
+ }
112
+
113
+ /**
114
+ * Persistence boundary for receipts, events and payment attempts, implemented
115
+ * by src/storage/receipts. Core depends only on this interface, never on
116
+ * SQLite.
117
+ */
118
+
119
+ interface PaymentAttemptReservation {
120
+ readonly requestId: string;
121
+ readonly resourceId: string;
122
+ readonly provider: string;
123
+ /** Must be unique across the store; see `PaymentResult.replayKey` */
124
+ readonly replayKey: string;
125
+ readonly amount: string;
126
+ readonly currency: string;
127
+ readonly payer?: string;
128
+ readonly payee?: string;
129
+ /**
130
+ * Reclaim this `replayKey` if the same `provider` rejected it, which
131
+ * settled nothing. Set only for rails whose authorizations remain reusable
132
+ * until settled.
133
+ */
134
+ readonly reclaimRejected?: boolean;
135
+ /**
136
+ * Journal data to write atomically with the reservation. Stores without
137
+ * journal support ignore it.
138
+ */
139
+ readonly transaction?: NewTransaction;
140
+ }
141
+ /**
142
+ * Data for a journal row opened with a replay reservation. Journal stores
143
+ * must initialize an included authorization hold as `reserved`. The reservation
144
+ * supplies the request, resource, provider, replay key, amount, currency and
145
+ * payee.
146
+ */
147
+ interface NewTransaction {
148
+ readonly id: string;
149
+ readonly protocol: ProtocolName;
150
+ readonly network?: string;
151
+ readonly asset?: string;
152
+ readonly locator?: Readonly<Record<string, unknown>>;
153
+ readonly expiresAt?: IsoTimestamp;
154
+ readonly authorization?: AuthorizationRecord & {
155
+ readonly reservationId: string;
156
+ };
157
+ readonly inputDigest?: string;
158
+ readonly configDigest: string;
159
+ }
160
+ /** A journal update after replay reservation */
161
+ type TransactionStep = {
162
+ readonly transactionId: string;
163
+ readonly at: IsoTimestamp;
164
+ } & ({
165
+ readonly kind: 'settling';
166
+ } | {
167
+ readonly kind: 'hold';
168
+ readonly hold: AuthorizationHoldState;
169
+ } | {
170
+ readonly kind: 'backend-dispatched';
171
+ readonly deadlineAt: IsoTimestamp;
172
+ } | {
173
+ readonly kind: 'backend-result';
174
+ readonly status: number;
175
+ readonly errorCode?: string;
176
+ } | {
177
+ readonly kind: 'receipt';
178
+ readonly receiptId: string;
179
+ } | {
180
+ readonly kind: 'completed';
181
+ readonly persistenceFailures?: readonly PersistenceFailure[];
182
+ });
183
+ interface TransactionListOptions extends ListOptions {
184
+ /** Opaque cursor from a previous page's `nextCursor` */
185
+ readonly cursor?: string;
186
+ readonly state?: TransactionState;
187
+ /** When true, exclude `delivered` and `payment-failed` states */
188
+ readonly unresolved?: boolean;
189
+ /** When true, filter for `reserved` or `uncertain` authorization holds */
190
+ readonly pendingHold?: boolean;
191
+ }
192
+ /** Transactions in newest-first order */
193
+ interface TransactionPage {
194
+ readonly transactions: readonly Transaction[];
195
+ /**
196
+ * Continue with this cursor even when filtering returns fewer than `limit`
197
+ * transactions, including an empty page. Pagination ends when it is absent.
198
+ */
199
+ readonly nextCursor?: string;
200
+ }
201
+ interface PaymentAttemptResolveRequest {
202
+ readonly attemptId: string;
203
+ /** Update only if the attempt still has this status and no resolution */
204
+ readonly expectedStatus: PaymentAttempt['status'];
205
+ readonly status: 'settled' | 'rejected';
206
+ readonly rejectionReason?: string;
207
+ readonly resolution: PaymentAttemptResolution;
208
+ }
209
+ interface PaymentAttemptUpdate {
210
+ readonly replayKey: string;
211
+ readonly status: PaymentAttempt['status'];
212
+ readonly externalReference?: string;
213
+ readonly rejectionReason?: string;
214
+ }
215
+ interface ListOptions {
216
+ readonly limit?: number;
217
+ readonly requestId?: string;
218
+ }
219
+ interface ReceiptListOptions extends ListOptions {
220
+ /**
221
+ * When true, return only receipts counted by {@link ReceiptStore.countUndeliveredReceipts}.
222
+ * Stores ignoring this flag also return delivered receipts.
223
+ */
224
+ readonly undelivered?: boolean;
225
+ }
226
+ interface PaymentAttemptListOptions extends ListOptions {
227
+ /**
228
+ * When true, return only attempts counted by {@link ReceiptStore.countUncertainPaymentAttempts}.
229
+ * Stores that ignore this flag do not filter by settlement status.
230
+ */
231
+ readonly uncertain?: boolean;
232
+ }
233
+ interface ReceiptStore {
234
+ init(): Promise<void>;
235
+ /** Append a canonical event. Must not throw into the caller's flow */
236
+ appendEvent(event: CommerceEvent): Promise<void>;
237
+ /**
238
+ * Atomically reserve a payment authorization before settlement. If its
239
+ * `replayKey` is already reserved, throws `CommerceError('PAYMENT_REPLAYED')`
240
+ * with the existing attempt's `PaymentAttempt.status` in
241
+ * `details.attemptStatus` when available.
242
+ *
243
+ * With `reclaimRejected`, replace the same provider's `rejected` attempt,
244
+ * which settled nothing. Only one concurrent claim can replace it with the
245
+ * new reservation.
246
+ */
247
+ reservePaymentAttempt(reservation: PaymentAttemptReservation): Promise<PaymentAttempt>;
248
+ /** Must not change an attempt that has a resolution; the SQLite store throws `STORAGE_ERROR` */
249
+ updatePaymentAttempt(update: PaymentAttemptUpdate): Promise<void>;
250
+ saveReceipt(receipt: CommerceReceipt): Promise<void>;
251
+ getReceipt(id: string): Promise<CommerceReceipt | undefined>;
252
+ listReceipts(options?: ReceiptListOptions): Promise<readonly CommerceReceipt[]>;
253
+ /**
254
+ * Total receipts held. `listReceipts` clamps every page, so counting a list's
255
+ * length would stop at the clamp.
256
+ */
257
+ countReceipts(): Promise<number>;
258
+ /**
259
+ * Receipts whose delivery failed: `backendStatus` outside 2xx, including 0
260
+ * when no status is known. Counted rather than listed for the same reason as
261
+ * {@link countReceipts}.
262
+ *
263
+ * In practice this is "paid but undelivered": the pipeline writes a receipt
264
+ * for a failed delivery only after a settled payment, so a free resource
265
+ * whose backend fails leaves no row here. It is the row a merchant must
266
+ * notice, because settlement is final and the gateway issues no refunds.
267
+ */
268
+ countUndeliveredReceipts(): Promise<number>;
269
+ /**
270
+ * Counts `settlement-uncertain` and legacy `failed` payment attempts.
271
+ * Funds may have moved, but the pipeline withholds delivery and writes no
272
+ * receipt for an uncertain settlement. {@link countUndeliveredReceipts}
273
+ * therefore misses these attempts. Reconcile them on chain using
274
+ * `externalReference` when it holds a transaction hash.
275
+ */
276
+ countUncertainPaymentAttempts(): Promise<number>;
277
+ listEvents(options?: ListOptions): Promise<readonly CommerceEvent[]>;
278
+ listPaymentAttempts(options?: PaymentAttemptListOptions): Promise<readonly PaymentAttempt[]>;
279
+ /**
280
+ * Record a journal step. Journal methods are optional for compatibility with
281
+ * stores that do not support the journal. Implementations must also recompute
282
+ * a transaction's cached state atomically with payment-attempt updates.
283
+ */
284
+ recordTransactionStep?(step: TransactionStep): Promise<void>;
285
+ getTransaction?(id: string): Promise<Transaction | undefined>;
286
+ listTransactions?(options?: TransactionListOptions): Promise<TransactionPage>;
287
+ getPaymentAttempt?(id: string): Promise<PaymentAttempt | undefined>;
288
+ /**
289
+ * Returns the current attempt holding `replayKey`, excluding attempts
290
+ * replaced by a reclaim. If a rejected proof carries this key, the pipeline
291
+ * uses the lookup to return `PAYMENT_REPLAYED` while its attempt is unfinished.
292
+ * Experimental: may change in a minor release.
293
+ */
294
+ findPaymentAttemptByReplayKey?(replayKey: string): Promise<PaymentAttempt | undefined>;
295
+ /**
296
+ * Compare-and-set: return `false` without writing if the attempt's status
297
+ * differs from `expectedStatus` or it already has a resolution
298
+ */
299
+ resolvePaymentAttempt?(request: PaymentAttemptResolveRequest): Promise<boolean>;
300
+ /**
301
+ * Idempotency claims for protocol adapters. A store must implement all three
302
+ * methods or none. Experimental: may change in a minor release.
303
+ *
304
+ * Atomically claim `scope` after deleting expired `completed` claims and
305
+ * expired `unresolved` claims on `PAYMENT_KEY_ENDPOINT_PREFIX` endpoints.
306
+ * Expiry occurs at `expiresAt`; other claims do not expire. Return `reserved`
307
+ * for a new scope, or `conflict` for a different `fingerprint` in any state.
308
+ *
309
+ * New claims retain `owner`, an opaque non-secret tag returned with
310
+ * `in-flight` and `unresolved` results. Completed claims return their response
311
+ * instead; the tag is unavailable after release or expiry.
312
+ */
313
+ claimIdempotencyKey?(scope: IdempotencyScope, fingerprint: string, expiresAt: IsoTimestamp, owner?: string): Promise<IdempotencyClaim>;
314
+ /** Record a claim's outcome. Experimental: may change in a minor release */
315
+ updateIdempotencyKey?(scope: IdempotencyScope, update: IdempotencyUpdate): Promise<void>;
316
+ /**
317
+ * Call at startup before accepting claims. Mark every `in-flight` claim
318
+ * `unresolved`, or delete them if `release` is true. Return the number
319
+ * changed. Assumes one gateway per store. Experimental: may change in a
320
+ * minor release.
321
+ */
322
+ recoverIdempotencyKeys?(options: {
323
+ readonly release: boolean;
324
+ /** Match endpoints by a literal, case-sensitive prefix; omit to include all endpoints */
325
+ readonly endpointPrefix?: string;
326
+ }): Promise<number>;
327
+ /**
328
+ * Read a claim without writing. Return `undefined` if the claim is absent
329
+ * or expired under `claimIdempotencyKey`'s rule. Otherwise, return the same
330
+ * result as `claimIdempotencyKey`. Experimental: may change in a minor release.
331
+ */
332
+ getIdempotencyKey?(scope: IdempotencyScope, fingerprint: string): Promise<IdempotencyClaim | undefined>;
333
+ /**
334
+ * Authorization holds for authorization providers. A store must implement
335
+ * all four methods or none. Experimental: may change in a minor release.
336
+ *
337
+ * Atomically reserve a hold. Return `replayed` with the existing holder's
338
+ * state if this reference, or another with the same `bindingReference`, is
339
+ * not `released`. A released reference can be reserved again by the new
340
+ * `requestId`.
341
+ */
342
+ reserveAuthorizationHold?(reservation: AuthorizationHoldReservation): Promise<AuthorizationHoldResult>;
343
+ /**
344
+ * Move a `reserved` or `uncertain` hold to `to`. This method leaves
345
+ * `consumed` and `released` holds unchanged. When supplied, `requestId`
346
+ * restricts changes to that request's hold. Return true when the hold is
347
+ * in `to`, including on repeated calls. If `requestId` no longer holds the
348
+ * reference, leave the current hold unchanged and return true only when
349
+ * `to` is `released`. Return false otherwise. Experimental: may change in
350
+ * a minor release.
351
+ */
352
+ transitionAuthorizationHold?(reference: string, to: Exclude<AuthorizationHoldState, 'reserved'>, requestId?: string): Promise<boolean>;
353
+ /** Experimental: may change in a minor release */
354
+ getAuthorizationHoldState?(reference: string): Promise<AuthorizationHoldState | undefined>;
355
+ /**
356
+ * List `reserved` holds last updated before `updatedBefore`, oldest first,
357
+ * whose request has no current or replaced payment attempt. The pipeline
358
+ * reserves an attempt before settlement, so after the request ends it cannot
359
+ * settle a payment for such a hold. Experimental: may change in a minor
360
+ * release.
361
+ */
362
+ listOrphanAuthorizationHolds?(options: {
363
+ readonly updatedBefore: IsoTimestamp;
364
+ readonly limit?: number;
365
+ }): Promise<readonly AuthorizationHold[]>;
366
+ /**
367
+ * Pending tasks for protocol adapters. A store must implement all three
368
+ * methods or none. Experimental: may change in a minor release.
369
+ *
370
+ * Delete expired tasks, then store `task`, replacing any task with the same
371
+ * ID. Return false without storing when `maxTasks` unexpired tasks exist.
372
+ */
373
+ putPendingTask?(task: PendingTask, options: {
374
+ readonly maxTasks: number;
375
+ }): Promise<boolean>;
376
+ /** Return undefined for a missing or expired task. Experimental: may change in a minor release */
377
+ getPendingTask?(id: string): Promise<PendingTask | undefined>;
378
+ /**
379
+ * Atomically delete and return the task. Return undefined if it has expired
380
+ * or a concurrent or earlier call already took it. Experimental: may change
381
+ * in a minor release.
382
+ */
383
+ takePendingTask?(id: string): Promise<PendingTask | undefined>;
384
+ readonly descriptor: AdapterDescriptor;
385
+ health(): Promise<AdapterHealth>;
386
+ close(): Promise<void>;
387
+ }
388
+
389
+ export type { AuthorizationHold as A, IdempotencyClaim as I, ListOptions as L, NewTransaction as N, PaymentAttemptListOptions as P, ReceiptStore as R, TransactionListOptions as T, AuthorizationHoldReservation as a, AuthorizationHoldResult as b, IdempotencyScope as c, IdempotencyUpdate as d, PaymentAttemptReservation as e, PaymentAttemptResolveRequest as f, PaymentAttemptUpdate as g, PendingTask as h, ReceiptListOptions as i, TransactionPage as j, TransactionStep as k };
@@ -0,0 +1,51 @@
1
+ import { Clock } from './index.js';
2
+ import { ReceiptStore } from './index.js';
3
+ import './transaction-BXXJltZ-.js';
4
+
5
+ /**
6
+ * Receipt store conformance cases for use with any test runner. Each case has
7
+ * a name, an optional skip reason and a `run()` using `node:assert/strict`.
8
+ * For example, wrap them with Vitest:
9
+ *
10
+ * ```ts
11
+ * const cases = await receiptStoreConformanceCases(open);
12
+ * for (const c of cases) it.skipIf(c.skip !== undefined)(c.name, () => c.run());
13
+ * ```
14
+ */
15
+
16
+ /** Experimental: may change in a minor release */
17
+ interface ConformanceContext {
18
+ /** Pass it to the store: expiry cases move it instead of waiting */
19
+ readonly clock: Clock;
20
+ }
21
+ /** Experimental: may change in a minor release */
22
+ interface ConformanceStore {
23
+ /** A new, empty store; the suite calls `init()` and `close()` */
24
+ readonly store: ReceiptStore;
25
+ /**
26
+ * Close the current store and return a new one using the same data.
27
+ * Durability cases are skipped when this function is absent.
28
+ */
29
+ readonly reopen?: () => Promise<ReceiptStore>;
30
+ }
31
+ /**
32
+ * Creates stores for capability discovery and individual cases. Experimental:
33
+ * may change in a minor release.
34
+ */
35
+ type ConformanceStoreFactory = (context: ConformanceContext) => ConformanceStore | Promise<ConformanceStore>;
36
+ /** Experimental: may change in a minor release */
37
+ interface ConformanceCase {
38
+ readonly name: string;
39
+ /** Why the case does not apply to this store. Report it as skipped, never as passed */
40
+ readonly skip?: string;
41
+ run(): Promise<void>;
42
+ }
43
+ /**
44
+ * Build cases for the stores `open` creates. Probe one store to identify its
45
+ * optional methods and whether the factory supports reopening. Experimental:
46
+ * may change in a minor release.
47
+ */
48
+ declare function receiptStoreConformanceCases(open: ConformanceStoreFactory): Promise<readonly ConformanceCase[]>;
49
+
50
+ export { receiptStoreConformanceCases };
51
+ export type { ConformanceCase, ConformanceContext, ConformanceStore, ConformanceStoreFactory };