@movmo/express-checkout-button 1.14.0 → 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 +87 -56
- package/dist/dts/MovmoCheckoutButton.d.ts +20 -18
- package/dist/dts/env.d.ts +15 -1
- package/dist/dts/index.d.ts +2 -1
- package/dist/dts/redirect.d.ts +47 -0
- package/dist/dts/returnHandler.d.ts +47 -0
- package/dist/dts/umd.d.ts +8 -0
- package/dist/dts/urlScrub.d.ts +14 -0
- package/dist/express-checkout.umd.js +27 -27
- package/dist/express-checkout.umd.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +49 -48
- package/dist/index.es.js +2 -2
- package/dist/index.es.js.map +1 -1
- package/package.json +3 -3
- package/dist/dts/MovmoCheckoutOverlay.d.ts +0 -47
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
|
-
| `
|
|
94
|
-
| `
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
or
|
|
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/
|
|
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.
|
|
179
|
-
|
|
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 `/
|
|
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
|
|
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
|
|
220
|
-
the airline page through the
|
|
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
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
| Event
|
|
232
|
-
|
|
|
233
|
-
| `plugin_loaded`
|
|
234
|
-
| `button_viewed`
|
|
235
|
-
| `button_hovered`
|
|
236
|
-
| `button_clicked`
|
|
237
|
-
| `offer_save_started`
|
|
238
|
-
| `offer_save_succeeded`
|
|
239
|
-
| `offer_save_failed`
|
|
240
|
-
| `
|
|
241
|
-
| `
|
|
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` (
|
|
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.
|
|
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
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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 './
|
|
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
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* the
|
|
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
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
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;
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -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
|
|
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;
|