torque-checkout 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +37 -5
- package/dist/index.d.ts +22 -0
- package/dist/index.esm.js +49 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -1
- package/dist/nextjs.d.ts +7 -2
- package/dist/nextjs.esm.js +26 -15
- package/dist/nextjs.esm.js.map +1 -1
- package/dist/nextjs.js +26 -14
- package/dist/nextjs.js.map +1 -1
- package/dist/react.d.ts +3 -1
- package/dist/react.esm.js +24 -0
- package/dist/react.esm.js.map +1 -1
- package/dist/react.js +24 -0
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to the `torque-checkout` package will be documented in this
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Documentation
|
|
11
|
+
- README, QUICK_START, EXAMPLES, and `nextjs` JSDoc: Next.js examples use `app/api/checkout-session/route.ts` and `fetch('/api/checkout-session')` instead of `app/api/checkout/route.ts` / `fetch('/api/checkout')`, matching the Torque webapp (generic `POST /api/checkout` is not a supported SDK proxy on the hosted app).
|
|
12
|
+
|
|
13
|
+
## [3.2.0] - 2026-04-18
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- **Checkout session response**: `TorqueCheckout.requestCheckoutSession(cart)` returns full `{ success, checkoutUrl, expiresAt, cartSummary, business }` (aligned with hosted-checkout APIs like Suby’s session + `paymentUrl`).
|
|
17
|
+
- **`CartOptions`**: `successUrl`, `cancelUrl`, `externalRef` — embedded in cart payloads from `POST /api/torque-checkout` and `POST /api/checkout/generate-link` so the hosted checkout can offer **Return to store** after payment.
|
|
18
|
+
- **`redirectToCheckout(url, mode)`** — same-tab vs new-tab navigation helper.
|
|
19
|
+
- **`useTorqueCheckout`**: `requestCheckoutSession` for full session payloads alongside `generateCheckout`.
|
|
20
|
+
- **Next.js `handleWebhook`**: verifies `X-Torque-Signature` with **HMAC-SHA256** over the raw body (no longer a stub). Exported **`verifyTorqueWebhookSignature`** for custom routes.
|
|
21
|
+
|
|
22
|
+
### Integration (Torque webapp)
|
|
23
|
+
- Hosted checkout page reads `successUrl` from cart JSON and passes it to the payment confirmation modal as **Return to store** (http/https only).
|
|
24
|
+
|
|
8
25
|
## [3.1.1] - 2026-04-08
|
|
9
26
|
|
|
10
27
|
### Documentation
|
package/README.md
CHANGED
|
@@ -122,6 +122,36 @@ export default function CheckoutButton({ torqueProductId }: { torqueProductId: s
|
|
|
122
122
|
|
|
123
123
|
**Done!** Customer clicks → Redirects to checkout → Payment goes to your wallet.
|
|
124
124
|
|
|
125
|
+
### Checkout sessions & return URL (Suby-style)
|
|
126
|
+
|
|
127
|
+
Torque’s hosted checkout is a **session URL** you send the customer to (like Suby’s `paymentUrl`). The SDK can also return the **full response** and attach **merchant metadata** to the cart:
|
|
128
|
+
|
|
129
|
+
| `cart.options` field | Purpose |
|
|
130
|
+
|----------------------|--------|
|
|
131
|
+
| `successUrl` | After crypto payment confirms, the hosted checkout can show **Return to store** (HTTPS URL of your storefront). |
|
|
132
|
+
| `cancelUrl` | Reserved for analytics / future use. |
|
|
133
|
+
| `externalRef` | Your order id — stored on the session for reconciliation. |
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { createTorqueCheckout, redirectToCheckout } from 'torque-checkout'
|
|
137
|
+
|
|
138
|
+
const torque = createTorqueCheckout({ businessId, apiKey, baseUrl: 'https://app.torque.fi' })
|
|
139
|
+
|
|
140
|
+
// Full session: URL + cartSummary + expiresAt
|
|
141
|
+
const session = await torque.requestCheckoutSession({
|
|
142
|
+
items: [{ productId: 'j…', quantity: 1 }],
|
|
143
|
+
customer: { email: 'buyer@example.com' },
|
|
144
|
+
options: {
|
|
145
|
+
successUrl: 'https://your-store.com/thank-you',
|
|
146
|
+
externalRef: 'order_123',
|
|
147
|
+
},
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
redirectToCheckout(session.checkoutUrl, 'same_tab') // or 'new_tab'
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Webhooks: use `verifyTorqueWebhookSignature` from `torque-checkout/nextjs` with the **raw** request body and header `X-Torque-Signature` (HMAC-SHA256).
|
|
154
|
+
|
|
125
155
|
---
|
|
126
156
|
|
|
127
157
|
### Detailed Setup
|
|
@@ -203,8 +233,10 @@ export default function CheckoutButton() {
|
|
|
203
233
|
|
|
204
234
|
#### Option B: Server-Side API Route (Most Secure)
|
|
205
235
|
|
|
236
|
+
Add a route **in your Next.js app** (use any path; this example uses `checkout-session` so it does not collide with Torque’s hosted `/api/torque-checkout`):
|
|
237
|
+
|
|
206
238
|
```ts
|
|
207
|
-
// app/api/checkout/route.ts
|
|
239
|
+
// app/api/checkout-session/route.ts
|
|
208
240
|
import { handleCheckoutRequest } from 'torque-checkout/nextjs'
|
|
209
241
|
|
|
210
242
|
export const POST = handleCheckoutRequest()
|
|
@@ -213,7 +245,7 @@ export const POST = handleCheckoutRequest()
|
|
|
213
245
|
Then call from your frontend:
|
|
214
246
|
|
|
215
247
|
```tsx
|
|
216
|
-
const response = await fetch('/api/checkout', {
|
|
248
|
+
const response = await fetch('/api/checkout-session', {
|
|
217
249
|
method: 'POST',
|
|
218
250
|
headers: { 'Content-Type': 'application/json' },
|
|
219
251
|
body: JSON.stringify({
|
|
@@ -514,7 +546,7 @@ function ShoppingCart() {
|
|
|
514
546
|
Complete API route handler with error handling.
|
|
515
547
|
|
|
516
548
|
```ts
|
|
517
|
-
// app/api/checkout/route.ts
|
|
549
|
+
// app/api/checkout-session/route.ts (path is your choice)
|
|
518
550
|
import { handleCheckoutRequest } from 'torque-checkout/nextjs'
|
|
519
551
|
|
|
520
552
|
export const POST = handleCheckoutRequest({
|
|
@@ -562,7 +594,7 @@ export const POST = handleWebhook({
|
|
|
562
594
|
Server-side checkout URL generation.
|
|
563
595
|
|
|
564
596
|
```ts
|
|
565
|
-
// app/api/checkout/route.ts
|
|
597
|
+
// app/api/checkout-session/route.ts (path is your choice)
|
|
566
598
|
import { generateCheckoutUrl } from 'torque-checkout/nextjs'
|
|
567
599
|
|
|
568
600
|
export async function POST(request: Request) {
|
|
@@ -909,7 +941,7 @@ try {
|
|
|
909
941
|
})
|
|
910
942
|
|
|
911
943
|
// GOOD - Use server-side API routes
|
|
912
|
-
// app/api/checkout/route.ts
|
|
944
|
+
// app/api/checkout-session/route.ts
|
|
913
945
|
export const POST = handleCheckoutRequest()
|
|
914
946
|
```
|
|
915
947
|
|
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,17 @@ export interface CartOptions {
|
|
|
37
37
|
domain?: string;
|
|
38
38
|
expiresIn?: number;
|
|
39
39
|
metadata?: Record<string, any>;
|
|
40
|
+
/** @deprecated Prefer successUrl — passed through to hosted checkout cart payload */
|
|
40
41
|
redirectUrl?: string;
|
|
42
|
+
/**
|
|
43
|
+
* After a successful payment on the hosted checkout, the confirmation modal can show
|
|
44
|
+
* “Return to store” (cart flows). Same idea as Suby’s `successUrl` redirect after pay.
|
|
45
|
+
*/
|
|
46
|
+
successUrl?: string;
|
|
47
|
+
/** Shown if the buyer abandons before paying (optional future use / analytics). */
|
|
48
|
+
cancelUrl?: string;
|
|
49
|
+
/** Your order reference — stored on the cart session for reconciliation & webhooks. */
|
|
50
|
+
externalRef?: string;
|
|
41
51
|
}
|
|
42
52
|
export interface CartData {
|
|
43
53
|
items: CartItem[];
|
|
@@ -179,6 +189,13 @@ export interface CheckoutResponse {
|
|
|
179
189
|
logo?: string;
|
|
180
190
|
};
|
|
181
191
|
}
|
|
192
|
+
/** Full API response from `POST /api/torque-checkout` (Suby-style session object). */
|
|
193
|
+
export type CheckoutSession = CheckoutResponse;
|
|
194
|
+
/**
|
|
195
|
+
* Redirect the browser to a Torque-hosted checkout URL.
|
|
196
|
+
* Prefer `same_tab` for a single continuous flow (matches common hosted-checkout UX).
|
|
197
|
+
*/
|
|
198
|
+
export declare function redirectToCheckout(checkoutUrl: string, mode?: 'same_tab' | 'new_tab'): void;
|
|
182
199
|
export interface OrderStatus {
|
|
183
200
|
orderId: string;
|
|
184
201
|
status: string;
|
|
@@ -243,6 +260,11 @@ export declare class TorqueCheckout {
|
|
|
243
260
|
* @throws {TorqueCheckoutError} If cart validation fails or API request fails
|
|
244
261
|
*/
|
|
245
262
|
generateCartCheckoutUrl(cart: CartData): Promise<string>;
|
|
263
|
+
/**
|
|
264
|
+
* Create a checkout session and return the full API payload (Suby-style: URL + expiry + summary).
|
|
265
|
+
* Use this when you need `cartSummary`, `expiresAt`, or to pass `successUrl` / `externalRef` via `cart.options`.
|
|
266
|
+
*/
|
|
267
|
+
requestCheckoutSession(cart: CartData): Promise<CheckoutSession>;
|
|
246
268
|
/**
|
|
247
269
|
* Generate a single product checkout URL
|
|
248
270
|
* @param productId - Product ID
|
package/dist/index.esm.js
CHANGED
|
@@ -7,6 +7,21 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*/
|
|
10
|
+
/**
|
|
11
|
+
* Redirect the browser to a Torque-hosted checkout URL.
|
|
12
|
+
* Prefer `same_tab` for a single continuous flow (matches common hosted-checkout UX).
|
|
13
|
+
*/
|
|
14
|
+
function redirectToCheckout(checkoutUrl, mode = 'same_tab') {
|
|
15
|
+
if (typeof window === 'undefined') {
|
|
16
|
+
throw new TorqueCheckoutError('redirectToCheckout is browser-only', 'SSR_NOT_SUPPORTED', 400);
|
|
17
|
+
}
|
|
18
|
+
if (mode === 'new_tab') {
|
|
19
|
+
window.open(checkoutUrl, '_blank', 'noopener,noreferrer');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
window.location.assign(checkoutUrl);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
10
25
|
// ============================================================================
|
|
11
26
|
// Error Classes
|
|
12
27
|
// ============================================================================
|
|
@@ -122,6 +137,39 @@ class TorqueCheckout {
|
|
|
122
137
|
throw new TorqueCheckoutError(error instanceof Error ? error.message : 'Failed to generate checkout URL', 'NETWORK_ERROR', 500);
|
|
123
138
|
}
|
|
124
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Create a checkout session and return the full API payload (Suby-style: URL + expiry + summary).
|
|
142
|
+
* Use this when you need `cartSummary`, `expiresAt`, or to pass `successUrl` / `externalRef` via `cart.options`.
|
|
143
|
+
*/
|
|
144
|
+
async requestCheckoutSession(cart) {
|
|
145
|
+
const validationErrors = validateCartData(cart);
|
|
146
|
+
if (validationErrors.length > 0) {
|
|
147
|
+
throw new TorqueCheckoutError(`Cart validation failed: ${validationErrors.join(', ')}`, 'VALIDATION_ERROR', 400, { errors: validationErrors });
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const response = await this.makeRequest('/api/torque-checkout', {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
body: {
|
|
153
|
+
businessId: this.businessId,
|
|
154
|
+
cart: {
|
|
155
|
+
items: cart.items
|
|
156
|
+
},
|
|
157
|
+
customerData: cart.customer,
|
|
158
|
+
options: cart.options
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
if (!response.success || !response.checkoutUrl) {
|
|
162
|
+
throw new TorqueCheckoutError(response.message || 'Failed to create checkout session', response.error || 'CHECKOUT_GENERATION_FAILED', response.statusCode || 500, response.details);
|
|
163
|
+
}
|
|
164
|
+
return response;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (error instanceof TorqueCheckoutError) {
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
throw new TorqueCheckoutError(error instanceof Error ? error.message : 'Failed to create checkout session', 'NETWORK_ERROR', 500);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
125
173
|
/**
|
|
126
174
|
* Generate a single product checkout URL
|
|
127
175
|
* @param productId - Product ID
|
|
@@ -784,5 +832,5 @@ function createTorqueCheckoutFromEnv(overrides) {
|
|
|
784
832
|
// This section is for re-exporting if needed for convenience
|
|
785
833
|
// All types are available via named exports from the main module
|
|
786
834
|
|
|
787
|
-
export { TorqueCheckout, TorqueCheckoutError, createTorqueCheckout, createTorqueCheckoutFromEnv, validateCartData, validateCartItem, validateConfig };
|
|
835
|
+
export { TorqueCheckout, TorqueCheckoutError, createTorqueCheckout, createTorqueCheckoutFromEnv, redirectToCheckout, validateCartData, validateCartItem, validateConfig };
|
|
788
836
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Torque Checkout SDK\n * Official SDK for integrating Torque checkout into your eCommerce applications\n *\n * **Hosted app (app.torque.fi):** Use `generateCartCheckoutUrl`, `validateCart`, catalog getters, and `getOrderStatus`.\n * Subscription lifecycle and analytics helpers call routes that may not exist on every deployment; see package README.\n *\n * @packageDocumentation\n */\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\nexport interface CartItem {\n productId: string // Must be a valid Torque product ID (Convex ID format)\n quantity: number\n variant?: string // Optional variant ID if product has variants\n metadata?: Record<string, any> // Optional merchant metadata\n // Note: price is NOT included - prices come from Torque product database\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 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\nexport interface Product {\n id: string // Torque product ID (Convex ID format, e.g., \"j1234567890abcdef\")\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 price: number // Base price (for non-subscription) or base price (for subscription)\n currency: string\n image?: string\n images?: string[]\n requiresShipping: boolean\n shippingCost?: number\n taxRate?: number\n inventory: number // -1 for unlimited\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// Alias for backward compatibility\nexport interface SubscriptionProduct extends Product {\n basePrice: number // Alias for price\n}\n\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\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\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 baseUrl?: 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 interface TorqueError extends Error {\n code?: string\n statusCode?: number\n details?: any\n}\n\n// ============================================================================\n// Error Classes\n// ============================================================================\n\nexport class TorqueCheckoutError extends Error implements TorqueError {\n code?: string\n statusCode?: number\n details?: any\n\n constructor(message: string, code?: string, statusCode?: number, details?: any) {\n super(message)\n this.name = 'TorqueCheckoutError'\n this.code = code\n this.statusCode = statusCode\n this.details = details\n Object.setPrototypeOf(this, TorqueCheckoutError.prototype)\n }\n}\n\n// ============================================================================\n// Validation Utilities\n// ============================================================================\n\n/**\n * Validates a Convex ID format (e.g., \"j1234567890abcdef\")\n * Convex IDs are alphanumeric strings starting with a letter\n */\nfunction isValidConvexId(id: string): boolean {\n return /^[a-z][a-z0-9]{15,}$/i.test(id)\n}\n\nexport function validateCartItem(item: CartItem): string[] {\n const errors: string[] = []\n \n if (!item.productId || typeof item.productId !== 'string' || item.productId.trim() === '') {\n errors.push('Product ID is required and must be a non-empty string')\n } else if (!isValidConvexId(item.productId)) {\n errors.push('Product ID must be a valid Torque product ID. Products must be uploaded to Torque first at /business/products')\n }\n \n if (typeof item.quantity !== 'number' || item.quantity <= 0 || !Number.isInteger(item.quantity)) {\n errors.push('Quantity must be a positive integer')\n }\n \n // Price validation removed - prices come from Torque product database\n // Prices are fetched from Torque when generating checkout URL\n \n return errors\n}\n\nexport function validateCartData(cart: CartData): string[] {\n const errors: string[] = []\n \n if (!cart.items || !Array.isArray(cart.items) || cart.items.length === 0) {\n errors.push('Cart must contain at least one item')\n return errors\n }\n \n cart.items.forEach((item, index) => {\n const itemErrors = validateCartItem(item)\n itemErrors.forEach(error => errors.push(`Item ${index + 1}: ${error}`))\n })\n \n if (cart.customer?.email && !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(cart.customer.email)) {\n errors.push('Customer email must be a valid email address')\n }\n \n return errors\n}\n\nexport function validateConfig(config: TorqueConfig): string[] {\n const errors: string[] = []\n \n if (!config.businessId || typeof config.businessId !== 'string' || config.businessId.trim() === '') {\n errors.push('Business ID is required')\n }\n \n if (!config.apiKey || typeof config.apiKey !== 'string' || config.apiKey.trim() === '') {\n errors.push('API key is required')\n }\n \n if (config.timeout !== undefined && (typeof config.timeout !== 'number' || config.timeout <= 0)) {\n errors.push('Timeout must be a positive number')\n }\n \n return errors\n}\n\n// ============================================================================\n// Main SDK Class\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 const configErrors = validateConfig(config)\n if (configErrors.length > 0) {\n throw new TorqueCheckoutError(\n `Invalid configuration: ${configErrors.join(', ')}`,\n 'INVALID_CONFIG',\n 400,\n { errors: configErrors }\n )\n }\n\n this.businessId = config.businessId.trim()\n this.apiKey = config.apiKey.trim()\n this.baseUrl = (config.baseUrl || 'https://app.torque.fi').replace(/\\/$/, '')\n this.timeout = config.timeout || 30000\n }\n\n /**\n * Generate a cart checkout URL\n * @param cart - Cart data containing items, customer info, and options\n * @returns Promise resolving to checkout URL\n * @throws {TorqueCheckoutError} If cart validation fails or API request fails\n */\n async generateCartCheckoutUrl(cart: CartData): Promise<string> {\n const validationErrors = validateCartData(cart)\n if (validationErrors.length > 0) {\n throw new TorqueCheckoutError(\n `Cart validation failed: ${validationErrors.join(', ')}`,\n 'VALIDATION_ERROR',\n 400,\n { errors: validationErrors }\n )\n }\n\n try {\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 TorqueCheckoutError(\n response.message || 'Failed to generate checkout URL',\n response.error || 'CHECKOUT_GENERATION_FAILED',\n response.statusCode || 500,\n response.details\n )\n }\n\n return response.checkoutUrl\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to generate checkout URL',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Generate a single product checkout URL\n * @param productId - Product ID\n * @param quantity - Quantity (default: 1)\n * @param customer - Optional customer data\n * @param options - Optional cart options\n * @returns Promise resolving to checkout URL\n */\n async generateProductCheckoutUrl(\n productId: string,\n quantity: number = 1,\n customer?: CustomerData,\n options?: CartOptions\n ): 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 * @param productId - Subscription product ID\n * @param paymentPlanId - Payment plan ID\n * @param customer - Optional customer data\n * @param options - Optional cart options\n * @returns Promise resolving to checkout URL\n */\n async generateSubscriptionCheckoutUrl(\n productId: string,\n paymentPlanId: string,\n customer?: CustomerData,\n options?: CartOptions\n ): 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 * @param cart - Cart data to validate\n * @returns Promise resolving to validation result\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 const validationErrors = validateCartData(cart)\n return {\n valid: false,\n errors: error instanceof Error \n ? [error.message, ...validationErrors]\n : ['Validation failed', ...validationErrors],\n warnings: [],\n estimatedTotal: 0\n }\n }\n }\n\n /**\n * Get order status\n * @param orderId - Order ID\n * @returns Promise resolving to order status\n * @throws {TorqueCheckoutError} If order not found or API request fails\n */\n async getOrderStatus(orderId: string): Promise<OrderStatus> {\n if (!orderId || typeof orderId !== 'string') {\n throw new TorqueCheckoutError('Order ID is required', 'INVALID_ORDER_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/checkout/order-status/${orderId}?businessId=${this.businessId}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get order status',\n response.error || 'ORDER_NOT_FOUND',\n response.statusCode || 404\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get order status',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Create a new subscription\n * @param data - Subscription creation data\n * @returns Promise resolving to created subscription\n */\n async createSubscription(data: CreateSubscriptionData): Promise<Subscription> {\n try {\n const response = await this.makeRequest('/api/subscriptions/create', {\n method: 'POST',\n body: data\n })\n\n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to create subscription',\n response.error || 'SUBSCRIPTION_CREATION_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to create subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscription by ID\n * @param subscriptionId - Subscription ID\n * @returns Promise resolving to subscription\n */\n async getSubscription(subscriptionId: string): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get subscription',\n response.error || 'SUBSCRIPTION_NOT_FOUND',\n response.statusCode || 404\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscriptions for a business\n * @param businessId - Business ID (optional, uses instance businessId if not provided)\n * @param status - Optional status filter\n * @param limit - Optional limit\n * @returns Promise resolving to array of subscriptions\n */\n async getBusinessSubscriptions(businessId?: string, status?: string, limit?: number): Promise<Subscription[]> {\n const bid = businessId || this.businessId\n const params = new URLSearchParams({ businessId: bid })\n if (status) params.append('status', status)\n if (limit) params.append('limit', limit.toString())\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/business?${params}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get business subscriptions',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n return Array.isArray(response) ? response : []\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get business subscriptions',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscriptions for a customer\n * @param customerEmail - Customer email\n * @returns Promise resolving to array of subscriptions\n */\n async getCustomerSubscriptions(customerEmail: string): Promise<Subscription[]> {\n if (!customerEmail || typeof customerEmail !== 'string' || !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(customerEmail)) {\n throw new TorqueCheckoutError('Valid customer email is required', 'INVALID_EMAIL', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/customer/${encodeURIComponent(customerEmail)}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get customer subscriptions',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n return Array.isArray(response) ? response : []\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get customer subscriptions',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Update subscription status\n * @param subscriptionId - Subscription ID\n * @param data - Update data\n * @returns Promise resolving to updated subscription\n */\n async updateSubscription(subscriptionId: string, data: UpdateSubscriptionData): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\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 TorqueCheckoutError(\n response.message || 'Failed to update subscription',\n response.error || 'UPDATE_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to update subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Cancel subscription\n * @param subscriptionId - Subscription ID\n * @param effectiveDate - Optional effective date for cancellation\n * @returns Promise resolving to cancelled subscription\n */\n async cancelSubscription(subscriptionId: string, effectiveDate?: number): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\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 TorqueCheckoutError(\n response.message || 'Failed to cancel subscription',\n response.error || 'CANCEL_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to cancel subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Pause subscription\n * @param subscriptionId - Subscription ID\n * @param resumeDate - Optional resume date\n * @returns Promise resolving to paused subscription\n */\n async pauseSubscription(subscriptionId: string, resumeDate?: number): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\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 TorqueCheckoutError(\n response.message || 'Failed to pause subscription',\n response.error || 'PAUSE_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to pause subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Resume subscription\n * @param subscriptionId - Subscription ID\n * @returns Promise resolving to resumed subscription\n */\n async resumeSubscription(subscriptionId: string): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/resume`, {\n method: 'PUT'\n })\n\n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to resume subscription',\n response.error || 'RESUME_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to resume subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Process subscription renewal\n * @param subscriptionId - Subscription ID\n * @returns Promise resolving to renewed subscription\n */\n async processSubscriptionRenewal(subscriptionId: string): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/renew`, {\n method: 'PUT'\n })\n\n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to process subscription renewal',\n response.error || 'RENEWAL_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to process subscription renewal',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscriptions due for renewal\n * @param daysAhead - Number of days ahead to check (default: 7)\n * @returns Promise resolving to array of subscriptions\n */\n async getSubscriptionsDueForRenewal(daysAhead: number = 7): Promise<Subscription[]> {\n if (typeof daysAhead !== 'number' || daysAhead < 0) {\n throw new TorqueCheckoutError('Days ahead must be a non-negative number', 'INVALID_PARAMETER', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/due-for-renewal?daysAhead=${daysAhead}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get subscriptions due for renewal',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n return Array.isArray(response) ? response : []\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get subscriptions due for renewal',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get all products for a business\n * Use this to sync your ecommerce catalog with Torque products\n * @param businessId - Business ID (optional, uses instance businessId if not provided)\n * @param status - Optional status filter ('active', 'inactive', 'draft', 'archived')\n * @returns Promise resolving to array of products\n * \n * @example\n * ```ts\n * const products = await torque.getProducts()\n * // Sync products with your database\n * products.forEach(product => {\n * await db.products.update({\n * where: { sku: product.sku },\n * data: { torqueProductId: product.id }\n * })\n * })\n * ```\n */\n async getProducts(businessId?: string, status?: 'active' | 'inactive' | 'draft' | 'archived'): Promise<Product[]> {\n const bid = businessId || this.businessId\n const params = new URLSearchParams({ businessId: bid })\n if (status) params.append('status', status)\n\n try {\n const response = await this.makeRequest(`/api/products?${params}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get products',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n return Array.isArray(response) ? response : []\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get products',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscription products for a business\n * @param businessId - Business ID (optional, uses instance businessId if not provided)\n * @returns Promise resolving to array of subscription products\n */\n async getSubscriptionProducts(businessId?: string): Promise<SubscriptionProduct[]> {\n const bid = businessId || this.businessId\n\n try {\n const response = await this.makeRequest(`/api/products/subscriptions?businessId=${bid}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get subscription products',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n const products = Array.isArray(response) ? response : []\n // Map to SubscriptionProduct format with basePrice alias\n return products.map(p => ({\n ...p,\n basePrice: p.price || p.basePrice || 0\n }))\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get subscription products',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get a single product by ID\n * @param productId - Product ID (Torque product ID)\n * @returns Promise resolving to product\n */\n async getProduct(productId: string): Promise<Product> {\n if (!productId || typeof productId !== 'string') {\n throw new TorqueCheckoutError('Product ID is required', 'INVALID_PRODUCT_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/products/${productId}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get product',\n response.error || 'PRODUCT_NOT_FOUND',\n response.statusCode || 404\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get product',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get product with payment plans\n * @param productId - Product ID\n * @returns Promise resolving to product with payment plans\n */\n async getProductWithPaymentPlans(productId: string): Promise<SubscriptionProduct> {\n if (!productId || typeof productId !== 'string') {\n throw new TorqueCheckoutError('Product ID is required', 'INVALID_PRODUCT_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/products/${productId}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get product',\n response.error || 'PRODUCT_NOT_FOUND',\n response.statusCode || 404\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get product',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Send webhook event\n * @param orderId - Order ID\n * @param status - Order status\n * @param customerData - Optional customer data\n * @param metadata - Optional metadata\n */\n async sendWebhookEvent(\n orderId: string,\n status: string,\n customerData?: any,\n metadata?: Record<string, any>\n ): Promise<void> {\n if (!orderId || typeof orderId !== 'string') {\n throw new TorqueCheckoutError('Order ID is required', 'INVALID_ORDER_ID', 400)\n }\n\n try {\n await this.makeRequest('/api/webhooks/order-update', {\n method: 'POST',\n body: {\n orderId,\n status,\n customerData,\n metadata\n }\n })\n } catch (error) {\n // Webhook events are non-critical, log but don't throw\n console.warn('Failed to send webhook event:', error)\n }\n }\n\n /**\n * Track cart view for analytics\n * @param cartId - Cart ID\n * @param cartData - Cart data\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 // Analytics tracking is non-critical, log but don't throw\n console.warn('Failed to track cart view:', error)\n }\n }\n\n /**\n * Track checkout completion for analytics\n * @param orderId - Order ID\n * @param checkoutData - Checkout data\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 // Analytics tracking is non-critical, log but don't throw\n console.warn('Failed to track checkout completion:', error)\n }\n }\n\n /**\n * Track subscription creation for analytics\n * @param subscriptionId - Subscription ID\n * @param subscriptionData - Subscription data\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 // Analytics tracking is non-critical, log but don't throw\n console.warn('Failed to track subscription creation:', error)\n }\n }\n\n /**\n * Generate cart hash for caching\n * @param cart - Cart data\n * @returns Cart hash string\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 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 * @param subscriptionData - Subscription data\n * @returns Subscription hash string\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 * @private\n */\n private async makeRequest(\n endpoint: string,\n options: { method?: string; body?: any; headers?: Record<string, string> } = {}\n ): 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 { body, ...fetchOptions } = options\n const response = await fetch(url, {\n ...fetchOptions,\n method: options.method || 'GET',\n body: body ? JSON.stringify(body) : undefined,\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 const responseData = await response.json().catch(() => ({}))\n\n if (!response.ok) {\n throw new TorqueCheckoutError(\n responseData.message || `HTTP ${response.status}: ${response.statusText}`,\n responseData.error || 'API_ERROR',\n response.status,\n responseData.details\n )\n }\n\n return responseData\n } catch (error) {\n clearTimeout(timeoutId)\n \n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new TorqueCheckoutError('Request timeout', 'TIMEOUT', 408)\n }\n throw new TorqueCheckoutError(error.message, 'NETWORK_ERROR', 500)\n }\n \n throw new TorqueCheckoutError('Request failed', 'UNKNOWN_ERROR', 500)\n }\n }\n}\n\n// ============================================================================\n// Factory Functions\n// ============================================================================\n\n/**\n * Create a new TorqueCheckout instance\n * @param config - Configuration object\n * @returns TorqueCheckout instance\n */\nexport function createTorqueCheckout(config: TorqueConfig): TorqueCheckout {\n return new TorqueCheckout(config)\n}\n\n/**\n * Create a TorqueCheckout instance from environment variables\n * Requires TORQUE_BUSINESS_ID and TORQUE_API_KEY environment variables\n * @param overrides - Optional configuration overrides\n * @returns TorqueCheckout instance\n */\nexport function createTorqueCheckoutFromEnv(overrides?: Partial<TorqueConfig>): TorqueCheckout {\n const businessId = process.env.TORQUE_BUSINESS_ID || overrides?.businessId\n const apiKey = process.env.TORQUE_API_KEY || overrides?.apiKey\n\n if (!businessId || !apiKey) {\n throw new TorqueCheckoutError(\n 'TORQUE_BUSINESS_ID and TORQUE_API_KEY environment variables are required',\n 'MISSING_ENV_VARS',\n 400\n )\n }\n\n return new TorqueCheckout({\n businessId,\n apiKey,\n baseUrl: process.env.TORQUE_BASE_URL || overrides?.baseUrl,\n timeout: overrides?.timeout\n })\n}\n\n// ============================================================================\n// Type Exports\n// ============================================================================\n\n// Types are already exported above as interfaces/types\n// This section is for re-exporting if needed for convenience\n// All types are available via named exports from the main module\n"],"names":[],"mappings":"AAAA;;;;;;;;AAQG;AA+OH;AACA;AACA;AAEM,MAAO,mBAAoB,SAAQ,KAAK,CAAA;AAK5C,IAAA,WAAA,CAAY,OAAe,EAAE,IAAa,EAAE,UAAmB,EAAE,OAAa,EAAA;QAC5E,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,IAAI,GAAG,qBAAqB;AACjC,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAChB,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU;AAC5B,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;QACtB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC;IAC5D;AACD;AAED;AACA;AACA;AAEA;;;AAGG;AACH,SAAS,eAAe,CAAC,EAAU,EAAA;AACjC,IAAA,OAAO,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC;AACzC;AAEM,SAAU,gBAAgB,CAAC,IAAc,EAAA;IAC7C,MAAM,MAAM,GAAa,EAAE;IAE3B,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,IAAI,IAAI,CAAC,SAAS,CAAC,I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CAAC;QACxB,UAAU;QACV,MAAM;QACN,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,SAAS,EAAE,OAAO;QAC1D,OAAO,EAAE,SAAS,EAAE;AACrB,KAAA,CAAC;AACJ;AAEA;AACA;AACA;AAEA;AACA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Torque Checkout SDK\n * Official SDK for integrating Torque checkout into your eCommerce applications\n *\n * **Hosted app (app.torque.fi):** Use `generateCartCheckoutUrl`, `validateCart`, catalog getters, and `getOrderStatus`.\n * Subscription lifecycle and analytics helpers call routes that may not exist on every deployment; see package README.\n *\n * @packageDocumentation\n */\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\nexport interface CartItem {\n productId: string // Must be a valid Torque product ID (Convex ID format)\n quantity: number\n variant?: string // Optional variant ID if product has variants\n metadata?: Record<string, any> // Optional merchant metadata\n // Note: price is NOT included - prices come from Torque product database\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 /** @deprecated Prefer successUrl — passed through to hosted checkout cart payload */\n redirectUrl?: string\n /**\n * After a successful payment on the hosted checkout, the confirmation modal can show\n * “Return to store” (cart flows). Same idea as Suby’s `successUrl` redirect after pay.\n */\n successUrl?: string\n /** Shown if the buyer abandons before paying (optional future use / analytics). */\n cancelUrl?: string\n /** Your order reference — stored on the cart session for reconciliation & webhooks. */\n externalRef?: string\n}\n\nexport interface CartData {\n items: CartItem[]\n customer?: CustomerData\n options?: CartOptions\n}\n\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\nexport interface Product {\n id: string // Torque product ID (Convex ID format, e.g., \"j1234567890abcdef\")\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 price: number // Base price (for non-subscription) or base price (for subscription)\n currency: string\n image?: string\n images?: string[]\n requiresShipping: boolean\n shippingCost?: number\n taxRate?: number\n inventory: number // -1 for unlimited\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// Alias for backward compatibility\nexport interface SubscriptionProduct extends Product {\n basePrice: number // Alias for price\n}\n\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\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\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 baseUrl?: 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\n/** Full API response from `POST /api/torque-checkout` (Suby-style session object). */\nexport type CheckoutSession = CheckoutResponse\n\n/**\n * Redirect the browser to a Torque-hosted checkout URL.\n * Prefer `same_tab` for a single continuous flow (matches common hosted-checkout UX).\n */\nexport function redirectToCheckout(\n checkoutUrl: string,\n mode: 'same_tab' | 'new_tab' = 'same_tab'\n): void {\n if (typeof window === 'undefined') {\n throw new TorqueCheckoutError(\n 'redirectToCheckout is browser-only',\n 'SSR_NOT_SUPPORTED',\n 400\n )\n }\n if (mode === 'new_tab') {\n window.open(checkoutUrl, '_blank', 'noopener,noreferrer')\n } else {\n window.location.assign(checkoutUrl)\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 interface TorqueError extends Error {\n code?: string\n statusCode?: number\n details?: any\n}\n\n// ============================================================================\n// Error Classes\n// ============================================================================\n\nexport class TorqueCheckoutError extends Error implements TorqueError {\n code?: string\n statusCode?: number\n details?: any\n\n constructor(message: string, code?: string, statusCode?: number, details?: any) {\n super(message)\n this.name = 'TorqueCheckoutError'\n this.code = code\n this.statusCode = statusCode\n this.details = details\n Object.setPrototypeOf(this, TorqueCheckoutError.prototype)\n }\n}\n\n// ============================================================================\n// Validation Utilities\n// ============================================================================\n\n/**\n * Validates a Convex ID format (e.g., \"j1234567890abcdef\")\n * Convex IDs are alphanumeric strings starting with a letter\n */\nfunction isValidConvexId(id: string): boolean {\n return /^[a-z][a-z0-9]{15,}$/i.test(id)\n}\n\nexport function validateCartItem(item: CartItem): string[] {\n const errors: string[] = []\n \n if (!item.productId || typeof item.productId !== 'string' || item.productId.trim() === '') {\n errors.push('Product ID is required and must be a non-empty string')\n } else if (!isValidConvexId(item.productId)) {\n errors.push('Product ID must be a valid Torque product ID. Products must be uploaded to Torque first at /business/products')\n }\n \n if (typeof item.quantity !== 'number' || item.quantity <= 0 || !Number.isInteger(item.quantity)) {\n errors.push('Quantity must be a positive integer')\n }\n \n // Price validation removed - prices come from Torque product database\n // Prices are fetched from Torque when generating checkout URL\n \n return errors\n}\n\nexport function validateCartData(cart: CartData): string[] {\n const errors: string[] = []\n \n if (!cart.items || !Array.isArray(cart.items) || cart.items.length === 0) {\n errors.push('Cart must contain at least one item')\n return errors\n }\n \n cart.items.forEach((item, index) => {\n const itemErrors = validateCartItem(item)\n itemErrors.forEach(error => errors.push(`Item ${index + 1}: ${error}`))\n })\n \n if (cart.customer?.email && !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(cart.customer.email)) {\n errors.push('Customer email must be a valid email address')\n }\n \n return errors\n}\n\nexport function validateConfig(config: TorqueConfig): string[] {\n const errors: string[] = []\n \n if (!config.businessId || typeof config.businessId !== 'string' || config.businessId.trim() === '') {\n errors.push('Business ID is required')\n }\n \n if (!config.apiKey || typeof config.apiKey !== 'string' || config.apiKey.trim() === '') {\n errors.push('API key is required')\n }\n \n if (config.timeout !== undefined && (typeof config.timeout !== 'number' || config.timeout <= 0)) {\n errors.push('Timeout must be a positive number')\n }\n \n return errors\n}\n\n// ============================================================================\n// Main SDK Class\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 const configErrors = validateConfig(config)\n if (configErrors.length > 0) {\n throw new TorqueCheckoutError(\n `Invalid configuration: ${configErrors.join(', ')}`,\n 'INVALID_CONFIG',\n 400,\n { errors: configErrors }\n )\n }\n\n this.businessId = config.businessId.trim()\n this.apiKey = config.apiKey.trim()\n this.baseUrl = (config.baseUrl || 'https://app.torque.fi').replace(/\\/$/, '')\n this.timeout = config.timeout || 30000\n }\n\n /**\n * Generate a cart checkout URL\n * @param cart - Cart data containing items, customer info, and options\n * @returns Promise resolving to checkout URL\n * @throws {TorqueCheckoutError} If cart validation fails or API request fails\n */\n async generateCartCheckoutUrl(cart: CartData): Promise<string> {\n const validationErrors = validateCartData(cart)\n if (validationErrors.length > 0) {\n throw new TorqueCheckoutError(\n `Cart validation failed: ${validationErrors.join(', ')}`,\n 'VALIDATION_ERROR',\n 400,\n { errors: validationErrors }\n )\n }\n\n try {\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 TorqueCheckoutError(\n response.message || 'Failed to generate checkout URL',\n response.error || 'CHECKOUT_GENERATION_FAILED',\n response.statusCode || 500,\n response.details\n )\n }\n\n return response.checkoutUrl\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to generate checkout URL',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Create a checkout session and return the full API payload (Suby-style: URL + expiry + summary).\n * Use this when you need `cartSummary`, `expiresAt`, or to pass `successUrl` / `externalRef` via `cart.options`.\n */\n async requestCheckoutSession(cart: CartData): Promise<CheckoutSession> {\n const validationErrors = validateCartData(cart)\n if (validationErrors.length > 0) {\n throw new TorqueCheckoutError(\n `Cart validation failed: ${validationErrors.join(', ')}`,\n 'VALIDATION_ERROR',\n 400,\n { errors: validationErrors }\n )\n }\n\n try {\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 || !response.checkoutUrl) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to create checkout session',\n response.error || 'CHECKOUT_GENERATION_FAILED',\n response.statusCode || 500,\n response.details\n )\n }\n\n return response as CheckoutSession\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to create checkout session',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Generate a single product checkout URL\n * @param productId - Product ID\n * @param quantity - Quantity (default: 1)\n * @param customer - Optional customer data\n * @param options - Optional cart options\n * @returns Promise resolving to checkout URL\n */\n async generateProductCheckoutUrl(\n productId: string,\n quantity: number = 1,\n customer?: CustomerData,\n options?: CartOptions\n ): 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 * @param productId - Subscription product ID\n * @param paymentPlanId - Payment plan ID\n * @param customer - Optional customer data\n * @param options - Optional cart options\n * @returns Promise resolving to checkout URL\n */\n async generateSubscriptionCheckoutUrl(\n productId: string,\n paymentPlanId: string,\n customer?: CustomerData,\n options?: CartOptions\n ): 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 * @param cart - Cart data to validate\n * @returns Promise resolving to validation result\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 const validationErrors = validateCartData(cart)\n return {\n valid: false,\n errors: error instanceof Error \n ? [error.message, ...validationErrors]\n : ['Validation failed', ...validationErrors],\n warnings: [],\n estimatedTotal: 0\n }\n }\n }\n\n /**\n * Get order status\n * @param orderId - Order ID\n * @returns Promise resolving to order status\n * @throws {TorqueCheckoutError} If order not found or API request fails\n */\n async getOrderStatus(orderId: string): Promise<OrderStatus> {\n if (!orderId || typeof orderId !== 'string') {\n throw new TorqueCheckoutError('Order ID is required', 'INVALID_ORDER_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/checkout/order-status/${orderId}?businessId=${this.businessId}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get order status',\n response.error || 'ORDER_NOT_FOUND',\n response.statusCode || 404\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get order status',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Create a new subscription\n * @param data - Subscription creation data\n * @returns Promise resolving to created subscription\n */\n async createSubscription(data: CreateSubscriptionData): Promise<Subscription> {\n try {\n const response = await this.makeRequest('/api/subscriptions/create', {\n method: 'POST',\n body: data\n })\n\n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to create subscription',\n response.error || 'SUBSCRIPTION_CREATION_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to create subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscription by ID\n * @param subscriptionId - Subscription ID\n * @returns Promise resolving to subscription\n */\n async getSubscription(subscriptionId: string): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get subscription',\n response.error || 'SUBSCRIPTION_NOT_FOUND',\n response.statusCode || 404\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscriptions for a business\n * @param businessId - Business ID (optional, uses instance businessId if not provided)\n * @param status - Optional status filter\n * @param limit - Optional limit\n * @returns Promise resolving to array of subscriptions\n */\n async getBusinessSubscriptions(businessId?: string, status?: string, limit?: number): Promise<Subscription[]> {\n const bid = businessId || this.businessId\n const params = new URLSearchParams({ businessId: bid })\n if (status) params.append('status', status)\n if (limit) params.append('limit', limit.toString())\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/business?${params}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get business subscriptions',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n return Array.isArray(response) ? response : []\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get business subscriptions',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscriptions for a customer\n * @param customerEmail - Customer email\n * @returns Promise resolving to array of subscriptions\n */\n async getCustomerSubscriptions(customerEmail: string): Promise<Subscription[]> {\n if (!customerEmail || typeof customerEmail !== 'string' || !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(customerEmail)) {\n throw new TorqueCheckoutError('Valid customer email is required', 'INVALID_EMAIL', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/customer/${encodeURIComponent(customerEmail)}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get customer subscriptions',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n return Array.isArray(response) ? response : []\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get customer subscriptions',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Update subscription status\n * @param subscriptionId - Subscription ID\n * @param data - Update data\n * @returns Promise resolving to updated subscription\n */\n async updateSubscription(subscriptionId: string, data: UpdateSubscriptionData): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\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 TorqueCheckoutError(\n response.message || 'Failed to update subscription',\n response.error || 'UPDATE_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to update subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Cancel subscription\n * @param subscriptionId - Subscription ID\n * @param effectiveDate - Optional effective date for cancellation\n * @returns Promise resolving to cancelled subscription\n */\n async cancelSubscription(subscriptionId: string, effectiveDate?: number): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\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 TorqueCheckoutError(\n response.message || 'Failed to cancel subscription',\n response.error || 'CANCEL_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to cancel subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Pause subscription\n * @param subscriptionId - Subscription ID\n * @param resumeDate - Optional resume date\n * @returns Promise resolving to paused subscription\n */\n async pauseSubscription(subscriptionId: string, resumeDate?: number): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\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 TorqueCheckoutError(\n response.message || 'Failed to pause subscription',\n response.error || 'PAUSE_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to pause subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Resume subscription\n * @param subscriptionId - Subscription ID\n * @returns Promise resolving to resumed subscription\n */\n async resumeSubscription(subscriptionId: string): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/resume`, {\n method: 'PUT'\n })\n\n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to resume subscription',\n response.error || 'RESUME_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to resume subscription',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Process subscription renewal\n * @param subscriptionId - Subscription ID\n * @returns Promise resolving to renewed subscription\n */\n async processSubscriptionRenewal(subscriptionId: string): Promise<Subscription> {\n if (!subscriptionId || typeof subscriptionId !== 'string') {\n throw new TorqueCheckoutError('Subscription ID is required', 'INVALID_SUBSCRIPTION_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/${subscriptionId}/renew`, {\n method: 'PUT'\n })\n\n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to process subscription renewal',\n response.error || 'RENEWAL_FAILED',\n response.statusCode || 500\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to process subscription renewal',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscriptions due for renewal\n * @param daysAhead - Number of days ahead to check (default: 7)\n * @returns Promise resolving to array of subscriptions\n */\n async getSubscriptionsDueForRenewal(daysAhead: number = 7): Promise<Subscription[]> {\n if (typeof daysAhead !== 'number' || daysAhead < 0) {\n throw new TorqueCheckoutError('Days ahead must be a non-negative number', 'INVALID_PARAMETER', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/subscriptions/due-for-renewal?daysAhead=${daysAhead}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get subscriptions due for renewal',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n return Array.isArray(response) ? response : []\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get subscriptions due for renewal',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get all products for a business\n * Use this to sync your ecommerce catalog with Torque products\n * @param businessId - Business ID (optional, uses instance businessId if not provided)\n * @param status - Optional status filter ('active', 'inactive', 'draft', 'archived')\n * @returns Promise resolving to array of products\n * \n * @example\n * ```ts\n * const products = await torque.getProducts()\n * // Sync products with your database\n * products.forEach(product => {\n * await db.products.update({\n * where: { sku: product.sku },\n * data: { torqueProductId: product.id }\n * })\n * })\n * ```\n */\n async getProducts(businessId?: string, status?: 'active' | 'inactive' | 'draft' | 'archived'): Promise<Product[]> {\n const bid = businessId || this.businessId\n const params = new URLSearchParams({ businessId: bid })\n if (status) params.append('status', status)\n\n try {\n const response = await this.makeRequest(`/api/products?${params}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get products',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n return Array.isArray(response) ? response : []\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get products',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get subscription products for a business\n * @param businessId - Business ID (optional, uses instance businessId if not provided)\n * @returns Promise resolving to array of subscription products\n */\n async getSubscriptionProducts(businessId?: string): Promise<SubscriptionProduct[]> {\n const bid = businessId || this.businessId\n\n try {\n const response = await this.makeRequest(`/api/products/subscriptions?businessId=${bid}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get subscription products',\n response.error || 'FETCH_FAILED',\n response.statusCode || 500\n )\n }\n\n const products = Array.isArray(response) ? response : []\n // Map to SubscriptionProduct format with basePrice alias\n return products.map(p => ({\n ...p,\n basePrice: p.price || p.basePrice || 0\n }))\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get subscription products',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get a single product by ID\n * @param productId - Product ID (Torque product ID)\n * @returns Promise resolving to product\n */\n async getProduct(productId: string): Promise<Product> {\n if (!productId || typeof productId !== 'string') {\n throw new TorqueCheckoutError('Product ID is required', 'INVALID_PRODUCT_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/products/${productId}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get product',\n response.error || 'PRODUCT_NOT_FOUND',\n response.statusCode || 404\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get product',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Get product with payment plans\n * @param productId - Product ID\n * @returns Promise resolving to product with payment plans\n */\n async getProductWithPaymentPlans(productId: string): Promise<SubscriptionProduct> {\n if (!productId || typeof productId !== 'string') {\n throw new TorqueCheckoutError('Product ID is required', 'INVALID_PRODUCT_ID', 400)\n }\n\n try {\n const response = await this.makeRequest(`/api/products/${productId}`)\n \n if (response.error) {\n throw new TorqueCheckoutError(\n response.message || 'Failed to get product',\n response.error || 'PRODUCT_NOT_FOUND',\n response.statusCode || 404\n )\n }\n\n return response\n } catch (error) {\n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n throw new TorqueCheckoutError(\n error instanceof Error ? error.message : 'Failed to get product',\n 'NETWORK_ERROR',\n 500\n )\n }\n }\n\n /**\n * Send webhook event\n * @param orderId - Order ID\n * @param status - Order status\n * @param customerData - Optional customer data\n * @param metadata - Optional metadata\n */\n async sendWebhookEvent(\n orderId: string,\n status: string,\n customerData?: any,\n metadata?: Record<string, any>\n ): Promise<void> {\n if (!orderId || typeof orderId !== 'string') {\n throw new TorqueCheckoutError('Order ID is required', 'INVALID_ORDER_ID', 400)\n }\n\n try {\n await this.makeRequest('/api/webhooks/order-update', {\n method: 'POST',\n body: {\n orderId,\n status,\n customerData,\n metadata\n }\n })\n } catch (error) {\n // Webhook events are non-critical, log but don't throw\n console.warn('Failed to send webhook event:', error)\n }\n }\n\n /**\n * Track cart view for analytics\n * @param cartId - Cart ID\n * @param cartData - Cart data\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 // Analytics tracking is non-critical, log but don't throw\n console.warn('Failed to track cart view:', error)\n }\n }\n\n /**\n * Track checkout completion for analytics\n * @param orderId - Order ID\n * @param checkoutData - Checkout data\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 // Analytics tracking is non-critical, log but don't throw\n console.warn('Failed to track checkout completion:', error)\n }\n }\n\n /**\n * Track subscription creation for analytics\n * @param subscriptionId - Subscription ID\n * @param subscriptionData - Subscription data\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 // Analytics tracking is non-critical, log but don't throw\n console.warn('Failed to track subscription creation:', error)\n }\n }\n\n /**\n * Generate cart hash for caching\n * @param cart - Cart data\n * @returns Cart hash string\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 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 * @param subscriptionData - Subscription data\n * @returns Subscription hash string\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 * @private\n */\n private async makeRequest(\n endpoint: string,\n options: { method?: string; body?: any; headers?: Record<string, string> } = {}\n ): 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 { body, ...fetchOptions } = options\n const response = await fetch(url, {\n ...fetchOptions,\n method: options.method || 'GET',\n body: body ? JSON.stringify(body) : undefined,\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 const responseData = await response.json().catch(() => ({}))\n\n if (!response.ok) {\n throw new TorqueCheckoutError(\n responseData.message || `HTTP ${response.status}: ${response.statusText}`,\n responseData.error || 'API_ERROR',\n response.status,\n responseData.details\n )\n }\n\n return responseData\n } catch (error) {\n clearTimeout(timeoutId)\n \n if (error instanceof TorqueCheckoutError) {\n throw error\n }\n\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new TorqueCheckoutError('Request timeout', 'TIMEOUT', 408)\n }\n throw new TorqueCheckoutError(error.message, 'NETWORK_ERROR', 500)\n }\n \n throw new TorqueCheckoutError('Request failed', 'UNKNOWN_ERROR', 500)\n }\n }\n}\n\n// ============================================================================\n// Factory Functions\n// ============================================================================\n\n/**\n * Create a new TorqueCheckout instance\n * @param config - Configuration object\n * @returns TorqueCheckout instance\n */\nexport function createTorqueCheckout(config: TorqueConfig): TorqueCheckout {\n return new TorqueCheckout(config)\n}\n\n/**\n * Create a TorqueCheckout instance from environment variables\n * Requires TORQUE_BUSINESS_ID and TORQUE_API_KEY environment variables\n * @param overrides - Optional configuration overrides\n * @returns TorqueCheckout instance\n */\nexport function createTorqueCheckoutFromEnv(overrides?: Partial<TorqueConfig>): TorqueCheckout {\n const businessId = process.env.TORQUE_BUSINESS_ID || overrides?.businessId\n const apiKey = process.env.TORQUE_API_KEY || overrides?.apiKey\n\n if (!businessId || !apiKey) {\n throw new TorqueCheckoutError(\n 'TORQUE_BUSINESS_ID and TORQUE_API_KEY environment variables are required',\n 'MISSING_ENV_VARS',\n 400\n )\n }\n\n return new TorqueCheckout({\n businessId,\n apiKey,\n baseUrl: process.env.TORQUE_BASE_URL || overrides?.baseUrl,\n timeout: overrides?.timeout\n })\n}\n\n// ============================================================================\n// Type Exports\n// ============================================================================\n\n// Types are already exported above as interfaces/types\n// This section is for re-exporting if needed for convenience\n// All types are available via named exports from the main module\n"],"names":[],"mappings":"AAAA;;;;;;;;AAQG;AA+MH;;;AAGG;SACa,kBAAkB,CAChC,WAAmB,EACnB,OAA+B,UAAU,EAAA;AAEzC,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,MAAM,IAAI,mBAAmB,CAC3B,oCAAoC,EACpC,mBAAmB,EACnB,GAAG,CACJ;IACH;AACA,IAAA,IAAI,IAAI,KAAK,SAAS,EAAE;QACtB,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,qBAAqB,CAAC;IAC3D;SAAO;AACL,QAAA,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC;IACrC;AACF;AA+CA;AACA;AACA;AAEM,MAAO,mBAAoB,SAAQ,KAAK,CAAA;AAK5C,IAAA,WAAA,CAAY,OAAe,EAAE,IAAa,EAAE,UAAmB,EAAE,OAAa,EAAA;QAC5E,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,IAAI,GAAG,qBAAqB;AACjC,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAChB,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU;AAC5B,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;QACtB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC;IAC5D;AACD;AAED;AACA;AACA;AAEA;;;AAGG;AACH,SAAS,eAAe,CAAC,EAAU,EAAA;AACjC,IAAA,OAAO,uBAAuB,CAA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cAAc,IAAI,SAAS,EAAE,MAAM;AAE9D,IAAA,IAAI,CAAC,UAAU,IAAI,CAAC,MAAM,EAAE;QAC1B,MAAM,IAAI,mBAAmB,CAC3B,0EAA0E,EAC1E,kBAAkB,EAClB,GAAG,CACJ;IACH;IAEA,OAAO,IAAI,cAAc,CAAC;QACxB,UAAU;QACV,MAAM;QACN,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,SAAS,EAAE,OAAO;QAC1D,OAAO,EAAE,SAAS,EAAE;AACrB,KAAA,CAAC;AACJ;AAEA;AACA;AACA;AAEA;AACA;AACA;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,21 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @packageDocumentation
|
|
11
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* Redirect the browser to a Torque-hosted checkout URL.
|
|
14
|
+
* Prefer `same_tab` for a single continuous flow (matches common hosted-checkout UX).
|
|
15
|
+
*/
|
|
16
|
+
function redirectToCheckout(checkoutUrl, mode = 'same_tab') {
|
|
17
|
+
if (typeof window === 'undefined') {
|
|
18
|
+
throw new TorqueCheckoutError('redirectToCheckout is browser-only', 'SSR_NOT_SUPPORTED', 400);
|
|
19
|
+
}
|
|
20
|
+
if (mode === 'new_tab') {
|
|
21
|
+
window.open(checkoutUrl, '_blank', 'noopener,noreferrer');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
window.location.assign(checkoutUrl);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
12
27
|
// ============================================================================
|
|
13
28
|
// Error Classes
|
|
14
29
|
// ============================================================================
|
|
@@ -124,6 +139,39 @@ class TorqueCheckout {
|
|
|
124
139
|
throw new TorqueCheckoutError(error instanceof Error ? error.message : 'Failed to generate checkout URL', 'NETWORK_ERROR', 500);
|
|
125
140
|
}
|
|
126
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Create a checkout session and return the full API payload (Suby-style: URL + expiry + summary).
|
|
144
|
+
* Use this when you need `cartSummary`, `expiresAt`, or to pass `successUrl` / `externalRef` via `cart.options`.
|
|
145
|
+
*/
|
|
146
|
+
async requestCheckoutSession(cart) {
|
|
147
|
+
const validationErrors = validateCartData(cart);
|
|
148
|
+
if (validationErrors.length > 0) {
|
|
149
|
+
throw new TorqueCheckoutError(`Cart validation failed: ${validationErrors.join(', ')}`, 'VALIDATION_ERROR', 400, { errors: validationErrors });
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const response = await this.makeRequest('/api/torque-checkout', {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
body: {
|
|
155
|
+
businessId: this.businessId,
|
|
156
|
+
cart: {
|
|
157
|
+
items: cart.items
|
|
158
|
+
},
|
|
159
|
+
customerData: cart.customer,
|
|
160
|
+
options: cart.options
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
if (!response.success || !response.checkoutUrl) {
|
|
164
|
+
throw new TorqueCheckoutError(response.message || 'Failed to create checkout session', response.error || 'CHECKOUT_GENERATION_FAILED', response.statusCode || 500, response.details);
|
|
165
|
+
}
|
|
166
|
+
return response;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if (error instanceof TorqueCheckoutError) {
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
throw new TorqueCheckoutError(error instanceof Error ? error.message : 'Failed to create checkout session', 'NETWORK_ERROR', 500);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
127
175
|
/**
|
|
128
176
|
* Generate a single product checkout URL
|
|
129
177
|
* @param productId - Product ID
|
|
@@ -790,6 +838,7 @@ exports.TorqueCheckout = TorqueCheckout;
|
|
|
790
838
|
exports.TorqueCheckoutError = TorqueCheckoutError;
|
|
791
839
|
exports.createTorqueCheckout = createTorqueCheckout;
|
|
792
840
|
exports.createTorqueCheckoutFromEnv = createTorqueCheckoutFromEnv;
|
|
841
|
+
exports.redirectToCheckout = redirectToCheckout;
|
|
793
842
|
exports.validateCartData = validateCartData;
|
|
794
843
|
exports.validateCartItem = validateCartItem;
|
|
795
844
|
exports.validateConfig = validateConfig;
|