@agentcash/router 1.2.4 → 1.2.6

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,
@@ -2294,7 +2301,7 @@ function deriveTag(routeKey) {
2294
2301
  return routeKey.split("/")[0].split("-").map((w) => w[0].toUpperCase() + w.slice(1)).join(" ");
2295
2302
  }
2296
2303
  function buildOperation(routeKey, entry, tag) {
2297
- const protocols = entry.protocols.length > 0 ? entry.protocols : void 0;
2304
+ const protocols = entry.protocols.length > 0 ? entry.protocols.map(toProtocolObject) : void 0;
2298
2305
  const paymentRequired = Boolean(entry.pricing) || entry.authMode === "paid";
2299
2306
  const requiresSiwxScheme = entry.authMode === "siwx" || Boolean(entry.siwxEnabled);
2300
2307
  const requiresApiKeyScheme = Boolean(entry.apiKeyResolver) && entry.authMode !== "siwx";
@@ -2354,19 +2361,27 @@ function buildOperation(routeKey, entry, tag) {
2354
2361
  requiresApiKeyScheme
2355
2362
  };
2356
2363
  }
2364
+ function toProtocolObject(protocol) {
2365
+ if (protocol === "mpp") {
2366
+ return { mpp: { method: "", intent: "", currency: "" } };
2367
+ }
2368
+ return { [protocol]: {} };
2369
+ }
2357
2370
  function buildPricingInfo(entry) {
2358
2371
  if (!entry.pricing) return void 0;
2359
2372
  if (typeof entry.pricing === "string") {
2360
2373
  return {
2361
- pricingMode: "fixed",
2362
- price: entry.pricing
2374
+ price: { mode: "fixed", currency: "USD", amount: entry.pricing }
2363
2375
  };
2364
2376
  }
2365
2377
  if (typeof entry.pricing === "function") {
2366
2378
  return {
2367
- pricingMode: "quote",
2368
- ...entry.minPrice ? { minPrice: entry.minPrice } : {},
2369
- ...entry.maxPrice ? { maxPrice: entry.maxPrice } : {}
2379
+ price: {
2380
+ mode: "dynamic",
2381
+ currency: "USD",
2382
+ min: entry.minPrice ?? "0",
2383
+ max: entry.maxPrice ?? "0"
2384
+ }
2370
2385
  };
2371
2386
  }
2372
2387
  if ("tiers" in entry.pricing) {
@@ -2376,19 +2391,20 @@ function buildPricingInfo(entry) {
2376
2391
  if (Number.isFinite(min) && Number.isFinite(max)) {
2377
2392
  if (min === max) {
2378
2393
  return {
2379
- pricingMode: "fixed",
2380
- price: String(min)
2394
+ price: { mode: "fixed", currency: "USD", amount: String(min) }
2381
2395
  };
2382
2396
  }
2383
2397
  return {
2384
- pricingMode: "range",
2385
- minPrice: String(min),
2386
- maxPrice: String(max)
2398
+ price: { mode: "dynamic", currency: "USD", min: String(min), max: String(max) }
2387
2399
  };
2388
2400
  }
2389
2401
  return {
2390
- pricingMode: "quote",
2391
- ...entry.maxPrice ? { maxPrice: entry.maxPrice } : {}
2402
+ price: {
2403
+ mode: "dynamic",
2404
+ currency: "USD",
2405
+ min: "0",
2406
+ max: entry.maxPrice ?? "0"
2407
+ }
2392
2408
  };
2393
2409
  }
2394
2410
  return void 0;
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,
@@ -2255,7 +2262,7 @@ function deriveTag(routeKey) {
2255
2262
  return routeKey.split("/")[0].split("-").map((w) => w[0].toUpperCase() + w.slice(1)).join(" ");
2256
2263
  }
2257
2264
  function buildOperation(routeKey, entry, tag) {
2258
- const protocols = entry.protocols.length > 0 ? entry.protocols : void 0;
2265
+ const protocols = entry.protocols.length > 0 ? entry.protocols.map(toProtocolObject) : void 0;
2259
2266
  const paymentRequired = Boolean(entry.pricing) || entry.authMode === "paid";
2260
2267
  const requiresSiwxScheme = entry.authMode === "siwx" || Boolean(entry.siwxEnabled);
2261
2268
  const requiresApiKeyScheme = Boolean(entry.apiKeyResolver) && entry.authMode !== "siwx";
@@ -2315,19 +2322,27 @@ function buildOperation(routeKey, entry, tag) {
2315
2322
  requiresApiKeyScheme
2316
2323
  };
2317
2324
  }
2325
+ function toProtocolObject(protocol) {
2326
+ if (protocol === "mpp") {
2327
+ return { mpp: { method: "", intent: "", currency: "" } };
2328
+ }
2329
+ return { [protocol]: {} };
2330
+ }
2318
2331
  function buildPricingInfo(entry) {
2319
2332
  if (!entry.pricing) return void 0;
2320
2333
  if (typeof entry.pricing === "string") {
2321
2334
  return {
2322
- pricingMode: "fixed",
2323
- price: entry.pricing
2335
+ price: { mode: "fixed", currency: "USD", amount: entry.pricing }
2324
2336
  };
2325
2337
  }
2326
2338
  if (typeof entry.pricing === "function") {
2327
2339
  return {
2328
- pricingMode: "quote",
2329
- ...entry.minPrice ? { minPrice: entry.minPrice } : {},
2330
- ...entry.maxPrice ? { maxPrice: entry.maxPrice } : {}
2340
+ price: {
2341
+ mode: "dynamic",
2342
+ currency: "USD",
2343
+ min: entry.minPrice ?? "0",
2344
+ max: entry.maxPrice ?? "0"
2345
+ }
2331
2346
  };
2332
2347
  }
2333
2348
  if ("tiers" in entry.pricing) {
@@ -2337,19 +2352,20 @@ function buildPricingInfo(entry) {
2337
2352
  if (Number.isFinite(min) && Number.isFinite(max)) {
2338
2353
  if (min === max) {
2339
2354
  return {
2340
- pricingMode: "fixed",
2341
- price: String(min)
2355
+ price: { mode: "fixed", currency: "USD", amount: String(min) }
2342
2356
  };
2343
2357
  }
2344
2358
  return {
2345
- pricingMode: "range",
2346
- minPrice: String(min),
2347
- maxPrice: String(max)
2359
+ price: { mode: "dynamic", currency: "USD", min: String(min), max: String(max) }
2348
2360
  };
2349
2361
  }
2350
2362
  return {
2351
- pricingMode: "quote",
2352
- ...entry.maxPrice ? { maxPrice: entry.maxPrice } : {}
2363
+ price: {
2364
+ mode: "dynamic",
2365
+ currency: "USD",
2366
+ min: "0",
2367
+ max: entry.maxPrice ?? "0"
2368
+ }
2353
2369
  };
2354
2370
  }
2355
2371
  return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
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",