@agentcash/router 1.2.6 → 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.map(toProtocolObject) : 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,9 +2365,15 @@ function buildOperation(routeKey, entry, tag) {
2361
2365
  requiresApiKeyScheme
2362
2366
  };
2363
2367
  }
2364
- function toProtocolObject(protocol) {
2368
+ function toProtocolObject(protocol, mppInfo) {
2365
2369
  if (protocol === "mpp") {
2366
- return { mpp: { method: "", intent: "", currency: "" } };
2370
+ return {
2371
+ mpp: {
2372
+ method: mppInfo?.method ?? "tempo",
2373
+ intent: mppInfo?.intent ?? "charge",
2374
+ currency: mppInfo?.currency ?? "0x20c0000000000000000000000000000000000001"
2375
+ }
2376
+ };
2367
2377
  }
2368
2378
  return { [protocol]: {} };
2369
2379
  }
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.map(toProtocolObject) : 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,9 +2326,15 @@ function buildOperation(routeKey, entry, tag) {
2322
2326
  requiresApiKeyScheme
2323
2327
  };
2324
2328
  }
2325
- function toProtocolObject(protocol) {
2329
+ function toProtocolObject(protocol, mppInfo) {
2326
2330
  if (protocol === "mpp") {
2327
- return { mpp: { method: "", intent: "", currency: "" } };
2331
+ return {
2332
+ mpp: {
2333
+ method: mppInfo?.method ?? "tempo",
2334
+ intent: mppInfo?.intent ?? "charge",
2335
+ currency: mppInfo?.currency ?? "0x20c0000000000000000000000000000000000001"
2336
+ }
2337
+ };
2328
2338
  }
2329
2339
  return { [protocol]: {} };
2330
2340
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentcash/router",
3
- "version": "1.2.6",
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": {