@flopay/js 1.14.5 → 1.14.7

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.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Shared primitives for reading billing-API error bodies. The two error
3
+ * builders that consume these — `buildApiErrorFromResponse` (payment-api) and
4
+ * `buildCheckoutSessionError` (create-checkout-session) — diverge in their
5
+ * fallback semantics (array-message joining + status code vs. coupon-specific
6
+ * messages), but the field-level guards are identical, so they live here.
7
+ */
8
+ /** A non-empty string value, or `undefined` for anything else. */
9
+ export declare function readErrorString(value: unknown): string | undefined;
10
+ /**
11
+ * Read an error `message` that may be a `string` or a `string[]`.
12
+ *
13
+ * NestJS class-validator returns `message` as a `string[]` (one entry per
14
+ * failed constraint), e.g. `["postcode must be a valid GB postcode"]`. Read as
15
+ * a plain string that collapses to the generic fallback; here we join the
16
+ * non-empty entries so a country-aware account-snapshot validation error
17
+ * surfaces its real reason instead of "Failed to persist account snapshot".
18
+ */
19
+ export declare function readErrorMessage(value: unknown): string | undefined;
@@ -1,24 +1,16 @@
1
- export { C as CardCaptureOperation, P as PaymentAPI, a as PciVaultCardCapture, b as PciVaultCardCaptureConfig } from './pci-vault-card-capture-Dt3F9i7Q.js';
2
- import '@flopay/shared';
3
-
4
1
  /**
5
- * The Stripe redirect return of a payment-method setup surface. A buyer who
6
- * saves a redirect method (a bank or wallet that leaves the page) comes back
7
- * with Stripe's standard `setup_intent` / `setup_intent_client_secret` /
8
- * `redirect_status` query parameters.
2
+ * Stripe-free entry for card-setup surfaces (`@flopay/js/card-setup`).
9
3
  *
10
- * Shared by every UI binding (`@flopay/react`, `@flopay/vue`) and exported from
11
- * the Stripe-free `@flopay/js/card-setup` entry, so reading it never loads
12
- * Stripe.js.
4
+ * The main entry eagerly imports `@stripe/stripe-js`, whose module evaluation
5
+ * starts downloading the js.stripe.com script — deliberate for checkout (the
6
+ * script fetches in parallel with the session fetch and is ready when the
7
+ * publishable key arrives), but wrong for surfaces that never initialise
8
+ * Stripe. This entry's module graph contains only what the hosted vault
9
+ * card-setup flow needs, so a page importing from it stays free of Stripe
10
+ * network activity by construction.
13
11
  */
14
- /** A buyer returning from a wallet/APM redirect (Stripe's standard query params). */
15
- interface SetupRedirectReturn {
16
- /** `redirect_status=failed`: the provider reports the setup failed. */
17
- failed: boolean;
18
- }
19
- /** Read a setup redirect return from the current URL, if this page load is one. */
20
- declare function readSetupRedirectReturn(): SetupRedirectReturn | null;
21
- /** Drop the redirect-return params so a reload does not replay the outcome. */
22
- declare function clearSetupRedirectParams(): void;
23
-
24
- export { type SetupRedirectReturn, clearSetupRedirectParams, readSetupRedirectReturn };
12
+ export { PaymentAPI } from './payment-api.js';
13
+ export type { CardCaptureOperation, PciVaultCardCaptureConfig, } from './pci-vault-card-capture.js';
14
+ export { PciVaultCardCapture } from './pci-vault-card-capture.js';
15
+ export type { SetupRedirectReturn } from './setup-redirect-return.js';
16
+ export { clearSetupRedirectParams, readSetupRedirectReturn } from './setup-redirect-return.js';
@@ -0,0 +1,19 @@
1
+ import type { CheckoutSessionResult, CreateSessionParams } from '@flopay/shared';
2
+ export declare function createCheckoutSession(options: CreateSessionParams): Promise<CheckoutSessionResult>;
3
+ /**
4
+ * Creates a checkout session with automatic retry on transient transport,
5
+ * timeout/abort, and idempotency-in-progress errors.
6
+ *
7
+ * Uses jittered exponential backoff under the same total deadline as a single
8
+ * create (12 seconds by default, configurable with `timeoutMs`).
9
+ *
10
+ * The idempotency key (supplied or generated) is resolved **once**, before the
11
+ * retry loop, and reused for every attempt — so a timeout, a lost response, or
12
+ * a documented in-progress reply all replay the *same* key and cannot mint a
13
+ * second checkout session (TeamFloPay/backend#972). A later independent call
14
+ * resolves its own fresh key. A payload-conflict (`409`) is surfaced without
15
+ * retrying, since only the exact same request may safely replay a key.
16
+ */
17
+ export declare function createCheckoutSessionWithRetries(options: CreateSessionParams & {
18
+ maxRetries?: number;
19
+ }): Promise<CheckoutSessionResult>;
@@ -0,0 +1,59 @@
1
+ import type { CaptureMethod, CardCaptureAdapter, CheckoutSession, FloPayConfig, NormalizedCheckoutSession, PaymentProviderAdapter } from '@flopay/shared';
2
+ import { TelemetryReporter } from './telemetry-reporter.js';
3
+ /**
4
+ * The main FloPay SDK instance.
5
+ *
6
+ * Created via `loadFloPay(publishableKey)`. Provides hosted card capture,
7
+ * raw-provider access, and session retrieval.
8
+ */
9
+ export declare class FloPay {
10
+ private readonly provider;
11
+ private readonly config;
12
+ private readonly telemetryReporter?;
13
+ private now;
14
+ constructor(provider: PaymentProviderAdapter, config: FloPayConfig);
15
+ /**
16
+ * Create a {@link CardCaptureAdapter} for collecting card details through the
17
+ * backend-rendered hosted vault PCI widget (TeamFloPay/backend#823).
18
+ *
19
+ * The returned adapter injects the server-supplied widget HTML (the session's
20
+ * {@link CheckoutSession.vault} block, or one fetched via
21
+ * `PaymentAPI.getVaultCapture`) and relays the widget's terminal outcome. The
22
+ * backend owns tokenization, the PaymentIntent, 3DS, and fulfilment — no
23
+ * Stripe.js is involved on the card path and PCI-sensitive fields never enter
24
+ * the SDK runtime.
25
+ */
26
+ cardCapture(options?: {
27
+ /** Checkout session id to bind the capture to (outcome correlation). */
28
+ sessionId?: string;
29
+ /** Capture behavior used to classify legacy vault outcomes safely. */
30
+ captureMethod?: CaptureMethod;
31
+ }): CardCaptureAdapter;
32
+ /**
33
+ * Retrieves a checkout session by ID via the billing API.
34
+ *
35
+ * Returns the normalized `CheckoutSession` with amount, currency,
36
+ * customer data, and status.
37
+ *
38
+ * Requires `billingApiUrl` to be set — either via `loadFloPay(key, { billingApiUrl })`
39
+ * or passed directly as the second argument.
40
+ */
41
+ retrieveSession(sessionId: string, billingApiUrl?: string): Promise<CheckoutSession>;
42
+ /**
43
+ * Retrieves and normalizes a checkout session, including provider-specific
44
+ * data (Stripe clientSecret/publishableKey, Chargebee site, etc.).
45
+ *
46
+ * The billing API URL is resolved from: explicit param → `loadFloPay()` config
47
+ * → `NEXT_PUBLIC_FLOPAY_ENV` env var → `configureFlopay()` → staging fallback.
48
+ */
49
+ retrieveUnifiedSession(sessionId: string, billingApiUrl?: string): Promise<NormalizedCheckoutSession>;
50
+ /**
51
+ * Returns the raw underlying provider instance (e.g. Stripe object).
52
+ * Used internally by components that need direct provider access.
53
+ */
54
+ getRawProvider(): unknown;
55
+ /** Tears down the SDK instance and releases resources. */
56
+ destroy(): void;
57
+ }
58
+ /** Create the loadFloPay-owned instance without publishing reporter injection. */
59
+ export declare function createInstrumentedFloPay(provider: PaymentProviderAdapter, config: FloPayConfig, reporter: TelemetryReporter): FloPay;
package/dist/index.d.ts CHANGED
@@ -1,232 +1,14 @@
1
- import { CreateSessionParams, CheckoutSessionResult, PaymentProviderAdapter, FloPayConfig, CaptureMethod, CardCaptureAdapter, CheckoutSession, NormalizedCheckoutSession, FloPayError } from '@flopay/shared';
2
- export { SentryEventLike, SentryStackFrameLike, StripeSafeAppearance, dropThirdPartyOnlyError, toStripeAppearance, toStripeAppearanceTheme } from '@flopay/shared';
3
- import { P as PaymentAPI } from './pci-vault-card-capture-Dt3F9i7Q.js';
4
- export { C as CardCaptureOperation, a as PciVaultCardCapture, b as PciVaultCardCaptureConfig, S as SESSION_CREATE_TELEMETRY, c as SessionDisplayCacheData, d as SessionDisplayProduct, e as cacheSessionDisplayData, f as clearSessionDisplayData, g as getSessionDisplayData } from './pci-vault-card-capture-Dt3F9i7Q.js';
5
-
6
- declare function createCheckoutSession(options: CreateSessionParams): Promise<CheckoutSessionResult>;
7
- /**
8
- * Creates a checkout session with automatic retry on transient transport,
9
- * timeout/abort, and idempotency-in-progress errors.
10
- *
11
- * Uses jittered exponential backoff under the same total deadline as a single
12
- * create (12 seconds by default, configurable with `timeoutMs`).
13
- *
14
- * The idempotency key (supplied or generated) is resolved **once**, before the
15
- * retry loop, and reused for every attempt — so a timeout, a lost response, or
16
- * a documented in-progress reply all replay the *same* key and cannot mint a
17
- * second checkout session (TeamFloPay/backend#972). A later independent call
18
- * resolves its own fresh key. A payload-conflict (`409`) is surfaced without
19
- * retrying, since only the exact same request may safely replay a key.
20
- */
21
- declare function createCheckoutSessionWithRetries(options: CreateSessionParams & {
22
- maxRetries?: number;
23
- }): Promise<CheckoutSessionResult>;
24
-
25
- /**
26
- * The main FloPay SDK instance.
27
- *
28
- * Created via `loadFloPay(publishableKey)`. Provides hosted card capture,
29
- * raw-provider access, and session retrieval.
30
- */
31
- declare class FloPay {
32
- private readonly provider;
33
- private readonly config;
34
- private readonly telemetryReporter?;
35
- private now;
36
- constructor(provider: PaymentProviderAdapter, config: FloPayConfig);
37
- /**
38
- * Create a {@link CardCaptureAdapter} for collecting card details through the
39
- * backend-rendered hosted vault PCI widget (TeamFloPay/backend#823).
40
- *
41
- * The returned adapter injects the server-supplied widget HTML (the session's
42
- * {@link CheckoutSession.vault} block, or one fetched via
43
- * `PaymentAPI.getVaultCapture`) and relays the widget's terminal outcome. The
44
- * backend owns tokenization, the PaymentIntent, 3DS, and fulfilment — no
45
- * Stripe.js is involved on the card path and PCI-sensitive fields never enter
46
- * the SDK runtime.
47
- */
48
- cardCapture(options?: {
49
- /** Checkout session id to bind the capture to (outcome correlation). */
50
- sessionId?: string;
51
- /** Capture behavior used to classify legacy vault outcomes safely. */
52
- captureMethod?: CaptureMethod;
53
- }): CardCaptureAdapter;
54
- /**
55
- * Retrieves a checkout session by ID via the billing API.
56
- *
57
- * Returns the normalized `CheckoutSession` with amount, currency,
58
- * customer data, and status.
59
- *
60
- * Requires `billingApiUrl` to be set — either via `loadFloPay(key, { billingApiUrl })`
61
- * or passed directly as the second argument.
62
- */
63
- retrieveSession(sessionId: string, billingApiUrl?: string): Promise<CheckoutSession>;
64
- /**
65
- * Retrieves and normalizes a checkout session, including provider-specific
66
- * data (Stripe clientSecret/publishableKey, Chargebee site, etc.).
67
- *
68
- * The billing API URL is resolved from: explicit param → `loadFloPay()` config
69
- * → `NEXT_PUBLIC_FLOPAY_ENV` env var → `configureFlopay()` → staging fallback.
70
- */
71
- retrieveUnifiedSession(sessionId: string, billingApiUrl?: string): Promise<NormalizedCheckoutSession>;
72
- /**
73
- * Returns the raw underlying provider instance (e.g. Stripe object).
74
- * Used internally by components that need direct provider access.
75
- */
76
- getRawProvider(): unknown;
77
- /** Tears down the SDK instance and releases resources. */
78
- destroy(): void;
79
- }
80
-
81
- /**
82
- * Loads and initializes the FloPay SDK.
83
- *
84
- * This is the primary entry point for consumer applications.
85
- * It initializes the underlying payment provider (currently Stripe)
86
- * and returns a ready-to-use `FloPay` instance.
87
- *
88
- * Instances are cached per complete behavior-affecting configuration.
89
- * Matching calls return the same instance; calls with different billing API,
90
- * telemetry, locale, API version, or appearance options receive independent
91
- * instances.
92
- *
93
- * @example
94
- * ```ts
95
- * import { loadFloPay } from '@flopay/js';
96
- *
97
- * const flopay = await loadFloPay('pk_test_...');
98
- * const session = await flopay.retrieveSession('session_uuid');
99
- * console.log(session.status);
100
- * ```
101
- */
102
- declare function loadFloPay(publishableKey: string, options?: Omit<FloPayConfig, 'publishableKey'>): Promise<FloPay>;
103
-
104
- /**
105
- * Outcome the backend's `/3ds/complete` sync resolver returns to the SDK.
106
- * Mirrors `ThreeDsResolveOutcome` on the backend without importing it. The
107
- * caller branches on `status`:
108
- * - `succeeded` → show success
109
- * - `authorized` → a captured-later authorization (manual capture); as
110
- * terminal as `succeeded`
111
- * - `declined` → a decline (the session stays `pending`, so polling
112
- * session-status would just time out)
113
- * - `timeout` → the documented 3DS timeout
114
- * - `pending` / `requires_action` / `no_attempt` → fall back to the
115
- * session-status poll
116
- */
117
- type SavedCardChallengeOutcome = {
118
- status: 'succeeded';
119
- providerIntentId?: string | null;
120
- } | {
121
- status: 'authorized';
122
- providerIntentId?: string | null;
123
- } | {
124
- status: 'declined';
125
- providerIntentId?: string | null;
126
- declineReason?: string | null;
127
- gatewayDeclineReason?: string | null;
128
- } | {
129
- status: 'requires_action';
130
- providerIntentId?: string | null;
131
- nextActionRedirectUrl?: string | null;
132
- } | {
133
- status: 'pending';
134
- providerIntentId?: string | null;
135
- } | {
136
- status: 'timeout';
137
- providerIntentId?: string | null;
138
- } | {
139
- status: 'no_attempt';
140
- } | {
141
- status: 'unknown';
142
- };
143
- /** A `declined` outcome from `/3ds/complete`. */
144
- type SavedCardChallengeDecline = Extract<SavedCardChallengeOutcome, {
145
- status: 'declined';
146
- }>;
147
- /** Input for {@link runSavedCardChallenge}. */
148
- interface SavedCardChallengeInput {
149
- billingApiUrl: string;
150
- sessionId: string;
151
- /** Session-bound checkout token, sent as `x-checkout-session-token`. */
152
- nonce: string;
153
- /** The provider-hosted challenge the backend advertised for the attempt. */
154
- nextActionRedirectUrl: string;
155
- /**
156
- * Legacy flows poll `/3ds/complete` while the challenge is open; provider-neutral
157
- * saved cards complete once, only after the authenticated return. Defaults to polling.
158
- */
159
- pollCompletionEndpoint?: boolean;
160
- /**
161
- * Optional cancellation hook. SPA callers pass a signal tied to component
162
- * unmount / route change so an abandoned challenge tears down its overlay
163
- * (and rejects the promise) immediately.
164
- */
165
- signal?: AbortSignal;
166
- }
167
- /** Input for {@link completeSavedCardNextAction}. */
168
- interface SavedCardNextActionInput {
169
- billingApiUrl: string;
170
- sessionId: string;
171
- /** Session-bound checkout token, sent as `x-checkout-session-token`. */
172
- nonce: string;
173
- /** The provider-hosted challenge the backend advertised for the attempt. */
174
- nextActionRedirectUrl: string;
175
- /** Cancels the challenge (component unmount, route change). */
176
- signal?: AbortSignal;
177
- /**
178
- * Builds the error thrown for a `/3ds/complete` decline, so each framework
179
- * keeps its own decline mapping. Defaults to a `FloPayError` whose `code` is
180
- * the decline reason.
181
- */
182
- createDeclineError?: (decline: SavedCardChallengeDecline) => Error;
183
- }
184
- /** The buyer cancelled (or the owning UI unmounted) during a saved-card challenge. */
185
- declare function createSavedCardActionAbortedError(cause?: unknown): FloPayError;
186
- /**
187
- * Render a provider-hosted 3DS challenge in a full-page overlay iframe and
188
- * resolve once the buyer completes (or abandons) it. This is the one saved-card
189
- * challenge runner: `@flopay/react` and `@flopay/vue` both use it.
190
- *
191
- * The provider's challenge eventually redirects to `/v1/vault/3ds/return`,
192
- * which postMessages `flopay-vault-3ds-return` back to the parent (this
193
- * window). The promise resolves on receipt of that message — but only when it
194
- * arrives from the challenge iframe (`event.source`) and the billing API
195
- * origin, so a sibling frame on the merchant page can't dismiss the challenge
196
- * early by forging the marker string. We then call `/3ds/complete` to drive the
197
- * backend's sync resolver to write the terminal attempt row.
198
- *
199
- * The overlay carries `role="dialog"`/`aria-modal` and moves focus into the
200
- * iframe on mount, restoring the prior focus target on teardown, so keyboard /
201
- * screen-reader buyers aren't stranded on the obscured page.
202
- *
203
- * Times out after the 3DS challenge window with `three_ds_timeout`; an aborted
204
- * `signal` rejects with `three_ds_aborted`.
205
- */
206
- declare function runSavedCardChallenge(input: SavedCardChallengeInput): Promise<SavedCardChallengeOutcome>;
207
- /**
208
- * Complete a backend-owned saved-card challenge (`ACTION_REQUIRED` with a
209
- * `nextActionRedirectUrl`) with no browser payment provider: show the
210
- * challenge, post `/3ds/complete` once after the authenticated return, then
211
- * reconcile the session through the authenticated `/status` endpoint.
212
- *
213
- * The status poll also races the challenge, because a provider sandbox can
214
- * swallow the return-page message while the signed return endpoint still
215
- * resolves the attempt server-side.
216
- *
217
- * Resolves with the reconciled session. Rejects with a decline (built by
218
- * `createDeclineError`), `three_ds_timeout`, the status poll's own timeout, or
219
- * `three_ds_aborted`.
220
- */
221
- declare function completeSavedCardNextAction(input: SavedCardNextActionInput, api: Pick<PaymentAPI, 'waitForCheckoutSessionCompletion'>): Promise<NormalizedCheckoutSession>;
222
-
223
- /** Payment provider adapter backed by Stripe. */
224
- declare class StripeAdapter implements PaymentProviderAdapter {
225
- readonly name = "stripe";
226
- private stripe;
227
- initialize(config: FloPayConfig): Promise<void>;
228
- getRawProvider(): unknown;
229
- destroy(): void;
230
- }
231
-
232
- export { FloPay, PaymentAPI, type SavedCardChallengeDecline, type SavedCardChallengeInput, type SavedCardChallengeOutcome, type SavedCardNextActionInput, StripeAdapter, completeSavedCardNextAction, createCheckoutSession, createCheckoutSessionWithRetries, createSavedCardActionAbortedError, loadFloPay, runSavedCardChallenge };
1
+ export type { SentryEventLike, SentryStackFrameLike } from '@flopay/shared';
2
+ export { dropThirdPartyOnlyError } from '@flopay/shared';
3
+ export { createCheckoutSession, createCheckoutSessionWithRetries, } from './create-checkout-session.js';
4
+ export { FloPay } from './flopay.js';
5
+ export { loadFloPay } from './load.js';
6
+ export { PaymentAPI, SESSION_CREATE_TELEMETRY } from './payment-api.js';
7
+ export type { CardCaptureOperation, PciVaultCardCaptureConfig, } from './pci-vault-card-capture.js';
8
+ export { PciVaultCardCapture } from './pci-vault-card-capture.js';
9
+ export type { SavedCardChallengeDecline, SavedCardChallengeInput, SavedCardChallengeOutcome, SavedCardNextActionInput, } from './saved-card-action.js';
10
+ export { completeSavedCardNextAction, createSavedCardActionAbortedError, runSavedCardChallenge, } from './saved-card-action.js';
11
+ export type { SessionDisplayCacheData, SessionDisplayProduct, } from './session-display-cache.js';
12
+ export { cacheSessionDisplayData, clearSessionDisplayData, getSessionDisplayData, } from './session-display-cache.js';
13
+ export type { StripeSafeAppearance } from './stripe-adapter.js';
14
+ export { StripeAdapter, toStripeAppearance, toStripeAppearanceTheme } from './stripe-adapter.js';
package/dist/load.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import type { FloPayConfig } from '@flopay/shared';
2
+ import { type FloPay } from './flopay.js';
3
+ /**
4
+ * Loads and initializes the FloPay SDK.
5
+ *
6
+ * This is the primary entry point for consumer applications.
7
+ * It initializes the underlying payment provider (currently Stripe)
8
+ * and returns a ready-to-use `FloPay` instance.
9
+ *
10
+ * Instances are cached per complete behavior-affecting configuration.
11
+ * Matching calls return the same instance; calls with different billing API,
12
+ * telemetry, locale, API version, or appearance options receive independent
13
+ * instances.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { loadFloPay } from '@flopay/js';
18
+ *
19
+ * const flopay = await loadFloPay('pk_test_...');
20
+ * const session = await flopay.retrieveSession('session_uuid');
21
+ * console.log(session.status);
22
+ * ```
23
+ */
24
+ export declare function loadFloPay(publishableKey: string, options?: Omit<FloPayConfig, 'publishableKey'>): Promise<FloPay>;