@usethrottle/checkout-sdk 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @usethrottle/checkout-sdk
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add cart-level Net-N invoice terms. Carts now accept nullable `netN`, checkout
8
+ sessions can stamp cart terms with `paymentTerms.netN`, and invoice resolution
9
+ uses `customer.netN ?? cart.netN ?? DEFAULT_NET_N`.
10
+
11
+ ## 1.0.2
12
+
13
+ ### Patch Changes
14
+
15
+ - Expose customer Net-N payment terms in the generated API client and republish the public SDK package set.
16
+ - Updated dependencies
17
+ - @usethrottle/checkout-react@1.0.1
18
+
3
19
  ## 1.0.1
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # @usethrottle/checkout-sdk
2
2
 
3
- Throttle Checkout SDK Phase 1.
3
+ Production checkout SDK for Throttle storefront integrations.
4
4
 
5
- Wraps `@usethrottle/checkout-react` with idempotency, telemetry, and brand theming.
5
+ Use the server entrypoint from backend routes to create sessions, mint embed tokens,
6
+ and read orders/payments. Use the React wrapper in the browser when you want
7
+ idempotent terminal callbacks, telemetry, and brand theming on top of
8
+ `@usethrottle/checkout-react`.
6
9
 
7
10
  ## Install
8
11
 
@@ -21,7 +24,7 @@ import { ThrottleCheckout } from '@usethrottle/checkout-sdk';
21
24
  theme={{ primary: '#ff6600', logo: 'https://shop.example.com/logo.png' }}
22
25
  onSucceeded={({ orderId }) => router.push(`/orders/${orderId}`)}
23
26
  onTelemetry={(event) => analytics.track(event.type, event)}
24
- />
27
+ />;
25
28
  ```
26
29
 
27
30
  ## Server quickstart
@@ -46,6 +49,8 @@ const session = await checkout.createSession({
46
49
  cartId: 'cart_123',
47
50
  returnUrl: 'https://shop.example.com/checkout/success',
48
51
  cancelUrl: 'https://shop.example.com/cart',
52
+ allowedMethods: ['net30'],
53
+ paymentTerms: { netN: 45 },
49
54
  collect: { shippingAddress: true, billingAddress: false },
50
55
  });
51
56
 
@@ -64,40 +69,54 @@ const hostedUrl = buildCheckoutHostedUrl({
64
69
 
65
70
  ### Server methods
66
71
 
67
- | Method | Endpoint | Description |
68
- |------|----------|-------------|
69
- | `createSession(input)` | `POST /api/v1/checkout/sessions` | Creates a cart-backed hosted/embed checkout session. |
70
- | `completeSession(id, input)` | `POST /api/v1/checkout/sessions/:id/complete` | Completes a checkout session from server-side proxy mode. |
71
- | `createEmbedToken(input)` | `POST /api/v1/checkout-sessions/embed-token` | Mints a Gr4vy Embed token for proxy-mode card capture. |
72
- | `getOrder(id)` | `GET /api/v1/orders/:id` | Reads public-safe order totals/status. |
73
- | `listOrderPayments(id)` | `GET /api/v1/orders/:id/payments` | Lists payments for an order. |
74
- | `listPaymentTransactions(id)` | `GET /api/v1/payments/:id/transactions` | Lists transactions for a payment. |
75
- | `getOrderWithPayments(id)` | Combined reads | Fetches an order, payments, and transactions together. |
72
+ | Method | Endpoint | Description |
73
+ | ----------------------------- | --------------------------------------------- | --------------------------------------------------------- |
74
+ | `createSession(input)` | `POST /api/v1/checkout/sessions` | Creates a cart-backed hosted/embed checkout session. |
75
+ | `completeSession(id, input)` | `POST /api/v1/checkout/sessions/:id/complete` | Completes a checkout session from server-side proxy mode. |
76
+ | `createEmbedToken(input)` | `POST /api/v1/checkout-sessions/embed-token` | Mints a Gr4vy Embed token for proxy-mode card capture. |
77
+ | `getOrder(id)` | `GET /api/v1/orders/:id` | Reads public-safe order totals/status. |
78
+ | `listOrderPayments(id)` | `GET /api/v1/orders/:id/payments` | Lists payments for an order. |
79
+ | `listPaymentTransactions(id)` | `GET /api/v1/payments/:id/transactions` | Lists transactions for a payment. |
80
+ | `getOrderWithPayments(id)` | Combined reads | Fetches an order, payments, and transactions together. |
81
+
82
+ ### Net-N invoice terms
83
+
84
+ Use `paymentTerms.netN` when creating a checkout session to stamp a cart-level
85
+ Invoice Terms override. Customer-level `netN` still wins when the attached
86
+ customer has an override; otherwise checkout falls back to the cart override and
87
+ then `DEFAULT_NET_N`.
88
+
89
+ ```text
90
+ customer.netN ?? cart.netN ?? DEFAULT_NET_N
91
+ ```
92
+
93
+ `allowedMethods` remains only a method filter, for example `['net30']`; the
94
+ Net-N day count belongs in `paymentTerms.netN`.
76
95
 
77
96
  ## Props
78
97
 
79
- | Prop | Type | Required | Description |
80
- |------|------|----------|-------------|
81
- | `sessionId` | `string` | Yes | Throttle checkout session id (`cs_*`) |
82
- | `parentOrigin` | `string` | No | Origin of the page mounting the embed |
83
- | `baseUrl` | `string` | No | Override the hosted checkout URL (default: `https://throttle-checkout.vercel.app`) |
84
- | `theme` | `BrandTheme` | No | Brand colour + logo forwarded to hosted page |
85
- | `onSucceeded` | `(args) => void` | No | Called once on successful payment |
86
- | `onFailed` | `(args) => void` | No | Called once on terminal payment failure |
87
- | `onCancelled` | `() => void` | No | Called when the user cancels |
88
- | `onTelemetry` | `(event) => void` | No | Receives every lifecycle event |
98
+ | Prop | Type | Required | Description |
99
+ | -------------- | ----------------- | -------- | ------------------------------------------------------------------------------ |
100
+ | `sessionId` | `string` | Yes | Throttle checkout session id (`cs_*`) |
101
+ | `parentOrigin` | `string` | No | Origin of the page mounting the embed |
102
+ | `baseUrl` | `string` | No | Override the hosted checkout URL (default: `https://checkout.usethrottle.dev`) |
103
+ | `theme` | `BrandTheme` | No | Brand colour + logo forwarded to hosted page |
104
+ | `onSucceeded` | `(args) => void` | No | Called once on successful payment |
105
+ | `onFailed` | `(args) => void` | No | Called once on terminal payment failure |
106
+ | `onCancelled` | `() => void` | No | Called when the user cancels |
107
+ | `onTelemetry` | `(event) => void` | No | Receives every lifecycle event |
89
108
 
90
109
  ## Telemetry events
91
110
 
92
- | `event.type` | Additional payload | Description |
93
- |---|---|---|
94
- | `mounted` | `sessionId`, `timestamp` | Component mounted in the DOM |
95
- | `ready` | `sessionId`, `timestamp` | Hosted iframe fully loaded |
96
- | `processing` | `sessionId`, `timestamp` | Payment authorization in-flight |
97
- | `succeeded` | `sessionId`, `orderId`, `paymentId`, `timestamp` | Payment completed successfully |
98
- | `failed` | `sessionId`, `code`, `message`, `timestamp` | Terminal payment failure |
99
- | `cancelled` | `sessionId`, `timestamp` | User cancelled checkout |
100
- | `step_changed` | `sessionId`, `step`, `timestamp` | Checkout step navigation (full embed only) |
111
+ | `event.type` | Additional payload | Description |
112
+ | -------------- | ------------------------------------------------ | ------------------------------------------ |
113
+ | `mounted` | `sessionId`, `timestamp` | Component mounted in the DOM |
114
+ | `ready` | `sessionId`, `timestamp` | Hosted iframe fully loaded |
115
+ | `processing` | `sessionId`, `timestamp` | Payment authorization in-flight |
116
+ | `succeeded` | `sessionId`, `orderId`, `paymentId`, `timestamp` | Payment completed successfully |
117
+ | `failed` | `sessionId`, `code`, `message`, `timestamp` | Terminal payment failure |
118
+ | `cancelled` | `sessionId`, `timestamp` | User cancelled checkout |
119
+ | `step_changed` | `sessionId`, `step`, `timestamp` | Checkout step navigation (full embed only) |
101
120
 
102
121
  ## Idempotency
103
122
 
@@ -113,4 +132,5 @@ const hostedUrl = buildCheckoutHostedUrl({
113
132
  pnpm --filter @usethrottle/checkout-sdk build
114
133
  ```
115
134
 
116
- Emits CJS (`dist/index.cjs`), ESM (`dist/index.js`), and TypeScript declarations (`dist/index.d.ts`).
135
+ Emits CJS, ESM, and TypeScript declarations for both the browser entrypoint and
136
+ `@usethrottle/checkout-sdk/server`.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/ThrottleCheckout.tsx"],"sourcesContent":["export { ThrottleCheckout } from './ThrottleCheckout.js';\nexport type { BrandTheme, TelemetryEvent, ThrottleCheckoutProps } from './types.js';\n","import { useCallback, useEffect, useRef } from 'react';\nimport { PaymentEmbed } from '@usethrottle/checkout-react';\nimport type { ThrottleCheckoutProps, TelemetryEvent } from './types.js';\n\n/**\n * ThrottleCheckout — Phase 1 platform SDK wrapper.\n *\n * Wraps `<PaymentEmbed>` from `@usethrottle/checkout-react` and adds:\n * 1. Idempotency — settledRef ensures `onSucceeded` / `onFailed` fire at most once\n * per component lifetime, even if the iframe sends duplicate events.\n * 2. Telemetry — `onTelemetry` callback receives every lifecycle event with a\n * typed payload so merchants can pipe to Datadog / Segment / etc.\n * 3. Brand theming — `theme.primary` + `theme.logo` are forwarded to the underlying\n * `<PaymentEmbed>` which appends them as URL query params on the\n * hosted checkout iframe src.\n */\nexport function ThrottleCheckout({\n sessionId,\n parentOrigin = '',\n baseUrl,\n theme,\n onSucceeded,\n onFailed,\n onCancelled,\n onTelemetry,\n}: ThrottleCheckoutProps): JSX.Element {\n // Idempotency guard — once a terminal event (success or failure) fires,\n // all subsequent duplicate events from the iframe are silently dropped.\n const settledRef = useRef(false);\n\n const emit = useCallback(\n (event: TelemetryEvent) => {\n onTelemetry?.(event);\n },\n [onTelemetry],\n );\n\n // Fire \"mounted\" telemetry once on initial render.\n useEffect(() => {\n emit({ type: 'mounted', sessionId, timestamp: Date.now() });\n // intentionally only on mount — sessionId identity change re-mounts anyway\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleReady = useCallback(() => {\n emit({ type: 'ready', sessionId, timestamp: Date.now() });\n }, [emit, sessionId]);\n\n const handleProcessing = useCallback(() => {\n emit({ type: 'processing', sessionId, timestamp: Date.now() });\n }, [emit, sessionId]);\n\n const handleSucceeded = useCallback(\n ({ orderId, paymentId }: { orderId: string; paymentId: string }) => {\n if (settledRef.current) return;\n settledRef.current = true;\n emit({ type: 'succeeded', sessionId, orderId, paymentId, timestamp: Date.now() });\n onSucceeded?.({ orderId, paymentId });\n },\n [emit, sessionId, onSucceeded],\n );\n\n const handleFailed = useCallback(\n ({ code, message }: { code: string; message: string }) => {\n if (settledRef.current) return;\n settledRef.current = true;\n emit({ type: 'failed', sessionId, code, message, timestamp: Date.now() });\n onFailed?.({ code, message });\n },\n [emit, sessionId, onFailed],\n );\n\n const handleCanceled = useCallback(() => {\n emit({ type: 'cancelled', sessionId, timestamp: Date.now() });\n onCancelled?.();\n }, [emit, sessionId, onCancelled]);\n\n return (\n <PaymentEmbed\n sessionId={sessionId}\n parentOrigin={parentOrigin}\n {...(baseUrl !== undefined ? { baseUrl } : {})}\n primary={theme?.primary}\n logo={theme?.logo}\n onReady={handleReady}\n onProcessing={handleProcessing}\n onSucceeded={handleSucceeded}\n onFailed={handleFailed}\n onCanceled={handleCanceled}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA+C;AAC/C,4BAA6B;AA6EzB;AA9DG,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AAGrC,QAAM,iBAAa,qBAAO,KAAK;AAE/B,QAAM,WAAO;AAAA,IACX,CAAC,UAA0B;AACzB,oBAAc,KAAK;AAAA,IACrB;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAGA,8BAAU,MAAM;AACd,SAAK,EAAE,MAAM,WAAW,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAG5D,GAAG,CAAC,CAAC;AAEL,QAAM,kBAAc,0BAAY,MAAM;AACpC,SAAK,EAAE,MAAM,SAAS,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAC1D,GAAG,CAAC,MAAM,SAAS,CAAC;AAEpB,QAAM,uBAAmB,0BAAY,MAAM;AACzC,SAAK,EAAE,MAAM,cAAc,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAC/D,GAAG,CAAC,MAAM,SAAS,CAAC;AAEpB,QAAM,sBAAkB;AAAA,IACtB,CAAC,EAAE,SAAS,UAAU,MAA8C;AAClE,UAAI,WAAW,QAAS;AACxB,iBAAW,UAAU;AACrB,WAAK,EAAE,MAAM,aAAa,WAAW,SAAS,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAChF,oBAAc,EAAE,SAAS,UAAU,CAAC;AAAA,IACtC;AAAA,IACA,CAAC,MAAM,WAAW,WAAW;AAAA,EAC/B;AAEA,QAAM,mBAAe;AAAA,IACnB,CAAC,EAAE,MAAM,QAAQ,MAAyC;AACxD,UAAI,WAAW,QAAS;AACxB,iBAAW,UAAU;AACrB,WAAK,EAAE,MAAM,UAAU,WAAW,MAAM,SAAS,WAAW,KAAK,IAAI,EAAE,CAAC;AACxE,iBAAW,EAAE,MAAM,QAAQ,CAAC;AAAA,IAC9B;AAAA,IACA,CAAC,MAAM,WAAW,QAAQ;AAAA,EAC5B;AAEA,QAAM,qBAAiB,0BAAY,MAAM;AACvC,SAAK,EAAE,MAAM,aAAa,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAC5D,kBAAc;AAAA,EAChB,GAAG,CAAC,MAAM,WAAW,WAAW,CAAC;AAEjC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACC,GAAI,YAAY,SAAY,EAAE,QAAQ,IAAI,CAAC;AAAA,MAC5C,SAAS,OAAO;AAAA,MAChB,MAAM,OAAO;AAAA,MACb,SAAS;AAAA,MACT,cAAc;AAAA,MACd,aAAa;AAAA,MACb,UAAU;AAAA,MACV,YAAY;AAAA;AAAA,EACd;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/ThrottleCheckout.tsx"],"sourcesContent":["export { ThrottleCheckout } from './ThrottleCheckout.js';\nexport type { BrandTheme, TelemetryEvent, ThrottleCheckoutProps } from './types.js';\n","import { useCallback, useEffect, useRef } from 'react';\nimport { PaymentEmbed } from '@usethrottle/checkout-react';\nimport type { ThrottleCheckoutProps, TelemetryEvent } from './types.js';\n\n/**\n * ThrottleCheckout — Phase 1 platform SDK wrapper.\n *\n * Wraps `<PaymentEmbed>` from `@usethrottle/checkout-react` and adds:\n * 1. Idempotency — settledRef ensures `onSucceeded` / `onFailed` fire at most once\n * per component lifetime, even if the iframe sends duplicate events.\n * 2. Telemetry — `onTelemetry` callback receives every lifecycle event with a\n * typed payload so workspaces can pipe to Datadog / Segment / etc.\n * 3. Brand theming — `theme.primary` + `theme.logo` are forwarded to the underlying\n * `<PaymentEmbed>` which appends them as URL query params on the\n * hosted checkout iframe src.\n */\nexport function ThrottleCheckout({\n sessionId,\n parentOrigin = '',\n baseUrl,\n theme,\n onSucceeded,\n onFailed,\n onCancelled,\n onTelemetry,\n}: ThrottleCheckoutProps): JSX.Element {\n // Idempotency guard — once a terminal event (success or failure) fires,\n // all subsequent duplicate events from the iframe are silently dropped.\n const settledRef = useRef(false);\n\n const emit = useCallback(\n (event: TelemetryEvent) => {\n onTelemetry?.(event);\n },\n [onTelemetry],\n );\n\n // Fire \"mounted\" telemetry once on initial render.\n useEffect(() => {\n emit({ type: 'mounted', sessionId, timestamp: Date.now() });\n // intentionally only on mount — sessionId identity change re-mounts anyway\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleReady = useCallback(() => {\n emit({ type: 'ready', sessionId, timestamp: Date.now() });\n }, [emit, sessionId]);\n\n const handleProcessing = useCallback(() => {\n emit({ type: 'processing', sessionId, timestamp: Date.now() });\n }, [emit, sessionId]);\n\n const handleSucceeded = useCallback(\n ({ orderId, paymentId }: { orderId: string; paymentId: string }) => {\n if (settledRef.current) return;\n settledRef.current = true;\n emit({ type: 'succeeded', sessionId, orderId, paymentId, timestamp: Date.now() });\n onSucceeded?.({ orderId, paymentId });\n },\n [emit, sessionId, onSucceeded],\n );\n\n const handleFailed = useCallback(\n ({ code, message }: { code: string; message: string }) => {\n if (settledRef.current) return;\n settledRef.current = true;\n emit({ type: 'failed', sessionId, code, message, timestamp: Date.now() });\n onFailed?.({ code, message });\n },\n [emit, sessionId, onFailed],\n );\n\n const handleCanceled = useCallback(() => {\n emit({ type: 'cancelled', sessionId, timestamp: Date.now() });\n onCancelled?.();\n }, [emit, sessionId, onCancelled]);\n\n return (\n <PaymentEmbed\n sessionId={sessionId}\n parentOrigin={parentOrigin}\n {...(baseUrl !== undefined ? { baseUrl } : {})}\n primary={theme?.primary}\n logo={theme?.logo}\n onReady={handleReady}\n onProcessing={handleProcessing}\n onSucceeded={handleSucceeded}\n onFailed={handleFailed}\n onCanceled={handleCanceled}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA+C;AAC/C,4BAA6B;AA6EzB;AA9DG,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AAGrC,QAAM,iBAAa,qBAAO,KAAK;AAE/B,QAAM,WAAO;AAAA,IACX,CAAC,UAA0B;AACzB,oBAAc,KAAK;AAAA,IACrB;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAGA,8BAAU,MAAM;AACd,SAAK,EAAE,MAAM,WAAW,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAG5D,GAAG,CAAC,CAAC;AAEL,QAAM,kBAAc,0BAAY,MAAM;AACpC,SAAK,EAAE,MAAM,SAAS,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAC1D,GAAG,CAAC,MAAM,SAAS,CAAC;AAEpB,QAAM,uBAAmB,0BAAY,MAAM;AACzC,SAAK,EAAE,MAAM,cAAc,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAC/D,GAAG,CAAC,MAAM,SAAS,CAAC;AAEpB,QAAM,sBAAkB;AAAA,IACtB,CAAC,EAAE,SAAS,UAAU,MAA8C;AAClE,UAAI,WAAW,QAAS;AACxB,iBAAW,UAAU;AACrB,WAAK,EAAE,MAAM,aAAa,WAAW,SAAS,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAChF,oBAAc,EAAE,SAAS,UAAU,CAAC;AAAA,IACtC;AAAA,IACA,CAAC,MAAM,WAAW,WAAW;AAAA,EAC/B;AAEA,QAAM,mBAAe;AAAA,IACnB,CAAC,EAAE,MAAM,QAAQ,MAAyC;AACxD,UAAI,WAAW,QAAS;AACxB,iBAAW,UAAU;AACrB,WAAK,EAAE,MAAM,UAAU,WAAW,MAAM,SAAS,WAAW,KAAK,IAAI,EAAE,CAAC;AACxE,iBAAW,EAAE,MAAM,QAAQ,CAAC;AAAA,IAC9B;AAAA,IACA,CAAC,MAAM,WAAW,QAAQ;AAAA,EAC5B;AAEA,QAAM,qBAAiB,0BAAY,MAAM;AACvC,SAAK,EAAE,MAAM,aAAa,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAC5D,kBAAc;AAAA,EAChB,GAAG,CAAC,MAAM,WAAW,WAAW,CAAC;AAEjC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACC,GAAI,YAAY,SAAY,EAAE,QAAQ,IAAI,CAAC;AAAA,MAC5C,SAAS,OAAO;AAAA,MAChB,MAAM,OAAO;AAAA,MACb,SAAS;AAAA,MACT,cAAc;AAAA,MACd,aAAa;AAAA,MACb,UAAU;AAAA,MACV,YAAY;AAAA;AAAA,EACd;AAEJ;","names":[]}
package/dist/index.d.cts CHANGED
@@ -76,7 +76,7 @@ interface ThrottleCheckoutProps {
76
76
  * 1. Idempotency — settledRef ensures `onSucceeded` / `onFailed` fire at most once
77
77
  * per component lifetime, even if the iframe sends duplicate events.
78
78
  * 2. Telemetry — `onTelemetry` callback receives every lifecycle event with a
79
- * typed payload so merchants can pipe to Datadog / Segment / etc.
79
+ * typed payload so workspaces can pipe to Datadog / Segment / etc.
80
80
  * 3. Brand theming — `theme.primary` + `theme.logo` are forwarded to the underlying
81
81
  * `<PaymentEmbed>` which appends them as URL query params on the
82
82
  * hosted checkout iframe src.
package/dist/index.d.ts CHANGED
@@ -76,7 +76,7 @@ interface ThrottleCheckoutProps {
76
76
  * 1. Idempotency — settledRef ensures `onSucceeded` / `onFailed` fire at most once
77
77
  * per component lifetime, even if the iframe sends duplicate events.
78
78
  * 2. Telemetry — `onTelemetry` callback receives every lifecycle event with a
79
- * typed payload so merchants can pipe to Datadog / Segment / etc.
79
+ * typed payload so workspaces can pipe to Datadog / Segment / etc.
80
80
  * 3. Brand theming — `theme.primary` + `theme.logo` are forwarded to the underlying
81
81
  * `<PaymentEmbed>` which appends them as URL query params on the
82
82
  * hosted checkout iframe src.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ThrottleCheckout.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport { PaymentEmbed } from '@usethrottle/checkout-react';\nimport type { ThrottleCheckoutProps, TelemetryEvent } from './types.js';\n\n/**\n * ThrottleCheckout — Phase 1 platform SDK wrapper.\n *\n * Wraps `<PaymentEmbed>` from `@usethrottle/checkout-react` and adds:\n * 1. Idempotency — settledRef ensures `onSucceeded` / `onFailed` fire at most once\n * per component lifetime, even if the iframe sends duplicate events.\n * 2. Telemetry — `onTelemetry` callback receives every lifecycle event with a\n * typed payload so merchants can pipe to Datadog / Segment / etc.\n * 3. Brand theming — `theme.primary` + `theme.logo` are forwarded to the underlying\n * `<PaymentEmbed>` which appends them as URL query params on the\n * hosted checkout iframe src.\n */\nexport function ThrottleCheckout({\n sessionId,\n parentOrigin = '',\n baseUrl,\n theme,\n onSucceeded,\n onFailed,\n onCancelled,\n onTelemetry,\n}: ThrottleCheckoutProps): JSX.Element {\n // Idempotency guard — once a terminal event (success or failure) fires,\n // all subsequent duplicate events from the iframe are silently dropped.\n const settledRef = useRef(false);\n\n const emit = useCallback(\n (event: TelemetryEvent) => {\n onTelemetry?.(event);\n },\n [onTelemetry],\n );\n\n // Fire \"mounted\" telemetry once on initial render.\n useEffect(() => {\n emit({ type: 'mounted', sessionId, timestamp: Date.now() });\n // intentionally only on mount — sessionId identity change re-mounts anyway\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleReady = useCallback(() => {\n emit({ type: 'ready', sessionId, timestamp: Date.now() });\n }, [emit, sessionId]);\n\n const handleProcessing = useCallback(() => {\n emit({ type: 'processing', sessionId, timestamp: Date.now() });\n }, [emit, sessionId]);\n\n const handleSucceeded = useCallback(\n ({ orderId, paymentId }: { orderId: string; paymentId: string }) => {\n if (settledRef.current) return;\n settledRef.current = true;\n emit({ type: 'succeeded', sessionId, orderId, paymentId, timestamp: Date.now() });\n onSucceeded?.({ orderId, paymentId });\n },\n [emit, sessionId, onSucceeded],\n );\n\n const handleFailed = useCallback(\n ({ code, message }: { code: string; message: string }) => {\n if (settledRef.current) return;\n settledRef.current = true;\n emit({ type: 'failed', sessionId, code, message, timestamp: Date.now() });\n onFailed?.({ code, message });\n },\n [emit, sessionId, onFailed],\n );\n\n const handleCanceled = useCallback(() => {\n emit({ type: 'cancelled', sessionId, timestamp: Date.now() });\n onCancelled?.();\n }, [emit, sessionId, onCancelled]);\n\n return (\n <PaymentEmbed\n sessionId={sessionId}\n parentOrigin={parentOrigin}\n {...(baseUrl !== undefined ? { baseUrl } : {})}\n primary={theme?.primary}\n logo={theme?.logo}\n onReady={handleReady}\n onProcessing={handleProcessing}\n onSucceeded={handleSucceeded}\n onFailed={handleFailed}\n onCanceled={handleCanceled}\n />\n );\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,cAAc;AAC/C,SAAS,oBAAoB;AA6EzB;AA9DG,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AAGrC,QAAM,aAAa,OAAO,KAAK;AAE/B,QAAM,OAAO;AAAA,IACX,CAAC,UAA0B;AACzB,oBAAc,KAAK;AAAA,IACrB;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAGA,YAAU,MAAM;AACd,SAAK,EAAE,MAAM,WAAW,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAG5D,GAAG,CAAC,CAAC;AA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;AAAA,MACV,YAAY;AAAA;AAAA,EACd;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../src/ThrottleCheckout.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport { PaymentEmbed } from '@usethrottle/checkout-react';\nimport type { ThrottleCheckoutProps, TelemetryEvent } from './types.js';\n\n/**\n * ThrottleCheckout — Phase 1 platform SDK wrapper.\n *\n * Wraps `<PaymentEmbed>` from `@usethrottle/checkout-react` and adds:\n * 1. Idempotency — settledRef ensures `onSucceeded` / `onFailed` fire at most once\n * per component lifetime, even if the iframe sends duplicate events.\n * 2. Telemetry — `onTelemetry` callback receives every lifecycle event with a\n * typed payload so workspaces can pipe to Datadog / Segment / etc.\n * 3. Brand theming — `theme.primary` + `theme.logo` are forwarded to the underlying\n * `<PaymentEmbed>` which appends them as URL query params on the\n * hosted checkout iframe src.\n */\nexport function ThrottleCheckout({\n sessionId,\n parentOrigin = '',\n baseUrl,\n theme,\n onSucceeded,\n onFailed,\n onCancelled,\n onTelemetry,\n}: ThrottleCheckoutProps): JSX.Element {\n // Idempotency guard — once a terminal event (success or failure) fires,\n // all subsequent duplicate events from the iframe are silently dropped.\n const settledRef = useRef(false);\n\n const emit = useCallback(\n (event: TelemetryEvent) => {\n onTelemetry?.(event);\n },\n [onTelemetry],\n );\n\n // Fire \"mounted\" telemetry once on initial render.\n useEffect(() => {\n emit({ type: 'mounted', sessionId, timestamp: Date.now() });\n // intentionally only on mount — sessionId identity change re-mounts anyway\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleReady = useCallback(() => {\n emit({ type: 'ready', sessionId, timestamp: Date.now() });\n }, [emit, sessionId]);\n\n const handleProcessing = useCallback(() => {\n emit({ type: 'processing', sessionId, timestamp: Date.now() });\n }, [emit, sessionId]);\n\n const handleSucceeded = useCallback(\n ({ orderId, paymentId }: { orderId: string; paymentId: string }) => {\n if (settledRef.current) return;\n settledRef.current = true;\n emit({ type: 'succeeded', sessionId, orderId, paymentId, timestamp: Date.now() });\n onSucceeded?.({ orderId, paymentId });\n },\n [emit, sessionId, onSucceeded],\n );\n\n const handleFailed = useCallback(\n ({ code, message }: { code: string; message: string }) => {\n if (settledRef.current) return;\n settledRef.current = true;\n emit({ type: 'failed', sessionId, code, message, timestamp: Date.now() });\n onFailed?.({ code, message });\n },\n [emit, sessionId, onFailed],\n );\n\n const handleCanceled = useCallback(() => {\n emit({ type: 'cancelled', sessionId, timestamp: Date.now() });\n onCancelled?.();\n }, [emit, sessionId, onCancelled]);\n\n return (\n <PaymentEmbed\n sessionId={sessionId}\n parentOrigin={parentOrigin}\n {...(baseUrl !== undefined ? { baseUrl } : {})}\n primary={theme?.primary}\n logo={theme?.logo}\n onReady={handleReady}\n onProcessing={handleProcessing}\n onSucceeded={handleSucceeded}\n onFailed={handleFailed}\n onCanceled={handleCanceled}\n />\n );\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,cAAc;AAC/C,SAAS,oBAAoB;AA6EzB;AA9DG,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AAGrC,QAAM,aAAa,OAAO,KAAK;AAE/B,QAAM,OAAO;AAAA,IACX,CAAC,UAA0B;AACzB,oBAAc,KAAK;AAAA,IACrB;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAGA,YAAU,MAAM;AACd,SAAK,EAAE,MAAM,WAAW,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAG5D,GAAG,CAAC,CAAC;AAEL,QAAM,cAAc,YAAY,MAAM;AACpC,SAAK,EAAE,MAAM,SAAS,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAC1D,GAAG,CAAC,MAAM,SAAS,CAAC;AAEpB,QAAM,mBAAmB,YAAY,MAAM;AACzC,SAAK,EAAE,MAAM,cAAc,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAAA,EAC/D,GAAG,CAAC,MAAM,SAAS,CAAC;AAEpB,QAAM,kBAAkB;AAAA,IACtB,CAAC,EAAE,SAAS,UAAU,MAA8C;AAClE,UAAI,WAAW,QAAS;AACxB,iBAAW,UAAU;AACrB,WAAK,EAAE,MAAM,aAAa,WAAW,SAAS,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAChF,oBAAc,EAAE,SAAS,UAAU,CAAC;AAAA,IACtC;AAAA,IACA,CAAC,MAAM,WAAW,WAAW;AAAA,EAC/B;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,EAAE,MAAM,QAAQ,MAAyC;AACxD,UAAI,WAAW,QAAS;AACxB,iBAAW,UAAU;AACrB,WAAK,EAAE,MAAM,UAAU,WAAW,MAAM,SAAS,WAAW,KAAK,IAAI,EAAE,CAAC;AACxE,iBAAW,EAAE,MAAM,QAAQ,CAAC;AAAA,IAC9B;AAAA,IACA,CAAC,MAAM,WAAW,QAAQ;AAAA,EAC5B;AAEA,QAAM,iBAAiB,YAAY,MAAM;AACvC,SAAK,EAAE,MAAM,aAAa,WAAW,WAAW,KAAK,IAAI,EAAE,CAAC;AAC5D,kBAAc;AAAA,EAChB,GAAG,CAAC,MAAM,WAAW,WAAW,CAAC;AAEjC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACC,GAAI,YAAY,SAAY,EAAE,QAAQ,IAAI,CAAC;AAAA,MAC5C,SAAS,OAAO;AAAA,MAChB,MAAM,OAAO;AAAA,MACb,SAAS;AAAA,MACT,cAAc;AAAA,MACd,aAAa;AAAA,MACb,UAAU;AAAA,MACV,YAAY;AAAA;AAAA,EACd;AAEJ;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server.ts"],"sourcesContent":["export type PaymentMethod = 'net30' | 'card' | 'gr4vy';\nexport type SubscriptionInterval = 'weekly' | '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 CreateCheckoutSessionInput {\n storeId: string;\n cartId?: string;\n externalCartId?: string;\n customerEmail?: string;\n customer?: CheckoutCustomerInput;\n returnUrl: string;\n cancelUrl: string;\n allowedMethods?: string[];\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 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 gr4vyCheckoutSessionId?: string;\n gr4vyTransactionId?: 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 allowedMethods?: string[];\n}\n\nexport interface CreateEmbedTokenResult {\n embedToken: string;\n checkoutSessionId: string;\n amount: number;\n currency: string;\n hostedUrl?: string;\n embedUrl?: string;\n gr4vyId?: 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 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\nexport class ThrottleCheckoutError extends Error {\n readonly code: string;\n readonly statusCode: number;\n readonly details?: unknown;\n readonly body?: unknown;\n\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n body?: unknown;\n }) {\n super(args.message);\n this.name = 'ThrottleCheckoutError';\n this.code = args.code;\n this.statusCode = args.statusCode;\n this.details = args.details;\n this.body = args.body;\n }\n}\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 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 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?.session_id ?? raw?.id;\n return {\n ...raw,\n id: optionalString(raw?.id),\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl ?? raw?.checkout_url) ?? undefined,\n hostedUrl: optionalString(raw?.hostedUrl ?? raw?.hosted_url) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl ?? raw?.embed_url) ?? undefined,\n embedToken: optionalString(raw?.embedToken ?? raw?.embed_token) ?? undefined,\n expiresAt: optionalString(raw?.expiresAt ?? raw?.expires_at) ?? undefined,\n };\n}\n\nfunction normalizeCompleteResult(raw: any): CompleteCheckoutSessionResult {\n const orderId = raw?.orderId ?? raw?.order_id ?? raw?.id;\n return {\n ...raw,\n orderId: requiredString(orderId, 'checkoutComplete.orderId'),\n orderNumber: optionalString(raw?.orderNumber ?? raw?.order_number) ?? undefined,\n paymentId: optionalString(raw?.paymentId ?? raw?.payment_id) ?? undefined,\n total: optionalNumber(raw?.total),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n paymentStatus: optionalString(raw?.paymentStatus ?? raw?.payment_status) ?? undefined,\n };\n}\n\nfunction normalizeEmbedToken(raw: any): CreateEmbedTokenResult {\n return {\n ...raw,\n embedToken: requiredString(raw?.embedToken ?? raw?.embed_token, 'embedToken.embedToken'),\n checkoutSessionId: requiredString(\n raw?.checkoutSessionId ?? raw?.checkout_session_id,\n 'embedToken.checkoutSessionId',\n ),\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n hostedUrl: optionalString(raw?.hostedUrl ?? raw?.hosted_url) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl ?? raw?.embed_url) ?? undefined,\n gr4vyId: optionalString(raw?.gr4vyId ?? raw?.gr4vy_id) ?? undefined,\n merchantAccountId:\n optionalString(raw?.merchantAccountId ?? raw?.merchant_account_id) ?? undefined,\n };\n}\n\nfunction normalizeOrder(raw: any): CheckoutOrder {\n return {\n ...raw,\n id: requiredString(raw?.id, 'order.id'),\n orderNumber: optionalString(raw?.orderNumber ?? raw?.order_number) ?? undefined,\n status: optionalString(raw?.status) ?? 'processing',\n paymentStatus: optionalString(raw?.paymentStatus ?? raw?.payment_status),\n currency: optionalString(raw?.currency) ?? 'USD',\n subtotal: Number(raw?.subtotal ?? 0),\n taxTotal: Number(raw?.taxTotal ?? raw?.tax_total ?? 0),\n shippingTotal: Number(raw?.shippingTotal ?? raw?.shipping_total ?? 0),\n total: Number(raw?.total ?? 0),\n metadata: objectOrUndefined(raw?.metadata),\n };\n}\n\nfunction normalizePayment(raw: any): CheckoutPayment {\n return {\n ...raw,\n id: requiredString(raw?.id, 'payment.id'),\n orderId: optionalString(raw?.orderId ?? raw?.order_id) ?? undefined,\n processor: optionalString(raw?.processor) ?? undefined,\n processorTransactionId:\n optionalString(raw?.processorTransactionId ?? raw?.processor_transaction_id) ?? 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 ?? raw?.created_at) ?? undefined,\n };\n}\n\nfunction normalizeTransaction(raw: any): CheckoutPaymentTransaction {\n return {\n ...raw,\n id: requiredString(raw?.id, 'transaction.id'),\n paymentId: optionalString(raw?.paymentId ?? raw?.payment_id) ?? 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 ?? raw?.created_at) ?? undefined,\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;AA2MO,IAAM,wBAAN,cAAoC,MAAM;AAAA,EAM/C,YAAY,MAMT;AACD,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,aAAa,KAAK;AACvB,SAAK,UAAU,KAAK;AACpB,SAAK,OAAO,KAAK;AAAA,EACnB;AACF;AAEO,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,SA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AQ,eAAe,KAAK,MAAM,KAAK;AAAA,IACvC,WAAW,eAAe,KAAK,aAAa,KAAK,UAAU,KAAK;AAAA,EAClE;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":[]}
1
+ {"version":3,"sources":["../src/server.ts"],"sourcesContent":["export type PaymentMethod = 'net30' | 'card' | 'gr4vy';\nexport type SubscriptionInterval = 'weekly' | '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 type CreateCheckoutSessionInput = (\n | { storeId: string; applicationId?: string }\n | { applicationId: string; storeId?: string }\n) & {\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 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 gr4vyCheckoutSessionId?: string;\n gr4vyTransactionId?: 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 allowedMethods?: string[];\n}\n\nexport interface CreateEmbedTokenResult {\n embedToken: string;\n checkoutSessionId: string;\n amount: number;\n currency: string;\n hostedUrl?: string;\n embedUrl?: string;\n gr4vyId?: 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 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\nexport class ThrottleCheckoutError extends Error {\n readonly code: string;\n readonly statusCode: number;\n readonly details?: unknown;\n readonly body?: unknown;\n\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n body?: unknown;\n }) {\n super(args.message);\n this.name = 'ThrottleCheckoutError';\n this.code = args.code;\n this.statusCode = args.statusCode;\n this.details = args.details;\n this.body = args.body;\n }\n}\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 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 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?.session_id ?? raw?.id;\n return {\n ...raw,\n id: optionalString(raw?.id),\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl ?? raw?.checkout_url) ?? undefined,\n hostedUrl: optionalString(raw?.hostedUrl ?? raw?.hosted_url) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl ?? raw?.embed_url) ?? undefined,\n embedToken: optionalString(raw?.embedToken ?? raw?.embed_token) ?? undefined,\n expiresAt: optionalString(raw?.expiresAt ?? raw?.expires_at) ?? undefined,\n };\n}\n\nfunction normalizeCompleteResult(raw: any): CompleteCheckoutSessionResult {\n const orderId = raw?.orderId ?? raw?.order_id ?? raw?.id;\n return {\n ...raw,\n orderId: requiredString(orderId, 'checkoutComplete.orderId'),\n orderNumber: optionalString(raw?.orderNumber ?? raw?.order_number) ?? undefined,\n paymentId: optionalString(raw?.paymentId ?? raw?.payment_id) ?? undefined,\n total: optionalNumber(raw?.total),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n paymentStatus: optionalString(raw?.paymentStatus ?? raw?.payment_status) ?? undefined,\n };\n}\n\nfunction normalizeEmbedToken(raw: any): CreateEmbedTokenResult {\n return {\n ...raw,\n embedToken: requiredString(raw?.embedToken ?? raw?.embed_token, 'embedToken.embedToken'),\n checkoutSessionId: requiredString(\n raw?.checkoutSessionId ?? raw?.checkout_session_id,\n 'embedToken.checkoutSessionId',\n ),\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n hostedUrl: optionalString(raw?.hostedUrl ?? raw?.hosted_url) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl ?? raw?.embed_url) ?? undefined,\n gr4vyId: optionalString(raw?.gr4vyId ?? raw?.gr4vy_id) ?? undefined,\n merchantAccountId:\n optionalString(raw?.merchantAccountId ?? raw?.merchant_account_id) ?? undefined,\n };\n}\n\nfunction normalizeOrder(raw: any): CheckoutOrder {\n return {\n ...raw,\n id: requiredString(raw?.id, 'order.id'),\n orderNumber: optionalString(raw?.orderNumber ?? raw?.order_number) ?? undefined,\n status: optionalString(raw?.status) ?? 'processing',\n paymentStatus: optionalString(raw?.paymentStatus ?? raw?.payment_status),\n currency: optionalString(raw?.currency) ?? 'USD',\n subtotal: Number(raw?.subtotal ?? 0),\n taxTotal: Number(raw?.taxTotal ?? raw?.tax_total ?? 0),\n shippingTotal: Number(raw?.shippingTotal ?? raw?.shipping_total ?? 0),\n total: Number(raw?.total ?? 0),\n metadata: objectOrUndefined(raw?.metadata),\n };\n}\n\nfunction normalizePayment(raw: any): CheckoutPayment {\n return {\n ...raw,\n id: requiredString(raw?.id, 'payment.id'),\n orderId: optionalString(raw?.orderId ?? raw?.order_id) ?? undefined,\n processor: optionalString(raw?.processor) ?? undefined,\n processorTransactionId:\n optionalString(raw?.processorTransactionId ?? raw?.processor_transaction_id) ?? 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 ?? raw?.created_at) ?? undefined,\n };\n}\n\nfunction normalizeTransaction(raw: any): CheckoutPaymentTransaction {\n return {\n ...raw,\n id: requiredString(raw?.id, 'transaction.id'),\n paymentId: optionalString(raw?.paymentId ?? raw?.payment_id) ?? 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 ?? raw?.created_at) ?? undefined,\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;AAkNO,IAAM,wBAAN,cAAoC,MAAM;AAAA,EAM/C,YAAY,MAMT;AACD,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,aAAa,KAAK;AACvB,SAAK,UAAU,KAAK;AACpB,SAAK,OAAO,KAAK;AAAA,EACnB;AACF;AAEO,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,QAA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AQ;AACvE;AAEA,SAAS,kBAAkB,OAAqD;AAC9E,SAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAC5D,QACD;AACN;","names":[]}
package/dist/server.d.cts CHANGED
@@ -54,8 +54,16 @@ interface CheckoutCollectInput {
54
54
  shippingAddress?: boolean;
55
55
  billingAddress?: boolean;
56
56
  }
57
- interface CreateCheckoutSessionInput {
57
+ interface CheckoutPaymentTermsInput {
58
+ netN?: number | null;
59
+ }
60
+ type CreateCheckoutSessionInput = ({
58
61
  storeId: string;
62
+ applicationId?: string;
63
+ } | {
64
+ applicationId: string;
65
+ storeId?: string;
66
+ }) & {
59
67
  cartId?: string;
60
68
  externalCartId?: string;
61
69
  customerEmail?: string;
@@ -63,11 +71,12 @@ interface CreateCheckoutSessionInput {
63
71
  returnUrl: string;
64
72
  cancelUrl: string;
65
73
  allowedMethods?: string[];
74
+ paymentTerms?: CheckoutPaymentTermsInput;
66
75
  recurring?: RecurringIntentInput;
67
76
  collect?: CheckoutCollectInput;
68
77
  metadata?: Record<string, unknown>;
69
78
  discountCode?: string;
70
- }
79
+ };
71
80
  interface CheckoutSession {
72
81
  sessionId: string;
73
82
  id?: string;
@@ -215,4 +224,4 @@ declare function createCheckoutClient(opts: CheckoutClientOptions): CheckoutClie
215
224
  declare function buildCheckoutHostedUrl(options: BuildCheckoutUrlOptions): string;
216
225
  declare function buildCheckoutEmbedUrl(options: BuildCheckoutUrlOptions): string;
217
226
 
218
- export { type BuildCheckoutUrlOptions, type CheckoutAddress, CheckoutClient, type CheckoutClientOptions, type CheckoutCollectInput, type CheckoutCustomerAddressInput, type CheckoutCustomerInput, type CheckoutEmbedMode, type CheckoutEmbedRoute, type CheckoutOrder, type CheckoutPayment, type CheckoutPaymentTransaction, type CheckoutSession, type CompleteCheckoutSessionInput, type CompleteCheckoutSessionResult, type CreateCheckoutSessionInput, type CreateEmbedTokenInput, type CreateEmbedTokenResult, type Net30Acceptance, type PaymentMethod, type RecurringIntentInput, type SubscriptionInterval, ThrottleCheckoutError, type ThrottleEnvelope, buildCheckoutEmbedUrl, buildCheckoutHostedUrl, createCheckoutClient };
227
+ 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 CompleteCheckoutSessionInput, type CompleteCheckoutSessionResult, type CreateCheckoutSessionInput, type CreateEmbedTokenInput, type CreateEmbedTokenResult, type Net30Acceptance, type PaymentMethod, type RecurringIntentInput, type SubscriptionInterval, ThrottleCheckoutError, type ThrottleEnvelope, buildCheckoutEmbedUrl, buildCheckoutHostedUrl, createCheckoutClient };
package/dist/server.d.ts CHANGED
@@ -54,8 +54,16 @@ interface CheckoutCollectInput {
54
54
  shippingAddress?: boolean;
55
55
  billingAddress?: boolean;
56
56
  }
57
- interface CreateCheckoutSessionInput {
57
+ interface CheckoutPaymentTermsInput {
58
+ netN?: number | null;
59
+ }
60
+ type CreateCheckoutSessionInput = ({
58
61
  storeId: string;
62
+ applicationId?: string;
63
+ } | {
64
+ applicationId: string;
65
+ storeId?: string;
66
+ }) & {
59
67
  cartId?: string;
60
68
  externalCartId?: string;
61
69
  customerEmail?: string;
@@ -63,11 +71,12 @@ interface CreateCheckoutSessionInput {
63
71
  returnUrl: string;
64
72
  cancelUrl: string;
65
73
  allowedMethods?: string[];
74
+ paymentTerms?: CheckoutPaymentTermsInput;
66
75
  recurring?: RecurringIntentInput;
67
76
  collect?: CheckoutCollectInput;
68
77
  metadata?: Record<string, unknown>;
69
78
  discountCode?: string;
70
- }
79
+ };
71
80
  interface CheckoutSession {
72
81
  sessionId: string;
73
82
  id?: string;
@@ -215,4 +224,4 @@ declare function createCheckoutClient(opts: CheckoutClientOptions): CheckoutClie
215
224
  declare function buildCheckoutHostedUrl(options: BuildCheckoutUrlOptions): string;
216
225
  declare function buildCheckoutEmbedUrl(options: BuildCheckoutUrlOptions): string;
217
226
 
218
- export { type BuildCheckoutUrlOptions, type CheckoutAddress, CheckoutClient, type CheckoutClientOptions, type CheckoutCollectInput, type CheckoutCustomerAddressInput, type CheckoutCustomerInput, type CheckoutEmbedMode, type CheckoutEmbedRoute, type CheckoutOrder, type CheckoutPayment, type CheckoutPaymentTransaction, type CheckoutSession, type CompleteCheckoutSessionInput, type CompleteCheckoutSessionResult, type CreateCheckoutSessionInput, type CreateEmbedTokenInput, type CreateEmbedTokenResult, type Net30Acceptance, type PaymentMethod, type RecurringIntentInput, type SubscriptionInterval, ThrottleCheckoutError, type ThrottleEnvelope, buildCheckoutEmbedUrl, buildCheckoutHostedUrl, createCheckoutClient };
227
+ 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 CompleteCheckoutSessionInput, type CompleteCheckoutSessionResult, type CreateCheckoutSessionInput, type CreateEmbedTokenInput, type CreateEmbedTokenResult, type Net30Acceptance, type PaymentMethod, type RecurringIntentInput, type SubscriptionInterval, ThrottleCheckoutError, type ThrottleEnvelope, buildCheckoutEmbedUrl, buildCheckoutHostedUrl, createCheckoutClient };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server.ts"],"sourcesContent":["export type PaymentMethod = 'net30' | 'card' | 'gr4vy';\nexport type SubscriptionInterval = 'weekly' | '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 CreateCheckoutSessionInput {\n storeId: string;\n cartId?: string;\n externalCartId?: string;\n customerEmail?: string;\n customer?: CheckoutCustomerInput;\n returnUrl: string;\n cancelUrl: string;\n allowedMethods?: string[];\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 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 gr4vyCheckoutSessionId?: string;\n gr4vyTransactionId?: 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 allowedMethods?: string[];\n}\n\nexport interface CreateEmbedTokenResult {\n embedToken: string;\n checkoutSessionId: string;\n amount: number;\n currency: string;\n hostedUrl?: string;\n embedUrl?: string;\n gr4vyId?: 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 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\nexport class ThrottleCheckoutError extends Error {\n readonly code: string;\n readonly statusCode: number;\n readonly details?: unknown;\n readonly body?: unknown;\n\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n body?: unknown;\n }) {\n super(args.message);\n this.name = 'ThrottleCheckoutError';\n this.code = args.code;\n this.statusCode = args.statusCode;\n this.details = args.details;\n this.body = args.body;\n }\n}\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 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 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?.session_id ?? raw?.id;\n return {\n ...raw,\n id: optionalString(raw?.id),\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl ?? raw?.checkout_url) ?? undefined,\n hostedUrl: optionalString(raw?.hostedUrl ?? raw?.hosted_url) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl ?? raw?.embed_url) ?? undefined,\n embedToken: optionalString(raw?.embedToken ?? raw?.embed_token) ?? undefined,\n expiresAt: optionalString(raw?.expiresAt ?? raw?.expires_at) ?? undefined,\n };\n}\n\nfunction normalizeCompleteResult(raw: any): CompleteCheckoutSessionResult {\n const orderId = raw?.orderId ?? raw?.order_id ?? raw?.id;\n return {\n ...raw,\n orderId: requiredString(orderId, 'checkoutComplete.orderId'),\n orderNumber: optionalString(raw?.orderNumber ?? raw?.order_number) ?? undefined,\n paymentId: optionalString(raw?.paymentId ?? raw?.payment_id) ?? undefined,\n total: optionalNumber(raw?.total),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n paymentStatus: optionalString(raw?.paymentStatus ?? raw?.payment_status) ?? undefined,\n };\n}\n\nfunction normalizeEmbedToken(raw: any): CreateEmbedTokenResult {\n return {\n ...raw,\n embedToken: requiredString(raw?.embedToken ?? raw?.embed_token, 'embedToken.embedToken'),\n checkoutSessionId: requiredString(\n raw?.checkoutSessionId ?? raw?.checkout_session_id,\n 'embedToken.checkoutSessionId',\n ),\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n hostedUrl: optionalString(raw?.hostedUrl ?? raw?.hosted_url) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl ?? raw?.embed_url) ?? undefined,\n gr4vyId: optionalString(raw?.gr4vyId ?? raw?.gr4vy_id) ?? undefined,\n merchantAccountId:\n optionalString(raw?.merchantAccountId ?? raw?.merchant_account_id) ?? undefined,\n };\n}\n\nfunction normalizeOrder(raw: any): CheckoutOrder {\n return {\n ...raw,\n id: requiredString(raw?.id, 'order.id'),\n orderNumber: optionalString(raw?.orderNumber ?? raw?.order_number) ?? undefined,\n status: optionalString(raw?.status) ?? 'processing',\n paymentStatus: optionalString(raw?.paymentStatus ?? raw?.payment_status),\n currency: optionalString(raw?.currency) ?? 'USD',\n subtotal: Number(raw?.subtotal ?? 0),\n taxTotal: Number(raw?.taxTotal ?? raw?.tax_total ?? 0),\n shippingTotal: Number(raw?.shippingTotal ?? raw?.shipping_total ?? 0),\n total: Number(raw?.total ?? 0),\n metadata: objectOrUndefined(raw?.metadata),\n };\n}\n\nfunction normalizePayment(raw: any): CheckoutPayment {\n return {\n ...raw,\n id: requiredString(raw?.id, 'payment.id'),\n orderId: optionalString(raw?.orderId ?? raw?.order_id) ?? undefined,\n processor: optionalString(raw?.processor) ?? undefined,\n processorTransactionId:\n optionalString(raw?.processorTransactionId ?? raw?.processor_transaction_id) ?? 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 ?? raw?.created_at) ?? undefined,\n };\n}\n\nfunction normalizeTransaction(raw: any): CheckoutPaymentTransaction {\n return {\n ...raw,\n id: requiredString(raw?.id, 'transaction.id'),\n paymentId: optionalString(raw?.paymentId ?? raw?.payment_id) ?? 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 ?? raw?.created_at) ?? undefined,\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":";AA2MO,IAAM,wBAAN,cAAoC,MAAM;AAAA,EAM/C,YAAY,MAMT;AACD,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,aAAa,KAAK;AACvB,SAAK,UAAU,KAAK;AACpB,SAAK,OAAO,KAAK;AAAA,EACnB;AACF;AAEO,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,UA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,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":[]}
1
+ {"version":3,"sources":["../src/server.ts"],"sourcesContent":["export type PaymentMethod = 'net30' | 'card' | 'gr4vy';\nexport type SubscriptionInterval = 'weekly' | '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 type CreateCheckoutSessionInput = (\n | { storeId: string; applicationId?: string }\n | { applicationId: string; storeId?: string }\n) & {\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 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 gr4vyCheckoutSessionId?: string;\n gr4vyTransactionId?: 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 allowedMethods?: string[];\n}\n\nexport interface CreateEmbedTokenResult {\n embedToken: string;\n checkoutSessionId: string;\n amount: number;\n currency: string;\n hostedUrl?: string;\n embedUrl?: string;\n gr4vyId?: 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 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\nexport class ThrottleCheckoutError extends Error {\n readonly code: string;\n readonly statusCode: number;\n readonly details?: unknown;\n readonly body?: unknown;\n\n constructor(args: {\n code: string;\n message: string;\n statusCode: number;\n details?: unknown;\n body?: unknown;\n }) {\n super(args.message);\n this.name = 'ThrottleCheckoutError';\n this.code = args.code;\n this.statusCode = args.statusCode;\n this.details = args.details;\n this.body = args.body;\n }\n}\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 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 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?.session_id ?? raw?.id;\n return {\n ...raw,\n id: optionalString(raw?.id),\n sessionId: requiredString(sessionId, 'checkoutSession.sessionId'),\n checkoutUrl: optionalString(raw?.checkoutUrl ?? raw?.checkout_url) ?? undefined,\n hostedUrl: optionalString(raw?.hostedUrl ?? raw?.hosted_url) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl ?? raw?.embed_url) ?? undefined,\n embedToken: optionalString(raw?.embedToken ?? raw?.embed_token) ?? undefined,\n expiresAt: optionalString(raw?.expiresAt ?? raw?.expires_at) ?? undefined,\n };\n}\n\nfunction normalizeCompleteResult(raw: any): CompleteCheckoutSessionResult {\n const orderId = raw?.orderId ?? raw?.order_id ?? raw?.id;\n return {\n ...raw,\n orderId: requiredString(orderId, 'checkoutComplete.orderId'),\n orderNumber: optionalString(raw?.orderNumber ?? raw?.order_number) ?? undefined,\n paymentId: optionalString(raw?.paymentId ?? raw?.payment_id) ?? undefined,\n total: optionalNumber(raw?.total),\n currency: optionalString(raw?.currency) ?? undefined,\n status: optionalString(raw?.status) ?? undefined,\n paymentStatus: optionalString(raw?.paymentStatus ?? raw?.payment_status) ?? undefined,\n };\n}\n\nfunction normalizeEmbedToken(raw: any): CreateEmbedTokenResult {\n return {\n ...raw,\n embedToken: requiredString(raw?.embedToken ?? raw?.embed_token, 'embedToken.embedToken'),\n checkoutSessionId: requiredString(\n raw?.checkoutSessionId ?? raw?.checkout_session_id,\n 'embedToken.checkoutSessionId',\n ),\n amount: Number(raw?.amount ?? 0),\n currency: optionalString(raw?.currency) ?? 'USD',\n hostedUrl: optionalString(raw?.hostedUrl ?? raw?.hosted_url) ?? undefined,\n embedUrl: optionalString(raw?.embedUrl ?? raw?.embed_url) ?? undefined,\n gr4vyId: optionalString(raw?.gr4vyId ?? raw?.gr4vy_id) ?? undefined,\n merchantAccountId:\n optionalString(raw?.merchantAccountId ?? raw?.merchant_account_id) ?? undefined,\n };\n}\n\nfunction normalizeOrder(raw: any): CheckoutOrder {\n return {\n ...raw,\n id: requiredString(raw?.id, 'order.id'),\n orderNumber: optionalString(raw?.orderNumber ?? raw?.order_number) ?? undefined,\n status: optionalString(raw?.status) ?? 'processing',\n paymentStatus: optionalString(raw?.paymentStatus ?? raw?.payment_status),\n currency: optionalString(raw?.currency) ?? 'USD',\n subtotal: Number(raw?.subtotal ?? 0),\n taxTotal: Number(raw?.taxTotal ?? raw?.tax_total ?? 0),\n shippingTotal: Number(raw?.shippingTotal ?? raw?.shipping_total ?? 0),\n total: Number(raw?.total ?? 0),\n metadata: objectOrUndefined(raw?.metadata),\n };\n}\n\nfunction normalizePayment(raw: any): CheckoutPayment {\n return {\n ...raw,\n id: requiredString(raw?.id, 'payment.id'),\n orderId: optionalString(raw?.orderId ?? raw?.order_id) ?? undefined,\n processor: optionalString(raw?.processor) ?? undefined,\n processorTransactionId:\n optionalString(raw?.processorTransactionId ?? raw?.processor_transaction_id) ?? 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 ?? raw?.created_at) ?? undefined,\n };\n}\n\nfunction normalizeTransaction(raw: any): CheckoutPaymentTransaction {\n return {\n ...raw,\n id: requiredString(raw?.id, 'transaction.id'),\n paymentId: optionalString(raw?.paymentId ?? raw?.payment_id) ?? 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 ?? raw?.created_at) ?? undefined,\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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6
6
  "module": "./dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "react-dom": ">=18 <20"
28
28
  },
29
29
  "dependencies": {
30
- "@usethrottle/checkout-react": "1.0.0"
30
+ "@usethrottle/checkout-react": "1.0.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@testing-library/react": "^16.0.0",