@agentcash/router 1.2.5 → 1.3.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/dist/index.cjs CHANGED
@@ -1913,6 +1913,8 @@ var RouteBuilder = class {
1913
1913
  _providerConfig;
1914
1914
  /** @internal */
1915
1915
  _validateFn;
1916
+ /** @internal */
1917
+ _mppInfo;
1916
1918
  constructor(key, registry, deps) {
1917
1919
  this._key = key;
1918
1920
  this._registry = registry;
@@ -1936,6 +1938,7 @@ var RouteBuilder = class {
1936
1938
  if (options?.maxPrice) next._maxPrice = options.maxPrice;
1937
1939
  if (options?.minPrice) next._minPrice = options.minPrice;
1938
1940
  if (options?.payTo) next._payTo = options.payTo;
1941
+ if (options?.mpp) next._mppInfo = options.mpp;
1939
1942
  if (typeof pricing === "object" && "tiers" in pricing) {
1940
1943
  for (const [tierKey, tierConfig] of Object.entries(pricing.tiers)) {
1941
1944
  if (!tierKey) {
@@ -2094,7 +2097,8 @@ var RouteBuilder = class {
2094
2097
  apiKeyResolver: this._apiKeyResolver,
2095
2098
  providerName: this._providerName,
2096
2099
  providerConfig: this._providerConfig,
2097
- validateFn: this._validateFn
2100
+ validateFn: this._validateFn,
2101
+ mppInfo: this._mppInfo
2098
2102
  };
2099
2103
  this._registry.register(entry);
2100
2104
  return createRequestHandler(entry, fn, this._deps);
@@ -2301,7 +2305,7 @@ function deriveTag(routeKey) {
2301
2305
  return routeKey.split("/")[0].split("-").map((w) => w[0].toUpperCase() + w.slice(1)).join(" ");
2302
2306
  }
2303
2307
  function buildOperation(routeKey, entry, tag) {
2304
- const protocols = entry.protocols.length > 0 ? entry.protocols : void 0;
2308
+ const protocols = entry.protocols.length > 0 ? entry.protocols.map((p) => toProtocolObject(p, entry.mppInfo)) : void 0;
2305
2309
  const paymentRequired = Boolean(entry.pricing) || entry.authMode === "paid";
2306
2310
  const requiresSiwxScheme = entry.authMode === "siwx" || Boolean(entry.siwxEnabled);
2307
2311
  const requiresApiKeyScheme = Boolean(entry.apiKeyResolver) && entry.authMode !== "siwx";
@@ -2361,19 +2365,33 @@ function buildOperation(routeKey, entry, tag) {
2361
2365
  requiresApiKeyScheme
2362
2366
  };
2363
2367
  }
2368
+ function toProtocolObject(protocol, mppInfo) {
2369
+ if (protocol === "mpp") {
2370
+ return {
2371
+ mpp: {
2372
+ method: mppInfo?.method ?? "tempo",
2373
+ intent: mppInfo?.intent ?? "charge",
2374
+ currency: mppInfo?.currency ?? "0x20c0000000000000000000000000000000000001"
2375
+ }
2376
+ };
2377
+ }
2378
+ return { [protocol]: {} };
2379
+ }
2364
2380
  function buildPricingInfo(entry) {
2365
2381
  if (!entry.pricing) return void 0;
2366
2382
  if (typeof entry.pricing === "string") {
2367
2383
  return {
2368
- pricingMode: "fixed",
2369
- price: entry.pricing
2384
+ price: { mode: "fixed", currency: "USD", amount: entry.pricing }
2370
2385
  };
2371
2386
  }
2372
2387
  if (typeof entry.pricing === "function") {
2373
2388
  return {
2374
- pricingMode: "quote",
2375
- ...entry.minPrice ? { minPrice: entry.minPrice } : {},
2376
- ...entry.maxPrice ? { maxPrice: entry.maxPrice } : {}
2389
+ price: {
2390
+ mode: "dynamic",
2391
+ currency: "USD",
2392
+ min: entry.minPrice ?? "0",
2393
+ max: entry.maxPrice ?? "0"
2394
+ }
2377
2395
  };
2378
2396
  }
2379
2397
  if ("tiers" in entry.pricing) {
@@ -2383,19 +2401,20 @@ function buildPricingInfo(entry) {
2383
2401
  if (Number.isFinite(min) && Number.isFinite(max)) {
2384
2402
  if (min === max) {
2385
2403
  return {
2386
- pricingMode: "fixed",
2387
- price: String(min)
2404
+ price: { mode: "fixed", currency: "USD", amount: String(min) }
2388
2405
  };
2389
2406
  }
2390
2407
  return {
2391
- pricingMode: "range",
2392
- minPrice: String(min),
2393
- maxPrice: String(max)
2408
+ price: { mode: "dynamic", currency: "USD", min: String(min), max: String(max) }
2394
2409
  };
2395
2410
  }
2396
2411
  return {
2397
- pricingMode: "quote",
2398
- ...entry.maxPrice ? { maxPrice: entry.maxPrice } : {}
2412
+ price: {
2413
+ mode: "dynamic",
2414
+ currency: "USD",
2415
+ min: "0",
2416
+ max: entry.maxPrice ?? "0"
2417
+ }
2399
2418
  };
2400
2419
  }
2401
2420
  return void 0;
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
@@ -1874,6 +1874,8 @@ var RouteBuilder = class {
1874
1874
  _providerConfig;
1875
1875
  /** @internal */
1876
1876
  _validateFn;
1877
+ /** @internal */
1878
+ _mppInfo;
1877
1879
  constructor(key, registry, deps) {
1878
1880
  this._key = key;
1879
1881
  this._registry = registry;
@@ -1897,6 +1899,7 @@ var RouteBuilder = class {
1897
1899
  if (options?.maxPrice) next._maxPrice = options.maxPrice;
1898
1900
  if (options?.minPrice) next._minPrice = options.minPrice;
1899
1901
  if (options?.payTo) next._payTo = options.payTo;
1902
+ if (options?.mpp) next._mppInfo = options.mpp;
1900
1903
  if (typeof pricing === "object" && "tiers" in pricing) {
1901
1904
  for (const [tierKey, tierConfig] of Object.entries(pricing.tiers)) {
1902
1905
  if (!tierKey) {
@@ -2055,7 +2058,8 @@ var RouteBuilder = class {
2055
2058
  apiKeyResolver: this._apiKeyResolver,
2056
2059
  providerName: this._providerName,
2057
2060
  providerConfig: this._providerConfig,
2058
- validateFn: this._validateFn
2061
+ validateFn: this._validateFn,
2062
+ mppInfo: this._mppInfo
2059
2063
  };
2060
2064
  this._registry.register(entry);
2061
2065
  return createRequestHandler(entry, fn, this._deps);
@@ -2262,7 +2266,7 @@ function deriveTag(routeKey) {
2262
2266
  return routeKey.split("/")[0].split("-").map((w) => w[0].toUpperCase() + w.slice(1)).join(" ");
2263
2267
  }
2264
2268
  function buildOperation(routeKey, entry, tag) {
2265
- const protocols = entry.protocols.length > 0 ? entry.protocols : void 0;
2269
+ const protocols = entry.protocols.length > 0 ? entry.protocols.map((p) => toProtocolObject(p, entry.mppInfo)) : void 0;
2266
2270
  const paymentRequired = Boolean(entry.pricing) || entry.authMode === "paid";
2267
2271
  const requiresSiwxScheme = entry.authMode === "siwx" || Boolean(entry.siwxEnabled);
2268
2272
  const requiresApiKeyScheme = Boolean(entry.apiKeyResolver) && entry.authMode !== "siwx";
@@ -2322,19 +2326,33 @@ function buildOperation(routeKey, entry, tag) {
2322
2326
  requiresApiKeyScheme
2323
2327
  };
2324
2328
  }
2329
+ function toProtocolObject(protocol, mppInfo) {
2330
+ if (protocol === "mpp") {
2331
+ return {
2332
+ mpp: {
2333
+ method: mppInfo?.method ?? "tempo",
2334
+ intent: mppInfo?.intent ?? "charge",
2335
+ currency: mppInfo?.currency ?? "0x20c0000000000000000000000000000000000001"
2336
+ }
2337
+ };
2338
+ }
2339
+ return { [protocol]: {} };
2340
+ }
2325
2341
  function buildPricingInfo(entry) {
2326
2342
  if (!entry.pricing) return void 0;
2327
2343
  if (typeof entry.pricing === "string") {
2328
2344
  return {
2329
- pricingMode: "fixed",
2330
- price: entry.pricing
2345
+ price: { mode: "fixed", currency: "USD", amount: entry.pricing }
2331
2346
  };
2332
2347
  }
2333
2348
  if (typeof entry.pricing === "function") {
2334
2349
  return {
2335
- pricingMode: "quote",
2336
- ...entry.minPrice ? { minPrice: entry.minPrice } : {},
2337
- ...entry.maxPrice ? { maxPrice: entry.maxPrice } : {}
2350
+ price: {
2351
+ mode: "dynamic",
2352
+ currency: "USD",
2353
+ min: entry.minPrice ?? "0",
2354
+ max: entry.maxPrice ?? "0"
2355
+ }
2338
2356
  };
2339
2357
  }
2340
2358
  if ("tiers" in entry.pricing) {
@@ -2344,19 +2362,20 @@ function buildPricingInfo(entry) {
2344
2362
  if (Number.isFinite(min) && Number.isFinite(max)) {
2345
2363
  if (min === max) {
2346
2364
  return {
2347
- pricingMode: "fixed",
2348
- price: String(min)
2365
+ price: { mode: "fixed", currency: "USD", amount: String(min) }
2349
2366
  };
2350
2367
  }
2351
2368
  return {
2352
- pricingMode: "range",
2353
- minPrice: String(min),
2354
- maxPrice: String(max)
2369
+ price: { mode: "dynamic", currency: "USD", min: String(min), max: String(max) }
2355
2370
  };
2356
2371
  }
2357
2372
  return {
2358
- pricingMode: "quote",
2359
- ...entry.maxPrice ? { maxPrice: entry.maxPrice } : {}
2373
+ price: {
2374
+ mode: "dynamic",
2375
+ currency: "USD",
2376
+ min: "0",
2377
+ max: entry.maxPrice ?? "0"
2378
+ }
2360
2379
  };
2361
2380
  }
2362
2381
  return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "1.2.5",
3
+ "version": "1.3.0",
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": {