{"version":3,"file":"utils_CreateContinueUrls.BM6pyIMI.mjs","names":["promo"],"sources":["https:/framerusercontent.com/modules/EYW7hnHTTx9LO8bg7Bbo/mS5N8K6BCwcYqV4DrihL/utils_CreateSaveDesign.js","https:/framerusercontent.com/modules/Tegr1u830ah9SEz5Wrrc/NWy02LXj5tKEcB4tIVma/utils_CreateContinueUrls.js"],"sourcesContent":["import{getStarMapJewelrySku}from\"https://framerusercontent.com/modules/KYsdNQQbOOPfSKUhrJi1/dGQMzt7E45c5ph0pOn44/utils_JewelrySku.js\";import{getStarMapPrintSku}from\"https://framerusercontent.com/modules/a8wELR7klhmQ2Qw6JnVs/S9VUEjuxzZS4Le1lp439/utils_PrintSku.js\";import{setTnsSessionData}from\"https://framerusercontent.com/modules/hVOQolyK4JiFCyR5tOtr/vbBIjAH2gXJf2PUZIEAN/utils_Cookies.js\";import{getTnsProps}from\"https://framerusercontent.com/modules/f5MemFRu7KXGzetUeQ0m/M3l6rVHoK960AERCuYrr/utils_TnsProps.js\";import{setProductPropsSessionStorage}from\"https://framerusercontent.com/modules/6NueQ0CouAFqjFEtYeCA/tIeJnDQYKyR2jruc6FvK/store_ProductPropsLocalStorage.js\";import promo from\"https://framerusercontent.com/modules/dS8EvCCZ7YznNbOLW9Uv/3IzGog3eooSoD6DtWpO9/promoStore.js\";// API URL\n// const baseApiSaveDesignUrl = `https://api-server.thenightsky.com/api/cart/urlTriggeredAddToCart`\nconst baseApiSaveDesignUrl=`https://api-server.thenightsky.com/api/framer/saveDesignAddOrCreateCart`;const baseApiCartInfoUrl=`https://api-server.thenightsky.com/api/framer/cart-info`;export async function getCartInfo(store){try{const apiData={cartId:store?.cartId||\"\",orderId:store?.orderId||\"\",customerId:store?.customerId||\"\"};const rawResponse=await fetch(baseApiCartInfoUrl,{method:\"POST\",headers:{Accept:\"application/json\",\"Content-Type\":\"application/json\"},body:JSON.stringify(apiData)});return rawResponse.json();}catch(error){console.error(`Failed to get Cart from Props`);}return{};}export async function triggerSaveDesign(store,setStore,countryCode,email,consent){try{// ////////////\n// GET SKU\nlet tnsSku=\"\";if(store.productFormat===\"Jewelry\"){tnsSku=getStarMapJewelrySku(store.productFormat,store.jewelryPiece,store.jewelryMaterial,store.jewelrySize,store.jewelryBezelMount,store.jewelryChain);}else if(store.productFormat===\"Print\"){tnsSku=getStarMapPrintSku(store.printFormat,store.printTheme,store.printStyle,store.printLayout,store.printSize,store.printFrame,store.printFoilColor);}// ////////////\n// GET TNS PROPS\nconst tnsProps=getTnsProps(store);// Star signs:\n// const skuProps = {\n//     sign: jewelryStarSign,\n//     text: (jewelryEngraveText || \"\").trim(),\n// }\n// //////////////////////\n// BUILT URL PARAMETERS\n// ////////////\n// GET ORDER OR CART IDS * from Local Store\nconst{cartId,orderId,customerId}=store;//\nlet hostname;if(typeof window!==\"undefined\"&&window.location?.hostname){hostname=window.location.hostname;}// Get discount code if there is one\nconst discountCode=promo.getDiscountCode()||\"\";//\nconst apiData={orderId,customerId,atcSku:tnsSku||\"\",atcSkuProps:{...tnsProps},cartId,countryCode,atcSaveDesignProps:{email,consent:consent!==false},hostname,couponCode:discountCode};try{const rawResponse=await fetch(baseApiSaveDesignUrl,{method:\"POST\",headers:{Accept:\"application/json\",\"Content-Type\":\"application/json\"},body:JSON.stringify(apiData,(key,value)=>{if(value!==null)return value;})});const result=await rawResponse.json();if(!result){console.error(`Save Design Failed`);}else{let itemId=\"\";if(result?.cart?.items?.length>0){const latestItem=result.cart.items[result.cart.items.length-1];itemId=latestItem.id;}//\n// SUCCESS\n//\nconst updatedStoreProps={...store,...result.cartId?{cartId:result.cartId}:{},...result.orderId?{orderId:result.orderId}:{},...result.customerId?{customerId:result.customerId}:{}};// Update store values for in page refresh\nawait setStore(updatedStoreProps);// Store Values\nsetTnsSessionData({...result.cartId?{cartId:result.cartId}:{},...result.orderId?{orderId:result.orderId}:{},...result.customerId?{customerId:result.customerId}:{}});if(result.orderId){setProductPropsSessionStorage(\"orderId\",result.orderId);if(result.customerId){setProductPropsSessionStorage(\"customerId\",result.customerId);}}else if(result.cartId){setProductPropsSessionStorage(\"cartId\",result.cartId);}return result;}}catch(error){console.error(`Error saving design`,error);}}catch(error){console.error(`Failed to get Create Url from Props`);}return null;}\nexport const __FramerMetadata__ = {\"exports\":{\"triggerSaveDesign\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getCartInfo\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}","import{getStarMapJewelrySku}from\"https://framerusercontent.com/modules/KYsdNQQbOOPfSKUhrJi1/dGQMzt7E45c5ph0pOn44/utils_JewelrySku.js\";import{getStarMapPrintSku}from\"https://framerusercontent.com/modules/a8wELR7klhmQ2Qw6JnVs/S9VUEjuxzZS4Le1lp439/utils_PrintSku.js\";import{getTnsProps}from\"https://framerusercontent.com/modules/f5MemFRu7KXGzetUeQ0m/M3l6rVHoK960AERCuYrr/utils_TnsProps.js\";const designUrl=\"https://www.thenightsky.com/design\";const cartUrl=\"https://www.thenightsky.com/checkout/cart\";export function getContinueUrl(addToCartNotPersonalize,productProps,countryCode,referringProduct,discountCode){let url=\"\";try{// ////////////\n// GET SKU\nlet tnsSku=\"\";let printProps={};if(productProps.productFormat===\"Jewelry\"){tnsSku=getStarMapJewelrySku(productProps.productFormat,productProps.jewelryPiece,productProps.jewelryMaterial,productProps.jewelrySize,productProps.jewelryBezelMount,productProps.jewelryChain);}else if(productProps.productFormat===\"Print\"){tnsSku=getStarMapPrintSku(productProps.printFormat,productProps.printTheme,productProps.printStyle,productProps.printLayout,productProps.printSize,productProps.printFrame,productProps.printFoilColor);}// // ////////////\n// // GET TNS PROPS\n// const tnsProps = {\n//     ...(printProps ? { ...printProps } : null),\n//     ...(productProps.textLocation\n//         ? { textLocation: productProps.textLocation }\n//         : null),\n//     ...(productProps.latitude\n//         ? { latitude: productProps.latitude }\n//         : null),\n//     ...(productProps.longitude\n//         ? { longitude: productProps.longitude }\n//         : null),\n//     ...(productProps.text ? { text: productProps.text } : null),\n//     ...(productProps.time ? { time: productProps.time } : null),\n//     ...(productProps.textDate\n//         ? { textDate: productProps.textDate }\n//         : null),\n//     ...(productProps.grid !== undefined && productProps.grid !== null\n//         ? { grid: productProps.grid }\n//         : null),\n//     ...(productProps.constellations !== undefined &&\n//     productProps.constellations !== null\n//         ? { constellations: productProps.constellations }\n//         : null),\n//     ...(productProps.moon !== undefined && productProps.moon !== null\n//         ? { moon: productProps.moon }\n//         : null),\n// }\nconst tnsProps=getTnsProps(productProps);// Star signs:\n// const skuProps = {\n//     sign: jewelryStarSign,\n//     text: (jewelryEngraveText || \"\").trim(),\n// }\n// //////////////////////\n// BUILT URL PARAMETERS\nlet urlParameters=[];// ////////////\n// GET ORDER OR CART IDS\nif(addToCartNotPersonalize){const{cartId,orderId,customerId}=productProps;if(orderId&&customerId){// Order Id trumps all\nurlParameters.push(`customerId=${customerId}`);urlParameters.push(`orderId=${orderId}`);}else if(cartId){urlParameters.push(`cartId=${cartId}`);}const itemId=productProps.itemId||\"\";if(itemId){urlParameters.push(`itemId=${itemId}`);}}// SKU\nif(tnsSku){if(addToCartNotPersonalize){urlParameters.push(`atcSku=${encodeURIComponent(tnsSku)}`);}else{urlParameters.push(`sku=${encodeURIComponent(tnsSku)}`);}}// Country Code\nif(countryCode){urlParameters.push(`tnscc=${countryCode}`);}if(discountCode){urlParameters.push(`code=${discountCode}`);}// Props\nif(Object.keys(tnsProps).length>0){if(addToCartNotPersonalize){urlParameters.push(`atcSkuProps=${encodeURIComponent(JSON.stringify(tnsProps))}`);}else{urlParameters.push(`skuProps=${encodeURIComponent(JSON.stringify(tnsProps))}`);}}// Referring Product\nif(referringProduct){urlParameters.push(`rp=${referringProduct}`);}// Continue URL:\nconst continueUrl=addToCartNotPersonalize?cartUrl:designUrl;const continueUrlParams=urlParameters.join(\"&\");return`${continueUrl}${continueUrlParams.length>0?\"?\":\"\"}${continueUrlParams}`;}catch(error){console.error(`Failed to get Create Url from Props`);}return\"\";}export var ContinueDestination;(function(ContinueDestination){ContinueDestination[\"PERSONALIZE\"]=\"personalize\";ContinueDestination[\"ADD_TO_CART\"]=\"add_to_cart\";ContinueDestination[\"REDIRECT_TO_CART\"]=\"redirect_to_cart\";})(ContinueDestination||(ContinueDestination={}));export function getCreatePlatformUrl(continueDestination,productProps,countryCode,referringProduct){let url=\"\";try{// ////////////\n// GET SKU\nlet tnsSku=\"\";if(productProps.productFormat===\"Jewelry\"){tnsSku=getStarMapJewelrySku(productProps.productFormat,productProps.jewelryPiece,productProps.jewelryMaterial,productProps.jewelrySize,productProps.jewelryBezelMount,productProps.jewelryChain);}else if(productProps.productFormat===\"Print\"){tnsSku=getStarMapPrintSku(productProps.printFormat,productProps.printTheme,productProps.printStyle,productProps.printLayout,productProps.printSize,productProps.printFrame,productProps.printFoilColor);}// ////////////\n// GET TNS PROPS\nconst tnsProps=getTnsProps(productProps);// Star signs:\n// const skuProps = {\n//     sign: jewelryStarSign,\n//     text: (jewelryEngraveText || \"\").trim(),\n// }\n// //////////////////////\n// BUILT URL PARAMETERS\nlet urlParameters=[];// Country Code\nif(countryCode){urlParameters.push(`tnscc=${countryCode}`);}// ////////////\n// GET ORDER OR CART IDS\nconst{cartId,orderId,customerId}=productProps;if(orderId&&customerId){// Order Id trumps all\nurlParameters.push(`customerId=${customerId}`);urlParameters.push(`orderId=${orderId}`);}else if(cartId){urlParameters.push(`cartId=${cartId}`);}const itemId=productProps.itemId||\"\";if(itemId){urlParameters.push(`itemId=${itemId}`);}// BUILD URL:\nlet url=designUrl;switch(continueDestination){default:case\"personalize\":// SKU\nif(tnsSku){urlParameters.push(`sku=${encodeURIComponent(tnsSku)}`);}// Props\nif(Object.keys(tnsProps).length>0){urlParameters.push(`skuProps=${encodeURIComponent(JSON.stringify(tnsProps))}`);}break;case\"add_to_cart\":url=cartUrl;// SKU\nif(tnsSku){urlParameters.push(`atcSku=${encodeURIComponent(tnsSku)}`);}// Props\nif(Object.keys(tnsProps).length>0){urlParameters.push(`atcSkuProps=${encodeURIComponent(JSON.stringify(tnsProps))}`);}break;case\"redirect_to_cart\":url=cartUrl;break;}// Referring Product\nif(referringProduct){urlParameters.push(`rp=${referringProduct}`);}const continueUrlParams=urlParameters.join(\"&\");return`${url}?${continueUrlParams}`;}catch(error){console.error(`Failed to get Create Platform Url from Props`);}return\"\";}export function getCartUrl(cartId,orderId,customerId,countryCode){try{// BUILT URL PARAMETERS\nlet urlParameters=[];if(orderId&&customerId){// Order Id trumps all\nurlParameters.push(`customerId=${customerId}`);urlParameters.push(`orderId=${orderId}`);}else if(cartId){urlParameters.push(`cartId=${cartId}`);}// Country Code\nif(countryCode){urlParameters.push(`tnscc=${countryCode}`);}return`${cartUrl}?${urlParameters.join(\"&\")}`;}catch(error){console.error(`Failed to get Create Platform Url from Props`);}return\"\";}\nexport const __FramerMetadata__ = {\"exports\":{\"getCreatePlatformUrl\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getCartUrl\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"ContinueDestination\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getContinueUrl\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"8ZAEilB,eAAsB,EAAkB,EAAM,EAAS,EAAY,EAAM,EAAQ,CAAC,GAAG,CAEtqB,IAAI,EAAO,GAAM,EAAM,gBAAgB,UAAW,EAAO,EAAqB,EAAM,cAAc,EAAM,aAAa,EAAM,gBAAgB,EAAM,YAAY,EAAM,kBAAkB,EAAM,aAAa,CAAU,EAAM,gBAAgB,UAAS,EAAO,EAAmB,EAAM,YAAY,EAAM,WAAW,EAAM,WAAW,EAAM,YAAY,EAAM,UAAU,EAAM,WAAW,EAAM,eAAe,EAEvY,IAAM,EAAS,EAAY,EAAM,CAS5B,CAAC,SAAO,UAAQ,cAAY,EAC7B,EA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