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DP,KAAKO,YAAc,GAJI,UAQUP,KAAKQ,4BARf,IAQvB,IAAK,EAAL,sBACE8B,EAAA,WATqB,8BAWvBtC,KAAKQ,2BAA6B,K,iCAGpC,SAAoBD,GAAa,WAC/B,OAAOP,KAAKuC,YAAYnB,MAAK,SAACoB,GAC5BC,eAAeC,QAAQ1D,EAAkBwD,GACzC,EAAK/B,aACHvB,EAAmBsD,IAAWtD,EAAkB,GAElD,IALuC,EAKjCyD,EAAc,GACdC,EAAe,GANkB,IAObrC,GAPa,IAOvC,IAAK,EAAL,qBAAuC,KAA1BS,EAA0B,QAA1BA,QACXA,EAAQ6B,WAAW,QACfD,EAAa3B,KAAKD,EAAQ8B,MAAM,IAChCH,EAAY1B,KAAKD,IAVgB,8BAavC,OAAOmB,QAAQY,IAAI,CACjB,EAAK9C,eAAe+C,YAAYL,GAChC,EAAK1C,eAAegD,aAAaL,U,uBAKvC,WAEE,IAAIM,EAAgBT,eAAeU,QAAQnE,GAO3C,OAJKoE,qCACHF,EAAgBjE,GAGbiE,EAWEf,QAAQjB,QAAQgC,IAVrBlD,KAAKqD,mBAALrD,KAAKqD,iBAAqBC,MAAM,GAAD,OAC1BC,EAAAA,EAAAA,uBAD0B,uBAG5BnC,MAAK,SAACoC,GAAD,OAAcA,EAASC,UAC5BrC,MAAK,SAACqC,GAAD,OAAUA,EAAKC,gBAAkBzE,KACtC8C,OAAM,kBAAM9C,MAERe,KAAKqD,uB,sEA9HGtD,I","sources":["webpack:///./resources/js/utils/localized-pricing.ts"],"sourcesContent":["import { ProductPricingStore } from \"@atlassian/bxp-product-pricing\";\nimport {\n CCPProductCatalogClient,\n ProductCatalogClient,\n} from \"@atlassiansox/asc-product-catalog\";\nimport Environment from \"../common/environment\";\n\nconst LOCALE_CACHE_KEY = \"bxp.currentLocale\";\n\nconst DEFAULT_LOCALE = \"US\";\nconst LOCALE_TO_CURRENCY = {\n US: \"USD\",\n JP: \"JPY\",\n};\n\nconst CONTENTFUL_CONFIG = {\n space: LOCALIZED_PRICING_CONTENTFUL_SPACE,\n environment: LOCALIZED_PRICING_CONTENTFUL_ENVIRONMENT,\n accessToken: LOCALIZED_PRICING_CONTENTFUL_ACCESS_TOKEN,\n};\n\nconst CCP_CONTENTFUL_CONFIG = {\n space: LOCALIZED_PRICING_CONTENTFUL_SPACE,\n environment: LOCALIZED_CCP_PRICING_CONTENTFUL_ENVIRONMENT,\n accessToken: LOCALIZED_CCP_PRICING_CONTENTFUL_ACCESS_TOKEN,\n};\n\nexport default class LocalizedPricing {\n constructor() {\n this.productPricing = new ProductPricingStore({\n productCatalogClient: new ProductCatalogClient(CONTENTFUL_CONFIG),\n ccpProductCatalogClient: new CCPProductCatalogClient(\n CCP_CONTENTFUL_CONFIG\n ),\n });\n this.productReqs = [];\n this.resolvePricingPromiseFuncs = [];\n this.currencyCode = null;\n }\n\n getPricingPromise(\n productKey,\n period,\n identifiers,\n customCurrencyCode,\n offeringSku\n ) {\n let pricingPromiseExecutor;\n const planKey = offeringSku ? \"sku:\" + offeringSku : productKey;\n\n if (planKey) {\n this.productReqs.push({ planKey, period });\n\n pricingPromiseExecutor = (resolve) => {\n // there's no service call promise yet so store a function that will resolve\n // this promise with the 'real' promise (localizedPricingPromise) once it exists\n const resolvePromiseFunc = () =>\n resolve(\n this.localizedPricingPromise\n .then(([hamsPricing, ccpPricing]) => {\n const priceTiersByPeriod = offeringSku\n ? ccpPricing[offeringSku]\n : hamsPricing[productKey];\n\n return {\n identifiers: identifiers ? identifiers : [],\n\n currencyCode: customCurrencyCode\n ? customCurrencyCode\n : this.currencyCode,\n\n pricingTiers:\n priceTiersByPeriod && priceTiersByPeriod[period]\n ? priceTiersByPeriod[period].map(\n ({ prices, ...rest }) => ({\n ...rest,\n price: prices.find(\n ({ currency }) =>\n currency ===\n (customCurrencyCode || this.currencyCode)\n ).unitPrice,\n })\n )\n : [],\n };\n })\n .catch((err) =>\n console.error(\n `Error on trying to retrieve pricing for plan key \"${planKey}\"`,\n err\n )\n )\n );\n\n this.resolvePricingPromiseFuncs.push(resolvePromiseFunc);\n };\n }\n\n return new Promise(pricingPromiseExecutor);\n }\n\n resolvePricingPromises() {\n if (this.productReqs.length)\n this.localizedPricingPromise = this.getLocalizedPricing(this.productReqs);\n\n this.productReqs = [];\n\n // we now have a promise making the actual service call to wait for\n // (localizedPricingPromise) so resolve the individual promises to it\n for (const resolvePromiseFunc of this.resolvePricingPromiseFuncs)\n resolvePromiseFunc();\n\n this.resolvePricingPromiseFuncs = [];\n }\n\n getLocalizedPricing(productReqs) {\n return this.getLocale().then((locale) => {\n sessionStorage.setItem(LOCALE_CACHE_KEY, locale);\n this.currencyCode =\n LOCALE_TO_CURRENCY[locale] || LOCALE_TO_CURRENCY[DEFAULT_LOCALE];\n\n const productKeys = [];\n const offeringSkus = [];\n for (const { planKey } of productReqs) {\n planKey.startsWith(\"sku:\")\n ? offeringSkus.push(planKey.slice(4))\n : productKeys.push(planKey);\n }\n\n return Promise.all([\n this.productPricing.getProducts(productKeys),\n this.productPricing.getOfferings(offeringSkus),\n ]);\n });\n }\n\n getLocale() {\n // pull locale from session storage if exists (also can be used for testing)\n let currentLocale = sessionStorage.getItem(LOCALE_CACHE_KEY);\n\n // skip the location query if we've disabled using geo currency\n if (!LOCALIZED_PRICING_USE_GEO_CURRENCY) {\n currentLocale = DEFAULT_LOCALE;\n }\n\n if (!currentLocale) {\n this.getLocalePromise ||= fetch(\n `${Environment.getWacIntegrationUrl()}/endpoint/location`\n )\n .then((response) => response.json())\n .then((json) => json.countryIsoCode || DEFAULT_LOCALE)\n .catch(() => DEFAULT_LOCALE);\n\n return this.getLocalePromise;\n }\n\n return Promise.resolve(currentLocale);\n }\n}\n"],"names":["LOCALE_CACHE_KEY","DEFAULT_LOCALE","LOCALE_TO_CURRENCY","US","JP","CONTENTFUL_CONFIG","space","LOCALIZED_PRICING_CONTENTFUL_SPACE","environment","LOCALIZED_PRICING_CONTENTFUL_ENVIRONMENT","accessToken","LOCALIZED_PRICING_CONTENTFUL_ACCESS_TOKEN","CCP_CONTENTFUL_CONFIG","LOCALIZED_CCP_PRICING_CONTENTFUL_ENVIRONMENT","LOCALIZED_CCP_PRICING_CONTENTFUL_ACCESS_TOKEN","LocalizedPricing","this","productPricing","ProductPricingStore","productCatalogClient","ProductCatalogClient","ccpProductCatalogClient","CCPProductCatalogClient","productReqs","resolvePricingPromiseFuncs","currencyCode","productKey","period","identifiers","customCurrencyCode","offeringSku","pricingPromiseExecutor","planKey","push","resolve","localizedPricingPromise","then","hamsPricing","ccpPricing","priceTiersByPeriod","pricingTiers","map","prices","price","find","currency","unitPrice","catch","err","console","error","Promise","length","getLocalizedPricing","resolvePromiseFunc","getLocale","locale","sessionStorage","setItem","productKeys","offeringSkus","startsWith","slice","all","getProducts","getOfferings","currentLocale","getItem","LOCALIZED_PRICING_USE_GEO_CURRENCY","getLocalePromise","fetch","Environment","response","json","countryIsoCode"],"sourceRoot":""}