{"version":3,"file":"ecom-headless.biFHUae1.mjs","sources":["../../src/client/constants.ts","../../src/storefront/utils/get-ecwid-window-method.ts","../../src/storefront/utils/wait-ecwid-api-loaded.ts","../../src/storefront/methods/get-store-id.ts"],"sourcesContent":["export const ERROR_MESSAGES = {\n  FETCH_API_NOT_AVAILABLE: [\n    'Cannot initialize the API client.',\n    'Please use Node 18+ or a runtime with fetch() support. ',\n    'For older Node.js versions, consider using a fetch polyfill.',\n  ].join('\\n'),\n  CONFIG_NOT_INITIALIZED: 'Error initializing Storefront API: Please call initStorefrontApi() method first.',\n  CONFIG_PUBLIC_TOKEN_REQUIRED: 'Error initializing Storefront API: publicToken is required',\n  CONFIG_STORE_ID_NOT_FOUND: 'Error initializing Storefront API: storeId not found',\n  STOREFRONT_JS_API_NOT_AVAILABLE: [\n    'Ecwid JS API not found on window object.',\n    'Ensure the Ecwid storefront script is loaded.',\n  ].join('\\n'),\n  STOREFRONT_JS_API_METHOD_NOT_AVAILABLE: (methodName: string) => [\n    `Ecwid JS API method \"${methodName}\" is not available.`,\n    'Ensure the Ecwid storefront script is loaded.',\n  ].join('\\n'),\n} as const;\n","import { ERROR_MESSAGES } from '@/client/constants';\n\ntype EcwidJsApi = NonNullable<typeof globalThis.window.Ecwid>;\n\ntype EcwidJsApiMethod = keyof EcwidJsApi;\n\nexport function getEcwidWindowMethod<K extends EcwidJsApiMethod>(methodName: K): NonNullable<EcwidJsApi[K]> {\n  const ecwidJsApi = globalThis.window?.Ecwid;\n  const methodFunction = ecwidJsApi?.[methodName];\n\n  if (ecwidJsApi === undefined) {\n    throw new Error(ERROR_MESSAGES.STOREFRONT_JS_API_NOT_AVAILABLE);\n  }\n\n  if (methodFunction === undefined) {\n    throw new Error(ERROR_MESSAGES.STOREFRONT_JS_API_METHOD_NOT_AVAILABLE(methodName));\n  }\n\n  return methodFunction;\n}\n","export async function waitEcwidApiLoaded<T>(callback: () => T): Promise<T> {\n  const invokeCallback = (\n    resolve: (value: T | PromiseLike<T>) => void,\n    reject: (reason: unknown) => void,\n  ) => {\n    try {\n      resolve(callback());\n    } catch (error) {\n      reject(error);\n    }\n  };\n\n  return new Promise((resolve, reject) => {\n    const OnAPILoaded = globalThis.window?.Ecwid?.OnAPILoaded;\n\n    if (OnAPILoaded !== undefined) {\n      OnAPILoaded.add(() => invokeCallback(resolve, reject));\n    } else {\n      invokeCallback(resolve, reject);\n    }\n  });\n}\n","import { getEcwidWindowMethod, waitEcwidApiLoaded } from '@/storefront/utils';\n\nasync function getOwnerIdInternal(): Promise<number> {\n  return waitEcwidApiLoaded(\n    () => getEcwidWindowMethod('getOwnerId')(),\n  );\n}\n\n/**\n * This method allows you to receive the store ID. Works on any opened storefront page.\n *\n * @example\n *\n * ```ts\n * import { getStoreId } from '@lightspeed/ecom-headless';\n *\n * const storeId = await getStoreId();\n * console.log(storeId);\n * // 1003\n * ```\n */\nexport const getStoreId = getOwnerIdInternal;\n\n/**\n * This method allows you to receive the store ID. Works on any opened storefront page.\n *\n * @example\n *\n * ```ts\n * import { getOwnerId } from '@lightspeed/ecom-headless';\n *\n * const storeId = await getOwnerId();\n * console.log(storeId);\n * // 1003\n * ```\n */\nexport const getOwnerId = getOwnerIdInternal;\n"],"names":["ERROR_MESSAGES","methodName","getEcwidWindowMethod","ecwidJsApi","methodFunction","waitEcwidApiLoaded","callback","invokeCallback","resolve","reject","error","OnAPILoaded","getOwnerIdInternal","getStoreId","getOwnerId"],"mappings":"AAAO,MAAMA,EAAiB,CAC5B,wBAAyB,CACvB,oCACA,0DACA,8DACF,EAAE,KAAK;AAAA,CAAI,EACX,uBAAwB,mFACxB,6BAA8B,6DAC9B,0BAA2B,uDAC3B,gCAAiC,CAC/B,2CACA,+CACF,EAAE,KAAK;AAAA,CAAI,EACX,uCAAyCC,GAAuB,CAC9D,wBAAwBA,CAAU,sBAClC,+CACF,EAAE,KAAK;AAAA,CAAI,CACb,ECXO,SAASC,EAAiDD,EAA2C,CAC1G,MAAME,EAAa,WAAW,QAAQ,MAChCC,EAAiBD,IAAaF,CAAU,EAE9C,GAAIE,IAAe,OACjB,MAAM,IAAI,MAAMH,EAAe,+BAA+B,EAGhE,GAAII,IAAmB,OACrB,MAAM,IAAI,MAAMJ,EAAe,uCAAuCC,CAAU,CAAC,EAGnF,OAAOG,CACT,CCnBA,eAAsBC,EAAsBC,EAA+B,CACzE,MAAMC,EAAiB,CACrBC,EACAC,IACG,CACH,GAAI,CACFD,EAAQF,EAAAA,CAAU,CACpB,OAASI,EAAO,CACdD,EAAOC,CAAK,CACd,CACF,EAEA,OAAO,IAAI,QAAQ,CAACF,EAASC,IAAW,CACtC,MAAME,EAAc,WAAW,QAAQ,OAAO,YAE1CA,IAAgB,OAClBA,EAAY,IAAI,IAAMJ,EAAeC,EAASC,CAAM,CAAC,EAErDF,EAAeC,EAASC,CAAM,CAElC,CAAC,CACH,CCnBA,eAAeG,GAAsC,CACnD,OAAOP,EACL,IAAMH,EAAqB,YAAY,GACzC,CACF,CAeO,MAAMW,EAAaD,EAebE,EAAaF"}