@devlab.group/agent-commerce 2.7.0 → 2.7.2
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 +1 -0
- package/dist/ap2.js +1 -1
- package/dist/chunk-2573DASO.js +8 -0
- package/dist/{chunk-O3ACF45K.js.map → chunk-2573DASO.js.map} +1 -1
- package/dist/{chunk-EMKITGVV.js → chunk-5AO5N2XY.js} +9 -3
- package/dist/chunk-5AO5N2XY.js.map +1 -0
- package/dist/{chunk-ZSIUZPNB.js → chunk-XXHC6AA3.js} +30 -18
- package/dist/chunk-XXHC6AA3.js.map +1 -0
- package/dist/cli/{ap2-5FFGSW6F.js → ap2-O3HJSS2E.js} +3 -3
- package/dist/cli/{ap2-5FFGSW6F.js.map → ap2-O3HJSS2E.js.map} +1 -1
- package/dist/cli/chunk-B4QJV7OC.js +8 -0
- package/dist/cli/{chunk-ZCW56PZ3.js.map → chunk-B4QJV7OC.js.map} +1 -1
- package/dist/cli/{chunk-AGQ4U7IN.js → chunk-FETTSOMT.js} +9 -3
- package/dist/cli/chunk-FETTSOMT.js.map +1 -0
- package/dist/cli/{chunk-ZFVQWOGG.js → chunk-GBBG66O6.js} +18 -5
- package/dist/cli/chunk-GBBG66O6.js.map +1 -0
- package/dist/cli/{chunk-5K2JDM4G.js → chunk-QUFFT5K3.js} +30 -18
- package/dist/cli/chunk-QUFFT5K3.js.map +1 -0
- package/dist/cli/{chunk-PLHPKXAT.js → chunk-S5TQXKQ7.js} +5 -5
- package/dist/cli/{chunk-PLHPKXAT.js.map → chunk-S5TQXKQ7.js.map} +1 -1
- package/dist/cli/{chunk-5TID36YG.js → chunk-XRG5UTIC.js} +3 -3
- package/dist/cli/{chunk-5TID36YG.js.map → chunk-XRG5UTIC.js.map} +1 -1
- package/dist/cli/{config-WT5HHDRR.js → config-ODN4IEMZ.js} +4 -4
- package/dist/cli/{config-WT5HHDRR.js.map → config-ODN4IEMZ.js.map} +1 -1
- package/dist/cli/index.js +22 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-HHGNOUKE.js → mcp-G2D2Z77G.js} +3 -3
- package/dist/cli/{mcp-HHGNOUKE.js.map → mcp-G2D2Z77G.js.map} +1 -1
- package/dist/cli/payment-providers-7RIIZ5OF.js +6 -0
- package/dist/cli/{payment-providers-EWXZFBIE.js.map → payment-providers-7RIIZ5OF.js.map} +1 -1
- package/dist/cli/{provider-XUPLYNQ7.js → provider-ARV3VAQ7.js} +5 -5
- package/dist/cli/{provider-XUPLYNQ7.js.map → provider-ARV3VAQ7.js.map} +1 -1
- package/dist/cli/{receipts-3DSV4DIK.js → receipts-HLQ7D722.js} +4 -4
- package/dist/cli/{receipts-3DSV4DIK.js.map → receipts-HLQ7D722.js.map} +1 -1
- package/dist/cli/{run-7KLKW3HE.js → run-BHODKC6H.js} +49 -23
- package/dist/cli/run-BHODKC6H.js.map +1 -0
- package/dist/cli/{svm-KDSPDFJG.js → svm-NBZY7H6W.js} +9 -6
- package/dist/cli/svm-NBZY7H6W.js.map +1 -0
- package/dist/cli/{x402-HP4E3QET.js → x402-LHW2YQ6W.js} +6 -6
- package/dist/cli/{x402-HP4E3QET.js.map → x402-LHW2YQ6W.js.map} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +57 -18
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +1 -1
- package/dist/mpp.js +3 -3
- package/dist/{store-BVvMzpuV.d.ts → store-DQwbKhnc.d.ts} +1 -1
- package/dist/{svm-KNC3PHMS.js → svm-4HR5OEP7.js} +9 -6
- package/dist/svm-4HR5OEP7.js.map +1 -0
- package/dist/x402.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-EMKITGVV.js.map +0 -1
- package/dist/chunk-O3ACF45K.js +0 -8
- package/dist/chunk-ZSIUZPNB.js.map +0 -1
- package/dist/cli/chunk-5K2JDM4G.js.map +0 -1
- package/dist/cli/chunk-AGQ4U7IN.js.map +0 -1
- package/dist/cli/chunk-ZCW56PZ3.js +0 -8
- package/dist/cli/chunk-ZFVQWOGG.js.map +0 -1
- package/dist/cli/payment-providers-EWXZFBIE.js +0 -6
- package/dist/cli/run-7KLKW3HE.js.map +0 -1
- package/dist/cli/svm-KDSPDFJG.js.map +0 -1
- package/dist/svm-KNC3PHMS.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LOCATOR_VERSION, computeSvmReplayKey } from './chunk-663ALDZA.js';
|
|
2
2
|
import { isRecord } from './chunk-3M6U7ILB.js';
|
|
3
|
-
import { getAddressEncoder, getProgramDerivedAddress, address, getCompiledTransactionMessageDecoder } from '@solana/kit';
|
|
4
|
-
import {
|
|
3
|
+
import { getAddressEncoder, getProgramDerivedAddress, address, getCompiledTransactionMessageDecoder, getTransactionDecoder, getBase64Encoder } from '@solana/kit';
|
|
4
|
+
import { transactionMessageHash } from '@x402/svm';
|
|
5
5
|
|
|
6
6
|
var MAX_TRANSACTION_BASE64 = 1644;
|
|
7
7
|
var ASSOCIATED_TOKEN_PROGRAM = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
@@ -22,7 +22,7 @@ function inspectSvmPayload(payload, network) {
|
|
|
22
22
|
let messageHash;
|
|
23
23
|
let recentBlockhash;
|
|
24
24
|
try {
|
|
25
|
-
const decoded =
|
|
25
|
+
const decoded = decodeTransaction(transaction);
|
|
26
26
|
messageHash = transactionMessageHash(decoded);
|
|
27
27
|
recentBlockhash = getCompiledTransactionMessageDecoder().decode(
|
|
28
28
|
decoded.messageBytes
|
|
@@ -37,12 +37,15 @@ function inspectSvmPayload(payload, network) {
|
|
|
37
37
|
}
|
|
38
38
|
function messageHashOf(transaction) {
|
|
39
39
|
try {
|
|
40
|
-
return transactionMessageHash(
|
|
40
|
+
return transactionMessageHash(decodeTransaction(transaction));
|
|
41
41
|
} catch {
|
|
42
42
|
return void 0;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
function decodeTransaction(base64) {
|
|
46
|
+
return getTransactionDecoder().decode(getBase64Encoder().encode(base64));
|
|
47
|
+
}
|
|
45
48
|
|
|
46
49
|
export { associatedTokenAccount, inspectSvmPayload, messageHashOf };
|
|
47
|
-
//# sourceMappingURL=svm-
|
|
48
|
-
//# sourceMappingURL=svm-
|
|
50
|
+
//# sourceMappingURL=svm-NBZY7H6W.js.map
|
|
51
|
+
//# sourceMappingURL=svm-NBZY7H6W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/payments/x402/svm.ts"],"names":[],"mappings":";;;;;AAyBA,IAAM,sBAAA,GAAyB,IAAA;AAE/B,IAAM,wBAAA,GAA2B,8CAAA;AAMjC,eAAsB,sBAAA,CACpB,KAAA,EACA,IAAA,EACA,YAAA,EACiB;AACjB,EAAA,MAAM,UAAU,iBAAA,EAAkB;AAClC,EAAA,MAAM,CAAC,OAAO,CAAA,GAAI,MAAM,wBAAA,CAAyB;AAAA,IAC/C,cAAA,EAAgB,QAAQ,wBAAwB,CAAA;AAAA,IAChD,KAAA,EAAO,CAAC,KAAA,EAAO,YAAA,EAAc,IAAI,CAAA,CAAE,GAAA,CAAI,CAAC,GAAA,KAAQ,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,GAAG,CAAC,CAAC;AAAA,GAC7E,CAAA;AACD,EAAA,OAAO,OAAA;AACT;AAOO,SAAS,iBAAA,CACd,SACA,OAAA,EAC8F;AAC9F,EAAA,IAAI,CAAC,QAAA,CAAS,OAAO,CAAA,EAAG,OAAO,uCAAA;AAC/B,EAAA,MAAM,WAAA,GAAc,QAAQ,aAAa,CAAA;AACzC,EAAA,IAAI,OAAO,WAAA,KAAgB,QAAA,IAAY,WAAA,CAAY,SAAS,sBAAA,EAAwB;AAClF,IAAA,OAAO,uCAAA;AAAA,EACT;AACA,EAAA,IAAI,WAAA;AACJ,EAAA,IAAI,eAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,GAAU,kBAAkB,WAAW,CAAA;AAC7C,IAAA,WAAA,GAAc,uBAAuB,OAAO,CAAA;AAC5C,IAAA,eAAA,GAAkB,sCAAqC,CAAE,MAAA;AAAA,MACvD,OAAA,CAAQ;AAAA,KACV,CAAE,aAAA;AAAA,EACJ,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,4DAAA;AAAA,EACT;AACA,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,mBAAA,CAAoB,EAAE,OAAA,EAAS,aAAa,CAAA;AAAA,IACvD,SAAS,EAAE,CAAA,EAAG,eAAA,EAAiB,OAAA,EAAS,aAAa,eAAA;AAAgB,GACvE;AACF;AAMO,SAAS,cAAc,WAAA,EAAyC;AACrE,EAAA,IAAI;AACF,IAAA,OAAO,sBAAA,CAAuB,iBAAA,CAAkB,WAAW,CAAC,CAAA;AAAA,EAC9D,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAIA,SAAS,kBAAkB,MAAA,EAA6B;AACtD,EAAA,OAAO,uBAAsB,CAAE,MAAA,CAAO,kBAAiB,CAAE,MAAA,CAAO,MAAM,CAAC,CAAA;AACzE","file":"svm-NBZY7H6W.js","sourcesContent":["/**\n * Solana `exact` payload inspection with bounded decoding, replay identity and\n * reconciliation coordinates. The provider loads this module, including its\n * `@x402/svm` and `@solana/kit` imports, when a Solana offer is configured.\n *\n * The facilitator checks the transaction itself: the fee payer, signatures,\n * instruction layout, mint, recipient token account and amount, and a\n * simulation. Its smart-wallet path accepts layouts the gateway could not\n * parse, so the gateway does not read the transfer.\n */\nimport {\n address,\n getAddressEncoder,\n getBase64Encoder,\n getCompiledTransactionMessageDecoder,\n getProgramDerivedAddress,\n getTransactionDecoder,\n type Transaction,\n} from '@solana/kit';\nimport { transactionMessageHash } from '@x402/svm';\nimport { isRecord } from '../../core/is-record';\nimport { LOCATOR_VERSION } from './locator';\nimport { computeSvmReplayKey } from './replay-key';\n\n// A Solana transaction fits a 1232-byte packet, which is 1644 base64 characters\nconst MAX_TRANSACTION_BASE64 = 1644;\n\nconst ASSOCIATED_TOKEN_PROGRAM = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';\n\n/**\n * The associated token account of `owner` for `mint`, where the SDK client\n * sends a Solana `exact` payment. Its transaction cannot create the account.\n */\nexport async function associatedTokenAccount(\n owner: string,\n mint: string,\n tokenProgram: string,\n): Promise<string> {\n const encoder = getAddressEncoder();\n const [account] = await getProgramDerivedAddress({\n programAddress: address(ASSOCIATED_TOKEN_PROGRAM),\n seeds: [owner, tokenProgram, mint].map((key) => encoder.encode(address(key))),\n });\n return account;\n}\n\n/**\n * Returns the Solana `exact` replay key and locator, or an SDK refusal reason\n * for a missing, oversized or undecodable transaction. The provider adds the\n * payer from the facilitator's verdict when a usable address is available.\n */\nexport function inspectSvmPayload(\n payload: unknown,\n network: string,\n): { readonly replayKey: string; readonly locator: Readonly<Record<string, unknown>> } | string {\n if (!isRecord(payload)) return 'invalid_exact_svm_payload_transaction';\n const transaction = payload['transaction'];\n if (typeof transaction !== 'string' || transaction.length > MAX_TRANSACTION_BASE64) {\n return 'invalid_exact_svm_payload_transaction';\n }\n let messageHash: string;\n let recentBlockhash: string;\n try {\n const decoded = decodeTransaction(transaction);\n messageHash = transactionMessageHash(decoded);\n recentBlockhash = getCompiledTransactionMessageDecoder().decode(\n decoded.messageBytes,\n ).lifetimeToken;\n } catch {\n return 'invalid_exact_svm_payload_transaction_could_not_be_decoded';\n }\n return {\n replayKey: computeSvmReplayKey({ network, messageHash }),\n locator: { v: LOCATOR_VERSION, network, messageHash, recentBlockhash },\n };\n}\n\n/**\n * Returns the message hash of base64 transaction bytes using the same decoder\n * as payment inspection, or undefined if decoding or hashing fails\n */\nexport function messageHashOf(transaction: string): string | undefined {\n try {\n return transactionMessageHash(decodeTransaction(transaction));\n } catch {\n return undefined;\n }\n}\n\n// Match decodeTransactionFromPayload without its failure logging, which exposes\n// caller input and a stack trace through console.error\nfunction decodeTransaction(base64: string): Transaction {\n return getTransactionDecoder().decode(getBase64Encoder().encode(base64));\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { chainIdFromCaip2 } from './chunk-
|
|
2
|
-
export { createX402PaymentProvider } from './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
import { chainIdFromCaip2 } from './chunk-QUFFT5K3.js';
|
|
2
|
+
export { createX402PaymentProvider } from './chunk-QUFFT5K3.js';
|
|
3
|
+
import './chunk-FETTSOMT.js';
|
|
4
4
|
export { SUPPORTED_NETWORK_IDS } from './chunk-66NTYSXI.js';
|
|
5
|
-
import './chunk-
|
|
5
|
+
import './chunk-B4QJV7OC.js';
|
|
6
6
|
import './chunk-55AI6CLW.js';
|
|
7
7
|
import { CommerceError } from './chunk-C5YISPT6.js';
|
|
8
8
|
import './chunk-663ALDZA.js';
|
|
@@ -94,5 +94,5 @@ function randomNonce() {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export { createPaymentProof };
|
|
97
|
-
//# sourceMappingURL=x402-
|
|
98
|
-
//# sourceMappingURL=x402-
|
|
97
|
+
//# sourceMappingURL=x402-LHW2YQ6W.js.map
|
|
98
|
+
//# sourceMappingURL=x402-LHW2YQ6W.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/payments/x402/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAuCA,IAAM,YAAA,GAAe,CAAA;AAErB,IAAM,iCAAA,GAAoC;AAAA,EACxC,yBAAA,EAA2B;AAAA,IACzB,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,IAChC,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,SAAA,EAAU;AAAA,IAC9B,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,SAAA,EAAU;AAAA,IACtC,EAAE,IAAA,EAAM,aAA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AAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,EAAE,CAAA;AAC/B,EAAA,MAAA,CAAO,gBAAgB,KAAK,CAAA;AAC5B,EAAA,OAAO,MAAM,KAAK,CAAA;AACpB","file":"x402-LHW2YQ6W.js","sourcesContent":["/**\n * Client-side payment helper: builds and EIP-712-signs an x402 v2 `exact`/EVM\n * authorization on the buyer's side. The demo buyer agent and the test suites\n * use it, and the `/x402` entry exports it. The gateway never calls it and\n * never holds a buyer key.\n *\n * It signs directly rather than through the SDK's `x402Client` because of\n * `overrides`: negative tests need deliberately wrong authorizations that a\n * conforming client will not produce. The x402 settlement E2E suite also\n * settles a payment built by `x402Client` itself to cover interoperability.\n */\n\nimport { PaymentRequirementsV2Schema } from '@x402/core/schemas';\nimport type { PaymentPayload, PaymentRequirements } from '@x402/core/types';\nimport { getAddress, toHex } from 'viem';\nimport { privateKeyToAccount } from 'viem/accounts';\nimport { CommerceError } from '../../core';\nimport { chainIdFromCaip2 } from './chain';\n\nexport interface CreatePaymentProofOptions {\n /** The buyer's private key. It signs locally and is never sent anywhere */\n readonly buyerPrivateKey: `0x${string}`;\n /** One entry from PaymentRequiredEnvelope.payment.accepts, verbatim */\n readonly accepts: Readonly<Record<string, unknown>>;\n /**\n * `PaymentPayload.extensions`, sent outside the signature. Echo the challenge's\n * declarations; for `payment-identifier`, add the buyer's `id` to `info`.\n */\n readonly extensions?: Readonly<Record<string, unknown>>;\n /** For negative tests only: a wrong amount, recipient, nonce or validity window */\n readonly overrides?: {\n readonly value?: string;\n readonly payTo?: string;\n readonly nonce?: `0x${string}`;\n readonly validBefore?: number;\n readonly validAfter?: number;\n };\n}\n\nconst X402_VERSION = 2;\n\nconst TRANSFER_WITH_AUTHORIZATION_TYPES = {\n TransferWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const;\n\n/** Returns the base64 `PAYMENT-SIGNATURE` value to send back to the gateway */\nexport async function createPaymentProof(options: CreatePaymentProofOptions): Promise<string> {\n const requirements = PaymentRequirementsV2Schema.parse(options.accepts);\n const method = requirements.extra?.['assetTransferMethod'];\n if (method !== undefined && method !== 'eip3009') {\n throw new CommerceError(\n 'INPUT_INVALID',\n `createPaymentProof: signs EIP-3009 only, and this offer uses \"${String(method)}\"; sign it with the SDK's x402Client`,\n );\n }\n if (\n !requirements.extra ||\n typeof requirements.extra['name'] !== 'string' ||\n typeof requirements.extra['version'] !== 'string'\n ) {\n throw new CommerceError(\n 'INPUT_INVALID',\n 'createPaymentProof: payment requirement is missing extra.name/extra.version, so the EIP-712 domain cannot be built',\n );\n }\n\n const chainId = chainIdFromCaip2(requirements.network);\n if (chainId === undefined) {\n throw new CommerceError(\n 'INPUT_INVALID',\n `createPaymentProof: network \"${requirements.network}\" is not a CAIP-2 eip155 identifier, so there is no chain id to sign against`,\n );\n }\n\n const account = privateKeyToAccount(options.buyerPrivateKey);\n\n const nonce = options.overrides?.nonce ?? randomNonce();\n const nowSeconds = Math.floor(Date.now() / 1000);\n // 0, as in the SDK's own v2 client: nothing here wants the authorization\n // delayed\n const validAfter = options.overrides?.validAfter ?? 0;\n const validBefore = options.overrides?.validBefore ?? nowSeconds + requirements.maxTimeoutSeconds;\n const to = getAddress((options.overrides?.payTo ?? requirements.payTo) as `0x${string}`);\n const value = BigInt(options.overrides?.value ?? requirements.amount);\n\n const signature = await account.signTypedData({\n domain: {\n name: requirements.extra['name'],\n version: requirements.extra['version'],\n chainId,\n verifyingContract: getAddress(requirements.asset as `0x${string}`),\n },\n types: TRANSFER_WITH_AUTHORIZATION_TYPES,\n primaryType: 'TransferWithAuthorization',\n message: {\n from: account.address,\n to,\n value,\n validAfter: BigInt(validAfter),\n validBefore: BigInt(validBefore),\n nonce,\n },\n });\n\n // v2 echoes the chosen requirement back as `accepted` so a stateless\n // facilitator knows which offer was taken. The gateway verifies against its\n // own copy.\n const payload: PaymentPayload = {\n x402Version: X402_VERSION,\n accepted: requirements as PaymentRequirements,\n payload: {\n signature,\n authorization: {\n from: account.address,\n to,\n value: value.toString(),\n validAfter: validAfter.toString(),\n validBefore: validBefore.toString(),\n nonce,\n },\n },\n ...(options.extensions !== undefined ? { extensions: { ...options.extensions } } : {}),\n };\n\n return Buffer.from(JSON.stringify(payload), 'utf8').toString('base64');\n}\n\nfunction randomNonce(): `0x${string}` {\n const bytes = new Uint8Array(32);\n crypto.getRandomValues(bytes);\n return toHex(bytes);\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ import { C as CustomNetworks } from './networks-DDHYJLcg.js';
|
|
|
7
7
|
export { A as AuthorizationHoldState, C as COMMERCE_EVENT_TYPES, a as CommerceEvent, b as CommerceEventType, E as EventSink, P as PersistenceFailure, T as TRANSACTION_STATES, c as Transaction, d as TransactionFacts, e as TransactionState, t as transactionState } from './transaction-BXXJltZ-.js';
|
|
8
8
|
import { D as DeliveredOutcome, P as PaymentRequiredOutcome, E as ExecutionPipeline, a as ProtocolAdapter, H as HttpProtocolAdapter, A as AdapterHttpRoute, b as ProtocolAdapterContext } from './protocol-adapter-DdFL5LBU.js';
|
|
9
9
|
export { C as CanonicalRequest, c as ExecutionOutcome, i as isHttpProtocolAdapter } from './protocol-adapter-DdFL5LBU.js';
|
|
10
|
-
import { R as ReceiptStore } from './store-
|
|
11
|
-
export { A as AuthorizationHold, a as AuthorizationHoldReservation, b as AuthorizationHoldResult, I as IdempotencyClaim, c as IdempotencyScope, d as IdempotencyUpdate, L as ListOptions, N as NewTransaction, P as PaymentAttemptListOptions, e as PaymentAttemptReservation, f as PaymentAttemptResolveRequest, g as PaymentAttemptUpdate, h as PendingTask, i as ReceiptListOptions, T as TransactionListOptions, j as TransactionPage, k as TransactionStep } from './store-
|
|
10
|
+
import { R as ReceiptStore } from './store-DQwbKhnc.js';
|
|
11
|
+
export { A as AuthorizationHold, a as AuthorizationHoldReservation, b as AuthorizationHoldResult, I as IdempotencyClaim, c as IdempotencyScope, d as IdempotencyUpdate, L as ListOptions, N as NewTransaction, P as PaymentAttemptListOptions, e as PaymentAttemptReservation, f as PaymentAttemptResolveRequest, g as PaymentAttemptUpdate, h as PendingTask, i as ReceiptListOptions, T as TransactionListOptions, j as TransactionPage, k as TransactionStep } from './store-DQwbKhnc.js';
|
|
12
12
|
import { L as Logger } from './logger-CllGwQ8i.js';
|
|
13
13
|
export { N as NOOP_LOGGER } from './logger-CllGwQ8i.js';
|
|
14
14
|
import { FastifyInstance } from 'fastify';
|
|
@@ -740,7 +740,7 @@ interface SqliteReceiptStoreSummary {
|
|
|
740
740
|
readonly orphanHolds: number;
|
|
741
741
|
/** Unresolved claims whose endpoints do not start with `payment:` */
|
|
742
742
|
readonly unresolvedIdempotencyKeys: number;
|
|
743
|
-
/**
|
|
743
|
+
/** Unexpired unresolved claims whose endpoints start with `payment:` */
|
|
744
744
|
readonly unresolvedPaymentKeys: number;
|
|
745
745
|
readonly unexpiredPendingTasks: number;
|
|
746
746
|
readonly legacyImports: readonly SqliteLegacyImport[];
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { openSqliteDatabase, AP2_SPEC_VERSION, AP2_MODES, AP2_DEFAULT_CLOCK_SKEW
|
|
|
2
2
|
import { readCappedBody, createBearerCheck, MCP_TOOL_NAME_PATTERN, settlementResponse, joinUrl, settlementResponseFromDetails, settlementFailure, x402ErrorCode, x402RefusalStatus } from './chunk-77HLISG4.js';
|
|
3
3
|
import { MPP_DEFAULT_NETWORK, isMppNetwork, MPP_NETWORKS, MPP_DEFAULT_PAYMENT_FLOW, MPP_MIN_CHALLENGE_SECRET_LENGTH, MPP_PROFILE } from './chunk-6Z2H53CG.js';
|
|
4
4
|
import { contentDigest, CONTENT_DIGEST_METADATA_KEY, mppProblem, mppProblemDetail } from './chunk-D7FPSGUQ.js';
|
|
5
|
-
import { X402_PAYMENT_FLOWS, validateCustomNetworks, findX402Network, X402_DEFAULT_PAYMENT_FLOW, resolveX402Deployment, resolveDeploymentMode, requireX402Network, resolveX402Option, isEvmAddress, isEvmZeroAddress, SETTLE_AFTER_BACKEND_METADATA_KEY, x402OfferName, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, canonicalJson } from './chunk-
|
|
6
|
-
import { PACKAGE_VERSION } from './chunk-
|
|
5
|
+
import { X402_PAYMENT_FLOWS, validateCustomNetworks, findX402Network, X402_DEFAULT_PAYMENT_FLOW, resolveX402Deployment, resolveDeploymentMode, requireX402Network, resolveX402Option, isEvmAddress, isEvmZeroAddress, SETTLE_AFTER_BACKEND_METADATA_KEY, x402OfferName, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, canonicalJson } from './chunk-5AO5N2XY.js';
|
|
6
|
+
import { PACKAGE_VERSION } from './chunk-2573DASO.js';
|
|
7
7
|
import { PAYMENT_KEY_ENDPOINT_PREFIX } from './chunk-IWXVQYG5.js';
|
|
8
8
|
import { hasMethodGroup } from './chunk-WDD2ZUR3.js';
|
|
9
9
|
import { RESERVED_INPUT_FIELDS, PROTOCOL_NAMES, PAYMENT_METHOD_NAMES, PAYMENT_HEADER, AUTHORIZATION_HEADER, CommerceError, systemClock, NOOP_LOGGER, transactionState, DEFAULT_BACKEND_TIMEOUT_MS, isCommerceError, describeError, isHttpProtocolAdapter, toLogInfo, toCommerceError, extractReservedInputFields, parseAuthorizationHeader, toPaymentRequiredEnvelope, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, toErrorEnvelope, DELIVERY_SUMMARY_META_KEY, toDeliverySummary, PAYMENT_INPUT_FIELD, AUTHORIZATION_INPUT_FIELD, parseAuthorizationSubmission, RECONCILIATION_METADATA_KEY, TRANSACTION_STATES, redactedErrorText } from './chunk-YHNTTMED.js';
|
|
@@ -3372,7 +3372,10 @@ function normalizeResource(id, entry, protocols, x402, mpp, ap2) {
|
|
|
3372
3372
|
{ details: { path: `resources.${id}.mimeType`, resourceId: id } }
|
|
3373
3373
|
);
|
|
3374
3374
|
}
|
|
3375
|
-
const
|
|
3375
|
+
const servingRail = paymentMethods.find(
|
|
3376
|
+
(method) => method === "x402" && x402?.config.enabled === true || method === "mpp" && mpp?.enabled === true
|
|
3377
|
+
);
|
|
3378
|
+
const idempotency = normalizeResourceIdempotency(id, entry, paymentMethods, servingRail);
|
|
3376
3379
|
const pricing = entry.pricing.type === "free" ? { type: "free" } : { type: "fixed", amount: entry.pricing.amount, currency: entry.pricing.currency };
|
|
3377
3380
|
const authorization = normalizeResourceAuthorization(id, entry, pricing, ap2);
|
|
3378
3381
|
return {
|
|
@@ -3400,7 +3403,7 @@ function normalizeResource(id, entry, protocols, x402, mpp, ap2) {
|
|
|
3400
3403
|
...idempotency !== void 0 ? { idempotency } : {}
|
|
3401
3404
|
};
|
|
3402
3405
|
}
|
|
3403
|
-
function normalizeResourceIdempotency(id, entry, paymentMethods) {
|
|
3406
|
+
function normalizeResourceIdempotency(id, entry, paymentMethods, servingRail) {
|
|
3404
3407
|
const raw = entry.idempotency;
|
|
3405
3408
|
if (raw === void 0) return void 0;
|
|
3406
3409
|
const path2 = `resources.${id}.idempotency`;
|
|
@@ -3422,6 +3425,11 @@ function normalizeResourceIdempotency(id, entry, paymentMethods) {
|
|
|
3422
3425
|
`${path2}.redelivery.required`
|
|
3423
3426
|
);
|
|
3424
3427
|
}
|
|
3428
|
+
if (required && servingRail !== void 0 && servingRail !== "x402") {
|
|
3429
|
+
console.warn(
|
|
3430
|
+
`[agent-commerce] Resource "${id}" sets idempotency.redelivery.required, which applies to x402 only, but the gateway serves it on ${servingRail}, the first enabled rail in its payments. The setting has no effect; list "x402" first or remove it.`
|
|
3431
|
+
);
|
|
3432
|
+
}
|
|
3425
3433
|
redelivery = {
|
|
3426
3434
|
retentionHours: toNumber(
|
|
3427
3435
|
raw.redelivery.retentionHours ?? DEFAULT_REDELIVERY_RETENTION_HOURS,
|
|
@@ -3522,6 +3530,11 @@ function normalize(raw) {
|
|
|
3522
3530
|
{ details: { path: "protocols.a2a.enabled" } }
|
|
3523
3531
|
);
|
|
3524
3532
|
}
|
|
3533
|
+
if (!isHttpUrl(raw.merchant.publicBaseUrl)) {
|
|
3534
|
+
console.warn(
|
|
3535
|
+
`[agent-commerce] merchant.publicBaseUrl ${JSON.stringify(raw.merchant.publicBaseUrl)} is not an http:// or https:// URL. The Host check may then refuse every caller but loopback, and the A2A Agent Card and ACP discovery publish broken URLs.`
|
|
3536
|
+
);
|
|
3537
|
+
}
|
|
3525
3538
|
return {
|
|
3526
3539
|
version: SUPPORTED_CONFIG_VERSION,
|
|
3527
3540
|
merchant: {
|
|
@@ -3683,6 +3696,7 @@ function resolveConfigPath(explicitPath, env, cwd) {
|
|
|
3683
3696
|
}
|
|
3684
3697
|
|
|
3685
3698
|
// src/gateway/access-control.ts
|
|
3699
|
+
var HEALTH_PATH = "/health";
|
|
3686
3700
|
var CORS_METHODS = "GET,POST,OPTIONS";
|
|
3687
3701
|
var CORS_HEADERS = [
|
|
3688
3702
|
"content-type",
|
|
@@ -3716,8 +3730,9 @@ function buildAccessControlHook(options) {
|
|
|
3716
3730
|
const allowedOrigins = new Set(options.allowedOrigins.map((origin) => origin.toLowerCase()));
|
|
3717
3731
|
const publicHostname = hostnameOf(options.publicBaseUrl);
|
|
3718
3732
|
return async (request, reply) => {
|
|
3719
|
-
const
|
|
3720
|
-
|
|
3733
|
+
const route = request.routeOptions;
|
|
3734
|
+
const isHealthProbe = route.url === HEALTH_PATH && (route.method === "GET" || route.method === "HEAD");
|
|
3735
|
+
if (!isHealthProbe && !isAllowedHost(request.headers.host, publicHostname)) {
|
|
3721
3736
|
reply.status(403).send({ status: "error", code: "FORBIDDEN", message: "Host not allowed" });
|
|
3722
3737
|
return;
|
|
3723
3738
|
}
|
|
@@ -4252,7 +4267,7 @@ var AUTHORIZATION_PROVIDER_DETAIL = {
|
|
|
4252
4267
|
warn: "authorization-provider-degraded",
|
|
4253
4268
|
fail: "authorization-provider-unreachable"
|
|
4254
4269
|
};
|
|
4255
|
-
async function probe(target, kind, details, options) {
|
|
4270
|
+
async function probe(target, kind, details, options, failing) {
|
|
4256
4271
|
let health;
|
|
4257
4272
|
let threw = false;
|
|
4258
4273
|
try {
|
|
@@ -4263,7 +4278,16 @@ async function probe(target, kind, details, options) {
|
|
|
4263
4278
|
health = { status: "fail", checkedAt: options.clock.nowIso() };
|
|
4264
4279
|
threw = true;
|
|
4265
4280
|
}
|
|
4266
|
-
|
|
4281
|
+
const key = `${kind}:${target.name}`;
|
|
4282
|
+
const startsFailing = health.status === "fail" && !failing.has(key);
|
|
4283
|
+
if (health.status === "fail") failing.add(key);
|
|
4284
|
+
else failing.delete(key);
|
|
4285
|
+
if (startsFailing && !threw) {
|
|
4286
|
+
options.logger.warn(
|
|
4287
|
+
{ name: target.name, ...health.detail !== void 0 ? { detail: health.detail } : {} },
|
|
4288
|
+
`${kind} health check failed (detail not sent to the client)`
|
|
4289
|
+
);
|
|
4290
|
+
} else if (health.detail !== void 0) {
|
|
4267
4291
|
options.logger.debug(
|
|
4268
4292
|
{ name: target.name, detail: health.detail },
|
|
4269
4293
|
`${kind} health detail (not sent to the client)`
|
|
@@ -4279,25 +4303,32 @@ async function probe(target, kind, details, options) {
|
|
|
4279
4303
|
health
|
|
4280
4304
|
};
|
|
4281
4305
|
}
|
|
4282
|
-
async function evaluate(options) {
|
|
4306
|
+
async function evaluate(options, failing) {
|
|
4283
4307
|
const [store, adapters, paymentProviders, authorizationProviders] = await Promise.all([
|
|
4284
|
-
probe(
|
|
4308
|
+
probe(
|
|
4309
|
+
{ name: "store", health: () => options.store.health() },
|
|
4310
|
+
"store",
|
|
4311
|
+
STORE_DETAIL,
|
|
4312
|
+
options,
|
|
4313
|
+
failing
|
|
4314
|
+
),
|
|
4285
4315
|
Promise.all(
|
|
4286
4316
|
options.adapterRuntimes.map(async (runtime) => ({
|
|
4287
4317
|
runtime,
|
|
4288
4318
|
probed: await probe(
|
|
4289
|
-
// getAdapterHealth
|
|
4290
|
-
//
|
|
4319
|
+
// getAdapterHealth converts throws to failed results, which use
|
|
4320
|
+
// the logging rules for returned results
|
|
4291
4321
|
{ name: runtime.adapter.name, health: () => getAdapterHealth(runtime, options.clock) },
|
|
4292
4322
|
"adapter",
|
|
4293
4323
|
ADAPTER_DETAIL,
|
|
4294
|
-
options
|
|
4324
|
+
options,
|
|
4325
|
+
failing
|
|
4295
4326
|
)
|
|
4296
4327
|
}))
|
|
4297
4328
|
),
|
|
4298
4329
|
Promise.all(
|
|
4299
4330
|
options.paymentProviders.map(
|
|
4300
|
-
(provider) => probe(provider, "payment provider", PAYMENT_PROVIDER_DETAIL, options)
|
|
4331
|
+
(provider) => probe(provider, "payment provider", PAYMENT_PROVIDER_DETAIL, options, failing)
|
|
4301
4332
|
)
|
|
4302
4333
|
),
|
|
4303
4334
|
// An unusable authorization provider blocks readiness on the same threshold
|
|
@@ -4305,7 +4336,7 @@ async function evaluate(options) {
|
|
|
4305
4336
|
// without it, and serving the challenge anyway promises what we cannot honor
|
|
4306
4337
|
Promise.all(
|
|
4307
4338
|
options.authorizationProviders.map(
|
|
4308
|
-
(provider) => probe(provider, "authorization provider", AUTHORIZATION_PROVIDER_DETAIL, options)
|
|
4339
|
+
(provider) => probe(provider, "authorization provider", AUTHORIZATION_PROVIDER_DETAIL, options, failing)
|
|
4309
4340
|
)
|
|
4310
4341
|
)
|
|
4311
4342
|
]);
|
|
@@ -4337,11 +4368,12 @@ var READINESS_TTL_MS = 2e3;
|
|
|
4337
4368
|
function createReadinessProbe(options, ttlMs = READINESS_TTL_MS) {
|
|
4338
4369
|
let cached;
|
|
4339
4370
|
let inFlight;
|
|
4371
|
+
const failing = /* @__PURE__ */ new Set();
|
|
4340
4372
|
const current = async () => {
|
|
4341
4373
|
const now = options.clock.monotonicMs();
|
|
4342
4374
|
if (cached && now - cached.at < ttlMs) return cached.evaluation;
|
|
4343
4375
|
if (inFlight) return inFlight;
|
|
4344
|
-
inFlight = evaluate(options).then((evaluation) => {
|
|
4376
|
+
inFlight = evaluate(options, failing).then((evaluation) => {
|
|
4345
4377
|
cached = { evaluation, at: options.clock.monotonicMs() };
|
|
4346
4378
|
return evaluation;
|
|
4347
4379
|
}).finally(() => {
|
|
@@ -4487,7 +4519,7 @@ function registerRoutes(options) {
|
|
|
4487
4519
|
clock: options.clock,
|
|
4488
4520
|
logger: options.logger
|
|
4489
4521
|
});
|
|
4490
|
-
server.get(
|
|
4522
|
+
server.get(HEALTH_PATH, async () => ({ status: "ok" }));
|
|
4491
4523
|
server.get("/ready", async (_request, reply) => {
|
|
4492
4524
|
const readiness = await readinessProbe.check();
|
|
4493
4525
|
reply.status(readiness.ready ? 200 : 503);
|
|
@@ -4766,7 +4798,14 @@ async function handleInvoke(request, reply, options) {
|
|
|
4766
4798
|
}
|
|
4767
4799
|
reply.status(outcome.backendStatus).send(outcome.body);
|
|
4768
4800
|
} catch (error) {
|
|
4769
|
-
|
|
4801
|
+
const commerceError = toCommerceError(error);
|
|
4802
|
+
const entry = { resourceId, requestId: request.id, err: toLogInfo(commerceError) };
|
|
4803
|
+
if (commerceError.httpStatus >= 500) {
|
|
4804
|
+
options.logger.warn(entry, "http adapter: execution failed");
|
|
4805
|
+
} else {
|
|
4806
|
+
options.logger.debug(entry, "http adapter: execution failed");
|
|
4807
|
+
}
|
|
4808
|
+
sendInvokeError(reply, commerceError, paymentMethod);
|
|
4770
4809
|
}
|
|
4771
4810
|
}
|
|
4772
4811
|
function relayedContentType(header2, body) {
|