@movmo/express-checkout-button 1.0.1 → 1.0.3

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
@@ -29,11 +29,11 @@ function MyBookingPage() {
29
29
  const flightOffer = {
30
30
  // Your flight offer data
31
31
  };
32
-
32
+
33
33
  return (
34
34
  <div className="booking-page">
35
35
  <h1>Complete your booking</h1>
36
-
36
+
37
37
  <MovmoCheckoutButton
38
38
  customerId="your-airline-id"
39
39
  apiKey="your-movmo-api-key"
@@ -50,13 +50,13 @@ export default MyBookingPage;
50
50
 
51
51
  ## Props
52
52
 
53
- | Prop | Type | Required | Description |
54
- |------|------|----------|-------------|
55
- | `customerId` | string | Yes | The unique identifier for your airline |
56
- | `apiKey` | string | Yes | Your Movmo API key |
57
- | `dataSource` | string | Yes | The source of flight data, must be either "amadeus" or "sabre" |
58
- | `flightOffer` | object | Yes | The flight offer data object |
59
- | `isProd` | boolean | No | Whether to use production endpoints (default: false). When true, uses production API and booking URLs; when false, uses e2e (testing) endpoints. |
53
+ | Prop | Type | Required | Description |
54
+ | ------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
55
+ | `customerId` | string | Yes | The unique identifier for your airline |
56
+ | `apiKey` | string | Yes | Your Movmo API key |
57
+ | `dataSource` | string | Yes | The source of flight data, must be either "amadeus" or "sabre" |
58
+ | `flightOffer` | object | Yes | The flight offer data object |
59
+ | `isProd` | boolean | No | Whether to use production endpoints (default: false). When true, uses production API and flights URLs; when false, uses e2e (testing) endpoints. |
60
60
 
61
61
  ## Data Source Options
62
62
 
@@ -64,8 +64,8 @@ The `dataSource` prop accepts the following string values:
64
64
 
65
65
  ```jsx
66
66
  // Available options
67
- "amadeus" // For Amadeus flight data
68
- "sabre" // For Sabre flight data
67
+ 'amadeus'; // For Amadeus flight data
68
+ 'sabre'; // For Sabre flight data
69
69
  ```
70
70
 
71
71
  ## Environment Configuration
@@ -73,12 +73,13 @@ The `dataSource` prop accepts the following string values:
73
73
  The `isProd` prop controls which Movmo endpoints are used:
74
74
 
75
75
  - When `isProd={false}` (default):
76
+
76
77
  - API endpoint: `https://e2e.api.movmo.io`
77
- - Booking UI: `https://booking-e2e.app.movmo.io`
78
+ - Flights UI: `https://flights.e2e.movmo.io`
78
79
 
79
80
  - When `isProd={true}`:
80
81
  - API endpoint: `https://api.movmo.io`
81
- - Booking UI: `https://booking.app.movmo.io`
82
+ - Flights UI: `https://flights.movmo.io`
82
83
 
83
84
  ## CSS Integration
84
85
 
@@ -116,7 +117,7 @@ npm run build
116
117
  The Storybook includes several examples:
117
118
 
118
119
  1. **Default**: Standard implementation of the checkout button
119
- 2. **Development Environment**: Example configured for development environment
120
+ 2. **Development Environment**: Example configured for development environment
120
121
  3. **Production Environment**: Example configured for production environment
121
122
  4. **Custom-Styled Button**: Example showing how to create a custom styled button
122
123
 
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  interface MovmoCheckoutButtonProps {
3
- customerId: string;
3
+ iataCode: string;
4
4
  apiKey: string;
5
5
  dataSource: "amadeus" | "sabre";
6
6
  flightOffer: object;
package/dist/dts/api.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { AxiosInstance } from "axios";
1
+ import { AxiosInstance } from 'axios';
2
2
  export declare const createAxiosClient: (apiKey: string, isProd?: boolean) => AxiosInstance;
3
3
  export interface FlightOfferRequest {
4
4
  dataSource: string;
5
- customerId: string;
5
+ iataCode: string;
6
6
  rawOffer: object;
7
7
  }
8
8
  export declare const saveFlightOffer: (payload: FlightOfferRequest, client: AxiosInstance) => Promise<string | null>;
package/dist/index.cjs.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @movmo/express-checkout-button v1.0.1
2
+ * @movmo/express-checkout-button v1.0.3
3
3
  * React component plugin for embedding Movmo Express Checkout on airline websites.
4
4
  * (c) 2025 Movmo
5
5
  * @license MIT
6
6
  */
7
- "use strict";var o=require("react/jsx-runtime"),e=require("react"),n=require("axios");function t(o,e=!1){if(document.getElementById("movmo-checkout"))return;const n=document.createElement("div");n.id="movmo-checkout",n.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background: white;\n z-index: 9999;\n ";const t=e?"https://booking.app.movmo.io":"https://booking-e2e.app.movmo.io";let i=`${t}/booking?${o}`;if(window.location.pathname.includes("/movmo/checkout/booking/")){i=`${t}/booking/${window.location.pathname.split("/").pop()}?airlineRef=${new URLSearchParams(window.location.search).get("airlineRef")||""}`,window.history.replaceState({checkoutOpen:!0,bookingComplete:!0},"",window.location.href)}n.innerHTML=`\n <iframe \n src="${i}"\n width="100%" \n height="100%" \n style="border: none;"\n id="movmo-checkout-iframe">\n </iframe>\n `,document.body.appendChild(n),window.addEventListener("message",(o=>{const n=function(o,e){const n=["https://booking.app.movmo.io"],t=["https://booking-e2e.app.movmo.io","http://localhost:3000"];return e?n.includes(o):t.includes(o)}(o.origin,e);if(n&&"MOVMO_BOOKING_COMPLETE"===o.data?.type){const{bookingId:e,airlineRef:n}=o.data;e&&window.history.pushState({checkoutOpen:!0,bookingComplete:!0,bookingId:e},"",`/movmo/checkout/booking/${e}?airlineRef=${n||""}`)}}))}window.addEventListener("popstate",(()=>{const o=document.getElementById("movmo-checkout");!window.history.state?.checkoutOpen&&o&&o.remove()})),"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(()=>{const o=window.location.pathname.includes("/movmo/checkout/booking/"),e=window.location.pathname.startsWith("/movmo/checkout");if(o||e){t(window.location.search.substring(1),function(){const o=window.location.hostname;return!o.includes("e2e")&&!o.includes("localhost")}())}}));exports.MovmoCheckoutButton=({customerId:i,apiKey:a,dataSource:c,flightOffer:r,isProd:s=!1})=>{const[d,m]=e.useState(!1),u=((o,e=!1)=>{const t=e?"https://api.movmo.io":"https://e2e.api.movmo.io";return n.create({baseURL:t,headers:{Accept:"application/json","Content-Type":"application/json","x-api-key":o},withCredentials:!0,timeout:3e4})})(a,s),h=`\n px-7 py-5 \n font-inter font-semibold text-lg \n rounded-xl \n text-white \n border-none\n cursor-pointer\n transition-all duration-200\n outline-none focus:ring-2 focus:ring-[#F63D68] focus:ring-opacity-50\n ${d?"bg-gradient-hover":"bg-gradient-normal"}\n `.trim(),p="\n ml-2 px-2 py-1\n bg-white \n text-[#171412] \n rounded-md \n text-lg\n ".trim();return o.jsxs("button",{onClick:async()=>{const o={dataSource:c,customerId:i,rawOffer:r},e=await(async(o,e)=>await e.post("/v1/flight_offers",o).then((o=>o.data.id)).catch((o=>null)))(o,u);if(!e)return;const n=new URLSearchParams({offerId:e,airlineRef:i}).toString();window.history.pushState({checkoutOpen:!0},"",`/movmo/checkout?${n}`),t(n,s)},onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),className:h,children:["Express Checkout",o.jsx("span",{className:p,children:"Movmo"})]})};
7
+ "use strict";var o=require("react/jsx-runtime"),e=require("react"),t=require("axios");function n(o,e=!1){if(document.getElementById("movmo-checkout"))return;const t=document.createElement("div");t.id="movmo-checkout",t.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background: white;\n z-index: 9999;\n ";const n=e?"https://flights.movmo.io":"https://flights.e2e.movmo.io";let i=`${n}/booking?${o}`;if(window.location.pathname.includes("/movmo/checkout/booking/")){i=`${n}/booking/${window.location.pathname.split("/").pop()}?airlineRef=${new URLSearchParams(window.location.search).get("airlineRef")||""}`,window.history.replaceState({checkoutOpen:!0,bookingComplete:!0},"",window.location.href)}t.innerHTML=`\n <iframe \n src="${i}"\n width="100%" \n height="100%" \n style="border: none;"\n id="movmo-checkout-iframe">\n </iframe>\n `,document.body.appendChild(t),window.addEventListener("message",(o=>{const t=function(o,e){const t=["https://flights.movmo.io"],n=["https://flights.e2e.movmo.io","http://localhost:3000"];return e?t.includes(o):n.includes(o)}(o.origin,e);if(t&&"MOVMO_BOOKING_COMPLETE"===o.data?.type){const{bookingId:e,airlineRef:t}=o.data;e&&window.history.pushState({checkoutOpen:!0,bookingComplete:!0,bookingId:e},"",`/movmo/checkout/booking/${e}?airlineRef=${t||""}`)}}))}window.addEventListener("popstate",(()=>{const o=document.getElementById("movmo-checkout");!window.history.state?.checkoutOpen&&o&&o.remove()})),"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(()=>{const o=window.location.pathname.includes("/movmo/checkout/booking/"),e=window.location.pathname.startsWith("/movmo/checkout");if(o||e){n(window.location.search.substring(1),function(){const o=window.location.hostname;return!o.includes("e2e")&&!o.includes("localhost")}())}}));exports.MovmoCheckoutButton=({iataCode:i,apiKey:a,dataSource:c,flightOffer:s,isProd:r=!1})=>{const[d,h]=e.useState(!1),m=((o,e=!1)=>{const n=e?"https://api.movmo.io":"https://e2e.api.movmo.io";return t.create({baseURL:n,headers:{Accept:"application/json","Content-Type":"application/json","x-api-key":o},withCredentials:!0,timeout:3e4})})(a,r),u=`\n px-7 py-5 \n font-inter font-semibold text-lg \n rounded-xl \n text-white \n border-none\n cursor-pointer\n transition-all duration-200\n outline-none focus:ring-2 focus:ring-[#F63D68] focus:ring-opacity-50\n ${d?"bg-gradient-hover":"bg-gradient-normal"}\n `.trim(),l="\n ml-2 px-2 py-1\n bg-white \n text-[#171412] \n rounded-md \n text-lg\n ".trim();return o.jsxs("button",{onClick:async()=>{const o={dataSource:c,iataCode:i,rawOffer:s},e=await(async(o,e)=>await e.post("/v1/flight_offers",o).then((o=>o.data.id)).catch((o=>null)))(o,m);if(!e)return;const t=new URLSearchParams({offerId:e,airlineRef:i}).toString();window.history.pushState({checkoutOpen:!0},"",`/movmo/checkout?${t}`),n(t,r)},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),className:u,children:["Express Checkout",o.jsx("span",{className:l,children:"Movmo"})]})};
8
8
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/MovmoCheckoutOverlay.tsx","../src/MovmoCheckoutButton.tsx","../src/api.ts"],"sourcesContent":["export function showMovmoOverlay(queryParams: string, isProd: boolean = false) {\n if (document.getElementById('movmo-checkout')) return;\n\n const container = document.createElement('div');\n container.id = 'movmo-checkout';\n container.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background: white;\n z-index: 9999;\n `;\n\n // Use production or development URL based on isProd flag\n const baseUrl = isProd ? \"https://booking.app.movmo.io\" : \"https://booking-e2e.app.movmo.io\";\n\n // Check if we're already on a booking confirmation URL\n let iframeUrl = `${baseUrl}/booking?${queryParams}`;\n\n // If the URL indicates we're on a booking confirmation page, load that instead\n if (window.location.pathname.includes('/movmo/checkout/booking/')) {\n const bookingId = window.location.pathname.split('/').pop();\n const urlParams = new URLSearchParams(window.location.search);\n const airlineRef = urlParams.get('airlineRef') || '';\n\n // Direct the iframe to the booking confirmation page\n iframeUrl = `${baseUrl}/booking/${bookingId}?airlineRef=${airlineRef}`;\n\n // Ensure we maintain the checkout state\n window.history.replaceState({ checkoutOpen: true, bookingComplete: true }, '', window.location.href);\n }\n\n container.innerHTML = `\n <iframe \n src=\"${iframeUrl}\"\n width=\"100%\" \n height=\"100%\" \n style=\"border: none;\"\n id=\"movmo-checkout-iframe\">\n </iframe>\n `;\n\n document.body.appendChild(container);\n\n // Setup communication channel with iframe\n window.addEventListener('message', (event) => {\n // Check if the origin is allowed\n const isAllowedOrigin = checkAllowedOrigin(event.origin, isProd);\n\n if (isAllowedOrigin && event.data?.type === 'MOVMO_BOOKING_COMPLETE') {\n const { bookingId, airlineRef } = event.data;\n if (bookingId) {\n // Update the parent URL to reflect booking completion\n window.history.pushState(\n { checkoutOpen: true, bookingComplete: true, bookingId },\n '',\n `/movmo/checkout/booking/${bookingId}?airlineRef=${airlineRef || ''}`\n );\n }\n }\n });\n}\n\n/**\n * Check if an origin is allowed based on environment\n * - Production: Only booking.app.movmo.io is allowed\n * - Development: Allows booking-e2e.app.movmo.io and localhost:3000 only\n */\nfunction checkAllowedOrigin(origin: string, isProd: boolean): boolean {\n // Production origins (only used in production)\n const productionOrigins = ['https://booking.app.movmo.io'];\n\n // Development specific domains\n const devSpecificDomains = [\n 'https://booking-e2e.app.movmo.io',\n 'http://localhost:3000' // Specifically port 3000 for local development\n ];\n\n if (isProd) {\n // In production, only allow production origins\n return productionOrigins.includes(origin);\n } else {\n // In development, only allow development specific domains\n return devSpecificDomains.includes(origin);\n }\n}\n\n// Clean up when back button is used\nwindow.addEventListener('popstate', () => {\n const container = document.getElementById('movmo-checkout');\n if (!window.history.state?.checkoutOpen && container) {\n container.remove();\n }\n});\n\n/**\n * Determine if the current environment is production based on hostname\n * - Production: hostname contains neither 'e2e' nor 'localhost'\n * - Development/Testing: hostname contains 'e2e' or 'localhost'\n */\nfunction isProductionEnvironment(): boolean {\n const hostname = window.location.hostname;\n // Check if we're on production (neither e2e nor localhost)\n return !hostname.includes('e2e') && !hostname.includes('localhost');\n}\n\n// Handle page refresh or direct navigation to a booking confirmation URL\nif (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n const isBookingConfirmation = window.location.pathname.includes('/movmo/checkout/booking/');\n const isCheckoutPath = window.location.pathname.startsWith('/movmo/checkout');\n\n if (isBookingConfirmation || isCheckoutPath) {\n const queryParams = window.location.search.substring(1);\n const isProd = isProductionEnvironment();\n showMovmoOverlay(queryParams, isProd);\n }\n });\n}\n","import React, { useState } from 'react';\n\nimport { createAxiosClient, FlightOfferRequest, saveFlightOffer } from './api';\nimport { showMovmoOverlay } from './MovmoCheckoutOverlay';\n\ninterface MovmoCheckoutButtonProps {\n customerId: string;\n apiKey: string;\n dataSource: \"amadeus\" | \"sabre\";\n // TODO: support fare splitting\n flightOffer: object;\n isProd?: boolean;\n}\n\nexport const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps> = ({\n customerId,\n apiKey,\n dataSource,\n flightOffer,\n isProd = false,\n}) => {\n const [isHovered, setIsHovered] = useState(false);\n const client = createAxiosClient(apiKey, isProd);\n\n const handleClick = async () => {\n const payload: FlightOfferRequest = {\n dataSource,\n customerId,\n rawOffer: flightOffer,\n };\n const offerId = await saveFlightOffer(payload, client);\n if (!offerId) {\n // TODO: handle error by displaying a message to the user\n return;\n }\n\n const queryParams = new URLSearchParams({\n offerId,\n airlineRef: customerId,\n }).toString();\n\n window.history.pushState({ checkoutOpen: true }, '', `/movmo/checkout?${queryParams}`);\n showMovmoOverlay(queryParams, isProd);\n };\n\n const buttonClasses = `\n px-7 py-5 \n font-inter font-semibold text-lg \n rounded-xl \n text-white \n border-none\n cursor-pointer\n transition-all duration-200\n outline-none focus:ring-2 focus:ring-[#F63D68] focus:ring-opacity-50\n ${isHovered ? 'bg-gradient-hover' : 'bg-gradient-normal'}\n `.trim();\n\n const badgeClasses = `\n ml-2 px-2 py-1\n bg-white \n text-[#171412] \n rounded-md \n text-lg\n `.trim();\n\n return (\n <button\n onClick={handleClick}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n className={buttonClasses}\n >\n Express Checkout\n <span className={badgeClasses}>\n Movmo\n </span>\n </button>\n );\n};\n","import axios, { AxiosInstance } from \"axios\";\n\n\nexport const createAxiosClient = (apiKey: string, isProd: boolean = false) => {\n const baseUrl = isProd ? \"https://api.movmo.io\" : \"https://e2e.api.movmo.io\";\n\n const client = axios.create({\n baseURL: baseUrl,\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey,\n },\n // Allow cookies to be sent with requests\n withCredentials: true,\n timeout: 30000,\n });\n\n return client;\n};\n\nexport interface FlightOfferRequest {\n dataSource: string;\n customerId: string;\n // The raw offer object from the data source; does not currently support fare splitting\n rawOffer: object;\n}\n\nexport const saveFlightOffer = async (payload: FlightOfferRequest, client: AxiosInstance): Promise<string | null> => {\n return await client.post(\"/v1/flight_offers\", payload)\n .then((res) => res.data.id)\n .catch((err) => {\n console.error(err);\n return null;\n });\n};\n"],"names":["showMovmoOverlay","queryParams","isProd","document","getElementById","container","createElement","id","style","cssText","baseUrl","iframeUrl","window","location","pathname","includes","split","pop","URLSearchParams","search","get","history","replaceState","checkoutOpen","bookingComplete","href","innerHTML","body","appendChild","addEventListener","event","isAllowedOrigin","origin","productionOrigins","devSpecificDomains","checkAllowedOrigin","data","type","bookingId","airlineRef","pushState","state","remove","isBookingConfirmation","isCheckoutPath","startsWith","substring","hostname","isProductionEnvironment","customerId","apiKey","dataSource","flightOffer","isHovered","setIsHovered","useState","client","axios","create","baseURL","headers","Accept","withCredentials","timeout","createAxiosClient","buttonClasses","trim","badgeClasses","_jsxs","onClick","async","payload","rawOffer","offerId","post","then","res","catch","err","saveFlightOffer","toString","onMouseEnter","onMouseLeave","className","children","_jsx"],"mappings":";;;;;;+FAAgBA,EAAiBC,EAAqBC,GAAkB,GACpE,GAAIC,SAASC,eAAe,kBAAmB,OAE/C,MAAMC,EAAYF,SAASG,cAAc,OACzCD,EAAUE,GAAK,iBACfF,EAAUG,MAAMC,QAAU,yKAW1B,MAAMC,EAAUR,EAAS,+BAAiC,mCAG1D,IAAIS,EAAY,GAAGD,aAAmBT,IAGtC,GAAIW,OAAOC,SAASC,SAASC,SAAS,4BAA6B,CAM/DJ,EAAY,GAAGD,aALGE,OAAOC,SAASC,SAASE,MAAM,KAAKC,oBACpC,IAAIC,gBAAgBN,OAAOC,SAASM,QACzBC,IAAI,eAAiB,KAMlDR,OAAOS,QAAQC,aAAa,CAAEC,cAAc,EAAMC,iBAAiB,GAAQ,GAAIZ,OAAOC,SAASY,MAGnGpB,EAAUqB,UAAY,wCAEPf,iKAQfR,SAASwB,KAAKC,YAAYvB,GAG1BO,OAAOiB,iBAAiB,WAAYC,IAEhC,MAAMC,EAqBd,SAA4BC,EAAgB9B,GAExC,MAAM+B,EAAoB,CAAC,gCAGrBC,EAAqB,CACvB,mCACA,yBAGJ,OAAIhC,EAEO+B,EAAkBlB,SAASiB,GAG3BE,EAAmBnB,SAASiB,EAE3C,CAtCgCG,CAAmBL,EAAME,OAAQ9B,GAEzD,GAAI6B,GAAwC,2BAArBD,EAA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E,OAAOC,GAEG,ODHWC,CAAgBR,EAASf,GAC/C,IAAKiB,EAED,OAGJ,MAAMxE,EAAc,IAAIiB,gBAAgB,CACpCuD,UACAlC,WAAYU,IACb+B,WAEHpE,OAAOS,QAAQmB,UAAU,CAAEjB,cAAc,GAAQ,GAAI,mBAAmBtB,KACxED,EAAiBC,EAAaC,EAAO,EA0BjC+E,aAAc,IAAM3B,GAAa,GACjC4B,aAAc,IAAM5B,GAAa,GACjC6B,UAAWlB,EAAamB,SAAA,CAAA,mBAGxBC,cAAMF,UAAWhB,EAEViB,SAAA,YACF"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/MovmoCheckoutOverlay.tsx","../src/MovmoCheckoutButton.tsx","../src/api.ts"],"sourcesContent":["export function showMovmoOverlay(queryParams: string, isProd: boolean = false) {\n if (document.getElementById('movmo-checkout')) return;\n\n const container = document.createElement('div');\n container.id = 'movmo-checkout';\n container.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background: white;\n z-index: 9999;\n `;\n\n // Use production or development URL based on isProd flag\n const baseUrl = isProd ? 'https://flights.movmo.io' : 'https://flights.e2e.movmo.io';\n\n // Check if we're already on a booking confirmation URL\n let iframeUrl = `${baseUrl}/booking?${queryParams}`;\n\n // If the URL indicates we're on a booking confirmation page, load that instead\n if (window.location.pathname.includes('/movmo/checkout/booking/')) {\n const bookingId = window.location.pathname.split('/').pop();\n const urlParams = new URLSearchParams(window.location.search);\n const airlineRef = urlParams.get('airlineRef') || '';\n\n // Direct the iframe to the booking confirmation page\n iframeUrl = `${baseUrl}/booking/${bookingId}?airlineRef=${airlineRef}`;\n\n // Ensure we maintain the checkout state\n window.history.replaceState(\n { checkoutOpen: true, bookingComplete: true },\n '',\n window.location.href,\n );\n }\n\n container.innerHTML = `\n <iframe \n src=\"${iframeUrl}\"\n width=\"100%\" \n height=\"100%\" \n style=\"border: none;\"\n id=\"movmo-checkout-iframe\">\n </iframe>\n `;\n\n document.body.appendChild(container);\n\n // Setup communication channel with iframe\n window.addEventListener('message', (event) => {\n // Check if the origin is allowed\n const isAllowedOrigin = checkAllowedOrigin(event.origin, isProd);\n\n if (isAllowedOrigin && event.data?.type === 'MOVMO_BOOKING_COMPLETE') {\n const { bookingId, airlineRef } = event.data;\n if (bookingId) {\n // Update the parent URL to reflect booking completion\n window.history.pushState(\n { checkoutOpen: true, bookingComplete: true, bookingId },\n '',\n `/movmo/checkout/booking/${bookingId}?airlineRef=${airlineRef || ''}`,\n );\n }\n }\n });\n}\n\n/**\n * Check if an origin is allowed based on environment\n * - Production: Only flights.movmo.io is allowed\n * - Development: Allows flights.e2e.movmo.io and localhost:3000 only\n */\nfunction checkAllowedOrigin(origin: string, isProd: boolean): boolean {\n // Production origins (only used in production)\n const productionOrigins = ['https://flights.movmo.io'];\n\n // Development specific domains\n const devSpecificDomains = [\n 'https://flights.e2e.movmo.io',\n 'http://localhost:3000', // Specifically port 3000 for local development\n ];\n\n if (isProd) {\n // In production, only allow production origins\n return productionOrigins.includes(origin);\n } else {\n // In development, only allow development specific domains\n return devSpecificDomains.includes(origin);\n }\n}\n\n// Clean up when back button is used\nwindow.addEventListener('popstate', () => {\n const container = document.getElementById('movmo-checkout');\n if (!window.history.state?.checkoutOpen && container) {\n container.remove();\n }\n});\n\n/**\n * Determine if the current environment is production based on hostname\n * - Production: hostname contains neither 'e2e' nor 'localhost'\n * - Development/Testing: hostname contains 'e2e' or 'localhost'\n */\nfunction isProductionEnvironment(): boolean {\n const hostname = window.location.hostname;\n // Check if we're on production (neither e2e nor localhost)\n return !hostname.includes('e2e') && !hostname.includes('localhost');\n}\n\n// Handle page refresh or direct navigation to a booking confirmation URL\nif (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n const isBookingConfirmation = window.location.pathname.includes('/movmo/checkout/booking/');\n const isCheckoutPath = window.location.pathname.startsWith('/movmo/checkout');\n\n if (isBookingConfirmation || isCheckoutPath) {\n const queryParams = window.location.search.substring(1);\n const isProd = isProductionEnvironment();\n showMovmoOverlay(queryParams, isProd);\n }\n });\n}\n","import React, { useState } from 'react';\n\nimport { createAxiosClient, FlightOfferRequest, saveFlightOffer } from './api';\nimport { showMovmoOverlay } from './MovmoCheckoutOverlay';\n\ninterface MovmoCheckoutButtonProps {\n iataCode: string;\n apiKey: string;\n dataSource: \"amadeus\" | \"sabre\";\n // TODO: support fare splitting\n flightOffer: object;\n isProd?: boolean;\n}\n\nexport const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps> = ({\n iataCode,\n apiKey,\n dataSource,\n flightOffer,\n isProd = false,\n}) => {\n const [isHovered, setIsHovered] = useState(false);\n const client = createAxiosClient(apiKey, isProd);\n\n const handleClick = async () => {\n const payload: FlightOfferRequest = {\n dataSource,\n iataCode,\n rawOffer: flightOffer,\n };\n const offerId = await saveFlightOffer(payload, client);\n if (!offerId) {\n // TODO: handle error by displaying a message to the user\n return;\n }\n\n const queryParams = new URLSearchParams({\n offerId,\n airlineRef: iataCode,\n }).toString();\n\n window.history.pushState({ checkoutOpen: true }, '', `/movmo/checkout?${queryParams}`);\n showMovmoOverlay(queryParams, isProd);\n };\n\n const buttonClasses = `\n px-7 py-5 \n font-inter font-semibold text-lg \n rounded-xl \n text-white \n border-none\n cursor-pointer\n transition-all duration-200\n outline-none focus:ring-2 focus:ring-[#F63D68] focus:ring-opacity-50\n ${isHovered ? 'bg-gradient-hover' : 'bg-gradient-normal'}\n `.trim();\n\n const badgeClasses = `\n ml-2 px-2 py-1\n bg-white \n text-[#171412] \n rounded-md \n text-lg\n `.trim();\n\n return (\n <button\n onClick={handleClick}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n className={buttonClasses}\n >\n Express Checkout\n <span className={badgeClasses}>\n Movmo\n </span>\n </button>\n );\n};\n","import axios, { AxiosInstance } from 'axios';\n\nexport const createAxiosClient = (apiKey: string, isProd: boolean = false) => {\n const baseUrl = isProd ? 'https://api.movmo.io' : 'https://e2e.api.movmo.io';\n\n const client = axios.create({\n baseURL: baseUrl,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey,\n },\n // Allow cookies to be sent with requests\n withCredentials: true,\n timeout: 30000,\n });\n\n return client;\n};\n\nexport interface FlightOfferRequest {\n dataSource: string;\n iataCode: string;\n // The raw offer object from the data source; does not currently support fare splitting\n rawOffer: object;\n}\n\nexport const saveFlightOffer = async (\n payload: FlightOfferRequest,\n client: AxiosInstance,\n): Promise<string | null> => {\n return await client\n .post('/v1/flight_offers', payload)\n .then((res) => res.data.id)\n .catch((err) => {\n console.error(err);\n return null;\n });\n};\n"],"names":["showMovmoOverlay","queryParams","isProd","document","getElementById","container","createElement","id","style","cssText","baseUrl","iframeUrl","window","location","pathname","includes","split","pop","URLSearchParams","search","get","history","replaceState","checkoutOpen","bookingComplete","href","innerHTML","body","appendChild","addEventListener","event","isAllowedOrigin","origin","productionOrigins","devSpecificDomains","checkAllowedOrigin","data","type","bookingId","airlineRef","pushState","state","remove","isBookingConfirmation","isCheckoutPath","startsWith","substring","hostname","isProductionEnvironment","iataCode","apiKey","dataSource","flightOffer","isHovered","setIsHovered","useState","client","axios","create","baseURL","headers","Accept","withCredentials","timeout","createAxiosClient","buttonClasses","trim","badgeClasses","_jsxs","onClick","async","payload","rawOffer","offerId","post","then","res","catch","err","saveFlightOffer","toString","onMouseEnter","onMouseLeave","className","children","_jsx"],"mappings":";;;;;;+FAAgBA,EAAiBC,EAAqBC,GAAkB,GACtE,GAAIC,SAASC,eAAe,kBAAmB,OAE/C,MAAMC,EAAYF,SAASG,cAAc,OACzCD,EAAUE,GAAK,iBACfF,EAAUG,MAAMC,QAAU,yKAW1B,MAAMC,EAAUR,EAAS,2BAA6B,+BAGtD,IAAIS,EAAY,GAAGD,aAAmBT,IAGtC,GAAIW,OAAOC,SAASC,SAASC,SAAS,4BAA6B,CAMjEJ,EAAY,GAAGD,aALGE,OAAOC,SAASC,SAASE,MAAM,KAAKC,oB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gBAAoB,CAAA,CACpB,OAAA,cAAmB,CAAnB,MAAA,iBAAmB,CAAnB,gBAAA,cAAmB,CAAnB,YAAA,qBAAmB,CAAnB,YAAA,oBAAmB,CAAnB,QAAA,gBAAmB,CAAnB,aAAA,iBAAmB,CAAnB,UAAA,iBAAmB,CAAnB,sDAAmB,CAAnB,mBAAA,uDAAmB,CAAnB,oBAAA,uDAAmB,CAAnB,MAAA,kBAAmB,CAAnB,mBAAmB,CAAnB,MAAA,oBAAmB,CAAnB,qBAAmB,CAAnB,MAAA,qBAAA,CAAA,kBAAmB,CAAnB,MAAA,sBAAA,CAAA,mBAAmB,CAAnB,YAAA,4BAAmB,CAAnB,SAAA,kBAAmB,CAAnB,mBAAmB,CAAnB,eAAA,eAAmB,CAAnB,mBAAA,mBAAmB,CAAnB,0CAAmB,CAAnB,YAAA,mBAAmB,CAAnB,6CAAmB,CAAnB,cAAA,6BAAmB,CAAnB,kBAAmB,CAAnB,gBAAA,wBAAA,CAAA,uBAAmB,CAAnB,kDAAmB,CAAnB,cAAA,uBAAmB,CALnB,qBAAA,0GAKoB,CALpB,wGAKoB,CALpB,wFAKoB,CALpB,gCAAA,mBAKoB,CALpB,sDAKoB,CALpB,8BAAA,qBAKoB","file":"index.css","sourcesContent":["/* Import Inter font from Google Fonts */\n@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');\n\n@tailwind base;\n@tailwind components;\n@tailwind utilities;"]}
1
+ {"version":3,"sources":["index.css"],"names":[],"mappings":"AACA,+FAA+F,CAE/F,iBAAA,uBAAc,CAAd,uBAAc,CAAd,kBAAc,CAAd,kBAAc,CAAd,aAAc,CAAd,aAAc,CAAd,aAAc,CAAd,cAAc,CAAd,cAAc,CAAd,YAAc,CAAd,YAAc,CAAd,iBAAc,CAAd,qCAAc,CAAd,6BAAc,CAAd,4BAAc,CAAd,2BAAc,CAAd,cAAc,CAAd,mBAAc,CAAd,qBAAc,CAAd,sBAAc,CAAd,uBAAc,CAAd,i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0BAAA,WAAA,gBAAoB,CAAA,CAApB,0BAAA,WAAA,gBAAoB,CAAA,CACpB,OAAA,cAAmB,CAAnB,MAAA,iBAAmB,CAAnB,gBAAA,cAAmB,CAAnB,YAAA,qBAAmB,CAAnB,YAAA,oBAAmB,CAAnB,QAAA,gBAAmB,CAAnB,aAAA,iBAAmB,CAAnB,UAAA,iBAAmB,CAAnB,sDAAmB,CAAnB,mBAAA,uDAAmB,CAAnB,oBAAA,uDAAmB,CAAnB,MAAA,kBAAmB,CAAnB,mBAAmB,CAAnB,MAAA,oBAAmB,CAAnB,qBAAmB,CAAnB,MAAA,qBAAA,CAAA,kBAAmB,CAAnB,MAAA,sBAAA,CAAA,mBAAmB,CAAnB,YAAA,4BAAmB,CAAnB,SAAA,kBAAmB,CAAnB,mBAAmB,CAAnB,eAAA,eAAmB,CAAnB,mBAAA,mBAAmB,CAAnB,0CAAmB,CAAnB,YAAA,mBAAmB,CAAnB,6CAAmB,CAAnB,cAAA,6BAAmB,CAAnB,kBAAmB,CAAnB,gBAAA,wBAAA,CAAA,uBAAmB,CAAnB,kDAAmB,CAAnB,cAAA,uBAAmB,CALnB,qBAAA,0GAMA,CANA,wGAMA,CANA,wFAMA,CANA,gCAAA,mBAMA,CANA,sDAMA,CANA,8BAAA,qBAMA","file":"index.css","sourcesContent":["/* Import Inter font from Google Fonts */\n@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');\n\n@tailwind base;\n@tailwind components;\n@tailwind utilities;\n"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @movmo/express-checkout-button v1.0.1
2
+ * @movmo/express-checkout-button v1.0.3
3
3
  * React component plugin for embedding Movmo Express Checkout on airline websites.
4
4
  * (c) 2025 Movmo
5
5
  * @license MIT
@@ -7,7 +7,7 @@
7
7
  import React from 'react';
8
8
 
9
9
  interface MovmoCheckoutButtonProps {
10
- customerId: string;
10
+ iataCode: string;
11
11
  apiKey: string;
12
12
  dataSource: "amadeus" | "sabre";
13
13
  flightOffer: object;
package/dist/index.es.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @movmo/express-checkout-button v1.0.1
2
+ * @movmo/express-checkout-button v1.0.3
3
3
  * React component plugin for embedding Movmo Express Checkout on airline websites.
4
4
  * (c) 2025 Movmo
5
5
  * @license MIT
6
6
  */
7
- import{jsxs as o,jsx as n}from"react/jsx-runtime";import{useState as t}from"react";import e from"axios";function i(o,n=!1){if(document.getElementById("movmo-checkout"))return;const t=document.createElement("div");t.id="movmo-checkout",t.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background: white;\n z-index: 9999;\n ";const e=n?"https://booking.app.movmo.io":"https://booking-e2e.app.movmo.io";let i=`${e}/booking?${o}`;if(window.location.pathname.includes("/movmo/checkout/booking/")){i=`${e}/booking/${window.location.pathname.split("/").pop()}?airlineRef=${new URLSearchParams(window.location.search).get("airlineRef")||""}`,window.history.replaceState({checkoutOpen:!0,bookingComplete:!0},"",window.location.href)}t.innerHTML=`\n <iframe \n src="${i}"\n width="100%" \n height="100%" \n style="border: none;"\n id="movmo-checkout-iframe">\n </iframe>\n `,document.body.appendChild(t),window.addEventListener("message",(o=>{const t=function(o,n){const t=["https://booking.app.movmo.io"],e=["https://booking-e2e.app.movmo.io","http://localhost:3000"];return n?t.includes(o):e.includes(o)}(o.origin,n);if(t&&"MOVMO_BOOKING_COMPLETE"===o.data?.type){const{bookingId:n,airlineRef:t}=o.data;n&&window.history.pushState({checkoutOpen:!0,bookingComplete:!0,bookingId:n},"",`/movmo/checkout/booking/${n}?airlineRef=${t||""}`)}}))}window.addEventListener("popstate",(()=>{const o=document.getElementById("movmo-checkout");!window.history.state?.checkoutOpen&&o&&o.remove()})),"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(()=>{const o=window.location.pathname.includes("/movmo/checkout/booking/"),n=window.location.pathname.startsWith("/movmo/checkout");if(o||n){i(window.location.search.substring(1),function(){const o=window.location.hostname;return!o.includes("e2e")&&!o.includes("localhost")}())}}));const a=({customerId:a,apiKey:c,dataSource:r,flightOffer:s,isProd:d=!1})=>{const[m,p]=t(!1),h=((o,n=!1)=>{const t=n?"https://api.movmo.io":"https://e2e.api.movmo.io";return e.create({baseURL:t,headers:{Accept:"application/json","Content-Type":"application/json","x-api-key":o},withCredentials:!0,timeout:3e4})})(c,d),l=`\n px-7 py-5 \n font-inter font-semibold text-lg \n rounded-xl \n text-white \n border-none\n cursor-pointer\n transition-all duration-200\n outline-none focus:ring-2 focus:ring-[#F63D68] focus:ring-opacity-50\n ${m?"bg-gradient-hover":"bg-gradient-normal"}\n `.trim(),u="\n ml-2 px-2 py-1\n bg-white \n text-[#171412] \n rounded-md \n text-lg\n ".trim();return o("button",{onClick:async()=>{const o={dataSource:r,customerId:a,rawOffer:s},n=await(async(o,n)=>await n.post("/v1/flight_offers",o).then((o=>o.data.id)).catch((o=>null)))(o,h);if(!n)return;const t=new URLSearchParams({offerId:n,airlineRef:a}).toString();window.history.pushState({checkoutOpen:!0},"",`/movmo/checkout?${t}`),i(t,d)},onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),className:l,children:["Express Checkout",n("span",{className:u,children:"Movmo"})]})};export{a as MovmoCheckoutButton};
7
+ import{jsxs as o,jsx as t}from"react/jsx-runtime";import{useState as n}from"react";import e from"axios";function i(o,t=!1){if(document.getElementById("movmo-checkout"))return;const n=document.createElement("div");n.id="movmo-checkout",n.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background: white;\n z-index: 9999;\n ";const e=t?"https://flights.movmo.io":"https://flights.e2e.movmo.io";let i=`${e}/booking?${o}`;if(window.location.pathname.includes("/movmo/checkout/booking/")){i=`${e}/booking/${window.location.pathname.split("/").pop()}?airlineRef=${new URLSearchParams(window.location.search).get("airlineRef")||""}`,window.history.replaceState({checkoutOpen:!0,bookingComplete:!0},"",window.location.href)}n.innerHTML=`\n <iframe \n src="${i}"\n width="100%" \n height="100%" \n style="border: none;"\n id="movmo-checkout-iframe">\n </iframe>\n `,document.body.appendChild(n),window.addEventListener("message",(o=>{const n=function(o,t){const n=["https://flights.movmo.io"],e=["https://flights.e2e.movmo.io","http://localhost:3000"];return t?n.includes(o):e.includes(o)}(o.origin,t);if(n&&"MOVMO_BOOKING_COMPLETE"===o.data?.type){const{bookingId:t,airlineRef:n}=o.data;t&&window.history.pushState({checkoutOpen:!0,bookingComplete:!0,bookingId:t},"",`/movmo/checkout/booking/${t}?airlineRef=${n||""}`)}}))}window.addEventListener("popstate",(()=>{const o=document.getElementById("movmo-checkout");!window.history.state?.checkoutOpen&&o&&o.remove()})),"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(()=>{const o=window.location.pathname.includes("/movmo/checkout/booking/"),t=window.location.pathname.startsWith("/movmo/checkout");if(o||t){i(window.location.search.substring(1),function(){const o=window.location.hostname;return!o.includes("e2e")&&!o.includes("localhost")}())}}));const a=({iataCode:a,apiKey:c,dataSource:r,flightOffer:s,isProd:d=!1})=>{const[m,h]=n(!1),l=((o,t=!1)=>{const n=t?"https://api.movmo.io":"https://e2e.api.movmo.io";return e.create({baseURL:n,headers:{Accept:"application/json","Content-Type":"application/json","x-api-key":o},withCredentials:!0,timeout:3e4})})(c,d),p=`\n px-7 py-5 \n font-inter font-semibold text-lg \n rounded-xl \n text-white \n border-none\n cursor-pointer\n transition-all duration-200\n outline-none focus:ring-2 focus:ring-[#F63D68] focus:ring-opacity-50\n ${m?"bg-gradient-hover":"bg-gradient-normal"}\n `.trim(),u="\n ml-2 px-2 py-1\n bg-white \n text-[#171412] \n rounded-md \n text-lg\n ".trim();return o("button",{onClick:async()=>{const o={dataSource:r,iataCode:a,rawOffer:s},t=await(async(o,t)=>await t.post("/v1/flight_offers",o).then((o=>o.data.id)).catch((o=>null)))(o,l);if(!t)return;const n=new URLSearchParams({offerId:t,airlineRef:a}).toString();window.history.pushState({checkoutOpen:!0},"",`/movmo/checkout?${n}`),i(n,d)},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),className:p,children:["Express Checkout",t("span",{className:u,children:"Movmo"})]})};export{a as MovmoCheckoutButton};
8
8
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/MovmoCheckoutOverlay.tsx","../src/MovmoCheckoutButton.tsx","../src/api.ts"],"sourcesContent":["export function showMovmoOverlay(queryParams: string, isProd: boolean = false) {\n if (document.getElementById('movmo-checkout')) return;\n\n const container = document.createElement('div');\n container.id = 'movmo-checkout';\n container.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background: white;\n z-index: 9999;\n `;\n\n // Use production or development URL based on isProd flag\n const baseUrl = isProd ? \"https://booking.app.movmo.io\" : \"https://booking-e2e.app.movmo.io\";\n\n // Check if we're already on a booking confirmation URL\n let iframeUrl = `${baseUrl}/booking?${queryParams}`;\n\n // If the URL indicates we're on a booking confirmation page, load that instead\n if (window.location.pathname.includes('/movmo/checkout/booking/')) {\n const bookingId = window.location.pathname.split('/').pop();\n const urlParams = new URLSearchParams(window.location.search);\n const airlineRef = urlParams.get('airlineRef') || '';\n\n // Direct the iframe to the booking confirmation page\n iframeUrl = `${baseUrl}/booking/${bookingId}?airlineRef=${airlineRef}`;\n\n // Ensure we maintain the checkout state\n window.history.replaceState({ checkoutOpen: true, bookingComplete: true }, '', window.location.href);\n }\n\n container.innerHTML = `\n <iframe \n src=\"${iframeUrl}\"\n width=\"100%\" \n height=\"100%\" \n style=\"border: none;\"\n id=\"movmo-checkout-iframe\">\n </iframe>\n `;\n\n document.body.appendChild(container);\n\n // Setup communication channel with iframe\n window.addEventListener('message', (event) => {\n // Check if the origin is allowed\n const isAllowedOrigin = checkAllowedOrigin(event.origin, isProd);\n\n if (isAllowedOrigin && event.data?.type === 'MOVMO_BOOKING_COMPLETE') {\n const { bookingId, airlineRef } = event.data;\n if (bookingId) {\n // Update the parent URL to reflect booking completion\n window.history.pushState(\n { checkoutOpen: true, bookingComplete: true, bookingId },\n '',\n `/movmo/checkout/booking/${bookingId}?airlineRef=${airlineRef || ''}`\n );\n }\n }\n });\n}\n\n/**\n * Check if an origin is allowed based on environment\n * - Production: Only booking.app.movmo.io is allowed\n * - Development: Allows booking-e2e.app.movmo.io and localhost:3000 only\n */\nfunction checkAllowedOrigin(origin: string, isProd: boolean): boolean {\n // Production origins (only used in production)\n const productionOrigins = ['https://booking.app.movmo.io'];\n\n // Development specific domains\n const devSpecificDomains = [\n 'https://booking-e2e.app.movmo.io',\n 'http://localhost:3000' // Specifically port 3000 for local development\n ];\n\n if (isProd) {\n // In production, only allow production origins\n return productionOrigins.includes(origin);\n } else {\n // In development, only allow development specific domains\n return devSpecificDomains.includes(origin);\n }\n}\n\n// Clean up when back button is used\nwindow.addEventListener('popstate', () => {\n const container = document.getElementById('movmo-checkout');\n if (!window.history.state?.checkoutOpen && container) {\n container.remove();\n }\n});\n\n/**\n * Determine if the current environment is production based on hostname\n * - Production: hostname contains neither 'e2e' nor 'localhost'\n * - Development/Testing: hostname contains 'e2e' or 'localhost'\n */\nfunction isProductionEnvironment(): boolean {\n const hostname = window.location.hostname;\n // Check if we're on production (neither e2e nor localhost)\n return !hostname.includes('e2e') && !hostname.includes('localhost');\n}\n\n// Handle page refresh or direct navigation to a booking confirmation URL\nif (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n const isBookingConfirmation = window.location.pathname.includes('/movmo/checkout/booking/');\n const isCheckoutPath = window.location.pathname.startsWith('/movmo/checkout');\n\n if (isBookingConfirmation || isCheckoutPath) {\n const queryParams = window.location.search.substring(1);\n const isProd = isProductionEnvironment();\n showMovmoOverlay(queryParams, isProd);\n }\n });\n}\n","import React, { useState } from 'react';\n\nimport { createAxiosClient, FlightOfferRequest, saveFlightOffer } from './api';\nimport { showMovmoOverlay } from './MovmoCheckoutOverlay';\n\ninterface MovmoCheckoutButtonProps {\n customerId: string;\n apiKey: string;\n dataSource: \"amadeus\" | \"sabre\";\n // TODO: support fare splitting\n flightOffer: object;\n isProd?: boolean;\n}\n\nexport const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps> = ({\n customerId,\n apiKey,\n dataSource,\n flightOffer,\n isProd = false,\n}) => {\n const [isHovered, setIsHovered] = useState(false);\n const client = createAxiosClient(apiKey, isProd);\n\n const handleClick = async () => {\n const payload: FlightOfferRequest = {\n dataSource,\n customerId,\n rawOffer: flightOffer,\n };\n const offerId = await saveFlightOffer(payload, client);\n if (!offerId) {\n // TODO: handle error by displaying a message to the user\n return;\n }\n\n const queryParams = new URLSearchParams({\n offerId,\n airlineRef: customerId,\n }).toString();\n\n window.history.pushState({ checkoutOpen: true }, '', `/movmo/checkout?${queryParams}`);\n showMovmoOverlay(queryParams, isProd);\n };\n\n const buttonClasses = `\n px-7 py-5 \n font-inter font-semibold text-lg \n rounded-xl \n text-white \n border-none\n cursor-pointer\n transition-all duration-200\n outline-none focus:ring-2 focus:ring-[#F63D68] focus:ring-opacity-50\n ${isHovered ? 'bg-gradient-hover' : 'bg-gradient-normal'}\n `.trim();\n\n const badgeClasses = `\n ml-2 px-2 py-1\n bg-white \n text-[#171412] \n rounded-md \n text-lg\n `.trim();\n\n return (\n <button\n onClick={handleClick}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n className={buttonClasses}\n >\n Express Checkout\n <span className={badgeClasses}>\n Movmo\n </span>\n </button>\n );\n};\n","import axios, { AxiosInstance } from \"axios\";\n\n\nexport const createAxiosClient = (apiKey: string, isProd: boolean = false) => {\n const baseUrl = isProd ? \"https://api.movmo.io\" : \"https://e2e.api.movmo.io\";\n\n const client = axios.create({\n baseURL: baseUrl,\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey,\n },\n // Allow cookies to be sent with requests\n withCredentials: true,\n timeout: 30000,\n });\n\n return client;\n};\n\nexport interface FlightOfferRequest {\n dataSource: string;\n customerId: string;\n // The raw offer object from the data source; does not currently support fare splitting\n rawOffer: object;\n}\n\nexport const saveFlightOffer = async (payload: FlightOfferRequest, client: AxiosInstance): Promise<string | null> => {\n return await client.post(\"/v1/flight_offers\", payload)\n .then((res) => res.data.id)\n .catch((err) => {\n console.error(err);\n return null;\n });\n};\n"],"names":["showMovmoOverlay","queryParams","isProd","document","getElementById","container","createElement","id","style","cssText","baseUrl","iframeUrl","window","location","pathname","includes","split","pop","URLSearchParams","search","get","history","replaceState","checkoutOpen","bookingComplete","href","innerHTML","body","appendChild","addEventListener","event","isAllowedOrigin","origin","productionOrigins","devSpecificDomains","checkAllowedOrigin","data","type","bookingId","airlineRef","pushState","state","remove","isBookingConfirmation","isCheckoutPath","startsWith","substring","hostname","isProductionEnvironment","MovmoCheckoutButton","customerId","apiKey","dataSource","flightOffer","isHovered","setIsHovered","useState","client","axios","create","baseURL","headers","Accept","withCredentials","timeout","createAxiosClient","buttonClasses","trim","badgeClasses","_jsxs","onClick","async","payload","rawOffer","offerId","post","then","res","catch","err","saveFlightOffer","toString","onMouseEnter","onMouseLeave","className","children","_jsx"],"mappings":";;;;;;iHAAgBA,EAAiBC,EAAqBC,GAAkB,GACpE,GAAIC,SAASC,eAAe,kBAAmB,OAE/C,MAAMC,EAAYF,SAASG,cAAc,OACzCD,EAAUE,GAAK,iBACfF,EAAUG,MAAMC,QAAU,yKAW1B,MAAMC,EAAUR,EAAS,+BAAiC,mCAG1D,IAAIS,EAAY,GAAGD,aAAmBT,IAGtC,GAAIW,OAAOC,SAASC,SAASC,SAAS,4BAA6B,CAM/DJ,EAAY,GAAGD,aALGE,OAAOC,SAASC,SAASE,MAAM,KAAKC,oBACpC,IAAIC,gBAAgBN,OAAOC,SAASM,QACzBC,IAAI,eAAiB,KAMlDR,OAAOS,QAAQC,aAAa,CAAEC,cAAc,EAAMC,iBAAiB,GAAQ,GAAIZ,OAAOC,SAASY,MAGnGpB,EAAUqB,UAAY,wCAEPf,iKAQfR,SAASwB,KAAKC,Y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Bd,EAAQjD,GAuBnCgE,EAAgB,sRAShBZ,EAAY,oBAAsB,6BACtCa,OAEIC,EAAe,mHAMnBD,OAEF,OACIE,EACI,SAAA,CAAAC,QA3CYC,UAChB,MAAMC,EAA8B,CAChCpB,aACAF,aACAuB,SAAUpB,GAERqB,OCFiBH,OAAOC,EAA6Bf,UAClDA,EAAOkB,KAAK,oBAAqBH,GACzCI,MAAMC,GAAQA,EAAIzC,KAAK7B,KACvBuE,OAAOC,GAEG,ODHWC,CAAgBR,EAASf,GAC/C,IAAKiB,EAED,OAGJ,MAAMzE,EAAc,IAAIiB,gBAAgB,CACpCwD,UACAnC,WAAYW,IACb+B,WAEHrE,OAAOS,QAAQmB,UAAU,CAAEjB,cAAc,GAAQ,GAAI,mBAAmBtB,KACxED,EAAiBC,EAAaC,EAAO,EA0BjCgF,aAAc,IAAM3B,GAAa,GACjC4B,aAAc,IAAM5B,GAAa,GACjC6B,UAAWlB,EAAamB,SAAA,CAAA,mBAGxBC,UAAMF,UAAWhB,EAEViB,SAAA,YACF"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/MovmoCheckoutOverlay.tsx","../src/MovmoCheckoutButton.tsx","../src/api.ts"],"sourcesContent":["export function showMovmoOverlay(queryParams: string, isProd: boolean = false) {\n if (document.getElementById('movmo-checkout')) return;\n\n const container = document.createElement('div');\n container.id = 'movmo-checkout';\n container.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background: white;\n z-index: 9999;\n `;\n\n // Use production or development URL based on isProd flag\n const baseUrl = isProd ? 'https://flights.movmo.io' : 'https://flights.e2e.movmo.io';\n\n // Check if we're already on a booking confirmation URL\n let iframeUrl = `${baseUrl}/booking?${queryParams}`;\n\n // If the URL indicates we're on a booking confirmation page, load that instead\n if (window.location.pathname.includes('/movmo/checkout/booking/')) {\n const bookingId = window.location.pathname.split('/').pop();\n const urlParams = new URLSearchParams(window.location.search);\n const airlineRef = urlParams.get('airlineRef') || '';\n\n // Direct the iframe to the booking confirmation page\n iframeUrl = `${baseUrl}/booking/${bookingId}?airlineRef=${airlineRef}`;\n\n // Ensure we maintain the checkout state\n window.history.replaceState(\n { checkoutOpen: true, bookingComplete: true },\n '',\n window.location.href,\n );\n }\n\n container.innerHTML = `\n <iframe \n src=\"${iframeUrl}\"\n width=\"100%\" \n height=\"100%\" \n style=\"border: none;\"\n id=\"movmo-checkout-iframe\">\n </iframe>\n `;\n\n document.body.appendChild(container);\n\n // Setup communication channel with iframe\n window.addEventListener('message', (event) => {\n // Check if the origin is allowed\n const isAllowedOrigin = checkAllowedOrigin(event.origin, isProd);\n\n if (isAllowedOrigin && event.data?.type === 'MOVMO_BOOKING_COMPLETE') {\n const { bookingId, airlineRef } = event.data;\n if (bookingId) {\n // Update the parent URL to reflect booking completion\n window.history.pushState(\n { checkoutOpen: true, bookingComplete: true, bookingId },\n '',\n `/movmo/checkout/booking/${bookingId}?airlineRef=${airlineRef || ''}`,\n );\n }\n }\n });\n}\n\n/**\n * Check if an origin is allowed based on environment\n * - Production: Only flights.movmo.io is allowed\n * - Development: Allows flights.e2e.movmo.io and localhost:3000 only\n */\nfunction checkAllowedOrigin(origin: string, isProd: boolean): boolean {\n // Production origins (only used in production)\n const productionOrigins = ['https://flights.movmo.io'];\n\n // Development specific domains\n const devSpecificDomains = [\n 'https://flights.e2e.movmo.io',\n 'http://localhost:3000', // Specifically port 3000 for local development\n ];\n\n if (isProd) {\n // In production, only allow production origins\n return productionOrigins.includes(origin);\n } else {\n // In development, only allow development specific domains\n return devSpecificDomains.includes(origin);\n }\n}\n\n// Clean up when back button is used\nwindow.addEventListener('popstate', () => {\n const container = document.getElementById('movmo-checkout');\n if (!window.history.state?.checkoutOpen && container) {\n container.remove();\n }\n});\n\n/**\n * Determine if the current environment is production based on hostname\n * - Production: hostname contains neither 'e2e' nor 'localhost'\n * - Development/Testing: hostname contains 'e2e' or 'localhost'\n */\nfunction isProductionEnvironment(): boolean {\n const hostname = window.location.hostname;\n // Check if we're on production (neither e2e nor localhost)\n return !hostname.includes('e2e') && !hostname.includes('localhost');\n}\n\n// Handle page refresh or direct navigation to a booking confirmation URL\nif (typeof window !== 'undefined') {\n window.addEventListener('DOMContentLoaded', () => {\n const isBookingConfirmation = window.location.pathname.includes('/movmo/checkout/booking/');\n const isCheckoutPath = window.location.pathname.startsWith('/movmo/checkout');\n\n if (isBookingConfirmation || isCheckoutPath) {\n const queryParams = window.location.search.substring(1);\n const isProd = isProductionEnvironment();\n showMovmoOverlay(queryParams, isProd);\n }\n });\n}\n","import React, { useState } from 'react';\n\nimport { createAxiosClient, FlightOfferRequest, saveFlightOffer } from './api';\nimport { showMovmoOverlay } from './MovmoCheckoutOverlay';\n\ninterface MovmoCheckoutButtonProps {\n iataCode: string;\n apiKey: string;\n dataSource: \"amadeus\" | \"sabre\";\n // TODO: support fare splitting\n flightOffer: object;\n isProd?: boolean;\n}\n\nexport const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps> = ({\n iataCode,\n apiKey,\n dataSource,\n flightOffer,\n isProd = false,\n}) => {\n const [isHovered, setIsHovered] = useState(false);\n const client = createAxiosClient(apiKey, isProd);\n\n const handleClick = async () => {\n const payload: FlightOfferRequest = {\n dataSource,\n iataCode,\n rawOffer: flightOffer,\n };\n const offerId = await saveFlightOffer(payload, client);\n if (!offerId) {\n // TODO: handle error by displaying a message to the user\n return;\n }\n\n const queryParams = new URLSearchParams({\n offerId,\n airlineRef: iataCode,\n }).toString();\n\n window.history.pushState({ checkoutOpen: true }, '', `/movmo/checkout?${queryParams}`);\n showMovmoOverlay(queryParams, isProd);\n };\n\n const buttonClasses = `\n px-7 py-5 \n font-inter font-semibold text-lg \n rounded-xl \n text-white \n border-none\n cursor-pointer\n transition-all duration-200\n outline-none focus:ring-2 focus:ring-[#F63D68] focus:ring-opacity-50\n ${isHovered ? 'bg-gradient-hover' : 'bg-gradient-normal'}\n `.trim();\n\n const badgeClasses = `\n ml-2 px-2 py-1\n bg-white \n text-[#171412] \n rounded-md \n text-lg\n `.trim();\n\n return (\n <button\n onClick={handleClick}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n className={buttonClasses}\n >\n Express Checkout\n <span className={badgeClasses}>\n Movmo\n </span>\n </button>\n );\n};\n","import axios, { AxiosInstance } from 'axios';\n\nexport const createAxiosClient = (apiKey: string, isProd: boolean = false) => {\n const baseUrl = isProd ? 'https://api.movmo.io' : 'https://e2e.api.movmo.io';\n\n const client = axios.create({\n baseURL: baseUrl,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey,\n },\n // Allow cookies to be sent with requests\n withCredentials: true,\n timeout: 30000,\n });\n\n return client;\n};\n\nexport interface FlightOfferRequest {\n dataSource: string;\n iataCode: string;\n // The raw offer object from the data source; does not currently support fare splitting\n rawOffer: object;\n}\n\nexport const saveFlightOffer = async (\n payload: FlightOfferRequest,\n client: AxiosInstance,\n): Promise<string | null> => {\n return await client\n .post('/v1/flight_offers', payload)\n .then((res) => res.data.id)\n .catch((err) => {\n console.error(err);\n return null;\n });\n};\n"],"names":["showMovmoOverlay","queryParams","isProd","document","getElementById","container","createElement","id","style","cssText","baseUrl","iframeUrl","window","location","pathname","includes","split","pop","URLSearchParams","search","get","history","replaceState","checkoutOpen","bookingComplete","href","innerHTML","body","appendChild","addEventListener","event","isAllowedOrigin","origin","productionOrigins","devSpecificDomains","checkAllowedOrigin","data","type","bookingId","airlineRef","pushState","state","remove","isBookingConfirmation","isCheckoutPath","startsWith","substring","hostname","isProductionEnvironment","MovmoCheckoutButton","iataCode","apiKey","dataSource","flightOffer","isHovered","setIsHovered","useState","client","axios","create","baseURL","headers","Accept","withCredentials","timeout","createAxiosClient","buttonClasses","trim","badgeClasses","_jsxs","onClick","async","payload","rawOffer","offerId","post","then","res","catch","err","saveFlightOffer","toString","onMouseEnter","onMouseLeave","className","children","_jsx"],"mappings":";;;;;;iHAAgBA,EAAiBC,EAAqBC,GAAkB,GACtE,G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GAAIF,GAAyBC,EAAgB,CAG3C5C,EAFoBY,OAAOC,SAASM,OAAO2B,UAAU,GAb3D,WACE,MAAMC,EAAWnC,OAAOC,SAASkC,SAEjC,OAAQA,EAAShC,SAAS,SAAWgC,EAAShC,SAAS,YACzD,CAUqBiC,QC1GR,MAAAC,EAA0D,EACnEC,WACAC,SACAC,aACAC,cACAnD,UAAS,MAET,MAAOoD,EAAWC,GAAgBC,GAAS,GACrCC,ECpBuB,EAACN,EAAgBjD,GAAkB,KAClE,MAAMQ,EAAUR,EAAS,uBAAyB,2BAclD,OAZewD,EAAMC,OAAO,CAC1BC,QAASlD,EACTmD,QAAS,CACPC,OAAQ,mBACR,eAAgB,mBAChB,YAAaX,GAGfY,iBAAiB,EACjBC,QAAS,KAGE,EDKIC,CAAkBd,EAAQjD,GAuBnCgE,EAAgB,sRAShBZ,EAAY,oBAAsB,6BACtCa,OAEIC,EAAe,mHAMnBD,OAEF,OACIE,EACI,SAAA,CAAAC,QA3CYC,UAChB,MAAMC,EAA8B,CAChCpB,aACAF,WACAuB,SAAUpB,GAERqB,OCHiBH,OAC7BC,EACAf,UAEaA,EACVkB,KAAK,oBAAqBH,GAC1BI,MAAMC,GAAQA,EAAIzC,KAAK7B,KACvBuE,OAAOC,GAEC,ODNiBC,CAAgBR,EAASf,GAC/C,IAAKiB,EAED,OAGJ,MAAMzE,EAAc,IAAIiB,gBAAgB,CACpCwD,UACAnC,WAAYW,IACb+B,WAEHrE,OAAOS,QAAQmB,UAAU,CAAEjB,cAAc,GAAQ,GAAI,mBAAmBtB,KACxED,EAAiBC,EAAaC,EAAO,EA0BjCgF,aAAc,IAAM3B,GAAa,GACjC4B,aAAc,IAAM5B,GAAa,GACjC6B,UAAWlB,EAAamB,SAAA,CAAA,mBAGxBC,UAAMF,UAAWhB,EAEViB,SAAA,YACF"}
package/package.json CHANGED
@@ -1,84 +1,85 @@
1
1
  {
2
- "name": "@movmo/express-checkout-button",
3
- "version": "1.0.1",
4
- "description": "React component plugin for embedding Movmo Express Checkout on airline websites.",
5
- "type": "module",
6
- "main": "dist/index.cjs.js",
7
- "module": "dist/index.es.js",
8
- "types": "dist/index.d.ts",
9
- "publishConfig": {
10
- "access": "public"
2
+ "name": "@movmo/express-checkout-button",
3
+ "version": "1.0.3",
4
+ "description": "React component plugin for embedding Movmo Express Checkout on airline websites.",
5
+ "type": "module",
6
+ "main": "dist/index.cjs.js",
7
+ "module": "dist/index.es.js",
8
+ "types": "dist/index.d.ts",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "dist/index.css"
15
+ ],
16
+ "scripts": {
17
+ "build": "rollup -c && tsc --emitDeclarationOnly",
18
+ "storybook": "storybook dev -p 6006",
19
+ "build-storybook": "storybook build"
20
+ },
21
+ "keywords": [
22
+ "movmo",
23
+ "checkout",
24
+ "plugin",
25
+ "airline",
26
+ "flights",
27
+ "react",
28
+ "iframe"
29
+ ],
30
+ "dependencies": {
31
+ "axios": "^1.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@chromatic-com/storybook": "^3.0.0",
35
+ "@rollup/plugin-commonjs": "^25.0.0",
36
+ "@rollup/plugin-node-resolve": "^15.0.0",
37
+ "@rollup/plugin-terser": "^0.4.0",
38
+ "@rollup/plugin-typescript": "^11.0.0",
39
+ "@storybook/addon-essentials": "^8.6.0",
40
+ "@storybook/addon-interactions": "^8.6.0",
41
+ "@storybook/addon-links": "^8.6.0",
42
+ "@storybook/addon-onboarding": "^8.6.0",
43
+ "@storybook/blocks": "^8.6.0",
44
+ "@storybook/react": "^8.6.0",
45
+ "@storybook/react-vite": "^8.6.0",
46
+ "@storybook/test": "^8.6.0",
47
+ "@types/node": "^22.15.3",
48
+ "@types/react": "^17.0.0 || ^18.0.0",
49
+ "@types/react-dom": "^17.0.0 || ^18.0.0",
50
+ "autoprefixer": "^10.4.16",
51
+ "postcss": "^8.4.32",
52
+ "rollup": "^4.0.0",
53
+ "rollup-plugin-dts": "^6.0.0",
54
+ "rollup-plugin-peer-deps-external": "^2.2.4",
55
+ "rollup-plugin-postcss": "^4.0.2",
56
+ "storybook": "^8.6.0",
57
+ "tailwindcss": "^3.4.0",
58
+ "tailwindcss-animate": "^1.0.0",
59
+ "tailwindcss-font-inter": "^4.0.0",
60
+ "typescript": "^4.0.0 || ^5.0.0",
61
+ "vite": "^6.2.1"
62
+ },
63
+ "peerDependencies": {
64
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
65
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
66
+ },
67
+ "peerDependenciesMeta": {
68
+ "react": {
69
+ "optional": false
11
70
  },
12
- "files": [
13
- "dist",
14
- "dist/index.css"
15
- ],
16
- "scripts": {
17
- "build": "rollup -c && tsc --emitDeclarationOnly",
18
- "storybook": "storybook dev -p 6006",
19
- "build-storybook": "storybook build"
20
- },
21
- "keywords": [
22
- "movmo",
23
- "checkout",
24
- "plugin",
25
- "airline",
26
- "react",
27
- "iframe"
28
- ],
29
- "dependencies": {
30
- "axios": "^1.0.0"
31
- },
32
- "devDependencies": {
33
- "@chromatic-com/storybook": "^3.0.0",
34
- "@rollup/plugin-commonjs": "^25.0.0",
35
- "@rollup/plugin-node-resolve": "^15.0.0",
36
- "@rollup/plugin-terser": "^0.4.0",
37
- "@rollup/plugin-typescript": "^11.0.0",
38
- "@storybook/addon-essentials": "^8.6.0",
39
- "@storybook/addon-interactions": "^8.6.0",
40
- "@storybook/addon-links": "^8.6.0",
41
- "@storybook/addon-onboarding": "^8.6.0",
42
- "@storybook/blocks": "^8.6.0",
43
- "@storybook/react": "^8.6.0",
44
- "@storybook/react-vite": "^8.6.0",
45
- "@storybook/test": "^8.6.0",
46
- "@types/node": "^22.15.3",
47
- "@types/react": "^17.0.0 || ^18.0.0",
48
- "@types/react-dom": "^17.0.0 || ^18.0.0",
49
- "autoprefixer": "^10.4.16",
50
- "postcss": "^8.4.32",
51
- "rollup": "^4.0.0",
52
- "rollup-plugin-dts": "^6.0.0",
53
- "rollup-plugin-peer-deps-external": "^2.2.4",
54
- "rollup-plugin-postcss": "^4.0.2",
55
- "storybook": "^8.6.0",
56
- "tailwindcss": "^3.4.0",
57
- "tailwindcss-animate": "^1.0.0",
58
- "tailwindcss-font-inter": "^4.0.0",
59
- "typescript": "^4.0.0 || ^5.0.0",
60
- "vite": "^6.2.1"
61
- },
62
- "peerDependencies": {
63
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
64
- "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
65
- },
66
- "peerDependenciesMeta": {
67
- "react": {
68
- "optional": false
69
- },
70
- "react-dom": {
71
- "optional": false
72
- }
73
- },
74
- "repository": {
75
- "type": "git",
76
- "url": "git+https://github.com/movmo-app/react-js-packages.git"
77
- },
78
- "author": "Movmo",
79
- "license": "MIT",
80
- "bugs": {
81
- "url": "https://github.com/movmo-app/react-js-packages/issues"
82
- },
83
- "homepage": "https://github.com/movmo-app/react-js-packages/blob/main/packages/@movmo/express-checkout-button/README.md"
84
- }
71
+ "react-dom": {
72
+ "optional": false
73
+ }
74
+ },
75
+ "repository": {
76
+ "type": "git",
77
+ "url": "git+https://github.com/movmo-app/react-js-packages.git"
78
+ },
79
+ "author": "Movmo",
80
+ "license": "MIT",
81
+ "bugs": {
82
+ "url": "https://github.com/movmo-app/react-js-packages/issues"
83
+ },
84
+ "homepage": "https://github.com/movmo-app/react-js-packages/blob/main/packages/@movmo/express-checkout-button/README.md"
85
+ }