@b3dotfun/sdk 0.1.68-alpha.2 → 0.1.68-alpha.4

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 (127) hide show
  1. package/dist/cjs/anyspend/platform/client.d.ts +35 -0
  2. package/dist/cjs/anyspend/platform/client.js +158 -0
  3. package/dist/cjs/anyspend/platform/errors.d.ts +38 -0
  4. package/dist/cjs/anyspend/platform/errors.js +77 -0
  5. package/dist/cjs/anyspend/platform/index.d.ts +87 -0
  6. package/dist/cjs/anyspend/platform/index.js +85 -0
  7. package/dist/cjs/anyspend/platform/resources/analytics.d.ts +7 -0
  8. package/dist/cjs/anyspend/platform/resources/analytics.js +12 -0
  9. package/dist/cjs/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
  10. package/dist/cjs/anyspend/platform/resources/checkout-sessions.js +27 -0
  11. package/dist/cjs/anyspend/platform/resources/customers.d.ts +19 -0
  12. package/dist/cjs/anyspend/platform/resources/customers.js +34 -0
  13. package/dist/cjs/anyspend/platform/resources/discount-codes.d.ts +29 -0
  14. package/dist/cjs/anyspend/platform/resources/discount-codes.js +31 -0
  15. package/dist/cjs/anyspend/platform/resources/events.d.ts +14 -0
  16. package/dist/cjs/anyspend/platform/resources/events.js +16 -0
  17. package/dist/cjs/anyspend/platform/resources/notifications.d.ts +18 -0
  18. package/dist/cjs/anyspend/platform/resources/notifications.js +27 -0
  19. package/dist/cjs/anyspend/platform/resources/organization.d.ts +17 -0
  20. package/dist/cjs/anyspend/platform/resources/organization.js +15 -0
  21. package/dist/cjs/anyspend/platform/resources/payment-links.d.ts +21 -0
  22. package/dist/cjs/anyspend/platform/resources/payment-links.js +49 -0
  23. package/dist/cjs/anyspend/platform/resources/products.d.ts +27 -0
  24. package/dist/cjs/anyspend/platform/resources/products.js +31 -0
  25. package/dist/cjs/anyspend/platform/resources/transactions.d.ts +11 -0
  26. package/dist/cjs/anyspend/platform/resources/transactions.js +25 -0
  27. package/dist/cjs/anyspend/platform/resources/webhooks.d.ts +14 -0
  28. package/dist/cjs/anyspend/platform/resources/webhooks.js +33 -0
  29. package/dist/cjs/anyspend/platform/resources/widgets.d.ts +38 -0
  30. package/dist/cjs/anyspend/platform/resources/widgets.js +31 -0
  31. package/dist/cjs/anyspend/platform/types.d.ts +478 -0
  32. package/dist/cjs/anyspend/platform/types.js +5 -0
  33. package/dist/cjs/anyspend/platform/utils/idempotency.d.ts +4 -0
  34. package/dist/cjs/anyspend/platform/utils/idempotency.js +17 -0
  35. package/dist/cjs/anyspend/platform/utils/pagination.d.ts +12 -0
  36. package/dist/cjs/anyspend/platform/utils/pagination.js +22 -0
  37. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.d.ts +10 -6
  38. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
  39. package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
  40. package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.js +145 -0
  41. package/dist/cjs/anyspend/react/components/index.d.ts +1 -1
  42. package/dist/esm/anyspend/platform/client.d.ts +35 -0
  43. package/dist/esm/anyspend/platform/client.js +153 -0
  44. package/dist/esm/anyspend/platform/errors.d.ts +38 -0
  45. package/dist/esm/anyspend/platform/errors.js +67 -0
  46. package/dist/esm/anyspend/platform/index.d.ts +87 -0
  47. package/dist/esm/anyspend/platform/index.js +75 -0
  48. package/dist/esm/anyspend/platform/resources/analytics.d.ts +7 -0
  49. package/dist/esm/anyspend/platform/resources/analytics.js +8 -0
  50. package/dist/esm/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
  51. package/dist/esm/anyspend/platform/resources/checkout-sessions.js +23 -0
  52. package/dist/esm/anyspend/platform/resources/customers.d.ts +19 -0
  53. package/dist/esm/anyspend/platform/resources/customers.js +30 -0
  54. package/dist/esm/anyspend/platform/resources/discount-codes.d.ts +29 -0
  55. package/dist/esm/anyspend/platform/resources/discount-codes.js +27 -0
  56. package/dist/esm/anyspend/platform/resources/events.d.ts +14 -0
  57. package/dist/esm/anyspend/platform/resources/events.js +12 -0
  58. package/dist/esm/anyspend/platform/resources/notifications.d.ts +18 -0
  59. package/dist/esm/anyspend/platform/resources/notifications.js +23 -0
  60. package/dist/esm/anyspend/platform/resources/organization.d.ts +17 -0
  61. package/dist/esm/anyspend/platform/resources/organization.js +11 -0
  62. package/dist/esm/anyspend/platform/resources/payment-links.d.ts +21 -0
  63. package/dist/esm/anyspend/platform/resources/payment-links.js +45 -0
  64. package/dist/esm/anyspend/platform/resources/products.d.ts +27 -0
  65. package/dist/esm/anyspend/platform/resources/products.js +27 -0
  66. package/dist/esm/anyspend/platform/resources/transactions.d.ts +11 -0
  67. package/dist/esm/anyspend/platform/resources/transactions.js +21 -0
  68. package/dist/esm/anyspend/platform/resources/webhooks.d.ts +14 -0
  69. package/dist/esm/anyspend/platform/resources/webhooks.js +29 -0
  70. package/dist/esm/anyspend/platform/resources/widgets.d.ts +38 -0
  71. package/dist/esm/anyspend/platform/resources/widgets.js +27 -0
  72. package/dist/esm/anyspend/platform/types.d.ts +478 -0
  73. package/dist/esm/anyspend/platform/types.js +4 -0
  74. package/dist/esm/anyspend/platform/utils/idempotency.d.ts +4 -0
  75. package/dist/esm/anyspend/platform/utils/idempotency.js +14 -0
  76. package/dist/esm/anyspend/platform/utils/pagination.d.ts +12 -0
  77. package/dist/esm/anyspend/platform/utils/pagination.js +19 -0
  78. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.d.ts +10 -6
  79. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
  80. package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
  81. package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.js +142 -0
  82. package/dist/esm/anyspend/react/components/index.d.ts +1 -1
  83. package/dist/styles/index.css +1 -1
  84. package/dist/types/anyspend/platform/client.d.ts +35 -0
  85. package/dist/types/anyspend/platform/errors.d.ts +38 -0
  86. package/dist/types/anyspend/platform/index.d.ts +87 -0
  87. package/dist/types/anyspend/platform/resources/analytics.d.ts +7 -0
  88. package/dist/types/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
  89. package/dist/types/anyspend/platform/resources/customers.d.ts +19 -0
  90. package/dist/types/anyspend/platform/resources/discount-codes.d.ts +29 -0
  91. package/dist/types/anyspend/platform/resources/events.d.ts +14 -0
  92. package/dist/types/anyspend/platform/resources/notifications.d.ts +18 -0
  93. package/dist/types/anyspend/platform/resources/organization.d.ts +17 -0
  94. package/dist/types/anyspend/platform/resources/payment-links.d.ts +21 -0
  95. package/dist/types/anyspend/platform/resources/products.d.ts +27 -0
  96. package/dist/types/anyspend/platform/resources/transactions.d.ts +11 -0
  97. package/dist/types/anyspend/platform/resources/webhooks.d.ts +14 -0
  98. package/dist/types/anyspend/platform/resources/widgets.d.ts +38 -0
  99. package/dist/types/anyspend/platform/types.d.ts +478 -0
  100. package/dist/types/anyspend/platform/utils/idempotency.d.ts +4 -0
  101. package/dist/types/anyspend/platform/utils/pagination.d.ts +12 -0
  102. package/dist/types/anyspend/react/components/checkout/AnySpendCheckout.d.ts +10 -6
  103. package/dist/types/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
  104. package/dist/types/anyspend/react/components/index.d.ts +1 -1
  105. package/package.json +6 -1
  106. package/src/anyspend/docs/checkout-sessions.md +20 -3
  107. package/src/anyspend/platform/client.ts +198 -0
  108. package/src/anyspend/platform/errors.ts +92 -0
  109. package/src/anyspend/platform/index.ts +129 -0
  110. package/src/anyspend/platform/resources/analytics.ts +10 -0
  111. package/src/anyspend/platform/resources/checkout-sessions.ts +36 -0
  112. package/src/anyspend/platform/resources/customers.ts +54 -0
  113. package/src/anyspend/platform/resources/discount-codes.ts +63 -0
  114. package/src/anyspend/platform/resources/events.ts +22 -0
  115. package/src/anyspend/platform/resources/notifications.ts +37 -0
  116. package/src/anyspend/platform/resources/organization.ts +24 -0
  117. package/src/anyspend/platform/resources/payment-links.ts +74 -0
  118. package/src/anyspend/platform/resources/products.ts +59 -0
  119. package/src/anyspend/platform/resources/transactions.ts +33 -0
  120. package/src/anyspend/platform/resources/webhooks.ts +47 -0
  121. package/src/anyspend/platform/resources/widgets.ts +63 -0
  122. package/src/anyspend/platform/types.ts +532 -0
  123. package/src/anyspend/platform/utils/idempotency.ts +15 -0
  124. package/src/anyspend/platform/utils/pagination.ts +32 -0
  125. package/src/anyspend/react/components/checkout/AnySpendCheckout.tsx +73 -18
  126. package/src/anyspend/react/components/checkout/VariablePricingInput.tsx +247 -0
  127. package/src/anyspend/react/components/index.ts +1 -0
@@ -0,0 +1,532 @@
1
+ /**
2
+ * TypeScript types for the AnySpend Platform API.
3
+ */
4
+
5
+ // ============== Base Types ==============
6
+
7
+ export interface ListResponse<T> {
8
+ object: "list";
9
+ data: T[];
10
+ has_more: boolean;
11
+ total_count: number;
12
+ url: string;
13
+ }
14
+
15
+ export interface DeletedResponse {
16
+ object: string;
17
+ id: string;
18
+ deleted: true;
19
+ }
20
+
21
+ export interface ActionResponse {
22
+ object: "action";
23
+ action: string;
24
+ [key: string]: unknown;
25
+ }
26
+
27
+ export interface PaginationParams {
28
+ page?: number;
29
+ limit?: number;
30
+ }
31
+
32
+ // ============== Payment Links ==============
33
+
34
+ export interface PaymentLink {
35
+ object: "payment_link";
36
+ id: string;
37
+ short_code: string;
38
+ url?: string;
39
+ name: string;
40
+ description: string | null;
41
+ amount: string | null;
42
+ min_amount: string | null;
43
+ max_amount: string | null;
44
+ suggested_amount: string | null;
45
+ token_address: string;
46
+ chain_id: number;
47
+ recipient_address: string;
48
+ product_id: string | null;
49
+ image_url: string | null;
50
+ theme_color: string | null;
51
+ button_text: string;
52
+ max_uses: number | null;
53
+ current_uses: number;
54
+ expires_at: number | null;
55
+ is_active: boolean;
56
+ form_schema: string | null;
57
+ shipping_options: string | null;
58
+ collect_shipping_address: boolean;
59
+ return_url: string | null;
60
+ return_label: string | null;
61
+ branding: string | null;
62
+ fee_on_top: boolean;
63
+ items?: PaymentLinkItem[];
64
+ created_at: number;
65
+ updated_at: number;
66
+ }
67
+
68
+ export interface PaymentLinkItem {
69
+ object: "payment_link_item";
70
+ id: string;
71
+ payment_link_id: string;
72
+ product_id: string | null;
73
+ name: string;
74
+ description: string | null;
75
+ image_url: string | null;
76
+ amount: string;
77
+ quantity: number;
78
+ sort_order: number;
79
+ created_at: number;
80
+ updated_at: number;
81
+ }
82
+
83
+ export interface CreatePaymentLinkParams {
84
+ name: string;
85
+ token_address: string;
86
+ chain_id: number;
87
+ recipient_address: string;
88
+ description?: string;
89
+ amount?: string;
90
+ min_amount?: string;
91
+ max_amount?: string;
92
+ suggested_amount?: string;
93
+ product_id?: string;
94
+ image_url?: string;
95
+ theme_color?: string;
96
+ button_text?: string;
97
+ max_uses?: number;
98
+ expires_at?: number;
99
+ form_schema?: Record<string, unknown>;
100
+ shipping_options?: Record<string, unknown>[];
101
+ collect_shipping_address?: boolean;
102
+ return_url?: string;
103
+ return_label?: string;
104
+ branding?: Record<string, unknown>;
105
+ fee_on_top?: boolean;
106
+ items?: CreatePaymentLinkItemParams[];
107
+ }
108
+
109
+ export interface CreatePaymentLinkItemParams {
110
+ name: string;
111
+ amount: string;
112
+ description?: string;
113
+ image_url?: string;
114
+ quantity?: number;
115
+ sort_order?: number;
116
+ product_id?: string;
117
+ }
118
+
119
+ export interface UpdatePaymentLinkParams extends Partial<Omit<CreatePaymentLinkParams, "items">> {
120
+ is_active?: boolean;
121
+ items?: CreatePaymentLinkItemParams[];
122
+ }
123
+
124
+ export interface ListPaymentLinksParams extends PaginationParams {
125
+ search?: string;
126
+ active?: "true" | "false";
127
+ sort?: "created_at" | "updated_at" | "name" | "current_uses";
128
+ order?: "asc" | "desc";
129
+ }
130
+
131
+ export interface PaymentLinkStats {
132
+ object: "payment_link_stats";
133
+ payment_link_id: string;
134
+ summary: {
135
+ total_views: number;
136
+ total_sessions: number;
137
+ total_completions: number;
138
+ lifetime_completions: number;
139
+ view_to_session_rate: string;
140
+ session_to_completion_rate: string;
141
+ overall_conversion_rate: string;
142
+ };
143
+ daily: {
144
+ views: { date: string; view_count: number; unique_visitors: number }[];
145
+ sessions: { date: string; sessions: number; completions: number }[];
146
+ };
147
+ utm_breakdown: Record<string, unknown>[];
148
+ }
149
+
150
+ // ============== Products ==============
151
+
152
+ export interface Product {
153
+ object: "product";
154
+ id: string;
155
+ name: string;
156
+ description: string | null;
157
+ image_url: string | null;
158
+ amount: string;
159
+ token_address: string;
160
+ chain_id: number;
161
+ recipient_address: string | null;
162
+ product_type: "one_time" | "subscription" | "variable";
163
+ is_active: boolean;
164
+ metadata: Record<string, unknown> | null;
165
+ form_schema: string | null;
166
+ shipping_options: string | null;
167
+ created_at: number;
168
+ updated_at: number;
169
+ }
170
+
171
+ export interface CreateProductParams {
172
+ name: string;
173
+ amount: string;
174
+ token_address: string;
175
+ chain_id: number;
176
+ description?: string;
177
+ image_url?: string;
178
+ recipient_address?: string;
179
+ product_type?: "one_time" | "subscription" | "variable";
180
+ metadata?: Record<string, unknown>;
181
+ form_schema?: Record<string, unknown>;
182
+ shipping_options?: Record<string, unknown>[];
183
+ }
184
+
185
+ export interface UpdateProductParams extends Partial<CreateProductParams> {
186
+ is_active?: boolean;
187
+ }
188
+
189
+ // ============== Customers ==============
190
+
191
+ export interface Customer {
192
+ object: "customer";
193
+ id: string;
194
+ wallet_address: string;
195
+ name: string | null;
196
+ email: string | null;
197
+ metadata: Record<string, unknown> | null;
198
+ total_paid: string | null;
199
+ transaction_count: number;
200
+ first_payment_at: number | null;
201
+ last_payment_at: number | null;
202
+ created_at: number;
203
+ updated_at: number;
204
+ }
205
+
206
+ export interface CreateCustomerParams {
207
+ wallet_address: string;
208
+ name?: string;
209
+ email?: string;
210
+ metadata?: Record<string, unknown>;
211
+ }
212
+
213
+ export interface UpdateCustomerParams {
214
+ name?: string;
215
+ email?: string;
216
+ metadata?: Record<string, unknown>;
217
+ }
218
+
219
+ // ============== Transactions ==============
220
+
221
+ export interface Transaction {
222
+ object: "transaction";
223
+ id: string;
224
+ tx_hash: string;
225
+ chain_id: number;
226
+ from_address: string;
227
+ to_address: string;
228
+ token_address: string;
229
+ amount: string;
230
+ amount_usd: string | null;
231
+ status: "pending" | "confirming" | "completed" | "failed";
232
+ payment_link_id: string | null;
233
+ customer_id: string | null;
234
+ created_at: number;
235
+ updated_at: number;
236
+ }
237
+
238
+ export interface TransactionStats {
239
+ object: "transaction_stats";
240
+ totalTransactions: number;
241
+ completedTransactions: number;
242
+ totalVolumeUsd: string;
243
+ last24h: { transactions: number; volumeUsd: string };
244
+ statusBreakdown: Record<string, number>;
245
+ }
246
+
247
+ export interface ListTransactionsParams extends PaginationParams {
248
+ status?: string;
249
+ customer_id?: string;
250
+ payment_link_id?: string;
251
+ from?: number;
252
+ to?: number;
253
+ }
254
+
255
+ // ============== Checkout Sessions ==============
256
+
257
+ export interface CheckoutSession {
258
+ object: "checkout_session";
259
+ id: string;
260
+ url: string | null;
261
+ status: "open" | "processing" | "completed" | "expired" | "failed";
262
+ payment_link_id: string | null;
263
+ product_id: string | null;
264
+ amount: string | null;
265
+ token_address: string;
266
+ chain_id: number;
267
+ recipient_address: string;
268
+ success_url: string | null;
269
+ cancel_url: string | null;
270
+ client_reference_id: string | null;
271
+ /** The API returns metadata as a serialized JSON string. Use JSON.parse() to recover the original object. */
272
+ metadata: string | null;
273
+ customer_email: string | null;
274
+ customer_name: string | null;
275
+ tx_hash: string | null;
276
+ completed_at: number | null;
277
+ expires_at: number;
278
+ created_at: number;
279
+ updated_at: number;
280
+ }
281
+
282
+ export interface CreateCheckoutSessionParams {
283
+ payment_link_id?: string;
284
+ token_address?: string;
285
+ chain_id?: number;
286
+ recipient_address?: string;
287
+ amount?: string;
288
+ product_id?: string;
289
+ success_url?: string;
290
+ cancel_url?: string;
291
+ client_reference_id?: string;
292
+ metadata?: Record<string, unknown>;
293
+ customer_email?: string;
294
+ customer_name?: string;
295
+ expires_in?: number;
296
+ utm_source?: string;
297
+ utm_medium?: string;
298
+ utm_campaign?: string;
299
+ }
300
+
301
+ // ============== Webhooks ==============
302
+
303
+ export interface Webhook {
304
+ object: "webhook";
305
+ id: string;
306
+ url: string;
307
+ events: string[];
308
+ secret?: string;
309
+ is_active: boolean;
310
+ success_count: number;
311
+ failure_count: number;
312
+ last_triggered_at: number | null;
313
+ created_at: number;
314
+ updated_at: number;
315
+ }
316
+
317
+ export interface CreateWebhookParams {
318
+ url: string;
319
+ events: string[];
320
+ description?: string;
321
+ }
322
+
323
+ export interface UpdateWebhookParams {
324
+ url?: string;
325
+ events?: string[];
326
+ is_active?: boolean;
327
+ }
328
+
329
+ // ============== Discount Codes ==============
330
+
331
+ export interface DiscountCode {
332
+ object: "discount_code";
333
+ id: string;
334
+ code: string;
335
+ type: "percentage" | "fixed";
336
+ value: string;
337
+ payment_link_id: string | null;
338
+ max_uses: number | null;
339
+ current_uses: number;
340
+ min_order_amount: string | null;
341
+ expires_at: number | null;
342
+ is_active: boolean;
343
+ created_at: number;
344
+ updated_at: number;
345
+ }
346
+
347
+ export interface CreateDiscountCodeParams {
348
+ code: string;
349
+ type: "percentage" | "fixed";
350
+ value: string;
351
+ payment_link_id?: string;
352
+ max_uses?: number;
353
+ min_order_amount?: string;
354
+ expires_at?: number;
355
+ }
356
+
357
+ export interface BatchCreateDiscountCodesParams {
358
+ codes: string[];
359
+ type: "percentage" | "fixed";
360
+ value: string;
361
+ payment_link_id?: string;
362
+ max_uses?: number;
363
+ min_order_amount?: string;
364
+ expires_at?: number;
365
+ }
366
+
367
+ // ============== Notifications ==============
368
+
369
+ export interface NotificationSettings {
370
+ object: "notification_settings";
371
+ id: string;
372
+ email_enabled: boolean;
373
+ email_address: string | null;
374
+ telegram_enabled: boolean;
375
+ telegram_chat_id: string | null;
376
+ enabled_events: string[];
377
+ }
378
+
379
+ export interface UpdateNotificationSettingsParams {
380
+ email_enabled?: boolean;
381
+ email_address?: string;
382
+ telegram_enabled?: boolean;
383
+ enabled_events?: string[];
384
+ }
385
+
386
+ // ============== Widgets ==============
387
+
388
+ export interface WidgetConfig {
389
+ object: "widget_config";
390
+ id: string;
391
+ short_code: string;
392
+ name: string;
393
+ description: string | null;
394
+ widget_type: string;
395
+ config: string;
396
+ theme: string;
397
+ is_active: boolean;
398
+ current_views: number;
399
+ created_at: number;
400
+ updated_at: number;
401
+ }
402
+
403
+ export interface CreateWidgetParams {
404
+ name: string;
405
+ widget_type: "swap" | "checkout" | "nft" | "deposit";
406
+ config: Record<string, unknown>;
407
+ description?: string;
408
+ theme?: Record<string, unknown>;
409
+ }
410
+
411
+ // ============== Organization ==============
412
+
413
+ export interface Organization {
414
+ object: "organization";
415
+ id: string;
416
+ name: string;
417
+ slug: string;
418
+ description: string | null;
419
+ logo_url: string | null;
420
+ website_url: string | null;
421
+ default_recipient_address: string | null;
422
+ default_chain_id: number | null;
423
+ default_token_address: string | null;
424
+ }
425
+
426
+ // ============== Analytics ==============
427
+
428
+ export interface AnalyticsOverview {
429
+ object: "analytics_overview";
430
+ period: string;
431
+ revenue: {
432
+ period_usd: string;
433
+ period_transactions: number;
434
+ all_time_usd: string;
435
+ all_time_transactions: number;
436
+ };
437
+ customers: { total: number; new_in_period: number };
438
+ payment_links: { total: number; active: number };
439
+ conversion_rate: string;
440
+ daily: { date: string; transactions: number; revenue_usd: number }[];
441
+ top_payment_links: Record<string, unknown>[];
442
+ top_tokens: Record<string, unknown>[];
443
+ top_chains: Record<string, unknown>[];
444
+ }
445
+
446
+ // ============== Events ==============
447
+
448
+ export interface ApiEvent {
449
+ object: "event";
450
+ id: string;
451
+ event_type: string;
452
+ resource_type: string;
453
+ resource_id: string | null;
454
+ ip_address: string | null;
455
+ request_method: string;
456
+ request_path: string;
457
+ status_code: number;
458
+ created_at: number;
459
+ }
460
+
461
+ // ============== Quick Pay ==============
462
+
463
+ export interface QuickPayParams {
464
+ recipient_address: string;
465
+ amount?: string;
466
+ token_address?: string;
467
+ chain_id?: number;
468
+ name?: string;
469
+ description?: string;
470
+ expires_in?: number;
471
+ }
472
+
473
+ // ============== API Keys ==============
474
+
475
+ export interface ApiKey {
476
+ object: "api_key";
477
+ id: string;
478
+ name: string;
479
+ prefix: string;
480
+ permissions: string[];
481
+ last_used_at: number | null;
482
+ created_at: number;
483
+ updated_at: number;
484
+ }
485
+
486
+ // ============== Webhook Deliveries ==============
487
+
488
+ export interface WebhookDelivery {
489
+ object: "webhook_delivery";
490
+ id: string;
491
+ webhook_id: string;
492
+ event_type: string;
493
+ url: string;
494
+ status: "pending" | "success" | "failed";
495
+ status_code: number | null;
496
+ response_body: string | null;
497
+ error_message: string | null;
498
+ attempted_at: number;
499
+ created_at: number;
500
+ }
501
+
502
+ // ============== Discount Code Validation ==============
503
+
504
+ export interface ValidateDiscountResult {
505
+ object: "discount_validation";
506
+ valid: boolean;
507
+ discount_code?: DiscountCode;
508
+ discount_amount?: string;
509
+ final_amount?: string;
510
+ reason?: string;
511
+ }
512
+
513
+ export interface BatchCreateResult {
514
+ object: "batch_result";
515
+ created: DiscountCode[];
516
+ errors: { code: string; error: string }[];
517
+ }
518
+
519
+ // ============== Export Params ==============
520
+
521
+ export interface ExportTransactionsParams {
522
+ format?: "csv" | "json";
523
+ status?: string;
524
+ from?: number;
525
+ to?: number;
526
+ }
527
+
528
+ export interface ExportCustomersParams {
529
+ format?: "csv" | "json";
530
+ from?: number;
531
+ to?: number;
532
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Idempotency key generation utility.
3
+ */
4
+
5
+ export function generateIdempotencyKey(): string {
6
+ if (typeof crypto !== "undefined" && crypto.randomUUID) {
7
+ return crypto.randomUUID();
8
+ }
9
+ // Fallback for environments without crypto.randomUUID
10
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, c => {
11
+ const r = (Math.random() * 16) | 0;
12
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
13
+ return v.toString(16);
14
+ });
15
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Auto-pagination async iterator for list endpoints.
3
+ */
4
+
5
+ import type { ListResponse } from "../types";
6
+
7
+ export interface AutoPaginateOptions {
8
+ startPage?: number;
9
+ limit?: number;
10
+ }
11
+
12
+ /**
13
+ * Creates an async iterator that automatically paginates through all results.
14
+ */
15
+ export async function* autoPaginate<T>(
16
+ fetchPage: (page: number, limit: number) => Promise<ListResponse<T>>,
17
+ options: AutoPaginateOptions = {},
18
+ ): AsyncGenerator<T, void, undefined> {
19
+ let page = options.startPage || 1;
20
+ const limit = options.limit || 100;
21
+
22
+ while (true) {
23
+ const result = await fetchPage(page, limit);
24
+
25
+ for (const item of result.data) {
26
+ yield item;
27
+ }
28
+
29
+ if (!result.has_more) break;
30
+ page++;
31
+ }
32
+ }