@devlab.group/agent-commerce 2.4.1 → 2.6.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 (126) hide show
  1. package/README.md +168 -16
  2. package/dist/ap2.d.ts +42 -17
  3. package/dist/ap2.js +83 -27
  4. package/dist/ap2.js.map +1 -1
  5. package/dist/{chunk-CXWC5LWM.js → chunk-DRLBML7Z.js} +661 -75
  6. package/dist/chunk-DRLBML7Z.js.map +1 -0
  7. package/dist/{chunk-WZW5ORZH.js → chunk-G3EYYHKF.js} +3 -3
  8. package/dist/{chunk-WZW5ORZH.js.map → chunk-G3EYYHKF.js.map} +1 -1
  9. package/dist/chunk-GA3O2A7R.js +92 -0
  10. package/dist/chunk-GA3O2A7R.js.map +1 -0
  11. package/dist/{chunk-DTKU3Z2M.js → chunk-M52FBNJX.js} +36 -5
  12. package/dist/chunk-M52FBNJX.js.map +1 -0
  13. package/dist/chunk-M6BSXXTF.js +8 -0
  14. package/dist/chunk-M6BSXXTF.js.map +1 -0
  15. package/dist/{chunk-QPV3EGJO.js → chunk-M6MQ3FYS.js} +25 -4
  16. package/dist/chunk-M6MQ3FYS.js.map +1 -0
  17. package/dist/chunk-M6WW6QIT.js +18 -0
  18. package/dist/chunk-M6WW6QIT.js.map +1 -0
  19. package/dist/cli/{ap2-GWSP4LYY.js → ap2-2YMYA2H6.js} +85 -29
  20. package/dist/cli/ap2-2YMYA2H6.js.map +1 -0
  21. package/dist/cli/{chunk-OZ4LAWBK.js → chunk-3NOMLMJW.js} +29 -8
  22. package/dist/cli/chunk-3NOMLMJW.js.map +1 -0
  23. package/dist/cli/chunk-4KLYFXMW.js +8 -0
  24. package/dist/cli/{chunk-ITWNSS2B.js.map → chunk-4KLYFXMW.js.map} +1 -1
  25. package/dist/cli/chunk-663ALDZA.js +92 -0
  26. package/dist/cli/chunk-663ALDZA.js.map +1 -0
  27. package/dist/cli/chunk-6R6WJ4FD.js +18 -0
  28. package/dist/cli/chunk-6R6WJ4FD.js.map +1 -0
  29. package/dist/cli/{chunk-G2JEY7MB.js → chunk-AZL7RPFU.js} +39 -33
  30. package/dist/cli/chunk-AZL7RPFU.js.map +1 -0
  31. package/dist/cli/chunk-DHFMIBPG.js +107 -0
  32. package/dist/cli/chunk-DHFMIBPG.js.map +1 -0
  33. package/dist/cli/{chunk-QQ3WY5L3.js → chunk-GET3CZGR.js} +36 -104
  34. package/dist/cli/chunk-GET3CZGR.js.map +1 -0
  35. package/dist/cli/chunk-NSYSMDQN.js +1544 -0
  36. package/dist/cli/chunk-NSYSMDQN.js.map +1 -0
  37. package/dist/cli/{chunk-PIMFPCNZ.js → chunk-PTL7SNOI.js} +313 -138
  38. package/dist/cli/chunk-PTL7SNOI.js.map +1 -0
  39. package/dist/cli/chunk-SYQLJXIU.js +105 -0
  40. package/dist/cli/chunk-SYQLJXIU.js.map +1 -0
  41. package/dist/cli/chunk-TFV3K6YS.js +373 -0
  42. package/dist/cli/chunk-TFV3K6YS.js.map +1 -0
  43. package/dist/cli/{chunk-3MGAJ5FX.js → chunk-VJ4EO4LE.js} +3 -3
  44. package/dist/cli/{chunk-3MGAJ5FX.js.map → chunk-VJ4EO4LE.js.map} +1 -1
  45. package/dist/cli/chunk-VJH6RYRK.js +119 -0
  46. package/dist/cli/chunk-VJH6RYRK.js.map +1 -0
  47. package/dist/cli/{chunk-TNMLDPUO.js → chunk-YOF7IK4V.js} +663 -77
  48. package/dist/cli/chunk-YOF7IK4V.js.map +1 -0
  49. package/dist/cli/{chunk-WYOGIANL.js → chunk-YWG2ZN3L.js} +4 -4
  50. package/dist/cli/{chunk-WYOGIANL.js.map → chunk-YWG2ZN3L.js.map} +1 -1
  51. package/dist/cli/config-3K65QJ22.js +12 -0
  52. package/dist/cli/{config-UI4EDG4L.js.map → config-3K65QJ22.js.map} +1 -1
  53. package/dist/cli/index.js +753 -212
  54. package/dist/cli/index.js.map +1 -1
  55. package/dist/cli/{mcp-PGBRWZVA.js → mcp-6F64A7KE.js} +5 -4
  56. package/dist/cli/mcp-6F64A7KE.js.map +1 -0
  57. package/dist/cli/{near-5AY3HWYF.js → near-U6365VFX.js} +15 -4
  58. package/dist/cli/near-U6365VFX.js.map +1 -0
  59. package/dist/cli/payment-providers-2ITS6KNR.js +6 -0
  60. package/dist/cli/payment-providers-2ITS6KNR.js.map +1 -0
  61. package/dist/cli/{provider-I2ESL6RS.js → provider-5BGG5YKQ.js} +53 -24
  62. package/dist/cli/provider-5BGG5YKQ.js.map +1 -0
  63. package/dist/cli/receipts-I4IIE7U6.js +8 -0
  64. package/dist/cli/receipts-I4IIE7U6.js.map +1 -0
  65. package/dist/cli/reconcile-55WNCSFC.js +4 -0
  66. package/dist/cli/reconcile-55WNCSFC.js.map +1 -0
  67. package/dist/cli/{run-JK4ERPJV.js → run-2P6ZGFUE.js} +356 -173
  68. package/dist/cli/run-2P6ZGFUE.js.map +1 -0
  69. package/dist/cli/svm-KDSPDFJG.js +48 -0
  70. package/dist/cli/svm-KDSPDFJG.js.map +1 -0
  71. package/dist/cli/{x402-7WBFZQXV.js → x402-4LPIIELI.js} +10 -9
  72. package/dist/cli/x402-4LPIIELI.js.map +1 -0
  73. package/dist/index.d.ts +116 -113
  74. package/dist/index.js +1928 -351
  75. package/dist/index.js.map +1 -1
  76. package/dist/logger-CllGwQ8i.d.ts +19 -0
  77. package/dist/mcp.d.ts +3 -2
  78. package/dist/mcp.js +2 -1
  79. package/dist/mcp.js.map +1 -1
  80. package/dist/mpp.d.ts +2 -1
  81. package/dist/mpp.js +48 -19
  82. package/dist/mpp.js.map +1 -1
  83. package/dist/{near-D6C42VPE.js → near-FH7HPZV3.js} +15 -4
  84. package/dist/near-FH7HPZV3.js.map +1 -0
  85. package/dist/{protocol-adapter-C9odYl6l.d.ts → protocol-adapter-1WbtM3xG.d.ts} +12 -85
  86. package/dist/{runtime-Cl_BLVZV.d.ts → runtime-B-kARa2f.d.ts} +218 -15
  87. package/dist/store-kIIMpUA-.d.ts +372 -0
  88. package/dist/svm-KNC3PHMS.js +48 -0
  89. package/dist/svm-KNC3PHMS.js.map +1 -0
  90. package/dist/testing.d.ts +51 -0
  91. package/dist/testing.js +1896 -0
  92. package/dist/testing.js.map +1 -0
  93. package/dist/transaction-Dv0UFGg5.d.ts +129 -0
  94. package/dist/{types-j7MnUXYN.d.ts → types-DWqjz81-.d.ts} +5 -2
  95. package/dist/x402.d.ts +2 -1
  96. package/dist/x402.js +6 -5
  97. package/dist/x402.js.map +1 -1
  98. package/package.json +5 -1
  99. package/dist/authorization-DjAecwuW.d.ts +0 -115
  100. package/dist/chunk-CXWC5LWM.js.map +0 -1
  101. package/dist/chunk-DTKU3Z2M.js.map +0 -1
  102. package/dist/chunk-KA2AX5FH.js +0 -44
  103. package/dist/chunk-KA2AX5FH.js.map +0 -1
  104. package/dist/chunk-QPV3EGJO.js.map +0 -1
  105. package/dist/cli/ap2-GWSP4LYY.js.map +0 -1
  106. package/dist/cli/chunk-G2JEY7MB.js.map +0 -1
  107. package/dist/cli/chunk-GJIMDMYT.js +0 -639
  108. package/dist/cli/chunk-GJIMDMYT.js.map +0 -1
  109. package/dist/cli/chunk-ITWNSS2B.js +0 -8
  110. package/dist/cli/chunk-OSTCU6ZK.js +0 -44
  111. package/dist/cli/chunk-OSTCU6ZK.js.map +0 -1
  112. package/dist/cli/chunk-OZ4LAWBK.js.map +0 -1
  113. package/dist/cli/chunk-PIMFPCNZ.js.map +0 -1
  114. package/dist/cli/chunk-QQ3WY5L3.js.map +0 -1
  115. package/dist/cli/chunk-TNMLDPUO.js.map +0 -1
  116. package/dist/cli/config-UI4EDG4L.js +0 -11
  117. package/dist/cli/mcp-PGBRWZVA.js.map +0 -1
  118. package/dist/cli/near-5AY3HWYF.js.map +0 -1
  119. package/dist/cli/provider-I2ESL6RS.js.map +0 -1
  120. package/dist/cli/run-JK4ERPJV.js.map +0 -1
  121. package/dist/cli/svm-3MMYFPC7.js +0 -33
  122. package/dist/cli/svm-3MMYFPC7.js.map +0 -1
  123. package/dist/cli/x402-7WBFZQXV.js.map +0 -1
  124. package/dist/near-D6C42VPE.js.map +0 -1
  125. package/dist/svm-QEUAUNPQ.js +0 -33
  126. package/dist/svm-QEUAUNPQ.js.map +0 -1
@@ -0,0 +1,92 @@
1
+ import { getAddress, encodeAbiParameters, keccak256 } from 'viem';
2
+ import { createHash } from 'crypto';
3
+ import { PERMIT2_ADDRESS } from '@x402/evm';
4
+
5
+ // src/payments/x402/locator.ts
6
+ var LOCATOR_VERSION = 1;
7
+ var SECONDS = /^\d{1,13}$/;
8
+ var MAX_DATE_MS = 864e13;
9
+ function isoFromSeconds(seconds) {
10
+ const ms = SECONDS.test(seconds) ? Number(seconds) * 1e3 : Number.NaN;
11
+ return ms <= MAX_DATE_MS ? new Date(ms).toISOString() : void 0;
12
+ }
13
+ function eip3009Locator(network, asset, authorization) {
14
+ const { from, to, value, validAfter, validBefore, nonce } = authorization;
15
+ return withExpiry(
16
+ {
17
+ v: LOCATOR_VERSION,
18
+ network,
19
+ method: "eip3009",
20
+ asset: getAddress(asset),
21
+ from: getAddress(from),
22
+ to: getAddress(to),
23
+ value,
24
+ nonce: nonce.toLowerCase(),
25
+ validAfter,
26
+ validBefore
27
+ },
28
+ validBefore
29
+ );
30
+ }
31
+ function permit2Locator(network, transfer) {
32
+ const { asset, owner, to, amount, nonce, deadline, validAfter, proxy } = transfer;
33
+ return withExpiry(
34
+ {
35
+ v: LOCATOR_VERSION,
36
+ network,
37
+ method: "permit2",
38
+ asset: getAddress(asset),
39
+ owner: getAddress(owner),
40
+ to: getAddress(to),
41
+ amount,
42
+ nonce,
43
+ deadline,
44
+ validAfter,
45
+ proxy: getAddress(proxy)
46
+ },
47
+ deadline
48
+ );
49
+ }
50
+ function withExpiry(locator, seconds) {
51
+ const expiresAt = isoFromSeconds(seconds);
52
+ return expiresAt !== void 0 ? { ...locator, expiresAt } : locator;
53
+ }
54
+ function computeReplayKey(input) {
55
+ const encoded = encodeAbiParameters(
56
+ [{ type: "uint256" }, { type: "address" }, { type: "address" }, { type: "bytes32" }],
57
+ [BigInt(input.chainId), input.asset, input.from, input.nonce]
58
+ );
59
+ return keccak256(encoded);
60
+ }
61
+ function computePermit2ReplayKey(input) {
62
+ return keccak256(
63
+ encodeAbiParameters(
64
+ [
65
+ { type: "string" },
66
+ { type: "uint256" },
67
+ { type: "address" },
68
+ { type: "address" },
69
+ { type: "uint256" }
70
+ ],
71
+ [
72
+ "x402/exact/permit2/v1",
73
+ BigInt(input.chainId),
74
+ PERMIT2_ADDRESS,
75
+ input.owner,
76
+ BigInt(input.nonce)
77
+ ]
78
+ )
79
+ );
80
+ }
81
+ function computeSvmReplayKey(input) {
82
+ const digest = createHash("sha256").update("x402/exact/svm/v1\0").update(input.network).update("\0").update(Buffer.from(input.messageHash, "base64")).digest("hex");
83
+ return `0x${digest}`;
84
+ }
85
+ function computeNearReplayKey(input) {
86
+ const digest = createHash("sha256").update("x402/exact/near/v1\0").update(`${input.network}\0${input.senderId}\0${input.publicKey}\0${input.nonce.toString(10)}`).digest("hex");
87
+ return `0x${digest}`;
88
+ }
89
+
90
+ export { LOCATOR_VERSION, computeNearReplayKey, computePermit2ReplayKey, computeReplayKey, computeSvmReplayKey, eip3009Locator, isoFromSeconds, permit2Locator };
91
+ //# sourceMappingURL=chunk-663ALDZA.js.map
92
+ //# sourceMappingURL=chunk-663ALDZA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/payments/x402/locator.ts","../../src/payments/x402/replay-key.ts"],"names":[],"mappings":";;;;;AAQO,IAAM,eAAA,GAAkB;AAG/B,IAAM,OAAA,GAAU,YAAA;AAChB,IAAM,WAAA,GAAc,MAAA;AAMb,SAAS,eAAe,OAAA,EAAqC;AAClE,EAAA,MAAM,EAAA,GAAK,QAAQ,IAAA,CAAK,OAAO,IAAI,MAAA,CAAO,OAAO,CAAA,GAAI,GAAA,GAAO,MAAA,CAAO,GAAA;AACnE,EAAA,OAAO,MAAM,WAAA,GAAc,IAAI,K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AS,qBAAqB,KAAA,EAK1B;AACT,EAAA,MAAM,MAAA,GAAS,UAAA,CAAW,QAAQ,CAAA,CAC/B,MAAA,CAAO,sBAAsB,CAAA,CAC7B,MAAA,CAAO,CAAA,EAAG,KAAA,CAAM,OAAO,CAAA,EAAA,EAAK,KAAA,CAAM,QAAQ,CAAA,EAAA,EAAK,KAAA,CAAM,SAAS,CAAA,EAAA,EAAK,KAAA,CAAM,KAAA,CAAM,QAAA,CAAS,EAAE,CAAC,CAAA,CAAE,CAAA,CAC7F,MAAA,CAAO,KAAK,CAAA;AACf,EAAA,OAAO,KAAK,MAAM,CAAA,CAAA;AACpB","file":"chunk-663ALDZA.js","sourcesContent":["/**\n * Public payment coordinates returned under `RECONCILIATION_METADATA_KEY`\n * for later reconciliation. Locators contain transfer details and derived\n * metadata, excluding signatures, payloads and transaction bytes. Field names\n * avoid \"token\" because the receipt store redacts values under such keys.\n */\nimport { getAddress } from 'viem';\n\nexport const LOCATOR_VERSION = 1;\n\n// Bound decimal input length to cover Date's range without parsing large integers\nconst SECONDS = /^\\d{1,13}$/;\nconst MAX_DATE_MS = 8.64e15;\n\n/**\n * Converts unsigned decimal Unix seconds to ISO time, or undefined for invalid\n * or out-of-range input\n */\nexport function isoFromSeconds(seconds: string): string | undefined {\n const ms = SECONDS.test(seconds) ? Number(seconds) * 1000 : Number.NaN;\n return ms <= MAX_DATE_MS ? new Date(ms).toISOString() : undefined;\n}\n\nexport interface Eip3009Authorization {\n readonly from: string;\n readonly to: string;\n readonly value: string;\n readonly validAfter: string;\n readonly validBefore: string;\n readonly nonce: string;\n}\n\n/** Builds the shared EIP-3009 locator used by x402 and MPP */\nexport function eip3009Locator(\n network: string,\n asset: string,\n authorization: Eip3009Authorization,\n): Readonly<Record<string, unknown>> {\n const { from, to, value, validAfter, validBefore, nonce } = authorization;\n return withExpiry(\n {\n v: LOCATOR_VERSION,\n network,\n method: 'eip3009',\n asset: getAddress(asset),\n from: getAddress(from),\n to: getAddress(to),\n value,\n nonce: nonce.toLowerCase(),\n validAfter,\n validBefore,\n },\n validBefore,\n );\n}\n\nexport interface Permit2Transfer {\n readonly asset: string;\n readonly owner: string;\n /** Recipient named in the signed witness for the x402 proxy transfer */\n readonly to: string;\n readonly amount: string;\n readonly nonce: string;\n readonly deadline: string;\n readonly validAfter: string;\n readonly proxy: string;\n}\n\n/** A Permit2 transfer's locator */\nexport function permit2Locator(\n network: string,\n transfer: Permit2Transfer,\n): Readonly<Record<string, unknown>> {\n const { asset, owner, to, amount, nonce, deadline, validAfter, proxy } = transfer;\n return withExpiry(\n {\n v: LOCATOR_VERSION,\n network,\n method: 'permit2',\n asset: getAddress(asset),\n owner: getAddress(owner),\n to: getAddress(to),\n amount,\n nonce,\n deadline,\n validAfter,\n proxy: getAddress(proxy),\n },\n deadline,\n );\n}\n\nfunction withExpiry(\n locator: Readonly<Record<string, unknown>>,\n seconds: string,\n): Readonly<Record<string, unknown>> {\n const expiresAt = isoFromSeconds(seconds);\n return expiresAt !== undefined ? { ...locator, expiresAt } : locator;\n}\n","/**\n * `PaymentResult.replayKey` is derived from the payment authorization alone,\n * never from the request id, so the same authorization replayed on another\n * request collides in the receipt store's reservation. The MPP provider uses\n * the EIP-3009 derivation.\n */\nimport { createHash } from 'node:crypto';\nimport { PERMIT2_ADDRESS } from '@x402/evm';\nimport { encodeAbiParameters, keccak256 } from 'viem';\n\nexport interface ReplayKeyInput {\n readonly chainId: number;\n readonly asset: `0x${string}`;\n readonly from: `0x${string}`;\n readonly nonce: `0x${string}`;\n}\n\nexport function computeReplayKey(input: ReplayKeyInput): string {\n const encoded = encodeAbiParameters(\n [{ type: 'uint256' }, { type: 'address' }, { type: 'address' }, { type: 'bytes32' }],\n [BigInt(input.chainId), input.asset, input.from, input.nonce],\n );\n return keccak256(encoded);\n}\n\n/**\n * Identifies a Permit2 authorization by chain, Permit2 contract, owner and\n * nonce. Nonces span all tokens and spenders, so asset and resource are excluded.\n * The tag separates these keys from EIP-3009 in the receipt store's unique column.\n */\nexport function computePermit2ReplayKey(input: {\n readonly chainId: number;\n readonly owner: `0x${string}`;\n readonly nonce: string;\n}): string {\n return keccak256(\n encodeAbiParameters(\n [\n { type: 'string' },\n { type: 'uint256' },\n { type: 'address' },\n { type: 'address' },\n { type: 'uint256' },\n ],\n [\n 'x402/exact/permit2/v1',\n BigInt(input.chainId),\n PERMIT2_ADDRESS,\n input.owner,\n BigInt(input.nonce),\n ],\n ),\n );\n}\n\n/**\n * Identifies a Solana `exact` payment by network and SHA-256 of the signed\n * message bytes. Excludes signatures, including the facilitator's fee payer\n * slot, so altered signatures keep the same key. `messageHash` is the SDK's\n * base64 `transactionMessageHash`.\n */\nexport function computeSvmReplayKey(input: {\n readonly network: string;\n readonly messageHash: string;\n}): string {\n const digest = createHash('sha256')\n .update('x402/exact/svm/v1\\0')\n .update(input.network)\n .update('\\0')\n .update(Buffer.from(input.messageHash, 'base64'))\n .digest('hex');\n return `0x${digest}`;\n}\n\n/**\n * Identifies a NEAR `exact` payment by network, sender, curve-prefixed public\n * key (`ed25519:...`) and delegate nonce. Nonces are scoped per access key,\n * excluding token, recipient, relayer and signature; another key of the same\n * sender has an independent nonce scope.\n */\nexport function computeNearReplayKey(input: {\n readonly network: string;\n readonly senderId: string;\n readonly publicKey: string;\n readonly nonce: bigint;\n}): string {\n const digest = createHash('sha256')\n .update('x402/exact/near/v1\\0')\n .update(`${input.network}\\0${input.senderId}\\0${input.publicKey}\\0${input.nonce.toString(10)}`)\n .digest('hex');\n return `0x${digest}`;\n}\n"]}
@@ -0,0 +1,18 @@
1
+ // src/core/store-method-groups.ts
2
+ var STORE_METHOD_GROUPS = {
3
+ idempotency_claims: ["claimIdempotencyKey", "updateIdempotencyKey", "recoverIdempotencyKeys"],
4
+ authorization_holds: [
5
+ "reserveAuthorizationHold",
6
+ "transitionAuthorizationHold",
7
+ "getAuthorizationHoldState",
8
+ "listOrphanAuthorizationHolds"
9
+ ],
10
+ pending_tasks: ["putPendingTask", "getPendingTask", "takePendingTask"]
11
+ };
12
+ function hasMethodGroup(store, group) {
13
+ return store !== void 0 && STORE_METHOD_GROUPS[group].every((method) => typeof store[method] === "function");
14
+ }
15
+
16
+ export { hasMethodGroup };
17
+ //# sourceMappingURL=chunk-6R6WJ4FD.js.map
18
+ //# sourceMappingURL=chunk-6R6WJ4FD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/store-method-groups.ts"],"names":[],"mappings":";AAKO,IAAM,mBAAA,GAAsB;AAAA,EACjC,kBAAA,EAAoB,CAAC,qBAAA,EAAuB,sBAAA,EAAwB,wBAAwB,CAAA;AAAA,EAC5F,mBAAA,EAAqB;AAAA,IACnB,0BAAA;AAAA,IACA,6BAAA;AAAA,IACA,2BAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA,aAAA,EAAe,CAAC,gBAAA,EAAkB,gBAAA,EAAkB,iBAAiB;AACvE,CAAA;AASO,SAAS,cAAA,CACd,OACA,KAAA,EAC8C;AAC9C,EAAA,OACE,KAAA,KAAU,MAAA,IACV,mBAAA,CAAoB,KAAK,CAAA,CAAE,KAAA,CAAM,CAAC,MAAA,KAAW,OAAO,KAAA,CAAM,MAAM,CAAA,KAAM,UAAU,CAAA;AAEpF","file":"chunk-6R6WJ4FD.js","sourcesContent":["// Optional ReceiptStore method groups. Adapters use a store for a group only\n// when all its methods are present; conformance checks that each group is\n// implemented in full or omitted.\nimport type { ReceiptStore } from './interfaces/store';\n\nexport const STORE_METHOD_GROUPS = {\n idempotency_claims: ['claimIdempotencyKey', 'updateIdempotencyKey', 'recoverIdempotencyKeys'],\n authorization_holds: [\n 'reserveAuthorizationHold',\n 'transitionAuthorizationHold',\n 'getAuthorizationHoldState',\n 'listOrphanAuthorizationHolds',\n ],\n pending_tasks: ['putPendingTask', 'getPendingTask', 'takePendingTask'],\n} as const satisfies Record<string, readonly (keyof ReceiptStore)[]>;\n\nexport type StoreMethodGroup = keyof typeof STORE_METHOD_GROUPS;\n\n/** The required store methods for one group */\nexport type StoreGroupMethods<G extends StoreMethodGroup> = Required<\n Pick<ReceiptStore, (typeof STORE_METHOD_GROUPS)[G][number]>\n>;\n\nexport function hasMethodGroup<G extends StoreMethodGroup>(\n store: ReceiptStore | undefined,\n group: G,\n): store is ReceiptStore & StoreGroupMethods<G> {\n return (\n store !== undefined &&\n STORE_METHOD_GROUPS[group].every((method) => typeof store[method] === 'function')\n );\n}\n"]}
@@ -1,13 +1,15 @@
1
- import { ACP_WELL_KNOWN_PATH, DEFAULT_CONFIG_FILENAME, ACP_CHECKOUT_OPERATIONS, isObjectSchemaNode, extractPathParameterNames, findUnparsedBraceToken, ACP_OPERATION_INPUT_KEYS, ACP_OPERATION_OPTIONAL_INPUT_KEYS, ACP_SESSION_ID_INPUT_KEY } from './chunk-PIMFPCNZ.js';
2
- import { MPP_DEFAULT_NETWORK, isMppNetwork, MPP_NETWORKS, MPP_DEFAULT_PAYMENT_FLOW, MPP_MIN_CHALLENGE_SECRET_LENGTH, MPP_PROFILE } from './chunk-AA3FIEAR.js';
3
- import { resolveX402Deployment, resolveX402Option } from './chunk-WYOGIANL.js';
4
- import { X402_PAYMENT_FLOWS, validateCustomNetworks, findX402Network, X402_DEFAULT_PAYMENT_FLOW, isEvmAddress, isEvmZeroAddress } from './chunk-OZ4LAWBK.js';
1
+ import { ACP_WELL_KNOWN_PATH, DEFAULT_CONFIG_FILENAME, ACP_CHECKOUT_OPERATIONS, isObjectSchemaNode, extractPathParameterNames, findUnparsedBraceToken, ACP_OPERATION_INPUT_KEYS, ACP_OPERATION_OPTIONAL_INPUT_KEYS, ACP_SESSION_ID_INPUT_KEY } from './chunk-PTL7SNOI.js';
5
2
  import { AP2_SPEC_VERSION, AP2_MODES, AP2_DEFAULT_CLOCK_SKEW_SECONDS, AP2_JWK_MEMBERS, AP2_KEY_TYPE, AP2_SIGNING_ALGORITHM, AP2_JWK_CURVE, AP2_JWK_COORDINATE_BYTES, AP2_MAX_CLOCK_SKEW_SECONDS } from './chunk-FHCFR2GS.js';
6
3
  import { MCP_TOOL_NAME_PATTERN } from './chunk-TPC4EJLT.js';
7
- import { PROTOCOL_NAMES, PAYMENT_METHOD_NAMES, CommerceError, RESERVED_INPUT_FIELDS } from './chunk-QQ3WY5L3.js';
4
+ import { MPP_DEFAULT_NETWORK, isMppNetwork, MPP_NETWORKS, MPP_DEFAULT_PAYMENT_FLOW, MPP_MIN_CHALLENGE_SECRET_LENGTH, MPP_PROFILE } from './chunk-AA3FIEAR.js';
5
+ import { resolveX402Deployment, resolveX402Option } from './chunk-YWG2ZN3L.js';
6
+ import { X402_PAYMENT_FLOWS, validateCustomNetworks, findX402Network, X402_DEFAULT_PAYMENT_FLOW, isEvmAddress, isEvmZeroAddress } from './chunk-3NOMLMJW.js';
7
+ import { PROTOCOL_NAMES, PAYMENT_METHOD_NAMES, RESERVED_INPUT_FIELDS } from './chunk-GET3CZGR.js';
8
+ import { CommerceError } from './chunk-SYQLJXIU.js';
8
9
  import { isRecord } from './chunk-3M6U7ILB.js';
9
10
  import { promises } from 'fs';
10
11
  import * as path from 'path';
12
+ import { resolve } from 'path';
11
13
  import { parse, YAMLError } from 'yaml';
12
14
  import { z } from 'zod';
13
15
 
@@ -160,10 +162,10 @@ function normalizeAcp(raw) {
160
162
  'protocols.acp.auth is required when ACP is enabled - every ACP checkout endpoint is authenticated, and "bearer" is the only scheme supported in this release'
161
163
  );
162
164
  }
163
- if (raw.idempotency === void 0) {
164
- throw acpInvalid(
165
- "protocols.acp.idempotency",
166
- "protocols.acp.idempotency is required when ACP is enabled - it names the SQLite file holding checkout idempotency records, and ACP makes the Idempotency-Key mandatory on every checkout POST"
165
+ const idempotency = raw.idempotency ?? {};
166
+ if (idempotency.path !== void 0) {
167
+ console.warn(
168
+ "[agent-commerce] protocols.acp.idempotency.path is deprecated: the receipt database holds ACP idempotency claims. The first start imports this file and keeps it locked while the gateway runs. Remove the key once no 2.5.x gateway uses the file; 3.0.0 stops reading it."
167
169
  );
168
170
  }
169
171
  const discovery = raw.discovery;
@@ -172,13 +174,13 @@ function normalizeAcp(raw) {
172
174
  mountPath,
173
175
  auth: raw.auth,
174
176
  idempotency: {
175
- path: raw.idempotency.path,
177
+ ...idempotency.path !== void 0 ? { path: idempotency.path } : {},
176
178
  retentionHours: toNumber(
177
- raw.idempotency.retentionHours ?? ACP_RETENTION_HOURS,
179
+ idempotency.retentionHours ?? ACP_RETENTION_HOURS,
178
180
  "protocols.acp.idempotency.retentionHours",
179
181
  { min: ACP_RETENTION_HOURS }
180
182
  ),
181
- merchantIdempotent: raw.idempotency.merchantIdempotent ?? false
183
+ merchantIdempotent: idempotency.merchantIdempotent ?? false
182
184
  },
183
185
  checkout: { operations: normalizeAcpOperations(raw.checkout) },
184
186
  // Built key by key so absent metadata stays absent rather than `undefined`
@@ -309,8 +311,6 @@ function closedObjectProperties(schema) {
309
311
  if (!isRecord(schema) || schema["additionalProperties"] !== false) return void 0;
310
312
  return isRecord(schema["properties"]) ? schema["properties"] : {};
311
313
  }
312
-
313
- // src/config/schema/ap2.ts
314
314
  var SUPPORTED_AUTHORIZATION_METHODS = /* @__PURE__ */ new Set(["ap2"]);
315
315
  function ap2Invalid(path2, message, extra = {}) {
316
316
  return new CommerceError("CONFIG_INVALID", message, { details: { path: path2, ...extra } });
@@ -332,10 +332,9 @@ function normalizeAp2(raw) {
332
332
  `authorization.ap2.mode "${mode}" is not supported. Supported: ${AP2_MODES.join(", ")}. Autonomous mode needs open mandates, agent key binding and constraint evaluation, none of which this release implements.`
333
333
  );
334
334
  }
335
- if (raw.replay === void 0) {
336
- throw ap2Invalid(
337
- "authorization.ap2.replay",
338
- "authorization.ap2.replay is required when AP2 is enabled - it names the SQLite file recording which mandates have been spent, and without it a verified mandate could authorize a second settlement"
335
+ if (raw.replay !== void 0) {
336
+ console.warn(
337
+ "[agent-commerce] authorization.ap2.replay.path is deprecated: the receipt database holds AP2 mandate holds. The first start imports this file and keeps it locked while the gateway runs. Remove the key once no 2.5.x gateway uses the file; 3.0.0 stops reading it."
339
338
  );
340
339
  }
341
340
  const mandateIssuers = normalizeIssuers(
@@ -364,7 +363,7 @@ function normalizeAp2(raw) {
364
363
  raw.requireMandateExpiry ?? false,
365
364
  "authorization.ap2.requireMandateExpiry"
366
365
  ),
367
- replay: { path: raw.replay.path }
366
+ ...raw.replay !== void 0 ? { replay: { path: raw.replay.path } } : {}
368
367
  };
369
368
  }
370
369
  function normalizeIssuers(raw, path2) {
@@ -459,16 +458,25 @@ function validateJwk(jwk, kid, path2) {
459
458
  }
460
459
  return normalized;
461
460
  }
462
- function validateReplayStoreIsolated(replayPath, receiptsPath, acp) {
463
- if (replayPath === ":memory:") return;
461
+ function validateLegacyStoresIsolated(ap2, acp, receiptsPath) {
462
+ const files = [
463
+ ["authorization.ap2.replay.path", ap2?.enabled ? ap2.replay?.path : void 0],
464
+ ["protocols.acp.idempotency.path", acp.enabled ? acp.idempotency.path : void 0]
465
+ ];
464
466
  const others = [["storage.receipts.path", receiptsPath]];
465
- if (acp.enabled) others.push(["protocols.acp.idempotency.path", acp.idempotency.path]);
466
- for (const [otherPath, other] of others) {
467
- if (replayPath !== other) continue;
468
- throw ap2Invalid(
469
- "authorization.ap2.replay.path",
470
- `authorization.ap2.replay.path is the same file as ${otherPath} ("${replayPath}") - the AP2 replay store keeps its own schema and must not share a database with another store`
467
+ for (const [key, path2] of files) {
468
+ if (path2 === void 0 || path2 === ":memory:") continue;
469
+ const clash = others.find(
470
+ ([, other]) => other !== ":memory:" && resolve(other) === resolve(path2)
471
471
  );
472
+ if (clash !== void 0) {
473
+ throw new CommerceError(
474
+ "CONFIG_INVALID",
475
+ `${key} is the same file as ${clash[0]} ("${resolve(path2)}") - a deprecated store file is imported into the receipt database and then locked, so it must be a separate file`,
476
+ { details: { path: key } }
477
+ );
478
+ }
479
+ others.push([key, path2]);
472
480
  }
473
481
  }
474
482
  function normalizeResourceAuthorization(id, entry, pricing, ap2) {
@@ -844,7 +852,7 @@ var MountPathSchema = z.string().min(1).refine((value) => value.startsWith("/"),
844
852
  );
845
853
  var AcpAuthSchema = z.object({ type: z.literal("bearer"), token: z.string().min(1) }).strict();
846
854
  var AcpIdempotencySchema = z.object({
847
- path: z.string().min(1),
855
+ path: z.string().min(1).optional(),
848
856
  retentionHours: NumberOrString.optional(),
849
857
  merchantIdempotent: z.boolean().optional()
850
858
  }).strict();
@@ -1561,9 +1569,7 @@ function normalize(raw) {
1561
1569
  const x402 = x402Settings?.config;
1562
1570
  const mpp = normalizeMpp(raw.payments.mpp);
1563
1571
  const ap2 = normalizeAp2(raw.authorization?.ap2);
1564
- if (ap2?.enabled) {
1565
- validateReplayStoreIsolated(ap2.replay.path, raw.storage.receipts.path, protocols.acp);
1566
- }
1572
+ validateLegacyStoresIsolated(ap2, protocols.acp, raw.storage.receipts.path);
1567
1573
  const resources = Object.entries(raw.resources).map(
1568
1574
  ([id, entry]) => normalizeResource(id, entry, protocols, x402Settings, mpp, ap2)
1569
1575
  );
@@ -1757,5 +1763,5 @@ function resolveConfigPath(explicitPath, env, cwd) {
1757
1763
  }
1758
1764
 
1759
1765
  export { loadConfig, parseConfig, substituteEnv };
1760
- //# sourceMappingURL=chunk-G2JEY7MB.js.map
1761
- //# sourceMappingURL=chunk-G2JEY7MB.js.map
1766
+ //# sourceMappingURL=chunk-AZL7RPFU.js.map
1767
+ //# sourceMappingURL=chunk-AZL7RPFU.js.map