@agentcash/router 1.1.2 → 1.1.4
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/dist/index.cjs +42 -9
- package/dist/index.js +42 -9
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -267,12 +267,12 @@ async function createX402Server(config) {
|
|
|
267
267
|
facilitatorsByNetwork
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
|
-
function cachedClient(inner,
|
|
270
|
+
function cachedClient(inner, kinds) {
|
|
271
271
|
return {
|
|
272
272
|
verify: inner.verify.bind(inner),
|
|
273
273
|
settle: inner.settle.bind(inner),
|
|
274
274
|
getSupported: async () => ({
|
|
275
|
-
kinds
|
|
275
|
+
kinds,
|
|
276
276
|
extensions: [],
|
|
277
277
|
signers: {}
|
|
278
278
|
})
|
|
@@ -282,7 +282,19 @@ function createFacilitatorClients(facilitatorsByNetwork, HTTPFacilitatorClient)
|
|
|
282
282
|
const groups = getResolvedX402FacilitatorGroups(facilitatorsByNetwork);
|
|
283
283
|
return groups.map((group) => {
|
|
284
284
|
const inner = new HTTPFacilitatorClient(group.config);
|
|
285
|
-
|
|
285
|
+
const kinds = group.networks.map((network) => ({
|
|
286
|
+
x402Version: 2,
|
|
287
|
+
scheme: "exact",
|
|
288
|
+
network,
|
|
289
|
+
...group.family === "solana" ? {
|
|
290
|
+
extra: {
|
|
291
|
+
features: {
|
|
292
|
+
xSettlementAccountSupported: true
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
} : {}
|
|
296
|
+
}));
|
|
297
|
+
return cachedClient(inner, kinds);
|
|
286
298
|
});
|
|
287
299
|
}
|
|
288
300
|
var init_server = __esm({
|
|
@@ -681,12 +693,33 @@ async function buildExpectedRequirements(server, request, price, accepts) {
|
|
|
681
693
|
return [...exactRequirements, ...customRequirements];
|
|
682
694
|
}
|
|
683
695
|
async function buildExactRequirements(server, request, price, accepts) {
|
|
684
|
-
const
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
];
|
|
688
|
-
if (
|
|
689
|
-
|
|
696
|
+
const exactGroups = [
|
|
697
|
+
buildEvmExactOptions(accepts, price),
|
|
698
|
+
buildSolanaExactOptions(accepts, price)
|
|
699
|
+
].filter((options) => options.length > 0);
|
|
700
|
+
if (exactGroups.length === 0) return [];
|
|
701
|
+
const requirements = [];
|
|
702
|
+
const failures = [];
|
|
703
|
+
for (const options of exactGroups) {
|
|
704
|
+
try {
|
|
705
|
+
requirements.push(
|
|
706
|
+
...await server.buildPaymentRequirementsFromOptions(options, { request })
|
|
707
|
+
);
|
|
708
|
+
} catch (error) {
|
|
709
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
710
|
+
failures.push(err);
|
|
711
|
+
if (exactGroups.length === 1) {
|
|
712
|
+
throw err;
|
|
713
|
+
}
|
|
714
|
+
console.warn(
|
|
715
|
+
`[router] Failed to build x402 exact requirements for ${options[0]?.network}: ${err.message}`
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if (requirements.length > 0) {
|
|
720
|
+
return requirements;
|
|
721
|
+
}
|
|
722
|
+
throw failures[0] ?? new Error("Failed to build x402 exact requirements");
|
|
690
723
|
}
|
|
691
724
|
function buildCustomRequirements(price, accepts) {
|
|
692
725
|
return accepts.filter((accept) => accept.scheme !== "exact").map((accept) => buildCustomRequirement(price, accept));
|
package/dist/index.js
CHANGED
|
@@ -245,12 +245,12 @@ async function createX402Server(config) {
|
|
|
245
245
|
facilitatorsByNetwork
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
|
-
function cachedClient(inner,
|
|
248
|
+
function cachedClient(inner, kinds) {
|
|
249
249
|
return {
|
|
250
250
|
verify: inner.verify.bind(inner),
|
|
251
251
|
settle: inner.settle.bind(inner),
|
|
252
252
|
getSupported: async () => ({
|
|
253
|
-
kinds
|
|
253
|
+
kinds,
|
|
254
254
|
extensions: [],
|
|
255
255
|
signers: {}
|
|
256
256
|
})
|
|
@@ -260,7 +260,19 @@ function createFacilitatorClients(facilitatorsByNetwork, HTTPFacilitatorClient)
|
|
|
260
260
|
const groups = getResolvedX402FacilitatorGroups(facilitatorsByNetwork);
|
|
261
261
|
return groups.map((group) => {
|
|
262
262
|
const inner = new HTTPFacilitatorClient(group.config);
|
|
263
|
-
|
|
263
|
+
const kinds = group.networks.map((network) => ({
|
|
264
|
+
x402Version: 2,
|
|
265
|
+
scheme: "exact",
|
|
266
|
+
network,
|
|
267
|
+
...group.family === "solana" ? {
|
|
268
|
+
extra: {
|
|
269
|
+
features: {
|
|
270
|
+
xSettlementAccountSupported: true
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} : {}
|
|
274
|
+
}));
|
|
275
|
+
return cachedClient(inner, kinds);
|
|
264
276
|
});
|
|
265
277
|
}
|
|
266
278
|
var init_server = __esm({
|
|
@@ -642,12 +654,33 @@ async function buildExpectedRequirements(server, request, price, accepts) {
|
|
|
642
654
|
return [...exactRequirements, ...customRequirements];
|
|
643
655
|
}
|
|
644
656
|
async function buildExactRequirements(server, request, price, accepts) {
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
];
|
|
649
|
-
if (
|
|
650
|
-
|
|
657
|
+
const exactGroups = [
|
|
658
|
+
buildEvmExactOptions(accepts, price),
|
|
659
|
+
buildSolanaExactOptions(accepts, price)
|
|
660
|
+
].filter((options) => options.length > 0);
|
|
661
|
+
if (exactGroups.length === 0) return [];
|
|
662
|
+
const requirements = [];
|
|
663
|
+
const failures = [];
|
|
664
|
+
for (const options of exactGroups) {
|
|
665
|
+
try {
|
|
666
|
+
requirements.push(
|
|
667
|
+
...await server.buildPaymentRequirementsFromOptions(options, { request })
|
|
668
|
+
);
|
|
669
|
+
} catch (error) {
|
|
670
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
671
|
+
failures.push(err);
|
|
672
|
+
if (exactGroups.length === 1) {
|
|
673
|
+
throw err;
|
|
674
|
+
}
|
|
675
|
+
console.warn(
|
|
676
|
+
`[router] Failed to build x402 exact requirements for ${options[0]?.network}: ${err.message}`
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
if (requirements.length > 0) {
|
|
681
|
+
return requirements;
|
|
682
|
+
}
|
|
683
|
+
throw failures[0] ?? new Error("Failed to build x402 exact requirements");
|
|
651
684
|
}
|
|
652
685
|
function buildCustomRequirements(price, accepts) {
|
|
653
686
|
return accepts.filter((accept) => accept.scheme !== "exact").map((accept) => buildCustomRequirement(price, accept));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentcash/router",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Unified route builder for Next.js App Router APIs with x402, MPP, SIWX, and API key auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -61,14 +61,14 @@
|
|
|
61
61
|
"@x402/extensions": "^2.3.0",
|
|
62
62
|
"@x402/svm": "2.3.0",
|
|
63
63
|
"eslint": "^10.0.0",
|
|
64
|
-
"mppx": "^0.
|
|
64
|
+
"mppx": "^0.4.1",
|
|
65
65
|
"next": "^15.0.0",
|
|
66
66
|
"prettier": "^3.8.1",
|
|
67
67
|
"react": "^19.0.0",
|
|
68
68
|
"tsup": "^8.0.0",
|
|
69
69
|
"typescript": "^5.8.0",
|
|
70
70
|
"typescript-eslint": "^8.55.0",
|
|
71
|
-
"viem": "^2.
|
|
71
|
+
"viem": "^2.47.2",
|
|
72
72
|
"vitest": "^3.0.0",
|
|
73
73
|
"zod": "^4.0.0",
|
|
74
74
|
"zod-openapi": "^5.0.0"
|