@agentcash/router 1.0.0 → 1.1.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.d.cts CHANGED
@@ -1,6 +1,7 @@
1
+ import { FacilitatorConfig } from '@x402/core/http';
1
2
  import { NextRequest, NextResponse } from 'next/server';
2
3
  import { ZodType } from 'zod';
3
- import { PaymentRequirements, PaymentRequired, SettleResponse } from '@x402/core/types';
4
+ import { PaymentRequirements, PaymentRequired, SettleResponse, Network } from '@x402/core/types';
4
5
  export { S as SIWX_ERROR_MESSAGES, a as SiwxErrorCode } from './siwx-BMlja_nt.cjs';
5
6
 
6
7
  interface EntitlementStore {
@@ -175,7 +176,7 @@ interface X402Server {
175
176
  url: string;
176
177
  method: string;
177
178
  description?: string;
178
- }, error: string | null, extensions?: Record<string, unknown>): Promise<PaymentRequired>;
179
+ }, error?: string, extensions?: Record<string, unknown>): Promise<PaymentRequired>;
179
180
  findMatchingRequirements(requirements: PaymentRequirements[], payload: unknown): PaymentRequirements;
180
181
  verifyPayment(payload: unknown, requirements: PaymentRequirements): Promise<{
181
182
  isValid: boolean;
@@ -214,12 +215,36 @@ type PricingConfig<TBody = unknown> = string | ((body: TBody) => string | Promis
214
215
  tiers: Record<string, TierConfig>;
215
216
  default?: string;
216
217
  };
218
+ type PayToConfig = string | ((request: Request) => string | Promise<string>);
219
+ interface X402AcceptBase {
220
+ network: string;
221
+ asset?: string;
222
+ decimals?: number;
223
+ maxTimeoutSeconds?: number;
224
+ extra?: Record<string, unknown>;
225
+ }
226
+ interface X402AcceptConfig extends X402AcceptBase {
227
+ scheme?: string;
228
+ payTo?: PayToConfig;
229
+ }
230
+ interface X402ResolvedAccept extends X402AcceptBase {
231
+ scheme: string;
232
+ payTo: string;
233
+ }
234
+ interface X402RouterFacilitatorConfig extends FacilitatorConfig {
235
+ createAcceptsHeaders?: () => Promise<Record<string, string>>;
236
+ }
237
+ type X402FacilitatorTarget = string | X402RouterFacilitatorConfig;
238
+ interface X402FacilitatorsConfig {
239
+ evm?: X402FacilitatorTarget;
240
+ solana?: X402FacilitatorTarget;
241
+ }
217
242
  interface PaidOptions {
218
243
  protocols?: ProtocolType[];
219
244
  maxPrice?: string;
220
245
  minPrice?: string;
221
246
  /** Override the payment recipient. String for static, function for dynamic (receives the Request). */
222
- payTo?: string | ((request: Request) => string | Promise<string>);
247
+ payTo?: PayToConfig;
223
248
  }
224
249
  interface HandlerContext<TBody = undefined, TQuery = undefined> {
225
250
  body: TBody;
@@ -274,7 +299,7 @@ interface RouteEntry {
274
299
  method: RouteMethod;
275
300
  maxPrice?: string;
276
301
  minPrice?: string;
277
- payTo?: string | ((request: Request) => string | Promise<string>);
302
+ payTo?: PayToConfig;
278
303
  apiKeyResolver?: (key: string) => unknown | Promise<unknown>;
279
304
  providerName?: string;
280
305
  providerConfig?: ProviderConfig;
@@ -296,7 +321,7 @@ interface DiscoveryConfig {
296
321
  serverUrl?: string;
297
322
  }
298
323
  interface RouterConfig {
299
- payeeAddress: string;
324
+ payeeAddress?: string;
300
325
  /**
301
326
  * Origin URL (e.g. `https://myapp.com`).
302
327
  * Used for 402 challenge realm, discovery URLs, OpenAPI servers, and MPP memo indexing.
@@ -306,7 +331,10 @@ interface RouterConfig {
306
331
  */
307
332
  baseUrl: string;
308
333
  network?: string;
309
- facilitatorUrl?: string;
334
+ x402?: {
335
+ accepts?: X402AcceptConfig[];
336
+ facilitators?: X402FacilitatorsConfig;
337
+ };
310
338
  plugin?: RouterPlugin;
311
339
  siwx?: {
312
340
  nonceStore?: NonceStore;
@@ -349,6 +377,7 @@ interface RouterConfig {
349
377
 
350
378
  declare class RouteRegistry {
351
379
  private routes;
380
+ private mapKey;
352
381
  register(entry: RouteEntry): void;
353
382
  get(key: string): RouteEntry | undefined;
354
383
  entries(): IterableIterator<[string, RouteEntry]>;
@@ -357,6 +386,14 @@ declare class RouteRegistry {
357
386
  validate(expectedKeys?: string[]): void;
358
387
  }
359
388
 
389
+ type NetworkFamily = 'evm' | 'solana';
390
+ interface ResolvedX402Facilitator {
391
+ family: NetworkFamily;
392
+ network: Network;
393
+ url?: string;
394
+ config: X402RouterFacilitatorConfig;
395
+ }
396
+
360
397
  interface OrchestrateDeps {
361
398
  x402Server: X402Server | null;
362
399
  initPromise: Promise<void>;
@@ -367,6 +404,8 @@ interface OrchestrateDeps {
367
404
  entitlementStore: EntitlementStore;
368
405
  payeeAddress: string;
369
406
  network: string;
407
+ x402FacilitatorsByNetwork?: Record<string, ResolvedX402Facilitator>;
408
+ x402Accepts: X402AcceptConfig[];
370
409
  mppx?: {
371
410
  charge: (options: {
372
411
  amount: string;
@@ -475,4 +514,4 @@ declare function createRouter<const P extends Record<string, string> = Record<ne
475
514
  prices?: P;
476
515
  }): ServiceRouter<Extract<keyof P, string>>;
477
516
 
478
- 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 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 X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
517
+ 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 };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { FacilitatorConfig } from '@x402/core/http';
1
2
  import { NextRequest, NextResponse } from 'next/server';
2
3
  import { ZodType } from 'zod';
3
- import { PaymentRequirements, PaymentRequired, SettleResponse } from '@x402/core/types';
4
+ import { PaymentRequirements, PaymentRequired, SettleResponse, Network } from '@x402/core/types';
4
5
  export { S as SIWX_ERROR_MESSAGES, a as SiwxErrorCode } from './siwx-BMlja_nt.js';
5
6
 
6
7
  interface EntitlementStore {
@@ -175,7 +176,7 @@ interface X402Server {
175
176
  url: string;
176
177
  method: string;
177
178
  description?: string;
178
- }, error: string | null, extensions?: Record<string, unknown>): Promise<PaymentRequired>;
179
+ }, error?: string, extensions?: Record<string, unknown>): Promise<PaymentRequired>;
179
180
  findMatchingRequirements(requirements: PaymentRequirements[], payload: unknown): PaymentRequirements;
180
181
  verifyPayment(payload: unknown, requirements: PaymentRequirements): Promise<{
181
182
  isValid: boolean;
@@ -214,12 +215,36 @@ type PricingConfig<TBody = unknown> = string | ((body: TBody) => string | Promis
214
215
  tiers: Record<string, TierConfig>;
215
216
  default?: string;
216
217
  };
218
+ type PayToConfig = string | ((request: Request) => string | Promise<string>);
219
+ interface X402AcceptBase {
220
+ network: string;
221
+ asset?: string;
222
+ decimals?: number;
223
+ maxTimeoutSeconds?: number;
224
+ extra?: Record<string, unknown>;
225
+ }
226
+ interface X402AcceptConfig extends X402AcceptBase {
227
+ scheme?: string;
228
+ payTo?: PayToConfig;
229
+ }
230
+ interface X402ResolvedAccept extends X402AcceptBase {
231
+ scheme: string;
232
+ payTo: string;
233
+ }
234
+ interface X402RouterFacilitatorConfig extends FacilitatorConfig {
235
+ createAcceptsHeaders?: () => Promise<Record<string, string>>;
236
+ }
237
+ type X402FacilitatorTarget = string | X402RouterFacilitatorConfig;
238
+ interface X402FacilitatorsConfig {
239
+ evm?: X402FacilitatorTarget;
240
+ solana?: X402FacilitatorTarget;
241
+ }
217
242
  interface PaidOptions {
218
243
  protocols?: ProtocolType[];
219
244
  maxPrice?: string;
220
245
  minPrice?: string;
221
246
  /** Override the payment recipient. String for static, function for dynamic (receives the Request). */
222
- payTo?: string | ((request: Request) => string | Promise<string>);
247
+ payTo?: PayToConfig;
223
248
  }
224
249
  interface HandlerContext<TBody = undefined, TQuery = undefined> {
225
250
  body: TBody;
@@ -274,7 +299,7 @@ interface RouteEntry {
274
299
  method: RouteMethod;
275
300
  maxPrice?: string;
276
301
  minPrice?: string;
277
- payTo?: string | ((request: Request) => string | Promise<string>);
302
+ payTo?: PayToConfig;
278
303
  apiKeyResolver?: (key: string) => unknown | Promise<unknown>;
279
304
  providerName?: string;
280
305
  providerConfig?: ProviderConfig;
@@ -296,7 +321,7 @@ interface DiscoveryConfig {
296
321
  serverUrl?: string;
297
322
  }
298
323
  interface RouterConfig {
299
- payeeAddress: string;
324
+ payeeAddress?: string;
300
325
  /**
301
326
  * Origin URL (e.g. `https://myapp.com`).
302
327
  * Used for 402 challenge realm, discovery URLs, OpenAPI servers, and MPP memo indexing.
@@ -306,7 +331,10 @@ interface RouterConfig {
306
331
  */
307
332
  baseUrl: string;
308
333
  network?: string;
309
- facilitatorUrl?: string;
334
+ x402?: {
335
+ accepts?: X402AcceptConfig[];
336
+ facilitators?: X402FacilitatorsConfig;
337
+ };
310
338
  plugin?: RouterPlugin;
311
339
  siwx?: {
312
340
  nonceStore?: NonceStore;
@@ -349,6 +377,7 @@ interface RouterConfig {
349
377
 
350
378
  declare class RouteRegistry {
351
379
  private routes;
380
+ private mapKey;
352
381
  register(entry: RouteEntry): void;
353
382
  get(key: string): RouteEntry | undefined;
354
383
  entries(): IterableIterator<[string, RouteEntry]>;
@@ -357,6 +386,14 @@ declare class RouteRegistry {
357
386
  validate(expectedKeys?: string[]): void;
358
387
  }
359
388
 
389
+ type NetworkFamily = 'evm' | 'solana';
390
+ interface ResolvedX402Facilitator {
391
+ family: NetworkFamily;
392
+ network: Network;
393
+ url?: string;
394
+ config: X402RouterFacilitatorConfig;
395
+ }
396
+
360
397
  interface OrchestrateDeps {
361
398
  x402Server: X402Server | null;
362
399
  initPromise: Promise<void>;
@@ -367,6 +404,8 @@ interface OrchestrateDeps {
367
404
  entitlementStore: EntitlementStore;
368
405
  payeeAddress: string;
369
406
  network: string;
407
+ x402FacilitatorsByNetwork?: Record<string, ResolvedX402Facilitator>;
408
+ x402Accepts: X402AcceptConfig[];
370
409
  mppx?: {
371
410
  charge: (options: {
372
411
  amount: string;
@@ -475,4 +514,4 @@ declare function createRouter<const P extends Record<string, string> = Record<ne
475
514
  prices?: P;
476
515
  }): ServiceRouter<Extract<keyof P, string>>;
477
516
 
478
- 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 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 X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
517
+ 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 };