@movmo_app/types 1.9.0 → 1.11.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.
@@ -13,6 +13,21 @@ export type BookingSeatSelection = {
13
13
  price?: number;
14
14
  currency?: string;
15
15
  };
16
+ /**
17
+ * BookingBagSelection represents a per-passenger checked-bag selection on a
18
+ * booking. Maps to the BookingBagSelection model in go-services-core — keyed by
19
+ * the ancillary service (service_id) with a quantity instead of a single seat.
20
+ */
21
+ export type BookingBagSelection = {
22
+ id: string;
23
+ booking_id: string;
24
+ user_passenger_id: string;
25
+ segment_id: string;
26
+ service_id: string;
27
+ quantity: number;
28
+ price?: number;
29
+ currency?: string;
30
+ };
16
31
  /**
17
32
  * BookingPassenger represents a passenger associated with a booking,
18
33
  * including full user passenger details and ticketing information.
@@ -36,4 +51,5 @@ export type BookingPassenger = {
36
51
  seat_number?: string;
37
52
  fare_basis_code?: string;
38
53
  seat_selections?: BookingSeatSelection[];
54
+ bag_selections?: BookingBagSelection[];
39
55
  };
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,94 @@
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 status: flights-ui (iframe) consumes this contract. The parent side
20
+ * (`@movmo/express-checkout-button`) adopts it in MOVMO-437 Part 2 (v1.4.0); until then
21
+ * the published parent uses its own hardcoded origin list and performs 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
+ export interface MovmoBookingFailedMessage {
54
+ type: MovmoFrameMessageType.BOOKING_FAILED;
55
+ action: 'search_again';
56
+ }
57
+ /** Discriminated union of every message exchanged across the frame boundary. */
58
+ export type MovmoFrameMessage = MovmoReadyMessage | MovmoInitMessage | MovmoBookingCompleteMessage | MovmoBookingFailedMessage;
59
+ /** A per-environment origin allowlist (production vs. everything else). */
60
+ export interface MovmoOriginAllowlist {
61
+ prod: readonly string[];
62
+ nonProd: readonly string[];
63
+ }
64
+ /**
65
+ * Origins served by Movmo's flights-ui iframe. The PARENT
66
+ * (`@movmo/express-checkout-button`) validates inbound messages against this list.
67
+ */
68
+ export declare const MOVMO_FLIGHTS_ORIGINS: MovmoOriginAllowlist;
69
+ /**
70
+ * Airline-partner origins permitted to embed the flights-ui iframe. The IFRAME
71
+ * (flights-ui) validates the inbound handshake against this list.
72
+ *
73
+ * `prod` is intentionally empty until a real partner goes live in production; populate it
74
+ * (or move it server-side, keyed by airline) as partners launch. The non-prod entries are
75
+ * the cross-domain demo/test harness (MOVMO-430) plus local development.
76
+ */
77
+ export declare const MOVMO_PARTNER_ORIGINS: MovmoOriginAllowlist;
78
+ export interface TrustedOriginOptions {
79
+ isProd: boolean;
80
+ /**
81
+ * Extra origins to trust in NON-PROD only (e.g. an env-injected override URL such as
82
+ * `REACT_APP_MOVMO_CHECKOUT_URL`). Ignored when `isProd` is true so a production build
83
+ * always keeps its hardcoded allowlist. Entries may be full URLs (origin is extracted)
84
+ * and `undefined`/empty values are skipped.
85
+ */
86
+ extraOrigins?: Array<string | undefined>;
87
+ }
88
+ /**
89
+ * Returns true when `origin` is trusted for the given allowlist and environment.
90
+ *
91
+ * In production only `list.prod` is consulted (env overrides are ignored). In non-prod,
92
+ * `list.nonProd` plus any valid `extraOrigins` are allowed.
93
+ */
94
+ 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 status: flights-ui (iframe) consumes this contract. The parent side
21
+ * (`@movmo/express-checkout-button`) adopts it in MOVMO-437 Part 2 (v1.4.0); until then
22
+ * the published parent uses its own hardcoded origin list and performs 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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@movmo_app/types",
3
- "version": "1.9.0",
3
+ "version": "1.11.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"