@moneymq/sdk 0.3.1 → 0.5.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.ts CHANGED
@@ -1,3 +1,40 @@
1
+ import { Signer } from 'x402-fetch';
2
+ export { Signer } from 'x402-fetch';
3
+
4
+ /** Payment requirements returned when payment is required (402) */
5
+ interface PaymentRequirements {
6
+ scheme: string;
7
+ network: string;
8
+ max_amount_required: string;
9
+ resource: string;
10
+ description: string;
11
+ mime_type: string;
12
+ pay_to: string;
13
+ max_timeout_seconds: number;
14
+ asset: string;
15
+ extra?: {
16
+ feePayer?: string;
17
+ product?: string;
18
+ };
19
+ }
20
+ /** Error thrown when payment is required to access a resource */
21
+ declare class PaymentRequiredError extends Error {
22
+ readonly paymentRequirements: PaymentRequirements[];
23
+ readonly raw: unknown;
24
+ constructor(message: string, paymentRequirements: PaymentRequirements[], raw: unknown);
25
+ }
26
+ /** Response from product access endpoint */
27
+ interface ProductAccessResponse {
28
+ object: 'product_access';
29
+ product_id: string;
30
+ access_granted: boolean;
31
+ message: string;
32
+ }
33
+ /** Parameters for accessing a product with x402 payment */
34
+ interface ProductAccessParams {
35
+ /** Base64-encoded X-Payment header value */
36
+ paymentHeader?: string;
37
+ }
1
38
  interface Product {
2
39
  id: string;
3
40
  object: 'product';
@@ -7,6 +44,8 @@ interface Product {
7
44
  metadata?: Record<string, string>;
8
45
  created: number;
9
46
  updated: number;
47
+ /** URL path for accessing this product (x402 gated) */
48
+ accessUrl: string;
10
49
  }
11
50
  interface ProductCreateParams {
12
51
  name: string;
@@ -74,6 +113,32 @@ declare class ProductsAPI {
74
113
  delete(id: string): Promise<{
75
114
  deleted: boolean;
76
115
  }>;
116
+ /**
117
+ * Access a product - gated by x402 payment
118
+ *
119
+ * This endpoint requires payment. If no payment header is provided (or payment is invalid),
120
+ * throws a PaymentRequiredError with the payment requirements.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * try {
125
+ * // First attempt without payment - will throw PaymentRequiredError
126
+ * const access = await moneymq.catalog.products.access('surfnet-max');
127
+ * } catch (error) {
128
+ * if (error instanceof PaymentRequiredError) {
129
+ * // Get payment requirements and create payment
130
+ * const requirements = error.paymentRequirements[0];
131
+ * const paymentHeader = await createPayment(requirements);
132
+ *
133
+ * // Retry with payment
134
+ * const access = await moneymq.catalog.products.access('surfnet-max', {
135
+ * paymentHeader,
136
+ * });
137
+ * }
138
+ * }
139
+ * ```
140
+ */
141
+ access(id: string, params?: ProductAccessParams): Promise<ProductAccessResponse>;
77
142
  }
78
143
  declare class PricesAPI {
79
144
  private config;
@@ -167,6 +232,60 @@ interface PaymentListParams {
167
232
  limit?: number;
168
233
  startingAfter?: string;
169
234
  }
235
+ interface PayParams {
236
+ /** Amount in smallest currency unit (e.g., cents for USD) */
237
+ amount: number;
238
+ /** Currency code (e.g., 'usd', 'usdc') */
239
+ currency: string;
240
+ /** Product name for display */
241
+ productName: string;
242
+ /** Product ID for tracking */
243
+ productId?: string;
244
+ /** Optional product description */
245
+ description?: string;
246
+ /** Customer wallet address */
247
+ customer?: string;
248
+ /** Additional metadata */
249
+ metadata?: Record<string, string>;
250
+ }
251
+ interface PayResult {
252
+ /** Checkout session ID */
253
+ sessionId: string;
254
+ /** Payment intent ID */
255
+ paymentIntentId: string;
256
+ /** Client secret for confirming payment */
257
+ clientSecret: string;
258
+ /** Total amount in smallest currency unit */
259
+ amount: number;
260
+ /** Currency */
261
+ currency: string;
262
+ /** Status */
263
+ status: 'requires_confirmation' | 'succeeded' | 'failed';
264
+ }
265
+ interface PaymentIntent {
266
+ id: string;
267
+ object: 'payment_intent';
268
+ amount: number;
269
+ currency: string;
270
+ status: 'requires_payment_method' | 'requires_confirmation' | 'processing' | 'succeeded' | 'canceled';
271
+ customer?: string;
272
+ description?: string;
273
+ metadata: Record<string, string>;
274
+ clientSecret?: string;
275
+ created: number;
276
+ }
277
+ interface PaymentIntentCreateParams {
278
+ /** Amount in smallest currency unit */
279
+ amount: number;
280
+ /** Currency code */
281
+ currency: string;
282
+ /** Customer wallet address */
283
+ customer?: string;
284
+ /** Description */
285
+ description?: string;
286
+ /** Metadata including product info */
287
+ metadata?: Record<string, string>;
288
+ }
170
289
  interface Customer {
171
290
  id: string;
172
291
  object: 'customer';
@@ -319,13 +438,41 @@ declare class WebhooksAPI {
319
438
  success: boolean;
320
439
  }>;
321
440
  }
441
+ /**
442
+ * Payment Intents API - for direct payments without full checkout flow
443
+ * Similar to Stripe's Payment Intents API
444
+ */
445
+ declare class PaymentIntentsAPI {
446
+ private request;
447
+ constructor(config: MoneyMQConfig);
448
+ /**
449
+ * Create a payment intent
450
+ * Use this for simple payments without the full checkout session flow
451
+ */
452
+ create(params: PaymentIntentCreateParams): Promise<PaymentIntent>;
453
+ /**
454
+ * Retrieve a payment intent
455
+ */
456
+ retrieve(id: string): Promise<PaymentIntent>;
457
+ /**
458
+ * Confirm a payment intent
459
+ * This triggers the actual payment (and x402 flow if required)
460
+ */
461
+ confirm(id: string): Promise<PaymentIntent>;
462
+ /**
463
+ * Cancel a payment intent
464
+ */
465
+ cancel(id: string): Promise<PaymentIntent>;
466
+ }
322
467
  /**
323
468
  * Payment API for checkout, links, customers, and payouts
324
469
  */
325
470
  declare class PaymentAPI {
326
471
  private request;
327
- /** Checkout sessions API */
472
+ /** Checkout sessions API - for full e-commerce flows with line items */
328
473
  readonly checkout: CheckoutAPI;
474
+ /** Payment intents API - for simpler direct payments */
475
+ readonly intents: PaymentIntentsAPI;
329
476
  /** Payment links API */
330
477
  readonly links: LinksAPI;
331
478
  /** Customers API */
@@ -335,6 +482,21 @@ declare class PaymentAPI {
335
482
  /** Webhooks API */
336
483
  readonly webhooks: WebhooksAPI;
337
484
  constructor(config: MoneyMQConfig);
485
+ /**
486
+ * Simple one-liner payment - creates a checkout session with inline product data
487
+ *
488
+ * @example
489
+ * ```ts
490
+ * const result = await moneymq.payment.pay({
491
+ * amount: 999,
492
+ * currency: 'usd',
493
+ * productName: 'Pro Plan',
494
+ * productId: 'pro-plan',
495
+ * customer: 'wallet_address',
496
+ * });
497
+ * ```
498
+ */
499
+ pay(params: PayParams): Promise<PayResult>;
338
500
  /**
339
501
  * Retrieve a payment by ID
340
502
  */
@@ -348,6 +510,154 @@ declare class PaymentAPI {
348
510
  }>;
349
511
  }
350
512
 
513
+ /**
514
+ * MoneyMQ server configuration returned from /config endpoint
515
+ */
516
+ interface ServerConfig {
517
+ account: {
518
+ name: string;
519
+ description: string;
520
+ };
521
+ x402: {
522
+ payoutAccount: {
523
+ currency: string;
524
+ decimals: number;
525
+ address: string;
526
+ tokenAddress: string;
527
+ };
528
+ facilitator: {
529
+ operatorAccount: {
530
+ out: string;
531
+ in: {
532
+ currency: string;
533
+ decimals: number;
534
+ address: string;
535
+ tokenAddress: string;
536
+ };
537
+ };
538
+ url: string;
539
+ };
540
+ validator: {
541
+ network: string;
542
+ rpcUrl: string;
543
+ bindHost: string;
544
+ rpcPort: number;
545
+ wsPort: number;
546
+ };
547
+ };
548
+ }
549
+ /**
550
+ * Fetch server configuration from MoneyMQ API
551
+ *
552
+ * @param apiUrl - The MoneyMQ API URL
553
+ * @returns Server configuration including RPC URL
554
+ *
555
+ * @example
556
+ * ```typescript
557
+ * const config = await fetchConfig('http://localhost:8488');
558
+ * console.log(config.x402.validator.rpcUrl);
559
+ * ```
560
+ */
561
+ declare function fetchConfig(apiUrl: string): Promise<ServerConfig>;
562
+ /**
563
+ * Get the Solana RPC URL from server config
564
+ *
565
+ * @param apiUrl - The MoneyMQ API URL
566
+ * @param fallback - Fallback RPC URL if fetch fails
567
+ * @returns RPC URL string
568
+ */
569
+ declare function getRpcUrl(apiUrl: string, fallback?: string): Promise<string>;
570
+
571
+ /**
572
+ * Parameters for getting a signer by tag
573
+ */
574
+ interface GetSignerParams {
575
+ /**
576
+ * Tag/label identifying the sandbox wallet account
577
+ * @example 'alice', 'bob', 'agent-1'
578
+ */
579
+ tag: string;
580
+ }
581
+
582
+ /**
583
+ * X402 configuration compatible with x402-fetch wrapFetchWithPayment
584
+ */
585
+ interface X402ClientConfig {
586
+ svmConfig?: {
587
+ rpcUrl: string;
588
+ };
589
+ }
590
+ /**
591
+ * X402 API for agentic payments
592
+ *
593
+ * @example
594
+ * ```typescript
595
+ * import { wrapFetchWithPayment } from 'x402-fetch';
596
+ *
597
+ * const moneymq = new MoneyMQ({
598
+ * endpoint: 'http://localhost:8488',
599
+ * });
600
+ *
601
+ * // Get signer for sandbox account by label
602
+ * const payer = await moneymq.x402.getSigner({ tag: 'alice' });
603
+ *
604
+ * // Get x402 config for the fetch wrapper
605
+ * const config = await moneymq.x402.getConfig();
606
+ *
607
+ * // Create the payment-enabled fetch
608
+ * const fetchWithPayment = wrapFetchWithPayment(
609
+ * fetch,
610
+ * payer,
611
+ * undefined,
612
+ * undefined,
613
+ * config,
614
+ * );
615
+ *
616
+ * // Make requests that automatically handle 402 payments
617
+ * const response = await fetchWithPayment(url, { method: 'GET' });
618
+ * ```
619
+ */
620
+ declare class X402API {
621
+ private config;
622
+ private serverConfig;
623
+ private sandboxAccounts;
624
+ constructor(config: MoneyMQConfig);
625
+ /**
626
+ * Fetch sandbox accounts from the server
627
+ */
628
+ private fetchSandboxAccounts;
629
+ /**
630
+ * Get a signer for a sandbox account by tag/label
631
+ *
632
+ * @param params - Parameters containing the wallet tag/label
633
+ * @returns A Signer that can be used directly with wrapFetchWithPayment
634
+ *
635
+ * @example
636
+ * ```typescript
637
+ * const payer = await moneymq.x402.getSigner({ tag: 'alice' });
638
+ * ```
639
+ */
640
+ getSigner(params: GetSignerParams): Promise<Signer>;
641
+ /**
642
+ * Get x402 configuration for use with wrapFetchWithPayment
643
+ *
644
+ * @returns Configuration object compatible with x402-fetch
645
+ *
646
+ * @example
647
+ * ```typescript
648
+ * const config = await moneymq.x402.getConfig();
649
+ * const fetchWithPayment = wrapFetchWithPayment(fetch, payer, undefined, undefined, config);
650
+ * ```
651
+ */
652
+ getConfig(): Promise<X402ClientConfig>;
653
+ /**
654
+ * Get the full server configuration
655
+ *
656
+ * @returns The complete server configuration including x402 settings
657
+ */
658
+ getServerConfig(): Promise<ServerConfig>;
659
+ }
660
+
351
661
  /**
352
662
  * Configuration options for the MoneyMQ client
353
663
  *
@@ -408,6 +718,10 @@ declare class MoneyMQ {
408
718
  readonly catalog: CatalogAPI;
409
719
  /** Payment API for checkout, links, customers, and payouts */
410
720
  readonly payment: PaymentAPI;
721
+ /** X402 API for agentic payments */
722
+ readonly x402: X402API;
723
+ /** MoneyMQ API endpoint */
724
+ get endpoint(): string;
411
725
  constructor(config: MoneyMQConfig);
412
726
  /**
413
727
  * Make an authenticated request to the MoneyMQ API
@@ -415,62 +729,4 @@ declare class MoneyMQ {
415
729
  request<T>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: unknown): Promise<T>;
416
730
  }
417
731
 
418
- /**
419
- * MoneyMQ server configuration returned from /config endpoint
420
- */
421
- interface ServerConfig {
422
- account: {
423
- name: string;
424
- description: string;
425
- };
426
- x402: {
427
- payoutAccount: {
428
- currency: string;
429
- decimals: number;
430
- address: string;
431
- tokenAddress: string;
432
- };
433
- facilitator: {
434
- operatorAccount: {
435
- out: string;
436
- in: {
437
- currency: string;
438
- decimals: number;
439
- address: string;
440
- tokenAddress: string;
441
- };
442
- };
443
- url: string;
444
- };
445
- validator: {
446
- network: string;
447
- rpcUrl: string;
448
- bindHost: string;
449
- rpcPort: number;
450
- wsPort: number;
451
- };
452
- };
453
- }
454
- /**
455
- * Fetch server configuration from MoneyMQ API
456
- *
457
- * @param apiUrl - The MoneyMQ API URL
458
- * @returns Server configuration including RPC URL
459
- *
460
- * @example
461
- * ```typescript
462
- * const config = await fetchConfig('http://localhost:8488');
463
- * console.log(config.x402.validator.rpcUrl);
464
- * ```
465
- */
466
- declare function fetchConfig(apiUrl: string): Promise<ServerConfig>;
467
- /**
468
- * Get the Solana RPC URL from server config
469
- *
470
- * @param apiUrl - The MoneyMQ API URL
471
- * @param fallback - Fallback RPC URL if fetch fails
472
- * @returns RPC URL string
473
- */
474
- declare function getRpcUrl(apiUrl: string, fallback?: string): Promise<string>;
475
-
476
- export { type CheckoutCreateParams, type CheckoutSession, type Customer, type CustomerCreateParams, type CustomerUpdateParams, MoneyMQ, type MoneyMQConfig, type Payment, type PaymentLink, type PaymentLinkCreateParams, type PaymentListParams, type Payout, type PayoutCreateParams, type PayoutListParams, type PayoutSettings, type PayoutSettingsUpdateParams, type Price, type PriceCreateParams, type Product, type ProductCreateParams, type ProductListParams, type ServerConfig, fetchConfig, getRpcUrl };
732
+ export { type CheckoutCreateParams, type CheckoutSession, type Customer, type CustomerCreateParams, type CustomerUpdateParams, type GetSignerParams, MoneyMQ, type MoneyMQConfig, type PayParams, type PayResult, type Payment, type PaymentIntent, type PaymentIntentCreateParams, type PaymentLink, type PaymentLinkCreateParams, type PaymentListParams, PaymentRequiredError, type PaymentRequirements, type Payout, type PayoutCreateParams, type PayoutListParams, type PayoutSettings, type PayoutSettingsUpdateParams, type Price, type PriceCreateParams, type Product, type ProductAccessParams, type ProductAccessResponse, type ProductCreateParams, type ProductListParams, type ServerConfig, type X402ClientConfig, fetchConfig, getRpcUrl };