@devlab.group/agent-commerce 2.6.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.
- package/README.md +17 -12
- package/dist/ap2.d.ts +1 -1
- package/dist/ap2.js +5 -5
- package/dist/{chunk-ES3V6ECS.js → chunk-77HLISG4.js} +3 -2
- package/dist/chunk-77HLISG4.js.map +1 -0
- package/dist/{chunk-5ZYXBCDX.js → chunk-D7FPSGUQ.js} +25 -4
- package/dist/chunk-D7FPSGUQ.js.map +1 -0
- package/dist/{chunk-G3EYYHKF.js → chunk-DJRWYDKJ.js} +3 -3
- package/dist/{chunk-G3EYYHKF.js.map → chunk-DJRWYDKJ.js.map} +1 -1
- package/dist/{chunk-M6MQ3FYS.js → chunk-EMKITGVV.js} +4 -4
- package/dist/chunk-EMKITGVV.js.map +1 -0
- package/dist/chunk-IWXVQYG5.js +6 -0
- package/dist/chunk-IWXVQYG5.js.map +1 -0
- package/dist/chunk-O3ACF45K.js +8 -0
- package/dist/{chunk-M6BSXXTF.js.map → chunk-O3ACF45K.js.map} +1 -1
- package/dist/{chunk-M6WW6QIT.js → chunk-WDD2ZUR3.js} +5 -3
- package/dist/chunk-WDD2ZUR3.js.map +1 -0
- package/dist/{chunk-M52FBNJX.js → chunk-YHNTTMED.js} +6 -4
- package/dist/chunk-YHNTTMED.js.map +1 -0
- package/dist/{chunk-DRLBML7Z.js → chunk-ZSIUZPNB.js} +175 -74
- package/dist/chunk-ZSIUZPNB.js.map +1 -0
- package/dist/cli/{ap2-2YMYA2H6.js → ap2-5FFGSW6F.js} +10 -11
- package/dist/cli/ap2-5FFGSW6F.js.map +1 -0
- package/dist/cli/{chunk-5K4XEAZV.js → chunk-3IEXJ7I3.js} +25 -4
- package/dist/cli/chunk-3IEXJ7I3.js.map +1 -0
- package/dist/cli/{chunk-VJH6RYRK.js → chunk-3NVJAQRO.js} +3 -3
- package/dist/cli/{chunk-VJH6RYRK.js.map → chunk-3NVJAQRO.js.map} +1 -1
- package/dist/cli/{chunk-GET3CZGR.js → chunk-55AI6CLW.js} +6 -4
- package/dist/cli/chunk-55AI6CLW.js.map +1 -0
- package/dist/cli/{chunk-YOF7IK4V.js → chunk-5K2JDM4G.js} +177 -76
- package/dist/cli/chunk-5K2JDM4G.js.map +1 -0
- package/dist/cli/{chunk-NSYSMDQN.js → chunk-5TID36YG.js} +57 -29
- package/dist/cli/chunk-5TID36YG.js.map +1 -0
- package/dist/cli/{chunk-3NOMLMJW.js → chunk-66NTYSXI.js} +3 -3
- package/dist/cli/{chunk-3NOMLMJW.js.map → chunk-66NTYSXI.js.map} +1 -1
- package/dist/cli/{chunk-VJ4EO4LE.js → chunk-6EBDOH37.js} +3 -3
- package/dist/cli/{chunk-VJ4EO4LE.js.map → chunk-6EBDOH37.js.map} +1 -1
- package/dist/cli/{chunk-YWG2ZN3L.js → chunk-AGQ4U7IN.js} +5 -5
- package/dist/cli/chunk-AGQ4U7IN.js.map +1 -0
- package/dist/cli/chunk-APC5BTQM.js +6 -0
- package/dist/cli/chunk-APC5BTQM.js.map +1 -0
- package/dist/cli/{chunk-SYQLJXIU.js → chunk-C5YISPT6.js} +3 -3
- package/dist/cli/chunk-C5YISPT6.js.map +1 -0
- package/dist/cli/chunk-DKWO6LLX.js +34 -0
- package/dist/cli/chunk-DKWO6LLX.js.map +1 -0
- package/dist/cli/{chunk-SPAYKVUP.js → chunk-FL4HPCD4.js} +3 -2
- package/dist/cli/chunk-FL4HPCD4.js.map +1 -0
- package/dist/cli/{chunk-3EQBCFZY.js → chunk-H7EBJ4I3.js} +3 -3
- package/dist/cli/{chunk-3EQBCFZY.js.map → chunk-H7EBJ4I3.js.map} +1 -1
- package/dist/cli/{chunk-PTL7SNOI.js → chunk-OETKXDGA.js} +467 -122
- package/dist/cli/chunk-OETKXDGA.js.map +1 -0
- package/dist/cli/{chunk-DHFMIBPG.js → chunk-PLHPKXAT.js} +6 -6
- package/dist/cli/{chunk-DHFMIBPG.js.map → chunk-PLHPKXAT.js.map} +1 -1
- package/dist/cli/{chunk-TFV3K6YS.js → chunk-VSSSU4AU.js} +3 -3
- package/dist/cli/{chunk-TFV3K6YS.js.map → chunk-VSSSU4AU.js.map} +1 -1
- package/dist/cli/chunk-ZCW56PZ3.js +8 -0
- package/dist/cli/{chunk-4KLYFXMW.js.map → chunk-ZCW56PZ3.js.map} +1 -1
- package/dist/cli/{chunk-AZL7RPFU.js → chunk-ZFVQWOGG.js} +64 -16
- package/dist/cli/chunk-ZFVQWOGG.js.map +1 -0
- package/dist/cli/config-WT5HHDRR.js +13 -0
- package/dist/cli/{config-3K65QJ22.js.map → config-WT5HHDRR.js.map} +1 -1
- package/dist/cli/index.js +51 -37
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-6F64A7KE.js → mcp-HHGNOUKE.js} +7 -7
- package/dist/cli/{mcp-6F64A7KE.js.map → mcp-HHGNOUKE.js.map} +1 -1
- package/dist/cli/payment-providers-EWXZFBIE.js +6 -0
- package/dist/cli/{payment-providers-2ITS6KNR.js.map → payment-providers-EWXZFBIE.js.map} +1 -1
- package/dist/cli/{provider-5BGG5YKQ.js → provider-XUPLYNQ7.js} +9 -9
- package/dist/cli/{provider-5BGG5YKQ.js.map → provider-XUPLYNQ7.js.map} +1 -1
- package/dist/cli/receipts-3DSV4DIK.js +9 -0
- package/dist/cli/{receipts-I4IIE7U6.js.map → receipts-3DSV4DIK.js.map} +1 -1
- package/dist/cli/reconcile-GS25MQ42.js +4 -0
- package/dist/cli/{reconcile-55WNCSFC.js.map → reconcile-GS25MQ42.js.map} +1 -1
- package/dist/cli/{run-2P6ZGFUE.js → run-7KLKW3HE.js} +107 -35
- package/dist/cli/run-7KLKW3HE.js.map +1 -0
- package/dist/cli/{x402-4LPIIELI.js → x402-HP4E3QET.js} +11 -10
- package/dist/cli/x402-HP4E3QET.js.map +1 -0
- package/dist/{guardrails-CX_jYXvZ.d.ts → guardrails-CeyLS1ou.d.ts} +2 -2
- package/dist/index.d.ts +23 -13
- package/dist/index.js +660 -170
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +4 -4
- package/dist/mpp.js +5 -5
- package/dist/{protocol-adapter-1WbtM3xG.d.ts → protocol-adapter-DdFL5LBU.d.ts} +12 -2
- package/dist/{runtime-B-kARa2f.d.ts → runtime-BmaSp2Ce.d.ts} +31 -3
- package/dist/{store-kIIMpUA-.d.ts → store-BVvMzpuV.d.ts} +25 -8
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +156 -2
- package/dist/testing.js.map +1 -1
- package/dist/{transaction-Dv0UFGg5.d.ts → transaction-BXXJltZ-.d.ts} +1 -1
- package/dist/x402.d.ts +7 -2
- package/dist/x402.js +7 -6
- package/dist/x402.js.map +1 -1
- package/package.json +13 -29
- package/dist/chunk-5ZYXBCDX.js.map +0 -1
- package/dist/chunk-DRLBML7Z.js.map +0 -1
- package/dist/chunk-ES3V6ECS.js.map +0 -1
- package/dist/chunk-M52FBNJX.js.map +0 -1
- package/dist/chunk-M6BSXXTF.js +0 -8
- package/dist/chunk-M6MQ3FYS.js.map +0 -1
- package/dist/chunk-M6WW6QIT.js.map +0 -1
- package/dist/cli/ap2-2YMYA2H6.js.map +0 -1
- package/dist/cli/chunk-4KLYFXMW.js +0 -8
- package/dist/cli/chunk-5K4XEAZV.js.map +0 -1
- package/dist/cli/chunk-6R6WJ4FD.js +0 -18
- package/dist/cli/chunk-6R6WJ4FD.js.map +0 -1
- package/dist/cli/chunk-AZL7RPFU.js.map +0 -1
- package/dist/cli/chunk-FHCFR2GS.js +0 -17
- package/dist/cli/chunk-FHCFR2GS.js.map +0 -1
- package/dist/cli/chunk-GET3CZGR.js.map +0 -1
- package/dist/cli/chunk-NSYSMDQN.js.map +0 -1
- package/dist/cli/chunk-PTL7SNOI.js.map +0 -1
- package/dist/cli/chunk-SPAYKVUP.js.map +0 -1
- package/dist/cli/chunk-SYQLJXIU.js.map +0 -1
- package/dist/cli/chunk-YOF7IK4V.js.map +0 -1
- package/dist/cli/chunk-YWG2ZN3L.js.map +0 -1
- package/dist/cli/config-3K65QJ22.js +0 -12
- package/dist/cli/payment-providers-2ITS6KNR.js +0 -6
- package/dist/cli/receipts-I4IIE7U6.js +0 -8
- package/dist/cli/reconcile-55WNCSFC.js +0 -4
- package/dist/cli/run-2P6ZGFUE.js.map +0 -1
- package/dist/cli/x402-4LPIIELI.js.map +0 -1
package/dist/mcp.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpProtocolAdapter } from './index.js';
|
|
2
2
|
import 'node:http';
|
|
3
|
-
import './runtime-
|
|
4
|
-
import './transaction-
|
|
3
|
+
import './runtime-BmaSp2Ce.js';
|
|
4
|
+
import './transaction-BXXJltZ-.js';
|
|
5
5
|
import './logger-CllGwQ8i.js';
|
|
6
6
|
|
|
7
7
|
interface McpAdapterOptions {
|
package/dist/mcp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MCP_TOOL_NAME_PATTERN, readCappedBody, MCP_MODERN_PROTOCOL_REVISION, x402ErrorCode, settlementFailure, settlementResponseFromDetails, x402McpPaymentSubmission, X402_MCP_PAYMENT_META_KEY, X402_MCP_PAYMENT_RESPONSE_META_KEY, settlementResponse, X402_MCP_ERROR_META_KEY } from './chunk-
|
|
2
|
-
import { mcpPaymentRequired, MPP_MCP_CREDENTIAL_META_KEY, receiptObject, MPP_MCP_RECEIPT_META_KEY, MPP_MCP_PAYMENT_REQUIRED_META_KEY } from './chunk-
|
|
3
|
-
import { PACKAGE_VERSION } from './chunk-
|
|
4
|
-
import { toLogInfo, toCommerceError, CommerceError, extractReservedInputFields, PAYMENT_INPUT_FIELD, AUTHORIZATION_INPUT_FIELD, toErrorEnvelope, DELIVERY_SUMMARY_META_KEY, toDeliverySummary, toPaymentRequiredEnvelope } from './chunk-
|
|
1
|
+
import { MCP_TOOL_NAME_PATTERN, readCappedBody, MCP_MODERN_PROTOCOL_REVISION, x402ErrorCode, settlementFailure, settlementResponseFromDetails, x402McpPaymentSubmission, X402_MCP_PAYMENT_META_KEY, X402_MCP_PAYMENT_RESPONSE_META_KEY, settlementResponse, X402_MCP_ERROR_META_KEY } from './chunk-77HLISG4.js';
|
|
2
|
+
import { mcpPaymentRequired, MPP_MCP_CREDENTIAL_META_KEY, receiptObject, MPP_MCP_RECEIPT_META_KEY, MPP_MCP_PAYMENT_REQUIRED_META_KEY } from './chunk-D7FPSGUQ.js';
|
|
3
|
+
import { PACKAGE_VERSION } from './chunk-O3ACF45K.js';
|
|
4
|
+
import { toLogInfo, toCommerceError, CommerceError, extractReservedInputFields, PAYMENT_INPUT_FIELD, AUTHORIZATION_INPUT_FIELD, toErrorEnvelope, DELIVERY_SUMMARY_META_KEY, toDeliverySummary, toPaymentRequiredEnvelope } from './chunk-YHNTTMED.js';
|
|
5
5
|
import { isRecord } from './chunk-2CJNA7MS.js';
|
|
6
6
|
import { createMcpHandler, Server, ProtocolError, ProtocolErrorCode, LATEST_PROTOCOL_VERSION } from '@modelcontextprotocol/server';
|
|
7
7
|
|
package/dist/mpp.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { MPP_PROFILE, MPP_NETWORKS, MPP_SUPPORTED_SPEC, MPP_DEFAULT_NETWORK, MPP_MIN_CHALLENGE_SECRET_LENGTH, isMppNetwork, MPP_DEFAULT_PAYMENT_FLOW, MPP_SPEC_DRAFTS } from './chunk-6Z2H53CG.js';
|
|
2
2
|
export { MPPX_VERSION, MPP_PROFILE, MPP_SPEC_COMMIT, MPP_SPEC_DRAFTS, MPP_SPEC_REPOSITORY, MPP_SUPPORTED_SPEC } from './chunk-6Z2H53CG.js';
|
|
3
|
-
import { CONTENT_DIGEST_METADATA_KEY } from './chunk-
|
|
4
|
-
import { createX402PaymentProvider, DEFAULT_IDS, parseCanonicalAmount } from './chunk-
|
|
5
|
-
import { SETTLE_AFTER_BACKEND_METADATA_KEY } from './chunk-
|
|
6
|
-
import { PACKAGE_VERSION } from './chunk-
|
|
7
|
-
import { systemClock, CommerceError, RECONCILIATION_METADATA_KEY } from './chunk-
|
|
3
|
+
import { CONTENT_DIGEST_METADATA_KEY } from './chunk-D7FPSGUQ.js';
|
|
4
|
+
import { createX402PaymentProvider, DEFAULT_IDS, parseCanonicalAmount } from './chunk-ZSIUZPNB.js';
|
|
5
|
+
import { SETTLE_AFTER_BACKEND_METADATA_KEY } from './chunk-EMKITGVV.js';
|
|
6
|
+
import { PACKAGE_VERSION } from './chunk-O3ACF45K.js';
|
|
7
|
+
import { systemClock, CommerceError, RECONCILIATION_METADATA_KEY } from './chunk-YHNTTMED.js';
|
|
8
8
|
import { computeReplayKey, eip3009Locator } from './chunk-GA3O2A7R.js';
|
|
9
9
|
import './chunk-2CJNA7MS.js';
|
|
10
10
|
import { PERMIT2_ADDRESS } from '@x402/evm';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
-
import { K as ProtocolName, c as PaymentSubmission, d as AuthorizationSubmission, I as IsoTimestamp, E as PaymentResult, p as CommerceReceipt, z as PaymentRequirement, a as AuthorizationRequirement, g as AdapterDescriptor, R as ResourceRegistry, C as Clock, f as IdGenerator, h as AdapterHealth } from './runtime-
|
|
3
|
-
import { P as PersistenceFailure, E as EventSink } from './transaction-
|
|
2
|
+
import { K as ProtocolName, c as PaymentSubmission, d as AuthorizationSubmission, I as IsoTimestamp, E as PaymentResult, p as CommerceReceipt, z as PaymentRequirement, a as AuthorizationRequirement, g as AdapterDescriptor, R as ResourceRegistry, C as Clock, f as IdGenerator, h as AdapterHealth } from './runtime-BmaSp2Ce.js';
|
|
3
|
+
import { P as PersistenceFailure, E as EventSink } from './transaction-BXXJltZ-.js';
|
|
4
4
|
import { L as Logger } from './logger-CllGwQ8i.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -32,6 +32,11 @@ interface CanonicalRequest {
|
|
|
32
32
|
* Passed on as `BackendRequest.idempotencyKey`.
|
|
33
33
|
*/
|
|
34
34
|
readonly idempotencyKey?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Client's key for retrying this paid request. Treat it as a credential;
|
|
37
|
+
* never log it. Experimental: may change in a minor release.
|
|
38
|
+
*/
|
|
39
|
+
readonly retryKey?: string;
|
|
35
40
|
/** Adapter headers passed to the backend; configured headers take precedence */
|
|
36
41
|
readonly backendHeaders?: Readonly<Record<string, string>>;
|
|
37
42
|
/** Non-secret transport metadata, such as client id or user agent */
|
|
@@ -54,6 +59,11 @@ interface DeliveredOutcome {
|
|
|
54
59
|
* marks `receipt.id` as uncommitted.
|
|
55
60
|
*/
|
|
56
61
|
readonly persistenceFailures?: readonly PersistenceFailure[];
|
|
62
|
+
/**
|
|
63
|
+
* True when this request reuses a stored response without another charge.
|
|
64
|
+
* Experimental: may change in a minor release.
|
|
65
|
+
*/
|
|
66
|
+
readonly redelivered?: boolean;
|
|
57
67
|
}
|
|
58
68
|
/** The resource costs money and the request carried no payment proof */
|
|
59
69
|
interface PaymentRequiredOutcome {
|
|
@@ -208,6 +208,23 @@ interface CommerceResource {
|
|
|
208
208
|
readonly authorization?: {
|
|
209
209
|
readonly required: readonly AuthorizationMethodName[];
|
|
210
210
|
};
|
|
211
|
+
/**
|
|
212
|
+
* Paid retry settings, disabled when omitted. For redelivery, the x402 provider
|
|
213
|
+
* extracts `payment-identifier` IDs; the HTTP invoke route reads MPP's
|
|
214
|
+
* `Idempotency-Key` header.
|
|
215
|
+
* Experimental: may change in a minor release.
|
|
216
|
+
*/
|
|
217
|
+
readonly idempotency?: {
|
|
218
|
+
/** Send the backend an `Idempotency-Key` identifying this paid operation */
|
|
219
|
+
readonly merchantKey?: boolean;
|
|
220
|
+
/** Store delivered responses for retries with the same client key */
|
|
221
|
+
readonly redelivery?: {
|
|
222
|
+
/** Hours from the initial retry check to the stored response's expiry */
|
|
223
|
+
readonly retentionHours: number;
|
|
224
|
+
/** If true, reject a missing `id` during x402 retry-key extraction with HTTP 400 */
|
|
225
|
+
readonly required: boolean;
|
|
226
|
+
};
|
|
227
|
+
};
|
|
211
228
|
}
|
|
212
229
|
/** Read-only view of every configured resource */
|
|
213
230
|
interface ResourceRegistry {
|
|
@@ -378,6 +395,15 @@ interface PaymentProvider {
|
|
|
378
395
|
* paid request, including one that already carries a proof to verify.
|
|
379
396
|
*/
|
|
380
397
|
createRequirement(context: PaymentContext): Promise<PaymentRequirement>;
|
|
398
|
+
/**
|
|
399
|
+
* Extract a client retry key from a proof without I/O. Return `undefined`
|
|
400
|
+
* if the proof has no key; throw `INPUT_INVALID` if the key is malformed.
|
|
401
|
+
* Experimental: may change in a minor release.
|
|
402
|
+
*/
|
|
403
|
+
retryKey?(context: {
|
|
404
|
+
readonly resource: CommerceResource;
|
|
405
|
+
readonly submission: PaymentSubmission;
|
|
406
|
+
}): string | undefined;
|
|
381
407
|
/**
|
|
382
408
|
* Selects a proof's offer before verification, returning its destination,
|
|
383
409
|
* network, asset and metadata while preserving `id` and the full `challenge`.
|
|
@@ -393,9 +419,11 @@ interface PaymentProvider {
|
|
|
393
419
|
*/
|
|
394
420
|
verify(context: PaymentVerificationContext): Promise<PaymentResult>;
|
|
395
421
|
/**
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
422
|
+
* Called only after `verify` returns `verified` and the replay key is reserved.
|
|
423
|
+
* Return a settlement verdict, including rejection. The pipeline records a
|
|
424
|
+
* throw as `settlement-uncertain`, unless a `CommerceError` has
|
|
425
|
+
* `details.settlementNotSubmitted: true`; that records `rejected` and releases
|
|
426
|
+
* the authorization hold.
|
|
399
427
|
*/
|
|
400
428
|
settle(context: PaymentSettlementContext): Promise<PaymentResult>;
|
|
401
429
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
2
|
-
import { A as AuthorizationHoldState, a as CommerceEvent, P as PersistenceFailure, c as Transaction, e as TransactionState } from './transaction-
|
|
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
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Protocol-neutral records for the receipt store's optional methods:
|
|
@@ -15,7 +15,10 @@ interface IdempotencyScope {
|
|
|
15
15
|
readonly endpoint: string;
|
|
16
16
|
readonly key: string;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
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
|
+
*/
|
|
19
22
|
type IdempotencyClaim =
|
|
20
23
|
/** The caller owns the key and must perform the operation */
|
|
21
24
|
{
|
|
@@ -24,10 +27,12 @@ type IdempotencyClaim =
|
|
|
24
27
|
/** Same fingerprint; an earlier claim is still in flight */
|
|
25
28
|
| {
|
|
26
29
|
readonly kind: 'in-flight';
|
|
30
|
+
readonly owner?: string;
|
|
27
31
|
}
|
|
28
32
|
/** Same fingerprint; an earlier attempt's outcome is unknown */
|
|
29
33
|
| {
|
|
30
34
|
readonly kind: 'unresolved';
|
|
35
|
+
readonly owner?: string;
|
|
31
36
|
}
|
|
32
37
|
/** A different fingerprint, regardless of the claim's state */
|
|
33
38
|
| {
|
|
@@ -296,12 +301,16 @@ interface ReceiptStore {
|
|
|
296
301
|
* Idempotency claims for protocol adapters. A store must implement all three
|
|
297
302
|
* methods or none. Experimental: may change in a minor release.
|
|
298
303
|
*
|
|
299
|
-
* Atomically claim `scope` after deleting `completed` claims
|
|
300
|
-
* `
|
|
301
|
-
*
|
|
302
|
-
*
|
|
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.
|
|
303
312
|
*/
|
|
304
|
-
claimIdempotencyKey?(scope: IdempotencyScope, fingerprint: string, expiresAt: IsoTimestamp): Promise<IdempotencyClaim>;
|
|
313
|
+
claimIdempotencyKey?(scope: IdempotencyScope, fingerprint: string, expiresAt: IsoTimestamp, owner?: string): Promise<IdempotencyClaim>;
|
|
305
314
|
/** Record a claim's outcome. Experimental: may change in a minor release */
|
|
306
315
|
updateIdempotencyKey?(scope: IdempotencyScope, update: IdempotencyUpdate): Promise<void>;
|
|
307
316
|
/**
|
|
@@ -312,7 +321,15 @@ interface ReceiptStore {
|
|
|
312
321
|
*/
|
|
313
322
|
recoverIdempotencyKeys?(options: {
|
|
314
323
|
readonly release: boolean;
|
|
324
|
+
/** Match endpoints by a literal, case-sensitive prefix; omit to include all endpoints */
|
|
325
|
+
readonly endpointPrefix?: string;
|
|
315
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>;
|
|
316
333
|
/**
|
|
317
334
|
* Authorization holds for authorization providers. A store must implement
|
|
318
335
|
* all four methods or none. Experimental: may change in a minor release.
|
package/dist/testing.d.ts
CHANGED
package/dist/testing.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PAYMENT_KEY_ENDPOINT_PREFIX } from './chunk-IWXVQYG5.js';
|
|
2
|
+
import { STORE_METHOD_GROUPS } from './chunk-WDD2ZUR3.js';
|
|
3
|
+
import { transactionState } from './chunk-YHNTTMED.js';
|
|
3
4
|
import './chunk-2CJNA7MS.js';
|
|
4
5
|
import assert2 from 'assert/strict';
|
|
5
6
|
|
|
@@ -1317,11 +1318,13 @@ var CORE_CASES = [
|
|
|
1317
1318
|
...DURABILITY_CASES
|
|
1318
1319
|
];
|
|
1319
1320
|
var CLAIMS = STORE_METHOD_GROUPS.idempotency_claims;
|
|
1321
|
+
var CLAIM_READS = [...CLAIMS, ...STORE_METHOD_GROUPS.response_redelivery];
|
|
1320
1322
|
var HOLDS = STORE_METHOD_GROUPS.authorization_holds;
|
|
1321
1323
|
var TASKS = STORE_METHOD_GROUPS.pending_tasks;
|
|
1322
1324
|
var MINUTE = 6e4;
|
|
1323
1325
|
var DAY = 24 * 60 * MINUTE;
|
|
1324
1326
|
var claims = (store) => store;
|
|
1327
|
+
var claimReads = (store) => store;
|
|
1325
1328
|
var holds = (store) => store;
|
|
1326
1329
|
var tasks = (store) => store;
|
|
1327
1330
|
var scope = (key, endpoint = "/acp/checkout_sessions") => ({
|
|
@@ -1453,6 +1456,102 @@ var CLAIM_CASES = [
|
|
|
1453
1456
|
});
|
|
1454
1457
|
}
|
|
1455
1458
|
},
|
|
1459
|
+
{
|
|
1460
|
+
name: "reading an idempotency scope answers as a claim would and creates nothing",
|
|
1461
|
+
uses: CLAIM_READS,
|
|
1462
|
+
async run({ store }) {
|
|
1463
|
+
const s = claimReads(store);
|
|
1464
|
+
assert2.equal(await s.getIdempotencyKey(scope("k1"), "fp"), void 0);
|
|
1465
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
|
|
1466
|
+
kind: "reserved"
|
|
1467
|
+
});
|
|
1468
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), { kind: "in-flight" });
|
|
1469
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "other"), { kind: "conflict" });
|
|
1470
|
+
await s.updateIdempotencyKey(scope("k1"), { kind: "unresolved" });
|
|
1471
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), { kind: "unresolved" });
|
|
1472
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "other"), { kind: "conflict" });
|
|
1473
|
+
await s.claimIdempotencyKey(scope("k2"), "fp", isoAt(DAY));
|
|
1474
|
+
await s.updateIdempotencyKey(scope("k2"), {
|
|
1475
|
+
kind: "completed",
|
|
1476
|
+
status: 201,
|
|
1477
|
+
body: { id: "cs_1" }
|
|
1478
|
+
});
|
|
1479
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("k2"), "fp"), {
|
|
1480
|
+
kind: "replay",
|
|
1481
|
+
status: 201,
|
|
1482
|
+
body: { id: "cs_1" }
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
},
|
|
1486
|
+
{
|
|
1487
|
+
name: "an expired completed claim reads as absent, and other checkout claims never expire",
|
|
1488
|
+
uses: CLAIM_READS,
|
|
1489
|
+
async run({ store, clock }) {
|
|
1490
|
+
const s = claimReads(store);
|
|
1491
|
+
await s.claimIdempotencyKey(scope("done"), "fp", isoAt(MINUTE));
|
|
1492
|
+
await s.updateIdempotencyKey(scope("done"), { kind: "completed", status: 200, body: {} });
|
|
1493
|
+
await s.claimIdempotencyKey(scope("running"), "fp", isoAt(MINUTE));
|
|
1494
|
+
await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(MINUTE));
|
|
1495
|
+
await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
|
|
1496
|
+
clock.advance(MINUTE - 1);
|
|
1497
|
+
assert2.equal((await s.getIdempotencyKey(scope("done"), "fp"))?.kind, "replay");
|
|
1498
|
+
clock.advance(1);
|
|
1499
|
+
assert2.equal(await s.getIdempotencyKey(scope("done"), "fp"), void 0);
|
|
1500
|
+
assert2.equal(await s.getIdempotencyKey(scope("done"), "other"), void 0);
|
|
1501
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("running"), "fp"), { kind: "in-flight" });
|
|
1502
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("unknown"), "fp"), { kind: "unresolved" });
|
|
1503
|
+
}
|
|
1504
|
+
},
|
|
1505
|
+
{
|
|
1506
|
+
name: "an expired unresolved payment key reads as absent and can be claimed again",
|
|
1507
|
+
uses: CLAIM_READS,
|
|
1508
|
+
async run({ store, clock }) {
|
|
1509
|
+
const s = claimReads(store);
|
|
1510
|
+
const paid = scope("paid", `${PAYMENT_KEY_ENDPOINT_PREFIX}report`);
|
|
1511
|
+
await s.claimIdempotencyKey(paid, "fp", isoAt(MINUTE));
|
|
1512
|
+
await s.updateIdempotencyKey(paid, { kind: "unresolved" });
|
|
1513
|
+
await s.claimIdempotencyKey(scope("acp"), "fp", isoAt(MINUTE));
|
|
1514
|
+
await s.updateIdempotencyKey(scope("acp"), { kind: "unresolved" });
|
|
1515
|
+
clock.advance(MINUTE - 1);
|
|
1516
|
+
assert2.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "unresolved" });
|
|
1517
|
+
clock.advance(1);
|
|
1518
|
+
assert2.equal(await s.getIdempotencyKey(paid, "fp"), void 0);
|
|
1519
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("acp"), "fp"), { kind: "unresolved" });
|
|
1520
|
+
assert2.deepEqual(await s.claimIdempotencyKey(paid, "fp", isoAt(DAY)), { kind: "reserved" });
|
|
1521
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("acp"), "fp", isoAt(DAY)), {
|
|
1522
|
+
kind: "unresolved"
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
},
|
|
1526
|
+
{
|
|
1527
|
+
name: "an unfinished claim returns its owner until it completes, and a conflict never does",
|
|
1528
|
+
uses: CLAIM_READS,
|
|
1529
|
+
async run({ store }) {
|
|
1530
|
+
const s = claimReads(store);
|
|
1531
|
+
const owned = { kind: "in-flight", owner: "proof-1" };
|
|
1532
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY), "proof-1"), {
|
|
1533
|
+
kind: "reserved"
|
|
1534
|
+
});
|
|
1535
|
+
assert2.deepEqual(
|
|
1536
|
+
await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY), "proof-2"),
|
|
1537
|
+
owned
|
|
1538
|
+
);
|
|
1539
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), owned);
|
|
1540
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "other"), { kind: "conflict" });
|
|
1541
|
+
assert2.equal(await s.recoverIdempotencyKeys({ release: false }), 1);
|
|
1542
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("k1"), "fp"), {
|
|
1543
|
+
kind: "unresolved",
|
|
1544
|
+
owner: "proof-1"
|
|
1545
|
+
});
|
|
1546
|
+
await s.claimIdempotencyKey(scope("k2"), "fp", isoAt(DAY), "proof-3");
|
|
1547
|
+
await s.updateIdempotencyKey(scope("k2"), { kind: "completed", status: 200, body: "ok" });
|
|
1548
|
+
assert2.deepEqual(await s.getIdempotencyKey(scope("k2"), "fp"), {
|
|
1549
|
+
kind: "replay",
|
|
1550
|
+
status: 200,
|
|
1551
|
+
body: "ok"
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
},
|
|
1456
1555
|
{
|
|
1457
1556
|
name: "recovery marks in-flight claims unresolved and counts them",
|
|
1458
1557
|
uses: CLAIMS,
|
|
@@ -1487,6 +1586,61 @@ var CLAIM_CASES = [
|
|
|
1487
1586
|
});
|
|
1488
1587
|
}
|
|
1489
1588
|
},
|
|
1589
|
+
{
|
|
1590
|
+
name: "recovery without an endpoint prefix reaches every endpoint",
|
|
1591
|
+
uses: CLAIMS,
|
|
1592
|
+
async run({ store }) {
|
|
1593
|
+
const s = claims(store);
|
|
1594
|
+
const paid = scope("b", "payment:report");
|
|
1595
|
+
await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY));
|
|
1596
|
+
await s.claimIdempotencyKey(paid, "fp", isoAt(DAY));
|
|
1597
|
+
assert2.equal(await s.recoverIdempotencyKeys({ release: false }), 2);
|
|
1598
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY)), {
|
|
1599
|
+
kind: "unresolved"
|
|
1600
|
+
});
|
|
1601
|
+
assert2.deepEqual(await s.claimIdempotencyKey(paid, "fp", isoAt(DAY)), {
|
|
1602
|
+
kind: "unresolved"
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
},
|
|
1606
|
+
{
|
|
1607
|
+
name: "recovery with an endpoint prefix leaves other endpoints alone",
|
|
1608
|
+
uses: CLAIM_READS,
|
|
1609
|
+
async run({ store }) {
|
|
1610
|
+
const s = claimReads(store);
|
|
1611
|
+
const checkout = scope("a");
|
|
1612
|
+
const paid = scope("b", "payment:report");
|
|
1613
|
+
const running = scope("c", "payment:report");
|
|
1614
|
+
await s.claimIdempotencyKey(checkout, "fp", isoAt(DAY));
|
|
1615
|
+
await s.claimIdempotencyKey(paid, "fp", isoAt(DAY));
|
|
1616
|
+
const marked = { release: false, endpointPrefix: "payment:" };
|
|
1617
|
+
assert2.equal(await s.recoverIdempotencyKeys(marked), 1);
|
|
1618
|
+
assert2.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "unresolved" });
|
|
1619
|
+
assert2.deepEqual(await s.getIdempotencyKey(checkout, "fp"), { kind: "in-flight" });
|
|
1620
|
+
await s.claimIdempotencyKey(running, "fp", isoAt(DAY));
|
|
1621
|
+
assert2.equal(await s.recoverIdempotencyKeys({ release: true, endpointPrefix: "/" }), 1);
|
|
1622
|
+
assert2.equal(await s.getIdempotencyKey(checkout, "fp"), void 0);
|
|
1623
|
+
assert2.deepEqual(await s.getIdempotencyKey(running, "fp"), { kind: "in-flight" });
|
|
1624
|
+
assert2.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "unresolved" });
|
|
1625
|
+
}
|
|
1626
|
+
},
|
|
1627
|
+
{
|
|
1628
|
+
name: "an endpoint prefix is literal text",
|
|
1629
|
+
uses: CLAIM_READS,
|
|
1630
|
+
async run({ store }) {
|
|
1631
|
+
const s = claimReads(store);
|
|
1632
|
+
const paid = scope("a", "payment:report_1");
|
|
1633
|
+
await s.claimIdempotencyKey(paid, "fp", isoAt(DAY));
|
|
1634
|
+
const misses = ["%", "payment%", "pay_ent:", "PAYMENT:", "report", "payment:report_12"];
|
|
1635
|
+
for (const endpointPrefix of misses) {
|
|
1636
|
+
const changed = await s.recoverIdempotencyKeys({ release: true, endpointPrefix });
|
|
1637
|
+
assert2.equal(changed, 0, endpointPrefix);
|
|
1638
|
+
}
|
|
1639
|
+
assert2.deepEqual(await s.getIdempotencyKey(paid, "fp"), { kind: "in-flight" });
|
|
1640
|
+
const whole = { release: true, endpointPrefix: "payment:report_1" };
|
|
1641
|
+
assert2.equal(await s.recoverIdempotencyKeys(whole), 1);
|
|
1642
|
+
}
|
|
1643
|
+
},
|
|
1490
1644
|
{
|
|
1491
1645
|
name: "concurrent claims of one idempotency scope reserve it once",
|
|
1492
1646
|
uses: CLAIMS,
|