@devlab.group/agent-commerce 2.7.2 → 2.8.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 +71 -24
- package/dist/ap2.d.ts +3 -11
- package/dist/ap2.js +96 -27
- package/dist/ap2.js.map +1 -1
- package/dist/{chunk-77HLISG4.js → chunk-2PVRHMVT.js} +14 -10
- package/dist/chunk-2PVRHMVT.js.map +1 -0
- package/dist/chunk-ENK63GKR.js +22 -0
- package/dist/chunk-ENK63GKR.js.map +1 -0
- package/dist/{chunk-YHNTTMED.js → chunk-MDOGXTZD.js} +2 -2
- package/dist/chunk-MDOGXTZD.js.map +1 -0
- package/dist/chunk-MNI6APE6.js +64 -0
- package/dist/chunk-MNI6APE6.js.map +1 -0
- package/dist/{chunk-XXHC6AA3.js → chunk-QZW5YL3G.js} +160 -41
- package/dist/chunk-QZW5YL3G.js.map +1 -0
- package/dist/{chunk-DJRWYDKJ.js → chunk-RXYGC7A3.js} +3 -3
- package/dist/{chunk-DJRWYDKJ.js.map → chunk-RXYGC7A3.js.map} +1 -1
- package/dist/{chunk-5AO5N2XY.js → chunk-VHS6MGXJ.js} +621 -4
- package/dist/chunk-VHS6MGXJ.js.map +1 -0
- package/dist/cli/{ap2-O3HJSS2E.js → ap2-GYKFGE66.js} +35 -8
- package/dist/cli/ap2-GYKFGE66.js.map +1 -0
- package/dist/cli/chunk-2PO65227.js +619 -0
- package/dist/cli/chunk-2PO65227.js.map +1 -0
- package/dist/cli/{chunk-GBBG66O6.js → chunk-3PGFOEVJ.js} +132 -103
- package/dist/cli/chunk-3PGFOEVJ.js.map +1 -0
- package/dist/cli/chunk-4YZULHX2.js +64 -0
- package/dist/cli/chunk-4YZULHX2.js.map +1 -0
- package/dist/cli/chunk-526C4KZA.js +93 -0
- package/dist/cli/chunk-526C4KZA.js.map +1 -0
- package/dist/cli/{chunk-FETTSOMT.js → chunk-5CH5VFC6.js} +139 -4
- package/dist/cli/chunk-5CH5VFC6.js.map +1 -0
- package/dist/cli/chunk-6BWEHQPJ.js +215 -0
- package/dist/cli/chunk-6BWEHQPJ.js.map +1 -0
- package/dist/cli/chunk-GISJ73ML.js +20 -0
- package/dist/cli/chunk-GISJ73ML.js.map +1 -0
- package/dist/cli/chunk-MASLG557.js +26 -0
- package/dist/cli/chunk-MASLG557.js.map +1 -0
- package/dist/cli/chunk-RQ7W3NA5.js +143 -0
- package/dist/cli/chunk-RQ7W3NA5.js.map +1 -0
- package/dist/cli/chunk-RWBUHDU7.js +48 -0
- package/dist/cli/chunk-RWBUHDU7.js.map +1 -0
- package/dist/cli/chunk-SAAT2XFX.js +8 -0
- package/dist/cli/{chunk-B4QJV7OC.js.map → chunk-SAAT2XFX.js.map} +1 -1
- package/dist/cli/{chunk-S5TQXKQ7.js → chunk-SYXLQ5BS.js} +7 -5
- package/dist/cli/chunk-SYXLQ5BS.js.map +1 -0
- package/dist/cli/{chunk-FL4HPCD4.js → chunk-THH7Y3OO.js} +3 -35
- package/dist/cli/chunk-THH7Y3OO.js.map +1 -0
- package/dist/cli/{chunk-55AI6CLW.js → chunk-USIXWAXZ.js} +2 -2
- package/dist/cli/chunk-USIXWAXZ.js.map +1 -0
- package/dist/cli/{chunk-QUFFT5K3.js → chunk-VWQMSWDF.js} +141 -42
- package/dist/cli/chunk-VWQMSWDF.js.map +1 -0
- package/dist/cli/{chunk-OETKXDGA.js → chunk-WFIR374D.js} +89 -272
- package/dist/cli/chunk-WFIR374D.js.map +1 -0
- package/dist/cli/{chunk-XRG5UTIC.js → chunk-YXXPZFWC.js} +4 -4
- package/dist/cli/{chunk-XRG5UTIC.js.map → chunk-YXXPZFWC.js.map} +1 -1
- package/dist/cli/config-JWMHWVRT.js +14 -0
- package/dist/cli/{config-ODN4IEMZ.js.map → config-JWMHWVRT.js.map} +1 -1
- package/dist/cli/index.js +349 -78
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-G2D2Z77G.js → mcp-OW5GY7TT.js} +84 -45
- package/dist/cli/mcp-OW5GY7TT.js.map +1 -0
- package/dist/cli/payment-providers-QL2BJYMD.js +6 -0
- package/dist/cli/{payment-providers-7RIIZ5OF.js.map → payment-providers-QL2BJYMD.js.map} +1 -1
- package/dist/cli/{provider-ARV3VAQ7.js → provider-3A2LVEQS.js} +145 -23
- package/dist/cli/provider-3A2LVEQS.js.map +1 -0
- package/dist/cli/receipts-FQUFGEQD.js +9 -0
- package/dist/cli/{receipts-HLQ7D722.js.map → receipts-FQUFGEQD.js.map} +1 -1
- package/dist/cli/{run-BHODKC6H.js → run-KF5OQYPL.js} +92 -63
- package/dist/cli/run-KF5OQYPL.js.map +1 -0
- package/dist/cli/{x402-LHW2YQ6W.js → x402-5A7CVCIJ.js} +12 -8
- package/dist/cli/x402-5A7CVCIJ.js.map +1 -0
- package/dist/index.d.ts +36 -12
- package/dist/index.js +340 -394
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +80 -42
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +3 -2
- package/dist/mpp.js +139 -20
- package/dist/mpp.js.map +1 -1
- package/dist/{protocol-adapter-DdFL5LBU.d.ts → protocol-adapter-D6JH_kk-.d.ts} +2 -2
- package/dist/{runtime-BmaSp2Ce.d.ts → runtime-D8u6lYfx.d.ts} +10 -0
- package/dist/{store-DQwbKhnc.d.ts → store-BzgwHOPu.d.ts} +2 -2
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/{transaction-BXXJltZ-.d.ts → transaction-F9ZvhokH.d.ts} +1 -1
- package/dist/types-Dl27vhEc.d.ts +167 -0
- package/dist/x402.d.ts +7 -110
- package/dist/x402.js +6 -5
- package/dist/x402.js.map +1 -1
- package/package.json +3 -1
- package/dist/chunk-2573DASO.js +0 -8
- package/dist/chunk-2573DASO.js.map +0 -1
- package/dist/chunk-5AO5N2XY.js.map +0 -1
- package/dist/chunk-77HLISG4.js.map +0 -1
- package/dist/chunk-XXHC6AA3.js.map +0 -1
- package/dist/chunk-YHNTTMED.js.map +0 -1
- package/dist/cli/ap2-O3HJSS2E.js.map +0 -1
- package/dist/cli/chunk-3NVJAQRO.js +0 -119
- package/dist/cli/chunk-3NVJAQRO.js.map +0 -1
- package/dist/cli/chunk-55AI6CLW.js.map +0 -1
- package/dist/cli/chunk-66NTYSXI.js +0 -277
- package/dist/cli/chunk-66NTYSXI.js.map +0 -1
- package/dist/cli/chunk-B4QJV7OC.js +0 -8
- package/dist/cli/chunk-FETTSOMT.js.map +0 -1
- package/dist/cli/chunk-FL4HPCD4.js.map +0 -1
- package/dist/cli/chunk-GBBG66O6.js.map +0 -1
- package/dist/cli/chunk-H7EBJ4I3.js +0 -53
- package/dist/cli/chunk-H7EBJ4I3.js.map +0 -1
- package/dist/cli/chunk-OETKXDGA.js.map +0 -1
- package/dist/cli/chunk-QUFFT5K3.js.map +0 -1
- package/dist/cli/chunk-S5TQXKQ7.js.map +0 -1
- package/dist/cli/chunk-TPC4EJLT.js +0 -11
- package/dist/cli/chunk-TPC4EJLT.js.map +0 -1
- package/dist/cli/config-ODN4IEMZ.js +0 -13
- package/dist/cli/mcp-G2D2Z77G.js.map +0 -1
- package/dist/cli/payment-providers-7RIIZ5OF.js +0 -6
- package/dist/cli/provider-ARV3VAQ7.js.map +0 -1
- package/dist/cli/receipts-HLQ7D722.js +0 -9
- package/dist/cli/run-BHODKC6H.js.map +0 -1
- package/dist/cli/x402-LHW2YQ6W.js.map +0 -1
- package/dist/networks-DDHYJLcg.d.ts +0 -39
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { exampleObject, publishedInputSchema, exampleValue } from './chunk-MNI6APE6.js';
|
|
2
|
+
import { CommerceError } from './chunk-MDOGXTZD.js';
|
|
3
|
+
import { isRecord } from './chunk-2CJNA7MS.js';
|
|
4
|
+
import { isDeepStrictEqual } from 'util';
|
|
2
5
|
|
|
3
6
|
// src/payments/x402/networks.ts
|
|
4
7
|
var LOCAL_CHAIN_ID = 31337;
|
|
@@ -176,6 +179,620 @@ function describeDeploymentMode(mode) {
|
|
|
176
179
|
var SETTLE_AFTER_BACKEND_METADATA_KEY = "settleAfterBackend";
|
|
177
180
|
var REUSE_REJECTED_AUTHORIZATION_METADATA_KEY = "reuseRejectedAuthorization";
|
|
178
181
|
|
|
182
|
+
// src/support/x402.json
|
|
183
|
+
var x402_default = {
|
|
184
|
+
name: "x402",
|
|
185
|
+
kind: "payment",
|
|
186
|
+
title: "x402",
|
|
187
|
+
status: "supported",
|
|
188
|
+
role: "Payment rail, carried by HTTP, MCP and A2A.",
|
|
189
|
+
subset: "`exact` on EVM through EIP-3009 or Permit2, on Solana, and on NEAR (partial): challenge, verification, settlement and replay binding",
|
|
190
|
+
spec: {
|
|
191
|
+
revisions: ["v2"],
|
|
192
|
+
display: "x402 v2",
|
|
193
|
+
source: {
|
|
194
|
+
repo: "x402-foundation/x402",
|
|
195
|
+
commit: "51a0664c2b7826e3cb02595481eb6848a1b11815"
|
|
196
|
+
},
|
|
197
|
+
stable: null,
|
|
198
|
+
statement: "Protocol Version: 2",
|
|
199
|
+
checked: "2026-11-17"
|
|
200
|
+
},
|
|
201
|
+
packages: [
|
|
202
|
+
{ name: "@x402/core", use: "runtime" },
|
|
203
|
+
{ name: "@x402/evm", use: "runtime" },
|
|
204
|
+
{ name: "@x402/svm", use: "runtime" },
|
|
205
|
+
{ name: "@x402/near", use: "runtime" },
|
|
206
|
+
{ name: "@x402/mcp", use: "test" }
|
|
207
|
+
],
|
|
208
|
+
artifacts: [],
|
|
209
|
+
features: [
|
|
210
|
+
{ name: "exact-evm", status: "supported" },
|
|
211
|
+
{ name: "exact-svm", status: "supported" },
|
|
212
|
+
{ name: "exact-near", status: "partial" },
|
|
213
|
+
{ name: "local-facilitator", status: "supported" },
|
|
214
|
+
{ name: "remote-facilitator", status: "supported" },
|
|
215
|
+
{ name: "eip-3009", status: "supported" },
|
|
216
|
+
{ name: "permit2", status: "supported" },
|
|
217
|
+
{ name: "caip-2", status: "supported" },
|
|
218
|
+
{ name: "mode=local", status: "supported" },
|
|
219
|
+
{ name: "mode=testnet", status: "supported" },
|
|
220
|
+
{ name: "mode=mainnet", status: "supported" },
|
|
221
|
+
{ name: "authorization-flow", status: "supported" },
|
|
222
|
+
{ name: "upfront-flow", status: "supported" },
|
|
223
|
+
{ name: "multiple-offers", status: "partial" },
|
|
224
|
+
{
|
|
225
|
+
name: "erc-8409-quotes",
|
|
226
|
+
status: "experimental",
|
|
227
|
+
spec: {
|
|
228
|
+
revisions: ["0ee33230"],
|
|
229
|
+
display: "draft `SergeevDmitry/ERCs@0ee33230`",
|
|
230
|
+
source: {
|
|
231
|
+
repo: "SergeevDmitry/ERCs",
|
|
232
|
+
commit: "0ee33230ca9f9f41a714382552a47cd860465ca7"
|
|
233
|
+
},
|
|
234
|
+
stable: false,
|
|
235
|
+
statement: "status: Draft",
|
|
236
|
+
checked: "2026-11-17"
|
|
237
|
+
},
|
|
238
|
+
title: "ERC-8409",
|
|
239
|
+
role: "x402 feature: EIP-712 signed quotes on the EVM offers of a challenge.",
|
|
240
|
+
subset: "signed quotes on x402 EVM offers; issuer published in `/.well-known/agent-commerce`"
|
|
241
|
+
},
|
|
242
|
+
{ name: "public-resource-url", status: "experimental" },
|
|
243
|
+
{ name: "bazaar", status: "experimental" }
|
|
244
|
+
],
|
|
245
|
+
exclusions: [
|
|
246
|
+
{ name: "permit2 gas sponsoring extensions" },
|
|
247
|
+
{ name: "upto scheme" },
|
|
248
|
+
{ name: "batch-settlement scheme" },
|
|
249
|
+
{ name: "auth-capture scheme" },
|
|
250
|
+
{
|
|
251
|
+
name: "x402 v1",
|
|
252
|
+
note: "A payload declaring an `x402Version` other than 2 is refused as `invalid_x402_version` on every carrier."
|
|
253
|
+
},
|
|
254
|
+
{ name: "payer-bound quotes", feature: "erc-8409-quotes" },
|
|
255
|
+
{
|
|
256
|
+
name: "contract quote issuers (ERC-1271, ERC-6492, EIP-7702 delegates)",
|
|
257
|
+
feature: "erc-8409-quotes"
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
name: "quote consumption, single-use enforcement or revocation",
|
|
261
|
+
feature: "erc-8409-quotes"
|
|
262
|
+
},
|
|
263
|
+
{ name: "quote client nonces", feature: "erc-8409-quotes" },
|
|
264
|
+
{ name: "quotes for MPP, Solana or NEAR", feature: "erc-8409-quotes" },
|
|
265
|
+
{
|
|
266
|
+
name: "signed receipts and the x402 offer-receipt extension",
|
|
267
|
+
feature: "erc-8409-quotes"
|
|
268
|
+
},
|
|
269
|
+
{ name: "remote quote signers and KMS", feature: "erc-8409-quotes" },
|
|
270
|
+
{ name: "per-resource quote toggles", feature: "erc-8409-quotes" }
|
|
271
|
+
],
|
|
272
|
+
deviations: [],
|
|
273
|
+
combinations: [
|
|
274
|
+
{
|
|
275
|
+
surface: "http",
|
|
276
|
+
method: "x402",
|
|
277
|
+
level: "e2e",
|
|
278
|
+
evidence: "tests/e2e/payment/x402-settlement.e2e.test.ts"
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
surface: "a2a",
|
|
282
|
+
method: "x402",
|
|
283
|
+
level: "e2e",
|
|
284
|
+
evidence: "tests/e2e/payment/x402-settlement.e2e.test.ts"
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
surface: "http",
|
|
288
|
+
method: "x402",
|
|
289
|
+
authorization: "ap2",
|
|
290
|
+
level: "e2e",
|
|
291
|
+
evidence: "tests/e2e/authorization/ap2-x402.e2e.test.ts"
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
surface: "mcp",
|
|
295
|
+
method: "x402",
|
|
296
|
+
level: "e2e",
|
|
297
|
+
evidence: "tests/e2e/payment/x402-bazaar.e2e.test.ts"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
surface: "mcp",
|
|
301
|
+
method: "x402",
|
|
302
|
+
level: "integration",
|
|
303
|
+
evidence: "tests/integration/mcp-payment-bindings.test.ts"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
surface: "http",
|
|
307
|
+
method: "x402",
|
|
308
|
+
level: "testnet",
|
|
309
|
+
evidence: "tests/testnet/x402.smoke.test.ts"
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
surface: "http",
|
|
313
|
+
method: "x402",
|
|
314
|
+
level: "mainnet",
|
|
315
|
+
evidence: "tests/mainnet/x402.smoke.test.ts"
|
|
316
|
+
}
|
|
317
|
+
],
|
|
318
|
+
gaps: [],
|
|
319
|
+
docs: ["docs/protocols/x402.md"]
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// src/core/execution/backend-request.ts
|
|
323
|
+
var NEVER_FORWARDED_HEADER = /^(authorization|cookie|set-cookie|host|content-length|content-type|connection|keep-alive|te|trailer|transfer-encoding|upgrade|idempotency-key|proxy-.*)$/;
|
|
324
|
+
var PATH_PARAM_PATTERN = /\{([a-zA-Z0-9_.-]+)\}/g;
|
|
325
|
+
function extractPathParameterNames(url) {
|
|
326
|
+
return [...url.matchAll(PATH_PARAM_PATTERN)].map((match) => match[1]);
|
|
327
|
+
}
|
|
328
|
+
function findUnparsedBraceToken(url) {
|
|
329
|
+
const residue = url.replace(PATH_PARAM_PATTERN, "");
|
|
330
|
+
const index = residue.search(/[{}]/);
|
|
331
|
+
if (index === -1) return void 0;
|
|
332
|
+
const token = /\{[^{}]*\}?|\}/.exec(residue.slice(index));
|
|
333
|
+
return token?.[0] ?? residue[index];
|
|
334
|
+
}
|
|
335
|
+
function validateBackendRequestShape(handler, input, context, backendHeaders) {
|
|
336
|
+
const inputRecord = isRecord(input) ? input : {};
|
|
337
|
+
const parts = buildBackendRequestParts(handler, inputRecord, context);
|
|
338
|
+
buildHeaders(handler, context, backendHeaders);
|
|
339
|
+
let target;
|
|
340
|
+
try {
|
|
341
|
+
target = new URL(parts.url);
|
|
342
|
+
} catch {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
checkQueryCollision(target, parts.query, context);
|
|
346
|
+
}
|
|
347
|
+
function acceptsBody(method) {
|
|
348
|
+
return method !== "GET" && method !== "DELETE";
|
|
349
|
+
}
|
|
350
|
+
function buildBackendRequestParts(handler, input, context) {
|
|
351
|
+
const bindings = handler.inputBindings;
|
|
352
|
+
if (bindings === void 0) {
|
|
353
|
+
const { url: url2, remaining } = applyPathTemplate(handler.url, input, context);
|
|
354
|
+
return acceptsBody(handler.method) ? { url: url2, query: {}, body: { value: remaining } } : { url: url2, query: remaining };
|
|
355
|
+
}
|
|
356
|
+
const pathValues = bindings.path === void 0 ? {} : resolveBoundGroup(input, bindings.path, "path", context);
|
|
357
|
+
const { url } = applyPathTemplate(handler.url, pathValues, context);
|
|
358
|
+
const query = bindings.query === void 0 ? {} : resolveBoundGroup(input, bindings.query, "query", context);
|
|
359
|
+
const bodyValue = bindings.body === void 0 ? void 0 : input[bindings.body];
|
|
360
|
+
if (bodyValue === void 0 || !acceptsBody(handler.method)) return { url, query };
|
|
361
|
+
return { url, query, body: { value: bodyValue } };
|
|
362
|
+
}
|
|
363
|
+
function resolveBoundGroup(input, key, kind, context) {
|
|
364
|
+
const value = input[key];
|
|
365
|
+
if (value === void 0) return {};
|
|
366
|
+
if (!isRecord(value)) {
|
|
367
|
+
throw new CommerceError(
|
|
368
|
+
"INPUT_INVALID",
|
|
369
|
+
`Input "${key}" must be an object of ${kind} parameters`,
|
|
370
|
+
{ ...context, details: { field: key } }
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
return value;
|
|
374
|
+
}
|
|
375
|
+
function checkQueryCollision(target, remaining, context) {
|
|
376
|
+
const templateKeys = new Set(target.searchParams.keys());
|
|
377
|
+
for (const key of Object.keys(remaining)) {
|
|
378
|
+
if (templateKeys.has(key)) {
|
|
379
|
+
throw new CommerceError(
|
|
380
|
+
"INPUT_INVALID",
|
|
381
|
+
`Input key "${key}" collides with a query parameter already set on backend.url`,
|
|
382
|
+
{ requestId: context.requestId, resourceId: context.resourceId, details: { field: key } }
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
var TRAVERSAL_PATH_VALUES = /* @__PURE__ */ new Set(["", ".", ".."]);
|
|
388
|
+
function applyPathTemplate(template, input, context) {
|
|
389
|
+
const remaining = { ...input };
|
|
390
|
+
let missing;
|
|
391
|
+
let invalid4;
|
|
392
|
+
const url = template.replace(PATH_PARAM_PATTERN, (_match, key) => {
|
|
393
|
+
if (!Object.hasOwn(remaining, key)) {
|
|
394
|
+
missing = key;
|
|
395
|
+
return "";
|
|
396
|
+
}
|
|
397
|
+
const value = remaining[key];
|
|
398
|
+
delete remaining[key];
|
|
399
|
+
const raw = stringifyPrimitive(value);
|
|
400
|
+
if (TRAVERSAL_PATH_VALUES.has(raw)) {
|
|
401
|
+
invalid4 = key;
|
|
402
|
+
return "";
|
|
403
|
+
}
|
|
404
|
+
return encodeURIComponent(raw);
|
|
405
|
+
});
|
|
406
|
+
if (missing !== void 0) {
|
|
407
|
+
throw new CommerceError("INPUT_INVALID", `Path parameter "${missing}" was not supplied`, {
|
|
408
|
+
...context,
|
|
409
|
+
details: { field: missing }
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
if (invalid4 !== void 0) {
|
|
413
|
+
throw new CommerceError("INPUT_INVALID", `Path parameter "${invalid4}" is not a valid value`, {
|
|
414
|
+
...context,
|
|
415
|
+
details: { field: invalid4 }
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
return { url, remaining };
|
|
419
|
+
}
|
|
420
|
+
function stringifyPrimitive(value) {
|
|
421
|
+
if (value === void 0 || value === null) return "";
|
|
422
|
+
if (typeof value === "string") return value;
|
|
423
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
424
|
+
try {
|
|
425
|
+
return JSON.stringify(value);
|
|
426
|
+
} catch {
|
|
427
|
+
return String(value);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function buildHeaders(handler, context, forwarded = {}) {
|
|
431
|
+
let headers;
|
|
432
|
+
try {
|
|
433
|
+
headers = new Headers(handler.headers);
|
|
434
|
+
} catch {
|
|
435
|
+
throw invalidHeaderError(context);
|
|
436
|
+
}
|
|
437
|
+
for (const [name, value] of Object.entries(forwarded)) {
|
|
438
|
+
if (NEVER_FORWARDED_HEADER.test(name.toLowerCase())) continue;
|
|
439
|
+
try {
|
|
440
|
+
if (!headers.has(name)) headers.set(name, value);
|
|
441
|
+
} catch {
|
|
442
|
+
throw new CommerceError("INPUT_INVALID", "A forwarded request header is invalid", {
|
|
443
|
+
...context,
|
|
444
|
+
details: { reason: "invalid-forwarded-header" }
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return headers;
|
|
449
|
+
}
|
|
450
|
+
function setHeader(headers, name, value, context) {
|
|
451
|
+
try {
|
|
452
|
+
headers.set(name, value);
|
|
453
|
+
} catch {
|
|
454
|
+
throw invalidHeaderError(context);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function invalidHeaderError(context) {
|
|
458
|
+
return new CommerceError("BACKEND_ERROR", "Backend request headers are invalid", {
|
|
459
|
+
...context,
|
|
460
|
+
details: { reason: "invalid-header" }
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
var SUPPORTED_TYPES = /* @__PURE__ */ new Set([
|
|
464
|
+
"object",
|
|
465
|
+
"string",
|
|
466
|
+
"number",
|
|
467
|
+
"integer",
|
|
468
|
+
"boolean",
|
|
469
|
+
"array",
|
|
470
|
+
"null"
|
|
471
|
+
]);
|
|
472
|
+
var ENFORCED_SCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
473
|
+
"type",
|
|
474
|
+
"properties",
|
|
475
|
+
"required",
|
|
476
|
+
"additionalProperties",
|
|
477
|
+
"enum",
|
|
478
|
+
"items",
|
|
479
|
+
"title",
|
|
480
|
+
"description",
|
|
481
|
+
"example",
|
|
482
|
+
"examples",
|
|
483
|
+
"default",
|
|
484
|
+
"$comment",
|
|
485
|
+
"deprecated",
|
|
486
|
+
"readOnly",
|
|
487
|
+
"writeOnly"
|
|
488
|
+
]);
|
|
489
|
+
var ANNOTATION_FORMS = [
|
|
490
|
+
["title", "a string", (value) => typeof value === "string"],
|
|
491
|
+
["description", "a string", (value) => typeof value === "string"],
|
|
492
|
+
["$comment", "a string", (value) => typeof value === "string"],
|
|
493
|
+
["examples", "a list", Array.isArray],
|
|
494
|
+
["deprecated", "a boolean", (value) => typeof value === "boolean"],
|
|
495
|
+
["readOnly", "a boolean", (value) => typeof value === "boolean"],
|
|
496
|
+
["writeOnly", "a boolean", (value) => typeof value === "boolean"]
|
|
497
|
+
];
|
|
498
|
+
var isDistinctStrings = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string") && new Set(value).size === value.length;
|
|
499
|
+
function unenforcedSchemaPart(schema, path = "$") {
|
|
500
|
+
if (!isRecord(schema)) return { path, message: "is not a schema object" };
|
|
501
|
+
const unknown = Object.keys(schema).find((key) => !ENFORCED_SCHEMA_KEYWORDS.has(key));
|
|
502
|
+
if (unknown !== void 0) {
|
|
503
|
+
return { path, message: `uses "${unknown}", which the gateway does not enforce` };
|
|
504
|
+
}
|
|
505
|
+
const malformed = (keyword, form) => ({
|
|
506
|
+
path,
|
|
507
|
+
message: `has a "${keyword}" that is not ${form}`
|
|
508
|
+
});
|
|
509
|
+
const { type, properties, required, additionalProperties, items } = schema;
|
|
510
|
+
const types = typeof type === "string" ? [type] : type === void 0 ? [] : type;
|
|
511
|
+
if (!isDistinctStrings(types) || Array.isArray(type) && type.length === 0 || !types.every((entry) => SUPPORTED_TYPES.has(entry))) {
|
|
512
|
+
return malformed("type", "a supported type or a list of distinct ones");
|
|
513
|
+
}
|
|
514
|
+
if (required !== void 0 && !isDistinctStrings(required)) {
|
|
515
|
+
return malformed("required", "a list of distinct strings");
|
|
516
|
+
}
|
|
517
|
+
const allowed = schema["enum"];
|
|
518
|
+
if (allowed !== void 0 && (!Array.isArray(allowed) || allowed.length === 0)) {
|
|
519
|
+
return malformed("enum", "a list with at least one value");
|
|
520
|
+
}
|
|
521
|
+
for (const [keyword, form, accepts] of ANNOTATION_FORMS) {
|
|
522
|
+
if (schema[keyword] !== void 0 && !accepts(schema[keyword])) return malformed(keyword, form);
|
|
523
|
+
}
|
|
524
|
+
if (properties !== void 0) {
|
|
525
|
+
if (!isRecord(properties)) return malformed("properties", "an object");
|
|
526
|
+
for (const [key, sub] of Object.entries(properties)) {
|
|
527
|
+
const part = unenforcedSchemaPart(sub, `${path}.properties.${key}`);
|
|
528
|
+
if (part !== void 0) return part;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (additionalProperties !== void 0) {
|
|
532
|
+
if (!isObjectSchemaNode(schema)) {
|
|
533
|
+
return { path, message: 'declares "additionalProperties" but is not an object schema' };
|
|
534
|
+
}
|
|
535
|
+
if (typeof additionalProperties !== "boolean") {
|
|
536
|
+
const part = unenforcedSchemaPart(additionalProperties, `${path}.additionalProperties`);
|
|
537
|
+
if (part !== void 0) return part;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (items === void 0) return void 0;
|
|
541
|
+
if (!types.includes("array")) {
|
|
542
|
+
return { path, message: 'declares "items" but its type does not include "array"' };
|
|
543
|
+
}
|
|
544
|
+
return unenforcedSchemaPart(items, `${path}.items`);
|
|
545
|
+
}
|
|
546
|
+
function compileJsonSchema(schema) {
|
|
547
|
+
return (input) => {
|
|
548
|
+
if (schema === void 0) return { valid: true, value: input };
|
|
549
|
+
const errors = validateNode(schema, input, "$");
|
|
550
|
+
return errors.length === 0 ? { valid: true, value: input } : { valid: false, errors };
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
function matchesType(type, value) {
|
|
554
|
+
switch (type) {
|
|
555
|
+
case "object":
|
|
556
|
+
return isRecord(value);
|
|
557
|
+
case "array":
|
|
558
|
+
return Array.isArray(value);
|
|
559
|
+
case "string":
|
|
560
|
+
return typeof value === "string";
|
|
561
|
+
case "boolean":
|
|
562
|
+
return typeof value === "boolean";
|
|
563
|
+
case "number":
|
|
564
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
565
|
+
case "integer":
|
|
566
|
+
return typeof value === "number" && Number.isInteger(value);
|
|
567
|
+
case "null":
|
|
568
|
+
return value === null;
|
|
569
|
+
default:
|
|
570
|
+
return true;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
function describeType(value) {
|
|
574
|
+
if (value === null) return "null";
|
|
575
|
+
if (Array.isArray(value)) return "array";
|
|
576
|
+
return typeof value;
|
|
577
|
+
}
|
|
578
|
+
function deepEqual(a, b) {
|
|
579
|
+
return a === b || isDeepStrictEqual(a, b);
|
|
580
|
+
}
|
|
581
|
+
function own(obj, key) {
|
|
582
|
+
return Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
583
|
+
}
|
|
584
|
+
function typeList(raw) {
|
|
585
|
+
if (typeof raw === "string") return [raw];
|
|
586
|
+
if (Array.isArray(raw) && raw.every((entry) => typeof entry === "string")) {
|
|
587
|
+
return raw;
|
|
588
|
+
}
|
|
589
|
+
return void 0;
|
|
590
|
+
}
|
|
591
|
+
function isObjectSchemaNode(schema) {
|
|
592
|
+
const types = typeList(schema["type"]);
|
|
593
|
+
if (types !== void 0) return types.includes("object");
|
|
594
|
+
return Object.hasOwn(schema, "properties") || Object.hasOwn(schema, "required");
|
|
595
|
+
}
|
|
596
|
+
function validateNode(schema, value, path) {
|
|
597
|
+
const errors = [];
|
|
598
|
+
const types = typeList(own(schema, "type"));
|
|
599
|
+
const recognizedTypes = types?.filter((entry) => SUPPORTED_TYPES.has(entry));
|
|
600
|
+
if (types !== void 0 && recognizedTypes !== void 0 && recognizedTypes.length === types.length && types.length > 0) {
|
|
601
|
+
if (!types.some((entry) => matchesType(entry, value))) {
|
|
602
|
+
errors.push({
|
|
603
|
+
path,
|
|
604
|
+
message: `expected type "${types.join(" | ")}" but got ${describeType(value)}`
|
|
605
|
+
});
|
|
606
|
+
return errors;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
const enumRaw = own(schema, "enum");
|
|
610
|
+
if (Array.isArray(enumRaw)) {
|
|
611
|
+
const allowed = enumRaw;
|
|
612
|
+
if (!allowed.some((candidate) => deepEqual(candidate, value))) {
|
|
613
|
+
errors.push({ path, message: `must be one of ${JSON.stringify(allowed)}` });
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (isObjectSchemaNode(schema) && isRecord(value)) {
|
|
617
|
+
errors.push(...validateObject(schema, value, path));
|
|
618
|
+
} else if ((types?.includes("array") ?? false) && Array.isArray(value)) {
|
|
619
|
+
errors.push(...validateArray(schema, value, path));
|
|
620
|
+
}
|
|
621
|
+
return errors;
|
|
622
|
+
}
|
|
623
|
+
function validateObject(schema, value, path) {
|
|
624
|
+
const errors = [];
|
|
625
|
+
const propsRaw = own(schema, "properties");
|
|
626
|
+
const properties = isRecord(propsRaw) ? propsRaw : {};
|
|
627
|
+
const requiredRaw = own(schema, "required");
|
|
628
|
+
const required = Array.isArray(requiredRaw) ? requiredRaw.filter((entry) => typeof entry === "string") : [];
|
|
629
|
+
for (const key of required) {
|
|
630
|
+
if (!Object.hasOwn(value, key)) {
|
|
631
|
+
errors.push({ path: `${path}.${key}`, message: "is required" });
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
const additional = own(schema, "additionalProperties");
|
|
635
|
+
for (const key of Object.keys(value)) {
|
|
636
|
+
const propSchemaRaw = own(properties, key);
|
|
637
|
+
if (propSchemaRaw !== void 0) {
|
|
638
|
+
if (isRecord(propSchemaRaw)) {
|
|
639
|
+
errors.push(...validateNode(propSchemaRaw, value[key], `${path}.${key}`));
|
|
640
|
+
}
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (additional === false) {
|
|
644
|
+
errors.push({ path: `${path}.${key}`, message: "additional property not allowed" });
|
|
645
|
+
} else if (isRecord(additional)) {
|
|
646
|
+
errors.push(...validateNode(additional, value[key], `${path}.${key}`));
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return errors;
|
|
650
|
+
}
|
|
651
|
+
function validateArray(schema, value, path) {
|
|
652
|
+
const errors = [];
|
|
653
|
+
const itemsRaw = own(schema, "items");
|
|
654
|
+
if (isRecord(itemsRaw)) {
|
|
655
|
+
value.forEach((item, index) => {
|
|
656
|
+
errors.push(...validateNode(itemsRaw, item, `${path}[${index}]`));
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
return errors;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// src/payments/x402/provider/bazaar.ts
|
|
663
|
+
var BAZAAR_EXTENSION_KEY = "bazaar";
|
|
664
|
+
var MAX_BAZAAR_EXTENSION_BYTES = 4096;
|
|
665
|
+
var MAX_BAZAAR_DESCRIPTION_LENGTH = 500;
|
|
666
|
+
var JSON_SCHEMA_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
667
|
+
function bazaarMetadata(resource, surfaces, mimeType) {
|
|
668
|
+
if (surfaces.length === 0) return { extensions: {}, omitted: [] };
|
|
669
|
+
const all = (reason) => ({
|
|
670
|
+
extensions: {},
|
|
671
|
+
omitted: [{ surfaces, reason }]
|
|
672
|
+
});
|
|
673
|
+
const description = resource.description ?? resource.name;
|
|
674
|
+
if (description.length > MAX_BAZAAR_DESCRIPTION_LENGTH) {
|
|
675
|
+
return all(
|
|
676
|
+
`its description is longer than ${MAX_BAZAAR_DESCRIPTION_LENGTH} characters, which the CDP facilitator refuses`
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
const schema = resource.inputSchema ?? {};
|
|
680
|
+
const part = unenforcedSchemaPart(schema, "input");
|
|
681
|
+
if (part !== void 0) {
|
|
682
|
+
return all(`its input schema cannot be published as is: ${part.path} ${part.message}`);
|
|
683
|
+
}
|
|
684
|
+
const example = exampleObject(schema);
|
|
685
|
+
if (!compileJsonSchema(schema)(example).valid || !shapeAccepts(resource, example)) {
|
|
686
|
+
return all("the example generated from its input schema fails the gateway input checks");
|
|
687
|
+
}
|
|
688
|
+
const built = {
|
|
689
|
+
http: () => httpForm(resource, schema, example, mimeType),
|
|
690
|
+
mcp: () => mcpForm(resource, description, example)
|
|
691
|
+
};
|
|
692
|
+
const extensions = {};
|
|
693
|
+
const oversized = [];
|
|
694
|
+
for (const surface of surfaces) {
|
|
695
|
+
const extension = built[surface]();
|
|
696
|
+
if (Buffer.byteLength(JSON.stringify(extension)) > MAX_BAZAAR_EXTENSION_BYTES) {
|
|
697
|
+
oversized.push(surface);
|
|
698
|
+
} else {
|
|
699
|
+
extensions[surface] = extension;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return {
|
|
703
|
+
extensions,
|
|
704
|
+
omitted: oversized.length > 0 ? [
|
|
705
|
+
{
|
|
706
|
+
surfaces: oversized,
|
|
707
|
+
reason: `the extension exceeds ${MAX_BAZAAR_EXTENSION_BYTES} bytes`
|
|
708
|
+
}
|
|
709
|
+
] : []
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
function shapeAccepts(resource, example) {
|
|
713
|
+
try {
|
|
714
|
+
validateBackendRequestShape(resource.handler, example, {
|
|
715
|
+
requestId: "bazaar-example",
|
|
716
|
+
resourceId: resource.id
|
|
717
|
+
});
|
|
718
|
+
return true;
|
|
719
|
+
} catch {
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
var JSON_MEDIA_TYPE = /^[^/;\s]+\/(?:[^;\s]+\+)?json\s*(?:;|$)/i;
|
|
724
|
+
function httpForm(resource, schema, example, mimeType) {
|
|
725
|
+
const output = mimeType === void 0 || JSON_MEDIA_TYPE.test(mimeType) ? outputExample(resource.outputSchema) : void 0;
|
|
726
|
+
return {
|
|
727
|
+
info: {
|
|
728
|
+
input: { type: "http", method: "POST", bodyType: "json", body: example },
|
|
729
|
+
...output !== void 0 ? { output: { type: "json", example: output } } : {}
|
|
730
|
+
},
|
|
731
|
+
schema: {
|
|
732
|
+
$schema: JSON_SCHEMA_2020_12,
|
|
733
|
+
type: "object",
|
|
734
|
+
properties: {
|
|
735
|
+
input: {
|
|
736
|
+
type: "object",
|
|
737
|
+
properties: {
|
|
738
|
+
type: { type: "string", const: "http" },
|
|
739
|
+
method: { type: "string", enum: ["POST"] },
|
|
740
|
+
bodyType: { type: "string", enum: ["json"] },
|
|
741
|
+
body: schema
|
|
742
|
+
},
|
|
743
|
+
required: ["type", "method", "bodyType", "body"],
|
|
744
|
+
additionalProperties: false
|
|
745
|
+
},
|
|
746
|
+
...output !== void 0 ? {
|
|
747
|
+
output: {
|
|
748
|
+
type: "object",
|
|
749
|
+
properties: { type: { type: "string" }, example: resource.outputSchema },
|
|
750
|
+
required: ["type"]
|
|
751
|
+
}
|
|
752
|
+
} : {}
|
|
753
|
+
},
|
|
754
|
+
required: ["input"]
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
function mcpForm(resource, description, example) {
|
|
759
|
+
return {
|
|
760
|
+
info: {
|
|
761
|
+
input: {
|
|
762
|
+
type: "mcp",
|
|
763
|
+
toolName: resource.id,
|
|
764
|
+
description,
|
|
765
|
+
inputSchema: publishedInputSchema(resource.inputSchema),
|
|
766
|
+
example
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
schema: {
|
|
770
|
+
$schema: JSON_SCHEMA_2020_12,
|
|
771
|
+
type: "object",
|
|
772
|
+
properties: {
|
|
773
|
+
input: {
|
|
774
|
+
type: "object",
|
|
775
|
+
properties: {
|
|
776
|
+
type: { type: "string", const: "mcp" },
|
|
777
|
+
toolName: { type: "string" },
|
|
778
|
+
description: { type: "string" },
|
|
779
|
+
inputSchema: { type: "object" },
|
|
780
|
+
example: { type: "object" }
|
|
781
|
+
},
|
|
782
|
+
required: ["type", "toolName", "inputSchema"],
|
|
783
|
+
additionalProperties: false
|
|
784
|
+
}
|
|
785
|
+
},
|
|
786
|
+
required: ["input"]
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
function outputExample(schema) {
|
|
791
|
+
if (schema === void 0 || unenforcedSchemaPart(schema) !== void 0) return void 0;
|
|
792
|
+
const example = exampleValue(schema, "output");
|
|
793
|
+
return compileJsonSchema(schema)(example).valid ? example : void 0;
|
|
794
|
+
}
|
|
795
|
+
|
|
179
796
|
// src/payments/x402/addresses.ts
|
|
180
797
|
var EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
181
798
|
var EVM_ZERO = /^0x0{40}$/i;
|
|
@@ -607,6 +1224,6 @@ function canonicalJson(value) {
|
|
|
607
1224
|
return `{${members.join(",")}}`;
|
|
608
1225
|
}
|
|
609
1226
|
|
|
610
|
-
export { CDP_FACILITATOR_URL, LOCAL_CHAIN_ID, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, SETTLE_AFTER_BACKEND_METADATA_KEY, SUPPORTED_NETWORK_IDS, X402_DEFAULT_PAYMENT_FLOW, X402_PAYMENT_FLOWS, assertDevKeyIsLocalOnly, assertPayToIsNotDevAddress, canonicalJson, describeDeploymentMode, describeRpc, findX402Network, isEvmAddress, isEvmZeroAddress, isTransactionReference, isWellKnownDevKey, normalizeAddress, requireX402Network, resolveDeploymentMode, resolveX402Deployment, resolveX402Option, sameAddress, validateCustomNetworks, x402OfferName };
|
|
611
|
-
//# sourceMappingURL=chunk-
|
|
612
|
-
//# sourceMappingURL=chunk-
|
|
1227
|
+
export { BAZAAR_EXTENSION_KEY, CDP_FACILITATOR_URL, ENFORCED_SCHEMA_KEYWORDS, LOCAL_CHAIN_ID, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, SETTLE_AFTER_BACKEND_METADATA_KEY, SUPPORTED_NETWORK_IDS, X402_DEFAULT_PAYMENT_FLOW, X402_PAYMENT_FLOWS, assertDevKeyIsLocalOnly, assertPayToIsNotDevAddress, bazaarMetadata, buildBackendRequestParts, buildHeaders, canonicalJson, checkQueryCollision, compileJsonSchema, describeDeploymentMode, describeRpc, extractPathParameterNames, findUnparsedBraceToken, findX402Network, isEvmAddress, isEvmZeroAddress, isObjectSchemaNode, isTransactionReference, isWellKnownDevKey, normalizeAddress, requireX402Network, resolveDeploymentMode, resolveX402Deployment, resolveX402Option, sameAddress, setHeader, stringifyPrimitive, validateBackendRequestShape, validateCustomNetworks, x402OfferName, x402_default };
|
|
1228
|
+
//# sourceMappingURL=chunk-VHS6MGXJ.js.map
|
|
1229
|
+
//# sourceMappingURL=chunk-VHS6MGXJ.js.map
|