{"version":3,"file":"walmart-preferences-31863de4.js","sources":["../../../client/src/javascripts/customer_pages/_application/walmart-preferences.js"],"sourcesContent":["// esversion: 8\nimport Cookies from 'js-cookie';\nimport Store from '../_utils/tools/store';\nimport { builderDispatch, WebUI } from '../_utils/ui';\n\nconst STORE_ID_COOKIE = 'assortmentStoreId';\nconst USER_ID_COOKIE = 'CID';\nconst CID_FORMAT = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nasync function checkForPreferences() {\n  // don't bother if the cookie is already set\n  if (Cookies.get(STORE_ID_COOKIE)) return;\n  // crude check we're logged in and cookie value matches CID format\n  if (!Cookies.get(USER_ID_COOKIE) || !CID_FORMAT.test(Cookies.get(USER_ID_COOKIE))) {\n    return;\n  }\n\n   // fetch the assortmentStoreId from GraphQL endpoint\n   const response = (await (await fetch(\"/orchestra/home/graphql/FooterLocation/177ddb14834fe8588360fba78c2af7ca1052a44f8e8721769717d189912ab8e6\", {\n      \"headers\": {\n         \"accept\": \"application/json\",\n         \"content-type\": \"application/json\",\n         \"wm_mp\": \"true\",\n         \"wm_page_url\": \"https://www.walmart.com/\",\n         \"x-apollo-operation-name\": \"FooterLocation\",\n         \"x-o-bu\": \"WALMART-US\",\n         \"x-o-ccm\": \"server\",\n         \"x-o-gql-query\": \"query FooterLocation\",\n         \"x-o-mart\": \"B2C\",\n         \"x-o-platform\": \"rweb-photo\",\n         \"x-o-platform-version\": \"main-496-c96289\",\n         \"x-o-segment\": \"oaoh\"\n      },\n      \"method\": \"GET\",\n      \"mode\": \"cors\",\n      \"credentials\": \"include\"\n   })).json());\n\n   // don't overwrite the cookie, if it's already set\n   if (Cookies.get(STORE_ID_COOKIE)) return;\n\n   if (response.data && response.data.location) {\n      const { data: { location: { nodeId } } } = response;\n      Cookies.set(STORE_ID_COOKIE, nodeId, { domain: '.walmart.com', path: '/' });\n   }\n}\n\nif (Store.isWalmart()) {\n   builderDispatch.register((event) => {\n      switch (event.type) {\n         case WebUI.LOGIN:\n            checkForPreferences();\n         break;\n         default:\n            // ignore;\n      }\n   });\n   checkForPreferences();\n}"],"names":["STORE_ID_COOKIE","USER_ID_COOKIE","CID_FORMAT","checkForPreferences","Cookies","response","nodeId","Store","builderDispatch","event","WebUI"],"mappings":"gIAKA,MAAMA,EAAkB,oBAClBC,EAAiB,MACjBC,EAAa,kEAEnB,eAAeC,GAAsB,CAInC,GAFIC,EAAQ,IAAIJ,CAAe,GAE3B,CAACI,EAAQ,IAAIH,CAAc,GAAK,CAACC,EAAW,KAAKE,EAAQ,IAAIH,CAAc,CAAC,EAC9E,OAID,MAAMI,EAAY,MAAO,MAAM,MAAM,0GAA2G,CAC7I,QAAW,CACR,OAAU,mBACV,eAAgB,mBAChB,MAAS,OACT,YAAe,2BACf,0BAA2B,iBAC3B,SAAU,aACV,UAAW,SACX,gBAAiB,uBACjB,WAAY,MACZ,eAAgB,aAChB,uBAAwB,kBACxB,cAAe,MACjB,EACD,OAAU,MACV,KAAQ,OACR,YAAe,SACrB,CAAI,GAAG,KAAI,EAGR,GAAI,CAAAD,EAAQ,IAAIJ,CAAe,GAE3BK,EAAS,MAAQA,EAAS,KAAK,SAAU,CAC1C,KAAM,CAAE,KAAM,CAAE,SAAU,CAAE,OAAAC,CAAQ,CAAA,CAAI,EAAGD,EAC3CD,EAAQ,IAAIJ,EAAiBM,EAAQ,CAAE,OAAQ,eAAgB,KAAM,GAAG,CAAE,CAC5E,CACJ,CAEIC,EAAM,UAAS,IAChBC,EAAgB,SAAUC,GAAU,CACjC,OAAQA,EAAM,KAAI,CACf,KAAKC,EAAM,MACRP,IACH,KAGF,CACP,CAAI,EACDA"}