@usethrottle/checkout-sdk 1.6.1 → 2.0.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 +38 -0
- package/README.md +1 -1
- package/dist/server.cjs +19 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +38 -5
- package/dist/server.d.ts +38 -5
- package/dist/server.js +18 -1
- package/dist/server.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @usethrottle/checkout-sdk
|
|
2
2
|
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Pass the failed response's headers into `ThrottleError` (and its per-SDK
|
|
8
|
+
subclasses) when constructing the error from a `fetch` `Response`, so
|
|
9
|
+
`error.requestId` now falls back to the `x-request-id` response header for
|
|
10
|
+
hand-built error bodies (401/403/500) that carry no `meta.requestId`. Bumps
|
|
11
|
+
`@usethrottle/errors` to `^1.1.0`, which added this fallback. `cli` and `mcp`
|
|
12
|
+
bundle `@usethrottle/errors` at build time and pick up the fix in their
|
|
13
|
+
published bundle.
|
|
14
|
+
|
|
15
|
+
## 2.0.0
|
|
16
|
+
|
|
17
|
+
### Major Changes
|
|
18
|
+
|
|
19
|
+
- 5221d34: `completeSession()` now returns `CompleteCheckoutSessionOutcome` — either the
|
|
20
|
+
existing `CompleteCheckoutSessionResult` or a new
|
|
21
|
+
`CompleteCheckoutSessionRequiresAction` when the card needs a 3-D Secure
|
|
22
|
+
challenge the buyer must answer. Previously that 200 response (which carries no
|
|
23
|
+
`orderId`, because nothing has been completed) threw a local parse error.
|
|
24
|
+
Narrow with the exported `isRequiresAction()` type guard before reading
|
|
25
|
+
`orderId`. Only the server-authorized card path
|
|
26
|
+
(`processorCheckoutSessionId` with no `processorTransactionId`) can produce it.
|
|
27
|
+
- 4a70dd0: Custom billing cadence and installment plans on the checkout recurring intent: `intervalUnit` + `intervalCount` (any cadence from 1 hour to 1 year) and `totalPayments` (2–60). `interval` is now optional and accepts `custom`. The cart line `recurring` type gains the optional cadence fields Throttle writes on the plan line. The CLI's `subscriptions change-plan` takes `--interval-unit` and `--interval-count`.
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- 5ec87ce: New `checkout.getSession(sessionId)` on the server client: reads a checkout session back (`GET /api/v1/checkout/sessions/{id}`) with its current `status`, so an integration can tell whether a session is still open before resuming or cancelling it. Exports `CheckoutSessionDetails` and `CheckoutSessionStatus`.
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- c3f4806: Completing a checkout session with `paymentMethod: 'card'` is now rejected by the API with 422 `payment_method_not_supported` (it previously returned 200 and left an unpaid order in `processing`). Card payments complete with `'embedded'` and the embed's `processorTransactionId`. Types are unchanged; the `paymentMethod` docs now say so.
|
|
36
|
+
- Updated dependencies [5221d34]
|
|
37
|
+
- Updated dependencies [5221d34]
|
|
38
|
+
- Updated dependencies [4a70dd0]
|
|
39
|
+
- @usethrottle/checkout-react@2.0.0
|
|
40
|
+
|
|
3
41
|
## 1.5.0
|
|
4
42
|
|
|
5
43
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ const nextCursor = ordersPage.pagination?.cursor;
|
|
|
84
84
|
| Method | Endpoint | Description |
|
|
85
85
|
| ----------------------------- | --------------------------------------------- | --------------------------------------------------------- |
|
|
86
86
|
| `createSession(input)` | `POST /api/v1/checkout/sessions` | Creates a cart-backed hosted/embed checkout session. |
|
|
87
|
-
| `completeSession(id, input)` | `POST /api/v1/checkout/sessions/:id/complete` | Completes a checkout session from server-side proxy mode. |
|
|
87
|
+
| `completeSession(id, input)` | `POST /api/v1/checkout/sessions/:id/complete` | Completes a checkout session from server-side proxy mode. May return `{status: 'requires_action'}` when the card needs a 3-D Secure challenge — narrow with `isRequiresAction()` before reading `orderId`. |
|
|
88
88
|
| `getSession(id)` | `GET /api/v1/checkout/sessions/:id` | Reads a session back, including its current `status`. |
|
|
89
89
|
| `cancelSession(id)` | `DELETE /api/v1/checkout/sessions/:id` | Cancels an in-flight session. Idempotent. |
|
|
90
90
|
| `createEmbedToken(input)` | `POST /api/v1/checkout-sessions/embed-token` | Mints an embed token for proxy-mode card capture. |
|
package/dist/server.cjs
CHANGED
|
@@ -26,11 +26,15 @@ __export(server_exports, {
|
|
|
26
26
|
buildCheckoutEmbedUrl: () => buildCheckoutEmbedUrl,
|
|
27
27
|
buildCheckoutHostedUrl: () => buildCheckoutHostedUrl,
|
|
28
28
|
createCheckoutClient: () => createCheckoutClient,
|
|
29
|
+
isRequiresAction: () => isRequiresAction,
|
|
29
30
|
isThrottleError: () => import_errors2.isThrottleError
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(server_exports);
|
|
32
33
|
var import_errors = require("@usethrottle/errors");
|
|
33
34
|
var import_errors2 = require("@usethrottle/errors");
|
|
35
|
+
function isRequiresAction(outcome) {
|
|
36
|
+
return outcome.status === "requires_action";
|
|
37
|
+
}
|
|
34
38
|
var ThrottleCheckoutError = class extends import_errors.ThrottleError {
|
|
35
39
|
constructor(args) {
|
|
36
40
|
super(args);
|
|
@@ -75,7 +79,8 @@ var CheckoutClient = class {
|
|
|
75
79
|
message: json.error?.message ?? `HTTP ${res.status}`,
|
|
76
80
|
statusCode: res.status,
|
|
77
81
|
details: json.error?.details,
|
|
78
|
-
body: json
|
|
82
|
+
body: json,
|
|
83
|
+
responseHeaders: res.headers
|
|
79
84
|
});
|
|
80
85
|
}
|
|
81
86
|
return json;
|
|
@@ -87,6 +92,11 @@ var CheckoutClient = class {
|
|
|
87
92
|
const data = await this.request("POST", "/api/v1/checkout/sessions", input);
|
|
88
93
|
return normalizeCheckoutSession(data);
|
|
89
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns either a completion or `{status: 'requires_action'}` when the card
|
|
97
|
+
* needs a 3-D Secure challenge — narrow with `isRequiresAction()` before
|
|
98
|
+
* reading `orderId`.
|
|
99
|
+
*/
|
|
90
100
|
async completeSession(sessionId, input) {
|
|
91
101
|
const data = await this.request(
|
|
92
102
|
"POST",
|
|
@@ -216,6 +226,13 @@ function normalizeCheckoutSession(raw) {
|
|
|
216
226
|
};
|
|
217
227
|
}
|
|
218
228
|
function normalizeCompleteResult(raw) {
|
|
229
|
+
if (raw?.status === "requires_action") {
|
|
230
|
+
return {
|
|
231
|
+
...withoutSnakeKeys(raw),
|
|
232
|
+
status: "requires_action",
|
|
233
|
+
paymentStatus: optionalString(raw?.paymentStatus) ?? void 0
|
|
234
|
+
};
|
|
235
|
+
}
|
|
219
236
|
const orderId = raw?.orderId ?? raw?.id;
|
|
220
237
|
return {
|
|
221
238
|
...withoutSnakeKeys(raw),
|
|
@@ -311,6 +328,7 @@ function objectOrUndefined(value) {
|
|
|
311
328
|
buildCheckoutEmbedUrl,
|
|
312
329
|
buildCheckoutHostedUrl,
|
|
313
330
|
createCheckoutClient,
|
|
331
|
+
isRequiresAction,
|
|
314
332
|
isThrottleError
|
|
315
333
|
});
|
|
316
334
|
//# sourceMappingURL=server.cjs.map
|
package/dist/server.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { ThrottleError } from '@usethrottle/errors';\n\n/**\n * `'embedded'` completes a card payment taken by the payment embed; `'net30'`\n * issues an invoice on terms. `'card'` names the card category in\n * `allowedMethods` — `completeSession` rejects it with 422\n * `payment_method_not_supported`. Use `'embedded'`.\n */\nexport type PaymentMethod = 'net30' | 'card' | 'embedded';\nexport type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly';\nexport type CheckoutEmbedMode = 'checkout-full' | 'payment-only';\nexport type CheckoutEmbedRoute = 'c' | 's';\n\nexport interface CheckoutClientOptions {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof globalThis.fetch;\n timeoutMs?: number;\n}\n\nexport interface CheckoutAddress {\n firstName: string;\n lastName: string;\n company?: string;\n addressLine1: string;\n addressLine2?: string;\n city: string;\n stateProvince: string;\n postalCode: string;\n countryCode: string;\n phone?: string;\n}\n\nexport interface CheckoutCustomerAddressInput {\n firstName?: string;\n lastName?: string;\n phone?: string;\n addressLine1?: string;\n addressLine2?: string;\n city?: string;\n state?: string;\n postalCode?: string;\n country?: string;\n}\n\nexport interface CheckoutCustomerInput {\n customerId?: string;\n externalCustomerId?: string;\n email?: string;\n firstName?: string;\n lastName?: string;\n phone?: string;\n shippingAddress?: CheckoutCustomerAddressInput;\n billingAddress?: CheckoutCustomerAddressInput;\n metadata?: Record<string, unknown>;\n}\n\nexport interface RecurringIntentInput {\n plan: string;\n interval: SubscriptionInterval;\n amount?: number;\n trialDays?: number;\n planName?: string;\n create?: 'auto' | 'manual';\n}\n\nexport interface CheckoutCollectInput {\n shippingAddress?: boolean;\n billingAddress?: boolean;\n}\n\nexport interface CheckoutPaymentTermsInput {\n netN?: number | null;\n}\n\nexport interface CreateCheckoutSessionInput {\n applicationId: string;\n cartId?: string;\n externalCartId?: string;\n customerEmail?: string;\n customer?: CheckoutCustomerInput;\n returnUrl: string;\n cancelUrl: string;\n allowedMethods?: string[];\n paymentTerms?: CheckoutPaymentTermsInput;\n recurring?: RecurringIntentInput;\n collect?: CheckoutCollectInput;\n metadata?: Record<string, unknown>;\n discountCode?: string;\n}\n\nexport interface CheckoutSession {\n sessionId: string;\n id?: string;\n checkoutUrl?: string;\n hostedUrl?: string;\n embedUrl?: string;\n embedToken?: string;\n expiresAt?: string;\n [key: string]: unknown;\n}\n\nexport type CheckoutSessionStatus =\n | 'open'\n | 'customer_set'\n | 'address_set'\n | 'processing'\n | 'completed'\n | 'expired'\n | 'cancelled';\n\n/** A session as read back by `getSession` — the create response plus its current state. */\nexport interface CheckoutSessionDetails extends CheckoutSession {\n status: CheckoutSessionStatus;\n cartId?: string | null;\n customerId?: string | null;\n customerEmail?: string | null;\n shippingAddress?: CheckoutAddress | null;\n billingAddress?: CheckoutAddress | null;\n returnUrl?: string;\n cancelUrl?: string;\n completedAt?: string | null;\n allowedMethods?: string[] | null;\n collectShipping?: boolean;\n collectBilling?: boolean;\n discountCode?: string | null;\n metadata?: Record<string, unknown>;\n}\n\nexport interface Net30Acceptance {\n termsHash: string;\n acceptedAt: string;\n companyName: string;\n billingEmail: string;\n}\n\nexport interface CompleteCheckoutSessionInput {\n email?: string;\n shippingAddress?: CheckoutAddress;\n billingAddress?: CheckoutAddress;\n billingSameAsShipping?: boolean;\n paymentMethod: PaymentMethod;\n netDays?: number;\n termsAccepted?: boolean;\n termsSnapshot?: string;\n invoiceNumber?: string;\n net30Acceptance?: Net30Acceptance;\n paymentToken?: string;\n processorCheckoutSessionId?: string;\n processorTransactionId?: string;\n}\n\nexport interface CompleteCheckoutSessionResult {\n orderId: string;\n orderNumber?: string;\n paymentId?: string;\n total?: number;\n currency?: string;\n status?: string;\n paymentStatus?: string;\n [key: string]: unknown;\n}\n\nexport interface CreateEmbedTokenInput {\n externalCartId?: string;\n amount: number;\n currency: string;\n country?: string;\n // NOTE: `allowedMethods` is intentionally NOT accepted here. A payment-only\n // Gr4vy embed cannot restrict payment methods (the Gr4vy widget renders the\n // methods configured on your Gr4vy connection). The server rejects it with\n // `allowed_methods_unsupported`. To restrict methods, configure the connection\n // or use the full hosted checkout, where allowedMethods filters the selection.\n}\n\nexport interface CreateEmbedTokenResult {\n embedToken: string;\n checkoutSessionId: string;\n amount: number;\n currency: string;\n hostedUrl?: string;\n embedUrl?: string;\n processorInstanceId?: string;\n merchantAccountId?: string;\n [key: string]: unknown;\n}\n\nexport interface CheckoutOrder {\n id: string;\n orderNumber?: string;\n status: string;\n paymentStatus: string | null;\n currency: string;\n subtotal: number;\n taxTotal: number;\n shippingTotal: number;\n total: number;\n metadata?: Record<string, unknown>;\n payments?: CheckoutPayment[];\n [key: string]: unknown;\n}\n\nexport interface ListOrdersOptions {\n customerId?: string;\n cursor?: string;\n limit?: number;\n status?: string;\n paymentStatus?: string;\n}\n\nexport interface PaginatedOrders {\n data: CheckoutOrder[];\n pagination?: {\n cursor: string | null;\n hasMore: boolean;\n };\n}\n\nexport interface CheckoutPayment {\n id: string;\n orderId?: string;\n processor?: string;\n processorTransactionId?: string | null;\n amount?: number;\n currency?: string;\n status?: string;\n method?: string;\n createdAt?: string;\n transactions?: CheckoutPaymentTransaction[];\n [key: string]: unknown;\n}\n\nexport interface CheckoutPaymentTransaction {\n id: string;\n paymentId?: string;\n type?: string;\n amount?: number;\n currency?: string;\n status?: string;\n createdAt?: string;\n [key: string]: unknown;\n}\n\nexport interface BuildCheckoutUrlOptions {\n checkoutOrigin?: string;\n sessionId: string;\n parentOrigin?: string;\n mode?: CheckoutEmbedMode;\n route?: CheckoutEmbedRoute;\n primary?: string;\n logo?: string;\n}\n\nexport interface ThrottleEnvelope<T> {\n data?: T;\n meta?: Record<string, unknown>;\n error?: {\n code?: string;\n message?: string;\n details?: unknown;\n };\n}\n\n/**\n * Thrown on a non-2xx response from the Throttle Checkout API.\n *\n * Extends the shared {@link ThrottleError} so a single\n * `catch (e) { if (e instanceof ThrottleError) … }` covers errors from every\n * Throttle SDK. `instanceof ThrottleCheckoutError` keeps working for existing\n * code.\n */\nexport class ThrottleCheckoutError extends ThrottleError {\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n body?: unknown;\n }) {\n super(args);\n this.name = 'ThrottleCheckoutError';\n }\n}\n\nexport { ThrottleError, isThrottleError } from '@usethrottle/errors';\n\nexport class CheckoutClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly timeoutMs: number;\n\n constructor(opts: CheckoutClientOptions) {\n if (!opts.apiKey) throw new Error('CheckoutClient: apiKey is required');\n const fetchImpl = opts.fetch ?? globalThis.fetch;\n if (!fetchImpl) throw new Error('CheckoutClient: fetch is required');\n this.apiKey = opts.apiKey;\n this.baseUrl = (opts.baseUrl ?? 'https://api.usethrottle.dev').replace(/\\/+$/, '');\n this.fetchImpl = fetchImpl;\n this.timeoutMs = opts.timeoutMs ?? 30_000;\n }\n\n async request<T = unknown>(method: string, path: string, body?: unknown): Promise<T> {\n const envelope = await this.requestEnvelope<T>(method, path, body);\n if (Object.prototype.hasOwnProperty.call(envelope, 'data')) {\n return envelope.data as T;\n }\n return envelope as T;\n }\n\n async requestEnvelope<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<ThrottleEnvelope<T>> {\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);\n\n try {\n const res = await this.fetchImpl(toAbsoluteUrl(this.baseUrl, path), {\n method,\n headers: {\n 'content-type': 'application/json',\n 'x-api-key': this.apiKey,\n },\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal: ctrl.signal,\n });\n\n if (res.status === 204) return { data: undefined as T };\n\n const json = (await res.json().catch(() => ({}))) as ThrottleEnvelope<T>;\n if (!res.ok) {\n throw new ThrottleCheckoutError({\n code: json.error?.code ?? 'unknown_error',\n message: json.error?.message ?? `HTTP ${res.status}`,\n statusCode: res.status,\n details: json.error?.details,\n body: json,\n });\n }\n return json;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async createSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout/sessions', input);\n return normalizeCheckoutSession(data);\n }\n\n async completeSession(\n sessionId: string,\n input: CompleteCheckoutSessionInput,\n ): Promise<CompleteCheckoutSessionResult> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}/complete`,\n input,\n );\n return normalizeCompleteResult(data);\n }\n\n /**\n * Read a checkout session's current state — `status` tells you whether the\n * buyer is still in it (`open`, `processing`) or it has settled (`completed`,\n * `cancelled`, `expired`). Use it to decide whether a session can be resumed\n * or cancelled instead of tracking that yourself.\n */\n async getSession(sessionId: string): Promise<CheckoutSessionDetails> {\n const data = await this.request<any>(\n 'GET',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}`,\n );\n return {\n ...normalizeCheckoutSession(data),\n status: requiredString(data?.status, 'checkoutSession.status') as CheckoutSessionStatus,\n };\n }\n\n /**\n * Cancel an in-flight checkout session (e.g. the buyer abandoned the embed).\n * Idempotent — cancelling an already-cancelled session is a no-op; a completed\n * session cannot be cancelled (the API returns 422 `already_completed`).\n */\n async cancelSession(sessionId: string): Promise<void> {\n await this.request<unknown>(\n 'DELETE',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}`,\n );\n }\n\n async createEmbedToken(input: CreateEmbedTokenInput): Promise<CreateEmbedTokenResult> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout-sessions/embed-token', input);\n return normalizeEmbedToken(data);\n }\n\n async getOrder(orderId: string): Promise<CheckoutOrder> {\n const data = await this.request<unknown>('GET', `/api/v1/orders/${encodeURIComponent(orderId)}`);\n return normalizeOrder(data);\n }\n\n async listOrders(options: ListOrdersOptions = {}): Promise<PaginatedOrders> {\n const params = new URLSearchParams();\n if (options.customerId) params.set('customerId', options.customerId);\n if (options.cursor) params.set('cursor', options.cursor);\n if (options.limit !== undefined) params.set('limit', String(options.limit));\n if (options.status) params.set('status', options.status);\n if (options.paymentStatus) params.set('paymentStatus', options.paymentStatus);\n\n const query = params.toString();\n const envelope = await this.requestEnvelope<unknown[]>(\n 'GET',\n `/api/v1/orders${query ? `?${query}` : ''}`,\n );\n return {\n data: (envelope.data ?? []).map(normalizeOrder),\n pagination: envelope.meta?.pagination as PaginatedOrders['pagination'],\n };\n }\n\n async listOrderPayments(orderId: string): Promise<CheckoutPayment[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/orders/${encodeURIComponent(orderId)}/payments`,\n );\n return (data ?? []).map(normalizePayment);\n }\n\n async listPaymentTransactions(paymentId: string): Promise<CheckoutPaymentTransaction[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/payments/${encodeURIComponent(paymentId)}/transactions`,\n );\n return (data ?? []).map(normalizeTransaction);\n }\n\n async getOrderWithPayments(orderId: string): Promise<CheckoutOrder> {\n const order = await this.getOrder(orderId);\n const payments = await this.listOrderPayments(orderId);\n return {\n ...order,\n payments: await Promise.all(\n payments.map(async (payment) => ({\n ...payment,\n transactions: payment.id ? await this.listPaymentTransactions(payment.id) : [],\n })),\n ),\n };\n }\n}\n\nexport function createCheckoutClient(opts: CheckoutClientOptions): CheckoutClient {\n return new CheckoutClient(opts);\n}\n\nexport function buildCheckoutHostedUrl(options: BuildCheckoutUrlOptions): string {\n const route = options.route ?? 's';\n const base = (options.checkoutOrigin ?? 'https://checkout.usethrottle.dev').replace(/\\/+$/, '');\n return `${base}/${route}/${encodeURIComponent(options.sessionId)}`;\n}\n\nexport function buildCheckoutEmbedUrl(options: BuildCheckoutUrlOptions): string {\n const baseUrl = buildCheckoutHostedUrl({\n checkoutOrigin: options.checkoutOrigin,\n sessionId: options.sessionId,\n route: options.route ?? 'c',\n });\n const params = new URLSearchParams({\n embed: '1',\n mode: options.mode ?? 'payment-only',\n ...(options.parentOrigin ? { parentOrigin: options.parentOrigin.replace(/\\/+$/, '') } : {}),\n });\n if (options.primary) params.set('primary', options.primary);\n if (options.logo) params.set('logo', options.logo);\n return `${baseUrl}?${params.toString()}`;\n}\n\nfunction toAbsoluteUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl}${path.startsWith('/') ? path : `/${path}`}`;\n}\n\nfunction normalizeCheckoutSession(raw: any): CheckoutSession {\n const sessionId = raw?.sessionId ?? raw?.id;\n return {\n ...withoutSnakeKeys(raw),\n id: optionalString(raw?.id) ?? undefined,\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl) ?? undefined,\n hostedUrl: optionalString(raw?.hostedUrl) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl) ?? undefined,\n embedToken: optionalString(raw?.embedToken) ?? undefined,\n expiresAt: optionalString(raw?.expiresAt) ?? undefined,\n };\n}\n\nfunction normalizeCompleteResult(raw: any): CompleteCheckoutSessionResult {\n const orderId = raw?.orderId ?? raw?.id;\n return {\n ...withoutSnakeKeys(raw),\n orderId: requiredString(orderId, 'checkoutComplete.orderId'),\n orderNumber: optionalString(raw?.orderNumber) ?? undefined,\n paymentId: optionalString(raw?.paymentId) ?? undefined,\n total: optionalNumber(raw?.total),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n paymentStatus: optionalString(raw?.paymentStatus) ?? undefined,\n };\n}\n\nfunction normalizeEmbedToken(raw: any): CreateEmbedTokenResult {\n return {\n ...withoutSnakeKeys(raw),\n embedToken: requiredString(raw?.embedToken, 'embedToken.embedToken'),\n checkoutSessionId: requiredString(raw?.checkoutSessionId, 'embedToken.checkoutSessionId'),\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n hostedUrl: optionalString(raw?.hostedUrl) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl) ?? undefined,\n processorInstanceId: optionalString(raw?.processorInstanceId) ?? undefined,\n merchantAccountId: optionalString(raw?.merchantAccountId) ?? undefined,\n };\n}\n\nfunction normalizeOrder(raw: any): CheckoutOrder {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'order.id'),\n orderNumber: optionalString(raw?.orderNumber) ?? undefined,\n status: optionalString(raw?.status) ?? 'processing',\n paymentStatus: optionalString(raw?.paymentStatus),\n currency: optionalString(raw?.currency) ?? 'USD',\n subtotal: Number(raw?.subtotal ?? 0),\n taxTotal: Number(raw?.taxTotal ?? 0),\n shippingTotal: Number(raw?.shippingTotal ?? 0),\n total: Number(raw?.total ?? 0),\n metadata: objectOrUndefined(raw?.metadata),\n payments: Array.isArray(raw?.payments) ? raw.payments.map(normalizePayment) : undefined,\n };\n}\n\nfunction normalizePayment(raw: any): CheckoutPayment {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'payment.id'),\n orderId: optionalString(raw?.orderId) ?? undefined,\n processor: optionalString(raw?.processor) ?? undefined,\n processorTransactionId:\n optionalString(raw?.processorTransactionId) ?? undefined,\n amount: optionalNumber(raw?.amount),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n method: optionalString(raw?.method) ?? undefined,\n createdAt: optionalString(raw?.createdAt) ?? undefined,\n transactions: Array.isArray(raw?.transactions)\n ? raw.transactions.map(normalizeTransaction)\n : undefined,\n };\n}\n\nfunction normalizeTransaction(raw: any): CheckoutPaymentTransaction {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'transaction.id'),\n paymentId: optionalString(raw?.paymentId) ?? undefined,\n type: optionalString(raw?.type) ?? undefined,\n amount: optionalNumber(raw?.amount),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n createdAt: optionalString(raw?.createdAt) ?? undefined,\n };\n}\n\nfunction withoutSnakeKeys(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return {};\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).filter(([key]) => !key.includes('_')),\n );\n}\n\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalString(value: unknown): string | null {\n return typeof value === 'string' && value.length > 0 ? value : null;\n}\n\nfunction optionalNumber(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n}\n\nfunction objectOrUndefined(value: unknown): Record<string, unknown> | undefined {\n return value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8B;AA4R9B,IA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AAI,eAAe,KAAK,IAAI,gBAAgB;AAAA,IAC5C,WAAW,eAAe,KAAK,SAAS,KAAK;AAAA,IAC7C,MAAM,eAAe,KAAK,IAAI,KAAK;AAAA,IACnC,QAAQ,eAAe,KAAK,MAAM;AAAA,IAClC,UAAU,eAAe,KAAK,QAAQ,KAAK;AAAA,IAC3C,QAAQ,eAAe,KAAK,MAAM,KAAK;AAAA,IACvC,WAAW,eAAe,KAAK,SAAS,KAAK;AAAA,EAC/C;AACF;AAEA,SAAS,iBAAiB,OAAyC;AACjE,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AACzE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,KAAgC,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,SAAS,GAAG,CAAC;AAAA,EACvF;AACF;AAEA,SAAS,eAAe,OAAgB,OAAuB;AAC7D,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,EAAG,QAAO;AAC1D,QAAM,IAAI,MAAM,sCAAsC,KAAK,EAAE;AAC/D;AAEA,SAAS,eAAe,OAA+B;AACrD,SAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AACjE;AAEA,SAAS,eAAe,OAAoC;AAC1D,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;AAEA,SAAS,kBAAkB,OAAqD;AAC9E,SAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAC5D,QACD;AACN;","names":["import_errors"]}
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { ThrottleError, type ThrottleErrorArgs } from '@usethrottle/errors';\n\n/**\n * `'embedded'` completes a card payment taken by the payment embed; `'net30'`\n * issues an invoice on terms. `'card'` names the card category in\n * `allowedMethods` — `completeSession` rejects it with 422\n * `payment_method_not_supported`. Use `'embedded'`.\n */\nexport type PaymentMethod = 'net30' | 'card' | 'embedded';\nexport type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'custom';\nexport type SubscriptionIntervalUnit = 'hour' | 'day' | 'week' | 'month';\nexport type CheckoutEmbedMode = 'checkout-full' | 'payment-only';\nexport type CheckoutEmbedRoute = 'c' | 's';\n\nexport interface CheckoutClientOptions {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof globalThis.fetch;\n timeoutMs?: number;\n}\n\nexport interface CheckoutAddress {\n firstName: string;\n lastName: string;\n company?: string;\n addressLine1: string;\n addressLine2?: string;\n city: string;\n stateProvince: string;\n postalCode: string;\n countryCode: string;\n phone?: string;\n}\n\nexport interface CheckoutCustomerAddressInput {\n firstName?: string;\n lastName?: string;\n phone?: string;\n addressLine1?: string;\n addressLine2?: string;\n city?: string;\n state?: string;\n postalCode?: string;\n country?: string;\n}\n\nexport interface CheckoutCustomerInput {\n customerId?: string;\n externalCustomerId?: string;\n email?: string;\n firstName?: string;\n lastName?: string;\n phone?: string;\n shippingAddress?: CheckoutCustomerAddressInput;\n billingAddress?: CheckoutCustomerAddressInput;\n metadata?: Record<string, unknown>;\n}\n\nexport interface RecurringIntentInput {\n plan: string;\n /** A named interval. Or send intervalUnit + intervalCount for any cadence from 1 hour to 1 year. */\n interval?: SubscriptionInterval;\n intervalUnit?: SubscriptionIntervalUnit;\n intervalCount?: number;\n /** Makes the subscription an installment plan of exactly this many payments (2–60). Not combinable with trialDays. */\n totalPayments?: number;\n amount?: number;\n trialDays?: number;\n planName?: string;\n create?: 'auto' | 'manual';\n}\n\nexport interface CheckoutCollectInput {\n shippingAddress?: boolean;\n billingAddress?: boolean;\n}\n\nexport interface CheckoutPaymentTermsInput {\n netN?: number | null;\n}\n\nexport interface CreateCheckoutSessionInput {\n applicationId: string;\n cartId?: string;\n externalCartId?: string;\n customerEmail?: string;\n customer?: CheckoutCustomerInput;\n returnUrl: string;\n cancelUrl: string;\n allowedMethods?: string[];\n paymentTerms?: CheckoutPaymentTermsInput;\n recurring?: RecurringIntentInput;\n collect?: CheckoutCollectInput;\n metadata?: Record<string, unknown>;\n discountCode?: string;\n}\n\nexport interface CheckoutSession {\n sessionId: string;\n id?: string;\n checkoutUrl?: string;\n hostedUrl?: string;\n embedUrl?: string;\n embedToken?: string;\n expiresAt?: string;\n [key: string]: unknown;\n}\n\nexport type CheckoutSessionStatus =\n | 'open'\n | 'customer_set'\n | 'address_set'\n | 'processing'\n | 'completed'\n | 'expired'\n | 'cancelled';\n\n/** A session as read back by `getSession` — the create response plus its current state. */\nexport interface CheckoutSessionDetails extends CheckoutSession {\n status: CheckoutSessionStatus;\n cartId?: string | null;\n customerId?: string | null;\n customerEmail?: string | null;\n shippingAddress?: CheckoutAddress | null;\n billingAddress?: CheckoutAddress | null;\n returnUrl?: string;\n cancelUrl?: string;\n completedAt?: string | null;\n allowedMethods?: string[] | null;\n collectShipping?: boolean;\n collectBilling?: boolean;\n discountCode?: string | null;\n metadata?: Record<string, unknown>;\n}\n\nexport interface Net30Acceptance {\n termsHash: string;\n acceptedAt: string;\n companyName: string;\n billingEmail: string;\n}\n\nexport interface CompleteCheckoutSessionInput {\n email?: string;\n shippingAddress?: CheckoutAddress;\n billingAddress?: CheckoutAddress;\n billingSameAsShipping?: boolean;\n paymentMethod: PaymentMethod;\n netDays?: number;\n termsAccepted?: boolean;\n termsSnapshot?: string;\n invoiceNumber?: string;\n net30Acceptance?: Net30Acceptance;\n paymentToken?: string;\n processorCheckoutSessionId?: string;\n processorTransactionId?: string;\n}\n\nexport interface CompleteCheckoutSessionResult {\n orderId: string;\n orderNumber?: string;\n paymentId?: string;\n total?: number;\n currency?: string;\n status?: string;\n paymentStatus?: string;\n [key: string]: unknown;\n}\n\n/**\n * The card needs a 3-D Secure challenge the buyer has to answer.\n *\n * Only the server-authorized card path (`processorCheckoutSessionId` with no\n * `processorTransactionId`) can produce this. The payment is neither completed\n * nor declined, so there is deliberately no `orderId` and no `paymentId`: put\n * the challenge in front of the buyer, then call `completeSession` again with\n * the same input.\n */\nexport interface CompleteCheckoutSessionRequiresAction {\n status: 'requires_action';\n orderId?: undefined;\n paymentStatus?: string;\n [key: string]: unknown;\n}\n\n/**\n * Narrow on `status === 'requires_action'` before reading `orderId`.\n * `isRequiresAction(result)` does that for you.\n */\nexport type CompleteCheckoutSessionOutcome =\n | CompleteCheckoutSessionResult\n | CompleteCheckoutSessionRequiresAction;\n\nexport function isRequiresAction(\n outcome: CompleteCheckoutSessionOutcome,\n): outcome is CompleteCheckoutSessionRequiresAction {\n return outcome.status === 'requires_action';\n}\n\nexport interface CreateEmbedTokenInput {\n externalCartId?: string;\n amount: number;\n currency: string;\n country?: string;\n // NOTE: `allowedMethods` is intentionally NOT accepted here. A payment-only\n // Gr4vy embed cannot restrict payment methods (the Gr4vy widget renders the\n // methods configured on your Gr4vy connection). The server rejects it with\n // `allowed_methods_unsupported`. To restrict methods, configure the connection\n // or use the full hosted checkout, where allowedMethods filters the selection.\n}\n\nexport interface CreateEmbedTokenResult {\n embedToken: string;\n checkoutSessionId: string;\n amount: number;\n currency: string;\n hostedUrl?: string;\n embedUrl?: string;\n processorInstanceId?: string;\n merchantAccountId?: string;\n [key: string]: unknown;\n}\n\nexport interface CheckoutOrder {\n id: string;\n orderNumber?: string;\n status: string;\n paymentStatus: string | null;\n currency: string;\n subtotal: number;\n taxTotal: number;\n shippingTotal: number;\n total: number;\n metadata?: Record<string, unknown>;\n payments?: CheckoutPayment[];\n [key: string]: unknown;\n}\n\nexport interface ListOrdersOptions {\n customerId?: string;\n cursor?: string;\n limit?: number;\n status?: string;\n paymentStatus?: string;\n}\n\nexport interface PaginatedOrders {\n data: CheckoutOrder[];\n pagination?: {\n cursor: string | null;\n hasMore: boolean;\n };\n}\n\nexport interface CheckoutPayment {\n id: string;\n orderId?: string;\n processor?: string;\n processorTransactionId?: string | null;\n amount?: number;\n currency?: string;\n status?: string;\n method?: string;\n createdAt?: string;\n transactions?: CheckoutPaymentTransaction[];\n [key: string]: unknown;\n}\n\nexport interface CheckoutPaymentTransaction {\n id: string;\n paymentId?: string;\n type?: string;\n amount?: number;\n currency?: string;\n status?: string;\n createdAt?: string;\n [key: string]: unknown;\n}\n\nexport interface BuildCheckoutUrlOptions {\n checkoutOrigin?: string;\n sessionId: string;\n parentOrigin?: string;\n mode?: CheckoutEmbedMode;\n route?: CheckoutEmbedRoute;\n primary?: string;\n logo?: string;\n}\n\nexport interface ThrottleEnvelope<T> {\n data?: T;\n meta?: Record<string, unknown>;\n error?: {\n code?: string;\n message?: string;\n details?: unknown;\n };\n}\n\n/**\n * Thrown on a non-2xx response from the Throttle Checkout API.\n *\n * Extends the shared {@link ThrottleError} so a single\n * `catch (e) { if (e instanceof ThrottleError) … }` covers errors from every\n * Throttle SDK. `instanceof ThrottleCheckoutError` keeps working for existing\n * code.\n */\nexport class ThrottleCheckoutError extends ThrottleError {\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n body?: unknown;\n responseHeaders?: ThrottleErrorArgs['responseHeaders'];\n }) {\n super(args);\n this.name = 'ThrottleCheckoutError';\n }\n}\n\nexport { ThrottleError, isThrottleError } from '@usethrottle/errors';\n\nexport class CheckoutClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly timeoutMs: number;\n\n constructor(opts: CheckoutClientOptions) {\n if (!opts.apiKey) throw new Error('CheckoutClient: apiKey is required');\n const fetchImpl = opts.fetch ?? globalThis.fetch;\n if (!fetchImpl) throw new Error('CheckoutClient: fetch is required');\n this.apiKey = opts.apiKey;\n this.baseUrl = (opts.baseUrl ?? 'https://api.usethrottle.dev').replace(/\\/+$/, '');\n this.fetchImpl = fetchImpl;\n this.timeoutMs = opts.timeoutMs ?? 30_000;\n }\n\n async request<T = unknown>(method: string, path: string, body?: unknown): Promise<T> {\n const envelope = await this.requestEnvelope<T>(method, path, body);\n if (Object.prototype.hasOwnProperty.call(envelope, 'data')) {\n return envelope.data as T;\n }\n return envelope as T;\n }\n\n async requestEnvelope<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<ThrottleEnvelope<T>> {\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);\n\n try {\n const res = await this.fetchImpl(toAbsoluteUrl(this.baseUrl, path), {\n method,\n headers: {\n 'content-type': 'application/json',\n 'x-api-key': this.apiKey,\n },\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal: ctrl.signal,\n });\n\n if (res.status === 204) return { data: undefined as T };\n\n const json = (await res.json().catch(() => ({}))) as ThrottleEnvelope<T>;\n if (!res.ok) {\n throw new ThrottleCheckoutError({\n code: json.error?.code ?? 'unknown_error',\n message: json.error?.message ?? `HTTP ${res.status}`,\n statusCode: res.status,\n details: json.error?.details,\n body: json,\n responseHeaders: res.headers,\n });\n }\n return json;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async createSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout/sessions', input);\n return normalizeCheckoutSession(data);\n }\n\n /**\n * Returns either a completion or `{status: 'requires_action'}` when the card\n * needs a 3-D Secure challenge — narrow with `isRequiresAction()` before\n * reading `orderId`.\n */\n async completeSession(\n sessionId: string,\n input: CompleteCheckoutSessionInput,\n ): Promise<CompleteCheckoutSessionOutcome> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}/complete`,\n input,\n );\n return normalizeCompleteResult(data);\n }\n\n /**\n * Read a checkout session's current state — `status` tells you whether the\n * buyer is still in it (`open`, `processing`) or it has settled (`completed`,\n * `cancelled`, `expired`). Use it to decide whether a session can be resumed\n * or cancelled instead of tracking that yourself.\n */\n async getSession(sessionId: string): Promise<CheckoutSessionDetails> {\n const data = await this.request<any>(\n 'GET',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}`,\n );\n return {\n ...normalizeCheckoutSession(data),\n status: requiredString(data?.status, 'checkoutSession.status') as CheckoutSessionStatus,\n };\n }\n\n /**\n * Cancel an in-flight checkout session (e.g. the buyer abandoned the embed).\n * Idempotent — cancelling an already-cancelled session is a no-op; a completed\n * session cannot be cancelled (the API returns 422 `already_completed`).\n */\n async cancelSession(sessionId: string): Promise<void> {\n await this.request<unknown>(\n 'DELETE',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}`,\n );\n }\n\n async createEmbedToken(input: CreateEmbedTokenInput): Promise<CreateEmbedTokenResult> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout-sessions/embed-token', input);\n return normalizeEmbedToken(data);\n }\n\n async getOrder(orderId: string): Promise<CheckoutOrder> {\n const data = await this.request<unknown>('GET', `/api/v1/orders/${encodeURIComponent(orderId)}`);\n return normalizeOrder(data);\n }\n\n async listOrders(options: ListOrdersOptions = {}): Promise<PaginatedOrders> {\n const params = new URLSearchParams();\n if (options.customerId) params.set('customerId', options.customerId);\n if (options.cursor) params.set('cursor', options.cursor);\n if (options.limit !== undefined) params.set('limit', String(options.limit));\n if (options.status) params.set('status', options.status);\n if (options.paymentStatus) params.set('paymentStatus', options.paymentStatus);\n\n const query = params.toString();\n const envelope = await this.requestEnvelope<unknown[]>(\n 'GET',\n `/api/v1/orders${query ? `?${query}` : ''}`,\n );\n return {\n data: (envelope.data ?? []).map(normalizeOrder),\n pagination: envelope.meta?.pagination as PaginatedOrders['pagination'],\n };\n }\n\n async listOrderPayments(orderId: string): Promise<CheckoutPayment[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/orders/${encodeURIComponent(orderId)}/payments`,\n );\n return (data ?? []).map(normalizePayment);\n }\n\n async listPaymentTransactions(paymentId: string): Promise<CheckoutPaymentTransaction[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/payments/${encodeURIComponent(paymentId)}/transactions`,\n );\n return (data ?? []).map(normalizeTransaction);\n }\n\n async getOrderWithPayments(orderId: string): Promise<CheckoutOrder> {\n const order = await this.getOrder(orderId);\n const payments = await this.listOrderPayments(orderId);\n return {\n ...order,\n payments: await Promise.all(\n payments.map(async (payment) => ({\n ...payment,\n transactions: payment.id ? await this.listPaymentTransactions(payment.id) : [],\n })),\n ),\n };\n }\n}\n\nexport function createCheckoutClient(opts: CheckoutClientOptions): CheckoutClient {\n return new CheckoutClient(opts);\n}\n\nexport function buildCheckoutHostedUrl(options: BuildCheckoutUrlOptions): string {\n const route = options.route ?? 's';\n const base = (options.checkoutOrigin ?? 'https://checkout.usethrottle.dev').replace(/\\/+$/, '');\n return `${base}/${route}/${encodeURIComponent(options.sessionId)}`;\n}\n\nexport function buildCheckoutEmbedUrl(options: BuildCheckoutUrlOptions): string {\n const baseUrl = buildCheckoutHostedUrl({\n checkoutOrigin: options.checkoutOrigin,\n sessionId: options.sessionId,\n route: options.route ?? 'c',\n });\n const params = new URLSearchParams({\n embed: '1',\n mode: options.mode ?? 'payment-only',\n ...(options.parentOrigin ? { parentOrigin: options.parentOrigin.replace(/\\/+$/, '') } : {}),\n });\n if (options.primary) params.set('primary', options.primary);\n if (options.logo) params.set('logo', options.logo);\n return `${baseUrl}?${params.toString()}`;\n}\n\nfunction toAbsoluteUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl}${path.startsWith('/') ? path : `/${path}`}`;\n}\n\nfunction normalizeCheckoutSession(raw: any): CheckoutSession {\n const sessionId = raw?.sessionId ?? raw?.id;\n return {\n ...withoutSnakeKeys(raw),\n id: optionalString(raw?.id) ?? undefined,\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl) ?? undefined,\n hostedUrl: optionalString(raw?.hostedUrl) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl) ?? undefined,\n embedToken: optionalString(raw?.embedToken) ?? undefined,\n expiresAt: optionalString(raw?.expiresAt) ?? undefined,\n };\n}\n\nfunction normalizeCompleteResult(raw: any): CompleteCheckoutSessionOutcome {\n // A 3-D Secure challenge is a 200, not an error, and carries no order — so\n // `requiredString(orderId)` below would throw a local parse error at exactly\n // the moment the caller needs to show the buyer a challenge.\n if (raw?.status === 'requires_action') {\n return {\n ...withoutSnakeKeys(raw),\n status: 'requires_action',\n paymentStatus: optionalString(raw?.paymentStatus) ?? undefined,\n };\n }\n const orderId = raw?.orderId ?? raw?.id;\n return {\n ...withoutSnakeKeys(raw),\n orderId: requiredString(orderId, 'checkoutComplete.orderId'),\n orderNumber: optionalString(raw?.orderNumber) ?? undefined,\n paymentId: optionalString(raw?.paymentId) ?? undefined,\n total: optionalNumber(raw?.total),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n paymentStatus: optionalString(raw?.paymentStatus) ?? undefined,\n };\n}\n\nfunction normalizeEmbedToken(raw: any): CreateEmbedTokenResult {\n return {\n ...withoutSnakeKeys(raw),\n embedToken: requiredString(raw?.embedToken, 'embedToken.embedToken'),\n checkoutSessionId: requiredString(raw?.checkoutSessionId, 'embedToken.checkoutSessionId'),\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n hostedUrl: optionalString(raw?.hostedUrl) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl) ?? undefined,\n processorInstanceId: optionalString(raw?.processorInstanceId) ?? undefined,\n merchantAccountId: optionalString(raw?.merchantAccountId) ?? undefined,\n };\n}\n\nfunction normalizeOrder(raw: any): CheckoutOrder {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'order.id'),\n orderNumber: optionalString(raw?.orderNumber) ?? undefined,\n status: optionalString(raw?.status) ?? 'processing',\n paymentStatus: optionalString(raw?.paymentStatus),\n currency: optionalString(raw?.currency) ?? 'USD',\n subtotal: Number(raw?.subtotal ?? 0),\n taxTotal: Number(raw?.taxTotal ?? 0),\n shippingTotal: Number(raw?.shippingTotal ?? 0),\n total: Number(raw?.total ?? 0),\n metadata: objectOrUndefined(raw?.metadata),\n payments: Array.isArray(raw?.payments) ? raw.payments.map(normalizePayment) : undefined,\n };\n}\n\nfunction normalizePayment(raw: any): CheckoutPayment {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'payment.id'),\n orderId: optionalString(raw?.orderId) ?? undefined,\n processor: optionalString(raw?.processor) ?? undefined,\n processorTransactionId:\n optionalString(raw?.processorTransactionId) ?? undefined,\n amount: optionalNumber(raw?.amount),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n method: optionalString(raw?.method) ?? undefined,\n createdAt: optionalString(raw?.createdAt) ?? undefined,\n transactions: Array.isArray(raw?.transactions)\n ? raw.transactions.map(normalizeTransaction)\n : undefined,\n };\n}\n\nfunction normalizeTransaction(raw: any): CheckoutPaymentTransaction {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'transaction.id'),\n paymentId: optionalString(raw?.paymentId) ?? undefined,\n type: optionalString(raw?.type) ?? undefined,\n amount: optionalNumber(raw?.amount),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n createdAt: optionalString(raw?.createdAt) ?? undefined,\n };\n}\n\nfunction withoutSnakeKeys(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return {};\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).filter(([key]) => !key.includes('_')),\n );\n}\n\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalString(value: unknown): string | null {\n return typeof value === 'string' && value.length > 0 ? value : null;\n}\n\nfunction optionalNumber(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n}\n\nfunction objectOrUndefined(value: unknown): Record<string, unknown> | undefined {\n return value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AA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S,kBAAkB,OAAqD;AAC9E,SAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAC5D,QACD;AACN;","names":["import_errors"]}
|
package/dist/server.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ThrottleError } from '@usethrottle/errors';
|
|
1
|
+
import { ThrottleError, ThrottleErrorArgs } from '@usethrottle/errors';
|
|
2
2
|
export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -8,7 +8,8 @@ export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
|
8
8
|
* `payment_method_not_supported`. Use `'embedded'`.
|
|
9
9
|
*/
|
|
10
10
|
type PaymentMethod = 'net30' | 'card' | 'embedded';
|
|
11
|
-
type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly';
|
|
11
|
+
type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'custom';
|
|
12
|
+
type SubscriptionIntervalUnit = 'hour' | 'day' | 'week' | 'month';
|
|
12
13
|
type CheckoutEmbedMode = 'checkout-full' | 'payment-only';
|
|
13
14
|
type CheckoutEmbedRoute = 'c' | 's';
|
|
14
15
|
interface CheckoutClientOptions {
|
|
@@ -53,7 +54,12 @@ interface CheckoutCustomerInput {
|
|
|
53
54
|
}
|
|
54
55
|
interface RecurringIntentInput {
|
|
55
56
|
plan: string;
|
|
56
|
-
interval
|
|
57
|
+
/** A named interval. Or send intervalUnit + intervalCount for any cadence from 1 hour to 1 year. */
|
|
58
|
+
interval?: SubscriptionInterval;
|
|
59
|
+
intervalUnit?: SubscriptionIntervalUnit;
|
|
60
|
+
intervalCount?: number;
|
|
61
|
+
/** Makes the subscription an installment plan of exactly this many payments (2–60). Not combinable with trialDays. */
|
|
62
|
+
totalPayments?: number;
|
|
57
63
|
amount?: number;
|
|
58
64
|
trialDays?: number;
|
|
59
65
|
planName?: string;
|
|
@@ -140,6 +146,27 @@ interface CompleteCheckoutSessionResult {
|
|
|
140
146
|
paymentStatus?: string;
|
|
141
147
|
[key: string]: unknown;
|
|
142
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* The card needs a 3-D Secure challenge the buyer has to answer.
|
|
151
|
+
*
|
|
152
|
+
* Only the server-authorized card path (`processorCheckoutSessionId` with no
|
|
153
|
+
* `processorTransactionId`) can produce this. The payment is neither completed
|
|
154
|
+
* nor declined, so there is deliberately no `orderId` and no `paymentId`: put
|
|
155
|
+
* the challenge in front of the buyer, then call `completeSession` again with
|
|
156
|
+
* the same input.
|
|
157
|
+
*/
|
|
158
|
+
interface CompleteCheckoutSessionRequiresAction {
|
|
159
|
+
status: 'requires_action';
|
|
160
|
+
orderId?: undefined;
|
|
161
|
+
paymentStatus?: string;
|
|
162
|
+
[key: string]: unknown;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Narrow on `status === 'requires_action'` before reading `orderId`.
|
|
166
|
+
* `isRequiresAction(result)` does that for you.
|
|
167
|
+
*/
|
|
168
|
+
type CompleteCheckoutSessionOutcome = CompleteCheckoutSessionResult | CompleteCheckoutSessionRequiresAction;
|
|
169
|
+
declare function isRequiresAction(outcome: CompleteCheckoutSessionOutcome): outcome is CompleteCheckoutSessionRequiresAction;
|
|
143
170
|
interface CreateEmbedTokenInput {
|
|
144
171
|
externalCartId?: string;
|
|
145
172
|
amount: number;
|
|
@@ -241,6 +268,7 @@ declare class ThrottleCheckoutError extends ThrottleError {
|
|
|
241
268
|
statusCode: number;
|
|
242
269
|
details?: unknown;
|
|
243
270
|
body?: unknown;
|
|
271
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
244
272
|
});
|
|
245
273
|
}
|
|
246
274
|
|
|
@@ -253,7 +281,12 @@ declare class CheckoutClient {
|
|
|
253
281
|
request<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
|
|
254
282
|
requestEnvelope<T = unknown>(method: string, path: string, body?: unknown): Promise<ThrottleEnvelope<T>>;
|
|
255
283
|
createSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession>;
|
|
256
|
-
|
|
284
|
+
/**
|
|
285
|
+
* Returns either a completion or `{status: 'requires_action'}` when the card
|
|
286
|
+
* needs a 3-D Secure challenge — narrow with `isRequiresAction()` before
|
|
287
|
+
* reading `orderId`.
|
|
288
|
+
*/
|
|
289
|
+
completeSession(sessionId: string, input: CompleteCheckoutSessionInput): Promise<CompleteCheckoutSessionOutcome>;
|
|
257
290
|
/**
|
|
258
291
|
* Read a checkout session's current state — `status` tells you whether the
|
|
259
292
|
* buyer is still in it (`open`, `processing`) or it has settled (`completed`,
|
|
@@ -278,4 +311,4 @@ declare function createCheckoutClient(opts: CheckoutClientOptions): CheckoutClie
|
|
|
278
311
|
declare function buildCheckoutHostedUrl(options: BuildCheckoutUrlOptions): string;
|
|
279
312
|
declare function buildCheckoutEmbedUrl(options: BuildCheckoutUrlOptions): string;
|
|
280
313
|
|
|
281
|
-
export { type BuildCheckoutUrlOptions, type CheckoutAddress, CheckoutClient, type CheckoutClientOptions, type CheckoutCollectInput, type CheckoutCustomerAddressInput, type CheckoutCustomerInput, type CheckoutEmbedMode, type CheckoutEmbedRoute, type CheckoutOrder, type CheckoutPayment, type CheckoutPaymentTermsInput, type CheckoutPaymentTransaction, type CheckoutSession, type CheckoutSessionDetails, type CheckoutSessionStatus, type CompleteCheckoutSessionInput, type CompleteCheckoutSessionResult, type CreateCheckoutSessionInput, type CreateEmbedTokenInput, type CreateEmbedTokenResult, type ListOrdersOptions, type Net30Acceptance, type PaginatedOrders, type PaymentMethod, type RecurringIntentInput, type SubscriptionInterval, ThrottleCheckoutError, type ThrottleEnvelope, buildCheckoutEmbedUrl, buildCheckoutHostedUrl, createCheckoutClient };
|
|
314
|
+
export { type BuildCheckoutUrlOptions, type CheckoutAddress, CheckoutClient, type CheckoutClientOptions, type CheckoutCollectInput, type CheckoutCustomerAddressInput, type CheckoutCustomerInput, type CheckoutEmbedMode, type CheckoutEmbedRoute, type CheckoutOrder, type CheckoutPayment, type CheckoutPaymentTermsInput, type CheckoutPaymentTransaction, type CheckoutSession, type CheckoutSessionDetails, type CheckoutSessionStatus, type CompleteCheckoutSessionInput, type CompleteCheckoutSessionOutcome, type CompleteCheckoutSessionRequiresAction, type CompleteCheckoutSessionResult, type CreateCheckoutSessionInput, type CreateEmbedTokenInput, type CreateEmbedTokenResult, type ListOrdersOptions, type Net30Acceptance, type PaginatedOrders, type PaymentMethod, type RecurringIntentInput, type SubscriptionInterval, type SubscriptionIntervalUnit, ThrottleCheckoutError, type ThrottleEnvelope, buildCheckoutEmbedUrl, buildCheckoutHostedUrl, createCheckoutClient, isRequiresAction };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ThrottleError } from '@usethrottle/errors';
|
|
1
|
+
import { ThrottleError, ThrottleErrorArgs } from '@usethrottle/errors';
|
|
2
2
|
export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -8,7 +8,8 @@ export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
|
8
8
|
* `payment_method_not_supported`. Use `'embedded'`.
|
|
9
9
|
*/
|
|
10
10
|
type PaymentMethod = 'net30' | 'card' | 'embedded';
|
|
11
|
-
type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly';
|
|
11
|
+
type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'custom';
|
|
12
|
+
type SubscriptionIntervalUnit = 'hour' | 'day' | 'week' | 'month';
|
|
12
13
|
type CheckoutEmbedMode = 'checkout-full' | 'payment-only';
|
|
13
14
|
type CheckoutEmbedRoute = 'c' | 's';
|
|
14
15
|
interface CheckoutClientOptions {
|
|
@@ -53,7 +54,12 @@ interface CheckoutCustomerInput {
|
|
|
53
54
|
}
|
|
54
55
|
interface RecurringIntentInput {
|
|
55
56
|
plan: string;
|
|
56
|
-
interval
|
|
57
|
+
/** A named interval. Or send intervalUnit + intervalCount for any cadence from 1 hour to 1 year. */
|
|
58
|
+
interval?: SubscriptionInterval;
|
|
59
|
+
intervalUnit?: SubscriptionIntervalUnit;
|
|
60
|
+
intervalCount?: number;
|
|
61
|
+
/** Makes the subscription an installment plan of exactly this many payments (2–60). Not combinable with trialDays. */
|
|
62
|
+
totalPayments?: number;
|
|
57
63
|
amount?: number;
|
|
58
64
|
trialDays?: number;
|
|
59
65
|
planName?: string;
|
|
@@ -140,6 +146,27 @@ interface CompleteCheckoutSessionResult {
|
|
|
140
146
|
paymentStatus?: string;
|
|
141
147
|
[key: string]: unknown;
|
|
142
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* The card needs a 3-D Secure challenge the buyer has to answer.
|
|
151
|
+
*
|
|
152
|
+
* Only the server-authorized card path (`processorCheckoutSessionId` with no
|
|
153
|
+
* `processorTransactionId`) can produce this. The payment is neither completed
|
|
154
|
+
* nor declined, so there is deliberately no `orderId` and no `paymentId`: put
|
|
155
|
+
* the challenge in front of the buyer, then call `completeSession` again with
|
|
156
|
+
* the same input.
|
|
157
|
+
*/
|
|
158
|
+
interface CompleteCheckoutSessionRequiresAction {
|
|
159
|
+
status: 'requires_action';
|
|
160
|
+
orderId?: undefined;
|
|
161
|
+
paymentStatus?: string;
|
|
162
|
+
[key: string]: unknown;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Narrow on `status === 'requires_action'` before reading `orderId`.
|
|
166
|
+
* `isRequiresAction(result)` does that for you.
|
|
167
|
+
*/
|
|
168
|
+
type CompleteCheckoutSessionOutcome = CompleteCheckoutSessionResult | CompleteCheckoutSessionRequiresAction;
|
|
169
|
+
declare function isRequiresAction(outcome: CompleteCheckoutSessionOutcome): outcome is CompleteCheckoutSessionRequiresAction;
|
|
143
170
|
interface CreateEmbedTokenInput {
|
|
144
171
|
externalCartId?: string;
|
|
145
172
|
amount: number;
|
|
@@ -241,6 +268,7 @@ declare class ThrottleCheckoutError extends ThrottleError {
|
|
|
241
268
|
statusCode: number;
|
|
242
269
|
details?: unknown;
|
|
243
270
|
body?: unknown;
|
|
271
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
244
272
|
});
|
|
245
273
|
}
|
|
246
274
|
|
|
@@ -253,7 +281,12 @@ declare class CheckoutClient {
|
|
|
253
281
|
request<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
|
|
254
282
|
requestEnvelope<T = unknown>(method: string, path: string, body?: unknown): Promise<ThrottleEnvelope<T>>;
|
|
255
283
|
createSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession>;
|
|
256
|
-
|
|
284
|
+
/**
|
|
285
|
+
* Returns either a completion or `{status: 'requires_action'}` when the card
|
|
286
|
+
* needs a 3-D Secure challenge — narrow with `isRequiresAction()` before
|
|
287
|
+
* reading `orderId`.
|
|
288
|
+
*/
|
|
289
|
+
completeSession(sessionId: string, input: CompleteCheckoutSessionInput): Promise<CompleteCheckoutSessionOutcome>;
|
|
257
290
|
/**
|
|
258
291
|
* Read a checkout session's current state — `status` tells you whether the
|
|
259
292
|
* buyer is still in it (`open`, `processing`) or it has settled (`completed`,
|
|
@@ -278,4 +311,4 @@ declare function createCheckoutClient(opts: CheckoutClientOptions): CheckoutClie
|
|
|
278
311
|
declare function buildCheckoutHostedUrl(options: BuildCheckoutUrlOptions): string;
|
|
279
312
|
declare function buildCheckoutEmbedUrl(options: BuildCheckoutUrlOptions): string;
|
|
280
313
|
|
|
281
|
-
export { type BuildCheckoutUrlOptions, type CheckoutAddress, CheckoutClient, type CheckoutClientOptions, type CheckoutCollectInput, type CheckoutCustomerAddressInput, type CheckoutCustomerInput, type CheckoutEmbedMode, type CheckoutEmbedRoute, type CheckoutOrder, type CheckoutPayment, type CheckoutPaymentTermsInput, type CheckoutPaymentTransaction, type CheckoutSession, type CheckoutSessionDetails, type CheckoutSessionStatus, type CompleteCheckoutSessionInput, type CompleteCheckoutSessionResult, type CreateCheckoutSessionInput, type CreateEmbedTokenInput, type CreateEmbedTokenResult, type ListOrdersOptions, type Net30Acceptance, type PaginatedOrders, type PaymentMethod, type RecurringIntentInput, type SubscriptionInterval, ThrottleCheckoutError, type ThrottleEnvelope, buildCheckoutEmbedUrl, buildCheckoutHostedUrl, createCheckoutClient };
|
|
314
|
+
export { type BuildCheckoutUrlOptions, type CheckoutAddress, CheckoutClient, type CheckoutClientOptions, type CheckoutCollectInput, type CheckoutCustomerAddressInput, type CheckoutCustomerInput, type CheckoutEmbedMode, type CheckoutEmbedRoute, type CheckoutOrder, type CheckoutPayment, type CheckoutPaymentTermsInput, type CheckoutPaymentTransaction, type CheckoutSession, type CheckoutSessionDetails, type CheckoutSessionStatus, type CompleteCheckoutSessionInput, type CompleteCheckoutSessionOutcome, type CompleteCheckoutSessionRequiresAction, type CompleteCheckoutSessionResult, type CreateCheckoutSessionInput, type CreateEmbedTokenInput, type CreateEmbedTokenResult, type ListOrdersOptions, type Net30Acceptance, type PaginatedOrders, type PaymentMethod, type RecurringIntentInput, type SubscriptionInterval, type SubscriptionIntervalUnit, ThrottleCheckoutError, type ThrottleEnvelope, buildCheckoutEmbedUrl, buildCheckoutHostedUrl, createCheckoutClient, isRequiresAction };
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// src/server.ts
|
|
2
2
|
import { ThrottleError } from "@usethrottle/errors";
|
|
3
3
|
import { ThrottleError as ThrottleError2, isThrottleError } from "@usethrottle/errors";
|
|
4
|
+
function isRequiresAction(outcome) {
|
|
5
|
+
return outcome.status === "requires_action";
|
|
6
|
+
}
|
|
4
7
|
var ThrottleCheckoutError = class extends ThrottleError {
|
|
5
8
|
constructor(args) {
|
|
6
9
|
super(args);
|
|
@@ -45,7 +48,8 @@ var CheckoutClient = class {
|
|
|
45
48
|
message: json.error?.message ?? `HTTP ${res.status}`,
|
|
46
49
|
statusCode: res.status,
|
|
47
50
|
details: json.error?.details,
|
|
48
|
-
body: json
|
|
51
|
+
body: json,
|
|
52
|
+
responseHeaders: res.headers
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
55
|
return json;
|
|
@@ -57,6 +61,11 @@ var CheckoutClient = class {
|
|
|
57
61
|
const data = await this.request("POST", "/api/v1/checkout/sessions", input);
|
|
58
62
|
return normalizeCheckoutSession(data);
|
|
59
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns either a completion or `{status: 'requires_action'}` when the card
|
|
66
|
+
* needs a 3-D Secure challenge — narrow with `isRequiresAction()` before
|
|
67
|
+
* reading `orderId`.
|
|
68
|
+
*/
|
|
60
69
|
async completeSession(sessionId, input) {
|
|
61
70
|
const data = await this.request(
|
|
62
71
|
"POST",
|
|
@@ -186,6 +195,13 @@ function normalizeCheckoutSession(raw) {
|
|
|
186
195
|
};
|
|
187
196
|
}
|
|
188
197
|
function normalizeCompleteResult(raw) {
|
|
198
|
+
if (raw?.status === "requires_action") {
|
|
199
|
+
return {
|
|
200
|
+
...withoutSnakeKeys(raw),
|
|
201
|
+
status: "requires_action",
|
|
202
|
+
paymentStatus: optionalString(raw?.paymentStatus) ?? void 0
|
|
203
|
+
};
|
|
204
|
+
}
|
|
189
205
|
const orderId = raw?.orderId ?? raw?.id;
|
|
190
206
|
return {
|
|
191
207
|
...withoutSnakeKeys(raw),
|
|
@@ -280,6 +296,7 @@ export {
|
|
|
280
296
|
buildCheckoutEmbedUrl,
|
|
281
297
|
buildCheckoutHostedUrl,
|
|
282
298
|
createCheckoutClient,
|
|
299
|
+
isRequiresAction,
|
|
283
300
|
isThrottleError
|
|
284
301
|
};
|
|
285
302
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { ThrottleError } from '@usethrottle/errors';\n\n/**\n * `'embedded'` completes a card payment taken by the payment embed; `'net30'`\n * issues an invoice on terms. `'card'` names the card category in\n * `allowedMethods` — `completeSession` rejects it with 422\n * `payment_method_not_supported`. Use `'embedded'`.\n */\nexport type PaymentMethod = 'net30' | 'card' | 'embedded';\nexport type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly';\nexport type CheckoutEmbedMode = 'checkout-full' | 'payment-only';\nexport type CheckoutEmbedRoute = 'c' | 's';\n\nexport interface CheckoutClientOptions {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof globalThis.fetch;\n timeoutMs?: number;\n}\n\nexport interface CheckoutAddress {\n firstName: string;\n lastName: string;\n company?: string;\n addressLine1: string;\n addressLine2?: string;\n city: string;\n stateProvince: string;\n postalCode: string;\n countryCode: string;\n phone?: string;\n}\n\nexport interface CheckoutCustomerAddressInput {\n firstName?: string;\n lastName?: string;\n phone?: string;\n addressLine1?: string;\n addressLine2?: string;\n city?: string;\n state?: string;\n postalCode?: string;\n country?: string;\n}\n\nexport interface CheckoutCustomerInput {\n customerId?: string;\n externalCustomerId?: string;\n email?: string;\n firstName?: string;\n lastName?: string;\n phone?: string;\n shippingAddress?: CheckoutCustomerAddressInput;\n billingAddress?: CheckoutCustomerAddressInput;\n metadata?: Record<string, unknown>;\n}\n\nexport interface RecurringIntentInput {\n plan: string;\n interval: SubscriptionInterval;\n amount?: number;\n trialDays?: number;\n planName?: string;\n create?: 'auto' | 'manual';\n}\n\nexport interface CheckoutCollectInput {\n shippingAddress?: boolean;\n billingAddress?: boolean;\n}\n\nexport interface CheckoutPaymentTermsInput {\n netN?: number | null;\n}\n\nexport interface CreateCheckoutSessionInput {\n applicationId: string;\n cartId?: string;\n externalCartId?: string;\n customerEmail?: string;\n customer?: CheckoutCustomerInput;\n returnUrl: string;\n cancelUrl: string;\n allowedMethods?: string[];\n paymentTerms?: CheckoutPaymentTermsInput;\n recurring?: RecurringIntentInput;\n collect?: CheckoutCollectInput;\n metadata?: Record<string, unknown>;\n discountCode?: string;\n}\n\nexport interface CheckoutSession {\n sessionId: string;\n id?: string;\n checkoutUrl?: string;\n hostedUrl?: string;\n embedUrl?: string;\n embedToken?: string;\n expiresAt?: string;\n [key: string]: unknown;\n}\n\nexport type CheckoutSessionStatus =\n | 'open'\n | 'customer_set'\n | 'address_set'\n | 'processing'\n | 'completed'\n | 'expired'\n | 'cancelled';\n\n/** A session as read back by `getSession` — the create response plus its current state. */\nexport interface CheckoutSessionDetails extends CheckoutSession {\n status: CheckoutSessionStatus;\n cartId?: string | null;\n customerId?: string | null;\n customerEmail?: string | null;\n shippingAddress?: CheckoutAddress | null;\n billingAddress?: CheckoutAddress | null;\n returnUrl?: string;\n cancelUrl?: string;\n completedAt?: string | null;\n allowedMethods?: string[] | null;\n collectShipping?: boolean;\n collectBilling?: boolean;\n discountCode?: string | null;\n metadata?: Record<string, unknown>;\n}\n\nexport interface Net30Acceptance {\n termsHash: string;\n acceptedAt: string;\n companyName: string;\n billingEmail: string;\n}\n\nexport interface CompleteCheckoutSessionInput {\n email?: string;\n shippingAddress?: CheckoutAddress;\n billingAddress?: CheckoutAddress;\n billingSameAsShipping?: boolean;\n paymentMethod: PaymentMethod;\n netDays?: number;\n termsAccepted?: boolean;\n termsSnapshot?: string;\n invoiceNumber?: string;\n net30Acceptance?: Net30Acceptance;\n paymentToken?: string;\n processorCheckoutSessionId?: string;\n processorTransactionId?: string;\n}\n\nexport interface CompleteCheckoutSessionResult {\n orderId: string;\n orderNumber?: string;\n paymentId?: string;\n total?: number;\n currency?: string;\n status?: string;\n paymentStatus?: string;\n [key: string]: unknown;\n}\n\nexport interface CreateEmbedTokenInput {\n externalCartId?: string;\n amount: number;\n currency: string;\n country?: string;\n // NOTE: `allowedMethods` is intentionally NOT accepted here. A payment-only\n // Gr4vy embed cannot restrict payment methods (the Gr4vy widget renders the\n // methods configured on your Gr4vy connection). The server rejects it with\n // `allowed_methods_unsupported`. To restrict methods, configure the connection\n // or use the full hosted checkout, where allowedMethods filters the selection.\n}\n\nexport interface CreateEmbedTokenResult {\n embedToken: string;\n checkoutSessionId: string;\n amount: number;\n currency: string;\n hostedUrl?: string;\n embedUrl?: string;\n processorInstanceId?: string;\n merchantAccountId?: string;\n [key: string]: unknown;\n}\n\nexport interface CheckoutOrder {\n id: string;\n orderNumber?: string;\n status: string;\n paymentStatus: string | null;\n currency: string;\n subtotal: number;\n taxTotal: number;\n shippingTotal: number;\n total: number;\n metadata?: Record<string, unknown>;\n payments?: CheckoutPayment[];\n [key: string]: unknown;\n}\n\nexport interface ListOrdersOptions {\n customerId?: string;\n cursor?: string;\n limit?: number;\n status?: string;\n paymentStatus?: string;\n}\n\nexport interface PaginatedOrders {\n data: CheckoutOrder[];\n pagination?: {\n cursor: string | null;\n hasMore: boolean;\n };\n}\n\nexport interface CheckoutPayment {\n id: string;\n orderId?: string;\n processor?: string;\n processorTransactionId?: string | null;\n amount?: number;\n currency?: string;\n status?: string;\n method?: string;\n createdAt?: string;\n transactions?: CheckoutPaymentTransaction[];\n [key: string]: unknown;\n}\n\nexport interface CheckoutPaymentTransaction {\n id: string;\n paymentId?: string;\n type?: string;\n amount?: number;\n currency?: string;\n status?: string;\n createdAt?: string;\n [key: string]: unknown;\n}\n\nexport interface BuildCheckoutUrlOptions {\n checkoutOrigin?: string;\n sessionId: string;\n parentOrigin?: string;\n mode?: CheckoutEmbedMode;\n route?: CheckoutEmbedRoute;\n primary?: string;\n logo?: string;\n}\n\nexport interface ThrottleEnvelope<T> {\n data?: T;\n meta?: Record<string, unknown>;\n error?: {\n code?: string;\n message?: string;\n details?: unknown;\n };\n}\n\n/**\n * Thrown on a non-2xx response from the Throttle Checkout API.\n *\n * Extends the shared {@link ThrottleError} so a single\n * `catch (e) { if (e instanceof ThrottleError) … }` covers errors from every\n * Throttle SDK. `instanceof ThrottleCheckoutError` keeps working for existing\n * code.\n */\nexport class ThrottleCheckoutError extends ThrottleError {\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n body?: unknown;\n }) {\n super(args);\n this.name = 'ThrottleCheckoutError';\n }\n}\n\nexport { ThrottleError, isThrottleError } from '@usethrottle/errors';\n\nexport class CheckoutClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly timeoutMs: number;\n\n constructor(opts: CheckoutClientOptions) {\n if (!opts.apiKey) throw new Error('CheckoutClient: apiKey is required');\n const fetchImpl = opts.fetch ?? globalThis.fetch;\n if (!fetchImpl) throw new Error('CheckoutClient: fetch is required');\n this.apiKey = opts.apiKey;\n this.baseUrl = (opts.baseUrl ?? 'https://api.usethrottle.dev').replace(/\\/+$/, '');\n this.fetchImpl = fetchImpl;\n this.timeoutMs = opts.timeoutMs ?? 30_000;\n }\n\n async request<T = unknown>(method: string, path: string, body?: unknown): Promise<T> {\n const envelope = await this.requestEnvelope<T>(method, path, body);\n if (Object.prototype.hasOwnProperty.call(envelope, 'data')) {\n return envelope.data as T;\n }\n return envelope as T;\n }\n\n async requestEnvelope<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<ThrottleEnvelope<T>> {\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);\n\n try {\n const res = await this.fetchImpl(toAbsoluteUrl(this.baseUrl, path), {\n method,\n headers: {\n 'content-type': 'application/json',\n 'x-api-key': this.apiKey,\n },\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal: ctrl.signal,\n });\n\n if (res.status === 204) return { data: undefined as T };\n\n const json = (await res.json().catch(() => ({}))) as ThrottleEnvelope<T>;\n if (!res.ok) {\n throw new ThrottleCheckoutError({\n code: json.error?.code ?? 'unknown_error',\n message: json.error?.message ?? `HTTP ${res.status}`,\n statusCode: res.status,\n details: json.error?.details,\n body: json,\n });\n }\n return json;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async createSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout/sessions', input);\n return normalizeCheckoutSession(data);\n }\n\n async completeSession(\n sessionId: string,\n input: CompleteCheckoutSessionInput,\n ): Promise<CompleteCheckoutSessionResult> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}/complete`,\n input,\n );\n return normalizeCompleteResult(data);\n }\n\n /**\n * Read a checkout session's current state — `status` tells you whether the\n * buyer is still in it (`open`, `processing`) or it has settled (`completed`,\n * `cancelled`, `expired`). Use it to decide whether a session can be resumed\n * or cancelled instead of tracking that yourself.\n */\n async getSession(sessionId: string): Promise<CheckoutSessionDetails> {\n const data = await this.request<any>(\n 'GET',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}`,\n );\n return {\n ...normalizeCheckoutSession(data),\n status: requiredString(data?.status, 'checkoutSession.status') as CheckoutSessionStatus,\n };\n }\n\n /**\n * Cancel an in-flight checkout session (e.g. the buyer abandoned the embed).\n * Idempotent — cancelling an already-cancelled session is a no-op; a completed\n * session cannot be cancelled (the API returns 422 `already_completed`).\n */\n async cancelSession(sessionId: string): Promise<void> {\n await this.request<unknown>(\n 'DELETE',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}`,\n );\n }\n\n async createEmbedToken(input: CreateEmbedTokenInput): Promise<CreateEmbedTokenResult> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout-sessions/embed-token', input);\n return normalizeEmbedToken(data);\n }\n\n async getOrder(orderId: string): Promise<CheckoutOrder> {\n const data = await this.request<unknown>('GET', `/api/v1/orders/${encodeURIComponent(orderId)}`);\n return normalizeOrder(data);\n }\n\n async listOrders(options: ListOrdersOptions = {}): Promise<PaginatedOrders> {\n const params = new URLSearchParams();\n if (options.customerId) params.set('customerId', options.customerId);\n if (options.cursor) params.set('cursor', options.cursor);\n if (options.limit !== undefined) params.set('limit', String(options.limit));\n if (options.status) params.set('status', options.status);\n if (options.paymentStatus) params.set('paymentStatus', options.paymentStatus);\n\n const query = params.toString();\n const envelope = await this.requestEnvelope<unknown[]>(\n 'GET',\n `/api/v1/orders${query ? `?${query}` : ''}`,\n );\n return {\n data: (envelope.data ?? []).map(normalizeOrder),\n pagination: envelope.meta?.pagination as PaginatedOrders['pagination'],\n };\n }\n\n async listOrderPayments(orderId: string): Promise<CheckoutPayment[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/orders/${encodeURIComponent(orderId)}/payments`,\n );\n return (data ?? []).map(normalizePayment);\n }\n\n async listPaymentTransactions(paymentId: string): Promise<CheckoutPaymentTransaction[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/payments/${encodeURIComponent(paymentId)}/transactions`,\n );\n return (data ?? []).map(normalizeTransaction);\n }\n\n async getOrderWithPayments(orderId: string): Promise<CheckoutOrder> {\n const order = await this.getOrder(orderId);\n const payments = await this.listOrderPayments(orderId);\n return {\n ...order,\n payments: await Promise.all(\n payments.map(async (payment) => ({\n ...payment,\n transactions: payment.id ? await this.listPaymentTransactions(payment.id) : [],\n })),\n ),\n };\n }\n}\n\nexport function createCheckoutClient(opts: CheckoutClientOptions): CheckoutClient {\n return new CheckoutClient(opts);\n}\n\nexport function buildCheckoutHostedUrl(options: BuildCheckoutUrlOptions): string {\n const route = options.route ?? 's';\n const base = (options.checkoutOrigin ?? 'https://checkout.usethrottle.dev').replace(/\\/+$/, '');\n return `${base}/${route}/${encodeURIComponent(options.sessionId)}`;\n}\n\nexport function buildCheckoutEmbedUrl(options: BuildCheckoutUrlOptions): string {\n const baseUrl = buildCheckoutHostedUrl({\n checkoutOrigin: options.checkoutOrigin,\n sessionId: options.sessionId,\n route: options.route ?? 'c',\n });\n const params = new URLSearchParams({\n embed: '1',\n mode: options.mode ?? 'payment-only',\n ...(options.parentOrigin ? { parentOrigin: options.parentOrigin.replace(/\\/+$/, '') } : {}),\n });\n if (options.primary) params.set('primary', options.primary);\n if (options.logo) params.set('logo', options.logo);\n return `${baseUrl}?${params.toString()}`;\n}\n\nfunction toAbsoluteUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl}${path.startsWith('/') ? path : `/${path}`}`;\n}\n\nfunction normalizeCheckoutSession(raw: any): CheckoutSession {\n const sessionId = raw?.sessionId ?? raw?.id;\n return {\n ...withoutSnakeKeys(raw),\n id: optionalString(raw?.id) ?? undefined,\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl) ?? undefined,\n hostedUrl: optionalString(raw?.hostedUrl) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl) ?? undefined,\n embedToken: optionalString(raw?.embedToken) ?? undefined,\n expiresAt: optionalString(raw?.expiresAt) ?? undefined,\n };\n}\n\nfunction normalizeCompleteResult(raw: any): CompleteCheckoutSessionResult {\n const orderId = raw?.orderId ?? raw?.id;\n return {\n ...withoutSnakeKeys(raw),\n orderId: requiredString(orderId, 'checkoutComplete.orderId'),\n orderNumber: optionalString(raw?.orderNumber) ?? undefined,\n paymentId: optionalString(raw?.paymentId) ?? undefined,\n total: optionalNumber(raw?.total),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n paymentStatus: optionalString(raw?.paymentStatus) ?? undefined,\n };\n}\n\nfunction normalizeEmbedToken(raw: any): CreateEmbedTokenResult {\n return {\n ...withoutSnakeKeys(raw),\n embedToken: requiredString(raw?.embedToken, 'embedToken.embedToken'),\n checkoutSessionId: requiredString(raw?.checkoutSessionId, 'embedToken.checkoutSessionId'),\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n hostedUrl: optionalString(raw?.hostedUrl) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl) ?? undefined,\n processorInstanceId: optionalString(raw?.processorInstanceId) ?? undefined,\n merchantAccountId: optionalString(raw?.merchantAccountId) ?? undefined,\n };\n}\n\nfunction normalizeOrder(raw: any): CheckoutOrder {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'order.id'),\n orderNumber: optionalString(raw?.orderNumber) ?? undefined,\n status: optionalString(raw?.status) ?? 'processing',\n paymentStatus: optionalString(raw?.paymentStatus),\n currency: optionalString(raw?.currency) ?? 'USD',\n subtotal: Number(raw?.subtotal ?? 0),\n taxTotal: Number(raw?.taxTotal ?? 0),\n shippingTotal: Number(raw?.shippingTotal ?? 0),\n total: Number(raw?.total ?? 0),\n metadata: objectOrUndefined(raw?.metadata),\n payments: Array.isArray(raw?.payments) ? raw.payments.map(normalizePayment) : undefined,\n };\n}\n\nfunction normalizePayment(raw: any): CheckoutPayment {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'payment.id'),\n orderId: optionalString(raw?.orderId) ?? undefined,\n processor: optionalString(raw?.processor) ?? undefined,\n processorTransactionId:\n optionalString(raw?.processorTransactionId) ?? undefined,\n amount: optionalNumber(raw?.amount),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n method: optionalString(raw?.method) ?? undefined,\n createdAt: optionalString(raw?.createdAt) ?? undefined,\n transactions: Array.isArray(raw?.transactions)\n ? raw.transactions.map(normalizeTransaction)\n : undefined,\n };\n}\n\nfunction normalizeTransaction(raw: any): CheckoutPaymentTransaction {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'transaction.id'),\n paymentId: optionalString(raw?.paymentId) ?? undefined,\n type: optionalString(raw?.type) ?? undefined,\n amount: optionalNumber(raw?.amount),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n createdAt: optionalString(raw?.createdAt) ?? undefined,\n };\n}\n\nfunction withoutSnakeKeys(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return {};\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).filter(([key]) => !key.includes('_')),\n );\n}\n\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalString(value: unknown): string | null {\n return typeof value === 'string' && value.length > 0 ? value : null;\n}\n\nfunction optionalNumber(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n}\n\nfunction objectOrUndefined(value: unknown): Record<string, unknown> | undefined {\n return value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AA4R9B,SAAS,iBAAAA,gBAAe,uBAAuB;AAbxC,IAAM,wBAAN,cAAoC,cAAc;AAAA,EACvD,YAAY,MAMT;AACD,UAAM,IAAI;AACV,SAAK,OAAO;AAAA,EACd;AACF;AAIO,IAAM,iBAAN,MAAqB;AAAA,EAM1B,YAAY,MAA6B;AACvC,QAAI,CAAC,KAAK,OAAQ,OAAM,IAAI,MAAM,oCAAoC;AACtE,UAAM,YAAY,KAAK,SAAS,WAAW;AAC3C,QAAI,CAAC,UAAW,OAAM,IAAI,MAAM,mCAAmC;AACnE,SAAK,SAAS,KAAK;AACnB,SAAK,WAAW,KAAK,WAAW,+BAA+B,QAAQ,QAAQ,EAAE;AACjF,SAAK,YAAY;AACjB,SAAK,YAAY,KAAK,aAAa;AAAA,EACrC;AAAA,EAEA,MAAM,QAAqB,QAAgB,MAAc,MAA4B;AACnF,UAAM,WAAW,MAAM,KAAK,gBAAmB,QAAQ,MAAM,IAAI;AACjE,QAAI,OAAO,UAAU,eAAe,KAAK,UAAU,MAAM,GAAG;AAC1D,aAAO,SAAS;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,gBACJ,QACA,MACA,MAC8B;AAC9B,UAAM,OAAO,IAAI,gBAAgB;AACjC,UAAM,QAAQ,WAAW,MAAM,KAAK,MAAM,GAAG,KAAK,SAAS;AAE3D,QAAI;AACF,YAAM,MAAM,MAAM,KAAK,UAAU,cAAc,KAAK,SAAS,IAAI,GAAG;AAAA,QAClE;AAAA,QACA,SAAS;AAAA,UACP,gBAAgB;AAAA,UAChB,aAAa,KAAK;AAAA,QACpB;AAAA,QACA,MAAM,SAAS,SAAY,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"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { ThrottleError, type ThrottleErrorArgs } from '@usethrottle/errors';\n\n/**\n * `'embedded'` completes a card payment taken by the payment embed; `'net30'`\n * issues an invoice on terms. `'card'` names the card category in\n * `allowedMethods` — `completeSession` rejects it with 422\n * `payment_method_not_supported`. Use `'embedded'`.\n */\nexport type PaymentMethod = 'net30' | 'card' | 'embedded';\nexport type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'custom';\nexport type SubscriptionIntervalUnit = 'hour' | 'day' | 'week' | 'month';\nexport type CheckoutEmbedMode = 'checkout-full' | 'payment-only';\nexport type CheckoutEmbedRoute = 'c' | 's';\n\nexport interface CheckoutClientOptions {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof globalThis.fetch;\n timeoutMs?: number;\n}\n\nexport interface CheckoutAddress {\n firstName: string;\n lastName: string;\n company?: string;\n addressLine1: string;\n addressLine2?: string;\n city: string;\n stateProvince: string;\n postalCode: string;\n countryCode: string;\n phone?: string;\n}\n\nexport interface CheckoutCustomerAddressInput {\n firstName?: string;\n lastName?: string;\n phone?: string;\n addressLine1?: string;\n addressLine2?: string;\n city?: string;\n state?: string;\n postalCode?: string;\n country?: string;\n}\n\nexport interface CheckoutCustomerInput {\n customerId?: string;\n externalCustomerId?: string;\n email?: string;\n firstName?: string;\n lastName?: string;\n phone?: string;\n shippingAddress?: CheckoutCustomerAddressInput;\n billingAddress?: CheckoutCustomerAddressInput;\n metadata?: Record<string, unknown>;\n}\n\nexport interface RecurringIntentInput {\n plan: string;\n /** A named interval. Or send intervalUnit + intervalCount for any cadence from 1 hour to 1 year. */\n interval?: SubscriptionInterval;\n intervalUnit?: SubscriptionIntervalUnit;\n intervalCount?: number;\n /** Makes the subscription an installment plan of exactly this many payments (2–60). Not combinable with trialDays. */\n totalPayments?: number;\n amount?: number;\n trialDays?: number;\n planName?: string;\n create?: 'auto' | 'manual';\n}\n\nexport interface CheckoutCollectInput {\n shippingAddress?: boolean;\n billingAddress?: boolean;\n}\n\nexport interface CheckoutPaymentTermsInput {\n netN?: number | null;\n}\n\nexport interface CreateCheckoutSessionInput {\n applicationId: string;\n cartId?: string;\n externalCartId?: string;\n customerEmail?: string;\n customer?: CheckoutCustomerInput;\n returnUrl: string;\n cancelUrl: string;\n allowedMethods?: string[];\n paymentTerms?: CheckoutPaymentTermsInput;\n recurring?: RecurringIntentInput;\n collect?: CheckoutCollectInput;\n metadata?: Record<string, unknown>;\n discountCode?: string;\n}\n\nexport interface CheckoutSession {\n sessionId: string;\n id?: string;\n checkoutUrl?: string;\n hostedUrl?: string;\n embedUrl?: string;\n embedToken?: string;\n expiresAt?: string;\n [key: string]: unknown;\n}\n\nexport type CheckoutSessionStatus =\n | 'open'\n | 'customer_set'\n | 'address_set'\n | 'processing'\n | 'completed'\n | 'expired'\n | 'cancelled';\n\n/** A session as read back by `getSession` — the create response plus its current state. */\nexport interface CheckoutSessionDetails extends CheckoutSession {\n status: CheckoutSessionStatus;\n cartId?: string | null;\n customerId?: string | null;\n customerEmail?: string | null;\n shippingAddress?: CheckoutAddress | null;\n billingAddress?: CheckoutAddress | null;\n returnUrl?: string;\n cancelUrl?: string;\n completedAt?: string | null;\n allowedMethods?: string[] | null;\n collectShipping?: boolean;\n collectBilling?: boolean;\n discountCode?: string | null;\n metadata?: Record<string, unknown>;\n}\n\nexport interface Net30Acceptance {\n termsHash: string;\n acceptedAt: string;\n companyName: string;\n billingEmail: string;\n}\n\nexport interface CompleteCheckoutSessionInput {\n email?: string;\n shippingAddress?: CheckoutAddress;\n billingAddress?: CheckoutAddress;\n billingSameAsShipping?: boolean;\n paymentMethod: PaymentMethod;\n netDays?: number;\n termsAccepted?: boolean;\n termsSnapshot?: string;\n invoiceNumber?: string;\n net30Acceptance?: Net30Acceptance;\n paymentToken?: string;\n processorCheckoutSessionId?: string;\n processorTransactionId?: string;\n}\n\nexport interface CompleteCheckoutSessionResult {\n orderId: string;\n orderNumber?: string;\n paymentId?: string;\n total?: number;\n currency?: string;\n status?: string;\n paymentStatus?: string;\n [key: string]: unknown;\n}\n\n/**\n * The card needs a 3-D Secure challenge the buyer has to answer.\n *\n * Only the server-authorized card path (`processorCheckoutSessionId` with no\n * `processorTransactionId`) can produce this. The payment is neither completed\n * nor declined, so there is deliberately no `orderId` and no `paymentId`: put\n * the challenge in front of the buyer, then call `completeSession` again with\n * the same input.\n */\nexport interface CompleteCheckoutSessionRequiresAction {\n status: 'requires_action';\n orderId?: undefined;\n paymentStatus?: string;\n [key: string]: unknown;\n}\n\n/**\n * Narrow on `status === 'requires_action'` before reading `orderId`.\n * `isRequiresAction(result)` does that for you.\n */\nexport type CompleteCheckoutSessionOutcome =\n | CompleteCheckoutSessionResult\n | CompleteCheckoutSessionRequiresAction;\n\nexport function isRequiresAction(\n outcome: CompleteCheckoutSessionOutcome,\n): outcome is CompleteCheckoutSessionRequiresAction {\n return outcome.status === 'requires_action';\n}\n\nexport interface CreateEmbedTokenInput {\n externalCartId?: string;\n amount: number;\n currency: string;\n country?: string;\n // NOTE: `allowedMethods` is intentionally NOT accepted here. A payment-only\n // Gr4vy embed cannot restrict payment methods (the Gr4vy widget renders the\n // methods configured on your Gr4vy connection). The server rejects it with\n // `allowed_methods_unsupported`. To restrict methods, configure the connection\n // or use the full hosted checkout, where allowedMethods filters the selection.\n}\n\nexport interface CreateEmbedTokenResult {\n embedToken: string;\n checkoutSessionId: string;\n amount: number;\n currency: string;\n hostedUrl?: string;\n embedUrl?: string;\n processorInstanceId?: string;\n merchantAccountId?: string;\n [key: string]: unknown;\n}\n\nexport interface CheckoutOrder {\n id: string;\n orderNumber?: string;\n status: string;\n paymentStatus: string | null;\n currency: string;\n subtotal: number;\n taxTotal: number;\n shippingTotal: number;\n total: number;\n metadata?: Record<string, unknown>;\n payments?: CheckoutPayment[];\n [key: string]: unknown;\n}\n\nexport interface ListOrdersOptions {\n customerId?: string;\n cursor?: string;\n limit?: number;\n status?: string;\n paymentStatus?: string;\n}\n\nexport interface PaginatedOrders {\n data: CheckoutOrder[];\n pagination?: {\n cursor: string | null;\n hasMore: boolean;\n };\n}\n\nexport interface CheckoutPayment {\n id: string;\n orderId?: string;\n processor?: string;\n processorTransactionId?: string | null;\n amount?: number;\n currency?: string;\n status?: string;\n method?: string;\n createdAt?: string;\n transactions?: CheckoutPaymentTransaction[];\n [key: string]: unknown;\n}\n\nexport interface CheckoutPaymentTransaction {\n id: string;\n paymentId?: string;\n type?: string;\n amount?: number;\n currency?: string;\n status?: string;\n createdAt?: string;\n [key: string]: unknown;\n}\n\nexport interface BuildCheckoutUrlOptions {\n checkoutOrigin?: string;\n sessionId: string;\n parentOrigin?: string;\n mode?: CheckoutEmbedMode;\n route?: CheckoutEmbedRoute;\n primary?: string;\n logo?: string;\n}\n\nexport interface ThrottleEnvelope<T> {\n data?: T;\n meta?: Record<string, unknown>;\n error?: {\n code?: string;\n message?: string;\n details?: unknown;\n };\n}\n\n/**\n * Thrown on a non-2xx response from the Throttle Checkout API.\n *\n * Extends the shared {@link ThrottleError} so a single\n * `catch (e) { if (e instanceof ThrottleError) … }` covers errors from every\n * Throttle SDK. `instanceof ThrottleCheckoutError` keeps working for existing\n * code.\n */\nexport class ThrottleCheckoutError extends ThrottleError {\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n body?: unknown;\n responseHeaders?: ThrottleErrorArgs['responseHeaders'];\n }) {\n super(args);\n this.name = 'ThrottleCheckoutError';\n }\n}\n\nexport { ThrottleError, isThrottleError } from '@usethrottle/errors';\n\nexport class CheckoutClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly timeoutMs: number;\n\n constructor(opts: CheckoutClientOptions) {\n if (!opts.apiKey) throw new Error('CheckoutClient: apiKey is required');\n const fetchImpl = opts.fetch ?? globalThis.fetch;\n if (!fetchImpl) throw new Error('CheckoutClient: fetch is required');\n this.apiKey = opts.apiKey;\n this.baseUrl = (opts.baseUrl ?? 'https://api.usethrottle.dev').replace(/\\/+$/, '');\n this.fetchImpl = fetchImpl;\n this.timeoutMs = opts.timeoutMs ?? 30_000;\n }\n\n async request<T = unknown>(method: string, path: string, body?: unknown): Promise<T> {\n const envelope = await this.requestEnvelope<T>(method, path, body);\n if (Object.prototype.hasOwnProperty.call(envelope, 'data')) {\n return envelope.data as T;\n }\n return envelope as T;\n }\n\n async requestEnvelope<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<ThrottleEnvelope<T>> {\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);\n\n try {\n const res = await this.fetchImpl(toAbsoluteUrl(this.baseUrl, path), {\n method,\n headers: {\n 'content-type': 'application/json',\n 'x-api-key': this.apiKey,\n },\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal: ctrl.signal,\n });\n\n if (res.status === 204) return { data: undefined as T };\n\n const json = (await res.json().catch(() => ({}))) as ThrottleEnvelope<T>;\n if (!res.ok) {\n throw new ThrottleCheckoutError({\n code: json.error?.code ?? 'unknown_error',\n message: json.error?.message ?? `HTTP ${res.status}`,\n statusCode: res.status,\n details: json.error?.details,\n body: json,\n responseHeaders: res.headers,\n });\n }\n return json;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async createSession(input: CreateCheckoutSessionInput): Promise<CheckoutSession> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout/sessions', input);\n return normalizeCheckoutSession(data);\n }\n\n /**\n * Returns either a completion or `{status: 'requires_action'}` when the card\n * needs a 3-D Secure challenge — narrow with `isRequiresAction()` before\n * reading `orderId`.\n */\n async completeSession(\n sessionId: string,\n input: CompleteCheckoutSessionInput,\n ): Promise<CompleteCheckoutSessionOutcome> {\n const data = await this.request<unknown>(\n 'POST',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}/complete`,\n input,\n );\n return normalizeCompleteResult(data);\n }\n\n /**\n * Read a checkout session's current state — `status` tells you whether the\n * buyer is still in it (`open`, `processing`) or it has settled (`completed`,\n * `cancelled`, `expired`). Use it to decide whether a session can be resumed\n * or cancelled instead of tracking that yourself.\n */\n async getSession(sessionId: string): Promise<CheckoutSessionDetails> {\n const data = await this.request<any>(\n 'GET',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}`,\n );\n return {\n ...normalizeCheckoutSession(data),\n status: requiredString(data?.status, 'checkoutSession.status') as CheckoutSessionStatus,\n };\n }\n\n /**\n * Cancel an in-flight checkout session (e.g. the buyer abandoned the embed).\n * Idempotent — cancelling an already-cancelled session is a no-op; a completed\n * session cannot be cancelled (the API returns 422 `already_completed`).\n */\n async cancelSession(sessionId: string): Promise<void> {\n await this.request<unknown>(\n 'DELETE',\n `/api/v1/checkout/sessions/${encodeURIComponent(sessionId)}`,\n );\n }\n\n async createEmbedToken(input: CreateEmbedTokenInput): Promise<CreateEmbedTokenResult> {\n const data = await this.request<unknown>('POST', '/api/v1/checkout-sessions/embed-token', input);\n return normalizeEmbedToken(data);\n }\n\n async getOrder(orderId: string): Promise<CheckoutOrder> {\n const data = await this.request<unknown>('GET', `/api/v1/orders/${encodeURIComponent(orderId)}`);\n return normalizeOrder(data);\n }\n\n async listOrders(options: ListOrdersOptions = {}): Promise<PaginatedOrders> {\n const params = new URLSearchParams();\n if (options.customerId) params.set('customerId', options.customerId);\n if (options.cursor) params.set('cursor', options.cursor);\n if (options.limit !== undefined) params.set('limit', String(options.limit));\n if (options.status) params.set('status', options.status);\n if (options.paymentStatus) params.set('paymentStatus', options.paymentStatus);\n\n const query = params.toString();\n const envelope = await this.requestEnvelope<unknown[]>(\n 'GET',\n `/api/v1/orders${query ? `?${query}` : ''}`,\n );\n return {\n data: (envelope.data ?? []).map(normalizeOrder),\n pagination: envelope.meta?.pagination as PaginatedOrders['pagination'],\n };\n }\n\n async listOrderPayments(orderId: string): Promise<CheckoutPayment[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/orders/${encodeURIComponent(orderId)}/payments`,\n );\n return (data ?? []).map(normalizePayment);\n }\n\n async listPaymentTransactions(paymentId: string): Promise<CheckoutPaymentTransaction[]> {\n const data = await this.request<unknown[]>(\n 'GET',\n `/api/v1/payments/${encodeURIComponent(paymentId)}/transactions`,\n );\n return (data ?? []).map(normalizeTransaction);\n }\n\n async getOrderWithPayments(orderId: string): Promise<CheckoutOrder> {\n const order = await this.getOrder(orderId);\n const payments = await this.listOrderPayments(orderId);\n return {\n ...order,\n payments: await Promise.all(\n payments.map(async (payment) => ({\n ...payment,\n transactions: payment.id ? await this.listPaymentTransactions(payment.id) : [],\n })),\n ),\n };\n }\n}\n\nexport function createCheckoutClient(opts: CheckoutClientOptions): CheckoutClient {\n return new CheckoutClient(opts);\n}\n\nexport function buildCheckoutHostedUrl(options: BuildCheckoutUrlOptions): string {\n const route = options.route ?? 's';\n const base = (options.checkoutOrigin ?? 'https://checkout.usethrottle.dev').replace(/\\/+$/, '');\n return `${base}/${route}/${encodeURIComponent(options.sessionId)}`;\n}\n\nexport function buildCheckoutEmbedUrl(options: BuildCheckoutUrlOptions): string {\n const baseUrl = buildCheckoutHostedUrl({\n checkoutOrigin: options.checkoutOrigin,\n sessionId: options.sessionId,\n route: options.route ?? 'c',\n });\n const params = new URLSearchParams({\n embed: '1',\n mode: options.mode ?? 'payment-only',\n ...(options.parentOrigin ? { parentOrigin: options.parentOrigin.replace(/\\/+$/, '') } : {}),\n });\n if (options.primary) params.set('primary', options.primary);\n if (options.logo) params.set('logo', options.logo);\n return `${baseUrl}?${params.toString()}`;\n}\n\nfunction toAbsoluteUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl}${path.startsWith('/') ? path : `/${path}`}`;\n}\n\nfunction normalizeCheckoutSession(raw: any): CheckoutSession {\n const sessionId = raw?.sessionId ?? raw?.id;\n return {\n ...withoutSnakeKeys(raw),\n id: optionalString(raw?.id) ?? undefined,\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl) ?? undefined,\n hostedUrl: optionalString(raw?.hostedUrl) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl) ?? undefined,\n embedToken: optionalString(raw?.embedToken) ?? undefined,\n expiresAt: optionalString(raw?.expiresAt) ?? undefined,\n };\n}\n\nfunction normalizeCompleteResult(raw: any): CompleteCheckoutSessionOutcome {\n // A 3-D Secure challenge is a 200, not an error, and carries no order — so\n // `requiredString(orderId)` below would throw a local parse error at exactly\n // the moment the caller needs to show the buyer a challenge.\n if (raw?.status === 'requires_action') {\n return {\n ...withoutSnakeKeys(raw),\n status: 'requires_action',\n paymentStatus: optionalString(raw?.paymentStatus) ?? undefined,\n };\n }\n const orderId = raw?.orderId ?? raw?.id;\n return {\n ...withoutSnakeKeys(raw),\n orderId: requiredString(orderId, 'checkoutComplete.orderId'),\n orderNumber: optionalString(raw?.orderNumber) ?? undefined,\n paymentId: optionalString(raw?.paymentId) ?? undefined,\n total: optionalNumber(raw?.total),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n paymentStatus: optionalString(raw?.paymentStatus) ?? undefined,\n };\n}\n\nfunction normalizeEmbedToken(raw: any): CreateEmbedTokenResult {\n return {\n ...withoutSnakeKeys(raw),\n embedToken: requiredString(raw?.embedToken, 'embedToken.embedToken'),\n checkoutSessionId: requiredString(raw?.checkoutSessionId, 'embedToken.checkoutSessionId'),\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n hostedUrl: optionalString(raw?.hostedUrl) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl) ?? undefined,\n processorInstanceId: optionalString(raw?.processorInstanceId) ?? undefined,\n merchantAccountId: optionalString(raw?.merchantAccountId) ?? undefined,\n };\n}\n\nfunction normalizeOrder(raw: any): CheckoutOrder {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'order.id'),\n orderNumber: optionalString(raw?.orderNumber) ?? undefined,\n status: optionalString(raw?.status) ?? 'processing',\n paymentStatus: optionalString(raw?.paymentStatus),\n currency: optionalString(raw?.currency) ?? 'USD',\n subtotal: Number(raw?.subtotal ?? 0),\n taxTotal: Number(raw?.taxTotal ?? 0),\n shippingTotal: Number(raw?.shippingTotal ?? 0),\n total: Number(raw?.total ?? 0),\n metadata: objectOrUndefined(raw?.metadata),\n payments: Array.isArray(raw?.payments) ? raw.payments.map(normalizePayment) : undefined,\n };\n}\n\nfunction normalizePayment(raw: any): CheckoutPayment {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'payment.id'),\n orderId: optionalString(raw?.orderId) ?? undefined,\n processor: optionalString(raw?.processor) ?? undefined,\n processorTransactionId:\n optionalString(raw?.processorTransactionId) ?? undefined,\n amount: optionalNumber(raw?.amount),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n method: optionalString(raw?.method) ?? undefined,\n createdAt: optionalString(raw?.createdAt) ?? undefined,\n transactions: Array.isArray(raw?.transactions)\n ? raw.transactions.map(normalizeTransaction)\n : undefined,\n };\n}\n\nfunction normalizeTransaction(raw: any): CheckoutPaymentTransaction {\n return {\n ...withoutSnakeKeys(raw),\n id: requiredString(raw?.id, 'transaction.id'),\n paymentId: optionalString(raw?.paymentId) ?? undefined,\n type: optionalString(raw?.type) ?? undefined,\n amount: optionalNumber(raw?.amount),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n createdAt: optionalString(raw?.createdAt) ?? undefined,\n };\n}\n\nfunction withoutSnakeKeys(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return {};\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).filter(([key]) => !key.includes('_')),\n );\n}\n\nfunction requiredString(value: unknown, label: string): string {\n if (typeof value === 'string' && value.length > 0) return value;\n throw new Error(`Invalid Throttle response: missing ${label}`);\n}\n\nfunction optionalString(value: unknown): string | null {\n return typeof value === 'string' && value.length > 0 ? value : null;\n}\n\nfunction optionalNumber(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n}\n\nfunction objectOrUndefined(value: unknown): Record<string, unknown> | undefined {\n return value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n"],"mappings":";AAAA,SAAS,qBAA6C;AAiUtD,SAAS,iBAAAA,gBAAe,uBAAuB;AAhIxC,SAAS,iBACd,SACkD;AAClD,SAAO,QAAQ,WAAW;AAC5B;AA8GO,IAAM,wBAAN,cAAoC,cAAc;AAAA,EACvD,YAAY,MAOT;AACD,UAAM,IAAI;AACV,SAAK,OAAO;AAAA,EACd;AACF;AAIO,IAAM,iBAAN,MAAqB;AAAA,EAM1B,YAAY,MAA6B;AACvC,QAAI,CAAC,KAAK,OAAQ,OAAM,IAAI,MAAM,oCAAoC;AACtE,UAAM,YAAY,KAAK,SAAS,WAAW;AAC3C,QAAI,CAAC,UAAW,OAAM,IAAI,MAAM,mCAAmC;AACnE,SAAK,SAAS,KAAK;AACnB,SAAK,WAAW,KAAK,WAAW,+BAA+B,QAAQ,QAAQ,EAAE;AACjF,SAAK,YAAY;AACjB,SAAK,YAAY,KAAK,aAAa;AAAA,EACrC;AAAA,EAEA,MAAM,QAAqB,QAAgB,MAAc,MAA4B;AACnF,UAAM,WAAW,MAAM,KAAK,gBAAmB,QAAQ,MAAM,IAAI;AACjE,QAAI,OAAO,UAAU,eAAe,KAAK,UAAU,MAAM,GAAG;AAC1D,aAAO,SAAS;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,gBACJ,QACA,MACA,MAC8B;AAC9B,UAAM,OAAO,IAAI,gBAAgB;AACjC,UAAM,QAAQ,WAAW,MAAM,KAAK,MAAM,GAAG,KAAK,SAAS;AAE3D,QAAI;AACF,YAAM,MAAM,MAAM,KAAK,UAAU,cAAc,KAAK,SAAS,IAAI,GAAG;AAAA,QAClE;AAAA,QACA,SAAS;AAAA,UACP,gBAA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AO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AACjE;AAEA,SAAS,eAAe,OAAoC;AAC1D,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;AAEA,SAAS,kBAAkB,OAAqD;AAC9E,SAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAC5D,QACD;AACN;","names":["ThrottleError"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/checkout-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"react-dom": ">=18 <20"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@usethrottle/errors": "^1.
|
|
31
|
-
"@usethrottle/checkout-react": "
|
|
30
|
+
"@usethrottle/errors": "^1.1.0",
|
|
31
|
+
"@usethrottle/checkout-react": "2.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@testing-library/react": "^16.0.0",
|