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BC,ECdFsB,EAACM,EAAaM,KACnC,MAAMJ,EAAU1B,OAAOa,aACvB,GAAKa,GAAYF,GAAQM,EAGzB,IACEJ,EAAQR,QAAQM,EAAKM,EACvB,CAAE,MAAO3B,GACPwB,QAAQC,MAAMzB,EAChB,GDK6Be,CAAQM,EAAKV,IACpC,KACF,CACA,QACE,MAAMW,MAAM,kBAGlB,CAAE,MAAOH,GACP3B,EAAiBC,EAAM0B,EACzB,I","sources":["webpack://nocodenodeweb/./src/client/embedded/message.ts","webpack://nocodenodeweb/./src/client/embedded/cartIframe.ts","webpack://nocodenodeweb/./src/client/utils/storage.ts"],"sourcesContent":["const DEFAULT_TIMEOUT_MS = 10000;\n\nexport enum CrossOriginAction {\n CheckLocalStorage = 'CHECK_LOCAL_STORAGE',\n GetItem = 'GET_ITEM',\n SetItem = 'SET_ITEM'\n}\n\nexport interface CrossOriginMessage {\n action: CrossOriginAction;\n payload?: Record;\n}\n\n/**\n * Promisifies sending messages so that we can use async/await syntax. Also adds timeout functionality for error handling\n * Creates a new message channel for each request so we can identify that the response coming back belongs to this request\n * port1 is used to send messages, and port2 is transferred over to the targetWindow to use to respond (in replyCrossOrigin)\n * @param targetWindow: the window we want to broadcast the mes to (usually `parent` or `iframe.contentWindow`)\n * @param message\n * @param timeoutMs: default 10000\n * @param targetOrigin: default '*'\n * @returns promise on response\n */\nexport function requestCrossOrigin(\n targetWindow: Window,\n message: CrossOriginMessage,\n targetOrigin: string = '*',\n timeoutMs: number = DEFAULT_TIMEOUT_MS\n): Promise {\n const messagePromise = new Promise((resolve, reject) => {\n const channel = new MessageChannel();\n\n channel.port1.onmessage = ({ data }) => {\n channel.port1.close();\n const response = data as TResponse | Error;\n if (response instanceof Error) {\n reject(response);\n } else {\n resolve(response);\n }\n };\n\n channel.port1.onmessageerror = ({ data }) => {\n channel.port1.close();\n reject(data);\n };\n\n targetWindow.postMessage(message, targetOrigin, [channel.port2]);\n });\n\n const timeoutPromise = new Promise((_, reject) => {\n const timeout = Math.max(timeoutMs, 0);\n setTimeout(\n () => reject(new Error(`Timeout: Unable to get response within ${timeout}ms`)),\n timeout\n );\n });\n\n return Promise.race([messagePromise, timeoutPromise]);\n}\n\n/**\n * Send response for requests coming from the requestCrossOrigin() function.\n * It is recommended to verify the `event.origin` before calling this function to make sure that the origin of the request is authorized.\n * For eg: `window.addEventListener('message', (event) => { if (event.origin===\"https://myapp.com\") replyCrossOrigin(event, myResponse) })`;\n * @param event the event object when the request is coming\n * @param response the response you want to send back\n */\nexport function replyCrossOrigin(port: MessagePort, message: TResponse | Error) {\n port.postMessage(message);\n port.close();\n}\n","import { getItem, setItem, isLocalStorageEnabled } from '@client/utils/storage';\nimport { replyCrossOrigin, CrossOriginAction, CrossOriginMessage } from './message';\n\nwindow.addEventListener('message', async (e) => {\n if (e.source !== window.parent || !e.ports[0] || typeof e.data !== 'object') {\n return;\n }\n\n const port = e.ports[0];\n\n try {\n const { action, payload } = e.data as CrossOriginMessage;\n\n switch (action) {\n case CrossOriginAction.CheckLocalStorage: {\n replyCrossOrigin(port, isLocalStorageEnabled());\n break;\n }\n case CrossOriginAction.GetItem: {\n if (typeof payload?.key !== 'string') {\n throw Error('Get Item: Invalid key');\n }\n\n replyCrossOrigin(port, getItem(payload?.key));\n break;\n }\n case CrossOriginAction.SetItem: {\n if (typeof payload?.key !== 'string') {\n throw Error('Set Item: Invalid key');\n }\n if (typeof payload?.value !== 'string') {\n throw Error('Set Item: Invalid value');\n }\n const { key, value } = payload;\n replyCrossOrigin(port, setItem(key, value));\n break;\n }\n default: {\n throw Error('Unknown action');\n }\n }\n } catch (err) {\n replyCrossOrigin(port, err);\n }\n});\n","export const PAYPAL_CART_KEY = '__paypal_hosted_cart__';\n\nexport const isLocalStorageEnabled = () => {\n const testKey = '__test__localStorage__';\n try {\n if (window.localStorage) {\n const value = Math.random().toString(); // NOSONAR this random number not need to be secure\n window.localStorage.setItem(testKey, value);\n const result = window.localStorage.getItem(testKey);\n window.localStorage.removeItem(testKey);\n if (value === result) {\n return true;\n }\n }\n } catch (err) {\n // err\n }\n return false;\n};\n\nexport const setItem = (key: string, item: string) => {\n const storage = window.localStorage;\n if (!storage || !key || !item) {\n return;\n }\n try {\n storage.setItem(key, item);\n } catch (e) {\n console.error(e);\n }\n};\n\nexport const getItem = (key: string): string | undefined => {\n const storage = window.localStorage;\n try {\n let value;\n if (storage) {\n value = storage.getItem(key);\n return value;\n }\n } catch (e) {\n console.error(e);\n }\n return undefined;\n};\n\nexport const getSessionId = () => {\n let sessionId: string | undefined;\n\n try {\n const paypal_storage = getItem('__paypal_storage__') ?? '';\n sessionId = JSON.parse(paypal_storage)?.__session__?.guid;\n } catch (e) {\n console.error(e);\n }\n\n return sessionId;\n};\n"],"names":["CrossOriginAction","replyCrossOrigin","port","message","postMessage","close","window","addEventListener","async","e","source","parent","ports","data","action","payload","CheckLocalStorage","isLocalStorageEnabled","testKey","localStorage","value","Math","random","toString","setItem","result","getItem","removeItem","err","GetItem","key","Error","storage","console","error","SetItem","item"],"sourceRoot":""}