@movmo_app/payments 0.7.0 → 0.8.0

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.ts CHANGED
@@ -73,41 +73,6 @@ export declare interface CardValidationState {
73
73
  */
74
74
  export declare const createMovmoAuthFetch: (options: CreateMovmoAuthFetchOptions) => typeof fetch;
75
75
 
76
- /**
77
- * Auth-aware `fetch` wrapper for `@movmo_app/payments`. The package's API
78
- * helpers call through `getPaymentsConfig().fetch`, bypassing whatever axios
79
- * interceptor stack the consumer wires up. Without this wrapper:
80
- *
81
- * - Session cookie expiry → silent 401/403 (no refresh, no logout).
82
- * - State-mutating endpoints → 403 because the CSRF cookie isn't echoed.
83
- * - Local-dev / multi-tenant flows → missing per-request headers like
84
- * `X-Movmo-Proxy-Auth` or `movmo-customer-id`.
85
- *
86
- * This factory replaces a ~95-line `paymentsFetch.ts` copy that was
87
- * duplicated across consumer apps. The contract:
88
- *
89
- * 1. CSRF token from `csrfCookieName` is set on every request as
90
- * `X-CSRF-Token` (matching the axios interceptor's unconditional set).
91
- * 2. `extraHeaders(input, init)` is invoked per-request to allow dynamic
92
- * headers (proxy-auth, customer id, etc.). Headers the caller already
93
- * set on `init.headers` win — `extraHeaders` only fills gaps.
94
- * 3. `credentials: 'include'` is forced so the session cookie travels.
95
- * 4. On a 401/403 from a non-auth endpoint, the wrapper calls
96
- * `refreshSession()` once (concurrent failures share one in-flight
97
- * promise) and retries the original request. If refresh ITSELF fails,
98
- * `onRefreshFailed(err)` fires so the consumer can drive a sign-out —
99
- * silently swallowing here would strand the user on a broken page.
100
- * Failures on the *retry* fetch are logged and the original response is
101
- * returned so the SDK still sees a Response to render an error from.
102
- * 5. The original fetch's network errors (offline, CORS, DNS) propagate.
103
- * Only retry-path failures are caught; pre-refresh errors are left for
104
- * the consumer to surface.
105
- *
106
- * The duplicated copies that this replaces both silently swallowed refresh
107
- * failure (see review issue #1 on both PR #47 + PR #180). Making
108
- * `onRefreshFailed` *required* enforces at the type level that consumers
109
- * wire up a logout path.
110
- */
111
76
  export declare interface CreateMovmoAuthFetchOptions {
112
77
  /**
113
78
  * Refreshes the session cookie. Called once on the first 401/403; concurrent
@@ -143,6 +108,11 @@ export declare interface CreateMovmoAuthFetchOptions {
143
108
  * infinite recursion when refresh returns 401. Defaults to `/v1/auth/`.
144
109
  */
145
110
  authPathFragment?: string;
111
+ /**
112
+ * 403 response `code`s that skip refresh + retry (the response is returned
113
+ * as-is). Defaults to {@link DEFAULT_NO_REFRESH_CODES}.
114
+ */
115
+ noRefreshCodes?: ReadonlySet<string>;
146
116
  /**
147
117
  * Underlying fetch impl. Defaults to `globalThis.fetch.bind(globalThis)`.
148
118
  * Override only for tests or non-browser environments.
@@ -155,6 +125,9 @@ export declare interface CreateMovmoAuthFetchOptions {
155
125
  readCookie?: (name: string) => string | null;
156
126
  }
157
127
 
128
+ /** 403 error codes that mean "refreshing will not help"; the wrapper returns them untouched. */
129
+ export declare const DEFAULT_NO_REFRESH_CODES: ReadonlySet<string>;
130
+
158
131
  /**
159
132
  * The cardholder/zip subset of {@link UpdatePaymentMethodPatch} that the Edit
160
133
  * flow (MOVMO-381) can mutate. Derived via `Pick` so it stays in sync if the
@@ -276,6 +249,12 @@ export declare interface PaymentManagerError {
276
249
  source: PaymentErrorSource;
277
250
  message: string;
278
251
  cause?: unknown;
252
+ /** HTTP status when the failure was an API response. */
253
+ status?: number;
254
+ /** Server error code (e.g. `recovery_cooldown`) when present. */
255
+ code?: string;
256
+ /** RFC3339 UTC end of a `recovery_cooldown`, when the server sent it. */
257
+ until?: string;
279
258
  }
280
259
 
281
260
  /**
@@ -448,6 +427,22 @@ export declare interface PaymentMethodSummary {
448
427
  zip?: string;
449
428
  }
450
429
 
430
+ /**
431
+ * Error thrown by every API helper on a non-2xx response. `code`/`until` come
432
+ * from the server's JSON error body (e.g. `recovery_cooldown`); `message` is
433
+ * user-facing (cool-down copy, the server `message`, or the helper's fallback).
434
+ */
435
+ export declare class PaymentsApiError extends Error {
436
+ readonly status: number;
437
+ readonly code?: string;
438
+ readonly until?: string;
439
+ constructor(message: string, opts: {
440
+ status: number;
441
+ code?: string;
442
+ until?: string;
443
+ });
444
+ }
445
+
451
446
  export declare interface PaymentsConfig {
452
447
  baseUrl: string;
453
448
  /**