@lightspeed/ecom-headless 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/api/index.cjs +2 -1
  3. package/dist/api/index.cjs.map +1 -0
  4. package/dist/api/index.d.cts +14 -1288
  5. package/dist/api/index.d.mts +14 -1288
  6. package/dist/api/index.d.ts +14 -1288
  7. package/dist/api/index.mjs +2 -1
  8. package/dist/api/index.mjs.map +1 -0
  9. package/dist/index.cjs +2 -2
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +4 -22
  12. package/dist/index.d.mts +4 -22
  13. package/dist/index.d.ts +4 -22
  14. package/dist/index.mjs +2 -2
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/plugin-visualizer/bundle.html +1 -1
  17. package/dist/shared/ecom-headless.BTRqua6N.d.cts +475 -0
  18. package/dist/shared/ecom-headless.BTRqua6N.d.mts +475 -0
  19. package/dist/shared/ecom-headless.BTRqua6N.d.ts +475 -0
  20. package/dist/shared/ecom-headless.BaNiBjDE.d.cts +1297 -0
  21. package/dist/shared/ecom-headless.BaNiBjDE.d.mts +1297 -0
  22. package/dist/shared/ecom-headless.BaNiBjDE.d.ts +1297 -0
  23. package/dist/shared/ecom-headless.CiGkSfL9.cjs +5 -0
  24. package/dist/shared/ecom-headless.CiGkSfL9.cjs.map +1 -0
  25. package/dist/shared/ecom-headless.D2QPHn5F.d.ts +676 -0
  26. package/dist/shared/ecom-headless.biFHUae1.mjs +5 -0
  27. package/dist/shared/ecom-headless.biFHUae1.mjs.map +1 -0
  28. package/dist/shared/ecom-headless.fwEDqznC.d.mts +676 -0
  29. package/dist/shared/ecom-headless.n2b3FM61.d.cts +676 -0
  30. package/dist/storefront/index.cjs +2 -1
  31. package/dist/storefront/index.cjs.map +1 -0
  32. package/dist/storefront/index.d.cts +2 -3
  33. package/dist/storefront/index.d.mts +2 -3
  34. package/dist/storefront/index.d.ts +2 -3
  35. package/dist/storefront/index.mjs +2 -1
  36. package/dist/storefront/index.mjs.map +1 -0
  37. package/dist/types/index.cjs +2 -0
  38. package/dist/types/index.cjs.map +1 -0
  39. package/dist/types/index.d.cts +31 -0
  40. package/dist/types/index.d.mts +31 -0
  41. package/dist/types/index.d.ts +31 -0
  42. package/dist/types/index.mjs +2 -0
  43. package/dist/types/index.mjs.map +1 -0
  44. package/package.json +45 -4
@@ -0,0 +1,5 @@
1
+ const e={FETCH_API_NOT_AVAILABLE:["Cannot initialize the API client.","Please use Node 18+ or a runtime with fetch() support. ","For older Node.js versions, consider using a fetch polyfill."].join(`
2
+ `),CONFIG_NOT_INITIALIZED:"Error initializing Storefront API: Please call initStorefrontApi() method first.",CONFIG_PUBLIC_TOKEN_REQUIRED:"Error initializing Storefront API: publicToken is required",CONFIG_STORE_ID_NOT_FOUND:"Error initializing Storefront API: storeId not found",STOREFRONT_JS_API_NOT_AVAILABLE:["Ecwid JS API not found on window object.","Ensure the Ecwid storefront script is loaded."].join(`
3
+ `),STOREFRONT_JS_API_METHOD_NOT_AVAILABLE:o=>[`Ecwid JS API method "${o}" is not available.`,"Ensure the Ecwid storefront script is loaded."].join(`
4
+ `)};function d(o){const t=globalThis.window?.Ecwid,i=t?.[o];if(t===void 0)throw new Error(e.STOREFRONT_JS_API_NOT_AVAILABLE);if(i===void 0)throw new Error(e.STOREFRONT_JS_API_METHOD_NOT_AVAILABLE(o));return i}async function s(o){const t=(i,n)=>{try{i(o())}catch(r){n(r)}};return new Promise((i,n)=>{const r=globalThis.window?.Ecwid?.OnAPILoaded;r!==void 0?r.add(()=>t(i,n)):t(i,n)})}async function E(){return s(()=>d("getOwnerId")())}const A=E,I=E;export{e as E,A as a,d as b,I as g,s as w};
5
+ //# sourceMappingURL=ecom-headless.biFHUae1.mjs.map
@@ -0,0 +1 @@
1
+ {"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":"AAAa,MAAAA,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,ECXgB,SAAAC,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,CCnBsB,eAAAC,EAAsBC,EAA+B,CACzE,MAAMC,EAAiB,CACrBC,EACAC,IACG,CACH,GAAI,CACFD,EAAQF,EAAS,CAAC,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,EACzC,CAAA,CACF,CAea,MAAAW,EAAaD,EAebE,EAAaF"}
@@ -0,0 +1,676 @@
1
+ import { E as EcwidApiPromise, p as CartData, y as CustomerCookieConsentType, u as JsApiPage, t as CustomerData, T as TrackingConsent, x as VisitorLocation, c as CartGetCallback, b as AddProductParameter, d as CartAddProductCallback, e as CartRemoveProductCallback, f as CartClearCallback, g as CartCalculateTotalCallback, h as CartGoToCheckoutCallback, q as CustomerGetCallback, r as CustomerSignOutCallback } from './ecom-headless.BTRqua6N.mjs';
2
+
3
+ declare const EcwidWidgetValues: {
4
+ /** Minicart widget */
5
+ readonly MINICART: "Minicart";
6
+ /** Search widget */
7
+ readonly SEARCH_PANEL: "SearchPanel";
8
+ /** Main storefront widget, contains full Ecwid store */
9
+ readonly PRODUCT_BROWSER: "ProductBrowser";
10
+ /** Horizontal categories menu widget */
11
+ readonly CATEGORIES: "Categories";
12
+ /** Widget with an embedded product page */
13
+ readonly PRODUCT: "Product";
14
+ };
15
+ type EcwidWidgetType = typeof EcwidWidgetValues[keyof typeof EcwidWidgetValues];
16
+
17
+ /**
18
+ * This event allows tracking any cart changes excluding the payment method selection.
19
+ * Its callback function with the cart argument contains details about the cart after the change event.
20
+ *
21
+ * OnCartChanged event triggers when:
22
+ * - Cart is initialized, synced, or cleared
23
+ * - Product has been added, updated (increased quantity, changed selected options), or removed from the cart
24
+ * - Discount coupon or discount is applied or removed
25
+ * - Shipping address is added or updated
26
+ * - Shipping method is selected or changed
27
+ *
28
+ * @example
29
+ *
30
+ * ```ts
31
+ * import { OnCartChanged } from '@lightspeed/ecom-headless';
32
+ *
33
+ * OnCartChanged.add((cart) => {
34
+ * console.log(`Cart ID: ${cart.cartId}`);
35
+ * console.log(`Items in cart: ${cart.productsQuantity}`);
36
+ * console.log(`Cart total: ${cart.total}`);
37
+ * });
38
+ * ```
39
+ */
40
+ declare const OnCartChanged: EcwidApiPromise<CartData>;
41
+
42
+ /**
43
+ * This method allows you to catch any changes to the consent value.
44
+ *
45
+ * @example
46
+ *
47
+ * ```ts
48
+ * import { OnConsentChanged, CustomerCookieConsent } from '@lightspeed/ecom-headless';
49
+ *
50
+ * OnConsentChanged.add((consent) => {
51
+ * console.log("consent changed to " + consent);
52
+ * });
53
+ * setTrackingConsent(CustomerCookieConsent.DECLINED);
54
+ * // "consent changed to DECLINED"
55
+ * ```
56
+ */
57
+ declare const OnConsentChanged: EcwidApiPromise<CustomerCookieConsentType>;
58
+
59
+ /**
60
+ * This event triggers instantly when the page DOM is loaded.
61
+ *
62
+ * This method doesn't wait for the Ecwid product browser and its contents to fully load
63
+ * and therefore doesn't return any details about the opened page.
64
+ *
65
+ * @example
66
+ *
67
+ * ```ts
68
+ * import { OnPageLoad } from '@lightspeed/ecom-headless';
69
+ *
70
+ * OnPageLoad.add(() => {
71
+ * console.log("Page DOM has just loaded");
72
+ * });
73
+ * ```
74
+ */
75
+ declare const OnPageLoad: EcwidApiPromise<void>;
76
+
77
+ /**
78
+ * This method allows you to track the full page load –
79
+ * a moment when both DOM and product browser are loaded and ready for customization.
80
+ *
81
+ * It contains a callback function with page argument containing information about a loaded page.
82
+ *
83
+ * @example
84
+ *
85
+ * ```ts
86
+ * import { OnPageLoaded, JsApiPageValues } from '@lightspeed/ecom-headless';
87
+ *
88
+ * OnPageLoaded.add((page) => {
89
+ * if (page.type === JsApiPageValues.PRODUCT) {
90
+ * console.log(page);
91
+ * }
92
+ * });
93
+ * // {
94
+ * // "type":"PRODUCT",
95
+ * // "categoryId":0,
96
+ * // "hasPrevious":false,
97
+ * // "mainCategoryId":0,
98
+ * // "name":"Desk Black 101x50x76.5 cm Engineered Wood",
99
+ * // "nameTranslated":{
100
+ * // "cs":"",
101
+ * // "en":"Desk Black 101x50x76.5 cm Engineered Wood"
102
+ * // },
103
+ * // "productId":561386461
104
+ * // }
105
+ * ```
106
+ */
107
+ declare const OnPageLoaded: EcwidApiPromise<JsApiPage>;
108
+
109
+ /**
110
+ * This method allows tracking and preventing page switches on the storefront.
111
+ * It is triggered when a user is about to switch a page (a new page is not yet loaded).
112
+ *
113
+ * The method works synchronously and contains the page argument in its callback function.
114
+ * Use it to identify the page where users go and prevent page loading by returning a false value.
115
+ *
116
+ * @example
117
+ *
118
+ * ```ts
119
+ * import { OnPageSwitch, JsApiPageValues } from '@lightspeed/ecom-headless';
120
+ *
121
+ * OnPageSwitch.add((page) => {
122
+ * if (page.type === JsApiPageValues.PRODUCT) {
123
+ * console.log(page);
124
+ * }
125
+ * });
126
+ * // {
127
+ * // "type":"PRODUCT",
128
+ * // "categoryId":0,
129
+ * // "hasPrevious":false,
130
+ * // "mainCategoryId":0,
131
+ * // "name":"Desk Black 101x50x76.5 cm Engineered Wood",
132
+ * // "nameTranslated":{
133
+ * // "cs":"",
134
+ * // "en":"Desk Black 101x50x76.5 cm Engineered Wood"
135
+ * // },
136
+ * // "productId":561386461
137
+ * // }
138
+ * ```
139
+ */
140
+ declare const OnPageSwitch: EcwidApiPromise<JsApiPage>;
141
+
142
+ /**
143
+ * This method allows you to track a moment when customers log in and out on the storefront.
144
+ * It contains a callback function with customer argument when a customer logs in, and null if a customer has logged out.
145
+ *
146
+ * @example
147
+ *
148
+ * ```ts
149
+ * import { OnSetProfile } from '@lightspeed/ecom-headless';
150
+ *
151
+ * OnSetProfile.add((customer) => {
152
+ * console.log(customer.email);
153
+ * // "ec.apps@lightspeedhq.com"
154
+ * });
155
+ * ```
156
+ */
157
+ declare const OnSetProfile: EcwidApiPromise<CustomerData | null>;
158
+
159
+ /**
160
+ * This method allows you to get store currency settings on the storefront.
161
+ * It is useful if you need to add a widget that displays some price to customers.
162
+ *
163
+ * It accepts a numeric price as an argument and responds with a formatted price
164
+ * using store settings: currency symbol, and delimiter symbol and precision.
165
+ *
166
+ * @example
167
+ *
168
+ * ```ts
169
+ * import { formatCurrency } from '@lightspeed/ecom-headless';
170
+ *
171
+ * const formattedPrice = await formatCurrency(12.99);
172
+ * console.log(formattedPrice);
173
+ * // "$12.99"
174
+ * ```
175
+ */
176
+ declare function formatCurrency(amount: number): Promise<string>;
177
+
178
+ /**
179
+ * This method accepts an app `client_id` as an argument and responds with a
180
+ * "public config" for the app. This config is the data saved in App Storage
181
+ * as a public key.
182
+ *
183
+ * Read more about setting up App Storage:
184
+ * {@link https://docs.ecwid.com/launch-apps/native-and-external-apps/build-user-settings-page-for-ecwid-admin/manage-personal-user-settings-storage}.
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * import { getAppPublicConfig } from '@lightspeed/ecom-headless';
189
+ *
190
+ * const publicConfig = await getAppPublicConfig('client_id');
191
+ * console.log(JSON.parse(publicConfig));
192
+ * // {"key": "public","value": "{'color':'red','text':'Email button','border-radius':'3px'}"}
193
+ * ```
194
+ */
195
+ declare function getAppPublicConfig(clientId: string): Promise<string>;
196
+
197
+ /**
198
+ * This method accepts app client_id as an argument and responds with a public access token for the app.
199
+ * Public tokens are safe to use on the storefront, as they won't be able to reveal any private store data.
200
+ *
201
+ * @example
202
+ *
203
+ * ```ts
204
+ * import { getAppPublicToken } from '@lightspeed/ecom-headless';
205
+ *
206
+ * const publicToken = await getAppPublicToken('client_id');
207
+ * console.log(publicToken);
208
+ * // "public_qKsUqKkNXzcj9DejwMUqEkY2q2E6BXM9"
209
+ * ```
210
+ */
211
+ declare function getAppPublicToken(clientId: string): Promise<string>;
212
+
213
+ /**
214
+ * This method responds with a list of widgets currently loaded on the website.
215
+ *
216
+ * @example
217
+ *
218
+ * ```ts
219
+ * import { getInitializedWidgets } from '@lightspeed/ecom-headless';
220
+ * const widgets = await getInitializedWidgets();
221
+ * console.log(widgets);
222
+ * // ["Minicart", "SearchPanel", "ProductBrowser"]
223
+ * ```
224
+ */
225
+ declare function getInitializedWidgets(): Promise<EcwidWidgetType[]>;
226
+
227
+ declare function getOwnerIdInternal(): Promise<number>;
228
+ /**
229
+ * This method allows you to receive the store ID. Works on any opened storefront page.
230
+ *
231
+ * @example
232
+ *
233
+ * ```ts
234
+ * import { getStoreId } from '@lightspeed/ecom-headless';
235
+ *
236
+ * const storeId = await getStoreId();
237
+ * console.log(storeId);
238
+ * // 1003
239
+ * ```
240
+ */
241
+ declare const getStoreId: typeof getOwnerIdInternal;
242
+ /**
243
+ * This method allows you to receive the store ID. Works on any opened storefront page.
244
+ *
245
+ * @example
246
+ *
247
+ * ```ts
248
+ * import { getOwnerId } from '@lightspeed/ecom-headless';
249
+ *
250
+ * const storeId = await getOwnerId();
251
+ * console.log(storeId);
252
+ * // 1003
253
+ * ```
254
+ */
255
+ declare const getOwnerId: typeof getOwnerIdInternal;
256
+
257
+ /**
258
+ * This method responds with the current storefront language in ISO 639-1 language code.
259
+ * Use it to dynamically translate custom content on the page.
260
+ *
261
+ * @example
262
+ *
263
+ * ```ts
264
+ * import { getStorefrontLang } from '@lightspeed/ecom-headless';
265
+ *
266
+ * const lang = await getStorefrontLang();
267
+ * console.log(lang);
268
+ * // "en"
269
+ * ```
270
+ */
271
+ declare function getStorefrontLang(): Promise<string>;
272
+
273
+ /**
274
+ * This method receives the customer's answer to the cookie consent banner.
275
+ * Use it to define what cookies your application can collect.
276
+ *
277
+ * If the cookie consent value is overridden by the JS method or config,
278
+ * getTrackingConsent() returns the new value added by JS method/config.
279
+ *
280
+ * @example
281
+ *
282
+ * ```ts
283
+ * import { getTrackingConsent } from '@lightspeed/ecom-headless';
284
+ *
285
+ * const trackingConsent = await getTrackingConsent();
286
+ * console.log(trackingConsent);
287
+ * // { userResponse: "ACCEPTED", askConsent: true }
288
+ * ```
289
+ */
290
+ declare function getTrackingConsent(): Promise<TrackingConsent>;
291
+
292
+ /**
293
+ * This method gets the visitor's location based on their shipping or billing address (when entered), or IP.
294
+ * The call works even for signed-out customers.
295
+ *
296
+ * @example
297
+ *
298
+ * ```ts
299
+ * import { getVisitorLocation } from '@lightspeed/ecom-headless';
300
+ *
301
+ * const location = await getVisitorLocation();
302
+ * console.log(location);
303
+ * // { countryCode: "US", stateCode: "NE", source: "IP_ADDRESS" }
304
+ * ```
305
+ */
306
+ declare function getVisitorLocation(): Promise<VisitorLocation>;
307
+
308
+ /**
309
+ * This method is useful for public applications developed before 2024.
310
+ * It helps apps to adapt their design by detecting the old storefront version.
311
+ *
312
+ * All stores created in 2024 and later are using the latest storefront without the ability to switch the version.
313
+ *
314
+ * @example
315
+ *
316
+ * ```ts
317
+ * import { isStorefrontV3 } from '@lightspeed/ecom-headless';
318
+ *
319
+ * const isStorefrontV3 = await isStorefrontV3();
320
+ * console.log(isStorefrontV3);
321
+ * // true
322
+ * ```
323
+ */
324
+ declare function isStorefrontV3(): Promise<boolean>;
325
+
326
+ /**
327
+ * This method allows you to open a specific page on the storefront. The function accepts page slugs and additional parameters in its arguments.
328
+ *
329
+ * For example, you can use these redirects in different promo activities:
330
+ * - Create a popup with a sale product and redirect customers to this product on click.
331
+ * - Offer customers to log in to receive some bonus.
332
+ * - Redirect customers to the search page with pre-configured terms showing promo products.
333
+ *
334
+ * @example
335
+ *
336
+ * ```ts
337
+ * import { openPage } from '@lightspeed/ecom-headless';
338
+ *
339
+ * // Redirect customers to the cart page
340
+ * openPage('cart');
341
+ *
342
+ * // Open search page with shoes of one brand
343
+ * openPage('search', {
344
+ * keyword: 'shoes',
345
+ * attribute_Brand: 'Nike',
346
+ * inventory: 'instock'
347
+ * });
348
+ * ```
349
+ *
350
+ * @see Full list of available pages: https://docs.ecwid.com/storefronts/open-page-on-the-storefront/overview-of-open-page-options#full-list-of-available-pages
351
+ *
352
+ * Learn more about pages that can be opened with additional params:
353
+ *
354
+ * {@link https://docs.ecwid.com/storefronts/open-page-on-the-storefront/open-product-pages-with-params Open product pages with params} |
355
+ * {@link https://docs.ecwid.com/storefronts/open-page-on-the-storefront/open-category-pages-with-params Open category pages with params} |
356
+ * {@link https://docs.ecwid.com/storefronts/open-page-on-the-storefront/open-search-page-with-params Open search page with params} |
357
+ * {@link https://docs.ecwid.com/storefronts/open-page-on-the-storefront/open-account-pages-with-params Open account pages with params}
358
+ */
359
+ declare function openPage(page: string, options?: Record<string, unknown>): Promise<void>;
360
+
361
+ /**
362
+ * This method accepts an argument matching one of the following values:
363
+ *
364
+ * "UNDEFINED": Customer hasn't given their consent yet.
365
+ *
366
+ * "ACCEPTED": Collect all types of cookies.
367
+ *
368
+ * "DECLINED": Collect only essential cookies.
369
+ *
370
+ * "ANALYTICS_ONLY": Collect essential and analytics cookies only.
371
+ *
372
+ * "PERSONALIZATION_ONLY": Collect essential and personalization cookies.
373
+ *
374
+ * @example
375
+ *
376
+ * ```ts
377
+ * import { setTrackingConsent, getTrackingConsent, CustomerCookieConsentValues } from '@lightspeed/ecom-headless';
378
+ *
379
+ * await setTrackingConsent(CustomerCookieConsentValues.DECLINED);
380
+ * const trackingConsent = await getTrackingConsent();
381
+ * console.log(trackingConsent);
382
+ * // { userResponse: "DECLINED", askConsent: false }
383
+ * ```
384
+ */
385
+ declare function setTrackingConsent(cookieConsent: CustomerCookieConsentType): Promise<void>;
386
+
387
+ /**
388
+ * This method allows you to receive full information about the current shopping cart.
389
+ * The response is available in the cart callback.
390
+ *
391
+ * @example
392
+ *
393
+ * ```ts
394
+ * import { Cart } from '@lightspeed/ecom-headless';
395
+ *
396
+ * Cart.get((cart) => {
397
+ * console.log(`Cart has ${cart.productsQuantity} products`);
398
+ * console.log(`Cart ID: ${cart.cartId}`);
399
+ * cart.items.forEach(item => {
400
+ * console.log(`${item.product.name} - Quantity: ${item.quantity}`);
401
+ * });
402
+ * });
403
+ * ```
404
+ */
405
+ declare function get$1(callback?: CartGetCallback): Promise<void>;
406
+
407
+ /**
408
+ * This method allows you to add a new product position to the shopping cart.
409
+ * It accepts either a product ID or a product object with extended details including
410
+ * product ID, quantity, selected options, or subscription product settings.
411
+ *
412
+ * When you use this method, it first checks the product by specified ID for stock and variations.
413
+ * If the selected options match one of the variations, Ecwid will check its stock first.
414
+ * If you don't have enough stock to add a product, Ecwid adds the available quantity.
415
+ * If the product is out of stock, nothing is added to the shopping cart.
416
+ *
417
+ * @example
418
+ *
419
+ * ```ts
420
+ * import { Cart } from '@lightspeed/ecom-headless';
421
+ *
422
+ * // Add product by ID with default quantity
423
+ * Cart.addProduct(10, (success, product, cart) => {
424
+ * if (success) {
425
+ * console.log('Product added successfully');
426
+ * }
427
+ * });
428
+ *
429
+ * // Add product with specific options and quantity
430
+ * Cart.addProduct({
431
+ * id: 10,
432
+ * quantity: 3,
433
+ * options: {
434
+ * "Size": "L"
435
+ * }
436
+ * }, (success, product, cart, error) => {
437
+ * if (success) {
438
+ * console.log(`Added ${product.quantity} items to cart`);
439
+ * } else {
440
+ * console.error('Failed to add product:', error);
441
+ * }
442
+ * });
443
+ *
444
+ * // Add subscription product
445
+ * Cart.addProduct({
446
+ * id: 15,
447
+ * quantity: 1,
448
+ * recurringChargeSettings: {
449
+ * recurringInterval: "MONTH",
450
+ * recurringIntervalCount: 1,
451
+ * }
452
+ * });
453
+ * ```
454
+ */
455
+ declare function addProduct(product: AddProductParameter, callback?: CartAddProductCallback): Promise<void>;
456
+
457
+ /**
458
+ * This method removes product position from the shopping cart entirely.
459
+ * The specified product will be removed completely even if its quantity is greater than zero.
460
+ *
461
+ * This method completely removes the product from the cart. If you want to decrease its quantity,
462
+ * use Cart.get() to save product details, then remove the product with Cart.removeProduct()
463
+ * and add it back with all the same details except for the decreased quantity with Cart.addProduct().
464
+ *
465
+ * To remove a product position from the cart, first, you need to get an index with the Cart.get() method.
466
+ * Position of the product in the items array is the index. For example, if you have two different
467
+ * products added to the cart, the first product has an index of 0, and the second has an index of 1.
468
+ *
469
+ * @example
470
+ *
471
+ * ```ts
472
+ * import { Cart } from '@lightspeed/ecom-headless';
473
+ *
474
+ * // Remove the first product from cart
475
+ * Cart.removeProduct(0, (success, itemsRemovedQuantity, product, cart, error) => {
476
+ * if (success) {
477
+ * console.log(`Removed ${itemsRemovedQuantity} items from cart`);
478
+ * console.log(`Product removed: ${product.name}`);
479
+ * } else {
480
+ * console.error('Failed to remove product:', error);
481
+ * }
482
+ * });
483
+ *
484
+ * // Remove product without callback
485
+ * Cart.removeProduct(1);
486
+ * ```
487
+ */
488
+ declare function removeProduct(index: number, callback?: CartRemoveProductCallback): Promise<void>;
489
+
490
+ /**
491
+ * This method works in the same way as Cart.removeProduct(), but allows you to remove
492
+ * multiple items from the cart at once by passing an array of indices.
493
+ *
494
+ * Each index represents the position of a product in the cart's items array.
495
+ * All specified products will be removed completely even if their quantity is greater than zero.
496
+ *
497
+ * @example
498
+ *
499
+ * ```ts
500
+ * import { Cart } from '@lightspeed/ecom-headless';
501
+ *
502
+ * // Remove first and second products from cart
503
+ * Cart.removeProducts([0, 1], (success, itemsRemovedQuantity, product, cart, error) => {
504
+ * if (success) {
505
+ * console.log(`Removed ${itemsRemovedQuantity} total items from cart`);
506
+ * } else {
507
+ * console.error('Failed to remove products:', error);
508
+ * }
509
+ * });
510
+ *
511
+ * // Remove multiple products without callback
512
+ * Cart.removeProducts([0, 2, 3]);
513
+ * ```
514
+ */
515
+ declare function removeProducts(indices: number[], callback?: CartRemoveProductCallback): Promise<void>;
516
+
517
+ /**
518
+ * This method allows you to clear all details from the shopping cart.
519
+ * If the method clears the cart successfully, you receive true in the success argument.
520
+ *
521
+ * @example
522
+ *
523
+ * ```ts
524
+ * import { Cart } from '@lightspeed/ecom-headless';
525
+ *
526
+ * Cart.clear((success, error) => {
527
+ * if (success) {
528
+ * console.log("Cart was cleared");
529
+ * } else {
530
+ * console.log("Cart clear failed. Error message: " + error);
531
+ * }
532
+ * });
533
+ *
534
+ * // Clear without callback
535
+ * Cart.clear();
536
+ * ```
537
+ */
538
+ declare function clear(callback?: CartClearCallback): Promise<void>;
539
+
540
+ /**
541
+ * This method calculates the current cart asynchronously and passes the result as an order
542
+ * callback argument with a snapshot of the generated order with essential details.
543
+ *
544
+ * The order object includes subtotals, taxes, discounts, shipping costs, and a full cart snapshot.
545
+ *
546
+ * @example
547
+ *
548
+ * ```ts
549
+ * import { Cart } from '@lightspeed/ecom-headless';
550
+ *
551
+ * Cart.calculateTotal((order) => {
552
+ * console.log(`Order total: ${order.total}`);
553
+ * console.log(`Subtotal: ${order.subtotal}`);
554
+ * console.log(`Tax: ${order.tax}`);
555
+ * console.log(`Shipping: ${order.shipping}`);
556
+ * console.log(`Items in cart: ${order.cart.productsQuantity}`);
557
+ *
558
+ * // Access individual cart items
559
+ * order.cart.items.forEach(item => {
560
+ * console.log(`${item.product.name} - Qty: ${item.quantity}`);
561
+ * });
562
+ * });
563
+ * ```
564
+ */
565
+ declare function calculateTotal(callback?: CartCalculateTotalCallback): Promise<void>;
566
+
567
+ /**
568
+ * This method checks whether you can send customers to the first step of the checkout called the shopping cart.
569
+ *
570
+ * @example
571
+ *
572
+ * ```ts
573
+ * import { Cart } from '@lightspeed/ecom-headless';
574
+ *
575
+ * const canGoToCheckout = await Cart.canGotoCheckout();
576
+ *
577
+ * if (canGoToCheckout) {
578
+ * Cart.gotoCheckout();
579
+ * }
580
+ * ```
581
+ */
582
+ declare function canGotoCheckout(): Promise<boolean>;
583
+
584
+ /**
585
+ * This method sends a customer to the first or second checkout step.
586
+ *
587
+ * This method works differently depending on the Ecwid admin > Settings > Legal > Terms & Conditions toggle
588
+ * and whether the customer has already left an email in the shopping cart:
589
+ *
590
+ * - No email: the customer is sent to the shopping cart page.
591
+ * - Email + toggle disabled: the customer is sent to the second checkout page (address details)
592
+ * - Email + toggle disabled + no shipping: the customer is sent to the payment page.
593
+ *
594
+ * @example
595
+ *
596
+ * ```ts
597
+ * import { Cart } from '@lightspeed/ecom-headless';
598
+ *
599
+ * Cart.gotoCheckout(() => {
600
+ * console.log("Checkout process started");
601
+ * });
602
+ * ```
603
+ */
604
+ declare function gotoCheckout(callback?: CartGoToCheckoutCallback): Promise<void>;
605
+
606
+ declare const index$1_addProduct: typeof addProduct;
607
+ declare const index$1_calculateTotal: typeof calculateTotal;
608
+ declare const index$1_canGotoCheckout: typeof canGotoCheckout;
609
+ declare const index$1_clear: typeof clear;
610
+ declare const index$1_gotoCheckout: typeof gotoCheckout;
611
+ declare const index$1_removeProduct: typeof removeProduct;
612
+ declare const index$1_removeProducts: typeof removeProducts;
613
+ declare namespace index$1 {
614
+ export {
615
+ index$1_addProduct as addProduct,
616
+ index$1_calculateTotal as calculateTotal,
617
+ index$1_canGotoCheckout as canGotoCheckout,
618
+ index$1_clear as clear,
619
+ get$1 as get,
620
+ index$1_gotoCheckout as gotoCheckout,
621
+ index$1_removeProduct as removeProduct,
622
+ index$1_removeProducts as removeProducts,
623
+ };
624
+ }
625
+
626
+ /**
627
+ * This method receives all data on the customer currently logged in to the store.
628
+ * If no customer is logged in, the method returns null.
629
+ *
630
+ * @example
631
+ *
632
+ * ```ts
633
+ * import { Customer } from '@lightspeed/ecom-headless';
634
+ *
635
+ * Customer.get((customer) => {
636
+ * if (customer === null) {
637
+ * console.log('No customer is logged in');
638
+ * } else {
639
+ * console.log(customer.email);
640
+ * }
641
+ * });
642
+ * ```
643
+ */
644
+ declare function get(callback?: CustomerGetCallback): Promise<void>;
645
+
646
+ /**
647
+ * This method signs out customer from their account.
648
+ *
649
+ * Error message has value only if success is false.
650
+ *
651
+ * @example
652
+ *
653
+ * ```ts
654
+ * import { Customer } from '@lightspeed/ecom-headless';
655
+ *
656
+ * Customer.signOut((success, error) => {
657
+ * if (success === true) {
658
+ * console.log('Customer signed out');
659
+ * } else {
660
+ * console.log('Signout failed. Error message: ' + error);
661
+ * }
662
+ * });
663
+ * ```
664
+ */
665
+ declare function signOut(callback?: CustomerSignOutCallback): Promise<void>;
666
+
667
+ declare const index_get: typeof get;
668
+ declare const index_signOut: typeof signOut;
669
+ declare namespace index {
670
+ export {
671
+ index_get as get,
672
+ index_signOut as signOut,
673
+ };
674
+ }
675
+
676
+ export { EcwidWidgetValues as E, OnCartChanged as O, getAppPublicToken as a, getInitializedWidgets as b, getOwnerId as c, getStoreId as d, getStorefrontLang as e, formatCurrency as f, getAppPublicConfig as g, getTrackingConsent as h, getVisitorLocation as i, isStorefrontV3 as j, OnConsentChanged as k, OnPageLoad as l, OnPageLoaded as m, OnPageSwitch as n, openPage as o, OnSetProfile as p, index$1 as q, index as r, setTrackingConsent as s };