@movmo/express-checkout-button 0.1.10 → 0.1.11

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.cjs.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @movmo/express-checkout-button v0.1.10
2
+ * @movmo/express-checkout-button v0.1.11
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.movmo.io":"https://booking.e2e.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=>{if(["https://booking.movmo.io","https://booking.e2e.movmo.io"].includes(o.origin)&&"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),-1===window.location.hostname.indexOf("e2e"))}}));exports.MovmoCheckoutButton=({customerId:i,apiKey:a,dataSource:r,flightOffer:c,isProd:s=!1})=>{const[d,m]=e.useState(!1),h=((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),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(),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:r,rawOffer:c},e=await(async(o,e)=>await e.post("/v1/flight_offers",o).then((o=>o.data.id)).catch((o=>null)))(o,h);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:u,children:["Express Checkout",o.jsx("span",{className:p,children:"Movmo"})]})};
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.movmo.io":"https://booking.e2e.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.movmo.io"],t=["https://booking.e2e.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(),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,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: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.movmo.io\" : \"https://booking.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({ 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 // Verify origin for security\n const allowedOrigins = [\n 'https://booking.movmo.io',\n 'https://booking.e2e.movmo.io'\n ];\n\n if (allowedOrigins.includes(event.origin) && 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// 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// 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 = window.location.hostname.indexOf('e2e') === -1; // Simple heuristic for environment\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 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 // 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","origin","data","type","bookingId","airlineRef","pushState","state","remove","isBookingConfirmation","isCheckoutPath","startsWith","substring","hostname","indexOf","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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AOC,SAAS8B,SAASC,QAAQ,wCCtEW,EACnEC,aACAC,SACAC,aACAC,cACA9C,UAAS,MAET,MAAO+C,EAAWC,GAAgBC,EAAAA,UAAS,GACrCC,ECnBuB,EAACN,EAAgB5C,GAAkB,KAChE,MAAMQ,EAAUR,EAAS,uBAAyB,2BAclD,OAZemD,EAAMC,OAAO,CACxBC,QAAS7C,EACT8C,QAAS,CACLC,OAAQ,mBACR,eAAgB,mBAChB,YAAaX,GAGjBY,iBAAiB,EACjBC,QAAS,KAGA,EDIEC,CAAkBd,EAAQ5C,GAsBnC2D,EAAgB,sRAShBZ,EAAY,oBAAsB,6BACtCa,OAEIC,EAAe,mHAMnBD,OAEF,OACIE,OACI,SAAA,CAAAC,QA1CYC,UAChB,MAAMC,EAA8B,CAChCpB,aACAqB,SAAUpB,GAERqB,OCFiBH,OAAOC,EAA6Bf,UAClDA,EAAOkB,KAAK,oBAAqBH,GACzCI,MAAMC,GAAQA,EAAIxC,KAAKzB,KACvBkE,OAAOC,GAEG,ODHWC,CAAgBR,EAASf,GAC/C,IAAKiB,EAED,OAGJ,MAAMpE,EAAc,IAAIiB,gBAAgB,CACpCmD,UACAlC,WAAYU,IACb+B,WAEHhE,OAAOS,QAAQe,UAAU,CAAEb,cAAc,GAAQ,GAAI,mBAAmBtB,KACxED,EAAiBC,EAAaC,EAAO,EA0BjC2E,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://booking.movmo.io\" : \"https://booking.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({ 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 https://booking.movmo.io is allowed\n * - Development: Allows booking.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://booking.movmo.io'];\n\n // Development specific domains\n const devSpecificDomains = [\n 'https://booking.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 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 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 // 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,2BAA6B,+BAGtD,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,4BAGrBC,EAAqB,CACvB,+BACA,yBAGJ,OAAIhC,EAEO+B,EAAkBlB,SAASiB,GAG3BE,EAAmBnB,SAASiB,EAE3C,CAtCgCG,CAAmBL,EAAME,OAAQ9B,GAEzD,GAAI6B,GAAwC,2BAArBD,EAAMM,MAAMC,KAAmC,CAClE,MAAMC,UAAEA,EAASC,WAAEA,GAAeT,EAAMM,KACpCE,GAEA1B,OAAOS,QAAQmB,UACX,CAAEjB,cAAc,EAAMC,iBAAiB,EAAMc,aAC7C,GACA,2BAA2BA,gBAAwBC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,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"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @movmo/express-checkout-button v0.1.10
2
+ * @movmo/express-checkout-button v0.1.11
3
3
  * React component plugin for embedding Movmo Express Checkout on airline websites.
4
4
  * (c) 2025 Movmo
5
5
  * @license MIT
package/dist/index.es.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @movmo/express-checkout-button v0.1.10
2
+ * @movmo/express-checkout-button v0.1.11
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 e}from"react";import t from"axios";function i(o,n=!1){if(document.getElementById("movmo-checkout"))return;const e=document.createElement("div");e.id="movmo-checkout",e.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=n?"https://booking.movmo.io":"https://booking.e2e.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)}e.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(e),window.addEventListener("message",(o=>{if(["https://booking.movmo.io","https://booking.e2e.movmo.io"].includes(o.origin)&&"MOVMO_BOOKING_COMPLETE"===o.data?.type){const{bookingId:n,airlineRef:e}=o.data;n&&window.history.pushState({checkoutOpen:!0,bookingComplete:!0,bookingId:n},"",`/movmo/checkout/booking/${n}?airlineRef=${e||""}`)}}))}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),-1===window.location.hostname.indexOf("e2e"))}}));const a=({customerId:a,apiKey:r,dataSource:c,flightOffer:s,isProd:d=!1})=>{const[m,h]=e(!1),p=((o,n=!1)=>{const e=n?"https://api.movmo.io":"https://e2e.api.movmo.io";return t.create({baseURL:e,headers:{Accept:"application/json","Content-Type":"application/json","x-api-key":o},withCredentials:!0,timeout:3e4})})(r,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:c,rawOffer:s},n=await(async(o,n)=>await n.post("/v1/flight_offers",o).then((o=>o.data.id)).catch((o=>null)))(o,p);if(!n)return;const e=new URLSearchParams({offerId:n,airlineRef:a}).toString();window.history.pushState({checkoutOpen:!0},"",`/movmo/checkout?${e}`),i(e,d)},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),className:l,children:["Express Checkout",n("span",{className:u,children:"Movmo"})]})};export{a as MovmoCheckoutButton};
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.movmo.io":"https://booking.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)}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.movmo.io"],e=["https://booking.e2e.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,h]=t(!1),l=((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),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 ${m?"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("button",{onClick:async()=>{const o={dataSource:r,rawOffer:s},n=await(async(o,n)=>await n.post("/v1/flight_offers",o).then((o=>o.data.id)).catch((o=>null)))(o,l);if(!n)return;const t=new URLSearchParams({offerId:n,airlineRef:a}).toString();window.history.pushState({checkoutOpen:!0},"",`/movmo/checkout?${t}`),i(t,d)},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),className:u,children:["Express Checkout",n("span",{className:p,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.movmo.io\" : \"https://booking.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({ 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 // Verify origin for security\n const allowedOrigins = [\n 'https://booking.movmo.io',\n 'https://booking.e2e.movmo.io'\n ];\n\n if (allowedOrigins.includes(event.origin) && 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// 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// 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 = window.location.hostname.indexOf('e2e') === -1; // Simple heuristic for environment\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 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 // 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","origin","data","type","bookingId","airlineRef","pushState","state","remove","isBookingConfirmation","isCheckoutPath","startsWith","substring","hostname","indexOf","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,2BAA6B,+BAGtD,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,IAOhC,GALuB,CACnB,2BACA,gCAGef,SAASe,EAAMC,SAAgC,2BAArBD,EAAME,MAAMC,KAAmC,CACxF,MAAMC,UAAEA,EAASC,WAAEA,GAAeL,EAAME,KACpCE,GAEAtB,OAAOS,QAAQe,UACX,CAAEb,cAAc,EAAMC,iBAAiB,EAAMU,aAC7C,GACA,2BAA2BA,gBAAwBC,GAAc,SAKrF,CAGAvB,OAAOiB,iBAAiB,YAAY,KAChC,MAAMxB,EAAYF,SAASC,eAAe,mBACrCQ,OAAOS,QAAQg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EViB,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://booking.movmo.io\" : \"https://booking.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({ 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 https://booking.movmo.io is allowed\n * - Development: Allows booking.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://booking.movmo.io'];\n\n // Development specific domains\n const devSpecificDomains = [\n 'https://booking.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 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 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 // 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,2BAA6B,+BAGtD,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,4BAGrBC,EAAqB,CACvB,+BACA,yBAGJ,OAAIhC,EAEO+B,E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AUpB,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movmo/express-checkout-button",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "React component plugin for embedding Movmo Express Checkout on airline websites.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",