@movmo/express-checkout-button 1.11.1 → 1.12.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 +37 -10
- package/dist/dts/MovmoCheckoutButton.d.ts +23 -0
- package/dist/dts/api.d.ts +17 -1
- package/dist/dts/index.d.ts +2 -1
- package/dist/express-checkout.umd.js +2 -2
- package/dist/express-checkout.umd.js.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +42 -2
- package/dist/index.es.js +2 -2
- package/dist/index.es.js.map +1 -1
- package/package.json +16 -3
- package/dist/index.cjs.js +0 -8
- package/dist/index.cjs.js.map +0 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ function MyBookingPage() {
|
|
|
34
34
|
<MovmoCheckoutButton
|
|
35
35
|
iataCode="PR"
|
|
36
36
|
apiKey="your-movmo-api-key"
|
|
37
|
-
providerID="
|
|
37
|
+
providerID="duffel"
|
|
38
38
|
flightOfferID="offer-123-456-789"
|
|
39
39
|
isProd={false} // Set to true for production environment
|
|
40
40
|
/>
|
|
@@ -56,7 +56,7 @@ import { MovmoCheckoutButton } from '@movmo/express-checkout-button';
|
|
|
56
56
|
import '@movmo/express-checkout-button/dist/index.css';
|
|
57
57
|
|
|
58
58
|
function MyBookingPage() {
|
|
59
|
-
// Flight offer data retrieved from your booking system (
|
|
59
|
+
// Flight offer data retrieved from your booking system (e.g. Darwin, Dohop)
|
|
60
60
|
const flightOffer = {
|
|
61
61
|
// Your raw flight offer data from the provider
|
|
62
62
|
};
|
|
@@ -68,7 +68,7 @@ function MyBookingPage() {
|
|
|
68
68
|
<MovmoCheckoutButton
|
|
69
69
|
iataCode="AA"
|
|
70
70
|
apiKey="your-movmo-api-key"
|
|
71
|
-
providerID="
|
|
71
|
+
providerID="darwin"
|
|
72
72
|
flightOffer={flightOffer}
|
|
73
73
|
isProd={false} // Set to true for production environment
|
|
74
74
|
/>
|
|
@@ -85,25 +85,38 @@ export default MyBookingPage;
|
|
|
85
85
|
| --------------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
86
86
|
| `iataCode` | string | Yes | The IATA code for the airline |
|
|
87
87
|
| `apiKey` | string | Yes | Your Movmo API key |
|
|
88
|
-
| `providerID` | string | Yes | The provider identifier
|
|
88
|
+
| `providerID` | string | Yes | The provider identifier: one of "darwin", "duffel", "dohop", or the sandbox provider id Movmo gives you at onboarding for testing |
|
|
89
89
|
| `flightOffer` | object | No\* | The raw flight offer data object from the provider. Required if `flightOfferID` is not provided |
|
|
90
90
|
| `flightOfferID` | string | No\* | The ID of a pre-saved flight offer. Required if `flightOffer` is not provided |
|
|
91
91
|
| `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
92
|
| `className` | string | No | Extra CSS classes merged onto the button element |
|
|
93
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
|
+
| `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 |
|
|
94
95
|
|
|
95
96
|
\*Note: Either `flightOffer` or `flightOfferID` must be provided, but not both.
|
|
96
97
|
|
|
98
|
+
### Handling errors
|
|
99
|
+
|
|
100
|
+
```jsx
|
|
101
|
+
<MovmoCheckoutButton
|
|
102
|
+
{...props}
|
|
103
|
+
onError={(error) => {
|
|
104
|
+
// Show your own error toast, or fall back to your native checkout.
|
|
105
|
+
showToast(`Checkout unavailable: ${error.message}`);
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
97
110
|
## Provider Options
|
|
98
111
|
|
|
99
112
|
The `providerID` prop accepts provider identifiers as strings. Common providers include:
|
|
100
113
|
|
|
101
114
|
```jsx
|
|
102
115
|
// Common provider IDs
|
|
103
|
-
'
|
|
104
|
-
'
|
|
105
|
-
'duffel'; // For Duffel flight data
|
|
106
|
-
//
|
|
116
|
+
'darwin'; // For Darwin flight data (raw PSS offer JSON via `flightOffer`)
|
|
117
|
+
'dohop'; // For Dohop flight data (raw offer JSON via `flightOffer`)
|
|
118
|
+
'duffel'; // For Duffel flight data (offer id via `flightOfferID` — no raw offer save)
|
|
119
|
+
// Testing: use the sandbox provider id Movmo gives you at onboarding
|
|
107
120
|
```
|
|
108
121
|
|
|
109
122
|
## Environment Configuration
|
|
@@ -139,7 +152,7 @@ the package's `unpkg` field) for host pages without React or a bundler. It defin
|
|
|
139
152
|
var handle = window.MovmoExpressCheckout.mount('#movmo-checkout', {
|
|
140
153
|
iataCode: 'AA',
|
|
141
154
|
apiKey: 'your-movmo-api-key',
|
|
142
|
-
providerID: '
|
|
155
|
+
providerID: 'darwin',
|
|
143
156
|
flightOffer: rawOffer,
|
|
144
157
|
// isProd: true — add when you go live
|
|
145
158
|
});
|
|
@@ -225,6 +238,20 @@ for the button, `.my-wrapper button > span` for the Movmo badge — which is sta
|
|
|
225
238
|
The package has no runtime HTTP dependency: the offer-save call uses the platform `fetch`. If your
|
|
226
239
|
project relied on the transitive `axios` install that older versions pulled in, declare it yourself.
|
|
227
240
|
|
|
241
|
+
### Tree-shaking (`sideEffects`)
|
|
242
|
+
|
|
243
|
+
`package.json` declares `"sideEffects": ["**/*.css"]` — everything except CSS is claimed
|
|
244
|
+
side-effect-free for bundlers that tree-shake unused code. This is accurate even though
|
|
245
|
+
`MovmoCheckoutOverlay` registers module-level `window` listeners (guarded by
|
|
246
|
+
`typeof window !== 'undefined'`) for back-button cleanup and refresh rehydration: the ESM/CJS
|
|
247
|
+
build (`dist/index.es.js` / `dist/index.cjs`) is a single, non-splittable module, not a set of
|
|
248
|
+
independently importable files a bundler could pick apart. A consumer either imports something
|
|
249
|
+
from this package (in which case the whole module — listeners included — loads and runs, exactly
|
|
250
|
+
as intended) or doesn't import it at all (in which case there's nothing to tree-shake in the first
|
|
251
|
+
place). There is no importable subset of this package whose side effects a bundler could silently
|
|
252
|
+
drop while still using another part of it, which is the only way a `sideEffects` flag like this
|
|
253
|
+
one causes real bugs.
|
|
254
|
+
|
|
228
255
|
## Development
|
|
229
256
|
|
|
230
257
|
### Running Storybook
|
|
@@ -252,7 +279,7 @@ npm run build
|
|
|
252
279
|
The Storybook includes several examples:
|
|
253
280
|
|
|
254
281
|
1. **With Pre-saved Offer ID**: Example using a pre-saved flight offer ID
|
|
255
|
-
2. **With Raw Flight Offer**: Example with raw
|
|
282
|
+
2. **With Raw Flight Offer**: Example with raw PSS flight offer data (e.g. Darwin) that will be saved on button click
|
|
256
283
|
3. **Production Environment**: Example configured for production environment
|
|
257
284
|
4. **Minimal With Offer ID**: Minimal configuration example with just the required props
|
|
258
285
|
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { MovmoCheckoutExitInfo } from './MovmoCheckoutOverlay';
|
|
3
|
+
/**
|
|
4
|
+
* A user-facing failure the button could not recover from on its own (MOVMO-673).
|
|
5
|
+
* `stage` is `'save_offer'` — the click-time raw-offer save failed (CORS from an
|
|
6
|
+
* unregistered origin, a 4xx/5xx from the proxy, or a timeout) — or `'missing_offer'`
|
|
7
|
+
* — neither `flightOfferID` nor `flightOffer` was provided. `status` is the HTTP
|
|
8
|
+
* status when the failure was a non-2xx response; it is omitted for network errors,
|
|
9
|
+
* timeouts, and the `missing_offer` stage. `message` prefers the backend's own JSON
|
|
10
|
+
* `message`/`error` field, falling back to a generic error string.
|
|
11
|
+
*/
|
|
12
|
+
export type MovmoCheckoutError = {
|
|
13
|
+
stage: 'save_offer' | 'missing_offer';
|
|
14
|
+
status?: number;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
3
17
|
export interface MovmoCheckoutButtonProps {
|
|
4
18
|
iataCode: string;
|
|
5
19
|
apiKey: string;
|
|
@@ -22,5 +36,14 @@ export interface MovmoCheckoutButtonProps {
|
|
|
22
36
|
* the checkout.
|
|
23
37
|
*/
|
|
24
38
|
onExit?: (info: MovmoCheckoutExitInfo) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Fires when the button hits a failure it cannot recover from on its own — the
|
|
41
|
+
* click-time offer save failed, or neither `flightOfferID` nor `flightOffer` was
|
|
42
|
+
* provided. The button already logs a `console.warn` and emits the matching
|
|
43
|
+
* analytics event either way; this is for the partner page to react (e.g. show
|
|
44
|
+
* its own error toast, or fall back to its native checkout). Additive — omitting
|
|
45
|
+
* it preserves the console-only behavior.
|
|
46
|
+
*/
|
|
47
|
+
onError?: (error: MovmoCheckoutError) => void;
|
|
25
48
|
}
|
|
26
49
|
export declare const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps>;
|
package/dist/dts/api.d.ts
CHANGED
|
@@ -9,4 +9,20 @@ export interface ApiClient {
|
|
|
9
9
|
post<T>(path: string, body: unknown): Promise<T>;
|
|
10
10
|
}
|
|
11
11
|
export declare const createApiClient: (apiKey: string, airlineRef: string, isProd?: boolean) => ApiClient;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Discriminated result of {@link saveProviderOffer} (MOVMO-673). Replaces the earlier
|
|
14
|
+
* `string | null` contract so the button (and, via `onError`, the partner page) can
|
|
15
|
+
* surface WHY a save failed — an HTTP status when the response was non-2xx, and a
|
|
16
|
+
* message that prefers the backend's own JSON `message`/`error` field over a generic
|
|
17
|
+
* fetch/timeout string.
|
|
18
|
+
*/
|
|
19
|
+
export type SaveOfferResult = {
|
|
20
|
+
ok: true;
|
|
21
|
+
offerId: string;
|
|
22
|
+
} | {
|
|
23
|
+
ok: false;
|
|
24
|
+
status?: number;
|
|
25
|
+
message: string;
|
|
26
|
+
cause?: unknown;
|
|
27
|
+
};
|
|
28
|
+
export declare const saveProviderOffer: (providerID: string, rawOffer: object, client: ApiClient) => Promise<SaveOfferResult>;
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import './index.css';
|
|
2
2
|
export { MovmoCheckoutButton } from './MovmoCheckoutButton';
|
|
3
|
-
export type { MovmoCheckoutButtonProps } from './MovmoCheckoutButton';
|
|
3
|
+
export type { MovmoCheckoutButtonProps, MovmoCheckoutError } from './MovmoCheckoutButton';
|
|
4
|
+
export type { SaveOfferResult } from './api';
|
|
4
5
|
export type { MovmoCheckoutExitInfo, MovmoCheckoutOverlayOptions } from './MovmoCheckoutOverlay';
|
|
5
6
|
export type { MovmoExitReason } from '@movmo_app/types';
|