{"version":3,"file":"a3cbbf1c.js","sources":["../../../node_modules/@shopify/hydrogen/dist/esnext/utilities/hash.js","../../../node_modules/@shopify/hydrogen/dist/esnext/utilities/suspense.js","../../../node_modules/@shopify/hydrogen/dist/esnext/foundation/fetchSync/ResponseSync.js","../../../node_modules/@shopify/hydrogen/dist/esnext/foundation/fetchSync/client/fetchSync.js"],"sourcesContent":["import { STOREFRONT_API_BUYER_IP_HEADER } from '../constants.js';\nexport function hashKey(queryKey) {\n const rawKeys = Array.isArray(queryKey) ? queryKey : [queryKey];\n let hash = '';\n // Keys from useShopQuery are in the following shape:\n // ['prefix', 'api-endpoint', {body:'query',headers:{}}]\n // Since the API endpoint already contains the shop domain and api version,\n // we can ignore the headers and only use the `body` from the payload.\n for (const key of rawKeys) {\n if (key != null) {\n if (typeof key === 'object') {\n // Queries from useQuery might not have a `body`. In that case,\n // fallback to a safer (but slower) stringify.\n if (!!key.body && typeof key.body === 'string') {\n hash += key.body;\n if (!!key.headers && key.headers[STOREFRONT_API_BUYER_IP_HEADER]) {\n hash += key.headers[STOREFRONT_API_BUYER_IP_HEADER];\n }\n }\n else {\n hash += JSON.stringify(key);\n }\n }\n else {\n hash += key;\n }\n }\n }\n return hash;\n}\n","import { hashKey } from './hash.js';\n/**\n * Wrap the fetch promise in a way that React Suspense understands.\n * Essentially, keep throwing something until you have legit data.\n */\nexport function wrapPromise(promise) {\n let status = 'pending';\n let response;\n const suspender = promise.then((res) => {\n status = 'success';\n response = res;\n }, (err) => {\n status = 'error';\n response = err;\n });\n const read = () => {\n switch (status) {\n case 'pending':\n throw suspender;\n case 'error':\n throw response;\n default:\n return response;\n }\n };\n return { read };\n}\nconst browserCache = {};\n/**\n * Perform an async function in a synchronous way for Suspense support.\n * To be used only in the client.\n * Inspired by https://github.com/pmndrs/suspend-react\n */\nfunction query(key, fn, preload = false) {\n const stringKey = hashKey(key);\n if (browserCache[stringKey]) {\n const entry = browserCache[stringKey];\n if (preload)\n return undefined;\n if (entry.error)\n throw entry.error;\n if (entry.response)\n return entry.response;\n if (!preload)\n throw entry.promise;\n }\n const entry = {\n promise: fn()\n .then((response) => (entry.response = response))\n .catch((error) => (entry.error = error)),\n };\n browserCache[stringKey] = entry;\n if (!preload)\n throw entry.promise;\n return undefined;\n}\nexport const suspendFunction = (key, fn) => query(key, fn);\nexport const preloadFunction = (key, fn) => query(key, fn, true);\n","import { parseJSON } from '../../utilities/parse.js';\nimport { log } from '../../utilities/log/index.js';\nexport class ResponseSync extends Response {\n bodyUsed = true;\n #text;\n #json;\n url;\n constructor(init) {\n super(init[0], init[1]);\n this.#text = init[0];\n this.url = init[2];\n }\n // @ts-expect-error Changing inherited types\n text() {\n return this.#text;\n }\n json() {\n try {\n return (this.#json ??= parseJSON(this.#text));\n }\n catch (e) {\n if (!this.ok) {\n throw new Error(`Request to ${this.url} failed with ${this.status} and the response body is not parseable.\\nMake sure to handle the error state when using fetchSync.`);\n }\n else\n throw e;\n }\n }\n /**\n * @deprecated Access response properties at the top level instead.\n */\n get response() {\n if (__HYDROGEN_DEV__) {\n log.warn(`Property 'response' is deprecated from the result of 'fetchSync'.` +\n ` Access response properties at the top level instead.`);\n }\n return this;\n }\n static async toSerializable(response) {\n return [\n await response.text(),\n {\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n },\n response.url,\n ];\n }\n}\n","import { suspendFunction, preloadFunction } from '../../../utilities/suspense.js';\nimport { ResponseSync } from '../ResponseSync.js';\n/**\n * Fetch a URL for use in a client component Suspense boundary.\n */\nexport function fetchSync(url, options) {\n const responseSyncInit = suspendFunction([url, options], async () => {\n const response = await globalThis.fetch(new URL(url, window.location.origin), options);\n return ResponseSync.toSerializable(response);\n });\n return new ResponseSync(responseSyncInit);\n}\n/**\n * Preload a URL for use in a client component Suspense boundary.\n * Useful for placing higher in the tree to avoid waterfalls.\n */\nexport function preload(url, options) {\n preloadFunction([url, options], async () => {\n const response = await globalThis.fetch(url, options);\n const text = await response.text();\n return [text, response];\n });\n}\n"],"names":["hashKey","queryKey","rawKeys","hash","key","STOREFRONT_API_BUYER_IP_HEADER","browserCache","query","fn","preload","stringKey","entry","response","error","suspendFunction","ResponseSync","init","__publicField","__privateAdd","_text","_json","__privateSet","__privateGet","_a","parseJSON","e","fetchSync","url","options","responseSyncInit"],"mappings":"ulBACO,SAASA,EAAQC,EAAU,CAC9B,MAAMC,EAAU,MAAM,QAAQD,CAAQ,EAAIA,EAAW,CAACA,CAAQ,EAC9D,IAAIE,EAAO,GAKX,UAAWC,KAAOF,EACVE,GAAO,OACH,OAAOA,GAAQ,SAGX,CAAC,CAACA,EAAI,MAAQ,OAAOA,EAAI,MAAS,UAClCD,GAAQC,EAAI,KACR,CAAC,CAACA,EAAI,SAAWA,EAAI,QAAQC,KAC7BF,GAAQC,EAAI,QAAQC,KAIxBF,GAAQ,KAAK,UAAUC,CAAG,EAI9BD,GAAQC,GAIpB,OAAOD,CACX,CCFA,MAAMG,EAAe,CAAA,EAMrB,SAASC,EAAMH,EAAKI,EAAIC,EAAU,GAAO,CACrC,MAAMC,EAAYV,EAAQI,CAAG,EAC7B,GAAIE,EAAaI,GAAY,CACzB,MAAMC,EAAQL,EAAaI,GAC3B,GAAID,EACA,OACJ,GAAIE,EAAM,MACN,MAAMA,EAAM,MAChB,GAAIA,EAAM,SACN,OAAOA,EAAM,SACjB,GAAI,CAACF,EACD,MAAME,EAAM,OACnB,CACD,MAAMA,EAAQ,CACV,QAASH,EAAI,EACR,KAAMI,GAAcD,EAAM,SAAWC,CAAS,EAC9C,MAAOC,GAAWF,EAAM,MAAQE,CAAM,CACnD,EAEI,GADAP,EAAaI,GAAaC,EACtB,CAACF,EACD,MAAME,EAAM,OAEpB,CACO,MAAMG,EAAkB,CAACV,EAAKI,IAAOD,EAAMH,EAAKI,CAAE,UCtDlD,MAAMO,UAAqB,QAAS,CAKvC,YAAYC,EAAM,CACd,MAAMA,EAAK,GAAIA,EAAK,EAAE,EAL1BC,EAAA,gBAAW,IACXC,EAAA,KAA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