@movmo/express-checkout-button 1.13.1 → 2.0.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/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  A React component for integrating Movmo's Express Checkout functionality into airline websites.
4
4
 
5
+ **2.0:** clicking the button now navigates the whole tab to Movmo checkout and Movmo sends the
6
+ traveler back to your page. The in-page overlay, the `/movmo/checkout` route and the
7
+ `postMessage` listener are gone. See [Redirect and return](#redirect-and-return).
8
+
5
9
  ## Installation
6
10
 
7
11
  ```bash
@@ -90,8 +94,9 @@ export default MyBookingPage;
90
94
  | `flightOfferID` | string | No\* | The ID of a pre-saved flight offer. Required if `flightOffer` is not provided |
91
95
  | `isProd` | boolean | No | Whether to use production endpoints (default: false). When true, uses production API and flights URLs; when false, uses e2e (testing) endpoints |
92
96
  | `className` | string | No | Extra CSS classes merged onto the button element |
93
- | `onExit` | function| No | `(info: MovmoCheckoutExitInfo) => void` — called when the checkout overlay hands control back to your page. `info.reason` is `'booking_confirmed'` (traveler clicked "Return to airline" after a successful booking — a booking-complete callback already fired for it), `'offer_unavailable'` (the offer expired/became unbookable), or `'search_again'` |
94
- | `onBookingComplete` | function| No | `(info: MovmoBookingCompleteInfo) => void` — called once per booking while the traveler is still on Movmo's confirmation screen, before any later `onExit({ reason: 'booking_confirmed' })`. `info.bookingId` is Movmo's booking id; `info.airlinePnr` is the airline's own record locator (absent if the provider returned none); `info.airlineRef` is the airline IATA/company code, not the PNR. Does not re-fire after a page refresh inside the checkout, and is deduped so a replayed message for a booking already reported won't call it twice |
97
+ | `returnUrl` | string | No | Where Movmo sends the traveler back to. Default: the page URL at click with every `movmo_*` query param removed and the other params kept; the fragment is kept only when it is a router route (`#/` or `#!/`), otherwise dropped. **`returnUrl` is sent to Movmo (CloudFront logs the query string):** pass an explicit `returnUrl` when your page URL carries tokens or PII. Must be on an origin registered with Movmo, otherwise the traveler gets no return link |
98
+ | `onExit` | function| No | `(info: MovmoCheckoutExitInfo) => void` — called when the traveler returns from Movmo checkout. `info.reason` is `'booking_confirmed'` (traveler clicked "Return to airline" after a successful booking — `onBookingComplete` has already fired when the return carried a `movmo_booking_id`), `'offer_unavailable'` (the offer expired/became unbookable), or `'search_again'` ("Back to airline" or a non-retryable failure). Not called if the traveler never returns |
99
+ | `onBookingComplete` | function| No | `(info: MovmoBookingCompleteInfo) => void` — called once on return from a confirmed booking, immediately before `onExit({ reason: 'booking_confirmed' })`. `info.bookingId` is Movmo's booking id; `info.airlinePnr` is the airline's own record locator (absent if the provider returned none); `info.airlineRef` is the airline IATA/company code, not the PNR |
95
100
  | `onError` | function| No | `(error: MovmoCheckoutError) => void` — called when the button hits a failure it can't recover from on its own: `{ stage: 'save_offer', status?, message }` when the click-time raw-offer save fails (a non-2xx response, a network error, or a timeout), or `{ stage: 'missing_offer', message }` when neither `flightOffer` nor `flightOfferID` was provided. `status` is the HTTP status code when the failure was a non-2xx response; it's omitted for network errors, timeouts, and the `missing_offer` stage. The button always logs a `console.warn` too, whether or not `onError` is provided |
96
101
 
97
102
  \*Note: Either `flightOffer` or `flightOfferID` must be provided, but not both.
@@ -121,11 +126,50 @@ export default MyBookingPage;
121
126
  />
122
127
  ```
123
128
 
124
- The raw `MOVMO_BOOKING_COMPLETE` `postMessage` still works if you already listen for it
125
- yourself — `onBookingComplete` is the preferred, typed way to get the same data. Either way,
126
- the PNR never appears in the page URL: the parent's `replaceState` after a booking only ever
127
- carries `bookingId`/`airlineRef`/`providerId`, so it can't leak into browser history, analytics
128
- or tag-manager tools, session replay, or a server log/Referer on refresh.
129
+ ## Redirect and return
130
+
131
+ > **`onBookingComplete` and `onExit` are unauthenticated browser signals.** The traveler can edit
132
+ > the return URL, so the callbacks prove nothing. Never use them to fulfil an order, award
133
+ > loyalty, or mark anything paid. Confirm the booking server-side with Movmo (a server-side booking lookup is planned) before acting on it. The nonce only guards against a stray or
134
+ > replayed return in the same tab, not against the traveler.
135
+
136
+ | Step | What happens |
137
+ | ---- | ------------ |
138
+ | Click | The button saves the offer (if you passed `flightOffer`), stores a one-time `state` nonce in `sessionStorage['movmo:checkout:pending']`, then runs `location.assign('https://flights.movmo.io/booking?offerId=…&returnUrl=…&state=…')`. No `/movmo/checkout` route and no `frame-src` CSP entry are needed. |
139
+ | Return | Movmo navigates to your `returnUrl` with `movmo_exit` (`search_again`, `offer_unavailable`, `booking_confirmed`), `movmo_state` (echo of your nonce) and, when booked, `movmo_booking_id`. The airline PNR is in the URL **fragment** only: `#movmo_pnr=ABC123`, or inside your hash route (`#/checkout?movmo_pnr=ABC123`, `#/r?a=1&movmo_pnr=ABC123`). |
140
+ | Consume | On mount the button reads those params. If `movmo_state` matches the stored nonce it calls `onBookingComplete` (confirmed bookings only), then `onExit`, and clears the nonce. A mismatch or missing nonce logs a warning and calls nothing. The `movmo_*` params are removed from the address bar with `history.replaceState` on every call (also when there is no return, for leftovers), keeping your own query and hash byte for byte. A pending record is single-use and expires after 24 hours. With two buttons on one page, the return is held for the button whose airline, provider and offer match the click, and the URL is scrubbed immediately. |
141
+
142
+ The callbacks fire on whichever page loads at `returnUrl`, so mount the button there, or call
143
+ `consumeMovmoCheckoutReturn` (ESM) / `window.MovmoExpressCheckout.consumeReturn` (script tag) on
144
+ pages that do not render it. A page-level call claims whatever return is pending and takes the
145
+ airline, provider and environment (`isProd`) from the record written at click; pass `isProd`
146
+ only as a fallback:
147
+
148
+ ```js
149
+ import { consumeMovmoCheckoutReturn } from '@movmo/express-checkout-button';
150
+
151
+ consumeMovmoCheckoutReturn({
152
+ isProd: true,
153
+ onBookingComplete: (info) => saveConfirmation(info),
154
+ onExit: ({ reason }) => route(reason),
155
+ });
156
+ ```
157
+
158
+ Notes:
159
+
160
+ - The PNR is in the fragment, so it is never sent to a server or in a `Referer` header. The
161
+ committed URL, fragment included, is in browser history until the scrub runs, and any script
162
+ that reads `location` earlier sees it: call `consumeMovmoCheckoutReturn` / `consumeReturn` as
163
+ early as possible, before analytics or session-replay scripts.
164
+ - Hash routers: keep `returnUrl` on the same route that mounts the button or calls
165
+ `consumeReturn`; the PNR is appended inside your existing hash.
166
+ - A throwing callback is caught and logged. Consumption runs once per page load.
167
+ - Build-time overrides (`REACT_APP_MOVMO_CHECKOUT_URL`, `REACT_APP_MOVMO_CHECKOUT_API_URL`,
168
+ `REACT_APP_MOVMO_ANALYTICS_URL`) work in the ESM/CJS builds only, are read at runtime from
169
+ `process.env` (not inlined by this package), and are accepted only for `https://*.movmo.io` or
170
+ `http://localhost` / `http://127.0.0.1`. The script-tag build ignores them entirely.
171
+ - If `crypto` is unavailable the redirect still happens without a `state`, and the return is
172
+ ignored (callbacks need a verified nonce).
129
173
 
130
174
  ## Provider Options
131
175
 
@@ -160,7 +204,7 @@ there is nothing else to include. It defines `window.MovmoExpressCheckout`:
160
204
 
161
205
  ```html
162
206
  <div id="movmo-checkout"></div>
163
- <script src="https://cdn.e2e.movmo.io/sdk/express-checkout/v1/express-checkout.js"></script>
207
+ <script src="https://cdn.e2e.movmo.io/sdk/express-checkout/v2/express-checkout.js"></script>
164
208
  <script>
165
209
  var handle = window.MovmoExpressCheckout.mount('#movmo-checkout', {
166
210
  iataCode: 'AA',
@@ -170,16 +214,19 @@ there is nothing else to include. It defines `window.MovmoExpressCheckout`:
170
214
  // isProd: true — add when you go live
171
215
  });
172
216
  // handle.unmount() removes the button; window.MovmoExpressCheckout.version reports the SDK version
217
+ // Callbacks (onExit, onBookingComplete) fire when the traveler returns to this page.
173
218
  </script>
174
219
  ```
175
220
 
176
221
  `mount(target, options)` accepts a CSS selector or an Element (it throws a clear error when a
177
222
  selector matches nothing) and takes the same options as the React component's props, including
178
- `onExit`, `onError`, and `onBookingComplete` — all pass straight through. Calling `mount()`
179
- again on the same element logs a warning and returns the existing handle instead of
223
+ `returnUrl`, `onExit`, `onError`, and `onBookingComplete` — all pass straight through. `mount()`
224
+ also consumes a pending return (see [Redirect and return](#redirect-and-return)), and
225
+ `window.MovmoExpressCheckout.consumeReturn(options)` does so on pages that do not mount the
226
+ button. Calling `mount()` again on the same element logs a warning and returns the existing handle instead of
180
227
  double-rendering.
181
228
 
182
- The `/v1/` URL above is a **mutable major-version alias** — it always serves the latest 1.x
229
+ The `/v2/` URL above is a **mutable major-version alias** — it always serves the latest 2.x
183
230
  release, so new releases apply automatically with no change on your side. Convenient for e2e
184
231
  and demo pages, but not immutable — don't pin CI or production configs to it by name.
185
232
 
@@ -211,40 +258,34 @@ are the primary, documented way to load the script tag build.
211
258
 
212
259
  When the host page URL carries `?mv_internal=1`, the button flags its own analytics events as
213
260
  internal traffic and appends `mv_internal=1` to the checkout URL, so the entire embedded session
214
- (button + Movmo checkout iframe) is excluded from partner-facing KPIs. Use it on demo, QA, and
261
+ (button + Movmo checkout) is excluded from partner-facing KPIs. Use it on demo, QA, and
215
262
  test pages; it is sticky per tab and entirely fail-open.
216
263
 
217
264
  ## Analytics (scoped)
218
265
 
219
- `MovmoCheckoutButton` self-instruments the pre-iframe funnel — from the button rendering on
220
- the airline page through the traveler landing inside the Movmo checkout — using
266
+ `MovmoCheckoutButton` self-instruments the partner-page funnel — from the button rendering on
267
+ the airline page through the redirect to Movmo and the return — using
221
268
  `@movmo_app/analytics` in **scoped mode**. Scoped mode disables every document-level listener
222
269
  the SDK would otherwise install (click/rage-click/hover/scroll/field/section autocapture);
223
- the button only ever attaches listeners to its own DOM node and the checkout overlay it
224
- creates. It never observes the partner's page, reads partner form fields, or inspects
225
- anything outside those two elements. The airline identifier passed as `iataCode` becomes
226
- `partner_id`, and the partner page's **hostname** is the only page context transmitted —
227
- never the path, full URL, referrer, page content, or DOM structure.
228
-
229
- Ten events cover the funnel:
230
-
231
- | Event | Fires when |
232
- | ------------------------------ | ------------------------------------------------------------------------ |
233
- | `plugin_loaded` | The button mounts and the scoped tracker initializes |
234
- | `button_viewed` | The button crosses 50% viewport visibility (once per mount) |
235
- | `button_hovered` | The pointer leaves the button after a ≥200ms hover |
236
- | `button_clicked` | The button is clicked |
237
- | `offer_save_started` | A raw flight offer begins saving (no pre-saved `flightOfferID`) |
238
- | `offer_save_succeeded` | The offer save call returns an offer ID |
239
- | `offer_save_failed` | The offer save call returns no offer ID (previously a silent no-op) |
240
- | `overlay_opened` | The checkout overlay iframe is created |
241
- | `iframe_ready` | The embedded flights-ui document sends its first `MOVMO_READY` handshake |
242
- | `overlay_abandoned_pre_iframe` | The overlay is torn down before `MOVMO_READY` was ever seen |
243
-
244
- `iframe_ready` and `overlay_abandoned_pre_iframe` are mutually exclusive per overlay open —
245
- whichever happens first wins, and neither fires again until the overlay is reopened. Both
246
- carry a `ms_since_open` property so you can track how long the iframe took to load or how
247
- quickly a traveler bounced.
270
+ the button only ever attaches listeners to its own DOM node. It never observes the partner's
271
+ page, reads partner form fields, or inspects anything outside that element. The airline
272
+ identifier passed as `iataCode` becomes `partner_id`, and the partner page's **hostname** is
273
+ the only page context transmitted — never the path, full URL, referrer, page content, or DOM
274
+ structure.
275
+
276
+ Nine events cover the funnel:
277
+
278
+ | Event | Fires when |
279
+ | --------------------------- | ----------------------------------------------------------------------- |
280
+ | `plugin_loaded` | The button mounts and the scoped tracker initializes |
281
+ | `button_viewed` | The button crosses 50% viewport visibility (once per mount) |
282
+ | `button_hovered` | The pointer leaves the button after a ≥200ms hover |
283
+ | `button_clicked` | The button is clicked |
284
+ | `offer_save_started` | A raw flight offer begins saving (no pre-saved `flightOfferID`) |
285
+ | `offer_save_succeeded` | The offer save call returns an offer ID |
286
+ | `offer_save_failed` | The offer save call returns no offer ID (previously a silent no-op) |
287
+ | `checkout_redirect_started` | Just before the page navigates to Movmo checkout |
288
+ | `checkout_returned` | A verified return is consumed; carries `reason` and `ms_away` |
248
289
 
249
290
  Every tracking call is fail-open: analytics never throws, and a network or init failure
250
291
  never blocks or delays checkout.
@@ -253,10 +294,10 @@ never blocks or delays checkout.
253
294
 
254
295
  - The analytics ingest endpoint defaults to `https://api.movmo.io/v1/t` (prod) /
255
296
  `https://e2e.api.movmo.io/v1/t` (e2e), selected by the same `isProd` prop as the checkout
256
- URL. Override it with `REACT_APP_MOVMO_ANALYTICS_URL` (inlined at build time), the same
297
+ URL. Override it with `REACT_APP_MOVMO_ANALYTICS_URL` (read at runtime, ESM/CJS builds only), the same
257
298
  mechanism as `REACT_APP_MOVMO_CHECKOUT_URL`.
258
299
  - On click, the button appends an `mvs` (Movmo session) query param to the checkout URL with
259
- its current analytics session id. The embedded flights-ui SDK adopts that id on load, so
300
+ its current analytics session id. flights-ui adopts that id on load, so
260
301
  `button_viewed` → … → `booking_confirmed` all land in one session instead of two.
261
302
 
262
303
  ## CSS Integration
@@ -284,21 +325,11 @@ project relied on the transitive `axios` install that older versions pulled in,
284
325
  ### Tree-shaking (`sideEffects`)
285
326
 
286
327
  `package.json` declares `"sideEffects": ["**/*.css"]` — everything except CSS is claimed
287
- side-effect-free for bundlers that tree-shake unused code. This is accurate even though
288
- `MovmoCheckoutOverlay` registers module-level `window` listeners (guarded by
289
- `typeof window !== 'undefined'`) for back-button cleanup and refresh rehydration: the ESM/CJS
290
- build (`dist/index.es.js` / `dist/index.cjs`) is a single, non-splittable module, not a set of
291
- independently importable files a bundler could pick apart. A consumer either imports something
292
- from this package (in which case the whole module — listeners included — loads and runs, exactly
293
- as intended) or doesn't import it at all (in which case there's nothing to tree-shake in the first
294
- place). There is no importable subset of this package whose side effects a bundler could silently
295
- drop while still using another part of it, which is the only way a `sideEffects` flag like this
296
- one causes real bugs.
297
-
298
- On refresh rehydration, the overlay reopens in the same environment (`isProd`) the button was
299
- originally mounted with, never guessed from your page's hostname; a direct visit to a
300
- `/movmo/checkout` URL that never went through that mount (so nothing was persisted) does not
301
- reopen the overlay.
328
+ side-effect-free for bundlers that tree-shake unused code. This is accurate: the package has no
329
+ module-level side effects (every `window`/`sessionStorage` access happens inside a function, so
330
+ it also imports cleanly during server-side rendering), and the ESM/CJS build is a single,
331
+ non-splittable module, so there is no importable subset whose side effects a bundler could
332
+ silently drop.
302
333
 
303
334
  ## Development
304
335
 
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { MovmoBookingCompleteInfo, MovmoCheckoutExitInfo } from './MovmoCheckoutOverlay';
2
+ import { MovmoBookingCompleteInfo, MovmoCheckoutExitInfo } from './returnHandler';
3
3
  /**
4
4
  * A user-facing failure the button could not recover from on its own (MOVMO-673).
5
5
  * `stage` is `'save_offer'` — the click-time raw-offer save failed (CORS from an
@@ -23,26 +23,28 @@ export interface MovmoCheckoutButtonProps {
23
23
  isProd?: boolean;
24
24
  className?: string;
25
25
  /**
26
- * Fires when the traveler exits the Movmo checkout from inside the overlay,
27
- * after the overlay is removed and the page URL is restored to where the
28
- * checkout was opened. `info.reason` says why: 'booking_confirmed' — the
29
- * traveler booked successfully and clicked "Return to {airline}" on the
30
- * confirmation; 'offer_unavailable' — a dead-end screen's exit;
31
- * 'search_again' — a non-retryable booking failure. Use it to route the
32
- * traveler onward (e.g. a post-booking landing for 'booking_confirmed',
33
- * search results otherwise) or record analytics; without it the traveler
34
- * is simply returned to the page they clicked the button on. Not invoked
35
- * for browser-back closes, and it does not survive a page refresh inside
36
- * the checkout.
26
+ * Where Movmo sends the traveler back to. Defaults to the current page URL at click
27
+ * with every `movmo_*` query param removed (other params and the hash are kept). Movmo
28
+ * validates it against the airline's registered origins; an unregistered origin gets no
29
+ * return link. The callbacks below fire on whichever page loads this button (or calls
30
+ * `consumeMovmoCheckoutReturn`) at that URL.
31
+ */
32
+ returnUrl?: string;
33
+ /**
34
+ * Fires when the traveler comes back from the Movmo checkout (a full-page return to
35
+ * `returnUrl`, verified against the state nonce minted at click). `info.reason` says
36
+ * why: 'booking_confirmed' - the traveler booked and clicked "Return to {airline}";
37
+ * 'offer_unavailable' - a dead-end screen's exit; 'search_again' - a non-retryable
38
+ * failure or the header's "Back to {airline}". Use it to route the traveler onward.
39
+ * Not invoked when the traveler never returns (browser back, closed tab).
37
40
  */
38
41
  onExit?: (info: MovmoCheckoutExitInfo) => void;
39
42
  /**
40
- * Fires once per booking, while the traveler is still on Movmo's confirmation
41
- * screen and before any `onExit({ reason: 'booking_confirmed' })` — that exit
42
- * only fires later, if the traveler clicks "Return to airline". `info.airlinePnr`
43
- * is the airline's own record locator (absent if the provider returned none);
44
- * `info.airlineRef` is the airline IATA/company code, not the PNR. Like `onExit`,
45
- * it does not re-fire after a page refresh inside the checkout.
43
+ * Fires once, on return, when the booking was confirmed, immediately BEFORE
44
+ * `onExit({ reason: 'booking_confirmed' })`. `info.airlinePnr` is the airline's own
45
+ * record locator (absent if the provider returned none; it travels only in the URL
46
+ * fragment and is scrubbed on arrival); `info.airlineRef` is the airline IATA/company
47
+ * code, not the PNR.
46
48
  */
47
49
  onBookingComplete?: (info: MovmoBookingCompleteInfo) => void;
48
50
  /**
package/dist/dts/env.d.ts CHANGED
@@ -1,9 +1,23 @@
1
+ /** Whether build-time environment overrides are honoured at all (false in the UMD build). */
2
+ export declare const ALLOW_ENV_OVERRIDES: boolean;
1
3
  /**
2
- * Reads a build-time environment override without assuming a `process` global.
4
+ * Reads a build-time environment override without assuming a `process` global. ESM/CJS builds
5
+ * only: the value is read at runtime from `process.env` (the consuming bundler's define), never
6
+ * inlined by this package, and the UMD build compiles overrides out entirely.
3
7
  *
4
8
  * Create React App inlines `process.env.REACT_APP_*`; Vite, Parcel, esbuild, Remix/Astro
5
9
  * on Vite and plain `<script type="module">` pages have no `process` in the browser, and a
6
10
  * bare `process.env.X` read throws `ReferenceError: process is not defined` at mount — which
7
11
  * unmounts the host page's whole tree. Always read overrides through this helper.
12
+ *
13
+ * Only a non-empty string is returned: markup that clobbers `window.process` (DOM clobbering)
14
+ * can make `process.env.X` an element or object, which must never reach a URL.
8
15
  */
9
16
  export declare function readEnv(name: string): string | undefined;
17
+ /**
18
+ * True for `https://movmo.io`, `https://*.movmo.io`, and `http://localhost[:port]` /
19
+ * `http://127.0.0.1[:port]` (local development). No credentials in the URL.
20
+ */
21
+ export declare function isTrustedMovmoUrl(raw: string): boolean;
22
+ /** A URL override that passes {@link isTrustedMovmoUrl}; anything else is ignored. */
23
+ export declare function readUrlOverride(name: string): string | undefined;
@@ -2,5 +2,6 @@ import './index.css';
2
2
  export { MovmoCheckoutButton } from './MovmoCheckoutButton';
3
3
  export type { MovmoCheckoutButtonProps, MovmoCheckoutError } from './MovmoCheckoutButton';
4
4
  export type { SaveOfferResult } from './api';
5
- export type { MovmoBookingCompleteInfo, MovmoCheckoutExitInfo, MovmoCheckoutOverlayOptions, } from './MovmoCheckoutOverlay';
5
+ export { consumeMovmoCheckoutReturn } from './returnHandler';
6
+ export type { MovmoBookingCompleteInfo, MovmoCheckoutExitInfo, MovmoCheckoutReturnOptions, } from './returnHandler';
6
7
  export type { MovmoExitReason } from '@movmo_app/types';
@@ -0,0 +1,47 @@
1
+ /** sessionStorage key holding the pending-return record on the partner origin. */
2
+ export declare const PENDING_KEY = "movmo:checkout:pending";
3
+ /** What the button remembers across the top-level navigation to Movmo and back. */
4
+ export interface PendingCheckout {
5
+ state: string;
6
+ offerId: string;
7
+ startedAt: number;
8
+ /** Stored at click so the return is attributed to the button that started it. */
9
+ providerId?: string;
10
+ airlineRef?: string;
11
+ /** Environment the button was mounted with; selects the analytics collector on return. */
12
+ isProd?: boolean;
13
+ }
14
+ /** A pending record older than this is ignored (an abandoned checkout, or a stale tab). */
15
+ export declare const PENDING_TTL_MS: number;
16
+ export interface BuildCheckoutUrlParams {
17
+ offerId: string;
18
+ providerId: string;
19
+ /** Airline IATA code, sent as `airlineRef`. */
20
+ airlineRef: string;
21
+ /** Partner analytics session id (`mvs`), when the tracker has one. */
22
+ mvs?: string | null;
23
+ internal?: boolean;
24
+ returnUrl: string;
25
+ /** Omitted only when the platform has no crypto at all. */
26
+ state?: string | null;
27
+ isProd: boolean;
28
+ }
29
+ /** Checkout origin: the build-time override, else prod or e2e. Path routing, not a hash route. */
30
+ export declare function checkoutBaseUrl(isProd: boolean): string;
31
+ export declare function buildCheckoutUrl(params: BuildCheckoutUrlParams): string;
32
+ /**
33
+ * The return URL sent to Movmo (it lands in CloudFront logs): the current page URL with every
34
+ * `movmo_*` query param removed. The other params are kept. The fragment is kept only when it
35
+ * looks like a router route (`#/` or `#!/`), and then without any `movmo_pnr`; any other
36
+ * fragment (anchors, tokens, partner data) is dropped.
37
+ */
38
+ export declare function defaultReturnUrl(href: string): string;
39
+ /**
40
+ * Random nonce echoed back as `movmo_state`. `crypto.randomUUID()`, else 16 random bytes as
41
+ * hex. With no crypto at all returns null: the redirect still happens without `state`, and the
42
+ * return is then not verifiable, so the SDK ignores it (fails closed on the callback side).
43
+ */
44
+ export declare function mintState(): string | null;
45
+ export declare function writePending(pending: PendingCheckout): void;
46
+ export declare function readPending(): PendingCheckout | null;
47
+ export declare function clearPending(): void;
@@ -0,0 +1,47 @@
1
+ import type { MovmoExitReason } from '@movmo_app/types';
2
+ /** Passed to the airline's onExit callback when the traveler returns from Movmo. */
3
+ export interface MovmoCheckoutExitInfo {
4
+ reason: MovmoExitReason;
5
+ }
6
+ /** Passed to onBookingComplete when the traveler returns from a confirmed booking. */
7
+ export interface MovmoBookingCompleteInfo {
8
+ bookingId: string;
9
+ /** Record locator (PNR) in the airline's own reservation system. Absent if the provider returned none. */
10
+ airlinePnr?: string;
11
+ /** Airline IATA / company code, not the PNR. */
12
+ airlineRef?: string;
13
+ providerId?: string;
14
+ }
15
+ export interface MovmoCheckoutReturnOptions {
16
+ /**
17
+ * The button's identity. When given, an instance only claims a return whose pending record
18
+ * (written at click) matches; a page-level `consumeReturn()` omits them and claims whatever
19
+ * is pending, taking the values from the record.
20
+ */
21
+ iataCode?: string;
22
+ providerID?: string;
23
+ /** The pre-saved offer id, when known, to tell two buttons with the same airline apart. */
24
+ offerId?: string;
25
+ /**
26
+ * Analytics environment, used only when the pending record does not carry one. When neither
27
+ * is known the tracker is not initialised here.
28
+ */
29
+ isProd?: boolean;
30
+ onExit?: (info: MovmoCheckoutExitInfo) => void;
31
+ onBookingComplete?: (info: MovmoBookingCompleteInfo) => void;
32
+ }
33
+ /** @internal Test hook: forget any parsed or claimed return. Not exported from the package entry. */
34
+ export declare function __resetForTests(): void;
35
+ /**
36
+ * Consume a return from Movmo checkout (MOVMO-549). Returns true when callbacks fired.
37
+ *
38
+ * Reads `movmo_exit`, `movmo_state`, `movmo_booking_id` from `location.search` and
39
+ * `movmo_pnr` from `location.hash` (the PNR lives in the fragment so it is never sent to a
40
+ * server or Referer). Callbacks run only when `movmo_state` matches the nonce stored at click
41
+ * and this instance matches the button that started the checkout. These are unauthenticated
42
+ * browser signals (the traveler can edit the URL): never fulfil or award anything from them.
43
+ *
44
+ * movmo_* params are scrubbed from the URL on the first call, with or without a return. Call
45
+ * it as early as possible, before analytics or session-replay scripts read the URL.
46
+ */
47
+ export declare function consumeMovmoCheckoutReturn(options?: MovmoCheckoutReturnOptions): boolean;
package/dist/dts/umd.d.ts CHANGED
@@ -1,7 +1,15 @@
1
1
  import './index.css';
2
2
  import { MovmoCheckoutButtonProps } from './MovmoCheckoutButton';
3
+ import { MovmoCheckoutReturnOptions } from './returnHandler';
3
4
  /** Semver of the bundled Express Checkout button. */
4
5
  export declare const version: string;
6
+ /**
7
+ * Consume a return from Movmo checkout on a page that does not mount the button (for example
8
+ * the return page differs from the page with the button). Fires `onBookingComplete` then
9
+ * `onExit` when `movmo_state` matches the pending nonce, and scrubs the movmo_* params.
10
+ * Returns true when callbacks fired.
11
+ */
12
+ export declare const consumeReturn: (options: MovmoCheckoutReturnOptions) => boolean;
5
13
  /** Handle returned by {@link mount} for tearing the button back down. */
6
14
  export interface MovmoMountHandle {
7
15
  unmount(): void;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * String-level URL surgery (no URLSearchParams round trip), so the partner's own query and
3
+ * hash survive byte for byte: `?q=a%20b&next=/x/y&flag` stays exactly that.
4
+ */
5
+ /** Remove every `movmo_*` key from a `?query` string; returns '' when nothing is left. */
6
+ export declare function scrubQuery(search: string): string;
7
+ /**
8
+ * Remove every `movmo_pnr=` segment from a `#fragment`, whatever delimiter (`?` or `&`)
9
+ * precedes it: `#movmo_pnr=A&movmo_pnr=B`, `#movmo_pnr=OLD?movmo_pnr=NEW`, `#/r?a=1&movmo_pnr=X`.
10
+ * Returns '' (no hash) when nothing is left.
11
+ */
12
+ export declare function scrubHashPnr(hash: string): string;
13
+ /** True when the fragment looks like a router route (`#/x`, `#!/x`) rather than an anchor or data. */
14
+ export declare function isRouteHash(hash: string): boolean;