{"version":3,"file":"Live_pricing_store.DAEhTPxG.mjs","names":["create","__exportAll","init_Shopify_client","f","init_Zustand","shopifyClient","LIVE_PRICING_CONFIG","init_Live_pricing_config","__esmMin","normalizePricingData","normalized","product","products","variant","variantId","fetchAllPagesLivePricing","variables","country","result","LIVE_PRICING_QUERY","allProducts","accumulatedProducts","fetchLivePricing","error","init_Live_pricing_service","getLivePricingFromCache","cached","CACHE_KEY","saveLivePricingToCache","cacheData","isCacheValid","cache","ttlMinutes","shouldFetchLivePricing","currentMarket","clearLivePricingCache","init_Live_pricing_cache","Live_pricing_store_exports","useLivePricingStore","init_Live_pricing_store","set","data","force","market","get","errorMsg","livePricing"],"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":"A,oKAAa,EAAoB,CAAC,kBAAkB,GAAG,iBAAiB,MAAM,uBAAuB,IAAI,oBAAoB,EAAI,C,OCgC9H,SAASS,EAAqB,EAAS,CAAC,IAAMC,EAAW,CAAC,EAAE,IAAI,IAAMC,KAAWC,EAAU,IAAI,GAAK,CAAC,KAAKC,KAAWF,EAAQ,SAAS,MAAM,CAC/I,IAAMG,EAAUD,EAAQ,GAAG,QAAQ,gCAAgC,EAAE,EAAE,EAAWC,GAAW,CAAC,MAAMD,EAAQ,MAAM,eAAeA,EAAQ,cAAc,CAAE,CAAE,OAAOH,CAAW,CAE1K,eAAeK,EAAyB,EAAQ,EAAM,EAAoB,CAAC,EAAE,CAAC,IAAMC,EAAU,CAAC,MAAMV,EAAoB,uBAAuB,QAAM,GAAGW,GAAS,CAAC,SAAO,CAAC,EAAQC,EAAO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