@flopay/shared 1.3.2 → 1.3.4

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/dist/index.d.cts CHANGED
@@ -1097,6 +1097,17 @@ interface CreateSessionParams {
1097
1097
  timeoutMs?: number;
1098
1098
  /** UTM and funnel tracking metadata. */
1099
1099
  utmMetadata?: Record<string, string | null | undefined>[];
1100
+ /**
1101
+ * Optional idempotency key identifying exactly **one** logical checkout
1102
+ * creation (TeamFloPay/backend#972). When supplied it is sent unchanged as
1103
+ * the `Idempotency-Key` header and reused across the SDK's transport retries,
1104
+ * so a timeout or lost response cannot mint a second session. Supply this to
1105
+ * keep the key stable across React remounts, multiple SDK instances, or
1106
+ * server retries you control; it **must not** be reused for a new purchase.
1107
+ * When omitted, the SDK generates a fresh, cryptographically random key per
1108
+ * call. Must be non-empty and at most 255 characters.
1109
+ */
1110
+ idempotencyKey?: string;
1100
1111
  }
1101
1112
  /**
1102
1113
  * Parameters for inline session creation via `FloPayCheckout.createSession`.
@@ -1141,6 +1152,16 @@ interface InlineSessionParams {
1141
1152
  tagsData?: TagsData;
1142
1153
  /** UTM and funnel tracking metadata. */
1143
1154
  utmMetadata?: Record<string, string | null | undefined>[];
1155
+ /**
1156
+ * Optional idempotency key identifying exactly **one** logical checkout
1157
+ * creation (TeamFloPay/backend#972). When supplied it is sent unchanged as
1158
+ * the `Idempotency-Key` header and reused across the SDK's transport retries.
1159
+ * Supply this to keep the key stable across React remounts, multiple SDK
1160
+ * instances, or server retries you control; it **must not** be reused for a
1161
+ * new purchase. When omitted, the SDK generates a fresh, cryptographically
1162
+ * random key per create. Must be non-empty and at most 255 characters.
1163
+ */
1164
+ idempotencyKey?: string;
1144
1165
  /** Whether AVS is enabled for this checkout. */
1145
1166
  avsCheck?: boolean;
1146
1167
  /** Checkout type: 'standard_checkout' or 'embedded_checkout'. */
@@ -1312,7 +1333,7 @@ declare function getConfiguredBillingApiUrl(): string;
1312
1333
  declare function getFloPayEnvironment(): FloPayEnvironment;
1313
1334
 
1314
1335
  /** Current SDK version. */
1315
- declare const SDK_VERSION = "1.3.2";
1336
+ declare const SDK_VERSION = "1.3.4";
1316
1337
  /**
1317
1338
  * HTTP header the SDK sends on `POST /v1/checkouts/sessions` so the backend
1318
1339
  * can decide whether to embed the vault capture block (the hosted PCI card
@@ -1907,4 +1928,60 @@ declare function isValidSecretKey(key: string): boolean;
1907
1928
  */
1908
1929
  declare function isSetupIntentClientSecret(clientSecret: string | null | undefined): boolean;
1909
1930
 
1910
- export { type AVSFieldConfig, BILLING_API_URL, BILLING_API_URL_PRODUCTION, BILLING_API_URL_STAGING, BOLD_DARK_APPEARANCE, BOLD_LIGHT_APPEARANCE, BUTTONS_LAYOUT_BOLD_DARK, BUTTONS_LAYOUT_BOLD_LIGHT, BUTTONS_LAYOUT_DARK, BUTTONS_LAYOUT_DEFAULT, BUTTONS_LAYOUT_GLASS_DARK, BUTTONS_LAYOUT_GLASS_LIGHT, BUTTONS_LAYOUT_MINIMAL, BUTTONS_LAYOUT_MODERN_DARK, BUTTONS_LAYOUT_MODERN_LIGHT, BUTTONS_LAYOUT_ROUNDED, type BeforeButtonClickEvent, type BillingDetails, type BillingProvider, type BuildCheckoutDisplayDataOptions, type ButtonsLayoutStyles, type ButtonsLayoutTheme, CA_PROVINCES, COUNTRY_OPTIONS, CURRENCY_MAP, type CardCaptureAdapter, type CardCaptureEventType, type CardCaptureMountOptions, type CardCaptureOutcomeEvent, type CardCaptureProviderId, type CheckoutAccount, type CheckoutButtonMethod, type CheckoutDisplayData, type CheckoutGateway, type CheckoutGateways, type CheckoutItem, type CheckoutMode, type CheckoutModeKind, type CheckoutProcessError, type CheckoutProcessingPending, type CheckoutProduct, type CheckoutProductType, type CheckoutSession, type CheckoutSessionProduct, type CheckoutSessionResult, type CheckoutSubscription, type ConfirmCardPaymentParams, type ConfirmCardPaymentResult, type ConfirmPaymentParams, type CountryOption, type CreateCustomerParams, type CreatePaymentMethodResult, type CreateSessionParams, type CurrencyInfo, type Customer, DEFAULT_API_BASE_URL, DEFAULT_API_VERSION, DEFAULT_APPEARANCE, DEFAULT_CURRENCY, type DeclineEvent, type DisplayLineItem, ELEMENT_TYPES, type ElementChangeEvent, type ElementOptions, type ElementType, FLAT_APPEARANCE, FLO_SDK_VERSION_HEADER, type FloPayAppearance, type FloPayConfig, type FloPayEnvironment, FloPayError, type FloPayErrorType, type FloPayThemeVariables, GLASS_DARK_APPEARANCE, GLASS_LIGHT_APPEARANCE, type GatewayEnvironment, type InlineSessionDraft, type InlineSessionParams, type InlineSessionPatch, type LineItem, MODERN_DARK_APPEARANCE, MODERN_LIGHT_APPEARANCE, type MountedElement, NIGHT_APPEARANCE, type NormalizedCheckoutSession, type NormalizedGatewayEnvironment, type PaymentProviderAdapter, type PaymentResult, type PriceData, type ProcessPaymentParams, type RecurringInterval, SDK_VERSION, STRIPE_EXPRESS_METHODS, STRIPE_METHOD_AMOUNT_LIMITS, STRIPE_METHOD_COUNTRIES, STRIPE_METHOD_CURRENCIES, STRIPE_METHOD_MATRIX, SUPPORTED_CARD_BRANDS, type StateOption, type StripeMethodEntry, type StripeMethodThemeVariant, THEMES, type TagsData, type ThemeBundle, type ThemeBundleId, type ThemeId, type TokenizedBody, US_STATES, type UpdateCustomerParams, type VaultCaptureBlock, type VaultCaptureResultMessage, type VaultCardFieldKey, type VaultCardThemeColors, type WebhookEvent, apiError, authenticationError, buildCheckoutDisplayData, buildItemPayload, buildProductPayload, buildSubscriptionPayload, configureFlopay, filterStripeMethodsByAmount, filterStripeMethodsByCountry, filterStripeMethodsByCurrency, foldIntoProducts, getConfiguredBillingApiUrl, getCountryByCode, getCurrencyByCountry, getFloPayEnvironment, getPostalCodeExample, getPostalCodeLabel, getStateFromPostalCode, getStateLabel, getStateOptions, getStripeMethodDisplayName, hasVendoredStripeMethodLogo, isAVSEnabled, isAVSFieldVisible, isPostalCodeSupported, isSetupIntentClientSecret, isValidPostalCode, isValidPublishableKey, isValidSecretKey, needsStripeMethodExplicitConfirm, networkError, normalizeGatewayEnvironment, partitionStripeMethods, rateLimitError, resolveAVSConfig, resolveBillingApiUrl, resolveButtonsLayoutTheme, resolveSessionCurrency, resolveStripeMethodBrandVariant, resolveTheme, stripeExpressMethodToOptionKey, validationError };
1931
+ /**
1932
+ * HTTP header the SDK sends to make checkout-session creation idempotent
1933
+ * (TeamFloPay/backend#972, paired SDK issue TeamFloPay/sdk#133).
1934
+ *
1935
+ * The backend treats the header as **optional**: when it is absent the legacy,
1936
+ * non-idempotent creation path runs unchanged. When present, every transport
1937
+ * retry of the same logical create reuses the same key so a timeout or lost
1938
+ * response cannot mint a second checkout session.
1939
+ */
1940
+ declare const IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
1941
+ /**
1942
+ * Maximum length of an idempotency key accepted by the billing API
1943
+ * (TeamFloPay/backend#972). Mirrors the widely-used 255-character ceiling;
1944
+ * automatically generated keys stay well under it.
1945
+ */
1946
+ declare const MAX_IDEMPOTENCY_KEY_LENGTH = 255;
1947
+ /**
1948
+ * Backend `code` (TeamFloPay/backend#972) returned when a checkout-create
1949
+ * replay arrives while the first request carrying the same key is still being
1950
+ * processed. It is a **retryable** in-progress response: the caller should
1951
+ * retry with the *same* key after a short backoff, never with a new key. This
1952
+ * is distinct from a payload-conflict (`409`), which is non-retryable.
1953
+ *
1954
+ * Mirrors a backend-defined code the same way the coupon error codes
1955
+ * (`CouponLimitExceeded`, `CouponCurrencyUnsupported`) mirror billing v1.1.2.
1956
+ */
1957
+ declare const IDEMPOTENCY_IN_PROGRESS_CODE = "IdempotencyKeyInProgress";
1958
+ /**
1959
+ * Generate a cryptographically random, high-entropy idempotency key.
1960
+ *
1961
+ * Prefers `crypto.randomUUID()` and falls back to 16 random bytes from
1962
+ * `crypto.getRandomValues`. Returns `undefined` when no cryptographically
1963
+ * secure RNG is available so the caller falls back to the legacy unkeyed path
1964
+ * rather than emitting a weak or predictable key.
1965
+ *
1966
+ * The key is never derived from request data, customer identity, or time, so
1967
+ * two independent operations never collide by construction.
1968
+ */
1969
+ declare function generateIdempotencyKey(): string | undefined;
1970
+ /**
1971
+ * Resolve the idempotency key for one logical checkout-create operation.
1972
+ *
1973
+ * - A merchant-supplied key is validated (non-empty, within
1974
+ * {@link MAX_IDEMPOTENCY_KEY_LENGTH}) and returned **unchanged** so it can be
1975
+ * preserved across React remounts, multiple SDK instances, or server retries
1976
+ * the merchant controls.
1977
+ * - Otherwise a fresh cryptographically random key is generated. When no secure
1978
+ * RNG is available this returns `undefined` and the caller omits the header,
1979
+ * preserving the legacy path.
1980
+ *
1981
+ * @throws FloPayError('validation_error') when a supplied key is empty,
1982
+ * whitespace-only, or exceeds the length limit. The offending value is never
1983
+ * included in the error message.
1984
+ */
1985
+ declare function resolveIdempotencyKey(supplied?: string): string | undefined;
1986
+
1987
+ export { type AVSFieldConfig, BILLING_API_URL, BILLING_API_URL_PRODUCTION, BILLING_API_URL_STAGING, BOLD_DARK_APPEARANCE, BOLD_LIGHT_APPEARANCE, BUTTONS_LAYOUT_BOLD_DARK, BUTTONS_LAYOUT_BOLD_LIGHT, BUTTONS_LAYOUT_DARK, BUTTONS_LAYOUT_DEFAULT, BUTTONS_LAYOUT_GLASS_DARK, BUTTONS_LAYOUT_GLASS_LIGHT, BUTTONS_LAYOUT_MINIMAL, BUTTONS_LAYOUT_MODERN_DARK, BUTTONS_LAYOUT_MODERN_LIGHT, BUTTONS_LAYOUT_ROUNDED, type BeforeButtonClickEvent, type BillingDetails, type BillingProvider, type BuildCheckoutDisplayDataOptions, type ButtonsLayoutStyles, type ButtonsLayoutTheme, CA_PROVINCES, COUNTRY_OPTIONS, CURRENCY_MAP, type CardCaptureAdapter, type CardCaptureEventType, type CardCaptureMountOptions, type CardCaptureOutcomeEvent, type CardCaptureProviderId, type CheckoutAccount, type CheckoutButtonMethod, type CheckoutDisplayData, type CheckoutGateway, type CheckoutGateways, type CheckoutItem, type CheckoutMode, type CheckoutModeKind, type CheckoutProcessError, type CheckoutProcessingPending, type CheckoutProduct, type CheckoutProductType, type CheckoutSession, type CheckoutSessionProduct, type CheckoutSessionResult, type CheckoutSubscription, type ConfirmCardPaymentParams, type ConfirmCardPaymentResult, type ConfirmPaymentParams, type CountryOption, type CreateCustomerParams, type CreatePaymentMethodResult, type CreateSessionParams, type CurrencyInfo, type Customer, DEFAULT_API_BASE_URL, DEFAULT_API_VERSION, DEFAULT_APPEARANCE, DEFAULT_CURRENCY, type DeclineEvent, type DisplayLineItem, ELEMENT_TYPES, type ElementChangeEvent, type ElementOptions, type ElementType, FLAT_APPEARANCE, FLO_SDK_VERSION_HEADER, type FloPayAppearance, type FloPayConfig, type FloPayEnvironment, FloPayError, type FloPayErrorType, type FloPayThemeVariables, GLASS_DARK_APPEARANCE, GLASS_LIGHT_APPEARANCE, type GatewayEnvironment, IDEMPOTENCY_IN_PROGRESS_CODE, IDEMPOTENCY_KEY_HEADER, type InlineSessionDraft, type InlineSessionParams, type InlineSessionPatch, type LineItem, MAX_IDEMPOTENCY_KEY_LENGTH, MODERN_DARK_APPEARANCE, MODERN_LIGHT_APPEARANCE, type MountedElement, NIGHT_APPEARANCE, type NormalizedCheckoutSession, type NormalizedGatewayEnvironment, type PaymentProviderAdapter, type PaymentResult, type PriceData, type ProcessPaymentParams, type RecurringInterval, SDK_VERSION, STRIPE_EXPRESS_METHODS, STRIPE_METHOD_AMOUNT_LIMITS, STRIPE_METHOD_COUNTRIES, STRIPE_METHOD_CURRENCIES, STRIPE_METHOD_MATRIX, SUPPORTED_CARD_BRANDS, type StateOption, type StripeMethodEntry, type StripeMethodThemeVariant, THEMES, type TagsData, type ThemeBundle, type ThemeBundleId, type ThemeId, type TokenizedBody, US_STATES, type UpdateCustomerParams, type VaultCaptureBlock, type VaultCaptureResultMessage, type VaultCardFieldKey, type VaultCardThemeColors, type WebhookEvent, apiError, authenticationError, buildCheckoutDisplayData, buildItemPayload, buildProductPayload, buildSubscriptionPayload, configureFlopay, filterStripeMethodsByAmount, filterStripeMethodsByCountry, filterStripeMethodsByCurrency, foldIntoProducts, generateIdempotencyKey, getConfiguredBillingApiUrl, getCountryByCode, getCurrencyByCountry, getFloPayEnvironment, getPostalCodeExample, getPostalCodeLabel, getStateFromPostalCode, getStateLabel, getStateOptions, getStripeMethodDisplayName, hasVendoredStripeMethodLogo, isAVSEnabled, isAVSFieldVisible, isPostalCodeSupported, isSetupIntentClientSecret, isValidPostalCode, isValidPublishableKey, isValidSecretKey, needsStripeMethodExplicitConfirm, networkError, normalizeGatewayEnvironment, partitionStripeMethods, rateLimitError, resolveAVSConfig, resolveBillingApiUrl, resolveButtonsLayoutTheme, resolveIdempotencyKey, resolveSessionCurrency, resolveStripeMethodBrandVariant, resolveTheme, stripeExpressMethodToOptionKey, validationError };
package/dist/index.d.ts CHANGED
@@ -1097,6 +1097,17 @@ interface CreateSessionParams {
1097
1097
  timeoutMs?: number;
1098
1098
  /** UTM and funnel tracking metadata. */
1099
1099
  utmMetadata?: Record<string, string | null | undefined>[];
1100
+ /**
1101
+ * Optional idempotency key identifying exactly **one** logical checkout
1102
+ * creation (TeamFloPay/backend#972). When supplied it is sent unchanged as
1103
+ * the `Idempotency-Key` header and reused across the SDK's transport retries,
1104
+ * so a timeout or lost response cannot mint a second session. Supply this to
1105
+ * keep the key stable across React remounts, multiple SDK instances, or
1106
+ * server retries you control; it **must not** be reused for a new purchase.
1107
+ * When omitted, the SDK generates a fresh, cryptographically random key per
1108
+ * call. Must be non-empty and at most 255 characters.
1109
+ */
1110
+ idempotencyKey?: string;
1100
1111
  }
1101
1112
  /**
1102
1113
  * Parameters for inline session creation via `FloPayCheckout.createSession`.
@@ -1141,6 +1152,16 @@ interface InlineSessionParams {
1141
1152
  tagsData?: TagsData;
1142
1153
  /** UTM and funnel tracking metadata. */
1143
1154
  utmMetadata?: Record<string, string | null | undefined>[];
1155
+ /**
1156
+ * Optional idempotency key identifying exactly **one** logical checkout
1157
+ * creation (TeamFloPay/backend#972). When supplied it is sent unchanged as
1158
+ * the `Idempotency-Key` header and reused across the SDK's transport retries.
1159
+ * Supply this to keep the key stable across React remounts, multiple SDK
1160
+ * instances, or server retries you control; it **must not** be reused for a
1161
+ * new purchase. When omitted, the SDK generates a fresh, cryptographically
1162
+ * random key per create. Must be non-empty and at most 255 characters.
1163
+ */
1164
+ idempotencyKey?: string;
1144
1165
  /** Whether AVS is enabled for this checkout. */
1145
1166
  avsCheck?: boolean;
1146
1167
  /** Checkout type: 'standard_checkout' or 'embedded_checkout'. */
@@ -1312,7 +1333,7 @@ declare function getConfiguredBillingApiUrl(): string;
1312
1333
  declare function getFloPayEnvironment(): FloPayEnvironment;
1313
1334
 
1314
1335
  /** Current SDK version. */
1315
- declare const SDK_VERSION = "1.3.2";
1336
+ declare const SDK_VERSION = "1.3.4";
1316
1337
  /**
1317
1338
  * HTTP header the SDK sends on `POST /v1/checkouts/sessions` so the backend
1318
1339
  * can decide whether to embed the vault capture block (the hosted PCI card
@@ -1907,4 +1928,60 @@ declare function isValidSecretKey(key: string): boolean;
1907
1928
  */
1908
1929
  declare function isSetupIntentClientSecret(clientSecret: string | null | undefined): boolean;
1909
1930
 
1910
- export { type AVSFieldConfig, BILLING_API_URL, BILLING_API_URL_PRODUCTION, BILLING_API_URL_STAGING, BOLD_DARK_APPEARANCE, BOLD_LIGHT_APPEARANCE, BUTTONS_LAYOUT_BOLD_DARK, BUTTONS_LAYOUT_BOLD_LIGHT, BUTTONS_LAYOUT_DARK, BUTTONS_LAYOUT_DEFAULT, BUTTONS_LAYOUT_GLASS_DARK, BUTTONS_LAYOUT_GLASS_LIGHT, BUTTONS_LAYOUT_MINIMAL, BUTTONS_LAYOUT_MODERN_DARK, BUTTONS_LAYOUT_MODERN_LIGHT, BUTTONS_LAYOUT_ROUNDED, type BeforeButtonClickEvent, type BillingDetails, type BillingProvider, type BuildCheckoutDisplayDataOptions, type ButtonsLayoutStyles, type ButtonsLayoutTheme, CA_PROVINCES, COUNTRY_OPTIONS, CURRENCY_MAP, type CardCaptureAdapter, type CardCaptureEventType, type CardCaptureMountOptions, type CardCaptureOutcomeEvent, type CardCaptureProviderId, type CheckoutAccount, type CheckoutButtonMethod, type CheckoutDisplayData, type CheckoutGateway, type CheckoutGateways, type CheckoutItem, type CheckoutMode, type CheckoutModeKind, type CheckoutProcessError, type CheckoutProcessingPending, type CheckoutProduct, type CheckoutProductType, type CheckoutSession, type CheckoutSessionProduct, type CheckoutSessionResult, type CheckoutSubscription, type ConfirmCardPaymentParams, type ConfirmCardPaymentResult, type ConfirmPaymentParams, type CountryOption, type CreateCustomerParams, type CreatePaymentMethodResult, type CreateSessionParams, type CurrencyInfo, type Customer, DEFAULT_API_BASE_URL, DEFAULT_API_VERSION, DEFAULT_APPEARANCE, DEFAULT_CURRENCY, type DeclineEvent, type DisplayLineItem, ELEMENT_TYPES, type ElementChangeEvent, type ElementOptions, type ElementType, FLAT_APPEARANCE, FLO_SDK_VERSION_HEADER, type FloPayAppearance, type FloPayConfig, type FloPayEnvironment, FloPayError, type FloPayErrorType, type FloPayThemeVariables, GLASS_DARK_APPEARANCE, GLASS_LIGHT_APPEARANCE, type GatewayEnvironment, type InlineSessionDraft, type InlineSessionParams, type InlineSessionPatch, type LineItem, MODERN_DARK_APPEARANCE, MODERN_LIGHT_APPEARANCE, type MountedElement, NIGHT_APPEARANCE, type NormalizedCheckoutSession, type NormalizedGatewayEnvironment, type PaymentProviderAdapter, type PaymentResult, type PriceData, type ProcessPaymentParams, type RecurringInterval, SDK_VERSION, STRIPE_EXPRESS_METHODS, STRIPE_METHOD_AMOUNT_LIMITS, STRIPE_METHOD_COUNTRIES, STRIPE_METHOD_CURRENCIES, STRIPE_METHOD_MATRIX, SUPPORTED_CARD_BRANDS, type StateOption, type StripeMethodEntry, type StripeMethodThemeVariant, THEMES, type TagsData, type ThemeBundle, type ThemeBundleId, type ThemeId, type TokenizedBody, US_STATES, type UpdateCustomerParams, type VaultCaptureBlock, type VaultCaptureResultMessage, type VaultCardFieldKey, type VaultCardThemeColors, type WebhookEvent, apiError, authenticationError, buildCheckoutDisplayData, buildItemPayload, buildProductPayload, buildSubscriptionPayload, configureFlopay, filterStripeMethodsByAmount, filterStripeMethodsByCountry, filterStripeMethodsByCurrency, foldIntoProducts, getConfiguredBillingApiUrl, getCountryByCode, getCurrencyByCountry, getFloPayEnvironment, getPostalCodeExample, getPostalCodeLabel, getStateFromPostalCode, getStateLabel, getStateOptions, getStripeMethodDisplayName, hasVendoredStripeMethodLogo, isAVSEnabled, isAVSFieldVisible, isPostalCodeSupported, isSetupIntentClientSecret, isValidPostalCode, isValidPublishableKey, isValidSecretKey, needsStripeMethodExplicitConfirm, networkError, normalizeGatewayEnvironment, partitionStripeMethods, rateLimitError, resolveAVSConfig, resolveBillingApiUrl, resolveButtonsLayoutTheme, resolveSessionCurrency, resolveStripeMethodBrandVariant, resolveTheme, stripeExpressMethodToOptionKey, validationError };
1931
+ /**
1932
+ * HTTP header the SDK sends to make checkout-session creation idempotent
1933
+ * (TeamFloPay/backend#972, paired SDK issue TeamFloPay/sdk#133).
1934
+ *
1935
+ * The backend treats the header as **optional**: when it is absent the legacy,
1936
+ * non-idempotent creation path runs unchanged. When present, every transport
1937
+ * retry of the same logical create reuses the same key so a timeout or lost
1938
+ * response cannot mint a second checkout session.
1939
+ */
1940
+ declare const IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
1941
+ /**
1942
+ * Maximum length of an idempotency key accepted by the billing API
1943
+ * (TeamFloPay/backend#972). Mirrors the widely-used 255-character ceiling;
1944
+ * automatically generated keys stay well under it.
1945
+ */
1946
+ declare const MAX_IDEMPOTENCY_KEY_LENGTH = 255;
1947
+ /**
1948
+ * Backend `code` (TeamFloPay/backend#972) returned when a checkout-create
1949
+ * replay arrives while the first request carrying the same key is still being
1950
+ * processed. It is a **retryable** in-progress response: the caller should
1951
+ * retry with the *same* key after a short backoff, never with a new key. This
1952
+ * is distinct from a payload-conflict (`409`), which is non-retryable.
1953
+ *
1954
+ * Mirrors a backend-defined code the same way the coupon error codes
1955
+ * (`CouponLimitExceeded`, `CouponCurrencyUnsupported`) mirror billing v1.1.2.
1956
+ */
1957
+ declare const IDEMPOTENCY_IN_PROGRESS_CODE = "IdempotencyKeyInProgress";
1958
+ /**
1959
+ * Generate a cryptographically random, high-entropy idempotency key.
1960
+ *
1961
+ * Prefers `crypto.randomUUID()` and falls back to 16 random bytes from
1962
+ * `crypto.getRandomValues`. Returns `undefined` when no cryptographically
1963
+ * secure RNG is available so the caller falls back to the legacy unkeyed path
1964
+ * rather than emitting a weak or predictable key.
1965
+ *
1966
+ * The key is never derived from request data, customer identity, or time, so
1967
+ * two independent operations never collide by construction.
1968
+ */
1969
+ declare function generateIdempotencyKey(): string | undefined;
1970
+ /**
1971
+ * Resolve the idempotency key for one logical checkout-create operation.
1972
+ *
1973
+ * - A merchant-supplied key is validated (non-empty, within
1974
+ * {@link MAX_IDEMPOTENCY_KEY_LENGTH}) and returned **unchanged** so it can be
1975
+ * preserved across React remounts, multiple SDK instances, or server retries
1976
+ * the merchant controls.
1977
+ * - Otherwise a fresh cryptographically random key is generated. When no secure
1978
+ * RNG is available this returns `undefined` and the caller omits the header,
1979
+ * preserving the legacy path.
1980
+ *
1981
+ * @throws FloPayError('validation_error') when a supplied key is empty,
1982
+ * whitespace-only, or exceeds the length limit. The offending value is never
1983
+ * included in the error message.
1984
+ */
1985
+ declare function resolveIdempotencyKey(supplied?: string): string | undefined;
1986
+
1987
+ export { type AVSFieldConfig, BILLING_API_URL, BILLING_API_URL_PRODUCTION, BILLING_API_URL_STAGING, BOLD_DARK_APPEARANCE, BOLD_LIGHT_APPEARANCE, BUTTONS_LAYOUT_BOLD_DARK, BUTTONS_LAYOUT_BOLD_LIGHT, BUTTONS_LAYOUT_DARK, BUTTONS_LAYOUT_DEFAULT, BUTTONS_LAYOUT_GLASS_DARK, BUTTONS_LAYOUT_GLASS_LIGHT, BUTTONS_LAYOUT_MINIMAL, BUTTONS_LAYOUT_MODERN_DARK, BUTTONS_LAYOUT_MODERN_LIGHT, BUTTONS_LAYOUT_ROUNDED, type BeforeButtonClickEvent, type BillingDetails, type BillingProvider, type BuildCheckoutDisplayDataOptions, type ButtonsLayoutStyles, type ButtonsLayoutTheme, CA_PROVINCES, COUNTRY_OPTIONS, CURRENCY_MAP, type CardCaptureAdapter, type CardCaptureEventType, type CardCaptureMountOptions, type CardCaptureOutcomeEvent, type CardCaptureProviderId, type CheckoutAccount, type CheckoutButtonMethod, type CheckoutDisplayData, type CheckoutGateway, type CheckoutGateways, type CheckoutItem, type CheckoutMode, type CheckoutModeKind, type CheckoutProcessError, type CheckoutProcessingPending, type CheckoutProduct, type CheckoutProductType, type CheckoutSession, type CheckoutSessionProduct, type CheckoutSessionResult, type CheckoutSubscription, type ConfirmCardPaymentParams, type ConfirmCardPaymentResult, type ConfirmPaymentParams, type CountryOption, type CreateCustomerParams, type CreatePaymentMethodResult, type CreateSessionParams, type CurrencyInfo, type Customer, DEFAULT_API_BASE_URL, DEFAULT_API_VERSION, DEFAULT_APPEARANCE, DEFAULT_CURRENCY, type DeclineEvent, type DisplayLineItem, ELEMENT_TYPES, type ElementChangeEvent, type ElementOptions, type ElementType, FLAT_APPEARANCE, FLO_SDK_VERSION_HEADER, type FloPayAppearance, type FloPayConfig, type FloPayEnvironment, FloPayError, type FloPayErrorType, type FloPayThemeVariables, GLASS_DARK_APPEARANCE, GLASS_LIGHT_APPEARANCE, type GatewayEnvironment, IDEMPOTENCY_IN_PROGRESS_CODE, IDEMPOTENCY_KEY_HEADER, type InlineSessionDraft, type InlineSessionParams, type InlineSessionPatch, type LineItem, MAX_IDEMPOTENCY_KEY_LENGTH, MODERN_DARK_APPEARANCE, MODERN_LIGHT_APPEARANCE, type MountedElement, NIGHT_APPEARANCE, type NormalizedCheckoutSession, type NormalizedGatewayEnvironment, type PaymentProviderAdapter, type PaymentResult, type PriceData, type ProcessPaymentParams, type RecurringInterval, SDK_VERSION, STRIPE_EXPRESS_METHODS, STRIPE_METHOD_AMOUNT_LIMITS, STRIPE_METHOD_COUNTRIES, STRIPE_METHOD_CURRENCIES, STRIPE_METHOD_MATRIX, SUPPORTED_CARD_BRANDS, type StateOption, type StripeMethodEntry, type StripeMethodThemeVariant, THEMES, type TagsData, type ThemeBundle, type ThemeBundleId, type ThemeId, type TokenizedBody, US_STATES, type UpdateCustomerParams, type VaultCaptureBlock, type VaultCaptureResultMessage, type VaultCardFieldKey, type VaultCardThemeColors, type WebhookEvent, apiError, authenticationError, buildCheckoutDisplayData, buildItemPayload, buildProductPayload, buildSubscriptionPayload, configureFlopay, filterStripeMethodsByAmount, filterStripeMethodsByCountry, filterStripeMethodsByCurrency, foldIntoProducts, generateIdempotencyKey, getConfiguredBillingApiUrl, getCountryByCode, getCurrencyByCountry, getFloPayEnvironment, getPostalCodeExample, getPostalCodeLabel, getStateFromPostalCode, getStateLabel, getStateOptions, getStripeMethodDisplayName, hasVendoredStripeMethodLogo, isAVSEnabled, isAVSFieldVisible, isPostalCodeSupported, isSetupIntentClientSecret, isValidPostalCode, isValidPublishableKey, isValidSecretKey, needsStripeMethodExplicitConfirm, networkError, normalizeGatewayEnvironment, partitionStripeMethods, rateLimitError, resolveAVSConfig, resolveBillingApiUrl, resolveButtonsLayoutTheme, resolveIdempotencyKey, resolveSessionCurrency, resolveStripeMethodBrandVariant, resolveTheme, stripeExpressMethodToOptionKey, validationError };
package/dist/index.mjs CHANGED
@@ -79,7 +79,7 @@ var PAYMENT_METHOD_LOGOS = {
79
79
  };
80
80
 
81
81
  // src/constants.ts
82
- var SDK_VERSION = "1.3.2";
82
+ var SDK_VERSION = "1.3.4";
83
83
  var FLO_SDK_VERSION_HEADER = "x-flo-sdk-version";
84
84
  var BILLING_API_URL_STAGING = "https://api.stage.flopay.com";
85
85
  var BILLING_API_URL_PRODUCTION = "https://api.flopay.com";
@@ -2157,6 +2157,49 @@ function isValidSecretKey(key) {
2157
2157
  function isSetupIntentClientSecret(clientSecret) {
2158
2158
  return typeof clientSecret === "string" && clientSecret.startsWith("seti_");
2159
2159
  }
2160
+
2161
+ // src/idempotency.ts
2162
+ var IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
2163
+ var MAX_IDEMPOTENCY_KEY_LENGTH = 255;
2164
+ var IDEMPOTENCY_IN_PROGRESS_CODE = "IdempotencyKeyInProgress";
2165
+ function getSecureRandomSource() {
2166
+ const source = globalThis.crypto;
2167
+ if (!source) return void 0;
2168
+ if (typeof source.randomUUID === "function" || typeof source.getRandomValues === "function") {
2169
+ return source;
2170
+ }
2171
+ return void 0;
2172
+ }
2173
+ function generateIdempotencyKey() {
2174
+ const source = getSecureRandomSource();
2175
+ if (!source) return void 0;
2176
+ if (typeof source.randomUUID === "function") {
2177
+ return source.randomUUID();
2178
+ }
2179
+ const bytes = new Uint8Array(16);
2180
+ source.getRandomValues(bytes);
2181
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
2182
+ }
2183
+ function resolveIdempotencyKey(supplied) {
2184
+ if (supplied === void 0) {
2185
+ return generateIdempotencyKey();
2186
+ }
2187
+ if (typeof supplied !== "string" || supplied.trim() === "") {
2188
+ throw new FloPayError(
2189
+ "idempotencyKey must be a non-empty string identifying exactly one checkout creation.",
2190
+ "validation_error",
2191
+ { code: "InvalidIdempotencyKey", param: "idempotencyKey" }
2192
+ );
2193
+ }
2194
+ if (supplied.length > MAX_IDEMPOTENCY_KEY_LENGTH) {
2195
+ throw new FloPayError(
2196
+ `idempotencyKey must be at most ${MAX_IDEMPOTENCY_KEY_LENGTH} characters.`,
2197
+ "validation_error",
2198
+ { code: "InvalidIdempotencyKey", param: "idempotencyKey" }
2199
+ );
2200
+ }
2201
+ return supplied;
2202
+ }
2160
2203
  export {
2161
2204
  BILLING_API_URL,
2162
2205
  BILLING_API_URL_PRODUCTION,
@@ -2186,6 +2229,9 @@ export {
2186
2229
  FloPayError,
2187
2230
  GLASS_DARK_APPEARANCE,
2188
2231
  GLASS_LIGHT_APPEARANCE,
2232
+ IDEMPOTENCY_IN_PROGRESS_CODE,
2233
+ IDEMPOTENCY_KEY_HEADER,
2234
+ MAX_IDEMPOTENCY_KEY_LENGTH,
2189
2235
  MODERN_DARK_APPEARANCE,
2190
2236
  MODERN_LIGHT_APPEARANCE,
2191
2237
  NIGHT_APPEARANCE,
@@ -2209,6 +2255,7 @@ export {
2209
2255
  filterStripeMethodsByCountry,
2210
2256
  filterStripeMethodsByCurrency,
2211
2257
  foldIntoProducts,
2258
+ generateIdempotencyKey,
2212
2259
  getConfiguredBillingApiUrl,
2213
2260
  getCountryByCode,
2214
2261
  getCurrencyByCountry,
@@ -2235,6 +2282,7 @@ export {
2235
2282
  resolveAVSConfig,
2236
2283
  resolveBillingApiUrl,
2237
2284
  resolveButtonsLayoutTheme,
2285
+ resolveIdempotencyKey,
2238
2286
  resolveSessionCurrency,
2239
2287
  resolveStripeMethodBrandVariant,
2240
2288
  resolveTheme,