torque-checkout 3.2.0 → 3.2.1
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 +1 -1
- package/README.md +35 -10
- package/dist/index.d.ts +19 -3
- package/dist/index.esm.js +15 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/nextjs.d.ts +2 -1
- package/dist/nextjs.esm.js +3 -2
- package/dist/nextjs.esm.js.map +1 -1
- package/dist/nextjs.js +3 -2
- package/dist/nextjs.js.map +1 -1
- package/dist/react.esm.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
13
13
|
## [3.2.0] - 2026-04-18
|
|
14
14
|
|
|
15
15
|
### Added
|
|
16
|
-
- **Checkout session response**: `TorqueCheckout.requestCheckoutSession(cart)` returns full `{ success, checkoutUrl, expiresAt, cartSummary, business }` (
|
|
16
|
+
- **Checkout session response**: `TorqueCheckout.requestCheckoutSession(cart)` returns full `{ success, checkoutUrl, expiresAt, cartSummary, business }` (hosted session + checkout URL).
|
|
17
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
18
|
- **`redirectToCheckout(url, mode)`** — same-tab vs new-tab navigation helper.
|
|
19
19
|
- **`useTorqueCheckout`**: `requestCheckoutSession` for full session payloads alongside `generateCheckout`.
|
package/README.md
CHANGED
|
@@ -97,7 +97,18 @@ TORQUE_BUSINESS_ID=your_business_id
|
|
|
97
97
|
TORQUE_API_KEY=your_api_key
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
**4.
|
|
100
|
+
**4. Checkout (≤6 lines)**
|
|
101
|
+
```ts
|
|
102
|
+
import { checkout, redirectToCheckout } from 'torque-checkout'
|
|
103
|
+
|
|
104
|
+
const url = await checkout({ productId: 'prod_123', email: 'customer@example.com' })
|
|
105
|
+
redirectToCheckout(url)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Done!** Hosted checkout → customer pays → payment goes to your wallet.
|
|
109
|
+
|
|
110
|
+
### React button (optional)
|
|
111
|
+
|
|
101
112
|
```tsx
|
|
102
113
|
'use client'
|
|
103
114
|
import { useTorqueCheckout } from 'torque-checkout/react'
|
|
@@ -120,11 +131,9 @@ export default function CheckoutButton({ torqueProductId }: { torqueProductId: s
|
|
|
120
131
|
}
|
|
121
132
|
```
|
|
122
133
|
|
|
123
|
-
|
|
134
|
+
### Checkout sessions & return URL
|
|
124
135
|
|
|
125
|
-
|
|
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:
|
|
136
|
+
Torque’s hosted checkout is a **session URL** you send the customer to (redirect after payment via merchant `successUrl`). The SDK can also return the **full response** and attach **merchant metadata** to the cart:
|
|
128
137
|
|
|
129
138
|
| `cart.options` field | Purpose |
|
|
130
139
|
|----------------------|--------|
|
|
@@ -187,7 +196,7 @@ Webhooks: use `verifyTorqueWebhookSignature` from `torque-checkout/nextjs` with
|
|
|
187
196
|
- Link your ecommerce products to Torque products
|
|
188
197
|
- Example: `product.torqueProductId = "j1234567890abcdef"`
|
|
189
198
|
|
|
190
|
-
> **Why?** Torque products are the source of truth for prices, names, and product data. This ensures consistency and prevents price manipulation.
|
|
199
|
+
> **Why?** Torque products are the source of truth for prices, names, and product data. This ensures consistency and prevents price manipulation. Create catalog items in Torque before generating checkout links.
|
|
191
200
|
|
|
192
201
|
### Step 2: Configure Environment Variables
|
|
193
202
|
|
|
@@ -233,12 +242,15 @@ export default function CheckoutButton() {
|
|
|
233
242
|
|
|
234
243
|
#### Option B: Server-Side API Route (Most Secure)
|
|
235
244
|
|
|
245
|
+
The handler keeps your Torque API key on the server: it reads `TORQUE_BUSINESS_ID` and `TORQUE_API_KEY` from the environment, accepts a **POST** JSON body (`CartData`: `items` with Torque product IDs, `customer` with at least `email`), and responds with `{ success: true, checkoutUrl, expiresAt }` or `{ success: false, error, code }`.
|
|
246
|
+
|
|
236
247
|
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
248
|
|
|
238
249
|
```ts
|
|
239
250
|
// app/api/checkout-session/route.ts
|
|
240
251
|
import { handleCheckoutRequest } from 'torque-checkout/nextjs'
|
|
241
252
|
|
|
253
|
+
// `handleCheckoutRequest()` returns the async function Next assigns to POST.
|
|
242
254
|
export const POST = handleCheckoutRequest()
|
|
243
255
|
```
|
|
244
256
|
|
|
@@ -254,11 +266,23 @@ const response = await fetch('/api/checkout-session', {
|
|
|
254
266
|
})
|
|
255
267
|
})
|
|
256
268
|
|
|
257
|
-
const
|
|
258
|
-
|
|
269
|
+
const data = await response.json()
|
|
270
|
+
if (!response.ok || !data.success || !data.checkoutUrl) {
|
|
271
|
+
throw new Error(data.error ?? 'Could not start checkout')
|
|
272
|
+
}
|
|
273
|
+
window.location.href = data.checkoutUrl
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
#### Option C: One-shot `checkout()` (≤6 lines)
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
import { checkout, redirectToCheckout } from 'torque-checkout'
|
|
280
|
+
|
|
281
|
+
const url = await checkout({ productId: 'prod_123', email: 'customer@example.com' })
|
|
282
|
+
redirectToCheckout(url)
|
|
259
283
|
```
|
|
260
284
|
|
|
261
|
-
#### Option
|
|
285
|
+
#### Option D: Direct SDK instance
|
|
262
286
|
|
|
263
287
|
```ts
|
|
264
288
|
import { createTorqueCheckoutFromEnv } from 'torque-checkout'
|
|
@@ -942,6 +966,7 @@ try {
|
|
|
942
966
|
|
|
943
967
|
// GOOD - Use server-side API routes
|
|
944
968
|
// app/api/checkout-session/route.ts
|
|
969
|
+
import { handleCheckoutRequest } from 'torque-checkout/nextjs'
|
|
945
970
|
export const POST = handleCheckoutRequest()
|
|
946
971
|
```
|
|
947
972
|
|
|
@@ -1096,7 +1121,7 @@ MIT © [Torque](https://torque.fi)
|
|
|
1096
1121
|
|
|
1097
1122
|
### How Product Sync Works
|
|
1098
1123
|
|
|
1099
|
-
Torque products are the **source of truth** for checkout
|
|
1124
|
+
Torque products are the **source of truth** for checkout:
|
|
1100
1125
|
|
|
1101
1126
|
1. **Upload products to Torque** at `/business/products`
|
|
1102
1127
|
2. **Get Torque product IDs** (manually or programmatically)
|
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export interface CartOptions {
|
|
|
41
41
|
redirectUrl?: string;
|
|
42
42
|
/**
|
|
43
43
|
* After a successful payment on the hosted checkout, the confirmation modal can show
|
|
44
|
-
* “Return to store” (cart flows)
|
|
44
|
+
* “Return to store” (cart flows): merchant `successUrl` redirect after payment.
|
|
45
45
|
*/
|
|
46
46
|
successUrl?: string;
|
|
47
47
|
/** Shown if the buyer abandons before paying (optional future use / analytics). */
|
|
@@ -189,7 +189,7 @@ export interface CheckoutResponse {
|
|
|
189
189
|
logo?: string;
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
|
-
/** Full API response from `POST /api/torque-checkout` (
|
|
192
|
+
/** Full API response from `POST /api/torque-checkout` (checkout session object). */
|
|
193
193
|
export type CheckoutSession = CheckoutResponse;
|
|
194
194
|
/**
|
|
195
195
|
* Redirect the browser to a Torque-hosted checkout URL.
|
|
@@ -261,7 +261,7 @@ export declare class TorqueCheckout {
|
|
|
261
261
|
*/
|
|
262
262
|
generateCartCheckoutUrl(cart: CartData): Promise<string>;
|
|
263
263
|
/**
|
|
264
|
-
* Create a checkout session and return the full API payload (
|
|
264
|
+
* Create a checkout session and return the full API payload (URL + expiry + summary).
|
|
265
265
|
* Use this when you need `cartSummary`, `expiresAt`, or to pass `successUrl` / `externalRef` via `cart.options`.
|
|
266
266
|
*/
|
|
267
267
|
requestCheckoutSession(cart: CartData): Promise<CheckoutSession>;
|
|
@@ -456,3 +456,19 @@ export declare function createTorqueCheckout(config: TorqueConfig): TorqueChecko
|
|
|
456
456
|
* @returns TorqueCheckout instance
|
|
457
457
|
*/
|
|
458
458
|
export declare function createTorqueCheckoutFromEnv(overrides?: Partial<TorqueConfig>): TorqueCheckout;
|
|
459
|
+
/**
|
|
460
|
+
* One-shot product checkout URL (≤6-line hero).
|
|
461
|
+
* Requires `TORQUE_BUSINESS_ID` + `TORQUE_API_KEY` (or pass `config`).
|
|
462
|
+
*
|
|
463
|
+
* ```ts
|
|
464
|
+
* import { checkout } from 'torque-checkout'
|
|
465
|
+
* const url = await checkout({ productId: 'prod_123', email: 'a@b.com' })
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
export declare function checkout(params: {
|
|
469
|
+
productId: string;
|
|
470
|
+
email: string;
|
|
471
|
+
quantity?: number;
|
|
472
|
+
options?: CartOptions;
|
|
473
|
+
config?: Partial<TorqueConfig>;
|
|
474
|
+
}): Promise<string>;
|
package/dist/index.esm.js
CHANGED
|
@@ -138,7 +138,7 @@ class TorqueCheckout {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
* Create a checkout session and return the full API payload (
|
|
141
|
+
* Create a checkout session and return the full API payload (URL + expiry + summary).
|
|
142
142
|
* Use this when you need `cartSummary`, `expiresAt`, or to pass `successUrl` / `externalRef` via `cart.options`.
|
|
143
143
|
*/
|
|
144
144
|
async requestCheckoutSession(cart) {
|
|
@@ -825,6 +825,19 @@ function createTorqueCheckoutFromEnv(overrides) {
|
|
|
825
825
|
timeout: overrides?.timeout
|
|
826
826
|
});
|
|
827
827
|
}
|
|
828
|
+
/**
|
|
829
|
+
* One-shot product checkout URL (≤6-line hero).
|
|
830
|
+
* Requires `TORQUE_BUSINESS_ID` + `TORQUE_API_KEY` (or pass `config`).
|
|
831
|
+
*
|
|
832
|
+
* ```ts
|
|
833
|
+
* import { checkout } from 'torque-checkout'
|
|
834
|
+
* const url = await checkout({ productId: 'prod_123', email: 'a@b.com' })
|
|
835
|
+
* ```
|
|
836
|
+
*/
|
|
837
|
+
async function checkout(params) {
|
|
838
|
+
const torque = createTorqueCheckoutFromEnv(params.config);
|
|
839
|
+
return torque.generateProductCheckoutUrl(params.productId, params.quantity ?? 1, { email: params.email }, params.options);
|
|
840
|
+
}
|
|
828
841
|
// ============================================================================
|
|
829
842
|
// Type Exports
|
|
830
843
|
// ============================================================================
|
|
@@ -832,5 +845,5 @@ function createTorqueCheckoutFromEnv(overrides) {
|
|
|
832
845
|
// This section is for re-exporting if needed for convenience
|
|
833
846
|
// All types are available via named exports from the main module
|
|
834
847
|
|
|
835
|
-
export { TorqueCheckout, TorqueCheckoutError, createTorqueCheckout, createTorqueCheckoutFromEnv, redirectToCheckout, validateCartData, validateCartItem, validateConfig };
|
|
848
|
+
export { TorqueCheckout, TorqueCheckoutError, checkout, createTorqueCheckout, createTorqueCheckoutFromEnv, redirectToCheckout, validateCartData, validateCartItem, validateConfig };
|
|
836
849
|
//# 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 /** @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,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IAAI,mBAAmB,CAAC,iBAAiB,EAAE,SAAS,EAAE,GAAG,CAAC;gBAClE;gBACA,MAAM,IAAI,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,CAAC;YACpE;YAEA,MAAM,IAAI,mBAAmB,CAAC,gBAAgB,EAAE,eAAe,EAAE,GAAG,CAAC;QACvE;IACF;AACD;AAED;AACA;AACA;AAEA;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,MAAoB,EAAA;AACvD,IAAA,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC;AACnC;AAEA;;;;;AAKG;AACG,SAAU,2BAA2B,CAAC,SAAiC,EAAA;IAC3E,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,SAAS,EAAE,UAAU;IAC1E,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,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;;;;"}
|
|
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): merchant `successUrl` redirect after payment.\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` (checkout 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 (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 * One-shot product checkout URL (≤6-line hero).\n * Requires `TORQUE_BUSINESS_ID` + `TORQUE_API_KEY` (or pass `config`).\n *\n * ```ts\n * import { checkout } from 'torque-checkout'\n * const url = await checkout({ productId: 'prod_123', email: 'a@b.com' })\n * ```\n */\nexport async function checkout(params: {\n productId: string\n email: string\n quantity?: number\n options?: CartOptions\n config?: Partial<TorqueConfig>\n}): Promise<string> {\n const torque = createTorqueCheckoutFromEnv(params.config)\n return torque.generateProductCheckoutUrl(\n params.productId,\n params.quantity ?? 1,\n { email: params.email },\n params.options,\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,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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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;;;;;;;;AAQG;AACI,eAAe,QAAQ,CAAC,MAM9B,EAAA;IACC,MAAM,MAAM,GAAG,2BAA2B,CAAC,MAAM,CAAC,MAAM,CAAC;IACzD,OAAO,MAAM,CAAC,0BAA0B,CACtC,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,QAAQ,IAAI,CAAC,EACpB,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,EACvB,MAAM,CAAC,OAAO,CACf;AACH;AAEA;AACA;AACA;AAEA;AACA;AACA;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -140,7 +140,7 @@ class TorqueCheckout {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
|
-
* Create a checkout session and return the full API payload (
|
|
143
|
+
* Create a checkout session and return the full API payload (URL + expiry + summary).
|
|
144
144
|
* Use this when you need `cartSummary`, `expiresAt`, or to pass `successUrl` / `externalRef` via `cart.options`.
|
|
145
145
|
*/
|
|
146
146
|
async requestCheckoutSession(cart) {
|
|
@@ -827,6 +827,19 @@ function createTorqueCheckoutFromEnv(overrides) {
|
|
|
827
827
|
timeout: overrides?.timeout
|
|
828
828
|
});
|
|
829
829
|
}
|
|
830
|
+
/**
|
|
831
|
+
* One-shot product checkout URL (≤6-line hero).
|
|
832
|
+
* Requires `TORQUE_BUSINESS_ID` + `TORQUE_API_KEY` (or pass `config`).
|
|
833
|
+
*
|
|
834
|
+
* ```ts
|
|
835
|
+
* import { checkout } from 'torque-checkout'
|
|
836
|
+
* const url = await checkout({ productId: 'prod_123', email: 'a@b.com' })
|
|
837
|
+
* ```
|
|
838
|
+
*/
|
|
839
|
+
async function checkout(params) {
|
|
840
|
+
const torque = createTorqueCheckoutFromEnv(params.config);
|
|
841
|
+
return torque.generateProductCheckoutUrl(params.productId, params.quantity ?? 1, { email: params.email }, params.options);
|
|
842
|
+
}
|
|
830
843
|
// ============================================================================
|
|
831
844
|
// Type Exports
|
|
832
845
|
// ============================================================================
|
|
@@ -836,6 +849,7 @@ function createTorqueCheckoutFromEnv(overrides) {
|
|
|
836
849
|
|
|
837
850
|
exports.TorqueCheckout = TorqueCheckout;
|
|
838
851
|
exports.TorqueCheckoutError = TorqueCheckoutError;
|
|
852
|
+
exports.checkout = checkout;
|
|
839
853
|
exports.createTorqueCheckout = createTorqueCheckout;
|
|
840
854
|
exports.createTorqueCheckoutFromEnv = createTorqueCheckoutFromEnv;
|
|
841
855
|
exports.redirectToCheckout = redirectToCheckout;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.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,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AE,GAAG,CAAC;QACvE;IACF;AACD;AAED;AACA;AACA;AAEA;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,MAAoB,EAAA;AACvD,IAAA,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC;AACnC;AAEA;;;;;AAKG;AACG,SAAU,2BAA2B,CAAC,SAAiC,EAAA;IAC3E,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,SAAS,EAAE,UAAU;IAC1E,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,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;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.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): merchant `successUrl` redirect after payment.\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` (checkout 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 (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 * One-shot product checkout URL (≤6-line hero).\n * Requires `TORQUE_BUSINESS_ID` + `TORQUE_API_KEY` (or pass `config`).\n *\n * ```ts\n * import { checkout } from 'torque-checkout'\n * const url = await checkout({ productId: 'prod_123', email: 'a@b.com' })\n * ```\n */\nexport async function checkout(params: {\n productId: string\n email: string\n quantity?: number\n options?: CartOptions\n config?: Partial<TorqueConfig>\n}): Promise<string> {\n const torque = createTorqueCheckoutFromEnv(params.config)\n return torque.generateProductCheckoutUrl(\n params.productId,\n params.quantity ?? 1,\n { email: params.email },\n params.options,\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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;;;;;;;AAQG;AACI,eAAe,QAAQ,CAAC,MAM9B,EAAA;IACC,MAAM,MAAM,GAAG,2BAA2B,CAAC,MAAM,CAAC,MAAM,CAAC;IACzD,OAAO,MAAM,CAAC,0BAA0B,CACtC,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,QAAQ,IAAI,CAAC,EACpB,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,EACvB,MAAM,CAAC,OAAO,CACf;AACH;AAEA;AACA;AACA;AAEA;AACA;AACA;;;;;;;;;;;;"}
|
package/dist/nextjs.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface CheckoutApiHandlerOptions {
|
|
|
40
40
|
* // app/api/checkout-session/route.ts (path is your choice)
|
|
41
41
|
* import { handleCheckoutRequest } from 'torque-checkout/nextjs'
|
|
42
42
|
*
|
|
43
|
+
* // Returns the POST handler: JSON cart body → Torque (env credentials) → { success, checkoutUrl } or error JSON
|
|
43
44
|
* export const POST = handleCheckoutRequest({
|
|
44
45
|
* onSuccess: async (url, cart) => {
|
|
45
46
|
* // Log checkout generation
|
|
@@ -96,7 +97,7 @@ export declare function handleWebhook(options?: WebhookHandlerOptions): (request
|
|
|
96
97
|
}>>;
|
|
97
98
|
/**
|
|
98
99
|
* Verify `X-Torque-Signature` (or raw hex) against HMAC-SHA256 of the **raw** webhook body.
|
|
99
|
-
* Accepts `hex`, `sha256=<hex>`, or `v1=<hex>`
|
|
100
|
+
* Accepts `hex`, `sha256=<hex>`, or `v1=<hex>` prefix forms.
|
|
100
101
|
*/
|
|
101
102
|
export declare function verifyTorqueWebhookSignature(rawBody: string, signatureHeader: string | null, secret: string): boolean;
|
|
102
103
|
/**
|
package/dist/nextjs.esm.js
CHANGED
|
@@ -44,6 +44,7 @@ async function generateCheckoutUrl(cart, config) {
|
|
|
44
44
|
* // app/api/checkout-session/route.ts (path is your choice)
|
|
45
45
|
* import { handleCheckoutRequest } from 'torque-checkout/nextjs'
|
|
46
46
|
*
|
|
47
|
+
* // Returns the POST handler: JSON cart body → Torque (env credentials) → { success, checkoutUrl } or error JSON
|
|
47
48
|
* export const POST = handleCheckoutRequest({
|
|
48
49
|
* onSuccess: async (url, cart) => {
|
|
49
50
|
* // Log checkout generation
|
|
@@ -108,7 +109,7 @@ function handleWebhook(options = {}) {
|
|
|
108
109
|
catch {
|
|
109
110
|
return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 });
|
|
110
111
|
}
|
|
111
|
-
// Verify HMAC-SHA256 of raw body (
|
|
112
|
+
// Verify HMAC-SHA256 of raw body (signed webhook pattern)
|
|
112
113
|
if (options.secret) {
|
|
113
114
|
const signature = request.headers.get('x-torque-signature');
|
|
114
115
|
if (!verifyTorqueWebhookSignature(rawBody, signature, options.secret)) {
|
|
@@ -145,7 +146,7 @@ function handleWebhook(options = {}) {
|
|
|
145
146
|
}
|
|
146
147
|
/**
|
|
147
148
|
* Verify `X-Torque-Signature` (or raw hex) against HMAC-SHA256 of the **raw** webhook body.
|
|
148
|
-
* Accepts `hex`, `sha256=<hex>`, or `v1=<hex>`
|
|
149
|
+
* Accepts `hex`, `sha256=<hex>`, or `v1=<hex>` prefix forms.
|
|
149
150
|
*/
|
|
150
151
|
function verifyTorqueWebhookSignature(rawBody, signatureHeader, secret) {
|
|
151
152
|
if (!signatureHeader || !secret)
|
package/dist/nextjs.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjs.esm.js","sources":["../src/nextjs.ts"],"sourcesContent":["/**\n * Next.js Server-Side Utilities\n * Server-side helpers for Next.js App Router and Pages Router\n * \n * @requires next >= 13.0.0\n */\n\nimport { createHmac, timingSafeEqual } from 'crypto'\n// Type-only imports for better compatibility\nimport type { NextRequest } from 'next/server'\nimport { NextResponse } from 'next/server'\nimport {\n TorqueCheckout,\n createTorqueCheckout,\n createTorqueCheckoutFromEnv,\n type TorqueConfig,\n type CartData,\n type OrderStatus,\n type TorqueCheckoutError\n} from './index'\n\n// ============================================================================\n// Server-Side Checkout Helper\n// ============================================================================\n\n/**\n * Generate checkout URL on the server\n * Use this in Next.js API routes or Server Components\n * \n * @example\n * ```ts\n * // app/api/checkout-session/route.ts (path is your choice)\n * import { generateCheckoutUrl } from 'torque-checkout/nextjs'\n * \n * export async function POST(request: Request) {\n * const cart = await request.json()\n * const url = await generateCheckoutUrl(cart, {\n * businessId: process.env.TORQUE_BUSINESS_ID!,\n * apiKey: process.env.TORQUE_API_KEY!\n * })\n * return Response.json({ checkoutUrl: url })\n * }\n * ```\n */\nexport async function generateCheckoutUrl(\n cart: CartData,\n config?: TorqueConfig\n): Promise<string> {\n const torque = config \n ? createTorqueCheckout(config)\n : createTorqueCheckoutFromEnv()\n\n return torque.generateCartCheckoutUrl(cart)\n}\n\n// ============================================================================\n// API Route Handler Helpers\n// ============================================================================\n\nexport interface CheckoutApiHandlerOptions {\n config?: TorqueConfig\n onSuccess?: (checkoutUrl: string, cart: CartData) => Promise<void> | void\n onError?: (error: TorqueCheckoutError, cart: CartData) => Promise<void> | void\n}\n\n/**\n * Next.js API route handler for generating checkout URLs\n * \n * @example\n * ```ts\n * // app/api/checkout-session/route.ts (path is your choice)\n * import { handleCheckoutRequest } from 'torque-checkout/nextjs'\n * \n * export const POST = handleCheckoutRequest({\n * onSuccess: async (url, cart) => {\n * // Log checkout generation\n * console.log('Checkout generated:', url)\n * }\n * })\n * ```\n */\nexport function handleCheckoutRequest(options: CheckoutApiHandlerOptions = {}) {\n return async (request: NextRequest) => {\n try {\n const cart: CartData = await request.json()\n\n const torque = options.config\n ? createTorqueCheckout(options.config)\n : createTorqueCheckoutFromEnv()\n\n const checkoutUrl = await torque.generateCartCheckoutUrl(cart)\n\n await options.onSuccess?.(checkoutUrl, cart)\n\n return NextResponse.json({\n success: true,\n checkoutUrl,\n expiresAt: new Date(Date.now() + (cart.options?.expiresIn || 24 * 60 * 60 * 1000)).toISOString()\n })\n } catch (error) {\n const torqueError = error instanceof Error && 'code' in error\n ? error as TorqueCheckoutError\n : new Error(error instanceof Error ? error.message : 'Unknown error') as TorqueCheckoutError\n\n await options.onError?.(torqueError, {} as CartData)\n\n return NextResponse.json(\n {\n success: false,\n error: torqueError.message,\n code: torqueError.code || 'UNKNOWN_ERROR'\n },\n { status: torqueError.statusCode || 500 }\n )\n }\n }\n}\n\n// ============================================================================\n// Webhook Handler\n// ============================================================================\n\nexport interface WebhookEvent {\n type: 'order.created' | 'order.completed' | 'order.failed' | 'subscription.created' | 'subscription.cancelled'\n orderId?: string\n subscriptionId?: string\n data: any\n timestamp: number\n}\n\nexport interface WebhookHandlerOptions {\n secret?: string\n onOrderCreated?: (event: WebhookEvent) => Promise<void> | void\n onOrderCompleted?: (event: WebhookEvent) => Promise<void> | void\n onOrderFailed?: (event: WebhookEvent) => Promise<void> | void\n onSubscriptionCreated?: (event: WebhookEvent) => Promise<void> | void\n onSubscriptionCancelled?: (event: WebhookEvent) => Promise<void> | void\n}\n\n/**\n * Next.js API route handler for webhook events\n * \n * @example\n * ```ts\n * // app/api/webhooks/torque/route.ts\n * import { handleWebhook } from 'torque-checkout/nextjs'\n * \n * export const POST = handleWebhook({\n * secret: process.env.TORQUE_WEBHOOK_SECRET,\n * onOrderCompleted: async (event) => {\n * // Fulfill order\n * await fulfillOrder(event.orderId!)\n * }\n * })\n * ```\n */\nexport function handleWebhook(options: WebhookHandlerOptions = {}) {\n return async (request: NextRequest) => {\n try {\n const rawBody = await request.text()\n let event: WebhookEvent\n try {\n event = JSON.parse(rawBody) as WebhookEvent\n } catch {\n return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 })\n }\n\n // Verify HMAC-SHA256 of raw body (same pattern as Suby-style signed webhooks)\n if (options.secret) {\n const signature = request.headers.get('x-torque-signature')\n if (!verifyTorqueWebhookSignature(rawBody, signature, options.secret)) {\n return NextResponse.json(\n { error: 'Invalid signature' },\n { status: 401 }\n )\n }\n }\n\n // Route to appropriate handler\n switch (event.type) {\n case 'order.created':\n await options.onOrderCreated?.(event)\n break\n case 'order.completed':\n await options.onOrderCompleted?.(event)\n break\n case 'order.failed':\n await options.onOrderFailed?.(event)\n break\n case 'subscription.created':\n await options.onSubscriptionCreated?.(event)\n break\n case 'subscription.cancelled':\n await options.onSubscriptionCancelled?.(event)\n break\n default:\n console.warn('Unknown webhook event type:', event.type)\n }\n\n return NextResponse.json({ received: true })\n } catch (error) {\n console.error('Webhook handler error:', error)\n return NextResponse.json(\n { error: 'Webhook processing failed' },\n { status: 500 }\n )\n }\n }\n}\n\n/**\n * Verify `X-Torque-Signature` (or raw hex) against HMAC-SHA256 of the **raw** webhook body.\n * Accepts `hex`, `sha256=<hex>`, or `v1=<hex>` (Suby-style prefix).\n */\nexport function verifyTorqueWebhookSignature(\n rawBody: string,\n signatureHeader: string | null,\n secret: string\n): boolean {\n if (!signatureHeader || !secret) return false\n const expectedHex = createHmac('sha256', secret).update(rawBody, 'utf8').digest('hex')\n const normalized = signatureHeader.trim().replace(/^(sha256|v1)=/i, '')\n try {\n const a = Buffer.from(normalized, 'hex')\n const b = Buffer.from(expectedHex, 'hex')\n if (a.length !== b.length) return false\n return timingSafeEqual(a, b)\n } catch {\n return false\n }\n}\n\n// ============================================================================\n// Order Status Helper\n// ============================================================================\n\n/**\n * Get order status on the server\n * \n * @example\n * ```ts\n * // app/api/orders/[orderId]/route.ts\n * import { getOrderStatus } from 'torque-checkout/nextjs'\n * \n * export async function GET(request: Request, { params }: { params: { orderId: string } }) {\n * const status = await getOrderStatus(params.orderId)\n * return Response.json(status)\n * }\n * ```\n */\nexport async function getOrderStatus(\n orderId: string,\n config?: TorqueConfig\n): Promise<OrderStatus> {\n const torque = config\n ? createTorqueCheckout(config)\n : createTorqueCheckoutFromEnv()\n\n return torque.getOrderStatus(orderId)\n}\n\n"],"names":[],"mappings":";;;;AAAA;;;;;AAKG;AAgBH;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AACI,eAAe,mBAAmB,CACvC,IAAc,EACd,MAAqB,EAAA;IAErB,MAAM,MAAM,GAA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AE,IAAA,MAAM;AACN,QAAA,OAAO,KAAK;IACd;AACF;AAEA;AACA;AACA;AAEA;;;;;;;;;;;;;AAaG;AACI,eAAe,cAAc,CAClC,OAAe,EACf,MAAqB,EAAA;IAErB,MAAM,MAAM,GAAG;AACb,UAAE,oBAAoB,CAAC,MAAM;UAC3B,2BAA2B,EAAE;AAEjC,IAAA,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC;AACvC;;;;"}
|
|
1
|
+
{"version":3,"file":"nextjs.esm.js","sources":["../src/nextjs.ts"],"sourcesContent":["/**\n * Next.js Server-Side Utilities\n * Server-side helpers for Next.js App Router and Pages Router\n * \n * @requires next >= 13.0.0\n */\n\nimport { createHmac, timingSafeEqual } from 'crypto'\n// Type-only imports for better compatibility\nimport type { NextRequest } from 'next/server'\nimport { NextResponse } from 'next/server'\nimport {\n TorqueCheckout,\n createTorqueCheckout,\n createTorqueCheckoutFromEnv,\n type TorqueConfig,\n type CartData,\n type OrderStatus,\n type TorqueCheckoutError\n} from './index'\n\n// ============================================================================\n// Server-Side Checkout Helper\n// ============================================================================\n\n/**\n * Generate checkout URL on the server\n * Use this in Next.js API routes or Server Components\n * \n * @example\n * ```ts\n * // app/api/checkout-session/route.ts (path is your choice)\n * import { generateCheckoutUrl } from 'torque-checkout/nextjs'\n * \n * export async function POST(request: Request) {\n * const cart = await request.json()\n * const url = await generateCheckoutUrl(cart, {\n * businessId: process.env.TORQUE_BUSINESS_ID!,\n * apiKey: process.env.TORQUE_API_KEY!\n * })\n * return Response.json({ checkoutUrl: url })\n * }\n * ```\n */\nexport async function generateCheckoutUrl(\n cart: CartData,\n config?: TorqueConfig\n): Promise<string> {\n const torque = config \n ? createTorqueCheckout(config)\n : createTorqueCheckoutFromEnv()\n\n return torque.generateCartCheckoutUrl(cart)\n}\n\n// ============================================================================\n// API Route Handler Helpers\n// ============================================================================\n\nexport interface CheckoutApiHandlerOptions {\n config?: TorqueConfig\n onSuccess?: (checkoutUrl: string, cart: CartData) => Promise<void> | void\n onError?: (error: TorqueCheckoutError, cart: CartData) => Promise<void> | void\n}\n\n/**\n * Next.js API route handler for generating checkout URLs\n * \n * @example\n * ```ts\n * // app/api/checkout-session/route.ts (path is your choice)\n * import { handleCheckoutRequest } from 'torque-checkout/nextjs'\n *\n * // Returns the POST handler: JSON cart body → Torque (env credentials) → { success, checkoutUrl } or error JSON\n * export const POST = handleCheckoutRequest({\n * onSuccess: async (url, cart) => {\n * // Log checkout generation\n * console.log('Checkout generated:', url)\n * }\n * })\n * ```\n */\nexport function handleCheckoutRequest(options: CheckoutApiHandlerOptions = {}) {\n return async (request: NextRequest) => {\n try {\n const cart: CartData = await request.json()\n\n const torque = options.config\n ? createTorqueCheckout(options.config)\n : createTorqueCheckoutFromEnv()\n\n const checkoutUrl = await torque.generateCartCheckoutUrl(cart)\n\n await options.onSuccess?.(checkoutUrl, cart)\n\n return NextResponse.json({\n success: true,\n checkoutUrl,\n expiresAt: new Date(Date.now() + (cart.options?.expiresIn || 24 * 60 * 60 * 1000)).toISOString()\n })\n } catch (error) {\n const torqueError = error instanceof Error && 'code' in error\n ? error as TorqueCheckoutError\n : new Error(error instanceof Error ? error.message : 'Unknown error') as TorqueCheckoutError\n\n await options.onError?.(torqueError, {} as CartData)\n\n return NextResponse.json(\n {\n success: false,\n error: torqueError.message,\n code: torqueError.code || 'UNKNOWN_ERROR'\n },\n { status: torqueError.statusCode || 500 }\n )\n }\n }\n}\n\n// ============================================================================\n// Webhook Handler\n// ============================================================================\n\nexport interface WebhookEvent {\n type: 'order.created' | 'order.completed' | 'order.failed' | 'subscription.created' | 'subscription.cancelled'\n orderId?: string\n subscriptionId?: string\n data: any\n timestamp: number\n}\n\nexport interface WebhookHandlerOptions {\n secret?: string\n onOrderCreated?: (event: WebhookEvent) => Promise<void> | void\n onOrderCompleted?: (event: WebhookEvent) => Promise<void> | void\n onOrderFailed?: (event: WebhookEvent) => Promise<void> | void\n onSubscriptionCreated?: (event: WebhookEvent) => Promise<void> | void\n onSubscriptionCancelled?: (event: WebhookEvent) => Promise<void> | void\n}\n\n/**\n * Next.js API route handler for webhook events\n * \n * @example\n * ```ts\n * // app/api/webhooks/torque/route.ts\n * import { handleWebhook } from 'torque-checkout/nextjs'\n * \n * export const POST = handleWebhook({\n * secret: process.env.TORQUE_WEBHOOK_SECRET,\n * onOrderCompleted: async (event) => {\n * // Fulfill order\n * await fulfillOrder(event.orderId!)\n * }\n * })\n * ```\n */\nexport function handleWebhook(options: WebhookHandlerOptions = {}) {\n return async (request: NextRequest) => {\n try {\n const rawBody = await request.text()\n let event: WebhookEvent\n try {\n event = JSON.parse(rawBody) as WebhookEvent\n } catch {\n return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 })\n }\n\n // Verify HMAC-SHA256 of raw body (signed webhook pattern)\n if (options.secret) {\n const signature = request.headers.get('x-torque-signature')\n if (!verifyTorqueWebhookSignature(rawBody, signature, options.secret)) {\n return NextResponse.json(\n { error: 'Invalid signature' },\n { status: 401 }\n )\n }\n }\n\n // Route to appropriate handler\n switch (event.type) {\n case 'order.created':\n await options.onOrderCreated?.(event)\n break\n case 'order.completed':\n await options.onOrderCompleted?.(event)\n break\n case 'order.failed':\n await options.onOrderFailed?.(event)\n break\n case 'subscription.created':\n await options.onSubscriptionCreated?.(event)\n break\n case 'subscription.cancelled':\n await options.onSubscriptionCancelled?.(event)\n break\n default:\n console.warn('Unknown webhook event type:', event.type)\n }\n\n return NextResponse.json({ received: true })\n } catch (error) {\n console.error('Webhook handler error:', error)\n return NextResponse.json(\n { error: 'Webhook processing failed' },\n { status: 500 }\n )\n }\n }\n}\n\n/**\n * Verify `X-Torque-Signature` (or raw hex) against HMAC-SHA256 of the **raw** webhook body.\n * Accepts `hex`, `sha256=<hex>`, or `v1=<hex>` prefix forms.\n */\nexport function verifyTorqueWebhookSignature(\n rawBody: string,\n signatureHeader: string | null,\n secret: string\n): boolean {\n if (!signatureHeader || !secret) return false\n const expectedHex = createHmac('sha256', secret).update(rawBody, 'utf8').digest('hex')\n const normalized = signatureHeader.trim().replace(/^(sha256|v1)=/i, '')\n try {\n const a = Buffer.from(normalized, 'hex')\n const b = Buffer.from(expectedHex, 'hex')\n if (a.length !== b.length) return false\n return timingSafeEqual(a, b)\n } catch {\n return false\n }\n}\n\n// ============================================================================\n// Order Status Helper\n// ============================================================================\n\n/**\n * Get order status on the server\n * \n * @example\n * ```ts\n * // app/api/orders/[orderId]/route.ts\n * import { getOrderStatus } from 'torque-checkout/nextjs'\n * \n * export async function GET(request: Request, { params }: { params: { orderId: string } }) {\n * const status = await getOrderStatus(params.orderId)\n * return Response.json(status)\n * }\n * ```\n */\nexport async function getOrderStatus(\n orderId: string,\n config?: TorqueConfig\n): Promise<OrderStatus> {\n const torque = config\n ? createTorqueCheckout(config)\n : createTorqueCheckoutFromEnv()\n\n return torque.getOrderStatus(orderId)\n}\n\n"],"names":[],"mappings":";;;;AAAA;;;;;AAKG;AAgBH;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AACI,eAAe,mBAAmB,CACvC,IAAc,EACd,MAAqB,EAAA;IAErB,MAAM,MAAM,GAAG;AACb,UAAE,oBAAoB,CAAC,MAAM;UAC3B,2BAA2B,EAAE;AAEjC,IAAA,OAAO,MAAM,CAAC,uBAAuB,CAAC,IAAI,CAAC;AAC7C;AAYA;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,qBAAqB,CAAC,OAAA,GAAqC,EAAE,EAAA;AAC3E,IAAA,OAAO,OAAO,OAAoB,KAAI;AACpC,QAAA,IAAI;AACF,YAAA,MAAM,IAAI,GAAa,MAAM,OAAO,CAAC,IAAI,EAAE;AAE3C,YAAA,MAAM,MAAM,GAAG,OAAO,CAAC;AACrB,kBAAE,oBAAoB,CAAC,OAAO,CAAC,MAAM;kBACnC,2BAA2B,EAAE;YAEjC,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,IAAI,CAAC;YAE9D,MAAM,OAAO,CAAC,SAAS,GAAG,WA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AAC;AACH;AAEA;;;AAGG;SACa,4BAA4B,CAC1C,OAAe,EACf,eAA8B,EAC9B,MAAc,EAAA;AAEd,IAAA,IAAI,CAAC,eAAe,IAAI,CAAC,MAAM;AAAE,QAAA,OAAO,KAAK;IAC7C,MAAM,WAAW,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;AACtF,IAAA,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;AACvE,IAAA,IAAI;QACF,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC;QACxC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC;AACzC,QAAA,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;AAAE,YAAA,OAAO,KAAK;AACvC,QAAA,OAAO,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9B;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,KAAK;IACd;AACF;AAEA;AACA;AACA;AAEA;;;;;;;;;;;;;AAaG;AACI,eAAe,cAAc,CAClC,OAAe,EACf,MAAqB,EAAA;IAErB,MAAM,MAAM,GAAG;AACb,UAAE,oBAAoB,CAAC,MAAM;UAC3B,2BAA2B,EAAE;AAEjC,IAAA,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC;AACvC;;;;"}
|
package/dist/nextjs.js
CHANGED
|
@@ -46,6 +46,7 @@ async function generateCheckoutUrl(cart, config) {
|
|
|
46
46
|
* // app/api/checkout-session/route.ts (path is your choice)
|
|
47
47
|
* import { handleCheckoutRequest } from 'torque-checkout/nextjs'
|
|
48
48
|
*
|
|
49
|
+
* // Returns the POST handler: JSON cart body → Torque (env credentials) → { success, checkoutUrl } or error JSON
|
|
49
50
|
* export const POST = handleCheckoutRequest({
|
|
50
51
|
* onSuccess: async (url, cart) => {
|
|
51
52
|
* // Log checkout generation
|
|
@@ -110,7 +111,7 @@ function handleWebhook(options = {}) {
|
|
|
110
111
|
catch {
|
|
111
112
|
return server.NextResponse.json({ error: 'Invalid JSON' }, { status: 400 });
|
|
112
113
|
}
|
|
113
|
-
// Verify HMAC-SHA256 of raw body (
|
|
114
|
+
// Verify HMAC-SHA256 of raw body (signed webhook pattern)
|
|
114
115
|
if (options.secret) {
|
|
115
116
|
const signature = request.headers.get('x-torque-signature');
|
|
116
117
|
if (!verifyTorqueWebhookSignature(rawBody, signature, options.secret)) {
|
|
@@ -147,7 +148,7 @@ function handleWebhook(options = {}) {
|
|
|
147
148
|
}
|
|
148
149
|
/**
|
|
149
150
|
* Verify `X-Torque-Signature` (or raw hex) against HMAC-SHA256 of the **raw** webhook body.
|
|
150
|
-
* Accepts `hex`, `sha256=<hex>`, or `v1=<hex>`
|
|
151
|
+
* Accepts `hex`, `sha256=<hex>`, or `v1=<hex>` prefix forms.
|
|
151
152
|
*/
|
|
152
153
|
function verifyTorqueWebhookSignature(rawBody, signatureHeader, secret) {
|
|
153
154
|
if (!signatureHeader || !secret)
|
package/dist/nextjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjs.js","sources":["../src/nextjs.ts"],"sourcesContent":["/**\n * Next.js Server-Side Utilities\n * Server-side helpers for Next.js App Router and Pages Router\n * \n * @requires next >= 13.0.0\n */\n\nimport { createHmac, timingSafeEqual } from 'crypto'\n// Type-only imports for better compatibility\nimport type { NextRequest } from 'next/server'\nimport { NextResponse } from 'next/server'\nimport {\n TorqueCheckout,\n createTorqueCheckout,\n createTorqueCheckoutFromEnv,\n type TorqueConfig,\n type CartData,\n type OrderStatus,\n type TorqueCheckoutError\n} from './index'\n\n// ============================================================================\n// Server-Side Checkout Helper\n// ============================================================================\n\n/**\n * Generate checkout URL on the server\n * Use this in Next.js API routes or Server Components\n * \n * @example\n * ```ts\n * // app/api/checkout-session/route.ts (path is your choice)\n * import { generateCheckoutUrl } from 'torque-checkout/nextjs'\n * \n * export async function POST(request: Request) {\n * const cart = await request.json()\n * const url = await generateCheckoutUrl(cart, {\n * businessId: process.env.TORQUE_BUSINESS_ID!,\n * apiKey: process.env.TORQUE_API_KEY!\n * })\n * return Response.json({ checkoutUrl: url })\n * }\n * ```\n */\nexport async function generateCheckoutUrl(\n cart: CartData,\n config?: TorqueConfig\n): Promise<string> {\n const torque = config \n ? createTorqueCheckout(config)\n : createTorqueCheckoutFromEnv()\n\n return torque.generateCartCheckoutUrl(cart)\n}\n\n// ============================================================================\n// API Route Handler Helpers\n// ============================================================================\n\nexport interface CheckoutApiHandlerOptions {\n config?: TorqueConfig\n onSuccess?: (checkoutUrl: string, cart: CartData) => Promise<void> | void\n onError?: (error: TorqueCheckoutError, cart: CartData) => Promise<void> | void\n}\n\n/**\n * Next.js API route handler for generating checkout URLs\n * \n * @example\n * ```ts\n * // app/api/checkout-session/route.ts (path is your choice)\n * import { handleCheckoutRequest } from 'torque-checkout/nextjs'\n * \n * export const POST = handleCheckoutRequest({\n * onSuccess: async (url, cart) => {\n * // Log checkout generation\n * console.log('Checkout generated:', url)\n * }\n * })\n * ```\n */\nexport function handleCheckoutRequest(options: CheckoutApiHandlerOptions = {}) {\n return async (request: NextRequest) => {\n try {\n const cart: CartData = await request.json()\n\n const torque = options.config\n ? createTorqueCheckout(options.config)\n : createTorqueCheckoutFromEnv()\n\n const checkoutUrl = await torque.generateCartCheckoutUrl(cart)\n\n await options.onSuccess?.(checkoutUrl, cart)\n\n return NextResponse.json({\n success: true,\n checkoutUrl,\n expiresAt: new Date(Date.now() + (cart.options?.expiresIn || 24 * 60 * 60 * 1000)).toISOString()\n })\n } catch (error) {\n const torqueError = error instanceof Error && 'code' in error\n ? error as TorqueCheckoutError\n : new Error(error instanceof Error ? error.message : 'Unknown error') as TorqueCheckoutError\n\n await options.onError?.(torqueError, {} as CartData)\n\n return NextResponse.json(\n {\n success: false,\n error: torqueError.message,\n code: torqueError.code || 'UNKNOWN_ERROR'\n },\n { status: torqueError.statusCode || 500 }\n )\n }\n }\n}\n\n// ============================================================================\n// Webhook Handler\n// ============================================================================\n\nexport interface WebhookEvent {\n type: 'order.created' | 'order.completed' | 'order.failed' | 'subscription.created' | 'subscription.cancelled'\n orderId?: string\n subscriptionId?: string\n data: any\n timestamp: number\n}\n\nexport interface WebhookHandlerOptions {\n secret?: string\n onOrderCreated?: (event: WebhookEvent) => Promise<void> | void\n onOrderCompleted?: (event: WebhookEvent) => Promise<void> | void\n onOrderFailed?: (event: WebhookEvent) => Promise<void> | void\n onSubscriptionCreated?: (event: WebhookEvent) => Promise<void> | void\n onSubscriptionCancelled?: (event: WebhookEvent) => Promise<void> | void\n}\n\n/**\n * Next.js API route handler for webhook events\n * \n * @example\n * ```ts\n * // app/api/webhooks/torque/route.ts\n * import { handleWebhook } from 'torque-checkout/nextjs'\n * \n * export const POST = handleWebhook({\n * secret: process.env.TORQUE_WEBHOOK_SECRET,\n * onOrderCompleted: async (event) => {\n * // Fulfill order\n * await fulfillOrder(event.orderId!)\n * }\n * })\n * ```\n */\nexport function handleWebhook(options: WebhookHandlerOptions = {}) {\n return async (request: NextRequest) => {\n try {\n const rawBody = await request.text()\n let event: WebhookEvent\n try {\n event = JSON.parse(rawBody) as WebhookEvent\n } catch {\n return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 })\n }\n\n // Verify HMAC-SHA256 of raw body (same pattern as Suby-style signed webhooks)\n if (options.secret) {\n const signature = request.headers.get('x-torque-signature')\n if (!verifyTorqueWebhookSignature(rawBody, signature, options.secret)) {\n return NextResponse.json(\n { error: 'Invalid signature' },\n { status: 401 }\n )\n }\n }\n\n // Route to appropriate handler\n switch (event.type) {\n case 'order.created':\n await options.onOrderCreated?.(event)\n break\n case 'order.completed':\n await options.onOrderCompleted?.(event)\n break\n case 'order.failed':\n await options.onOrderFailed?.(event)\n break\n case 'subscription.created':\n await options.onSubscriptionCreated?.(event)\n break\n case 'subscription.cancelled':\n await options.onSubscriptionCancelled?.(event)\n break\n default:\n console.warn('Unknown webhook event type:', event.type)\n }\n\n return NextResponse.json({ received: true })\n } catch (error) {\n console.error('Webhook handler error:', error)\n return NextResponse.json(\n { error: 'Webhook processing failed' },\n { status: 500 }\n )\n }\n }\n}\n\n/**\n * Verify `X-Torque-Signature` (or raw hex) against HMAC-SHA256 of the **raw** webhook body.\n * Accepts `hex`, `sha256=<hex>`, or `v1=<hex>` (Suby-style prefix).\n */\nexport function verifyTorqueWebhookSignature(\n rawBody: string,\n signatureHeader: string | null,\n secret: string\n): boolean {\n if (!signatureHeader || !secret) return false\n const expectedHex = createHmac('sha256', secret).update(rawBody, 'utf8').digest('hex')\n const normalized = signatureHeader.trim().replace(/^(sha256|v1)=/i, '')\n try {\n const a = Buffer.from(normalized, 'hex')\n const b = Buffer.from(expectedHex, 'hex')\n if (a.length !== b.length) return false\n return timingSafeEqual(a, b)\n } catch {\n return false\n }\n}\n\n// ============================================================================\n// Order Status Helper\n// ============================================================================\n\n/**\n * Get order status on the server\n * \n * @example\n * ```ts\n * // app/api/orders/[orderId]/route.ts\n * import { getOrderStatus } from 'torque-checkout/nextjs'\n * \n * export async function GET(request: Request, { params }: { params: { orderId: string } }) {\n * const status = await getOrderStatus(params.orderId)\n * return Response.json(status)\n * }\n * ```\n */\nexport async function getOrderStatus(\n orderId: string,\n config?: TorqueConfig\n): Promise<OrderStatus> {\n const torque = config\n ? createTorqueCheckout(config)\n : createTorqueCheckoutFromEnv()\n\n return torque.getOrderStatus(orderId)\n}\n\n"],"names":["createTorqueCheckout","createTorqueCheckoutFromEnv","NextResponse","createHmac","timingSafeEqual"],"mappings":";;;;;;AAAA;;;;;AAKG;AAgBH;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AACI,eAAe,mBAAmB,CACvC,IAAc,EACd,MAAqB,EAAA;IAErB,MAAM,MAAM,GAAG;AACb,UAAE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;IAC9B;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,KAAK;IACd;AACF;AAEA;AACA;AACA;AAEA;;;;;;;;;;;;;AAaG;AACI,eAAe,cAAc,CAClC,OAAe,EACf,MAAqB,EAAA;IAErB,MAAM,MAAM,GAAG;AACb,UAAEJ,0BAAoB,CAAC,MAAM;UAC3BC,iCAA2B,EAAE;AAEjC,IAAA,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC;AACvC;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"nextjs.js","sources":["../src/nextjs.ts"],"sourcesContent":["/**\n * Next.js Server-Side Utilities\n * Server-side helpers for Next.js App Router and Pages Router\n * \n * @requires next >= 13.0.0\n */\n\nimport { createHmac, timingSafeEqual } from 'crypto'\n// Type-only imports for better compatibility\nimport type { NextRequest } from 'next/server'\nimport { NextResponse } from 'next/server'\nimport {\n TorqueCheckout,\n createTorqueCheckout,\n createTorqueCheckoutFromEnv,\n type TorqueConfig,\n type CartData,\n type OrderStatus,\n type TorqueCheckoutError\n} from './index'\n\n// ============================================================================\n// Server-Side Checkout Helper\n// ============================================================================\n\n/**\n * Generate checkout URL on the server\n * Use this in Next.js API routes or Server Components\n * \n * @example\n * ```ts\n * // app/api/checkout-session/route.ts (path is your choice)\n * import { generateCheckoutUrl } from 'torque-checkout/nextjs'\n * \n * export async function POST(request: Request) {\n * const cart = await request.json()\n * const url = await generateCheckoutUrl(cart, {\n * businessId: process.env.TORQUE_BUSINESS_ID!,\n * apiKey: process.env.TORQUE_API_KEY!\n * })\n * return Response.json({ checkoutUrl: url })\n * }\n * ```\n */\nexport async function generateCheckoutUrl(\n cart: CartData,\n config?: TorqueConfig\n): Promise<string> {\n const torque = config \n ? createTorqueCheckout(config)\n : createTorqueCheckoutFromEnv()\n\n return torque.generateCartCheckoutUrl(cart)\n}\n\n// ============================================================================\n// API Route Handler Helpers\n// ============================================================================\n\nexport interface CheckoutApiHandlerOptions {\n config?: TorqueConfig\n onSuccess?: (checkoutUrl: string, cart: CartData) => Promise<void> | void\n onError?: (error: TorqueCheckoutError, cart: CartData) => Promise<void> | void\n}\n\n/**\n * Next.js API route handler for generating checkout URLs\n * \n * @example\n * ```ts\n * // app/api/checkout-session/route.ts (path is your choice)\n * import { handleCheckoutRequest } from 'torque-checkout/nextjs'\n *\n * // Returns the POST handler: JSON cart body → Torque (env credentials) → { success, checkoutUrl } or error JSON\n * export const POST = handleCheckoutRequest({\n * onSuccess: async (url, cart) => {\n * // Log checkout generation\n * console.log('Checkout generated:', url)\n * }\n * })\n * ```\n */\nexport function handleCheckoutRequest(options: CheckoutApiHandlerOptions = {}) {\n return async (request: NextRequest) => {\n try {\n const cart: CartData = await request.json()\n\n const torque = options.config\n ? createTorqueCheckout(options.config)\n : createTorqueCheckoutFromEnv()\n\n const checkoutUrl = await torque.generateCartCheckoutUrl(cart)\n\n await options.onSuccess?.(checkoutUrl, cart)\n\n return NextResponse.json({\n success: true,\n checkoutUrl,\n expiresAt: new Date(Date.now() + (cart.options?.expiresIn || 24 * 60 * 60 * 1000)).toISOString()\n })\n } catch (error) {\n const torqueError = error instanceof Error && 'code' in error\n ? error as TorqueCheckoutError\n : new Error(error instanceof Error ? error.message : 'Unknown error') as TorqueCheckoutError\n\n await options.onError?.(torqueError, {} as CartData)\n\n return NextResponse.json(\n {\n success: false,\n error: torqueError.message,\n code: torqueError.code || 'UNKNOWN_ERROR'\n },\n { status: torqueError.statusCode || 500 }\n )\n }\n }\n}\n\n// ============================================================================\n// Webhook Handler\n// ============================================================================\n\nexport interface WebhookEvent {\n type: 'order.created' | 'order.completed' | 'order.failed' | 'subscription.created' | 'subscription.cancelled'\n orderId?: string\n subscriptionId?: string\n data: any\n timestamp: number\n}\n\nexport interface WebhookHandlerOptions {\n secret?: string\n onOrderCreated?: (event: WebhookEvent) => Promise<void> | void\n onOrderCompleted?: (event: WebhookEvent) => Promise<void> | void\n onOrderFailed?: (event: WebhookEvent) => Promise<void> | void\n onSubscriptionCreated?: (event: WebhookEvent) => Promise<void> | void\n onSubscriptionCancelled?: (event: WebhookEvent) => Promise<void> | void\n}\n\n/**\n * Next.js API route handler for webhook events\n * \n * @example\n * ```ts\n * // app/api/webhooks/torque/route.ts\n * import { handleWebhook } from 'torque-checkout/nextjs'\n * \n * export const POST = handleWebhook({\n * secret: process.env.TORQUE_WEBHOOK_SECRET,\n * onOrderCompleted: async (event) => {\n * // Fulfill order\n * await fulfillOrder(event.orderId!)\n * }\n * })\n * ```\n */\nexport function handleWebhook(options: WebhookHandlerOptions = {}) {\n return async (request: NextRequest) => {\n try {\n const rawBody = await request.text()\n let event: WebhookEvent\n try {\n event = JSON.parse(rawBody) as WebhookEvent\n } catch {\n return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 })\n }\n\n // Verify HMAC-SHA256 of raw body (signed webhook pattern)\n if (options.secret) {\n const signature = request.headers.get('x-torque-signature')\n if (!verifyTorqueWebhookSignature(rawBody, signature, options.secret)) {\n return NextResponse.json(\n { error: 'Invalid signature' },\n { status: 401 }\n )\n }\n }\n\n // Route to appropriate handler\n switch (event.type) {\n case 'order.created':\n await options.onOrderCreated?.(event)\n break\n case 'order.completed':\n await options.onOrderCompleted?.(event)\n break\n case 'order.failed':\n await options.onOrderFailed?.(event)\n break\n case 'subscription.created':\n await options.onSubscriptionCreated?.(event)\n break\n case 'subscription.cancelled':\n await options.onSubscriptionCancelled?.(event)\n break\n default:\n console.warn('Unknown webhook event type:', event.type)\n }\n\n return NextResponse.json({ received: true })\n } catch (error) {\n console.error('Webhook handler error:', error)\n return NextResponse.json(\n { error: 'Webhook processing failed' },\n { status: 500 }\n )\n }\n }\n}\n\n/**\n * Verify `X-Torque-Signature` (or raw hex) against HMAC-SHA256 of the **raw** webhook body.\n * Accepts `hex`, `sha256=<hex>`, or `v1=<hex>` prefix forms.\n */\nexport function verifyTorqueWebhookSignature(\n rawBody: string,\n signatureHeader: string | null,\n secret: string\n): boolean {\n if (!signatureHeader || !secret) return false\n const expectedHex = createHmac('sha256', secret).update(rawBody, 'utf8').digest('hex')\n const normalized = signatureHeader.trim().replace(/^(sha256|v1)=/i, '')\n try {\n const a = Buffer.from(normalized, 'hex')\n const b = Buffer.from(expectedHex, 'hex')\n if (a.length !== b.length) return false\n return timingSafeEqual(a, b)\n } catch {\n return false\n }\n}\n\n// ============================================================================\n// Order Status Helper\n// ============================================================================\n\n/**\n * Get order status on the server\n * \n * @example\n * ```ts\n * // app/api/orders/[orderId]/route.ts\n * import { getOrderStatus } from 'torque-checkout/nextjs'\n * \n * export async function GET(request: Request, { params }: { params: { orderId: string } }) {\n * const status = await getOrderStatus(params.orderId)\n * return Response.json(status)\n * }\n * ```\n */\nexport async function getOrderStatus(\n orderId: string,\n config?: TorqueConfig\n): Promise<OrderStatus> {\n const torque = config\n ? createTorqueCheckout(config)\n : createTorqueCheckoutFromEnv()\n\n return torque.getOrderStatus(orderId)\n}\n\n"],"names":["createTorqueCheckout","createTorqueCheckoutFromEnv","NextResponse","createHmac","timingSafeEqual"],"mappings":";;;;;;AAAA;;;;;AAKG;AAgBH;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;AAkBG;AACI,eAAe,mBAAmB,CACvC,IAAc,EACd,MAAqB,EAAA;IAErB,MAAM,MAAM,GAAG;AACb,UAAEA,0BAAoB,CAAC,MAAM;UAC3BC,iCAA2B,EAAE;AAEjC,IAAA,OAAO,MAAM,CAAC,uBAAuB,CAAC,IAAI,CAAC;AAC7C;AAYA;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,qBAAqB,CAAC,OAAA,GAAqC,EAAE,EAAA;AAC3E,IAAA,OAAO,OAAO,OAAoB,KAAI;AACpC,QAAA,IAAI;AACF,YAAA,MAAM,IAAI,GAAa,MAAM,OAAO,CAAC,IAAI,EAAE;AAE3C,YAAA,MAAM,MAAM,GAAG,OAAO,CAAC;AACrB,kBAAED,0BAAoB,CAAC,OAAO,CAAC,MAAM;kBACnCC,iCAA2B,EAAE;YAEjC,MAAM,WAAW,GAAG,MAAM,M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que checkout SDK
|
|
3
|
+
"version": "3.2.1",
|
|
4
|
+
"description": "Official Torque checkout SDK — ≤6-line checkout() for Next.js and Node",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|