@flopay/js 1.3.0 → 1.3.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/dist/index.d.cts CHANGED
@@ -432,6 +432,9 @@ declare class PaymentAPI {
432
432
  };
433
433
  avsCheck?: boolean;
434
434
  avsConfig?: Record<string, unknown>;
435
+ }, options?: {
436
+ signal?: AbortSignal;
437
+ timeoutMs?: number;
435
438
  }): Promise<void>;
436
439
  /**
437
440
  * Create a PaymentIntent on the backend.
package/dist/index.d.ts CHANGED
@@ -432,6 +432,9 @@ declare class PaymentAPI {
432
432
  };
433
433
  avsCheck?: boolean;
434
434
  avsConfig?: Record<string, unknown>;
435
+ }, options?: {
436
+ signal?: AbortSignal;
437
+ timeoutMs?: number;
435
438
  }): Promise<void>;
436
439
  /**
437
440
  * Create a PaymentIntent on the backend.
package/dist/index.mjs CHANGED
@@ -593,6 +593,7 @@ var DEFAULT_PROCESSING_RETRY_AFTER_MS = 1e3;
593
593
  var MIN_PROCESSING_RETRY_AFTER_MS = 500;
594
594
  var DEFAULT_PROCESSING_TIMEOUT_MS = 15e3;
595
595
  var MAX_PROCESSING_RETRY_AFTER_MS = 3e3;
596
+ var DEFAULT_ACCOUNT_SNAPSHOT_TIMEOUT_MS = 1e4;
596
597
  function isRecord(value) {
597
598
  return typeof value === "object" && value !== null;
598
599
  }
@@ -600,6 +601,15 @@ function readString(payload, key) {
600
601
  const value = payload?.[key];
601
602
  return typeof value === "string" && value.trim() ? value : void 0;
602
603
  }
604
+ function readMessage(payload, key) {
605
+ const value = payload?.[key];
606
+ if (typeof value === "string") return value.trim() ? value : void 0;
607
+ if (Array.isArray(value)) {
608
+ const joined = value.filter((entry) => typeof entry === "string" && entry.trim().length > 0).join("; ");
609
+ return joined || void 0;
610
+ }
611
+ return void 0;
612
+ }
603
613
  function readNumber(payload, key) {
604
614
  const value = payload?.[key];
605
615
  return typeof value === "number" && Number.isFinite(value) ? value : void 0;
@@ -617,7 +627,7 @@ function createCheckoutProcessingTimeoutError() {
617
627
  async function buildApiErrorFromResponse(response, fallbackMessage) {
618
628
  const payload = await response.json().catch(() => null);
619
629
  const nestedError = isRecord(payload?.error) ? payload.error : null;
620
- const message = readString(payload, "message") ?? readString(nestedError, "message") ?? fallbackMessage;
630
+ const message = readMessage(payload, "message") ?? readMessage(nestedError, "message") ?? fallbackMessage;
621
631
  const code = readString(payload, "code") ?? readString(payload, "gatewayErrorCode") ?? readString(nestedError, "code") ?? `http_${response.status}`;
622
632
  return new FloPayError3(message, "api_error", {
623
633
  code,
@@ -806,18 +816,33 @@ var PaymentAPI = class {
806
816
  * pre-pay PATCH would silently leave AVS unsent and cause an
807
817
  * AVS-protected charge to decline downstream.
808
818
  */
809
- async patchAccountSnapshot(sessionId, nonce, body) {
810
- const response = await fetchWithNetworkRetry(
811
- `${this.baseUrl}/v1/checkouts/sessions/${encodeURIComponent(sessionId)}/account`,
812
- {
813
- method: "PATCH",
814
- headers: {
815
- "Content-Type": "application/json",
816
- "x-checkout-session-token": nonce
817
- },
818
- body: JSON.stringify(body)
819
- }
820
- );
819
+ async patchAccountSnapshot(sessionId, nonce, body, options) {
820
+ const timeoutMs = options?.timeoutMs ?? DEFAULT_ACCOUNT_SNAPSHOT_TIMEOUT_MS;
821
+ const controller = new AbortController();
822
+ const onCallerAbort = () => controller.abort();
823
+ if (options?.signal) {
824
+ if (options.signal.aborted) controller.abort();
825
+ else options.signal.addEventListener("abort", onCallerAbort, { once: true });
826
+ }
827
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
828
+ let response;
829
+ try {
830
+ response = await fetchWithNetworkRetry(
831
+ `${this.baseUrl}/v1/checkouts/sessions/${encodeURIComponent(sessionId)}/account`,
832
+ {
833
+ method: "PATCH",
834
+ headers: {
835
+ "Content-Type": "application/json",
836
+ "x-checkout-session-token": nonce
837
+ },
838
+ body: JSON.stringify(body),
839
+ signal: controller.signal
840
+ }
841
+ );
842
+ } finally {
843
+ clearTimeout(timer);
844
+ options?.signal?.removeEventListener("abort", onCallerAbort);
845
+ }
821
846
  if (!response.ok) {
822
847
  throw await buildApiErrorFromResponse(response, "Failed to persist account snapshot");
823
848
  }