@agentcash/router 1.2.4 → 1.2.5

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 CHANGED
@@ -189,10 +189,10 @@ var init_x402_facilitators = __esm({
189
189
  });
190
190
 
191
191
  // src/x402-config.ts
192
- async function resolvePayToValue(payTo, request, fallback) {
192
+ async function resolvePayToValue(payTo, request, fallback, body) {
193
193
  if (!payTo) return fallback;
194
194
  if (typeof payTo === "string") return payTo;
195
- return payTo(request);
195
+ return payTo(request, body);
196
196
  }
197
197
  function getConfiguredX402Accepts(config) {
198
198
  if (config.x402?.accepts?.length) {
@@ -209,12 +209,17 @@ function getConfiguredX402Accepts(config) {
209
209
  function getConfiguredX402Networks(config) {
210
210
  return [...new Set(getConfiguredX402Accepts(config).map((accept) => accept.network))];
211
211
  }
212
- async function resolveX402Accepts(request, routeEntry, accepts, fallbackPayTo) {
212
+ async function resolveX402Accepts(request, routeEntry, accepts, fallbackPayTo, body) {
213
213
  return Promise.all(
214
214
  accepts.map(async (accept) => ({
215
215
  network: accept.network,
216
216
  scheme: accept.scheme ?? "exact",
217
- payTo: await resolvePayToValue(accept.payTo ?? routeEntry.payTo, request, fallbackPayTo),
217
+ payTo: await resolvePayToValue(
218
+ routeEntry.payTo ?? accept.payTo,
219
+ request,
220
+ fallbackPayTo,
221
+ body
222
+ ),
218
223
  ...accept.asset ? { asset: accept.asset } : {},
219
224
  ...accept.decimals !== void 0 ? { decimals: accept.decimals } : {},
220
225
  ...accept.maxTimeoutSeconds !== void 0 ? { maxTimeoutSeconds: accept.maxTimeoutSeconds } : {},
@@ -1343,7 +1348,8 @@ function createRequestHandler(routeEntry, handler, deps) {
1343
1348
  request,
1344
1349
  routeEntry,
1345
1350
  deps.x402Accepts,
1346
- deps.payeeAddress
1351
+ deps.payeeAddress,
1352
+ body.data
1347
1353
  );
1348
1354
  const verify = await verifyX402Payment({
1349
1355
  server: deps.x402Server,
@@ -1774,7 +1780,8 @@ async function build402(request, routeEntry, deps, meta, pluginCtx, bodyData) {
1774
1780
  request,
1775
1781
  routeEntry,
1776
1782
  deps.x402Accepts,
1777
- deps.payeeAddress
1783
+ deps.payeeAddress,
1784
+ bodyData
1778
1785
  );
1779
1786
  const { encoded } = await buildX402Challenge({
1780
1787
  server: deps.x402Server,
package/dist/index.d.cts CHANGED
@@ -217,7 +217,7 @@ type PricingConfig<TBody = unknown> = string | ((body: TBody) => string | Promis
217
217
  tiers: Record<string, TierConfig>;
218
218
  default?: string;
219
219
  };
220
- type PayToConfig = string | ((request: Request) => string | Promise<string>);
220
+ type PayToConfig = string | ((request: Request, body?: unknown) => string | Promise<string>);
221
221
  interface X402AcceptBase {
222
222
  network: string;
223
223
  asset?: string;
package/dist/index.d.ts CHANGED
@@ -217,7 +217,7 @@ type PricingConfig<TBody = unknown> = string | ((body: TBody) => string | Promis
217
217
  tiers: Record<string, TierConfig>;
218
218
  default?: string;
219
219
  };
220
- type PayToConfig = string | ((request: Request) => string | Promise<string>);
220
+ type PayToConfig = string | ((request: Request, body?: unknown) => string | Promise<string>);
221
221
  interface X402AcceptBase {
222
222
  network: string;
223
223
  asset?: string;
package/dist/index.js CHANGED
@@ -167,10 +167,10 @@ var init_x402_facilitators = __esm({
167
167
  });
168
168
 
169
169
  // src/x402-config.ts
170
- async function resolvePayToValue(payTo, request, fallback) {
170
+ async function resolvePayToValue(payTo, request, fallback, body) {
171
171
  if (!payTo) return fallback;
172
172
  if (typeof payTo === "string") return payTo;
173
- return payTo(request);
173
+ return payTo(request, body);
174
174
  }
175
175
  function getConfiguredX402Accepts(config) {
176
176
  if (config.x402?.accepts?.length) {
@@ -187,12 +187,17 @@ function getConfiguredX402Accepts(config) {
187
187
  function getConfiguredX402Networks(config) {
188
188
  return [...new Set(getConfiguredX402Accepts(config).map((accept) => accept.network))];
189
189
  }
190
- async function resolveX402Accepts(request, routeEntry, accepts, fallbackPayTo) {
190
+ async function resolveX402Accepts(request, routeEntry, accepts, fallbackPayTo, body) {
191
191
  return Promise.all(
192
192
  accepts.map(async (accept) => ({
193
193
  network: accept.network,
194
194
  scheme: accept.scheme ?? "exact",
195
- payTo: await resolvePayToValue(accept.payTo ?? routeEntry.payTo, request, fallbackPayTo),
195
+ payTo: await resolvePayToValue(
196
+ routeEntry.payTo ?? accept.payTo,
197
+ request,
198
+ fallbackPayTo,
199
+ body
200
+ ),
196
201
  ...accept.asset ? { asset: accept.asset } : {},
197
202
  ...accept.decimals !== void 0 ? { decimals: accept.decimals } : {},
198
203
  ...accept.maxTimeoutSeconds !== void 0 ? { maxTimeoutSeconds: accept.maxTimeoutSeconds } : {},
@@ -1304,7 +1309,8 @@ function createRequestHandler(routeEntry, handler, deps) {
1304
1309
  request,
1305
1310
  routeEntry,
1306
1311
  deps.x402Accepts,
1307
- deps.payeeAddress
1312
+ deps.payeeAddress,
1313
+ body.data
1308
1314
  );
1309
1315
  const verify = await verifyX402Payment({
1310
1316
  server: deps.x402Server,
@@ -1735,7 +1741,8 @@ async function build402(request, routeEntry, deps, meta, pluginCtx, bodyData) {
1735
1741
  request,
1736
1742
  routeEntry,
1737
1743
  deps.x402Accepts,
1738
- deps.payeeAddress
1744
+ deps.payeeAddress,
1745
+ bodyData
1739
1746
  );
1740
1747
  const { encoded } = await buildX402Challenge({
1741
1748
  server: deps.x402Server,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
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": {
@@ -29,7 +29,7 @@
29
29
  "@x402/evm": "^2.3.0",
30
30
  "@x402/extensions": "^2.3.0",
31
31
  "@x402/svm": "2.3.0",
32
- "mppx": "^0.4.10",
32
+ "mppx": "^0.4.11",
33
33
  "next": ">=15.0.0",
34
34
  "zod": "^4.0.0",
35
35
  "zod-openapi": "^5.0.0"
@@ -61,7 +61,7 @@
61
61
  "@x402/extensions": "^2.3.0",
62
62
  "@x402/svm": "2.3.0",
63
63
  "eslint": "^10.0.0",
64
- "mppx": "^0.4.10",
64
+ "mppx": "^0.4.11",
65
65
  "next": "^15.0.0",
66
66
  "prettier": "^3.8.1",
67
67
  "react": "^19.0.0",