@movmo/express-checkout-button 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +2 -2
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @movmo/express-checkout-button v1.
|
|
2
|
+
* @movmo/express-checkout-button v1.3.0
|
|
3
3
|
* React component plugin for embedding Movmo Express Checkout on airline websites.
|
|
4
4
|
* (c) 2026 Movmo
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
7
|
-
"use strict";var o=require("react/jsx-runtime"),e=require("react"),t=require("axios");const n=(o,e,n=!1)=>{const i
|
|
7
|
+
"use strict";var o=require("react/jsx-runtime"),e=require("react"),t=require("axios");const n=(o,e,n=!1)=>{const i=n?"https://flights.movmo.io":"https://flights.e2e.movmo.io",r=process.env.REACT_APP_MOVMO_CHECKOUT_API_URL||`${i}/v1/proxy`,s=t.create({baseURL:r,headers:{Accept:"application/json","Content-Type":"application/json","x-api-key":o,"X-Forwarded-Host":"undefined"!=typeof window?window.location.host:"","movmo-customer-id":e,..."undefined"==typeof window||"localhost"!==window.location.hostname&&"127.0.0.1"!==window.location.hostname||!process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER?{}:{"X-Movmo-Proxy-Auth":process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER}},withCredentials:!0,timeout:3e4});return s.interceptors.request.use((o=>{o.headers?.Authorization&&delete o.headers.Authorization;const e=(o=>{const e=document.cookie.split(";");for(let t=0;t<e.length;t++){const n=e[t].trim();if(n.startsWith(o+"="))return decodeURIComponent(n.substring(o.length+1))}return null})("movmo_csrf_token");return e&&(o.headers["X-CSRF-Token"]=e),o})),s};function i(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=process.env.REACT_APP_MOVMO_CHECKOUT_URL||(e?"https://flights.movmo.io":"https://flights.e2e.movmo.io");let i=`${n}/index.html#/booking?${o}`;if(window.location.pathname.includes("/movmo/checkout/booking/")){const o=window.location.pathname.split("/").pop(),e=new URLSearchParams(window.location.search);i=`${n}/index.html#/booking/${o}?airlineRef=${e.get("airlineRef")||""}&providerId=${e.get("providerId")||""}`,window.history.replaceState({checkoutOpen:!0,bookingComplete:!0},"",window.location.href)}const r=document.createElement("iframe");r.src=i,r.width="100%",r.height="100%",r.style.border="none",r.id="movmo-checkout-iframe",t.appendChild(r),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"],i=process.env.REACT_APP_MOVMO_CHECKOUT_URL;if(i)try{n.push(new URL(i).origin)}catch{}return e?t.includes(o):n.includes(o)}(o.origin,e);if(t&&"MOVMO_BOOKING_COMPLETE"===o.data?.type){const{bookingId:e,airlineRef:t,providerId:n}=o.data;e&&window.history.pushState({checkoutOpen:!0,bookingComplete:!0,bookingId:e,providerId:n},"",`/movmo/checkout/booking/${e}?airlineRef=${t||""}&providerId=${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){i(window.location.search.substring(1),function(){const o=window.location.hostname;return!o.includes("e2e")&&!o.includes("localhost")}())}}));exports.MovmoCheckoutButton=({iataCode:t,apiKey:r,providerID:s,flightOffer:c,flightOfferID:d,isProd:a=!1,className:h})=>{const[l,m]=e.useState(!1),u=n(r,t,a),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 ${l?"bg-gradient-hover":"bg-gradient-normal"}\n ${h??""}\n `.trim(),w="\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()=>{let o=d;if(!o&&c){const e=await(async(o,e,t)=>await t.post(`/v1/flights/providers/${o}/offers`,e).then((o=>o.data.offer_id)).catch((o=>null)))(s,c,u);if(!e)return;o=e}if(!o)return;const e=new URLSearchParams({offerId:o,providerId:s,airlineRef:t}).toString();window.history.pushState({checkoutOpen:!0},"",`/movmo/checkout?${e}`),i(e,a)},onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),className:p,children:["Express Checkout",o.jsx("span",{className:w,children:"Movmo"})]})};
|
|
8
8
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/api.ts","../src/MovmoCheckoutOverlay.tsx","../src/MovmoCheckoutButton.tsx"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\n\n// Helper function to read cookie value from document.cookie\nconst getCookie = (name: string): string | null => {\n const cookieString = document.cookie;\n const cookies = cookieString.split(';');\n for (let i = 0; i < cookies.length; i++) {\n const cookie = cookies[i].trim();\n if (cookie.startsWith(name + '=')) {\n // URL-decode the cookie value to match what backend expects\n return decodeURIComponent(cookie.substring(name.length + 1));\n }\n }\n return null;\n};\n\nconst isLocalHost = () =>\n typeof window !== 'undefined' &&\n (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1');\n\nexport const createAxiosClient = (apiKey: string, airlineRef: string, isProd: boolean = false) => {\n const baseUrl = isProd ? 'https://flights.movmo.io' : 'https://flights.e2e.movmo.io';\n const proxyBaseUrl = `${baseUrl}/v1/proxy`;\n\n const client = axios.create({\n baseURL: proxyBaseUrl,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey,\n 'X-Forwarded-Host': typeof window !== 'undefined' ? window.location.host : '',\n 'movmo-customer-id': airlineRef,\n ...(isLocalHost() && process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER\n ? { 'X-Movmo-Proxy-Auth': process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER }\n : {}),\n },\n withCredentials: true,\n timeout: 30000,\n });\n\n client.interceptors.request.use((config) => {\n if (config.headers?.Authorization) {\n delete config.headers.Authorization;\n }\n const token = getCookie('movmo_csrf_token');\n if (token) {\n config.headers['X-CSRF-Token'] = token;\n }\n\n return config;\n });\n\n return client;\n};\n\nexport const saveProviderOffer = async (\n providerID: string,\n rawOffer: object,\n client: AxiosInstance,\n): Promise<string | null> => {\n return await client\n .post(`/v1/flights/providers/${providerID}/offers`, rawOffer)\n .then((res) => res.data.offer_id)\n .catch((err) => {\n console.error(err);\n return null;\n });\n};\n","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 // Load index.html explicitly and use hash routing to avoid CloudFront error response issues\n // This ensures we load a file that actually exists in S3, then let React Router handle navigation\n let iframeUrl = `${baseUrl}/index.html#/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 const providerId = urlParams.get('providerId') || '';\n\n // Direct the iframe to the booking confirmation page using hash routing\n iframeUrl = `${baseUrl}/index.html#/booking/${bookingId}?airlineRef=${airlineRef}&providerId=${providerId}`;\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 // Create iframe element imperatively to prevent XSS (APP-XSS-001 fix)\n const iframe = document.createElement('iframe');\n iframe.src = iframeUrl;\n iframe.width = '100%';\n iframe.height = '100%';\n iframe.style.border = 'none';\n iframe.id = 'movmo-checkout-iframe';\n\n container.appendChild(iframe);\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, providerId } = event.data;\n if (bookingId) {\n // Update the parent URL to reflect booking completion\n window.history.pushState(\n { checkoutOpen: true, bookingComplete: true, bookingId, providerId },\n '',\n `/movmo/checkout/booking/${bookingId}?airlineRef=${airlineRef || ''}&providerId=${providerId || ''}`,\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, saveProviderOffer } from './api';\nimport { showMovmoOverlay } from './MovmoCheckoutOverlay';\n\ninterface MovmoCheckoutButtonProps {\n iataCode: string;\n apiKey: string;\n providerID: string;\n // TODO: support fare splitting\n flightOffer?: object;\n flightOfferID?: string;\n isProd?: boolean;\n className?: string;\n}\n\nexport const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps> = ({\n iataCode,\n apiKey,\n providerID,\n flightOffer,\n flightOfferID,\n isProd = false,\n className,\n}) => {\n const [isHovered, setIsHovered] = useState(false);\n const client = createAxiosClient(apiKey, iataCode, isProd);\n\n const handleClick = async () => {\n let offerId = flightOfferID;\n\n // If no pre-saved offer ID, save the raw offer\n if (!offerId && flightOffer) {\n const savedOfferId = await saveProviderOffer(providerID, flightOffer, client);\n if (!savedOfferId) {\n // TODO: handle error by displaying a message to the user\n return;\n }\n offerId = savedOfferId;\n }\n\n if (!offerId) {\n // TODO: handle error - neither flightOfferID nor flightOffer provided\n console.error('Neither flightOfferID nor flightOffer provided');\n return;\n }\n\n const queryParams = new URLSearchParams({\n offerId,\n providerId: providerID,\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 ${className ?? ''}\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}>Movmo</span>\n </button>\n );\n};\n"],"names":["createAxiosClient","apiKey","airlineRef","isProd","proxyBaseUrl","client","axios","create","baseURL","headers","Accept","window","location","host","hostname","process","env","REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER","withCredentials","timeout","interceptors","request","use","config","Authorization","token","name","cookies","document","cookie","split","i","length","trim","startsWith","decodeURIComponent","substring","getCookie","showMovmoOverlay","queryParams","getElementById","container","createElement","id","style","cssText","baseUrl","iframeUrl","pathname","includes","bookingId","pop","urlParams","URLSearchParams","search","get","history","replaceState","checkoutOpen","bookingComplete","href","iframe","src","width","height","border","appendChild","body","addEventListener","event","isAllowedOrigin","origin","productionOrigins","devSpecificDomains","checkAllowedOrigin","data","type","providerId","pushState","state","remove","isBookingConfirmation","isCheckoutPath","isProductionEnvironment","iataCode","providerID","flightOffer","flightOfferID","className","isHovered","setIsHovered","useState","buttonClasses","badgeClasses","_jsxs","onClick","async","offerId","savedOfferId","rawOffer","post","then","res","offer_id","catch","err","saveProviderOffer","toString","onMouseEnter","onMouseLeave","children","_jsx"],"mappings":";;;;;;sFAGA,MAiBaA,EAAoB,CAACC,EAAgBC,EAAoBC,GAAkB,KACtF,MACMC,EAAe,GADLD,EAAS,2BAA6B,0CAGhDE,EAASC,EAAMC,OAAO,CAC1BC,QAASJ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AS,YACzD,CAUqBkC,GAEjB,iCC5GmE,EACrEC,WACAnF,SACAoF,aACAC,cACAC,gBACApF,UAAS,EACTqF,gBAEA,MAAOC,EAAWC,GAAgBC,EAAAA,UAAS,GACrCtF,EAASL,EAAkBC,EAAQmF,EAAUjF,GA+B7CyF,EAAgB,sRASdH,EAAY,oBAAsB,iCAClCD,GAAa,WACjBvD,OAEE4D,EAAe,mHAMjB5D,OAEJ,OACE6D,OAAA,SAAA,CACEC,QApDgBC,UAClB,IAAIC,EAAUV,EAGd,IAAKU,GAAWX,EAAa,CAC3B,MAAMY,OFsBqBF,OAC/BX,EACAc,EACA9F,UAEaA,EACV+F,KAAK,yBAAyBf,WAAqBc,GACnDE,MAAMC,GAAQA,EAAI3B,KAAK4B,WACvBC,OAAOC,GAEC,OEhCoBC,CAAkBrB,EAAYC,EAAajF,GACtE,IAAK6F,EAEH,OAEFD,EAAUC,CACZ,CAEA,IAAKD,EAGH,OAGF,MAAM1D,EAAc,IAAIc,gBAAgB,CACtC4C,UACApB,WAAYQ,EACZnF,WAAYkF,IACXuB,WAEHhG,OAAO6C,QAAQsB,UAAU,CAAEpB,cAAc,GAAQ,GAAI,mBAAmBnB,KACxED,EAAiBC,EAAapC,EAAO,EA2BnCyG,aAAc,IAAMlB,GAAa,GACjCmB,aAAc,IAAMnB,GAAa,GACjCF,UAAWI,EAAakB,SAAA,CAAA,mBAGxBC,EAAAA,YAAMvB,UAAWK,EAAYiB,SAAA,YACtB"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/api.ts","../src/MovmoCheckoutOverlay.tsx","../src/MovmoCheckoutButton.tsx"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\n\n// Helper function to read cookie value from document.cookie\nconst getCookie = (name: string): string | null => {\n const cookieString = document.cookie;\n const cookies = cookieString.split(';');\n for (let i = 0; i < cookies.length; i++) {\n const cookie = cookies[i].trim();\n if (cookie.startsWith(name + '=')) {\n // URL-decode the cookie value to match what backend expects\n return decodeURIComponent(cookie.substring(name.length + 1));\n }\n }\n return null;\n};\n\nconst isLocalHost = () =>\n typeof window !== 'undefined' &&\n (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1');\n\nexport const createAxiosClient = (apiKey: string, airlineRef: string, isProd: boolean = false) => {\n const baseUrl = isProd ? 'https://flights.movmo.io' : 'https://flights.e2e.movmo.io';\n // REACT_APP_MOVMO_CHECKOUT_API_URL overrides the API base (e.g. the offline demo\n // talks directly to the local monolith-api at http://localhost:8080, bypassing the\n // CloudFront /v1/proxy hop). Defaults are unchanged when the env var is unset.\n const proxyBaseUrl =\n process.env.REACT_APP_MOVMO_CHECKOUT_API_URL || `${baseUrl}/v1/proxy`;\n\n const client = axios.create({\n baseURL: proxyBaseUrl,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey,\n 'X-Forwarded-Host': typeof window !== 'undefined' ? window.location.host : '',\n 'movmo-customer-id': airlineRef,\n ...(isLocalHost() && process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER\n ? { 'X-Movmo-Proxy-Auth': process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER }\n : {}),\n },\n withCredentials: true,\n timeout: 30000,\n });\n\n client.interceptors.request.use((config) => {\n if (config.headers?.Authorization) {\n delete config.headers.Authorization;\n }\n const token = getCookie('movmo_csrf_token');\n if (token) {\n config.headers['X-CSRF-Token'] = token;\n }\n\n return config;\n });\n\n return client;\n};\n\nexport const saveProviderOffer = async (\n providerID: string,\n rawOffer: object,\n client: AxiosInstance,\n): Promise<string | null> => {\n return await client\n .post(`/v1/flights/providers/${providerID}/offers`, rawOffer)\n .then((res) => res.data.offer_id)\n .catch((err) => {\n console.error(err);\n return null;\n });\n};\n","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. REACT_APP_MOVMO_CHECKOUT_URL\n // overrides both (e.g. the offline demo points the overlay at http://localhost:3000);\n // defaults are unchanged when the env var is unset.\n const baseUrl =\n process.env.REACT_APP_MOVMO_CHECKOUT_URL ||\n (isProd ? 'https://flights.movmo.io' : 'https://flights.e2e.movmo.io');\n\n // Load index.html explicitly and use hash routing to avoid CloudFront error response issues\n // This ensures we load a file that actually exists in S3, then let React Router handle navigation\n let iframeUrl = `${baseUrl}/index.html#/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 const providerId = urlParams.get('providerId') || '';\n\n // Direct the iframe to the booking confirmation page using hash routing\n iframeUrl = `${baseUrl}/index.html#/booking/${bookingId}?airlineRef=${airlineRef}&providerId=${providerId}`;\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 // Create iframe element imperatively to prevent XSS (APP-XSS-001 fix)\n const iframe = document.createElement('iframe');\n iframe.src = iframeUrl;\n iframe.width = '100%';\n iframe.height = '100%';\n iframe.style.border = 'none';\n iframe.id = 'movmo-checkout-iframe';\n\n container.appendChild(iframe);\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, providerId } = event.data;\n if (bookingId) {\n // Update the parent URL to reflect booking completion\n window.history.pushState(\n { checkoutOpen: true, bookingComplete: true, bookingId, providerId },\n '',\n `/movmo/checkout/booking/${bookingId}?airlineRef=${airlineRef || ''}&providerId=${providerId || ''}`,\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 // Trust an explicitly configured overlay origin (e.g. the offline demo) so its\n // MOVMO_BOOKING_COMPLETE postMessage is accepted. This only widens the dev/non-prod\n // allowlist — env-injected origins are intentionally never trusted when isProd is\n // true, so a prod build keeps its hardcoded productionOrigins allowlist. (The offline\n // demo always runs with isProd=false, so the override applies as intended there.)\n const configuredCheckoutUrl = process.env.REACT_APP_MOVMO_CHECKOUT_URL;\n if (configuredCheckoutUrl) {\n try {\n devSpecificDomains.push(new URL(configuredCheckoutUrl).origin);\n } catch {\n // ignore a malformed override\n }\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, saveProviderOffer } from './api';\nimport { showMovmoOverlay } from './MovmoCheckoutOverlay';\n\ninterface MovmoCheckoutButtonProps {\n iataCode: string;\n apiKey: string;\n providerID: string;\n // TODO: support fare splitting\n flightOffer?: object;\n flightOfferID?: string;\n isProd?: boolean;\n className?: string;\n}\n\nexport const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps> = ({\n iataCode,\n apiKey,\n providerID,\n flightOffer,\n flightOfferID,\n isProd = false,\n className,\n}) => {\n const [isHovered, setIsHovered] = useState(false);\n const client = createAxiosClient(apiKey, iataCode, isProd);\n\n const handleClick = async () => {\n let offerId = flightOfferID;\n\n // If no pre-saved offer ID, save the raw offer\n if (!offerId && flightOffer) {\n const savedOfferId = await saveProviderOffer(providerID, flightOffer, client);\n if (!savedOfferId) {\n // TODO: handle error by displaying a message to the user\n return;\n }\n offerId = savedOfferId;\n }\n\n if (!offerId) {\n // TODO: handle error - neither flightOfferID nor flightOffer provided\n console.error('Neither flightOfferID nor flightOffer provided');\n return;\n }\n\n const queryParams = new URLSearchParams({\n offerId,\n providerId: providerID,\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 ${className ?? ''}\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}>Movmo</span>\n </button>\n );\n};\n"],"names":["createAxiosClient","apiKey","airlineRef","isProd","baseUrl","proxyBaseUrl","process","env","REACT_APP_MOVMO_CHECKOUT_API_URL","client","axios","create","baseURL","headers","Accept","window","location","host","hostname","REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER","withCredentials","timeout","interceptors","request","use","config","Authorization","token","name","cookies","document","cookie","split","i","length","trim","startsWith","decodeURIComponent","substring","getCookie","showMovmoOverlay","queryParams","getElementById","container","createElement","id","style","cssText","REACT_APP_MOVMO_CHECKOUT_URL","iframeUrl","pathname","includes","bookingId","pop","urlParams","URLSearchParams","search","get","history","replaceState","checkoutOpen","bookingComplete","href","iframe","src","width","height","border","appendChild","body","addEventListener","event","isAllowedOrigin","origin","productionOrigins","devSpecificDomains","configuredCheckoutUrl","push","URL","checkAllowedOrigin","data","type","providerId","pushState","state","remove","isBookingConfirmation","isCheckoutPath","isProductionEnvironment","iataCode","providerID","flightOffer","flightOfferID","className","isHovered","setIsHovered","useState","buttonClasses","badgeClasses","_jsxs","onClick","async","offerId","savedOfferId","rawOffer","post","then","res","offer_id","catch","err","saveProviderOffer","toString","onMouseEnter","onMouseLeave","children","_jsx"],"mappings":";;;;;;sFAGA,MAiBaA,EAAoB,CAACC,EAAgBC,EAAoBC,GAAkB,KACtF,MAAMC,EAAUD,EAAS,2BAA6B,+BAIhDE,EACJC,QAAQC,IAAIC,kCAAoC,GAAGJ,aAE/CK,EAASC,EAAMC,OAAO,CAC1BC,QAASP,EACTQ,QAAS,CACPC,OAAQ,mBACR,eAAgB,mBAChB,YAAab,EACb,mBAAsC,oBAAXc,OAAyBA,OAAOC,SAASC,KAAO,GAC3E,oBAAqBf,KAlBP,oBAAXa,QACuB,cAA7BA,OAAOC,SAASE,UAAyD,cAA7BH,OAAOC,SAASE,WAkBpCZ,QAAQC,IAAIY,0CAE7B,GADA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UAAS,EACT0F,gBAEA,MAAOC,EAAWC,GAAgBC,EAAAA,UAAS,GACrCvF,EAAST,EAAkBC,EAAQwF,EAAUtF,GA+B7C8F,EAAgB,sRASdH,EAAY,oBAAsB,iCAClCD,GAAa,WACjB1D,OAEE+D,EAAe,mHAMjB/D,OAEJ,OACEgE,OAAA,SAAA,CACEC,QApDgBC,UAClB,IAAIC,EAAUV,EAGd,IAAKU,GAAWX,EAAa,CAC3B,MAAMY,OF0BqBF,OAC/BX,EACAc,EACA/F,UAEaA,EACVgG,KAAK,yBAAyBf,WAAqBc,GACnDE,MAAMC,GAAQA,EAAI3B,KAAK4B,WACvBC,OAAOC,GAEC,OEpCoBC,CAAkBrB,EAAYC,EAAalF,GACtE,IAAK8F,EAEH,OAEFD,EAAUC,CACZ,CAEA,IAAKD,EAGH,OAGF,MAAM7D,EAAc,IAAIc,gBAAgB,CACtC+C,UACApB,WAAYQ,EACZxF,WAAYuF,IACXuB,WAEHjG,OAAO2C,QAAQyB,UAAU,CAAEvB,cAAc,GAAQ,GAAI,mBAAmBnB,KACxED,EAAiBC,EAAatC,EAAO,EA2BnC8G,aAAc,IAAMlB,GAAa,GACjCmB,aAAc,IAAMnB,GAAa,GACjCF,UAAWI,EAAakB,SAAA,CAAA,mBAGxBC,EAAAA,YAAMvB,UAAWK,EAAYiB,SAAA,YACtB"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @movmo/express-checkout-button v1.
|
|
2
|
+
* @movmo/express-checkout-button v1.3.0
|
|
3
3
|
* React component plugin for embedding Movmo Express Checkout on airline websites.
|
|
4
4
|
* (c) 2026 Movmo
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
7
|
-
import{jsxs as o,jsx as e}from"react/jsx-runtime";import{useState as t}from"react";import n from"axios";const i=(o,e,t=!1)=>{const i
|
|
7
|
+
import{jsxs as o,jsx as e}from"react/jsx-runtime";import{useState as t}from"react";import n from"axios";const i=(o,e,t=!1)=>{const i=t?"https://flights.movmo.io":"https://flights.e2e.movmo.io",r=process.env.REACT_APP_MOVMO_CHECKOUT_API_URL||`${i}/v1/proxy`,s=n.create({baseURL:r,headers:{Accept:"application/json","Content-Type":"application/json","x-api-key":o,"X-Forwarded-Host":"undefined"!=typeof window?window.location.host:"","movmo-customer-id":e,..."undefined"==typeof window||"localhost"!==window.location.hostname&&"127.0.0.1"!==window.location.hostname||!process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER?{}:{"X-Movmo-Proxy-Auth":process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER}},withCredentials:!0,timeout:3e4});return s.interceptors.request.use((o=>{o.headers?.Authorization&&delete o.headers.Authorization;const e=(o=>{const e=document.cookie.split(";");for(let t=0;t<e.length;t++){const n=e[t].trim();if(n.startsWith(o+"="))return decodeURIComponent(n.substring(o.length+1))}return null})("movmo_csrf_token");return e&&(o.headers["X-CSRF-Token"]=e),o})),s};function r(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=process.env.REACT_APP_MOVMO_CHECKOUT_URL||(e?"https://flights.movmo.io":"https://flights.e2e.movmo.io");let i=`${n}/index.html#/booking?${o}`;if(window.location.pathname.includes("/movmo/checkout/booking/")){const o=window.location.pathname.split("/").pop(),e=new URLSearchParams(window.location.search);i=`${n}/index.html#/booking/${o}?airlineRef=${e.get("airlineRef")||""}&providerId=${e.get("providerId")||""}`,window.history.replaceState({checkoutOpen:!0,bookingComplete:!0},"",window.location.href)}const r=document.createElement("iframe");r.src=i,r.width="100%",r.height="100%",r.style.border="none",r.id="movmo-checkout-iframe",t.appendChild(r),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"],i=process.env.REACT_APP_MOVMO_CHECKOUT_URL;if(i)try{n.push(new URL(i).origin)}catch{}return e?t.includes(o):n.includes(o)}(o.origin,e);if(t&&"MOVMO_BOOKING_COMPLETE"===o.data?.type){const{bookingId:e,airlineRef:t,providerId:n}=o.data;e&&window.history.pushState({checkoutOpen:!0,bookingComplete:!0,bookingId:e,providerId:n},"",`/movmo/checkout/booking/${e}?airlineRef=${t||""}&providerId=${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){r(window.location.search.substring(1),function(){const o=window.location.hostname;return!o.includes("e2e")&&!o.includes("localhost")}())}}));const s=({iataCode:n,apiKey:s,providerID:c,flightOffer:d,flightOfferID:a,isProd:h=!1,className:m})=>{const[l,p]=t(!1),u=i(s,n,h),f=`\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 ${l?"bg-gradient-hover":"bg-gradient-normal"}\n ${m??""}\n `.trim(),w="\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()=>{let o=a;if(!o&&d){const e=await(async(o,e,t)=>await t.post(`/v1/flights/providers/${o}/offers`,e).then((o=>o.data.offer_id)).catch((o=>null)))(c,d,u);if(!e)return;o=e}if(!o)return;const e=new URLSearchParams({offerId:o,providerId:c,airlineRef:n}).toString();window.history.pushState({checkoutOpen:!0},"",`/movmo/checkout?${e}`),r(e,h)},onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),className:f,children:["Express Checkout",e("span",{className:w,children:"Movmo"})]})};export{s as MovmoCheckoutButton};
|
|
8
8
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/api.ts","../src/MovmoCheckoutOverlay.tsx","../src/MovmoCheckoutButton.tsx"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\n\n// Helper function to read cookie value from document.cookie\nconst getCookie = (name: string): string | null => {\n const cookieString = document.cookie;\n const cookies = cookieString.split(';');\n for (let i = 0; i < cookies.length; i++) {\n const cookie = cookies[i].trim();\n if (cookie.startsWith(name + '=')) {\n // URL-decode the cookie value to match what backend expects\n return decodeURIComponent(cookie.substring(name.length + 1));\n }\n }\n return null;\n};\n\nconst isLocalHost = () =>\n typeof window !== 'undefined' &&\n (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1');\n\nexport const createAxiosClient = (apiKey: string, airlineRef: string, isProd: boolean = false) => {\n const baseUrl = isProd ? 'https://flights.movmo.io' : 'https://flights.e2e.movmo.io';\n const proxyBaseUrl = `${baseUrl}/v1/proxy`;\n\n const client = axios.create({\n baseURL: proxyBaseUrl,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey,\n 'X-Forwarded-Host': typeof window !== 'undefined' ? window.location.host : '',\n 'movmo-customer-id': airlineRef,\n ...(isLocalHost() && process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER\n ? { 'X-Movmo-Proxy-Auth': process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER }\n : {}),\n },\n withCredentials: true,\n timeout: 30000,\n });\n\n client.interceptors.request.use((config) => {\n if (config.headers?.Authorization) {\n delete config.headers.Authorization;\n }\n const token = getCookie('movmo_csrf_token');\n if (token) {\n config.headers['X-CSRF-Token'] = token;\n }\n\n return config;\n });\n\n return client;\n};\n\nexport const saveProviderOffer = async (\n providerID: string,\n rawOffer: object,\n client: AxiosInstance,\n): Promise<string | null> => {\n return await client\n .post(`/v1/flights/providers/${providerID}/offers`, rawOffer)\n .then((res) => res.data.offer_id)\n .catch((err) => {\n console.error(err);\n return null;\n });\n};\n","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 // Load index.html explicitly and use hash routing to avoid CloudFront error response issues\n // This ensures we load a file that actually exists in S3, then let React Router handle navigation\n let iframeUrl = `${baseUrl}/index.html#/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 const providerId = urlParams.get('providerId') || '';\n\n // Direct the iframe to the booking confirmation page using hash routing\n iframeUrl = `${baseUrl}/index.html#/booking/${bookingId}?airlineRef=${airlineRef}&providerId=${providerId}`;\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 // Create iframe element imperatively to prevent XSS (APP-XSS-001 fix)\n const iframe = document.createElement('iframe');\n iframe.src = iframeUrl;\n iframe.width = '100%';\n iframe.height = '100%';\n iframe.style.border = 'none';\n iframe.id = 'movmo-checkout-iframe';\n\n container.appendChild(iframe);\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, providerId } = event.data;\n if (bookingId) {\n // Update the parent URL to reflect booking completion\n window.history.pushState(\n { checkoutOpen: true, bookingComplete: true, bookingId, providerId },\n '',\n `/movmo/checkout/booking/${bookingId}?airlineRef=${airlineRef || ''}&providerId=${providerId || ''}`,\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, saveProviderOffer } from './api';\nimport { showMovmoOverlay } from './MovmoCheckoutOverlay';\n\ninterface MovmoCheckoutButtonProps {\n iataCode: string;\n apiKey: string;\n providerID: string;\n // TODO: support fare splitting\n flightOffer?: object;\n flightOfferID?: string;\n isProd?: boolean;\n className?: string;\n}\n\nexport const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps> = ({\n iataCode,\n apiKey,\n providerID,\n flightOffer,\n flightOfferID,\n isProd = false,\n className,\n}) => {\n const [isHovered, setIsHovered] = useState(false);\n const client = createAxiosClient(apiKey, iataCode, isProd);\n\n const handleClick = async () => {\n let offerId = flightOfferID;\n\n // If no pre-saved offer ID, save the raw offer\n if (!offerId && flightOffer) {\n const savedOfferId = await saveProviderOffer(providerID, flightOffer, client);\n if (!savedOfferId) {\n // TODO: handle error by displaying a message to the user\n return;\n }\n offerId = savedOfferId;\n }\n\n if (!offerId) {\n // TODO: handle error - neither flightOfferID nor flightOffer provided\n console.error('Neither flightOfferID nor flightOffer provided');\n return;\n }\n\n const queryParams = new URLSearchParams({\n offerId,\n providerId: providerID,\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 ${className ?? ''}\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}>Movmo</span>\n </button>\n );\n};\n"],"names":["createAxiosClient","apiKey","airlineRef","isProd","proxyBaseUrl","client","axios","create","baseURL","headers","Accept","window","location","host","hostname","process","env","REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER","withCredentials","timeout","interceptors","request","use","config","Authorization","token","name","cookies","document","cookie","split","i","length","trim","startsWith","decodeURIComponent","substring","getCookie","showMovmoOverlay","queryParams","getElementById","container","createElement","id","style","cssText","baseUrl","iframeUrl","pathname","includes","bookingId","pop","urlParams","URLSearchParams","search","get","history","replaceState","checkoutOpen","bookingComplete","href","iframe","src","width","height","border","appendChild","body","addEventListener","event","isAllowedOrigin","origin","productionOrigins","devSpecificDomains","checkAllowedOrigin","data","type","providerId","pushState","state","remove","isBookingConfirmation","isCheckoutPath","isProductionEnvironment","MovmoCheckoutButton","iataCode","providerID","flightOffer","flightOfferID","className","isHovered","setIsHovered","useState","buttonClasses","badgeClasses","_jsxs","onClick","async","offerId","savedOfferId","rawOffer","post","then","res","offer_id","catch","err","saveProviderOffer","toString","onMouseEnter","onMouseLeave","children","_jsx"],"mappings":";;;;;;wGAGA,MAiBaA,EAAoB,CAACC,EAAgBC,EAAoBC,GAAkB,KACtF,MACMC,EAAe,GADLD,EAAS,2BAA6B,0CAGhDE,EAASC,EAAMC,OAAO,CAC1BC,QAASJ,EACTK,QAAS,CACPC,OAAQ,mBACR,eAAgB,mBAChB,YAAaT,EACb,mBAAsC,oBAAXU,OAAyBA,OAAOC,SAASC,KAAO,GAC3E,oBAAqBX,KAdP,oBAAXS,QACuB,cAA7BA,OAAOC,SAASE,UAAyD,cAA7BH,OAAOC,SAASE,WAcpCC,QAAQC,IAAIC,0CAE7B,GADA,CAAE,qBAAsBF,QAAQC,IAAIC,4CAG1CC,iBAAiB,EACjBC,QAAS,MAeX,OAZAd,EAAOe,aAAaC,QAAQC,KAAKC,IAC3BA,EAAOd,SAASe,sBACXD,EAAOd,QAAQe,cAExB,MAAMC,EAzCQ,CAACC,IACjB,MACMC,EADeC,SAASC,OACDC,MAAM,KACnC,IAAK,IAAIC,EAAI,EAAGA,EAAIJ,EAAQK,OAAQD,IAAK,CACvC,MAAMF,EAASF,EAAQI,GAAGE,OAC1B,GAAIJ,EAAOK,WAAWR,EAAO,KAE3B,OAAOS,mBAAmBN,E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3D,EAAc,IAAIc,gBAAgB,CACtC6C,UACArB,WAAYS,EACZpF,WAAYmF,IACXuB,WAEHjG,OAAO6C,QAAQsB,UAAU,CAAEpB,cAAc,GAAQ,GAAI,mBAAmBnB,KACxED,EAAiBC,EAAapC,EAAO,EA2BnC0G,aAAc,IAAMlB,GAAa,GACjCmB,aAAc,IAAMnB,GAAa,GACjCF,UAAWI,EAAakB,SAAA,CAAA,mBAGxBC,UAAMvB,UAAWK,EAAYiB,SAAA,YACtB"}
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/api.ts","../src/MovmoCheckoutOverlay.tsx","../src/MovmoCheckoutButton.tsx"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\n\n// Helper function to read cookie value from document.cookie\nconst getCookie = (name: string): string | null => {\n const cookieString = document.cookie;\n const cookies = cookieString.split(';');\n for (let i = 0; i < cookies.length; i++) {\n const cookie = cookies[i].trim();\n if (cookie.startsWith(name + '=')) {\n // URL-decode the cookie value to match what backend expects\n return decodeURIComponent(cookie.substring(name.length + 1));\n }\n }\n return null;\n};\n\nconst isLocalHost = () =>\n typeof window !== 'undefined' &&\n (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1');\n\nexport const createAxiosClient = (apiKey: string, airlineRef: string, isProd: boolean = false) => {\n const baseUrl = isProd ? 'https://flights.movmo.io' : 'https://flights.e2e.movmo.io';\n // REACT_APP_MOVMO_CHECKOUT_API_URL overrides the API base (e.g. the offline demo\n // talks directly to the local monolith-api at http://localhost:8080, bypassing the\n // CloudFront /v1/proxy hop). Defaults are unchanged when the env var is unset.\n const proxyBaseUrl =\n process.env.REACT_APP_MOVMO_CHECKOUT_API_URL || `${baseUrl}/v1/proxy`;\n\n const client = axios.create({\n baseURL: proxyBaseUrl,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey,\n 'X-Forwarded-Host': typeof window !== 'undefined' ? window.location.host : '',\n 'movmo-customer-id': airlineRef,\n ...(isLocalHost() && process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER\n ? { 'X-Movmo-Proxy-Auth': process.env.REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER }\n : {}),\n },\n withCredentials: true,\n timeout: 30000,\n });\n\n client.interceptors.request.use((config) => {\n if (config.headers?.Authorization) {\n delete config.headers.Authorization;\n }\n const token = getCookie('movmo_csrf_token');\n if (token) {\n config.headers['X-CSRF-Token'] = token;\n }\n\n return config;\n });\n\n return client;\n};\n\nexport const saveProviderOffer = async (\n providerID: string,\n rawOffer: object,\n client: AxiosInstance,\n): Promise<string | null> => {\n return await client\n .post(`/v1/flights/providers/${providerID}/offers`, rawOffer)\n .then((res) => res.data.offer_id)\n .catch((err) => {\n console.error(err);\n return null;\n });\n};\n","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. REACT_APP_MOVMO_CHECKOUT_URL\n // overrides both (e.g. the offline demo points the overlay at http://localhost:3000);\n // defaults are unchanged when the env var is unset.\n const baseUrl =\n process.env.REACT_APP_MOVMO_CHECKOUT_URL ||\n (isProd ? 'https://flights.movmo.io' : 'https://flights.e2e.movmo.io');\n\n // Load index.html explicitly and use hash routing to avoid CloudFront error response issues\n // This ensures we load a file that actually exists in S3, then let React Router handle navigation\n let iframeUrl = `${baseUrl}/index.html#/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 const providerId = urlParams.get('providerId') || '';\n\n // Direct the iframe to the booking confirmation page using hash routing\n iframeUrl = `${baseUrl}/index.html#/booking/${bookingId}?airlineRef=${airlineRef}&providerId=${providerId}`;\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 // Create iframe element imperatively to prevent XSS (APP-XSS-001 fix)\n const iframe = document.createElement('iframe');\n iframe.src = iframeUrl;\n iframe.width = '100%';\n iframe.height = '100%';\n iframe.style.border = 'none';\n iframe.id = 'movmo-checkout-iframe';\n\n container.appendChild(iframe);\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, providerId } = event.data;\n if (bookingId) {\n // Update the parent URL to reflect booking completion\n window.history.pushState(\n { checkoutOpen: true, bookingComplete: true, bookingId, providerId },\n '',\n `/movmo/checkout/booking/${bookingId}?airlineRef=${airlineRef || ''}&providerId=${providerId || ''}`,\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 // Trust an explicitly configured overlay origin (e.g. the offline demo) so its\n // MOVMO_BOOKING_COMPLETE postMessage is accepted. This only widens the dev/non-prod\n // allowlist — env-injected origins are intentionally never trusted when isProd is\n // true, so a prod build keeps its hardcoded productionOrigins allowlist. (The offline\n // demo always runs with isProd=false, so the override applies as intended there.)\n const configuredCheckoutUrl = process.env.REACT_APP_MOVMO_CHECKOUT_URL;\n if (configuredCheckoutUrl) {\n try {\n devSpecificDomains.push(new URL(configuredCheckoutUrl).origin);\n } catch {\n // ignore a malformed override\n }\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, saveProviderOffer } from './api';\nimport { showMovmoOverlay } from './MovmoCheckoutOverlay';\n\ninterface MovmoCheckoutButtonProps {\n iataCode: string;\n apiKey: string;\n providerID: string;\n // TODO: support fare splitting\n flightOffer?: object;\n flightOfferID?: string;\n isProd?: boolean;\n className?: string;\n}\n\nexport const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps> = ({\n iataCode,\n apiKey,\n providerID,\n flightOffer,\n flightOfferID,\n isProd = false,\n className,\n}) => {\n const [isHovered, setIsHovered] = useState(false);\n const client = createAxiosClient(apiKey, iataCode, isProd);\n\n const handleClick = async () => {\n let offerId = flightOfferID;\n\n // If no pre-saved offer ID, save the raw offer\n if (!offerId && flightOffer) {\n const savedOfferId = await saveProviderOffer(providerID, flightOffer, client);\n if (!savedOfferId) {\n // TODO: handle error by displaying a message to the user\n return;\n }\n offerId = savedOfferId;\n }\n\n if (!offerId) {\n // TODO: handle error - neither flightOfferID nor flightOffer provided\n console.error('Neither flightOfferID nor flightOffer provided');\n return;\n }\n\n const queryParams = new URLSearchParams({\n offerId,\n providerId: providerID,\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 ${className ?? ''}\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}>Movmo</span>\n </button>\n );\n};\n"],"names":["createAxiosClient","apiKey","airlineRef","isProd","baseUrl","proxyBaseUrl","process","env","REACT_APP_MOVMO_CHECKOUT_API_URL","client","axios","create","baseURL","headers","Accept","window","location","host","hostname","REACT_APP_CLOUD_FRONT_PROXY_SECRET_HEADER","withCredentials","timeout","interceptors","request","use","config","Authorization","token","name","cookies","document","cookie","split","i","length","trim","startsWith","decodeURIComponent","substring","getCookie","showMovmoOverlay","queryParams","getElementById","container","createElement","id","style","cssText","REACT_APP_MOVMO_CHECKOUT_URL","iframeUrl","pathname","includes","bookingId","pop","urlParams","URLSearchParams","search","get","history","replaceState","checkoutOpen","bookingComplete","href","iframe","src","width","height","border","appendChild","body","addEventListener","event","isAllowedOrigin","origin","productionOrigins","devSpecificDomains","configuredCheckoutUrl","push","URL","checkAllowedOrigin","data","type","providerId","pushState","state","remove","isBookingConfirmation","isCheckoutPath","isProductionEnvironment","MovmoCheckoutButton","iataCode","providerID","flightOffer","flightOfferID","className","isHovered","setIsHovered","useState","buttonClasses","badgeClasses","_jsxs","onClick","async","offerId","savedOfferId","rawOffer","post","then","res","offer_id","catch","err","saveProviderOffer","toString","onMouseEnter","onMouseLeave","children","_jsx"],"mappings":";;;;;;wGAGA,MAiBaA,EAAoB,CAACC,EAAgBC,EAAoBC,GAAkB,KACtF,MAAMC,EAAUD,EAAS,2BAA6B,+BAIhDE,EACJC,QAAQC,IAAIC,kCAAoC,GAAGJ,aAE/CK,EAASC,EAAMC,OAAO,CAC1BC,QAASP,EACTQ,QAAS,CACPC,OAAQ,mBACR,eAAgB,mBAChB,YAAab,EACb,mBAAsC,oBAAXc,OAAyBA,OAAOC,SAASC,KAAO,GAC3E,oBAAqBf,KAlBP,oBAAXa,QACuB,cAA7BA,OAAOC,SAASE,UAAyD,cAA7BH,OAAOC,SAASE,WAkBpCZ,QAAQC,IAAIY,0CAE7B,GADA,CAAE,qBAAsBb,QAAQC,IAAIY,4CAG1CC,iBAAiB,EACjBC,QAAS,MAeX,OAZAZ,EAAOa,aAAaC,QAAQC,KAAKC,IAC3BA,EAAOZ,SAASa,sBACXD,EAAOZ,QAAQa,cAExB,MAAMC,EA7CQ,CAACC,IACjB,MACMC,EADeC,SAASC,OACDC,MAAM,KACnC,IAAK,IAAIC,EAAI,EAAGA,EAAIJ,EAAQK,OAAQD,IAAK,CACvC,MAAMF,EAASF,EAAQI,GAAGE,OAC1B,GAAIJ,EAAOK,WAAWR,EAAO,KAE3B,OAAOS,mBAAmBN,EAAOO,UAAUV,EAAKM,OAAS,GAE7D,CACA,OAAO,IAAI,EAmCKK,CAAU,oBAKxB,OAJIZ,IACFF,EAAOZ,QAAQ,gBAAkBc,GAG5BF,CAAM,IAGRhB,CAAM,WCxDC+B,EAAiBC,EAAqBtC,GAAkB,GACtE,GAAI2B,SAASY,eAAe,kBAAmB,OAE/C,MA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