@moneymq/sdk 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MoneyMQ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,262 @@
1
+ # @moneymq/sdk
2
+
3
+ Core SDK for the MoneyMQ payment platform. Accept stablecoin payments with a Stripe-like API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @moneymq/sdk
9
+ # or
10
+ pnpm add @moneymq/sdk
11
+ # or
12
+ yarn add @moneymq/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { MoneyMQ } from '@moneymq/sdk';
19
+
20
+ const moneymq = new MoneyMQ({
21
+ url: 'http://localhost:8488',
22
+ });
23
+
24
+ // Create a product
25
+ const product = await moneymq.catalog.products.create({
26
+ name: 'Pro Plan',
27
+ description: 'Full access to all features',
28
+ });
29
+
30
+ // Create a price
31
+ const price = await moneymq.catalog.prices.create({
32
+ product: product.id,
33
+ currency: 'USDC',
34
+ amount: 1000,
35
+ type: 'one_time',
36
+ });
37
+
38
+ // Create a checkout session
39
+ const session = await moneymq.payment.checkout.create({
40
+ lineItems: [{ price: price.id, quantity: 1 }],
41
+ successUrl: 'https://example.com/success',
42
+ cancelUrl: 'https://example.com/cancel',
43
+ });
44
+ ```
45
+
46
+ ## Configuration
47
+
48
+ ```typescript
49
+ const moneymq = new MoneyMQ({
50
+ // Required: MoneyMQ API URL
51
+ url: 'http://localhost:8488',
52
+
53
+ // Optional: Secret key for authenticated requests
54
+ secret: process.env.MONEYMQ_SECRET,
55
+
56
+ // Optional: Request timeout in milliseconds (default: 30000)
57
+ timeout: 30000,
58
+ });
59
+ ```
60
+
61
+ ## API Reference
62
+
63
+ ### Catalog
64
+
65
+ #### Products
66
+
67
+ ```typescript
68
+ // Create a product
69
+ const product = await moneymq.catalog.products.create({
70
+ name: 'Pro Plan',
71
+ description: 'Full access',
72
+ active: true,
73
+ metadata: { tier: 'premium' },
74
+ });
75
+
76
+ // Retrieve a product
77
+ const product = await moneymq.catalog.products.retrieve('prod_123');
78
+
79
+ // List products
80
+ const { data, hasMore } = await moneymq.catalog.products.list({
81
+ active: true,
82
+ limit: 10,
83
+ });
84
+
85
+ // Update a product
86
+ const updated = await moneymq.catalog.products.update('prod_123', {
87
+ name: 'Enterprise Plan',
88
+ });
89
+
90
+ // Delete a product
91
+ await moneymq.catalog.products.delete('prod_123');
92
+ ```
93
+
94
+ #### Prices
95
+
96
+ ```typescript
97
+ // Create a one-time price
98
+ const price = await moneymq.catalog.prices.create({
99
+ product: 'prod_123',
100
+ currency: 'USDC',
101
+ amount: 1000,
102
+ type: 'one_time',
103
+ });
104
+
105
+ // Create a recurring price
106
+ const subscription = await moneymq.catalog.prices.create({
107
+ product: 'prod_123',
108
+ currency: 'USDC',
109
+ amount: 9900,
110
+ type: 'recurring',
111
+ recurring: {
112
+ interval: 'month',
113
+ intervalCount: 1,
114
+ },
115
+ });
116
+
117
+ // Retrieve a price
118
+ const price = await moneymq.catalog.prices.retrieve('price_123');
119
+
120
+ // List prices
121
+ const { data } = await moneymq.catalog.prices.list({
122
+ product: 'prod_123',
123
+ active: true,
124
+ });
125
+ ```
126
+
127
+ ### Payment
128
+
129
+ #### Checkout Sessions
130
+
131
+ ```typescript
132
+ // Create a checkout session
133
+ const session = await moneymq.payment.checkout.create({
134
+ lineItems: [
135
+ { price: 'price_123', quantity: 1 },
136
+ ],
137
+ successUrl: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
138
+ cancelUrl: 'https://example.com/cancel',
139
+ customer: 'cus_123', // Optional
140
+ customerEmail: 'user@example.com', // Optional
141
+ metadata: { orderId: '12345' },
142
+ });
143
+
144
+ // Retrieve a session
145
+ const session = await moneymq.payment.checkout.retrieve('cs_123');
146
+ ```
147
+
148
+ #### Payment Links
149
+
150
+ ```typescript
151
+ // Create a payment link
152
+ const link = await moneymq.payment.links.create({
153
+ lineItems: [{ price: 'price_123', quantity: 1 }],
154
+ expiresAt: new Date('2025-12-31'),
155
+ });
156
+
157
+ // Retrieve a link
158
+ const link = await moneymq.payment.links.retrieve('plink_123');
159
+
160
+ // Deactivate a link
161
+ await moneymq.payment.links.deactivate('plink_123');
162
+ ```
163
+
164
+ #### Customers
165
+
166
+ ```typescript
167
+ // Create a customer
168
+ const customer = await moneymq.payment.customers.create({
169
+ email: 'user@example.com',
170
+ name: 'John Doe',
171
+ metadata: { userId: '123' },
172
+ });
173
+
174
+ // Retrieve with expanded fields
175
+ const customer = await moneymq.payment.customers.retrieve('cus_123', {
176
+ expand: ['payments', 'subscriptions'],
177
+ });
178
+
179
+ // Update a customer
180
+ await moneymq.payment.customers.update('cus_123', {
181
+ name: 'Jane Doe',
182
+ });
183
+
184
+ // List customers
185
+ const { data } = await moneymq.payment.customers.list({
186
+ email: 'user@example.com',
187
+ });
188
+ ```
189
+
190
+ #### Payments
191
+
192
+ ```typescript
193
+ // Retrieve a payment
194
+ const payment = await moneymq.payment.retrieve('pay_123');
195
+
196
+ // List payments
197
+ const { data } = await moneymq.payment.list({
198
+ customerId: 'cus_123',
199
+ status: 'completed',
200
+ limit: 20,
201
+ });
202
+ ```
203
+
204
+ #### Payouts
205
+
206
+ ```typescript
207
+ // Create a payout
208
+ const payout = await moneymq.payment.payouts.create({
209
+ amount: 100000,
210
+ currency: 'USDC',
211
+ destination: 'wallet_address',
212
+ });
213
+
214
+ // Get payout settings
215
+ const settings = await moneymq.payment.payouts.settings.retrieve();
216
+
217
+ // Update payout settings
218
+ await moneymq.payment.payouts.settings.update({
219
+ schedule: 'daily',
220
+ minimumAmount: 10000,
221
+ });
222
+ ```
223
+
224
+ ## Error Handling
225
+
226
+ ```typescript
227
+ import { MoneyMQ, MoneyMQError } from '@moneymq/sdk';
228
+
229
+ try {
230
+ await moneymq.catalog.products.retrieve('invalid_id');
231
+ } catch (error) {
232
+ if (error instanceof MoneyMQError) {
233
+ console.error('Status:', error.statusCode);
234
+ console.error('Message:', error.message);
235
+ console.error('Raw:', error.raw);
236
+ }
237
+ }
238
+ ```
239
+
240
+ ## TypeScript Support
241
+
242
+ This package includes full TypeScript definitions. All types are exported:
243
+
244
+ ```typescript
245
+ import type {
246
+ MoneyMQConfig,
247
+ Product,
248
+ ProductCreateParams,
249
+ Price,
250
+ PriceCreateParams,
251
+ CheckoutSession,
252
+ CheckoutCreateParams,
253
+ PaymentLink,
254
+ Customer,
255
+ Payment,
256
+ Payout,
257
+ } from '@moneymq/sdk';
258
+ ```
259
+
260
+ ## License
261
+
262
+ MIT
@@ -0,0 +1,418 @@
1
+ interface Product {
2
+ id: string;
3
+ object: 'product';
4
+ name: string;
5
+ description?: string;
6
+ active: boolean;
7
+ metadata?: Record<string, string>;
8
+ created: number;
9
+ updated: number;
10
+ }
11
+ interface ProductCreateParams {
12
+ name: string;
13
+ description?: string;
14
+ active?: boolean;
15
+ metadata?: Record<string, string>;
16
+ }
17
+ interface ProductListParams {
18
+ active?: boolean;
19
+ limit?: number;
20
+ startingAfter?: string;
21
+ }
22
+ interface Price {
23
+ id: string;
24
+ object: 'price';
25
+ product: string;
26
+ currency: string;
27
+ amount: number;
28
+ type: 'one_time' | 'recurring';
29
+ recurring?: {
30
+ interval: 'day' | 'week' | 'month' | 'year';
31
+ intervalCount: number;
32
+ };
33
+ active: boolean;
34
+ metadata?: Record<string, string>;
35
+ created: number;
36
+ }
37
+ interface PriceCreateParams {
38
+ product: string;
39
+ currency: string;
40
+ amount: number;
41
+ type: 'one_time' | 'recurring';
42
+ recurring?: {
43
+ interval: 'day' | 'week' | 'month' | 'year';
44
+ intervalCount?: number;
45
+ };
46
+ metadata?: Record<string, string>;
47
+ }
48
+ declare class ProductsAPI {
49
+ private config;
50
+ constructor(config: MoneyMQConfig);
51
+ private request;
52
+ /**
53
+ * Create a new product
54
+ */
55
+ create(params: ProductCreateParams): Promise<Product>;
56
+ /**
57
+ * Retrieve a product by ID
58
+ */
59
+ retrieve(id: string): Promise<Product>;
60
+ /**
61
+ * List all products
62
+ */
63
+ list(params?: ProductListParams): Promise<{
64
+ data: Product[];
65
+ hasMore: boolean;
66
+ }>;
67
+ /**
68
+ * Update a product
69
+ */
70
+ update(id: string, params: Partial<ProductCreateParams>): Promise<Product>;
71
+ /**
72
+ * Delete a product
73
+ */
74
+ delete(id: string): Promise<{
75
+ deleted: boolean;
76
+ }>;
77
+ }
78
+ declare class PricesAPI {
79
+ private config;
80
+ constructor(config: MoneyMQConfig);
81
+ private request;
82
+ /**
83
+ * Create a new price
84
+ */
85
+ create(params: PriceCreateParams): Promise<Price>;
86
+ /**
87
+ * Retrieve a price by ID
88
+ */
89
+ retrieve(id: string): Promise<Price>;
90
+ /**
91
+ * List all prices
92
+ */
93
+ list(params?: {
94
+ product?: string;
95
+ active?: boolean;
96
+ limit?: number;
97
+ }): Promise<{
98
+ data: Price[];
99
+ hasMore: boolean;
100
+ }>;
101
+ }
102
+ /**
103
+ * Catalog API for managing products and prices
104
+ */
105
+ declare class CatalogAPI {
106
+ /** Products API */
107
+ readonly products: ProductsAPI;
108
+ /** Prices API */
109
+ readonly prices: PricesAPI;
110
+ constructor(config: MoneyMQConfig);
111
+ }
112
+
113
+ interface LineItem {
114
+ price: string;
115
+ quantity: number;
116
+ }
117
+ interface CheckoutSession {
118
+ id: string;
119
+ object: 'checkout.session';
120
+ url: string;
121
+ status: 'open' | 'complete' | 'expired';
122
+ paymentStatus: 'unpaid' | 'paid';
123
+ customer?: string;
124
+ lineItems: LineItem[];
125
+ successUrl: string;
126
+ cancelUrl: string;
127
+ expiresAt: number;
128
+ created: number;
129
+ }
130
+ interface CheckoutCreateParams {
131
+ lineItems: LineItem[];
132
+ successUrl: string;
133
+ cancelUrl: string;
134
+ customerEmail?: string;
135
+ customer?: string;
136
+ metadata?: Record<string, string>;
137
+ }
138
+ interface PaymentLink {
139
+ id: string;
140
+ object: 'payment_link';
141
+ url: string;
142
+ active: boolean;
143
+ lineItems: LineItem[];
144
+ expiresAt?: number;
145
+ created: number;
146
+ }
147
+ interface PaymentLinkCreateParams {
148
+ lineItems: LineItem[];
149
+ expiresAt?: Date | number;
150
+ metadata?: Record<string, string>;
151
+ }
152
+ interface Payment {
153
+ id: string;
154
+ object: 'payment';
155
+ amount: number;
156
+ currency: string;
157
+ status: 'completed' | 'pending' | 'failed';
158
+ customer?: string;
159
+ checkout?: string;
160
+ signature?: string;
161
+ metadata?: Record<string, string>;
162
+ created: number;
163
+ }
164
+ interface PaymentListParams {
165
+ customerId?: string;
166
+ status?: 'completed' | 'pending' | 'failed';
167
+ limit?: number;
168
+ startingAfter?: string;
169
+ }
170
+ interface Customer {
171
+ id: string;
172
+ object: 'customer';
173
+ email: string;
174
+ name?: string;
175
+ metadata?: Record<string, string>;
176
+ subscriptions?: unknown[];
177
+ payments?: Payment[];
178
+ created: number;
179
+ }
180
+ interface CustomerCreateParams {
181
+ email: string;
182
+ name?: string;
183
+ metadata?: Record<string, string>;
184
+ }
185
+ interface CustomerUpdateParams {
186
+ email?: string;
187
+ name?: string;
188
+ metadata?: Record<string, string>;
189
+ }
190
+ interface Payout {
191
+ id: string;
192
+ object: 'payout';
193
+ amount: number;
194
+ currency: string;
195
+ status: 'pending' | 'completed' | 'failed';
196
+ destination: string;
197
+ created: number;
198
+ }
199
+ interface PayoutCreateParams {
200
+ amount: number;
201
+ currency: string;
202
+ destination: string;
203
+ }
204
+ interface PayoutListParams {
205
+ status?: 'pending' | 'completed' | 'failed';
206
+ limit?: number;
207
+ startingAfter?: string;
208
+ }
209
+ interface PayoutSettings {
210
+ destination: {
211
+ type: 'wallet';
212
+ address: string;
213
+ currency: string;
214
+ };
215
+ schedule: 'instant' | 'daily' | 'weekly' | 'monthly';
216
+ minimumAmount?: number;
217
+ }
218
+ interface PayoutSettingsUpdateParams {
219
+ destination?: PayoutSettings['destination'];
220
+ schedule?: PayoutSettings['schedule'];
221
+ minimumAmount?: number;
222
+ }
223
+ declare class CheckoutAPI {
224
+ private request;
225
+ constructor(config: MoneyMQConfig);
226
+ /**
227
+ * Create a checkout session
228
+ */
229
+ create(params: CheckoutCreateParams): Promise<CheckoutSession>;
230
+ /**
231
+ * Retrieve a checkout session
232
+ */
233
+ retrieve(id: string): Promise<CheckoutSession>;
234
+ }
235
+ declare class LinksAPI {
236
+ private request;
237
+ constructor(config: MoneyMQConfig);
238
+ /**
239
+ * Create a payment link
240
+ */
241
+ create(params: PaymentLinkCreateParams): Promise<PaymentLink>;
242
+ /**
243
+ * Retrieve a payment link
244
+ */
245
+ retrieve(id: string): Promise<PaymentLink>;
246
+ /**
247
+ * Deactivate a payment link
248
+ */
249
+ deactivate(id: string): Promise<PaymentLink>;
250
+ }
251
+ declare class CustomersAPI {
252
+ private request;
253
+ constructor(config: MoneyMQConfig);
254
+ /**
255
+ * Create a customer
256
+ */
257
+ create(params: CustomerCreateParams): Promise<Customer>;
258
+ /**
259
+ * Retrieve a customer
260
+ */
261
+ retrieve(id: string, options?: {
262
+ expand?: string[];
263
+ }): Promise<Customer>;
264
+ /**
265
+ * Update a customer
266
+ */
267
+ update(id: string, params: CustomerUpdateParams): Promise<Customer>;
268
+ /**
269
+ * List customers
270
+ */
271
+ list(params?: {
272
+ email?: string;
273
+ limit?: number;
274
+ }): Promise<{
275
+ data: Customer[];
276
+ hasMore: boolean;
277
+ }>;
278
+ }
279
+ declare class PayoutsAPI {
280
+ private request;
281
+ /** Payout settings */
282
+ readonly settings: PayoutSettingsAPI;
283
+ constructor(config: MoneyMQConfig);
284
+ /**
285
+ * Create a manual payout
286
+ */
287
+ create(params: PayoutCreateParams): Promise<Payout>;
288
+ /**
289
+ * Retrieve a payout
290
+ */
291
+ retrieve(id: string): Promise<Payout>;
292
+ /**
293
+ * List payouts
294
+ */
295
+ list(params?: PayoutListParams): Promise<{
296
+ data: Payout[];
297
+ hasMore: boolean;
298
+ }>;
299
+ }
300
+ declare class PayoutSettingsAPI {
301
+ private request;
302
+ constructor(config: MoneyMQConfig);
303
+ /**
304
+ * Get payout settings
305
+ */
306
+ retrieve(): Promise<PayoutSettings>;
307
+ /**
308
+ * Update payout settings
309
+ */
310
+ update(params: PayoutSettingsUpdateParams): Promise<PayoutSettings>;
311
+ }
312
+ declare class WebhooksAPI {
313
+ private request;
314
+ constructor(config: MoneyMQConfig);
315
+ /**
316
+ * Trigger a test webhook event (for testing)
317
+ */
318
+ trigger(event: string, data: Record<string, unknown>): Promise<{
319
+ success: boolean;
320
+ }>;
321
+ }
322
+ /**
323
+ * Payment API for checkout, links, customers, and payouts
324
+ */
325
+ declare class PaymentAPI {
326
+ private request;
327
+ /** Checkout sessions API */
328
+ readonly checkout: CheckoutAPI;
329
+ /** Payment links API */
330
+ readonly links: LinksAPI;
331
+ /** Customers API */
332
+ readonly customers: CustomersAPI;
333
+ /** Payouts API */
334
+ readonly payouts: PayoutsAPI;
335
+ /** Webhooks API */
336
+ readonly webhooks: WebhooksAPI;
337
+ constructor(config: MoneyMQConfig);
338
+ /**
339
+ * Retrieve a payment by ID
340
+ */
341
+ retrieve(id: string): Promise<Payment>;
342
+ /**
343
+ * List payments
344
+ */
345
+ list(params?: PaymentListParams): Promise<{
346
+ data: Payment[];
347
+ hasMore: boolean;
348
+ }>;
349
+ }
350
+
351
+ /**
352
+ * Configuration options for the MoneyMQ client
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * const config: MoneyMQConfig = {
357
+ * url: 'https://api.moneymq.com',
358
+ * secret: 'your-api-secret', // Optional
359
+ * timeout: 30000,
360
+ * };
361
+ * ```
362
+ */
363
+ interface MoneyMQConfig {
364
+ /**
365
+ * MoneyMQ API URL
366
+ * @example 'http://localhost:8488' or 'https://api.moneymq.com'
367
+ */
368
+ url: string;
369
+ /**
370
+ * Optional secret key for authenticated requests
371
+ * Used for server-side operations that require authentication
372
+ */
373
+ secret?: string;
374
+ /**
375
+ * Request timeout in milliseconds
376
+ * @default 30000
377
+ */
378
+ timeout?: number;
379
+ }
380
+ /**
381
+ * MoneyMQ SDK client for accepting stablecoin payments
382
+ *
383
+ * @example
384
+ * ```typescript
385
+ * import { MoneyMQ } from '@moneymq/sdk';
386
+ *
387
+ * const moneymq = new MoneyMQ({
388
+ * url: process.env.MONEYMQ_URL ?? 'http://localhost:8488',
389
+ * });
390
+ *
391
+ * // Create a product
392
+ * const product = await moneymq.catalog.products.create({
393
+ * name: 'Pro Plan',
394
+ * description: 'Full access to all features',
395
+ * });
396
+ *
397
+ * // Create a checkout session
398
+ * const session = await moneymq.payment.checkout.create({
399
+ * lineItems: [{ price: 'price_xxx', quantity: 1 }],
400
+ * successUrl: 'https://example.com/success',
401
+ * cancelUrl: 'https://example.com/cancel',
402
+ * });
403
+ * ```
404
+ */
405
+ declare class MoneyMQ {
406
+ private config;
407
+ /** Catalog API for products and prices */
408
+ readonly catalog: CatalogAPI;
409
+ /** Payment API for checkout, links, customers, and payouts */
410
+ readonly payment: PaymentAPI;
411
+ constructor(config: MoneyMQConfig);
412
+ /**
413
+ * Make an authenticated request to the MoneyMQ API
414
+ */
415
+ request<T>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: unknown): Promise<T>;
416
+ }
417
+
418
+ 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 };