torque-checkout 1.1.1 โ 1.1.3
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/README.md +22 -24
- package/dist/index.d.ts +151 -1
- package/dist/index.esm.js +199 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +199 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Official Torque checkout SDK for seamless ecommerce integrations. Generate multi-product checkout links, track orders, and manage customer data with our powerful API.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick Start
|
|
6
6
|
|
|
7
7
|
### Prerequisites
|
|
8
8
|
|
|
@@ -48,9 +48,21 @@ const checkoutUrl = await torque.generateCartCheckoutUrl({
|
|
|
48
48
|
|
|
49
49
|
// Redirect customer to checkout
|
|
50
50
|
window.location.href = checkoutUrl
|
|
51
|
+
|
|
52
|
+
// The generated URL will look like:
|
|
53
|
+
// https://torque.fi/checkout/{businessId}/cart?items={encoded_cart_data}
|
|
51
54
|
```
|
|
52
55
|
|
|
53
|
-
##
|
|
56
|
+
## URL Structure
|
|
57
|
+
|
|
58
|
+
The SDK generates checkout URLs in this format:
|
|
59
|
+
|
|
60
|
+
- **Single Product**: `https://torque.fi/checkout/{businessId}/{productId}?quantity=1`
|
|
61
|
+
- **Multi-Product Cart**: `https://torque.fi/checkout/{businessId}/cart?items={encoded_cart_data}`
|
|
62
|
+
|
|
63
|
+
The `items` parameter contains URL-encoded JSON with your cart data.
|
|
64
|
+
|
|
65
|
+
## API Reference
|
|
54
66
|
|
|
55
67
|
### Constructor
|
|
56
68
|
|
|
@@ -182,7 +194,7 @@ const cartHash = torque.generateCartHash({
|
|
|
182
194
|
})
|
|
183
195
|
```
|
|
184
196
|
|
|
185
|
-
##
|
|
197
|
+
## Data Types
|
|
186
198
|
|
|
187
199
|
### CartItem
|
|
188
200
|
|
|
@@ -311,7 +323,7 @@ function redirect_to_torque_checkout($order_id, $posted_data, $order) {
|
|
|
311
323
|
}
|
|
312
324
|
```
|
|
313
325
|
|
|
314
|
-
##
|
|
326
|
+
## Testing
|
|
315
327
|
|
|
316
328
|
### Test Environment
|
|
317
329
|
|
|
@@ -340,7 +352,7 @@ const testCart = {
|
|
|
340
352
|
const checkoutUrl = await torque.generateCartCheckoutUrl(testCart)
|
|
341
353
|
```
|
|
342
354
|
|
|
343
|
-
##
|
|
355
|
+
## Error Handling
|
|
344
356
|
|
|
345
357
|
The SDK throws descriptive errors for various failure scenarios:
|
|
346
358
|
|
|
@@ -360,7 +372,7 @@ try {
|
|
|
360
372
|
}
|
|
361
373
|
```
|
|
362
374
|
|
|
363
|
-
##
|
|
375
|
+
## Analytics & Tracking
|
|
364
376
|
|
|
365
377
|
Track customer behavior and optimize conversions:
|
|
366
378
|
|
|
@@ -376,7 +388,7 @@ await torque.trackCheckoutComplete('order_123', {
|
|
|
376
388
|
})
|
|
377
389
|
```
|
|
378
390
|
|
|
379
|
-
##
|
|
391
|
+
## Payment Destination
|
|
380
392
|
|
|
381
393
|
**All checkout payments are automatically sent to the wallet address you set in your business profile.**
|
|
382
394
|
|
|
@@ -385,7 +397,7 @@ await torque.trackCheckoutComplete('order_123', {
|
|
|
385
397
|
- **Secure**: No need to handle payment addresses in your code
|
|
386
398
|
- **Update anytime**: Change your payment wallet in business settings
|
|
387
399
|
|
|
388
|
-
##
|
|
400
|
+
## Security
|
|
389
401
|
|
|
390
402
|
- API keys are automatically included in all requests
|
|
391
403
|
- All requests use HTTPS
|
|
@@ -393,31 +405,17 @@ await torque.trackCheckoutComplete('order_123', {
|
|
|
393
405
|
- Input validation on all methods
|
|
394
406
|
- Payment wallet address is securely stored in your business profile
|
|
395
407
|
|
|
396
|
-
##
|
|
408
|
+
## Performance
|
|
397
409
|
|
|
398
410
|
- Built-in request caching with cart hashing
|
|
399
411
|
- Configurable timeouts
|
|
400
412
|
- Efficient error handling
|
|
401
413
|
- Minimal bundle size
|
|
402
414
|
|
|
403
|
-
##
|
|
415
|
+
## Support
|
|
404
416
|
|
|
405
417
|
- **Documentation**: [https://docs.torque.fi](https://docs.torque.fi)
|
|
406
418
|
- **API Reference**: [https://docs.torque.fi/api](https://docs.torque.fi/api)
|
|
407
419
|
- **Integration Guide**: [https://docs.torque.fi/integrations](https://docs.torque.fi/integrations)
|
|
408
420
|
- **NPM Package**: [https://www.npmjs.com/package/torque-checkout](https://www.npmjs.com/package/torque-checkout)
|
|
409
421
|
- **Support**: hello@torque.fi
|
|
410
|
-
|
|
411
|
-
## ๐ Changelog
|
|
412
|
-
|
|
413
|
-
### v1.0.0
|
|
414
|
-
- Initial release
|
|
415
|
-
- Multi-product cart support
|
|
416
|
-
- Customer data pre-population
|
|
417
|
-
- Order status tracking
|
|
418
|
-
- Webhook integration
|
|
419
|
-
- Analytics tracking
|
|
420
|
-
|
|
421
|
-
## ๐ License
|
|
422
|
-
|
|
423
|
-
MIT License - see [LICENSE](LICENSE) file for details.
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,96 @@ export interface CartData {
|
|
|
36
36
|
customer?: CustomerData;
|
|
37
37
|
options?: CartOptions;
|
|
38
38
|
}
|
|
39
|
+
export interface PaymentPlan {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
price: number;
|
|
43
|
+
interval: "weekly" | "monthly" | "quarterly" | "yearly";
|
|
44
|
+
intervalCount: number;
|
|
45
|
+
trialDays?: number;
|
|
46
|
+
maxCycles?: number;
|
|
47
|
+
description?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface SubscriptionProduct {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
description?: string;
|
|
53
|
+
isSubscription: boolean;
|
|
54
|
+
paymentPlans?: PaymentPlan[];
|
|
55
|
+
subscriptionContract?: {
|
|
56
|
+
address: string;
|
|
57
|
+
chainId: number;
|
|
58
|
+
abi?: string;
|
|
59
|
+
};
|
|
60
|
+
basePrice: number;
|
|
61
|
+
currency: string;
|
|
62
|
+
image?: string;
|
|
63
|
+
images?: string[];
|
|
64
|
+
requiresShipping: boolean;
|
|
65
|
+
shippingCost?: number;
|
|
66
|
+
taxRate?: number;
|
|
67
|
+
inventory: number;
|
|
68
|
+
status: 'active' | 'inactive' | 'draft' | 'archived';
|
|
69
|
+
sku?: string;
|
|
70
|
+
category?: string;
|
|
71
|
+
tags?: string[];
|
|
72
|
+
variants?: Array<{
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
price: number;
|
|
76
|
+
inventory?: number;
|
|
77
|
+
}>;
|
|
78
|
+
metadata?: any;
|
|
79
|
+
createdAt: number;
|
|
80
|
+
updatedAt: number;
|
|
81
|
+
}
|
|
82
|
+
export interface Subscription {
|
|
83
|
+
id: string;
|
|
84
|
+
businessId: string;
|
|
85
|
+
productId: string;
|
|
86
|
+
customerId?: string;
|
|
87
|
+
customerEmail: string;
|
|
88
|
+
customerName: string;
|
|
89
|
+
paymentPlanId: string;
|
|
90
|
+
status: "active" | "cancelled" | "paused" | "expired" | "past_due";
|
|
91
|
+
currentPeriodStart: number;
|
|
92
|
+
currentPeriodEnd: number;
|
|
93
|
+
nextBillingDate: number;
|
|
94
|
+
trialStart?: number;
|
|
95
|
+
trialEnd?: number;
|
|
96
|
+
totalCycles: number;
|
|
97
|
+
maxCycles?: number;
|
|
98
|
+
lastPaymentDate?: number;
|
|
99
|
+
nextPaymentAmount: number;
|
|
100
|
+
currency: string;
|
|
101
|
+
contractSubscriptionId?: string;
|
|
102
|
+
contractAddress?: string;
|
|
103
|
+
billingHistory?: Array<{
|
|
104
|
+
cycleNumber: number;
|
|
105
|
+
amount: number;
|
|
106
|
+
date: number;
|
|
107
|
+
status: "paid" | "failed" | "pending";
|
|
108
|
+
transactionId?: string;
|
|
109
|
+
}>;
|
|
110
|
+
metadata?: any;
|
|
111
|
+
createdAt: number;
|
|
112
|
+
updatedAt: number;
|
|
113
|
+
}
|
|
114
|
+
export interface CreateSubscriptionData {
|
|
115
|
+
businessId: string;
|
|
116
|
+
productId: string;
|
|
117
|
+
customerEmail: string;
|
|
118
|
+
customerName: string;
|
|
119
|
+
paymentPlanId: string;
|
|
120
|
+
customerId?: string;
|
|
121
|
+
metadata?: any;
|
|
122
|
+
}
|
|
123
|
+
export interface UpdateSubscriptionData {
|
|
124
|
+
status?: "active" | "cancelled" | "paused" | "expired" | "past_due";
|
|
125
|
+
pauseUntil?: number;
|
|
126
|
+
resumeDate?: number;
|
|
127
|
+
metadata?: any;
|
|
128
|
+
}
|
|
39
129
|
export interface TorqueConfig {
|
|
40
130
|
businessId?: string;
|
|
41
131
|
apiKey?: string;
|
|
@@ -128,6 +218,10 @@ export declare class TorqueCheckout {
|
|
|
128
218
|
* Generate a single product checkout URL
|
|
129
219
|
*/
|
|
130
220
|
generateProductCheckoutUrl(productId: string, quantity?: number, customer?: CustomerData, options?: CartOptions): Promise<string>;
|
|
221
|
+
/**
|
|
222
|
+
* Generate a subscription checkout URL
|
|
223
|
+
*/
|
|
224
|
+
generateSubscriptionCheckoutUrl(productId: string, paymentPlanId: string, customer?: CustomerData, options?: CartOptions): Promise<string>;
|
|
131
225
|
/**
|
|
132
226
|
* Validate cart data before checkout
|
|
133
227
|
*/
|
|
@@ -136,6 +230,54 @@ export declare class TorqueCheckout {
|
|
|
136
230
|
* Get order status
|
|
137
231
|
*/
|
|
138
232
|
getOrderStatus(orderId: string): Promise<OrderStatus>;
|
|
233
|
+
/**
|
|
234
|
+
* Create a new subscription
|
|
235
|
+
*/
|
|
236
|
+
createSubscription(data: CreateSubscriptionData): Promise<Subscription>;
|
|
237
|
+
/**
|
|
238
|
+
* Get subscription by ID
|
|
239
|
+
*/
|
|
240
|
+
getSubscription(subscriptionId: string): Promise<Subscription>;
|
|
241
|
+
/**
|
|
242
|
+
* Get subscriptions for a business
|
|
243
|
+
*/
|
|
244
|
+
getBusinessSubscriptions(businessId: string, status?: string, limit?: number): Promise<Subscription[]>;
|
|
245
|
+
/**
|
|
246
|
+
* Get subscriptions for a customer
|
|
247
|
+
*/
|
|
248
|
+
getCustomerSubscriptions(customerEmail: string): Promise<Subscription[]>;
|
|
249
|
+
/**
|
|
250
|
+
* Update subscription status
|
|
251
|
+
*/
|
|
252
|
+
updateSubscription(subscriptionId: string, data: UpdateSubscriptionData): Promise<Subscription>;
|
|
253
|
+
/**
|
|
254
|
+
* Cancel subscription
|
|
255
|
+
*/
|
|
256
|
+
cancelSubscription(subscriptionId: string, effectiveDate?: number): Promise<Subscription>;
|
|
257
|
+
/**
|
|
258
|
+
* Pause subscription
|
|
259
|
+
*/
|
|
260
|
+
pauseSubscription(subscriptionId: string, resumeDate?: number): Promise<Subscription>;
|
|
261
|
+
/**
|
|
262
|
+
* Resume subscription
|
|
263
|
+
*/
|
|
264
|
+
resumeSubscription(subscriptionId: string): Promise<Subscription>;
|
|
265
|
+
/**
|
|
266
|
+
* Process subscription renewal
|
|
267
|
+
*/
|
|
268
|
+
processSubscriptionRenewal(subscriptionId: string): Promise<Subscription>;
|
|
269
|
+
/**
|
|
270
|
+
* Get subscriptions due for renewal
|
|
271
|
+
*/
|
|
272
|
+
getSubscriptionsDueForRenewal(daysAhead?: number): Promise<Subscription[]>;
|
|
273
|
+
/**
|
|
274
|
+
* Get subscription products for a business
|
|
275
|
+
*/
|
|
276
|
+
getSubscriptionProducts(businessId: string): Promise<SubscriptionProduct[]>;
|
|
277
|
+
/**
|
|
278
|
+
* Get product with payment plans
|
|
279
|
+
*/
|
|
280
|
+
getProductWithPaymentPlans(productId: string): Promise<SubscriptionProduct>;
|
|
139
281
|
/**
|
|
140
282
|
* Send webhook event
|
|
141
283
|
*/
|
|
@@ -148,14 +290,22 @@ export declare class TorqueCheckout {
|
|
|
148
290
|
* Track checkout completion for analytics
|
|
149
291
|
*/
|
|
150
292
|
trackCheckoutComplete(orderId: string, checkoutData: any): Promise<void>;
|
|
293
|
+
/**
|
|
294
|
+
* Track subscription creation for analytics
|
|
295
|
+
*/
|
|
296
|
+
trackSubscriptionCreated(subscriptionId: string, subscriptionData: any): Promise<void>;
|
|
151
297
|
/**
|
|
152
298
|
* Generate cart hash for caching
|
|
153
299
|
*/
|
|
154
300
|
generateCartHash(cart: CartData): string;
|
|
301
|
+
/**
|
|
302
|
+
* Generate subscription hash for caching
|
|
303
|
+
*/
|
|
304
|
+
generateSubscriptionHash(subscriptionData: CreateSubscriptionData): string;
|
|
155
305
|
/**
|
|
156
306
|
* Make HTTP request to Torque API
|
|
157
307
|
*/
|
|
158
308
|
private makeRequest;
|
|
159
309
|
}
|
|
160
310
|
export declare const createTorqueCheckout: (config: TorqueConfig) => TorqueCheckout;
|
|
161
|
-
export type { CartItem, CustomerData, CartOptions, CartData, TorqueConfig, CheckoutResponse, OrderStatus, CartValidation };
|
|
311
|
+
export type { CartItem, CustomerData, CartOptions, CartData, PaymentPlan, SubscriptionProduct, Subscription, CreateSubscriptionData, UpdateSubscriptionData, TorqueConfig, CheckoutResponse, OrderStatus, CartValidation };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class TorqueCheckout {
|
|
2
2
|
constructor(config) {
|
|
3
|
-
this.baseUrl = '
|
|
3
|
+
this.baseUrl = '';
|
|
4
4
|
this.businessId = config.businessId;
|
|
5
5
|
this.apiKey = config.apiKey;
|
|
6
6
|
this.timeout = config.timeout || 30000;
|
|
@@ -9,7 +9,7 @@ class TorqueCheckout {
|
|
|
9
9
|
* Generate a cart checkout URL
|
|
10
10
|
*/
|
|
11
11
|
async generateCartCheckoutUrl(cart) {
|
|
12
|
-
const response = await this.makeRequest('/api/checkout
|
|
12
|
+
const response = await this.makeRequest('/api/torque-checkout', {
|
|
13
13
|
method: 'POST',
|
|
14
14
|
body: {
|
|
15
15
|
businessId: this.businessId,
|
|
@@ -35,6 +35,23 @@ class TorqueCheckout {
|
|
|
35
35
|
options
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Generate a subscription checkout URL
|
|
40
|
+
*/
|
|
41
|
+
async generateSubscriptionCheckoutUrl(productId, paymentPlanId, customer, options) {
|
|
42
|
+
return this.generateCartCheckoutUrl({
|
|
43
|
+
items: [{
|
|
44
|
+
productId,
|
|
45
|
+
quantity: 1,
|
|
46
|
+
metadata: {
|
|
47
|
+
isSubscription: true,
|
|
48
|
+
paymentPlanId
|
|
49
|
+
}
|
|
50
|
+
}],
|
|
51
|
+
customer,
|
|
52
|
+
options
|
|
53
|
+
});
|
|
54
|
+
}
|
|
38
55
|
/**
|
|
39
56
|
* Validate cart data before checkout
|
|
40
57
|
*/
|
|
@@ -69,6 +86,149 @@ class TorqueCheckout {
|
|
|
69
86
|
}
|
|
70
87
|
return response;
|
|
71
88
|
}
|
|
89
|
+
// New: Subscription Management Methods
|
|
90
|
+
/**
|
|
91
|
+
* Create a new subscription
|
|
92
|
+
*/
|
|
93
|
+
async createSubscription(data) {
|
|
94
|
+
const response = await this.makeRequest('/api/subscriptions/create', {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
body: data
|
|
97
|
+
});
|
|
98
|
+
if (response.error) {
|
|
99
|
+
throw new Error(`Failed to create subscription: ${response.error}`);
|
|
100
|
+
}
|
|
101
|
+
return response;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get subscription by ID
|
|
105
|
+
*/
|
|
106
|
+
async getSubscription(subscriptionId) {
|
|
107
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}`);
|
|
108
|
+
if (response.error) {
|
|
109
|
+
throw new Error(`Failed to get subscription: ${response.error}`);
|
|
110
|
+
}
|
|
111
|
+
return response;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get subscriptions for a business
|
|
115
|
+
*/
|
|
116
|
+
async getBusinessSubscriptions(businessId, status, limit) {
|
|
117
|
+
const params = new URLSearchParams({ businessId });
|
|
118
|
+
if (status)
|
|
119
|
+
params.append('status', status);
|
|
120
|
+
if (limit)
|
|
121
|
+
params.append('limit', limit.toString());
|
|
122
|
+
const response = await this.makeRequest(`/api/subscriptions/business?${params}`);
|
|
123
|
+
if (response.error) {
|
|
124
|
+
throw new Error(`Failed to get business subscriptions: ${response.error}`);
|
|
125
|
+
}
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get subscriptions for a customer
|
|
130
|
+
*/
|
|
131
|
+
async getCustomerSubscriptions(customerEmail) {
|
|
132
|
+
const response = await this.makeRequest(`/api/subscriptions/customer/${encodeURIComponent(customerEmail)}`);
|
|
133
|
+
if (response.error) {
|
|
134
|
+
throw new Error(`Failed to get customer subscriptions: ${response.error}`);
|
|
135
|
+
}
|
|
136
|
+
return response;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Update subscription status
|
|
140
|
+
*/
|
|
141
|
+
async updateSubscription(subscriptionId, data) {
|
|
142
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/update`, {
|
|
143
|
+
method: 'PUT',
|
|
144
|
+
body: data
|
|
145
|
+
});
|
|
146
|
+
if (response.error) {
|
|
147
|
+
throw new Error(`Failed to update subscription: ${response.error}`);
|
|
148
|
+
}
|
|
149
|
+
return response;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Cancel subscription
|
|
153
|
+
*/
|
|
154
|
+
async cancelSubscription(subscriptionId, effectiveDate) {
|
|
155
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/cancel`, {
|
|
156
|
+
method: 'PUT',
|
|
157
|
+
body: { effectiveDate }
|
|
158
|
+
});
|
|
159
|
+
if (response.error) {
|
|
160
|
+
throw new Error(`Failed to cancel subscription: ${response.error}`);
|
|
161
|
+
}
|
|
162
|
+
return response;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Pause subscription
|
|
166
|
+
*/
|
|
167
|
+
async pauseSubscription(subscriptionId, resumeDate) {
|
|
168
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/pause`, {
|
|
169
|
+
method: 'PUT',
|
|
170
|
+
body: { resumeDate }
|
|
171
|
+
});
|
|
172
|
+
if (response.error) {
|
|
173
|
+
throw new Error(`Failed to pause subscription: ${response.error}`);
|
|
174
|
+
}
|
|
175
|
+
return response;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Resume subscription
|
|
179
|
+
*/
|
|
180
|
+
async resumeSubscription(subscriptionId) {
|
|
181
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/resume`, {
|
|
182
|
+
method: 'PUT'
|
|
183
|
+
});
|
|
184
|
+
if (response.error) {
|
|
185
|
+
throw new Error(`Failed to resume subscription: ${response.error}`);
|
|
186
|
+
}
|
|
187
|
+
return response;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Process subscription renewal
|
|
191
|
+
*/
|
|
192
|
+
async processSubscriptionRenewal(subscriptionId) {
|
|
193
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/renew`, {
|
|
194
|
+
method: 'PUT'
|
|
195
|
+
});
|
|
196
|
+
if (response.error) {
|
|
197
|
+
throw new Error(`Failed to process subscription renewal: ${response.error}`);
|
|
198
|
+
}
|
|
199
|
+
return response;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get subscriptions due for renewal
|
|
203
|
+
*/
|
|
204
|
+
async getSubscriptionsDueForRenewal(daysAhead = 7) {
|
|
205
|
+
const response = await this.makeRequest(`/api/subscriptions/due-for-renewal?daysAhead=${daysAhead}`);
|
|
206
|
+
if (response.error) {
|
|
207
|
+
throw new Error(`Failed to get subscriptions due for renewal: ${response.error}`);
|
|
208
|
+
}
|
|
209
|
+
return response;
|
|
210
|
+
}
|
|
211
|
+
// New: Product Management Methods
|
|
212
|
+
/**
|
|
213
|
+
* Get subscription products for a business
|
|
214
|
+
*/
|
|
215
|
+
async getSubscriptionProducts(businessId) {
|
|
216
|
+
const response = await this.makeRequest(`/api/products/subscriptions?businessId=${businessId}`);
|
|
217
|
+
if (response.error) {
|
|
218
|
+
throw new Error(`Failed to get subscription products: ${response.error}`);
|
|
219
|
+
}
|
|
220
|
+
return response;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get product with payment plans
|
|
224
|
+
*/
|
|
225
|
+
async getProductWithPaymentPlans(productId) {
|
|
226
|
+
const response = await this.makeRequest(`/api/products/${productId}`);
|
|
227
|
+
if (response.error) {
|
|
228
|
+
throw new Error(`Failed to get product: ${response.error}`);
|
|
229
|
+
}
|
|
230
|
+
return response;
|
|
231
|
+
}
|
|
72
232
|
/**
|
|
73
233
|
* Send webhook event
|
|
74
234
|
*/
|
|
@@ -121,6 +281,25 @@ class TorqueCheckout {
|
|
|
121
281
|
console.warn('Failed to track checkout completion:', error);
|
|
122
282
|
}
|
|
123
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Track subscription creation for analytics
|
|
286
|
+
*/
|
|
287
|
+
async trackSubscriptionCreated(subscriptionId, subscriptionData) {
|
|
288
|
+
try {
|
|
289
|
+
await this.makeRequest('/api/analytics/subscription-created', {
|
|
290
|
+
method: 'POST',
|
|
291
|
+
body: {
|
|
292
|
+
subscriptionId,
|
|
293
|
+
businessId: this.businessId,
|
|
294
|
+
subscriptionData,
|
|
295
|
+
timestamp: Date.now()
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
console.warn('Failed to track subscription creation:', error);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
124
303
|
/**
|
|
125
304
|
* Generate cart hash for caching
|
|
126
305
|
*/
|
|
@@ -138,6 +317,24 @@ class TorqueCheckout {
|
|
|
138
317
|
}
|
|
139
318
|
return Math.abs(hash).toString(36);
|
|
140
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Generate subscription hash for caching
|
|
322
|
+
*/
|
|
323
|
+
generateSubscriptionHash(subscriptionData) {
|
|
324
|
+
const subscriptionString = JSON.stringify({
|
|
325
|
+
businessId: subscriptionData.businessId,
|
|
326
|
+
productId: subscriptionData.productId,
|
|
327
|
+
customerEmail: subscriptionData.customerEmail,
|
|
328
|
+
paymentPlanId: subscriptionData.paymentPlanId
|
|
329
|
+
});
|
|
330
|
+
let hash = 0;
|
|
331
|
+
for (let i = 0; i < subscriptionString.length; i++) {
|
|
332
|
+
const char = subscriptionString.charCodeAt(i);
|
|
333
|
+
hash = ((hash << 5) - hash) + char;
|
|
334
|
+
hash = hash & hash;
|
|
335
|
+
}
|
|
336
|
+
return Math.abs(hash).toString(36);
|
|
337
|
+
}
|
|
141
338
|
/**
|
|
142
339
|
* Make HTTP request to Torque API
|
|
143
340
|
*/
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["export interface CartItem {\n productId: string\n quantity: number\n variant?: string\n price?: number\n metadata?: Record<string, any>\n}\n\nexport interface CustomerData {\n email: string\n firstName?: string\n lastName?: string\n phone?: string\n shippingAddress?: {\n street: string\n city: string\n state: string\n zipCode: string\n country: string\n }\n billingAddress?: {\n street: string\n city: string\n state: string\n zipCode: string\n country: string\n }\n}\n\nexport interface CartOptions {\n domain?: string\n expiresIn?: number\n metadata?: Record<string, any>\n redirectUrl?: string\n}\n\nexport interface CartData {\n items: CartItem[]\n customer?: CustomerData\n options?: CartOptions\n}\n\nexport interface TorqueConfig {\n businessId?: string\n apiKey?: string\n timeout?: number\n}\n\nexport interface BusinessCreationData {\n name: string\n description?: string\n email: string\n phone?: string\n website?: string\n currency?: string\n timezone?: string\n walletAddress: string\n logo?: string\n}\n\nexport interface BusinessProfile {\n id: string\n name: string\n email: string\n apiKey: string\n walletAddress: string\n logo?: string\n website?: string\n status: 'active' | 'pending' | 'suspended'\n}\n\nexport interface CheckoutResponse {\n success: boolean\n checkoutUrl: string\n expiresAt: string\n cartSummary: {\n itemCount: number\n productCount: number\n estimatedTotal: number\n }\n business: {\n id: string\n name: string\n logo?: string\n }\n}\n\nexport interface OrderStatus {\n orderId: string\n status: string\n customer: {\n email: string\n firstName?: string\n lastName?: string\n phone?: string\n } | null\n items: Array<{\n productId: string\n productName: string\n productImage?: string\n quantity: number\n variant?: string\n price: number\n total: number\n }>\n totals: {\n subtotal: number\n shipping: number\n tax: number\n total: number\n }\n paymentStatus: string\n shippingAddress?: any\n billingAddress?: any\n createdAt: number\n updatedAt: number\n metadata: Record<string, any>\n}\n\nexport interface CartValidation {\n valid: boolean\n errors: string[]\n warnings: string[]\n estimatedTotal: number\n}\n\nexport class TorqueCheckout {\n private businessId: string\n private apiKey: string\n private baseUrl: string = 'https://app.torque.fi'\n private timeout: number\n\n constructor(config: TorqueConfig) {\n this.businessId = config.businessId\n this.apiKey = config.apiKey\n this.timeout = config.timeout || 30000\n }\n\n /**\n * Generate a cart checkout URL\n */\n async generateCartCheckoutUrl(cart: CartData): Promise<string> {\n const response = await this.makeRequest('/api/checkout/generate-link', {\n method: 'POST',\n body: {\n businessId: this.businessId,\n cart: {\n items: cart.items\n },\n customerData: cart.customer,\n options: cart.options\n }\n })\n\n if (!response.success) {\n throw new Error(`Failed to generate checkout URL: ${response.error || 'Unknown error'}`)\n }\n\n return response.checkoutUrl\n }\n\n /**\n * Generate a single product checkout URL\n */\n async generateProductCheckoutUrl(productId: string, quantity: number = 1, customer?: CustomerData, options?: CartOptions): Promise<string> {\n return this.generateCartCheckoutUrl({\n items: [{ productId, quantity }],\n customer,\n options\n })\n }\n\n /**\n * Validate cart data before checkout\n */\n async validateCart(cart: CartData): Promise<CartValidation> {\n try {\n const response = await this.makeRequest('/api/checkout/validate-cart', {\n method: 'POST',\n body: {\n businessId: this.businessId,\n cart: cart.items,\n customer: cart.customer\n }\n })\n\n return response\n } catch (error) {\n return {\n valid: false,\n errors: [error instanceof Error ? error.message : 'Validation failed'],\n warnings: [],\n estimatedTotal: 0\n }\n }\n }\n\n /**\n * Get order status\n */\n async getOrderStatus(orderId: string): Promise<OrderStatus> {\n const response = await this.makeRequest(`/api/checkout/order-status/${orderId}?businessId=${this.businessId}`)\n \n if (response.error) {\n throw new Error(`Failed to get order status: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Send webhook event\n */\n async sendWebhookEvent(orderId: string, status: string, customerData?: any, metadata?: Record<string, any>): Promise<void> {\n await this.makeRequest('/api/webhooks/order-update', {\n method: 'POST',\n body: {\n orderId,\n status,\n customerData,\n metadata\n }\n })\n }\n\n /**\n * Track cart view for analytics\n */\n async trackCartView(cartId: string, cartData: CartData): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/cart-view', {\n method: 'POST',\n body: {\n cartId,\n businessId: this.businessId,\n cartData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track cart view:', error)\n }\n }\n\n /**\n * Track checkout completion for analytics\n */\n async trackCheckoutComplete(orderId: string, checkoutData: any): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/checkout-complete', {\n method: 'POST',\n body: {\n orderId,\n businessId: this.businessId,\n checkoutData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track checkout completion:', error)\n }\n }\n\n /**\n * Generate cart hash for caching\n */\n generateCartHash(cart: CartData): string {\n const cartString = JSON.stringify({\n items: cart.items.sort((a, b) => a.productId.localeCompare(b.productId)),\n customer: cart.customer ? { email: cart.customer.email } : null\n })\n \n // Simple hash function for cart identification\n let hash = 0\n for (let i = 0; i < cartString.length; i++) {\n const char = cartString.charCodeAt(i)\n hash = ((hash << 5) - hash) + char\n hash = hash & hash // Convert to 32-bit integer\n }\n return Math.abs(hash).toString(36)\n }\n\n /**\n * Make HTTP request to Torque API\n */\n private async makeRequest(endpoint: string, options: RequestInit = {}): Promise<any> {\n const url = `${this.baseUrl}${endpoint}`\n \n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), this.timeout)\n\n try {\n const response = await fetch(url, {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`,\n ...options.headers\n },\n signal: controller.signal\n })\n\n clearTimeout(timeoutId)\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}))\n throw new Error(errorData.message || `HTTP ${response.status}: ${response.statusText}`)\n }\n\n return await response.json()\n } catch (error) {\n clearTimeout(timeoutId)\n \n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new Error('Request timeout')\n }\n throw error\n }\n \n throw new Error('Request failed')\n }\n }\n}\n\n// Export default instance factory\nexport const createTorqueCheckout = (config: TorqueConfig) => new TorqueCheckout(config)\n\n// Export types\nexport type {\n CartItem,\n CustomerData,\n CartOptions,\n CartData,\n TorqueConfig,\n CheckoutResponse,\n OrderStatus,\n CartValidation\n}\n"],"names":[],"mappings":"MA8Ha,cAAc,CAAA;AAMzB,IAAA,WAAA,CAAY,MAAoB,EAAA;QAHxB,IAAA,CAAA,OAAO,GAAW,uBAAuB;AAI/C,QAAA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;AACnC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK;IACxC;AAEA;;AAEG;IACH,MAAM,uBAAuB,CAAC,IAAc,EAAA;QAC1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,6BAA6B,EAAE;AACrE,YAAA,MAAM,EAAE,MAAM;AACd,YAAA,IAAI,EAAE;gBACJ,UAAU,EAAE,IAAI,CAAC,UAAU;AAC3B,gBAAA,IAAI,EAAE;oBACJ,KAAK,EAAE,IAAI,CAAC;AACb,iBAAA;gBACD,YAAY,EAAE,IAAI,CAAC,QAAQ;gBAC3B,OAAO,EAAE,IAAI,CAAC;AACf;AACF,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,CAAA,iCAAA,EAAoC,QAAQ,CAAC,KAAK,IAAI,eAAe,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AC,MAAM,CAAA,CAAE;oBACxC,GAAG,OAAO,CAAC;AACZ,iBAAA;gBACD,MAAM,EAAE,UAAU,CAAC;AACpB,aAAA,CAAC;YAEF,YAAY,CAAC,SAAS,CAAC;AAEvB,YAAA,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;AAChB,gBAAA,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AACzD,gBAAA,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,IAAI,CAAA,KAAA,EAAQ,QAAQ,CAAC,MAAM,CAAA,EAAA,EAAK,QAAQ,CAAC,UAAU,CAAA,CAAE,CAAC;YACzF;AAEA,YAAA,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE;QAC9B;QAAE,OAAO,KAAK,EAAE;YACd,YAAY,CAAC,SAAS,CAAC;AAEvB,YAAA,IAAI,KAAK,YAAY,KAAK,EAAE;AAC1B,gBAAA,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;AAC/B,oBAAA,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC;gBACpC;AACA,gBAAA,MAAM,KAAK;YACb;AAEA,YAAA,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC;QACnC;IACF;AACD;AAED;AACO,MAAM,oBAAoB,GAAG,CAAC,MAAoB,KAAK,IAAI,cAAc,CAAC,MAAM;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["export interface CartItem {\n productId: string\n quantity: number\n variant?: string\n price?: number\n metadata?: Record<string, any>\n}\n\nexport interface CustomerData {\n email: string\n firstName?: string\n lastName?: string\n phone?: string\n shippingAddress?: {\n street: string\n city: string\n state: string\n zipCode: string\n country: string\n }\n billingAddress?: {\n street: string\n city: string\n state: string\n zipCode: string\n country: string\n }\n}\n\nexport interface CartOptions {\n domain?: string\n expiresIn?: number\n metadata?: Record<string, any>\n redirectUrl?: string\n}\n\nexport interface CartData {\n items: CartItem[]\n customer?: CustomerData\n options?: CartOptions\n}\n\n// New: Payment Plan Interface\nexport interface PaymentPlan {\n id: string\n name: string\n price: number\n interval: \"weekly\" | \"monthly\" | \"quarterly\" | \"yearly\"\n intervalCount: number\n trialDays?: number\n maxCycles?: number\n description?: string\n}\n\n// New: Subscription Product Interface\nexport interface SubscriptionProduct {\n id: string\n name: string\n description?: string\n isSubscription: boolean\n paymentPlans?: PaymentPlan[]\n subscriptionContract?: {\n address: string\n chainId: number\n abi?: string\n }\n basePrice: number\n currency: string\n image?: string\n images?: string[]\n requiresShipping: boolean\n shippingCost?: number\n taxRate?: number\n inventory: number\n status: 'active' | 'inactive' | 'draft' | 'archived'\n sku?: string\n category?: string\n tags?: string[]\n variants?: Array<{\n id: string\n name: string\n price: number\n inventory?: number\n }>\n metadata?: any\n createdAt: number\n updatedAt: number\n}\n\n// New: Subscription Interface\nexport interface Subscription {\n id: string\n businessId: string\n productId: string\n customerId?: string\n customerEmail: string\n customerName: string\n paymentPlanId: string\n status: \"active\" | \"cancelled\" | \"paused\" | \"expired\" | \"past_due\"\n currentPeriodStart: number\n currentPeriodEnd: number\n nextBillingDate: number\n trialStart?: number\n trialEnd?: number\n totalCycles: number\n maxCycles?: number\n lastPaymentDate?: number\n nextPaymentAmount: number\n currency: string\n contractSubscriptionId?: string\n contractAddress?: string\n billingHistory?: Array<{\n cycleNumber: number\n amount: number\n date: number\n status: \"paid\" | \"failed\" | \"pending\"\n transactionId?: string\n }>\n metadata?: any\n createdAt: number\n updatedAt: number\n}\n\n// New: Subscription Creation Data\nexport interface CreateSubscriptionData {\n businessId: string\n productId: string\n customerEmail: string\n customerName: string\n paymentPlanId: string\n customerId?: string\n metadata?: any\n}\n\n// New: Subscription Update Data\nexport interface UpdateSubscriptionData {\n status?: \"active\" | \"cancelled\" | \"paused\" | \"expired\" | \"past_due\"\n pauseUntil?: number\n resumeDate?: number\n metadata?: any\n}\n\nexport interface TorqueConfig {\n businessId?: string\n apiKey?: string\n timeout?: number\n}\n\nexport interface BusinessCreationData {\n name: string\n description?: string\n email: string\n phone?: string\n website?: string\n currency?: string\n timezone?: string\n walletAddress: string\n logo?: string\n}\n\nexport interface BusinessProfile {\n id: string\n name: string\n email: string\n apiKey: string\n walletAddress: string\n logo?: string\n website?: string\n status: 'active' | 'pending' | 'suspended'\n}\n\nexport interface CheckoutResponse {\n success: boolean\n checkoutUrl: string\n expiresAt: string\n cartSummary: {\n itemCount: number\n productCount: number\n estimatedTotal: number\n }\n business: {\n id: string\n name: string\n logo?: string\n }\n}\n\nexport interface OrderStatus {\n orderId: string\n status: string\n customer: {\n email: string\n firstName?: string\n lastName?: string\n phone?: string\n } | null\n items: Array<{\n productId: string\n productName: string\n productImage?: string\n quantity: number\n variant?: string\n price: number\n total: number\n }>\n totals: {\n subtotal: number\n shipping: number\n tax: number\n total: number\n }\n paymentStatus: string\n shippingAddress?: any\n billingAddress?: any\n createdAt: number\n updatedAt: number\n metadata: Record<string, any>\n}\n\nexport interface CartValidation {\n valid: boolean\n errors: string[]\n warnings: string[]\n estimatedTotal: number\n}\n\nexport class TorqueCheckout {\n private businessId: string\n private apiKey: string\n private baseUrl: string = ''\n private timeout: number\n\n constructor(config: TorqueConfig) {\n this.businessId = config.businessId\n this.apiKey = config.apiKey\n this.timeout = config.timeout || 30000\n }\n\n /**\n * Generate a cart checkout URL\n */\n async generateCartCheckoutUrl(cart: CartData): Promise<string> {\n const response = await this.makeRequest('/api/torque-checkout', {\n method: 'POST',\n body: {\n businessId: this.businessId,\n cart: {\n items: cart.items\n },\n customerData: cart.customer,\n options: cart.options\n }\n })\n\n if (!response.success) {\n throw new Error(`Failed to generate checkout URL: ${response.error || 'Unknown error'}`)\n }\n\n return response.checkoutUrl\n }\n\n /**\n * Generate a single product checkout URL\n */\n async generateProductCheckoutUrl(productId: string, quantity: number = 1, customer?: CustomerData, options?: CartOptions): Promise<string> {\n return this.generateCartCheckoutUrl({\n items: [{ productId, quantity }],\n customer,\n options\n })\n }\n\n /**\n * Generate a subscription checkout URL\n */\n async generateSubscriptionCheckoutUrl(productId: string, paymentPlanId: string, customer?: CustomerData, options?: CartOptions): Promise<string> {\n return this.generateCartCheckoutUrl({\n items: [{ \n productId, \n quantity: 1,\n metadata: { \n isSubscription: true, \n paymentPlanId \n }\n }],\n customer,\n options\n })\n }\n\n /**\n * Validate cart data before checkout\n */\n async validateCart(cart: CartData): Promise<CartValidation> {\n try {\n const response = await this.makeRequest('/api/checkout/validate-cart', {\n method: 'POST',\n body: {\n businessId: this.businessId,\n cart: cart.items,\n customer: cart.customer\n }\n })\n\n return response\n } catch (error) {\n return {\n valid: false,\n errors: [error instanceof Error ? error.message : 'Validation failed'],\n warnings: [],\n estimatedTotal: 0\n }\n }\n }\n\n /**\n * Get order status\n */\n async getOrderStatus(orderId: string): Promise<OrderStatus> {\n const response = await this.makeRequest(`/api/checkout/order-status/${orderId}?businessId=${this.businessId}`)\n \n if (response.error) {\n throw new Error(`Failed to get order status: ${response.error}`)\n }\n\n return response\n }\n\n // New: Subscription Management Methods\n\n /**\n * Create a new subscription\n */\n async createSubscription(data: CreateSubscriptionData): Promise<Subscription> {\n const response = await this.makeRequest('/api/subscriptions/create', {\n method: 'POST',\n body: data\n })\n\n if (response.error) {\n throw new Error(`Failed to create subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get subscription by ID\n */\n async getSubscription(subscriptionId: string): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}`)\n \n if (response.error) {\n throw new Error(`Failed to get subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get subscriptions for a business\n */\n async getBusinessSubscriptions(businessId: string, status?: string, limit?: number): Promise<Subscription[]> {\n const params = new URLSearchParams({ businessId })\n if (status) params.append('status', status)\n if (limit) params.append('limit', limit.toString())\n\n const response = await this.makeRequest(`/api/subscriptions/business?${params}`)\n \n if (response.error) {\n throw new Error(`Failed to get business subscriptions: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get subscriptions for a customer\n */\n async getCustomerSubscriptions(customerEmail: string): Promise<Subscription[]> {\n const response = await this.makeRequest(`/api/subscriptions/customer/${encodeURIComponent(customerEmail)}`)\n \n if (response.error) {\n throw new Error(`Failed to get customer subscriptions: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Update subscription status\n */\n async updateSubscription(subscriptionId: string, data: UpdateSubscriptionData): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/update`, {\n method: 'PUT',\n body: data\n })\n\n if (response.error) {\n throw new Error(`Failed to update subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Cancel subscription\n */\n async cancelSubscription(subscriptionId: string, effectiveDate?: number): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/cancel`, {\n method: 'PUT',\n body: { effectiveDate }\n })\n\n if (response.error) {\n throw new Error(`Failed to cancel subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Pause subscription\n */\n async pauseSubscription(subscriptionId: string, resumeDate?: number): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/pause`, {\n method: 'PUT',\n body: { resumeDate }\n })\n\n if (response.error) {\n throw new Error(`Failed to pause subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Resume subscription\n */\n async resumeSubscription(subscriptionId: string): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/resume`, {\n method: 'PUT'\n })\n\n if (response.error) {\n throw new Error(`Failed to resume subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Process subscription renewal\n */\n async processSubscriptionRenewal(subscriptionId: string): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/renew`, {\n method: 'PUT'\n })\n\n if (response.error) {\n throw new Error(`Failed to process subscription renewal: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get subscriptions due for renewal\n */\n async getSubscriptionsDueForRenewal(daysAhead: number = 7): Promise<Subscription[]> {\n const response = await this.makeRequest(`/api/subscriptions/due-for-renewal?daysAhead=${daysAhead}`)\n \n if (response.error) {\n throw new Error(`Failed to get subscriptions due for renewal: ${response.error}`)\n }\n\n return response\n }\n\n // New: Product Management Methods\n\n /**\n * Get subscription products for a business\n */\n async getSubscriptionProducts(businessId: string): Promise<SubscriptionProduct[]> {\n const response = await this.makeRequest(`/api/products/subscriptions?businessId=${businessId}`)\n \n if (response.error) {\n throw new Error(`Failed to get subscription products: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get product with payment plans\n */\n async getProductWithPaymentPlans(productId: string): Promise<SubscriptionProduct> {\n const response = await this.makeRequest(`/api/products/${productId}`)\n \n if (response.error) {\n throw new Error(`Failed to get product: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Send webhook event\n */\n async sendWebhookEvent(orderId: string, status: string, customerData?: any, metadata?: Record<string, any>): Promise<void> {\n await this.makeRequest('/api/webhooks/order-update', {\n method: 'POST',\n body: {\n orderId,\n status,\n customerData,\n metadata\n }\n })\n }\n\n /**\n * Track cart view for analytics\n */\n async trackCartView(cartId: string, cartData: CartData): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/cart-view', {\n method: 'POST',\n body: {\n cartId,\n businessId: this.businessId,\n cartData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track cart view:', error)\n }\n }\n\n /**\n * Track checkout completion for analytics\n */\n async trackCheckoutComplete(orderId: string, checkoutData: any): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/checkout-complete', {\n method: 'POST',\n body: {\n orderId,\n businessId: this.businessId,\n checkoutData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track checkout completion:', error)\n }\n }\n\n /**\n * Track subscription creation for analytics\n */\n async trackSubscriptionCreated(subscriptionId: string, subscriptionData: any): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/subscription-created', {\n method: 'POST',\n body: {\n subscriptionId,\n businessId: this.businessId,\n subscriptionData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track subscription creation:', error)\n }\n }\n\n /**\n * Generate cart hash for caching\n */\n generateCartHash(cart: CartData): string {\n const cartString = JSON.stringify({\n items: cart.items.sort((a, b) => a.productId.localeCompare(b.productId)),\n customer: cart.customer ? { email: cart.customer.email } : null\n })\n \n // Simple hash function for cart identification\n let hash = 0\n for (let i = 0; i < cartString.length; i++) {\n const char = cartString.charCodeAt(i)\n hash = ((hash << 5) - hash) + char\n hash = hash & hash // Convert to 32-bit integer\n }\n return Math.abs(hash).toString(36)\n }\n\n /**\n * Generate subscription hash for caching\n */\n generateSubscriptionHash(subscriptionData: CreateSubscriptionData): string {\n const subscriptionString = JSON.stringify({\n businessId: subscriptionData.businessId,\n productId: subscriptionData.productId,\n customerEmail: subscriptionData.customerEmail,\n paymentPlanId: subscriptionData.paymentPlanId\n })\n \n let hash = 0\n for (let i = 0; i < subscriptionString.length; i++) {\n const char = subscriptionString.charCodeAt(i)\n hash = ((hash << 5) - hash) + char\n hash = hash & hash\n }\n return Math.abs(hash).toString(36)\n }\n\n /**\n * Make HTTP request to Torque API\n */\n private async makeRequest(endpoint: string, options: RequestInit = {}): Promise<any> {\n const url = `${this.baseUrl}${endpoint}`\n \n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), this.timeout)\n\n try {\n const response = await fetch(url, {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`,\n ...options.headers\n },\n signal: controller.signal\n })\n\n clearTimeout(timeoutId)\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}))\n throw new Error(errorData.message || `HTTP ${response.status}: ${response.statusText}`)\n }\n\n return await response.json()\n } catch (error) {\n clearTimeout(timeoutId)\n \n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new Error('Request timeout')\n }\n throw error\n }\n \n throw new Error('Request failed')\n }\n }\n}\n\n// Export default instance factory\nexport const createTorqueCheckout = (config: TorqueConfig) => new TorqueCheckout(config)\n\n// Export types\nexport type {\n CartItem,\n CustomerData,\n CartOptions,\n CartData,\n PaymentPlan,\n SubscriptionProduct,\n Subscription,\n CreateSubscriptionData,\n UpdateSubscriptionData,\n TorqueConfig,\n CheckoutResponse,\n OrderStatus,\n CartValidation\n}\n"],"names":[],"mappings":"MAkOa,cAAc,CAAA;AAMzB,IAAA,WAAA,CAAY,MAAoB,EAAA;QAHxB,IAAA,CAAA,OAAO,GAAW,EAAE;AAI1B,QAAA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;AACnC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK;IACxC;AAEA;;AAEG;IACH,MAAM,uBAAuB,CAAC,IAAc,EAAA;QAC1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,sBAAsB,EAAE;AAC9D,YAAA,MAAM,EAAE,MAAM;AACd,YAAA,IAAI,EAAE;gBACJ,UAAU,EAAE,IAAI,CAAC,UAAU;AAC3B,gBAAA,IAAI,EAAE;oBACJ,KAAK,EAAE,IAAI,CAAC;AACb,iBAAA;gBACD,YAAY,EAAE,IAAI,CAAC,QAAQ;gBAC3B,OAAO,EAAE,IAAI,CAAC;AACf;AACF,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,CAAA,iCAAA,EAAoC,QAAQ,CAAC,KAAK,IAAI,eAAe,CAAA,CAAE,CAAC;QAC1F;QAEA,OAAO,QAAQ,CAAC,WAAW;IAC7B;AAEA;;AAEG;IACH,MAAM,0BAA0B,CAAC,SAAiB,EAAE,WAAmB,CAAC,EAAE,QAAuB,EAAE,OAAqB,EAAA;QACtH,OAAO,IAAI,CAAC,uBAAuB,CAAC;AAClC,YAAA,KAAK,EAAE,CAAC,E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,CAAC,SAAS,CAAC,OAAO,IAAI,CAAA,KAAA,EAAQ,QAAQ,CAAC,MAAM,CAAA,EAAA,EAAK,QAAQ,CAAC,UAAU,CAAA,CAAE,CAAC;YACzF;AAEA,YAAA,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE;QAC9B;QAAE,OAAO,KAAK,EAAE;YACd,YAAY,CAAC,SAAS,CAAC;AAEvB,YAAA,IAAI,KAAK,YAAY,KAAK,EAAE;AAC1B,gBAAA,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;AAC/B,oBAAA,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC;gBACpC;AACA,gBAAA,MAAM,KAAK;YACb;AAEA,YAAA,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC;QACnC;IACF;AACD;AAED;AACO,MAAM,oBAAoB,GAAG,CAAC,MAAoB,KAAK,IAAI,cAAc,CAAC,MAAM;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
class TorqueCheckout {
|
|
4
4
|
constructor(config) {
|
|
5
|
-
this.baseUrl = '
|
|
5
|
+
this.baseUrl = '';
|
|
6
6
|
this.businessId = config.businessId;
|
|
7
7
|
this.apiKey = config.apiKey;
|
|
8
8
|
this.timeout = config.timeout || 30000;
|
|
@@ -11,7 +11,7 @@ class TorqueCheckout {
|
|
|
11
11
|
* Generate a cart checkout URL
|
|
12
12
|
*/
|
|
13
13
|
async generateCartCheckoutUrl(cart) {
|
|
14
|
-
const response = await this.makeRequest('/api/checkout
|
|
14
|
+
const response = await this.makeRequest('/api/torque-checkout', {
|
|
15
15
|
method: 'POST',
|
|
16
16
|
body: {
|
|
17
17
|
businessId: this.businessId,
|
|
@@ -37,6 +37,23 @@ class TorqueCheckout {
|
|
|
37
37
|
options
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Generate a subscription checkout URL
|
|
42
|
+
*/
|
|
43
|
+
async generateSubscriptionCheckoutUrl(productId, paymentPlanId, customer, options) {
|
|
44
|
+
return this.generateCartCheckoutUrl({
|
|
45
|
+
items: [{
|
|
46
|
+
productId,
|
|
47
|
+
quantity: 1,
|
|
48
|
+
metadata: {
|
|
49
|
+
isSubscription: true,
|
|
50
|
+
paymentPlanId
|
|
51
|
+
}
|
|
52
|
+
}],
|
|
53
|
+
customer,
|
|
54
|
+
options
|
|
55
|
+
});
|
|
56
|
+
}
|
|
40
57
|
/**
|
|
41
58
|
* Validate cart data before checkout
|
|
42
59
|
*/
|
|
@@ -71,6 +88,149 @@ class TorqueCheckout {
|
|
|
71
88
|
}
|
|
72
89
|
return response;
|
|
73
90
|
}
|
|
91
|
+
// New: Subscription Management Methods
|
|
92
|
+
/**
|
|
93
|
+
* Create a new subscription
|
|
94
|
+
*/
|
|
95
|
+
async createSubscription(data) {
|
|
96
|
+
const response = await this.makeRequest('/api/subscriptions/create', {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
body: data
|
|
99
|
+
});
|
|
100
|
+
if (response.error) {
|
|
101
|
+
throw new Error(`Failed to create subscription: ${response.error}`);
|
|
102
|
+
}
|
|
103
|
+
return response;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get subscription by ID
|
|
107
|
+
*/
|
|
108
|
+
async getSubscription(subscriptionId) {
|
|
109
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}`);
|
|
110
|
+
if (response.error) {
|
|
111
|
+
throw new Error(`Failed to get subscription: ${response.error}`);
|
|
112
|
+
}
|
|
113
|
+
return response;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get subscriptions for a business
|
|
117
|
+
*/
|
|
118
|
+
async getBusinessSubscriptions(businessId, status, limit) {
|
|
119
|
+
const params = new URLSearchParams({ businessId });
|
|
120
|
+
if (status)
|
|
121
|
+
params.append('status', status);
|
|
122
|
+
if (limit)
|
|
123
|
+
params.append('limit', limit.toString());
|
|
124
|
+
const response = await this.makeRequest(`/api/subscriptions/business?${params}`);
|
|
125
|
+
if (response.error) {
|
|
126
|
+
throw new Error(`Failed to get business subscriptions: ${response.error}`);
|
|
127
|
+
}
|
|
128
|
+
return response;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get subscriptions for a customer
|
|
132
|
+
*/
|
|
133
|
+
async getCustomerSubscriptions(customerEmail) {
|
|
134
|
+
const response = await this.makeRequest(`/api/subscriptions/customer/${encodeURIComponent(customerEmail)}`);
|
|
135
|
+
if (response.error) {
|
|
136
|
+
throw new Error(`Failed to get customer subscriptions: ${response.error}`);
|
|
137
|
+
}
|
|
138
|
+
return response;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Update subscription status
|
|
142
|
+
*/
|
|
143
|
+
async updateSubscription(subscriptionId, data) {
|
|
144
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/update`, {
|
|
145
|
+
method: 'PUT',
|
|
146
|
+
body: data
|
|
147
|
+
});
|
|
148
|
+
if (response.error) {
|
|
149
|
+
throw new Error(`Failed to update subscription: ${response.error}`);
|
|
150
|
+
}
|
|
151
|
+
return response;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Cancel subscription
|
|
155
|
+
*/
|
|
156
|
+
async cancelSubscription(subscriptionId, effectiveDate) {
|
|
157
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/cancel`, {
|
|
158
|
+
method: 'PUT',
|
|
159
|
+
body: { effectiveDate }
|
|
160
|
+
});
|
|
161
|
+
if (response.error) {
|
|
162
|
+
throw new Error(`Failed to cancel subscription: ${response.error}`);
|
|
163
|
+
}
|
|
164
|
+
return response;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Pause subscription
|
|
168
|
+
*/
|
|
169
|
+
async pauseSubscription(subscriptionId, resumeDate) {
|
|
170
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/pause`, {
|
|
171
|
+
method: 'PUT',
|
|
172
|
+
body: { resumeDate }
|
|
173
|
+
});
|
|
174
|
+
if (response.error) {
|
|
175
|
+
throw new Error(`Failed to pause subscription: ${response.error}`);
|
|
176
|
+
}
|
|
177
|
+
return response;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Resume subscription
|
|
181
|
+
*/
|
|
182
|
+
async resumeSubscription(subscriptionId) {
|
|
183
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/resume`, {
|
|
184
|
+
method: 'PUT'
|
|
185
|
+
});
|
|
186
|
+
if (response.error) {
|
|
187
|
+
throw new Error(`Failed to resume subscription: ${response.error}`);
|
|
188
|
+
}
|
|
189
|
+
return response;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Process subscription renewal
|
|
193
|
+
*/
|
|
194
|
+
async processSubscriptionRenewal(subscriptionId) {
|
|
195
|
+
const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/renew`, {
|
|
196
|
+
method: 'PUT'
|
|
197
|
+
});
|
|
198
|
+
if (response.error) {
|
|
199
|
+
throw new Error(`Failed to process subscription renewal: ${response.error}`);
|
|
200
|
+
}
|
|
201
|
+
return response;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get subscriptions due for renewal
|
|
205
|
+
*/
|
|
206
|
+
async getSubscriptionsDueForRenewal(daysAhead = 7) {
|
|
207
|
+
const response = await this.makeRequest(`/api/subscriptions/due-for-renewal?daysAhead=${daysAhead}`);
|
|
208
|
+
if (response.error) {
|
|
209
|
+
throw new Error(`Failed to get subscriptions due for renewal: ${response.error}`);
|
|
210
|
+
}
|
|
211
|
+
return response;
|
|
212
|
+
}
|
|
213
|
+
// New: Product Management Methods
|
|
214
|
+
/**
|
|
215
|
+
* Get subscription products for a business
|
|
216
|
+
*/
|
|
217
|
+
async getSubscriptionProducts(businessId) {
|
|
218
|
+
const response = await this.makeRequest(`/api/products/subscriptions?businessId=${businessId}`);
|
|
219
|
+
if (response.error) {
|
|
220
|
+
throw new Error(`Failed to get subscription products: ${response.error}`);
|
|
221
|
+
}
|
|
222
|
+
return response;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get product with payment plans
|
|
226
|
+
*/
|
|
227
|
+
async getProductWithPaymentPlans(productId) {
|
|
228
|
+
const response = await this.makeRequest(`/api/products/${productId}`);
|
|
229
|
+
if (response.error) {
|
|
230
|
+
throw new Error(`Failed to get product: ${response.error}`);
|
|
231
|
+
}
|
|
232
|
+
return response;
|
|
233
|
+
}
|
|
74
234
|
/**
|
|
75
235
|
* Send webhook event
|
|
76
236
|
*/
|
|
@@ -123,6 +283,25 @@ class TorqueCheckout {
|
|
|
123
283
|
console.warn('Failed to track checkout completion:', error);
|
|
124
284
|
}
|
|
125
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Track subscription creation for analytics
|
|
288
|
+
*/
|
|
289
|
+
async trackSubscriptionCreated(subscriptionId, subscriptionData) {
|
|
290
|
+
try {
|
|
291
|
+
await this.makeRequest('/api/analytics/subscription-created', {
|
|
292
|
+
method: 'POST',
|
|
293
|
+
body: {
|
|
294
|
+
subscriptionId,
|
|
295
|
+
businessId: this.businessId,
|
|
296
|
+
subscriptionData,
|
|
297
|
+
timestamp: Date.now()
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
console.warn('Failed to track subscription creation:', error);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
126
305
|
/**
|
|
127
306
|
* Generate cart hash for caching
|
|
128
307
|
*/
|
|
@@ -140,6 +319,24 @@ class TorqueCheckout {
|
|
|
140
319
|
}
|
|
141
320
|
return Math.abs(hash).toString(36);
|
|
142
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Generate subscription hash for caching
|
|
324
|
+
*/
|
|
325
|
+
generateSubscriptionHash(subscriptionData) {
|
|
326
|
+
const subscriptionString = JSON.stringify({
|
|
327
|
+
businessId: subscriptionData.businessId,
|
|
328
|
+
productId: subscriptionData.productId,
|
|
329
|
+
customerEmail: subscriptionData.customerEmail,
|
|
330
|
+
paymentPlanId: subscriptionData.paymentPlanId
|
|
331
|
+
});
|
|
332
|
+
let hash = 0;
|
|
333
|
+
for (let i = 0; i < subscriptionString.length; i++) {
|
|
334
|
+
const char = subscriptionString.charCodeAt(i);
|
|
335
|
+
hash = ((hash << 5) - hash) + char;
|
|
336
|
+
hash = hash & hash;
|
|
337
|
+
}
|
|
338
|
+
return Math.abs(hash).toString(36);
|
|
339
|
+
}
|
|
143
340
|
/**
|
|
144
341
|
* Make HTTP request to Torque API
|
|
145
342
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export interface CartItem {\n productId: string\n quantity: number\n variant?: string\n price?: number\n metadata?: Record<string, any>\n}\n\nexport interface CustomerData {\n email: string\n firstName?: string\n lastName?: string\n phone?: string\n shippingAddress?: {\n street: string\n city: string\n state: string\n zipCode: string\n country: string\n }\n billingAddress?: {\n street: string\n city: string\n state: string\n zipCode: string\n country: string\n }\n}\n\nexport interface CartOptions {\n domain?: string\n expiresIn?: number\n metadata?: Record<string, any>\n redirectUrl?: string\n}\n\nexport interface CartData {\n items: CartItem[]\n customer?: CustomerData\n options?: CartOptions\n}\n\nexport interface TorqueConfig {\n businessId?: string\n apiKey?: string\n timeout?: number\n}\n\nexport interface BusinessCreationData {\n name: string\n description?: string\n email: string\n phone?: string\n website?: string\n currency?: string\n timezone?: string\n walletAddress: string\n logo?: string\n}\n\nexport interface BusinessProfile {\n id: string\n name: string\n email: string\n apiKey: string\n walletAddress: string\n logo?: string\n website?: string\n status: 'active' | 'pending' | 'suspended'\n}\n\nexport interface CheckoutResponse {\n success: boolean\n checkoutUrl: string\n expiresAt: string\n cartSummary: {\n itemCount: number\n productCount: number\n estimatedTotal: number\n }\n business: {\n id: string\n name: string\n logo?: string\n }\n}\n\nexport interface OrderStatus {\n orderId: string\n status: string\n customer: {\n email: string\n firstName?: string\n lastName?: string\n phone?: string\n } | null\n items: Array<{\n productId: string\n productName: string\n productImage?: string\n quantity: number\n variant?: string\n price: number\n total: number\n }>\n totals: {\n subtotal: number\n shipping: number\n tax: number\n total: number\n }\n paymentStatus: string\n shippingAddress?: any\n billingAddress?: any\n createdAt: number\n updatedAt: number\n metadata: Record<string, any>\n}\n\nexport interface CartValidation {\n valid: boolean\n errors: string[]\n warnings: string[]\n estimatedTotal: number\n}\n\nexport class TorqueCheckout {\n private businessId: string\n private apiKey: string\n private baseUrl: string = 'https://app.torque.fi'\n private timeout: number\n\n constructor(config: TorqueConfig) {\n this.businessId = config.businessId\n this.apiKey = config.apiKey\n this.timeout = config.timeout || 30000\n }\n\n /**\n * Generate a cart checkout URL\n */\n async generateCartCheckoutUrl(cart: CartData): Promise<string> {\n const response = await this.makeRequest('/api/checkout/generate-link', {\n method: 'POST',\n body: {\n businessId: this.businessId,\n cart: {\n items: cart.items\n },\n customerData: cart.customer,\n options: cart.options\n }\n })\n\n if (!response.success) {\n throw new Error(`Failed to generate checkout URL: ${response.error || 'Unknown error'}`)\n }\n\n return response.checkoutUrl\n }\n\n /**\n * Generate a single product checkout URL\n */\n async generateProductCheckoutUrl(productId: string, quantity: number = 1, customer?: CustomerData, options?: CartOptions): Promise<string> {\n return this.generateCartCheckoutUrl({\n items: [{ productId, quantity }],\n customer,\n options\n })\n }\n\n /**\n * Validate cart data before checkout\n */\n async validateCart(cart: CartData): Promise<CartValidation> {\n try {\n const response = await this.makeRequest('/api/checkout/validate-cart', {\n method: 'POST',\n body: {\n businessId: this.businessId,\n cart: cart.items,\n customer: cart.customer\n }\n })\n\n return response\n } catch (error) {\n return {\n valid: false,\n errors: [error instanceof Error ? error.message : 'Validation failed'],\n warnings: [],\n estimatedTotal: 0\n }\n }\n }\n\n /**\n * Get order status\n */\n async getOrderStatus(orderId: string): Promise<OrderStatus> {\n const response = await this.makeRequest(`/api/checkout/order-status/${orderId}?businessId=${this.businessId}`)\n \n if (response.error) {\n throw new Error(`Failed to get order status: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Send webhook event\n */\n async sendWebhookEvent(orderId: string, status: string, customerData?: any, metadata?: Record<string, any>): Promise<void> {\n await this.makeRequest('/api/webhooks/order-update', {\n method: 'POST',\n body: {\n orderId,\n status,\n customerData,\n metadata\n }\n })\n }\n\n /**\n * Track cart view for analytics\n */\n async trackCartView(cartId: string, cartData: CartData): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/cart-view', {\n method: 'POST',\n body: {\n cartId,\n businessId: this.businessId,\n cartData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track cart view:', error)\n }\n }\n\n /**\n * Track checkout completion for analytics\n */\n async trackCheckoutComplete(orderId: string, checkoutData: any): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/checkout-complete', {\n method: 'POST',\n body: {\n orderId,\n businessId: this.businessId,\n checkoutData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track checkout completion:', error)\n }\n }\n\n /**\n * Generate cart hash for caching\n */\n generateCartHash(cart: CartData): string {\n const cartString = JSON.stringify({\n items: cart.items.sort((a, b) => a.productId.localeCompare(b.productId)),\n customer: cart.customer ? { email: cart.customer.email } : null\n })\n \n // Simple hash function for cart identification\n let hash = 0\n for (let i = 0; i < cartString.length; i++) {\n const char = cartString.charCodeAt(i)\n hash = ((hash << 5) - hash) + char\n hash = hash & hash // Convert to 32-bit integer\n }\n return Math.abs(hash).toString(36)\n }\n\n /**\n * Make HTTP request to Torque API\n */\n private async makeRequest(endpoint: string, options: RequestInit = {}): Promise<any> {\n const url = `${this.baseUrl}${endpoint}`\n \n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), this.timeout)\n\n try {\n const response = await fetch(url, {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`,\n ...options.headers\n },\n signal: controller.signal\n })\n\n clearTimeout(timeoutId)\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}))\n throw new Error(errorData.message || `HTTP ${response.status}: ${response.statusText}`)\n }\n\n return await response.json()\n } catch (error) {\n clearTimeout(timeoutId)\n \n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new Error('Request timeout')\n }\n throw error\n }\n \n throw new Error('Request failed')\n }\n }\n}\n\n// Export default instance factory\nexport const createTorqueCheckout = (config: TorqueConfig) => new TorqueCheckout(config)\n\n// Export types\nexport type {\n CartItem,\n CustomerData,\n CartOptions,\n CartData,\n TorqueConfig,\n CheckoutResponse,\n OrderStatus,\n CartValidation\n}\n"],"names":[],"mappings":";;MA8Ha,cAAc,CAAA;AAMzB,IAAA,WAAA,CAAY,MAAoB,EAAA;QAHxB,IAAA,CAAA,OAAO,GAAW,uBAAuB;AAI/C,QAAA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;AACnC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK;IACxC;AAEA;;AAEG;IACH,MAAM,uBAAuB,CAAC,IAAc,EAAA;QAC1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,6BAA6B,EAAE;AACrE,YAAA,MAAM,EAAE,MAAM;AACd,YAAA,IAAI,EAAE;gBACJ,UAAU,EAAE,IAAI,CAAC,UAAU;AAC3B,gBAAA,IAAI,EAAE;oBACJ,KAAK,EAAE,IAAI,CAAC;AACb,iBAAA;gBACD,YAAY,EAAE,IAAI,CAAC,QAAQ;gBAC3B,OAAO,EAAE,IAAI,CAAC;AACf;AACF,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,CAAA,iCAAA,EAAoC,QAAQ,CAAC,KAAK,IAAI,eAAe,CAAA,CAAE,CAAC;QAC1F;QAEA,OAAO,QAAQ,CAAC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Z,iBAAA;gBACD,MAAM,EAAE,UAAU,CAAC;AACpB,aAAA,CAAC;YAEF,YAAY,CAAC,SAAS,CAAC;AAEvB,YAAA,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;AAChB,gBAAA,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AACzD,gBAAA,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,IAAI,CAAA,KAAA,EAAQ,QAAQ,CAAC,MAAM,CAAA,EAAA,EAAK,QAAQ,CAAC,UAAU,CAAA,CAAE,CAAC;YACzF;AAEA,YAAA,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE;QAC9B;QAAE,OAAO,KAAK,EAAE;YACd,YAAY,CAAC,SAAS,CAAC;AAEvB,YAAA,IAAI,KAAK,YAAY,KAAK,EAAE;AAC1B,gBAAA,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;AAC/B,oBAAA,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC;gBACpC;AACA,gBAAA,MAAM,KAAK;YACb;AAEA,YAAA,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC;QACnC;IACF;AACD;AAED;AACO,MAAM,oBAAoB,GAAG,CAAC,MAAoB,KAAK,IAAI,cAAc,CAAC,MAAM;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export interface CartItem {\n productId: string\n quantity: number\n variant?: string\n price?: number\n metadata?: Record<string, any>\n}\n\nexport interface CustomerData {\n email: string\n firstName?: string\n lastName?: string\n phone?: string\n shippingAddress?: {\n street: string\n city: string\n state: string\n zipCode: string\n country: string\n }\n billingAddress?: {\n street: string\n city: string\n state: string\n zipCode: string\n country: string\n }\n}\n\nexport interface CartOptions {\n domain?: string\n expiresIn?: number\n metadata?: Record<string, any>\n redirectUrl?: string\n}\n\nexport interface CartData {\n items: CartItem[]\n customer?: CustomerData\n options?: CartOptions\n}\n\n// New: Payment Plan Interface\nexport interface PaymentPlan {\n id: string\n name: string\n price: number\n interval: \"weekly\" | \"monthly\" | \"quarterly\" | \"yearly\"\n intervalCount: number\n trialDays?: number\n maxCycles?: number\n description?: string\n}\n\n// New: Subscription Product Interface\nexport interface SubscriptionProduct {\n id: string\n name: string\n description?: string\n isSubscription: boolean\n paymentPlans?: PaymentPlan[]\n subscriptionContract?: {\n address: string\n chainId: number\n abi?: string\n }\n basePrice: number\n currency: string\n image?: string\n images?: string[]\n requiresShipping: boolean\n shippingCost?: number\n taxRate?: number\n inventory: number\n status: 'active' | 'inactive' | 'draft' | 'archived'\n sku?: string\n category?: string\n tags?: string[]\n variants?: Array<{\n id: string\n name: string\n price: number\n inventory?: number\n }>\n metadata?: any\n createdAt: number\n updatedAt: number\n}\n\n// New: Subscription Interface\nexport interface Subscription {\n id: string\n businessId: string\n productId: string\n customerId?: string\n customerEmail: string\n customerName: string\n paymentPlanId: string\n status: \"active\" | \"cancelled\" | \"paused\" | \"expired\" | \"past_due\"\n currentPeriodStart: number\n currentPeriodEnd: number\n nextBillingDate: number\n trialStart?: number\n trialEnd?: number\n totalCycles: number\n maxCycles?: number\n lastPaymentDate?: number\n nextPaymentAmount: number\n currency: string\n contractSubscriptionId?: string\n contractAddress?: string\n billingHistory?: Array<{\n cycleNumber: number\n amount: number\n date: number\n status: \"paid\" | \"failed\" | \"pending\"\n transactionId?: string\n }>\n metadata?: any\n createdAt: number\n updatedAt: number\n}\n\n// New: Subscription Creation Data\nexport interface CreateSubscriptionData {\n businessId: string\n productId: string\n customerEmail: string\n customerName: string\n paymentPlanId: string\n customerId?: string\n metadata?: any\n}\n\n// New: Subscription Update Data\nexport interface UpdateSubscriptionData {\n status?: \"active\" | \"cancelled\" | \"paused\" | \"expired\" | \"past_due\"\n pauseUntil?: number\n resumeDate?: number\n metadata?: any\n}\n\nexport interface TorqueConfig {\n businessId?: string\n apiKey?: string\n timeout?: number\n}\n\nexport interface BusinessCreationData {\n name: string\n description?: string\n email: string\n phone?: string\n website?: string\n currency?: string\n timezone?: string\n walletAddress: string\n logo?: string\n}\n\nexport interface BusinessProfile {\n id: string\n name: string\n email: string\n apiKey: string\n walletAddress: string\n logo?: string\n website?: string\n status: 'active' | 'pending' | 'suspended'\n}\n\nexport interface CheckoutResponse {\n success: boolean\n checkoutUrl: string\n expiresAt: string\n cartSummary: {\n itemCount: number\n productCount: number\n estimatedTotal: number\n }\n business: {\n id: string\n name: string\n logo?: string\n }\n}\n\nexport interface OrderStatus {\n orderId: string\n status: string\n customer: {\n email: string\n firstName?: string\n lastName?: string\n phone?: string\n } | null\n items: Array<{\n productId: string\n productName: string\n productImage?: string\n quantity: number\n variant?: string\n price: number\n total: number\n }>\n totals: {\n subtotal: number\n shipping: number\n tax: number\n total: number\n }\n paymentStatus: string\n shippingAddress?: any\n billingAddress?: any\n createdAt: number\n updatedAt: number\n metadata: Record<string, any>\n}\n\nexport interface CartValidation {\n valid: boolean\n errors: string[]\n warnings: string[]\n estimatedTotal: number\n}\n\nexport class TorqueCheckout {\n private businessId: string\n private apiKey: string\n private baseUrl: string = ''\n private timeout: number\n\n constructor(config: TorqueConfig) {\n this.businessId = config.businessId\n this.apiKey = config.apiKey\n this.timeout = config.timeout || 30000\n }\n\n /**\n * Generate a cart checkout URL\n */\n async generateCartCheckoutUrl(cart: CartData): Promise<string> {\n const response = await this.makeRequest('/api/torque-checkout', {\n method: 'POST',\n body: {\n businessId: this.businessId,\n cart: {\n items: cart.items\n },\n customerData: cart.customer,\n options: cart.options\n }\n })\n\n if (!response.success) {\n throw new Error(`Failed to generate checkout URL: ${response.error || 'Unknown error'}`)\n }\n\n return response.checkoutUrl\n }\n\n /**\n * Generate a single product checkout URL\n */\n async generateProductCheckoutUrl(productId: string, quantity: number = 1, customer?: CustomerData, options?: CartOptions): Promise<string> {\n return this.generateCartCheckoutUrl({\n items: [{ productId, quantity }],\n customer,\n options\n })\n }\n\n /**\n * Generate a subscription checkout URL\n */\n async generateSubscriptionCheckoutUrl(productId: string, paymentPlanId: string, customer?: CustomerData, options?: CartOptions): Promise<string> {\n return this.generateCartCheckoutUrl({\n items: [{ \n productId, \n quantity: 1,\n metadata: { \n isSubscription: true, \n paymentPlanId \n }\n }],\n customer,\n options\n })\n }\n\n /**\n * Validate cart data before checkout\n */\n async validateCart(cart: CartData): Promise<CartValidation> {\n try {\n const response = await this.makeRequest('/api/checkout/validate-cart', {\n method: 'POST',\n body: {\n businessId: this.businessId,\n cart: cart.items,\n customer: cart.customer\n }\n })\n\n return response\n } catch (error) {\n return {\n valid: false,\n errors: [error instanceof Error ? error.message : 'Validation failed'],\n warnings: [],\n estimatedTotal: 0\n }\n }\n }\n\n /**\n * Get order status\n */\n async getOrderStatus(orderId: string): Promise<OrderStatus> {\n const response = await this.makeRequest(`/api/checkout/order-status/${orderId}?businessId=${this.businessId}`)\n \n if (response.error) {\n throw new Error(`Failed to get order status: ${response.error}`)\n }\n\n return response\n }\n\n // New: Subscription Management Methods\n\n /**\n * Create a new subscription\n */\n async createSubscription(data: CreateSubscriptionData): Promise<Subscription> {\n const response = await this.makeRequest('/api/subscriptions/create', {\n method: 'POST',\n body: data\n })\n\n if (response.error) {\n throw new Error(`Failed to create subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get subscription by ID\n */\n async getSubscription(subscriptionId: string): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}`)\n \n if (response.error) {\n throw new Error(`Failed to get subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get subscriptions for a business\n */\n async getBusinessSubscriptions(businessId: string, status?: string, limit?: number): Promise<Subscription[]> {\n const params = new URLSearchParams({ businessId })\n if (status) params.append('status', status)\n if (limit) params.append('limit', limit.toString())\n\n const response = await this.makeRequest(`/api/subscriptions/business?${params}`)\n \n if (response.error) {\n throw new Error(`Failed to get business subscriptions: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get subscriptions for a customer\n */\n async getCustomerSubscriptions(customerEmail: string): Promise<Subscription[]> {\n const response = await this.makeRequest(`/api/subscriptions/customer/${encodeURIComponent(customerEmail)}`)\n \n if (response.error) {\n throw new Error(`Failed to get customer subscriptions: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Update subscription status\n */\n async updateSubscription(subscriptionId: string, data: UpdateSubscriptionData): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/update`, {\n method: 'PUT',\n body: data\n })\n\n if (response.error) {\n throw new Error(`Failed to update subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Cancel subscription\n */\n async cancelSubscription(subscriptionId: string, effectiveDate?: number): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/cancel`, {\n method: 'PUT',\n body: { effectiveDate }\n })\n\n if (response.error) {\n throw new Error(`Failed to cancel subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Pause subscription\n */\n async pauseSubscription(subscriptionId: string, resumeDate?: number): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/pause`, {\n method: 'PUT',\n body: { resumeDate }\n })\n\n if (response.error) {\n throw new Error(`Failed to pause subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Resume subscription\n */\n async resumeSubscription(subscriptionId: string): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/resume`, {\n method: 'PUT'\n })\n\n if (response.error) {\n throw new Error(`Failed to resume subscription: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Process subscription renewal\n */\n async processSubscriptionRenewal(subscriptionId: string): Promise<Subscription> {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/renew`, {\n method: 'PUT'\n })\n\n if (response.error) {\n throw new Error(`Failed to process subscription renewal: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get subscriptions due for renewal\n */\n async getSubscriptionsDueForRenewal(daysAhead: number = 7): Promise<Subscription[]> {\n const response = await this.makeRequest(`/api/subscriptions/due-for-renewal?daysAhead=${daysAhead}`)\n \n if (response.error) {\n throw new Error(`Failed to get subscriptions due for renewal: ${response.error}`)\n }\n\n return response\n }\n\n // New: Product Management Methods\n\n /**\n * Get subscription products for a business\n */\n async getSubscriptionProducts(businessId: string): Promise<SubscriptionProduct[]> {\n const response = await this.makeRequest(`/api/products/subscriptions?businessId=${businessId}`)\n \n if (response.error) {\n throw new Error(`Failed to get subscription products: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Get product with payment plans\n */\n async getProductWithPaymentPlans(productId: string): Promise<SubscriptionProduct> {\n const response = await this.makeRequest(`/api/products/${productId}`)\n \n if (response.error) {\n throw new Error(`Failed to get product: ${response.error}`)\n }\n\n return response\n }\n\n /**\n * Send webhook event\n */\n async sendWebhookEvent(orderId: string, status: string, customerData?: any, metadata?: Record<string, any>): Promise<void> {\n await this.makeRequest('/api/webhooks/order-update', {\n method: 'POST',\n body: {\n orderId,\n status,\n customerData,\n metadata\n }\n })\n }\n\n /**\n * Track cart view for analytics\n */\n async trackCartView(cartId: string, cartData: CartData): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/cart-view', {\n method: 'POST',\n body: {\n cartId,\n businessId: this.businessId,\n cartData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track cart view:', error)\n }\n }\n\n /**\n * Track checkout completion for analytics\n */\n async trackCheckoutComplete(orderId: string, checkoutData: any): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/checkout-complete', {\n method: 'POST',\n body: {\n orderId,\n businessId: this.businessId,\n checkoutData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track checkout completion:', error)\n }\n }\n\n /**\n * Track subscription creation for analytics\n */\n async trackSubscriptionCreated(subscriptionId: string, subscriptionData: any): Promise<void> {\n try {\n await this.makeRequest('/api/analytics/subscription-created', {\n method: 'POST',\n body: {\n subscriptionId,\n businessId: this.businessId,\n subscriptionData,\n timestamp: Date.now()\n }\n })\n } catch (error) {\n console.warn('Failed to track subscription creation:', error)\n }\n }\n\n /**\n * Generate cart hash for caching\n */\n generateCartHash(cart: CartData): string {\n const cartString = JSON.stringify({\n items: cart.items.sort((a, b) => a.productId.localeCompare(b.productId)),\n customer: cart.customer ? { email: cart.customer.email } : null\n })\n \n // Simple hash function for cart identification\n let hash = 0\n for (let i = 0; i < cartString.length; i++) {\n const char = cartString.charCodeAt(i)\n hash = ((hash << 5) - hash) + char\n hash = hash & hash // Convert to 32-bit integer\n }\n return Math.abs(hash).toString(36)\n }\n\n /**\n * Generate subscription hash for caching\n */\n generateSubscriptionHash(subscriptionData: CreateSubscriptionData): string {\n const subscriptionString = JSON.stringify({\n businessId: subscriptionData.businessId,\n productId: subscriptionData.productId,\n customerEmail: subscriptionData.customerEmail,\n paymentPlanId: subscriptionData.paymentPlanId\n })\n \n let hash = 0\n for (let i = 0; i < subscriptionString.length; i++) {\n const char = subscriptionString.charCodeAt(i)\n hash = ((hash << 5) - hash) + char\n hash = hash & hash\n }\n return Math.abs(hash).toString(36)\n }\n\n /**\n * Make HTTP request to Torque API\n */\n private async makeRequest(endpoint: string, options: RequestInit = {}): Promise<any> {\n const url = `${this.baseUrl}${endpoint}`\n \n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), this.timeout)\n\n try {\n const response = await fetch(url, {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`,\n ...options.headers\n },\n signal: controller.signal\n })\n\n clearTimeout(timeoutId)\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}))\n throw new Error(errorData.message || `HTTP ${response.status}: ${response.statusText}`)\n }\n\n return await response.json()\n } catch (error) {\n clearTimeout(timeoutId)\n \n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new Error('Request timeout')\n }\n throw error\n }\n \n throw new Error('Request failed')\n }\n }\n}\n\n// Export default instance factory\nexport const createTorqueCheckout = (config: TorqueConfig) => new TorqueCheckout(config)\n\n// Export types\nexport type {\n CartItem,\n CustomerData,\n CartOptions,\n CartData,\n PaymentPlan,\n SubscriptionProduct,\n Subscription,\n CreateSubscriptionData,\n UpdateSubscriptionData,\n TorqueConfig,\n CheckoutResponse,\n OrderStatus,\n CartValidation\n}\n"],"names":[],"mappings":";;MAkOa,cAAc,CAAA;AAMzB,IAAA,WAAA,CAAY,MAAoB,EAAA;QAHxB,IAAA,CAAA,OAAO,GAAW,EAAE;AAI1B,QAAA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;AACnC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK;IACxC;AAEA;;AAEG;IACH,MAAM,uBAAuB,CAAC,IAAc,EAAA;QAC1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,sBAAsB,EAAE;AAC9D,YAAA,MAAM,EAAE,MAAM;AACd,YAAA,IAAI,EAAE;gBACJ,UAAU,EAAE,IAAI,CAAC,UAAU;AAC3B,gBAAA,IAAI,EAAE;oBACJ,KAAK,EAAE,IAAI,CAAC;AACb,iBAAA;gBACD,YAAY,EAAE,IAAI,CAAC,QAAQ;gBAC3B,OAAO,EAAE,IAAI,CAAC;AACf;AACF,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,CAAA,iCAAA,EAAoC,QAAQ,CAAC,KAAK,IAAI,eAAe,CAAA,CAAE,CAAC;QAC1F;QAEA,OAAO,QAAQ,CAAC,WAAW;IAC7B;AAEA;;AAEG;IACH,MAAM,0BAA0B,CAAC,SAAiB,EAAE,WAAmB,CAAC,EAAE,QAAuB,EAAE,OAAqB,EAAA;QACtH,OAAO,IAAI,CAAC,uBAAuB,CAAC;AAClC,YAAA,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;YAChC,QAAQ;Y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QAAQ,CAAC,MAAM,CAAA,EAAA,EAAK,QAAQ,CAAC,UAAU,CAAA,CAAE,CAAC;YACzF;AAEA,YAAA,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE;QAC9B;QAAE,OAAO,KAAK,EAAE;YACd,YAAY,CAAC,SAAS,CAAC;AAEvB,YAAA,IAAI,KAAK,YAAY,KAAK,EAAE;AAC1B,gBAAA,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;AAC/B,oBAAA,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC;gBACpC;AACA,gBAAA,MAAM,KAAK;YACb;AAEA,YAAA,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC;QACnC;IACF;AACD;AAED;AACO,MAAM,oBAAoB,GAAG,CAAC,MAAoB,KAAK,IAAI,cAAc,CAAC,MAAM;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "torque-checkout",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Official Torque checkout SDK for ecommerce integrations",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
32
|
-
"url": "https://github.com/
|
|
32
|
+
"url": "https://github.com/torquefi/checkout.git"
|
|
33
33
|
},
|
|
34
34
|
"bugs": {
|
|
35
|
-
"url": "
|
|
35
|
+
"url": "ttps://torque.fi"
|
|
36
36
|
},
|
|
37
|
-
"homepage": "https://
|
|
37
|
+
"homepage": "https://torque.fi",
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
40
40
|
"@types/node": "^20.0.0",
|