@usethrottle/checkout-sdk 1.0.1 → 1.0.2

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,13 @@
1
1
  # @usethrottle/checkout-sdk
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Expose customer Net-N payment terms in the generated API client and republish the public SDK package set.
8
+ - Updated dependencies
9
+ - @usethrottle/checkout-react@1.0.1
10
+
3
11
  ## 1.0.1
4
12
 
5
13
  ### 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
@@ -64,40 +67,40 @@ const hostedUrl = buildCheckoutHostedUrl({
64
67
 
65
68
  ### Server methods
66
69
 
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. |
70
+ | Method | Endpoint | Description |
71
+ | ----------------------------- | --------------------------------------------- | --------------------------------------------------------- |
72
+ | `createSession(input)` | `POST /api/v1/checkout/sessions` | Creates a cart-backed hosted/embed checkout session. |
73
+ | `completeSession(id, input)` | `POST /api/v1/checkout/sessions/:id/complete` | Completes a checkout session from server-side proxy mode. |
74
+ | `createEmbedToken(input)` | `POST /api/v1/checkout-sessions/embed-token` | Mints a Gr4vy Embed token for proxy-mode card capture. |
75
+ | `getOrder(id)` | `GET /api/v1/orders/:id` | Reads public-safe order totals/status. |
76
+ | `listOrderPayments(id)` | `GET /api/v1/orders/:id/payments` | Lists payments for an order. |
77
+ | `listPaymentTransactions(id)` | `GET /api/v1/payments/:id/transactions` | Lists transactions for a payment. |
78
+ | `getOrderWithPayments(id)` | Combined reads | Fetches an order, payments, and transactions together. |
76
79
 
77
80
  ## Props
78
81
 
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 |
82
+ | Prop | Type | Required | Description |
83
+ | -------------- | ----------------- | -------- | ------------------------------------------------------------------------------ |
84
+ | `sessionId` | `string` | Yes | Throttle checkout session id (`cs_*`) |
85
+ | `parentOrigin` | `string` | No | Origin of the page mounting the embed |
86
+ | `baseUrl` | `string` | No | Override the hosted checkout URL (default: `https://checkout.usethrottle.dev`) |
87
+ | `theme` | `BrandTheme` | No | Brand colour + logo forwarded to hosted page |
88
+ | `onSucceeded` | `(args) => void` | No | Called once on successful payment |
89
+ | `onFailed` | `(args) => void` | No | Called once on terminal payment failure |
90
+ | `onCancelled` | `() => void` | No | Called when the user cancels |
91
+ | `onTelemetry` | `(event) => void` | No | Receives every lifecycle event |
89
92
 
90
93
  ## Telemetry events
91
94
 
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) |
95
+ | `event.type` | Additional payload | Description |
96
+ | -------------- | ------------------------------------------------ | ------------------------------------------ |
97
+ | `mounted` | `sessionId`, `timestamp` | Component mounted in the DOM |
98
+ | `ready` | `sessionId`, `timestamp` | Hosted iframe fully loaded |
99
+ | `processing` | `sessionId`, `timestamp` | Payment authorization in-flight |
100
+ | `succeeded` | `sessionId`, `orderId`, `paymentId`, `timestamp` | Payment completed successfully |
101
+ | `failed` | `sessionId`, `code`, `message`, `timestamp` | Terminal payment failure |
102
+ | `cancelled` | `sessionId`, `timestamp` | User cancelled checkout |
103
+ | `step_changed` | `sessionId`, `step`, `timestamp` | Checkout step navigation (full embed only) |
101
104
 
102
105
  ## Idempotency
103
106
 
@@ -113,4 +116,5 @@ const hostedUrl = buildCheckoutHostedUrl({
113
116
  pnpm --filter @usethrottle/checkout-sdk build
114
117
  ```
115
118
 
116
- Emits CJS (`dist/index.cjs`), ESM (`dist/index.js`), and TypeScript declarations (`dist/index.d.ts`).
119
+ Emits CJS, ESM, and TypeScript declarations for both the browser entrypoint and
120
+ `@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,SA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,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,QAA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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 onPro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AU,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
+ {"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;A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AI,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usethrottle/checkout-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
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",