@agentcash/router 1.2.6 → 1.3.1

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
@@ -258,6 +258,10 @@ async function createX402Server(config) {
258
258
  );
259
259
  if (evmNetworks.length > 0) {
260
260
  registerExactEvmScheme(server, { networks: evmNetworks });
261
+ const { UptoEvmScheme } = await import("@x402/evm/upto/server");
262
+ for (const network of evmNetworks) {
263
+ server.register(network, new UptoEvmScheme());
264
+ }
261
265
  }
262
266
  if (svmNetworks.length > 0) {
263
267
  const { registerExactSvmScheme } = await import("@x402/svm/exact/server");
@@ -287,18 +291,24 @@ function createFacilitatorClients(facilitatorsByNetwork, HTTPFacilitatorClient)
287
291
  const groups = getResolvedX402FacilitatorGroups(facilitatorsByNetwork);
288
292
  return groups.map((group) => {
289
293
  const inner = new HTTPFacilitatorClient(group.config);
290
- const kinds = group.networks.map((network) => ({
291
- x402Version: 2,
292
- scheme: "exact",
293
- network,
294
- ...group.family === "solana" ? {
295
- extra: {
296
- features: {
297
- xSettlementAccountSupported: true
294
+ const kinds = group.networks.flatMap((network) => {
295
+ const exactKind = {
296
+ x402Version: 2,
297
+ scheme: "exact",
298
+ network,
299
+ ...group.family === "solana" ? {
300
+ extra: {
301
+ features: {
302
+ xSettlementAccountSupported: true
303
+ }
298
304
  }
299
- }
300
- } : {}
301
- }));
305
+ } : {}
306
+ };
307
+ if (group.family === "evm") {
308
+ return [exactKind, { x402Version: 2, scheme: "upto", network }];
309
+ }
310
+ return [exactKind];
311
+ });
302
312
  return cachedClient(inner, kinds);
303
313
  });
304
314
  }
@@ -1913,6 +1923,8 @@ var RouteBuilder = class {
1913
1923
  _providerConfig;
1914
1924
  /** @internal */
1915
1925
  _validateFn;
1926
+ /** @internal */
1927
+ _mppInfo;
1916
1928
  constructor(key, registry, deps) {
1917
1929
  this._key = key;
1918
1930
  this._registry = registry;
@@ -1936,6 +1948,7 @@ var RouteBuilder = class {
1936
1948
  if (options?.maxPrice) next._maxPrice = options.maxPrice;
1937
1949
  if (options?.minPrice) next._minPrice = options.minPrice;
1938
1950
  if (options?.payTo) next._payTo = options.payTo;
1951
+ if (options?.mpp) next._mppInfo = options.mpp;
1939
1952
  if (typeof pricing === "object" && "tiers" in pricing) {
1940
1953
  for (const [tierKey, tierConfig] of Object.entries(pricing.tiers)) {
1941
1954
  if (!tierKey) {
@@ -2094,7 +2107,8 @@ var RouteBuilder = class {
2094
2107
  apiKeyResolver: this._apiKeyResolver,
2095
2108
  providerName: this._providerName,
2096
2109
  providerConfig: this._providerConfig,
2097
- validateFn: this._validateFn
2110
+ validateFn: this._validateFn,
2111
+ mppInfo: this._mppInfo
2098
2112
  };
2099
2113
  this._registry.register(entry);
2100
2114
  return createRequestHandler(entry, fn, this._deps);
@@ -2301,7 +2315,7 @@ function deriveTag(routeKey) {
2301
2315
  return routeKey.split("/")[0].split("-").map((w) => w[0].toUpperCase() + w.slice(1)).join(" ");
2302
2316
  }
2303
2317
  function buildOperation(routeKey, entry, tag) {
2304
- const protocols = entry.protocols.length > 0 ? entry.protocols.map(toProtocolObject) : void 0;
2318
+ const protocols = entry.protocols.length > 0 ? entry.protocols.map((p) => toProtocolObject(p, entry.mppInfo)) : void 0;
2305
2319
  const paymentRequired = Boolean(entry.pricing) || entry.authMode === "paid";
2306
2320
  const requiresSiwxScheme = entry.authMode === "siwx" || Boolean(entry.siwxEnabled);
2307
2321
  const requiresApiKeyScheme = Boolean(entry.apiKeyResolver) && entry.authMode !== "siwx";
@@ -2361,9 +2375,15 @@ function buildOperation(routeKey, entry, tag) {
2361
2375
  requiresApiKeyScheme
2362
2376
  };
2363
2377
  }
2364
- function toProtocolObject(protocol) {
2378
+ function toProtocolObject(protocol, mppInfo) {
2365
2379
  if (protocol === "mpp") {
2366
- return { mpp: { method: "", intent: "", currency: "" } };
2380
+ return {
2381
+ mpp: {
2382
+ method: mppInfo?.method ?? "tempo",
2383
+ intent: mppInfo?.intent ?? "charge",
2384
+ currency: mppInfo?.currency ?? "0x20c0000000000000000000000000000000000001"
2385
+ }
2386
+ };
2367
2387
  }
2368
2388
  return { [protocol]: {} };
2369
2389
  }
package/dist/index.d.cts CHANGED
@@ -241,12 +241,19 @@ interface X402FacilitatorsConfig {
241
241
  evm?: X402FacilitatorTarget;
242
242
  solana?: X402FacilitatorTarget;
243
243
  }
244
+ interface MppProtocolInfo {
245
+ method?: string;
246
+ intent?: string;
247
+ currency?: string;
248
+ }
244
249
  interface PaidOptions {
245
250
  protocols?: ProtocolType[];
246
251
  maxPrice?: string;
247
252
  minPrice?: string;
248
253
  /** Override the payment recipient. String for static, function for dynamic (receives the Request). */
249
254
  payTo?: PayToConfig;
255
+ /** Override MPP protocol metadata in x-payment-info discovery. */
256
+ mpp?: MppProtocolInfo;
250
257
  }
251
258
  interface HandlerContext<TBody = undefined, TQuery = undefined> {
252
259
  body: TBody;
@@ -306,6 +313,7 @@ interface RouteEntry {
306
313
  providerName?: string;
307
314
  providerConfig?: ProviderConfig;
308
315
  validateFn?: (body: unknown) => void | Promise<void>;
316
+ mppInfo?: MppProtocolInfo;
309
317
  }
310
318
  interface DiscoveryConfig {
311
319
  title: string;
@@ -481,6 +489,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, HasAuth extend
481
489
  /** @internal */ _providerName: string | undefined;
482
490
  /** @internal */ _providerConfig: ProviderConfig | undefined;
483
491
  /** @internal */ _validateFn: ((body: TBody) => void | Promise<void>) | undefined;
492
+ /** @internal */ _mppInfo: MppProtocolInfo | undefined;
484
493
  constructor(key: string, registry: RouteRegistry, deps: OrchestrateDeps);
485
494
  private fork;
486
495
  paid(pricing: string, options?: PaidOptions): RouteBuilder<TBody, TQuery, True, False, HasBody>;
@@ -553,4 +562,4 @@ declare function createRouter<const P extends Record<string, string> = Record<ne
553
562
  prices?: P;
554
563
  }): ServiceRouter<Extract<keyof P, string>>;
555
564
 
556
- export { type AlertEvent, type AlertFn, type AlertLevel, type AuthEvent, type AuthMode, type DiscoveryConfig, type EntitlementStore, type ErrorEvent, type HandlerContext, HttpError, MemoryEntitlementStore, MemoryNonceStore, type MonitorEntry, type NonceStore, type OveragePolicy, type PaidOptions, type PayToConfig, type PaymentEvent, type PluginContext, type PricingConfig, type ProtocolType, type ProviderConfig, type ProviderQuotaEvent, type QuotaInfo, type QuotaLevel, type RedisEntitlementStoreOptions, type RedisNonceStoreOptions, type RequestMeta, type ResponseMeta, RouteBuilder, type RouteEntry, RouteRegistry, type RouterConfig, type RouterPlugin, SIWX_CHALLENGE_EXPIRY_MS, type ServiceRouter, type SettlementEvent, type TierConfig, type X402AcceptConfig, type X402FacilitatorTarget, type X402FacilitatorsConfig, type X402ResolvedAccept, type X402RouterFacilitatorConfig, type X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
565
+ export { type AlertEvent, type AlertFn, type AlertLevel, type AuthEvent, type AuthMode, type DiscoveryConfig, type EntitlementStore, type ErrorEvent, type HandlerContext, HttpError, MemoryEntitlementStore, MemoryNonceStore, type MonitorEntry, type MppProtocolInfo, type NonceStore, type OveragePolicy, type PaidOptions, type PayToConfig, type PaymentEvent, type PluginContext, type PricingConfig, type ProtocolType, type ProviderConfig, type ProviderQuotaEvent, type QuotaInfo, type QuotaLevel, type RedisEntitlementStoreOptions, type RedisNonceStoreOptions, type RequestMeta, type ResponseMeta, RouteBuilder, type RouteEntry, RouteRegistry, type RouterConfig, type RouterPlugin, SIWX_CHALLENGE_EXPIRY_MS, type ServiceRouter, type SettlementEvent, type TierConfig, type X402AcceptConfig, type X402FacilitatorTarget, type X402FacilitatorsConfig, type X402ResolvedAccept, type X402RouterFacilitatorConfig, type X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
package/dist/index.d.ts CHANGED
@@ -241,12 +241,19 @@ interface X402FacilitatorsConfig {
241
241
  evm?: X402FacilitatorTarget;
242
242
  solana?: X402FacilitatorTarget;
243
243
  }
244
+ interface MppProtocolInfo {
245
+ method?: string;
246
+ intent?: string;
247
+ currency?: string;
248
+ }
244
249
  interface PaidOptions {
245
250
  protocols?: ProtocolType[];
246
251
  maxPrice?: string;
247
252
  minPrice?: string;
248
253
  /** Override the payment recipient. String for static, function for dynamic (receives the Request). */
249
254
  payTo?: PayToConfig;
255
+ /** Override MPP protocol metadata in x-payment-info discovery. */
256
+ mpp?: MppProtocolInfo;
250
257
  }
251
258
  interface HandlerContext<TBody = undefined, TQuery = undefined> {
252
259
  body: TBody;
@@ -306,6 +313,7 @@ interface RouteEntry {
306
313
  providerName?: string;
307
314
  providerConfig?: ProviderConfig;
308
315
  validateFn?: (body: unknown) => void | Promise<void>;
316
+ mppInfo?: MppProtocolInfo;
309
317
  }
310
318
  interface DiscoveryConfig {
311
319
  title: string;
@@ -481,6 +489,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, HasAuth extend
481
489
  /** @internal */ _providerName: string | undefined;
482
490
  /** @internal */ _providerConfig: ProviderConfig | undefined;
483
491
  /** @internal */ _validateFn: ((body: TBody) => void | Promise<void>) | undefined;
492
+ /** @internal */ _mppInfo: MppProtocolInfo | undefined;
484
493
  constructor(key: string, registry: RouteRegistry, deps: OrchestrateDeps);
485
494
  private fork;
486
495
  paid(pricing: string, options?: PaidOptions): RouteBuilder<TBody, TQuery, True, False, HasBody>;
@@ -553,4 +562,4 @@ declare function createRouter<const P extends Record<string, string> = Record<ne
553
562
  prices?: P;
554
563
  }): ServiceRouter<Extract<keyof P, string>>;
555
564
 
556
- export { type AlertEvent, type AlertFn, type AlertLevel, type AuthEvent, type AuthMode, type DiscoveryConfig, type EntitlementStore, type ErrorEvent, type HandlerContext, HttpError, MemoryEntitlementStore, MemoryNonceStore, type MonitorEntry, type NonceStore, type OveragePolicy, type PaidOptions, type PayToConfig, type PaymentEvent, type PluginContext, type PricingConfig, type ProtocolType, type ProviderConfig, type ProviderQuotaEvent, type QuotaInfo, type QuotaLevel, type RedisEntitlementStoreOptions, type RedisNonceStoreOptions, type RequestMeta, type ResponseMeta, RouteBuilder, type RouteEntry, RouteRegistry, type RouterConfig, type RouterPlugin, SIWX_CHALLENGE_EXPIRY_MS, type ServiceRouter, type SettlementEvent, type TierConfig, type X402AcceptConfig, type X402FacilitatorTarget, type X402FacilitatorsConfig, type X402ResolvedAccept, type X402RouterFacilitatorConfig, type X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
565
+ export { type AlertEvent, type AlertFn, type AlertLevel, type AuthEvent, type AuthMode, type DiscoveryConfig, type EntitlementStore, type ErrorEvent, type HandlerContext, HttpError, MemoryEntitlementStore, MemoryNonceStore, type MonitorEntry, type MppProtocolInfo, type NonceStore, type OveragePolicy, type PaidOptions, type PayToConfig, type PaymentEvent, type PluginContext, type PricingConfig, type ProtocolType, type ProviderConfig, type ProviderQuotaEvent, type QuotaInfo, type QuotaLevel, type RedisEntitlementStoreOptions, type RedisNonceStoreOptions, type RequestMeta, type ResponseMeta, RouteBuilder, type RouteEntry, RouteRegistry, type RouterConfig, type RouterPlugin, SIWX_CHALLENGE_EXPIRY_MS, type ServiceRouter, type SettlementEvent, type TierConfig, type X402AcceptConfig, type X402FacilitatorTarget, type X402FacilitatorsConfig, type X402ResolvedAccept, type X402RouterFacilitatorConfig, type X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
package/dist/index.js CHANGED
@@ -236,6 +236,10 @@ async function createX402Server(config) {
236
236
  );
237
237
  if (evmNetworks.length > 0) {
238
238
  registerExactEvmScheme(server, { networks: evmNetworks });
239
+ const { UptoEvmScheme } = await import("@x402/evm/upto/server");
240
+ for (const network of evmNetworks) {
241
+ server.register(network, new UptoEvmScheme());
242
+ }
239
243
  }
240
244
  if (svmNetworks.length > 0) {
241
245
  const { registerExactSvmScheme } = await import("@x402/svm/exact/server");
@@ -265,18 +269,24 @@ function createFacilitatorClients(facilitatorsByNetwork, HTTPFacilitatorClient)
265
269
  const groups = getResolvedX402FacilitatorGroups(facilitatorsByNetwork);
266
270
  return groups.map((group) => {
267
271
  const inner = new HTTPFacilitatorClient(group.config);
268
- const kinds = group.networks.map((network) => ({
269
- x402Version: 2,
270
- scheme: "exact",
271
- network,
272
- ...group.family === "solana" ? {
273
- extra: {
274
- features: {
275
- xSettlementAccountSupported: true
272
+ const kinds = group.networks.flatMap((network) => {
273
+ const exactKind = {
274
+ x402Version: 2,
275
+ scheme: "exact",
276
+ network,
277
+ ...group.family === "solana" ? {
278
+ extra: {
279
+ features: {
280
+ xSettlementAccountSupported: true
281
+ }
276
282
  }
277
- }
278
- } : {}
279
- }));
283
+ } : {}
284
+ };
285
+ if (group.family === "evm") {
286
+ return [exactKind, { x402Version: 2, scheme: "upto", network }];
287
+ }
288
+ return [exactKind];
289
+ });
280
290
  return cachedClient(inner, kinds);
281
291
  });
282
292
  }
@@ -1874,6 +1884,8 @@ var RouteBuilder = class {
1874
1884
  _providerConfig;
1875
1885
  /** @internal */
1876
1886
  _validateFn;
1887
+ /** @internal */
1888
+ _mppInfo;
1877
1889
  constructor(key, registry, deps) {
1878
1890
  this._key = key;
1879
1891
  this._registry = registry;
@@ -1897,6 +1909,7 @@ var RouteBuilder = class {
1897
1909
  if (options?.maxPrice) next._maxPrice = options.maxPrice;
1898
1910
  if (options?.minPrice) next._minPrice = options.minPrice;
1899
1911
  if (options?.payTo) next._payTo = options.payTo;
1912
+ if (options?.mpp) next._mppInfo = options.mpp;
1900
1913
  if (typeof pricing === "object" && "tiers" in pricing) {
1901
1914
  for (const [tierKey, tierConfig] of Object.entries(pricing.tiers)) {
1902
1915
  if (!tierKey) {
@@ -2055,7 +2068,8 @@ var RouteBuilder = class {
2055
2068
  apiKeyResolver: this._apiKeyResolver,
2056
2069
  providerName: this._providerName,
2057
2070
  providerConfig: this._providerConfig,
2058
- validateFn: this._validateFn
2071
+ validateFn: this._validateFn,
2072
+ mppInfo: this._mppInfo
2059
2073
  };
2060
2074
  this._registry.register(entry);
2061
2075
  return createRequestHandler(entry, fn, this._deps);
@@ -2262,7 +2276,7 @@ function deriveTag(routeKey) {
2262
2276
  return routeKey.split("/")[0].split("-").map((w) => w[0].toUpperCase() + w.slice(1)).join(" ");
2263
2277
  }
2264
2278
  function buildOperation(routeKey, entry, tag) {
2265
- const protocols = entry.protocols.length > 0 ? entry.protocols.map(toProtocolObject) : void 0;
2279
+ const protocols = entry.protocols.length > 0 ? entry.protocols.map((p) => toProtocolObject(p, entry.mppInfo)) : void 0;
2266
2280
  const paymentRequired = Boolean(entry.pricing) || entry.authMode === "paid";
2267
2281
  const requiresSiwxScheme = entry.authMode === "siwx" || Boolean(entry.siwxEnabled);
2268
2282
  const requiresApiKeyScheme = Boolean(entry.apiKeyResolver) && entry.authMode !== "siwx";
@@ -2322,9 +2336,15 @@ function buildOperation(routeKey, entry, tag) {
2322
2336
  requiresApiKeyScheme
2323
2337
  };
2324
2338
  }
2325
- function toProtocolObject(protocol) {
2339
+ function toProtocolObject(protocol, mppInfo) {
2326
2340
  if (protocol === "mpp") {
2327
- return { mpp: { method: "", intent: "", currency: "" } };
2341
+ return {
2342
+ mpp: {
2343
+ method: mppInfo?.method ?? "tempo",
2344
+ intent: mppInfo?.intent ?? "charge",
2345
+ currency: mppInfo?.currency ?? "0x20c0000000000000000000000000000000000001"
2346
+ }
2347
+ };
2328
2348
  }
2329
2349
  return { [protocol]: {} };
2330
2350
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "1.2.6",
3
+ "version": "1.3.1",
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": {
@@ -25,11 +25,11 @@
25
25
  ],
26
26
  "peerDependencies": {
27
27
  "@coinbase/x402": "^2.1.0",
28
- "@x402/core": "^2.3.0",
29
- "@x402/evm": "^2.3.0",
30
- "@x402/extensions": "^2.3.0",
31
- "@x402/svm": "2.3.0",
32
- "mppx": "^0.4.11",
28
+ "@x402/core": "^2.9.0",
29
+ "@x402/evm": "^2.9.0",
30
+ "@x402/extensions": "^2.9.0",
31
+ "@x402/svm": "^2.9.0",
32
+ "mppx": "^0.5.10",
33
33
  "next": ">=15.0.0",
34
34
  "zod": "^4.0.0",
35
35
  "zod-openapi": "^5.0.0"
@@ -56,12 +56,12 @@
56
56
  "@solana/spl-token": "^0.4.14",
57
57
  "@solana/web3.js": "^1.98.4",
58
58
  "@types/node": "^22.0.0",
59
- "@x402/core": "^2.3.0",
60
- "@x402/evm": "^2.3.0",
61
- "@x402/extensions": "^2.3.0",
62
- "@x402/svm": "2.3.0",
59
+ "@x402/core": "^2.9.0",
60
+ "@x402/evm": "^2.9.0",
61
+ "@x402/extensions": "^2.9.0",
62
+ "@x402/svm": "^2.9.0",
63
63
  "eslint": "^10.0.0",
64
- "mppx": "^0.4.11",
64
+ "mppx": "^0.5.10",
65
65
  "next": "^15.0.0",
66
66
  "prettier": "^3.8.1",
67
67
  "react": "^19.0.0",