{"version":3,"file":"Live_pricing_store.DoCePLBA.mjs","names":["create"],"sources":["https:/framerusercontent.com/modules/rf7AA1DfRPDSrhfmrmpj/dKau7FhYy42WCs2fsPCY/Live_pricing_config.js","https:/framerusercontent.com/modules/we4CziCpeycopbrILvTY/EVa1LORMEgcp0AY9EZq8/Live_pricing_service.js","https:/framerusercontent.com/modules/CyNT4Zo4FfF9Gv96WuEJ/2uJZkLBTWEMjZMRXEI9e/Live_pricing_cache.js","https:/framerusercontent.com/modules/3C9wF5reOoO0EZmRXDu0/ygnGnGXVxi5aqDsPa5BS/Live_pricing_store.js"],"sourcesContent":["export const LIVE_PRICING_CONFIG={CACHE_TTL_MINUTES:10,DEFAULT_CURRENCY:\"USD\",MAX_PRODUCTS_PER_QUERY:250,ENABLE_LIVE_PRICING:true};\nexport const __FramerMetadata__ = {\"exports\":{\"LIVE_PRICING_CONFIG\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Live_pricing_config.map","import{shopifyClient}from\"https://framerusercontent.com/modules/c5gtsBimYk7u4sSXwOlt/qYF6ekN6aOwuxUWbCTWd/Shopify_client.js\";import{LIVE_PRICING_CONFIG}from\"https://framerusercontent.com/modules/rf7AA1DfRPDSrhfmrmpj/dKau7FhYy42WCs2fsPCY/Live_pricing_config.js\";const LIVE_PRICING_QUERY=`#graphql\n  query GetLivePricing($country: CountryCode, $first: Int!, $after: String) \n    @inContext(country: $country) {\n    products(first: $first, after: $after) {\n      edges {\n        node {\n          id\n          variants(first: 100) {\n            edges {\n              node {\n                id\n                price {\n                  amount\n                  currencyCode\n                }\n                compareAtPrice {\n                  amount\n                  currencyCode\n                }\n              }\n            }\n          }\n        }\n      }\n      pageInfo {\n        hasNextPage\n        endCursor\n      }\n    }\n  }\n`;/**\n * Normalize pricing data from GraphQL response to flat map\n */function normalizePricingData(products){const normalized={};for(const product of products){for(const{node:variant}of product.variants.edges){// Strip GID prefix if present\nconst variantId=variant.id.replace(\"gid://shopify/ProductVariant/\",\"\");normalized[variantId]={price:variant.price,compareAtPrice:variant.compareAtPrice};}}return normalized;}/**\n * Fetch all pages of live pricing data recursively\n */async function fetchAllPagesLivePricing(country,after,accumulatedProducts=[]){const variables={first:LIVE_PRICING_CONFIG.MAX_PRODUCTS_PER_QUERY,after,...country&&{country}};const result=await shopifyClient({query:LIVE_PRICING_QUERY,variables});// Handle errors\nif(result.errors.length>0){return{data:null,errors:result.errors};}if(!result.data||!result.data.products){return{data:null,errors:[{message:\"No products data in response\"}]};}// Accumulate products from this page\nconst products=result.data.products.edges.map(e=>e.node);const allProducts=[...accumulatedProducts,...products];// Check if there are more pages\nif(result.data.products.pageInfo.hasNextPage&&result.data.products.pageInfo.endCursor){// Recursively fetch next page\nreturn fetchAllPagesLivePricing(country,result.data.products.pageInfo.endCursor,allProducts);}// All pages fetched, normalize and return\nconst normalized=normalizePricingData(allProducts);return{data:normalized,errors:[]};}/**\n * Main function to fetch live pricing for all products\n * @param country - Country code for market-specific pricing (e.g., \"US\", \"GB\")\n * @returns Normalized pricing data keyed by variant ID\n */export async function fetchLivePricing(country){try{const result=await fetchAllPagesLivePricing(country);return result;}catch(error){console.error(\"[Live Pricing] Error fetching live pricing:\",error);return{data:null,errors:[{message:error instanceof Error?error.message:\"Unknown error fetching live pricing\"}]};}}\nexport const __FramerMetadata__ = {\"exports\":{\"fetchLivePricing\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"NormalizedLivePricing\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Live_pricing_service.map","import{LIVE_PRICING_CONFIG}from\"https://framerusercontent.com/modules/rf7AA1DfRPDSrhfmrmpj/dKau7FhYy42WCs2fsPCY/Live_pricing_config.js\";const CACHE_KEY=\"frameship_live_pricing_cache\";/**\n * Get live pricing data from localStorage cache\n */export function getLivePricingFromCache(){try{const cached=localStorage.getItem(CACHE_KEY);if(!cached)return null;const parsed=JSON.parse(cached);return parsed;}catch(error){console.error(\"Error reading live pricing cache:\",error);return null;}}/**\n * Save live pricing data to localStorage cache\n */export function saveLivePricingToCache(data,market){try{const cacheData={data,timestamp:Date.now(),market,defaultCurrency:LIVE_PRICING_CONFIG.DEFAULT_CURRENCY};localStorage.setItem(CACHE_KEY,JSON.stringify(cacheData));}catch(error){console.error(\"Error saving live pricing cache:\",error);}}/**\n * Check if cache is still valid (not expired)\n */export function isCacheValid(cache,ttlMinutes=LIVE_PRICING_CONFIG.CACHE_TTL_MINUTES){if(!cache)return false;const ageMinutes=(Date.now()-cache.timestamp)/1e3/60;return ageMinutes<ttlMinutes;}/**\n * Determine if live pricing should be fetched\n * Fetch if:\n * 1. No cache exists\n * 2. Cache expired (> TTL)\n * 3. Market changed (different country code)\n */export function shouldFetchLivePricing(currentMarket){const cache=getLivePricingFromCache();// No cache exists - need to fetch\nif(!cache){return true;}// Cache expired - need to fetch\nif(!isCacheValid(cache)){return true;}// Market changed - need to fetch\nif(currentMarket&&cache.market!==currentMarket){return true;}return false;}/**\n * Clear live pricing cache\n */export function clearLivePricingCache(){try{localStorage.removeItem(CACHE_KEY);}catch(error){console.error(\"Error clearing live pricing cache:\",error);}}\nexport const __FramerMetadata__ = {\"exports\":{\"shouldFetchLivePricing\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getLivePricingFromCache\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"saveLivePricingToCache\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"LivePricingCacheData\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"clearLivePricingCache\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"isCacheValid\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Live_pricing_cache.map","import{create}from\"https://framerusercontent.com/modules/ieMSnIJVCiFKJmsg1OmM/KWFJj6n258MVreTmJoNk/Zustand.js\";import{fetchLivePricing}from\"https://framerusercontent.com/modules/we4CziCpeycopbrILvTY/EVa1LORMEgcp0AY9EZq8/Live_pricing_service.js\";import{getLivePricingFromCache,saveLivePricingToCache,shouldFetchLivePricing,clearLivePricingCache}from\"https://framerusercontent.com/modules/CyNT4Zo4FfF9Gv96WuEJ/2uJZkLBTWEMjZMRXEI9e/Live_pricing_cache.js\";import{LIVE_PRICING_CONFIG}from\"https://framerusercontent.com/modules/rf7AA1DfRPDSrhfmrmpj/dKau7FhYy42WCs2fsPCY/Live_pricing_config.js\";export const useLivePricingStore=create((set,get)=>{// Initialize from cache on store creation\nconst cachedData=getLivePricingFromCache();const initialData=cachedData?.data||null;return{livePricing:initialData,isLoading:false,isFetching:false,error:null,setLivePricing:data=>{set({livePricing:data,error:null});},fetchLivePricingData:async(market,force)=>{// Check if feature is enabled\nif(!LIVE_PRICING_CONFIG.ENABLE_LIVE_PRICING){return;}// Check if we should fetch\nif(!force&&!shouldFetchLivePricing(market)){return;}const currentData=get().livePricing;const hasExistingData=currentData!==null;// Set appropriate loading state\nif(hasExistingData){// Background refresh - use isFetching\nset({isFetching:true,error:null});}else{// Initial load - use isLoading\nset({isLoading:true,error:null});}try{const result=await fetchLivePricing(market);if(result.errors.length>0){const errorMsg=result.errors.map(e=>e.message).join(\", \");console.error(\"[Live Pricing] Fetch errors:\",errorMsg);set({error:errorMsg,isLoading:false,isFetching:false});return;}if(result.data){// Update store\nset({livePricing:result.data,error:null,isLoading:false,isFetching:false});// Save to cache\nsaveLivePricingToCache(result.data,market||\"default\");}else{set({error:\"No data received\",isLoading:false,isFetching:false});}}catch(error){const errorMsg=error instanceof Error?error.message:\"Unknown error\";console.error(\"[Live Pricing] Unexpected error:\",errorMsg);set({error:errorMsg,isLoading:false,isFetching:false});}},getLivePrice:variantId=>{const{livePricing}=get();if(!livePricing)return null;// Strip GID prefix if present in the variant ID\nconst cleanVariantId=variantId.replace(\"gid://shopify/ProductVariant/\",\"\");return livePricing[cleanVariantId]||null;},clearLivePricing:()=>{clearLivePricingCache();set({livePricing:null,error:null,isLoading:false,isFetching:false});}};});\nexport const __FramerMetadata__ = {\"exports\":{\"useLivePricingStore\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Live_pricing_store.map"],"mappings":"2IAAa,EAAoB,CAAC,kBAAkB,GAAG,iBAAiB,MAAM,uBAAuB,IAAI,oBAAoB,GAAK,ICgC/H,SAAS,EAAqB,EAAS,CAAC,IAAM,EAAW,EAAE,CAAC,IAAI,IAAM,KAAW,EAAU,IAAI,GAAK,CAAC,KAAK,KAAW,EAAQ,SAAS,MAAM,CAC/I,IAAM,EAAU,EAAQ,GAAG,QAAQ,gCAAgC,GAAG,CAAC,EAAW,GAAW,CAAC,MAAM,EAAQ,MAAM,eAAe,EAAQ,eAAe,CAAG,OAAO,EAE/J,eAAe,EAAyB,EAAQ,EAAM,EAAoB,EAAE,CAAC,CAAgG,IAAM,EAAO,MAAM,EAAc,CAAC,MAAM,EAAmB,UAA1I,CAAC,MAAM,EAAoB,uBAAuB,QAAM,GAAG,GAAS,CAAC,UAAQ,CAAC,CAAsE,CAAC,CACtP,GAAG,EAAO,OAAO,OAAO,EAAG,MAAM,CAAC,KAAK,KAAK,OAAO,EAAO,OAAO,CAAE,GAAG,CAAC,EAAO,MAAM,CAAC,EAAO,KAAK,SAAU,MAAM,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,QAAQ,+BAA+B,CAAC,CAAC,CAC9K,IAAM,EAAS,EAAO,KAAK,SAAS,MAAM,IAAI,GAAG,EAAE,KAAK,CAAO,EAAY,CAAC,GAAG,EAAoB,GAAG,EAAS,CAG5D,OAFhD,EAAO,KAAK,SAAS,SAAS,aAAa,EAAO,KA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