@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.cjs CHANGED
@@ -632,6 +632,7 @@ var DEFAULT_PROCESSING_RETRY_AFTER_MS = 1e3;
632
632
  var MIN_PROCESSING_RETRY_AFTER_MS = 500;
633
633
  var DEFAULT_PROCESSING_TIMEOUT_MS = 15e3;
634
634
  var MAX_PROCESSING_RETRY_AFTER_MS = 3e3;
635
+ var DEFAULT_ACCOUNT_SNAPSHOT_TIMEOUT_MS = 1e4;
635
636
  function isRecord(value) {
636
637
  return typeof value === "object" && value !== null;
637
638
  }
@@ -639,6 +640,15 @@ function readString(payload, key) {
639
640
  const value = payload?.[key];
640
641
  return typeof value === "string" && value.trim() ? value : void 0;
641
642
  }
643
+ function readMessage(payload, key) {
644
+ const value = payload?.[key];
645
+ if (typeof value === "string") return value.trim() ? value : void 0;
646
+ if (Array.isArray(value)) {
647
+ const joined = value.filter((entry) => typeof entry === "string" && entry.trim().length > 0).join("; ");
648
+ return joined || void 0;
649
+ }
650
+ return void 0;
651
+ }
642
652
  function readNumber(payload, key) {
643
653
  const value = payload?.[key];
644
654
  return typeof value === "number" && Number.isFinite(value) ? value : void 0;
@@ -656,7 +666,7 @@ function createCheckoutProcessingTimeoutError() {
656
666
  async function buildApiErrorFromResponse(response, fallbackMessage) {
657
667
  const payload = await response.json().catch(() => null);
658
668
  const nestedError = isRecord(payload?.error) ? payload.error : null;
659
- const message = readString(payload, "message") ?? readString(nestedError, "message") ?? fallbackMessage;
669
+ const message = readMessage(payload, "message") ?? readMessage(nestedError, "message") ?? fallbackMessage;
660
670
  const code = readString(payload, "code") ?? readString(payload, "gatewayErrorCode") ?? readString(nestedError, "code") ?? `http_${response.status}`;
661
671
  return new import_shared3.FloPayError(message, "api_error", {
662
672
  code,
@@ -845,18 +855,33 @@ var PaymentAPI = class {
845
855
  * pre-pay PATCH would silently leave AVS unsent and cause an
846
856
  * AVS-protected charge to decline downstream.
847
857
  */
848
- async patchAccountSnapshot(sessionId, nonce, body) {
849
- const response = await fetchWithNetworkRetry(
850
- `${this.baseUrl}/v1/checkouts/sessions/${encodeURIComponent(sessionId)}/account`,
851
- {
852
- method: "PATCH",
853
- headers: {
854
- "Content-Type": "application/json",
855
- "x-checkout-session-token": nonce
856
- },
857
- body: JSON.stringify(body)
858
- }
859
- );
858
+ async patchAccountSnapshot(sessionId, nonce, body, options) {
859
+ const timeoutMs = options?.timeoutMs ?? DEFAULT_ACCOUNT_SNAPSHOT_TIMEOUT_MS;
860
+ const controller = new AbortController();
861
+ const onCallerAbort = () => controller.abort();
862
+ if (options?.signal) {
863
+ if (options.signal.aborted) controller.abort();
864
+ else options.signal.addEventListener("abort", onCallerAbort, { once: true });
865
+ }
866
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
867
+ let response;
868
+ try {
869
+ response = await fetchWithNetworkRetry(
870
+ `${this.baseUrl}/v1/checkouts/sessions/${encodeURIComponent(sessionId)}/account`,
871
+ {
872
+ method: "PATCH",
873
+ headers: {
874
+ "Content-Type": "application/json",
875
+ "x-checkout-session-token": nonce
876
+ },
877
+ body: JSON.stringify(body),
878
+ signal: controller.signal
879
+ }
880
+ );
881
+ } finally {
882
+ clearTimeout(timer);
883
+ options?.signal?.removeEventListener("abort", onCallerAbort);
884
+ }
860
885
  if (!response.ok) {
861
886
  throw await buildApiErrorFromResponse(response, "Failed to persist account snapshot");
862
887
  }