moltspay 1.6.0 → 2.0.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.
Files changed (55) hide show
  1. package/README.md +1 -0
  2. package/dist/cdp/index.js.map +1 -1
  3. package/dist/cdp/index.mjs.map +1 -1
  4. package/dist/{cdp-DeohBe1o.d.ts → cdp-B5PhDUTC.d.ts} +1 -1
  5. package/dist/{cdp-p_eHuQpb.d.mts → cdp-D-5Hg3y_.d.mts} +1 -1
  6. package/dist/chains/index.d.mts +37 -1
  7. package/dist/chains/index.d.ts +37 -1
  8. package/dist/chains/index.js +22 -0
  9. package/dist/chains/index.js.map +1 -1
  10. package/dist/chains/index.mjs +19 -0
  11. package/dist/chains/index.mjs.map +1 -1
  12. package/dist/cli/index.js +1466 -61
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/cli/index.mjs +1466 -61
  15. package/dist/cli/index.mjs.map +1 -1
  16. package/dist/client/index.d.mts +41 -0
  17. package/dist/client/index.d.ts +41 -0
  18. package/dist/client/index.js +824 -10
  19. package/dist/client/index.js.map +1 -1
  20. package/dist/client/index.mjs +824 -10
  21. package/dist/client/index.mjs.map +1 -1
  22. package/dist/client/web/index.d.mts +17 -1
  23. package/dist/client/web/index.mjs +11 -0
  24. package/dist/client/web/index.mjs.map +1 -1
  25. package/dist/facilitators/index.d.mts +161 -4
  26. package/dist/facilitators/index.d.ts +161 -4
  27. package/dist/facilitators/index.js +370 -0
  28. package/dist/facilitators/index.js.map +1 -1
  29. package/dist/facilitators/index.mjs +365 -0
  30. package/dist/facilitators/index.mjs.map +1 -1
  31. package/dist/index.d.mts +77 -2
  32. package/dist/index.d.ts +77 -2
  33. package/dist/index.js +1412 -31
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.mjs +1406 -31
  36. package/dist/index.mjs.map +1 -1
  37. package/dist/mcp/index.js +828 -14
  38. package/dist/mcp/index.js.map +1 -1
  39. package/dist/mcp/index.mjs +828 -14
  40. package/dist/mcp/index.mjs.map +1 -1
  41. package/dist/{registry-OsEO2dOu.d.mts → registry-DIo0WNoO.d.mts} +8 -1
  42. package/dist/{registry-OsEO2dOu.d.ts → registry-DIo0WNoO.d.ts} +8 -1
  43. package/dist/server/index.d.mts +95 -2
  44. package/dist/server/index.d.ts +95 -2
  45. package/dist/server/index.js +554 -14
  46. package/dist/server/index.js.map +1 -1
  47. package/dist/server/index.mjs +554 -14
  48. package/dist/server/index.mjs.map +1 -1
  49. package/dist/verify/index.js.map +1 -1
  50. package/dist/verify/index.mjs.map +1 -1
  51. package/dist/wallet/index.js.map +1 -1
  52. package/dist/wallet/index.mjs.map +1 -1
  53. package/package.json +7 -1
  54. package/schemas/moltspay.services.schema.json +100 -6
  55. package/scripts/postinstall.js +91 -0
@@ -10,6 +10,13 @@ interface ClientConfig {
10
10
  maxPerTx: number;
11
11
  maxPerDay: number;
12
12
  };
13
+ /**
14
+ * Ordered rail preference (2.0.0). When the server's 402 offers more than
15
+ * one rail (e.g. USDC on Base AND CNY via Alipay) and the caller didn't
16
+ * pass an explicit `rail`, the first entry here that the server also
17
+ * accepts wins. e.g. `["base", "alipay"]`.
18
+ */
19
+ railPreference?: string[];
13
20
  }
14
21
  interface WalletData {
15
22
  address: string;
@@ -62,6 +69,10 @@ interface VerifyResponse {
62
69
  }
63
70
  interface MoltsPayClientOptions {
64
71
  configDir?: string;
72
+ /** Ordered rail preference; see {@link ClientConfig.railPreference}. */
73
+ railPreference?: string[];
74
+ /** Stable Alipay session id (else AIPAY_SESSION_ID, else a fresh UUID). */
75
+ alipaySessionId?: string;
65
76
  }
66
77
 
67
78
  /**
@@ -84,6 +95,24 @@ interface PayOptions {
84
95
  chain?: 'base' | 'polygon' | 'base_sepolia' | 'tempo_moderato' | 'bnb' | 'bnb_testnet' | 'solana' | 'solana_devnet';
85
96
  /** Send raw data at top level instead of wrapped in { params } */
86
97
  rawData?: boolean;
98
+ /**
99
+ * Explicit payment rail (2.0.0): `'alipay'` or a chain name. When set,
100
+ * routing skips the default crypto path. `'alipay'` dispatches to the
101
+ * alipay-bot-backed {@link AlipayClient} and needs no EVM wallet.
102
+ */
103
+ rail?: string;
104
+ /** Alipay: surfaced once the payment URL + tradeNo are known. */
105
+ onPaymentPending?: (info: {
106
+ paymentUrl: string;
107
+ shortenUrl?: string;
108
+ tradeNo: string;
109
+ }) => void;
110
+ /** Alipay: forward CLI output to the user verbatim (line by line). */
111
+ onLine?: (line: string) => void;
112
+ /** Alipay: overall budget; defaults to the challenge's pay_before window. */
113
+ timeoutMs?: number;
114
+ /** Cancellation (alipay poll loop). */
115
+ signal?: AbortSignal;
87
116
  }
88
117
  declare class MoltsPayClient {
89
118
  private configDir;
@@ -93,6 +122,8 @@ declare class MoltsPayClient {
93
122
  private signer;
94
123
  private todaySpending;
95
124
  private lastSpendingReset;
125
+ private railPreference?;
126
+ private alipaySessionId?;
96
127
  constructor(options?: MoltsPayClientOptions);
97
128
  /**
98
129
  * Check if client is initialized (has wallet)
@@ -130,6 +161,16 @@ declare class MoltsPayClient {
130
161
  * @param options - Payment options (token selection)
131
162
  */
132
163
  pay(serverUrl: string, service: string, params: Record<string, any>, options?: PayOptions): Promise<Record<string, any>>;
164
+ /**
165
+ * Pay for a service over the Alipay fiat rail (2.0.0).
166
+ *
167
+ * Unlike the crypto path this needs no EVM wallet — it shells out to
168
+ * alipay-bot via {@link AlipayClient}. Flow: hit the resource with no
169
+ * payment to get the 402 challenge, confirm the server actually offers the
170
+ * alipay rail (selectRail), then run the 8-step state machine and return the
171
+ * resource body.
172
+ */
173
+ private payViaAlipay;
133
174
  /**
134
175
  * Handle MPP (Machine Payments Protocol) payment flow
135
176
  * Called when pay() detects WWW-Authenticate header in 402 response
@@ -10,6 +10,13 @@ interface ClientConfig {
10
10
  maxPerTx: number;
11
11
  maxPerDay: number;
12
12
  };
13
+ /**
14
+ * Ordered rail preference (2.0.0). When the server's 402 offers more than
15
+ * one rail (e.g. USDC on Base AND CNY via Alipay) and the caller didn't
16
+ * pass an explicit `rail`, the first entry here that the server also
17
+ * accepts wins. e.g. `["base", "alipay"]`.
18
+ */
19
+ railPreference?: string[];
13
20
  }
14
21
  interface WalletData {
15
22
  address: string;
@@ -62,6 +69,10 @@ interface VerifyResponse {
62
69
  }
63
70
  interface MoltsPayClientOptions {
64
71
  configDir?: string;
72
+ /** Ordered rail preference; see {@link ClientConfig.railPreference}. */
73
+ railPreference?: string[];
74
+ /** Stable Alipay session id (else AIPAY_SESSION_ID, else a fresh UUID). */
75
+ alipaySessionId?: string;
65
76
  }
66
77
 
67
78
  /**
@@ -84,6 +95,24 @@ interface PayOptions {
84
95
  chain?: 'base' | 'polygon' | 'base_sepolia' | 'tempo_moderato' | 'bnb' | 'bnb_testnet' | 'solana' | 'solana_devnet';
85
96
  /** Send raw data at top level instead of wrapped in { params } */
86
97
  rawData?: boolean;
98
+ /**
99
+ * Explicit payment rail (2.0.0): `'alipay'` or a chain name. When set,
100
+ * routing skips the default crypto path. `'alipay'` dispatches to the
101
+ * alipay-bot-backed {@link AlipayClient} and needs no EVM wallet.
102
+ */
103
+ rail?: string;
104
+ /** Alipay: surfaced once the payment URL + tradeNo are known. */
105
+ onPaymentPending?: (info: {
106
+ paymentUrl: string;
107
+ shortenUrl?: string;
108
+ tradeNo: string;
109
+ }) => void;
110
+ /** Alipay: forward CLI output to the user verbatim (line by line). */
111
+ onLine?: (line: string) => void;
112
+ /** Alipay: overall budget; defaults to the challenge's pay_before window. */
113
+ timeoutMs?: number;
114
+ /** Cancellation (alipay poll loop). */
115
+ signal?: AbortSignal;
87
116
  }
88
117
  declare class MoltsPayClient {
89
118
  private configDir;
@@ -93,6 +122,8 @@ declare class MoltsPayClient {
93
122
  private signer;
94
123
  private todaySpending;
95
124
  private lastSpendingReset;
125
+ private railPreference?;
126
+ private alipaySessionId?;
96
127
  constructor(options?: MoltsPayClientOptions);
97
128
  /**
98
129
  * Check if client is initialized (has wallet)
@@ -130,6 +161,16 @@ declare class MoltsPayClient {
130
161
  * @param options - Payment options (token selection)
131
162
  */
132
163
  pay(serverUrl: string, service: string, params: Record<string, any>, options?: PayOptions): Promise<Record<string, any>>;
164
+ /**
165
+ * Pay for a service over the Alipay fiat rail (2.0.0).
166
+ *
167
+ * Unlike the crypto path this needs no EVM wallet — it shells out to
168
+ * alipay-bot via {@link AlipayClient}. Flow: hit the resource with no
169
+ * payment to get the 402 challenge, confirm the server actually offers the
170
+ * alipay rail (selectRail), then run the 8-step state machine and return the
171
+ * resource body.
172
+ */
173
+ private payViaAlipay;
133
174
  /**
134
175
  * Handle MPP (Machine Payments Protocol) payment flow
135
176
  * Called when pay() detects WWW-Authenticate header in 402 response