@movmo_app/types 1.10.0 → 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/dist/index.d.ts CHANGED
@@ -13,3 +13,4 @@ export * from './sessions';
13
13
  export * from './booking_passenger';
14
14
  export * from './movmo_flight_offer';
15
15
  export * from './locale_preferences';
16
+ export * from './postmessage_contracts';
package/dist/index.js CHANGED
@@ -29,3 +29,4 @@ __exportStar(require("./sessions"), exports);
29
29
  __exportStar(require("./booking_passenger"), exports);
30
30
  __exportStar(require("./movmo_flight_offer"), exports);
31
31
  __exportStar(require("./locale_preferences"), exports);
32
+ __exportStar(require("./postmessage_contracts"), exports);
@@ -0,0 +1,111 @@
1
+ /**
2
+ * postMessage contract shared by the Express Checkout iframe (flights-ui) and the
3
+ * embedding parent page (`@movmo/express-checkout-button`).
4
+ *
5
+ * Both sides SHOULD coordinate exclusively via `window.postMessage` — no direct
6
+ * cross-frame DOM access — validating every message against a strict origin allowlist in
7
+ * both directions:
8
+ *
9
+ * - The PARENT should validate inbound messages against {@link MOVMO_FLIGHTS_ORIGINS}
10
+ * ("is this really the Movmo checkout iframe I embedded?").
11
+ * - The IFRAME should validate the inbound handshake against {@link MOVMO_PARTNER_ORIGINS}
12
+ * ("is this parent page allowed to embed me and receive booking messages?").
13
+ *
14
+ * Handshake: on load the iframe posts {@link MovmoFrameMessageType.READY} (content-free)
15
+ * to `"*"`; the parent replies with {@link MovmoFrameMessageType.INIT} carrying its own
16
+ * origin, targeted at the iframe's origin. The iframe captures that origin so every
17
+ * subsequent message goes to a specific origin instead of `"*"`.
18
+ *
19
+ * Adoption: both flights-ui (iframe) and `@movmo/express-checkout-button` (parent, as of
20
+ * v1.4.0) consume this contract. Parent versions before v1.4.0 use their own hardcoded
21
+ * origin list and perform no handshake.
22
+ *
23
+ * Note: payload field names are camelCase (browser `postMessage` data), a deliberate
24
+ * departure from the snake_case Go-DTO convention used elsewhere in this package. Keep
25
+ * them camelCase — the cross-repo consumers read these exact keys off the wire.
26
+ */
27
+ export declare enum MovmoFrameMessageType {
28
+ /** iframe → parent: posted on load so the parent replies with INIT. Content-free. */
29
+ READY = "MOVMO_READY",
30
+ /** parent → iframe: handshake reply carrying the parent's origin so the iframe can
31
+ * target subsequent messages instead of using `"*"`. */
32
+ INIT = "MOVMO_INIT",
33
+ /** iframe → parent: a booking finished successfully. */
34
+ BOOKING_COMPLETE = "MOVMO_BOOKING_COMPLETE",
35
+ /** iframe → parent: a booking failed in a non-retryable way. */
36
+ BOOKING_FAILED = "MOVMO_BOOKING_FAILED"
37
+ }
38
+ export interface MovmoReadyMessage {
39
+ type: MovmoFrameMessageType.READY;
40
+ }
41
+ export interface MovmoInitMessage {
42
+ type: MovmoFrameMessageType.INIT;
43
+ /** Origin of the embedding parent page; the iframe targets this for outbound messages. */
44
+ parentOrigin: string;
45
+ }
46
+ export interface MovmoBookingCompleteMessage {
47
+ type: MovmoFrameMessageType.BOOKING_COMPLETE;
48
+ bookingId: string;
49
+ /** Airline IATA / company code the booking was made under. */
50
+ airlineRef?: string;
51
+ providerId?: string;
52
+ }
53
+ /**
54
+ * Why the iframe is handing control back to the airline page (MOVMO-474).
55
+ * Rides on BOOKING_FAILED rather than a new message type so that parents
56
+ * built before v1.6.0 — which already close the overlay on BOOKING_FAILED —
57
+ * keep working when a newer flights-ui sends an exit they don't understand.
58
+ */
59
+ export type MovmoExitReason = 'search_again' | 'offer_unavailable';
60
+ export interface MovmoBookingFailedMessage {
61
+ type: MovmoFrameMessageType.BOOKING_FAILED;
62
+ /**
63
+ * @deprecated Legacy constant no handler reads; kept so pre-1.6.0 parent
64
+ * typings keep compiling against this interface. Use `reason` instead.
65
+ */
66
+ action: 'search_again';
67
+ /**
68
+ * Optional so the field is additive: parents ≤1.5.0 ignore it and still
69
+ * close the overlay; parents ≥1.6.0 pass it to the airline's onExit
70
+ * callback. Absent means 'search_again' (messages from older flights-ui).
71
+ */
72
+ reason?: MovmoExitReason;
73
+ }
74
+ /** Discriminated union of every message exchanged across the frame boundary. */
75
+ export type MovmoFrameMessage = MovmoReadyMessage | MovmoInitMessage | MovmoBookingCompleteMessage | MovmoBookingFailedMessage;
76
+ /** A per-environment origin allowlist (production vs. everything else). */
77
+ export interface MovmoOriginAllowlist {
78
+ prod: readonly string[];
79
+ nonProd: readonly string[];
80
+ }
81
+ /**
82
+ * Origins served by Movmo's flights-ui iframe. The PARENT
83
+ * (`@movmo/express-checkout-button`) validates inbound messages against this list.
84
+ */
85
+ export declare const MOVMO_FLIGHTS_ORIGINS: MovmoOriginAllowlist;
86
+ /**
87
+ * Airline-partner origins permitted to embed the flights-ui iframe. The IFRAME
88
+ * (flights-ui) validates the inbound handshake against this list.
89
+ *
90
+ * `prod` is intentionally empty until a real partner goes live in production; populate it
91
+ * (or move it server-side, keyed by airline) as partners launch. The non-prod entries are
92
+ * the cross-domain demo/test harness (MOVMO-430) plus local development.
93
+ */
94
+ export declare const MOVMO_PARTNER_ORIGINS: MovmoOriginAllowlist;
95
+ export interface TrustedOriginOptions {
96
+ isProd: boolean;
97
+ /**
98
+ * Extra origins to trust in NON-PROD only (e.g. an env-injected override URL such as
99
+ * `REACT_APP_MOVMO_CHECKOUT_URL`). Ignored when `isProd` is true so a production build
100
+ * always keeps its hardcoded allowlist. Entries may be full URLs (origin is extracted)
101
+ * and `undefined`/empty values are skipped.
102
+ */
103
+ extraOrigins?: Array<string | undefined>;
104
+ }
105
+ /**
106
+ * Returns true when `origin` is trusted for the given allowlist and environment.
107
+ *
108
+ * In production only `list.prod` is consulted (env overrides are ignored). In non-prod,
109
+ * `list.nonProd` plus any valid `extraOrigins` are allowed.
110
+ */
111
+ export declare function isTrustedOrigin(origin: string, list: MovmoOriginAllowlist, { isProd, extraOrigins }: TrustedOriginOptions): boolean;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /**
3
+ * postMessage contract shared by the Express Checkout iframe (flights-ui) and the
4
+ * embedding parent page (`@movmo/express-checkout-button`).
5
+ *
6
+ * Both sides SHOULD coordinate exclusively via `window.postMessage` — no direct
7
+ * cross-frame DOM access — validating every message against a strict origin allowlist in
8
+ * both directions:
9
+ *
10
+ * - The PARENT should validate inbound messages against {@link MOVMO_FLIGHTS_ORIGINS}
11
+ * ("is this really the Movmo checkout iframe I embedded?").
12
+ * - The IFRAME should validate the inbound handshake against {@link MOVMO_PARTNER_ORIGINS}
13
+ * ("is this parent page allowed to embed me and receive booking messages?").
14
+ *
15
+ * Handshake: on load the iframe posts {@link MovmoFrameMessageType.READY} (content-free)
16
+ * to `"*"`; the parent replies with {@link MovmoFrameMessageType.INIT} carrying its own
17
+ * origin, targeted at the iframe's origin. The iframe captures that origin so every
18
+ * subsequent message goes to a specific origin instead of `"*"`.
19
+ *
20
+ * Adoption: both flights-ui (iframe) and `@movmo/express-checkout-button` (parent, as of
21
+ * v1.4.0) consume this contract. Parent versions before v1.4.0 use their own hardcoded
22
+ * origin list and perform no handshake.
23
+ *
24
+ * Note: payload field names are camelCase (browser `postMessage` data), a deliberate
25
+ * departure from the snake_case Go-DTO convention used elsewhere in this package. Keep
26
+ * them camelCase — the cross-repo consumers read these exact keys off the wire.
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.MOVMO_PARTNER_ORIGINS = exports.MOVMO_FLIGHTS_ORIGINS = exports.MovmoFrameMessageType = void 0;
30
+ exports.isTrustedOrigin = isTrustedOrigin;
31
+ var MovmoFrameMessageType;
32
+ (function (MovmoFrameMessageType) {
33
+ /** iframe → parent: posted on load so the parent replies with INIT. Content-free. */
34
+ MovmoFrameMessageType["READY"] = "MOVMO_READY";
35
+ /** parent → iframe: handshake reply carrying the parent's origin so the iframe can
36
+ * target subsequent messages instead of using `"*"`. */
37
+ MovmoFrameMessageType["INIT"] = "MOVMO_INIT";
38
+ /** iframe → parent: a booking finished successfully. */
39
+ MovmoFrameMessageType["BOOKING_COMPLETE"] = "MOVMO_BOOKING_COMPLETE";
40
+ /** iframe → parent: a booking failed in a non-retryable way. */
41
+ MovmoFrameMessageType["BOOKING_FAILED"] = "MOVMO_BOOKING_FAILED";
42
+ })(MovmoFrameMessageType || (exports.MovmoFrameMessageType = MovmoFrameMessageType = {}));
43
+ /**
44
+ * Origins served by Movmo's flights-ui iframe. The PARENT
45
+ * (`@movmo/express-checkout-button`) validates inbound messages against this list.
46
+ */
47
+ exports.MOVMO_FLIGHTS_ORIGINS = {
48
+ prod: ['https://flights.movmo.io'],
49
+ nonProd: ['https://flights.e2e.movmo.io', 'http://localhost:3000'],
50
+ };
51
+ /**
52
+ * Airline-partner origins permitted to embed the flights-ui iframe. The IFRAME
53
+ * (flights-ui) validates the inbound handshake against this list.
54
+ *
55
+ * `prod` is intentionally empty until a real partner goes live in production; populate it
56
+ * (or move it server-side, keyed by airline) as partners launch. The non-prod entries are
57
+ * the cross-domain demo/test harness (MOVMO-430) plus local development.
58
+ */
59
+ exports.MOVMO_PARTNER_ORIGINS = {
60
+ prod: [],
61
+ nonProd: ['https://mockairline-e2e.app.flyeasyapp.com', 'http://localhost:3000'],
62
+ };
63
+ /**
64
+ * Returns true when `origin` is trusted for the given allowlist and environment.
65
+ *
66
+ * In production only `list.prod` is consulted (env overrides are ignored). In non-prod,
67
+ * `list.nonProd` plus any valid `extraOrigins` are allowed.
68
+ */
69
+ function isTrustedOrigin(origin, list, { isProd, extraOrigins = [] }) {
70
+ if (isProd) {
71
+ return list.prod.includes(origin);
72
+ }
73
+ const allowed = [...list.nonProd];
74
+ for (const extra of extraOrigins) {
75
+ if (!extra)
76
+ continue;
77
+ try {
78
+ allowed.push(new URL(extra).origin);
79
+ }
80
+ catch (_a) {
81
+ // Stay fail-closed (a bad override never widens trust) but leave a breadcrumb —
82
+ // a fat-fingered override URL vanishing silently is a debugging trap in
83
+ // security-relevant code.
84
+ console.warn(`[movmo] isTrustedOrigin: ignoring malformed extra origin "${extra}"`);
85
+ }
86
+ }
87
+ return allowed.includes(origin);
88
+ }
package/dist/users.d.ts CHANGED
@@ -11,6 +11,7 @@ export type User = {
11
11
  last_name?: string;
12
12
  suffix?: string;
13
13
  email: string;
14
+ /** Empty string when the user has no phone on file (phone is optional since MOVMO-445). */
14
15
  phone_number: string;
15
16
  date_of_birth?: string;
16
17
  gender?: Gender;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@movmo_app/types",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "A collection of Movmo's types",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "echo \"No tests yet\""
9
+ "test": "vitest run"
10
10
  },
11
11
  "keywords": [],
12
12
  "license": "ISC",
@@ -17,7 +17,9 @@
17
17
  "@types/node": "^20.14.2",
18
18
  "typescript": "^5.4.5"
19
19
  },
20
- "devDependencies": {},
20
+ "devDependencies": {
21
+ "vitest": "^2.1.8"
22
+ },
21
23
  "repository": {
22
24
  "type": "git",
23
25
  "url": "git+https://github.com/movmo-app/react-js-packages.git"