@liquidcommerce/elements-sdk 2.6.0-beta.9 → 2.6.0-beta.90

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 (225) hide show
  1. package/README.md +84 -2520
  2. package/dist/index.checkout.esm.js +16940 -0
  3. package/dist/index.esm.js +24189 -20939
  4. package/dist/ssr-stub.checkout.esm.js +18 -0
  5. package/dist/ssr-stub.esm.js +270 -0
  6. package/dist/types/auto-initialize/checkout.d.ts +2 -0
  7. package/dist/types/auto-initialize/shared-utils.d.ts +50 -0
  8. package/dist/types/{elements-base-client.d.ts → clients/base.d.ts} +15 -2
  9. package/dist/types/clients/builder.d.ts +3 -0
  10. package/dist/types/clients/checkout.d.ts +6 -0
  11. package/dist/types/{elements-client-helper.d.ts → clients/helpers.d.ts} +2 -1
  12. package/dist/types/clients/main.d.ts +3 -0
  13. package/dist/types/constants/core.constant.d.ts +2 -6
  14. package/dist/types/core/api/api-client.service.d.ts +20 -18
  15. package/dist/types/core/api/api-result.d.ts +19 -0
  16. package/dist/types/core/api/auth-client.service.d.ts +37 -13
  17. package/dist/types/core/api/http-client.service.d.ts +0 -8
  18. package/dist/types/core/base-component.service.d.ts +2 -1
  19. package/dist/types/core/client/actions/base-action.service.d.ts +22 -0
  20. package/dist/types/core/client/actions/client-address-action.service.d.ts +18 -0
  21. package/dist/types/core/client/actions/client-cart-action.service.d.ts +38 -0
  22. package/dist/types/core/client/actions/client-checkout-action.service.d.ts +69 -0
  23. package/dist/types/core/client/actions/client-product-action.service.d.ts +15 -0
  24. package/dist/types/core/client/client-action.service.d.ts +6 -74
  25. package/dist/types/core/client/client-config.service.d.ts +8 -5
  26. package/dist/types/core/google-tag-manager.service.d.ts +2 -1
  27. package/dist/types/core/logger/logger.service.d.ts +1 -1
  28. package/dist/types/core/pubsub/interfaces/address.interface.d.ts +3 -0
  29. package/dist/types/core/pubsub/interfaces/cart.interface.d.ts +1 -1
  30. package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +36 -51
  31. package/dist/types/core/pubsub/interfaces/core.interface.d.ts +11 -6
  32. package/dist/types/core/pubsub/pubsub.service.d.ts +1 -2
  33. package/dist/types/core/singleton-manager.service.d.ts +12 -8
  34. package/dist/types/core/store/interfaces/cart.interface.d.ts +2 -3
  35. package/dist/types/core/store/interfaces/checkout.interface.d.ts +18 -108
  36. package/dist/types/core/store/interfaces/core.interface.d.ts +12 -2
  37. package/dist/types/core/store/interfaces/metadata.interface.d.ts +11 -0
  38. package/dist/types/core/store/interfaces/product-list.interface.d.ts +30 -0
  39. package/dist/types/core/store/interfaces/product.interface.d.ts +1 -0
  40. package/dist/types/core/store/store.constant.d.ts +5 -0
  41. package/dist/types/core/store/store.service.d.ts +1 -0
  42. package/dist/types/core/telemetry/telemetry.service.d.ts +1 -0
  43. package/dist/types/enums/core.enum.d.ts +39 -1
  44. package/dist/types/enums/index.d.ts +0 -1
  45. package/dist/types/index.checkout.d.ts +8 -0
  46. package/dist/types/index.checkout.umd.d.ts +4 -0
  47. package/dist/types/index.d.ts +8 -3
  48. package/dist/types/interfaces/api/cart.interface.d.ts +12 -7
  49. package/dist/types/interfaces/api/checkout.interface.d.ts +239 -0
  50. package/dist/types/interfaces/api/index.d.ts +5 -0
  51. package/dist/types/interfaces/api/product-list.interface.d.ts +39 -0
  52. package/dist/types/interfaces/api/product.interface.d.ts +10 -4
  53. package/dist/types/interfaces/client.interface.d.ts +72 -0
  54. package/dist/types/interfaces/component.interface.d.ts +7 -0
  55. package/dist/types/interfaces/config.interface.d.ts +40 -0
  56. package/dist/types/interfaces/configs/address.interface.d.ts +1 -1
  57. package/dist/types/interfaces/configs/cart.interface.d.ts +1 -1
  58. package/dist/types/interfaces/configs/checkout.interface.d.ts +2 -1
  59. package/dist/types/interfaces/configs/global.interface.d.ts +5 -3
  60. package/dist/types/interfaces/configs/index.d.ts +1 -0
  61. package/dist/types/interfaces/configs/product-list.interface.d.ts +49 -0
  62. package/dist/types/interfaces/configs/product.interface.d.ts +3 -1
  63. package/dist/types/interfaces/injection.interface.d.ts +49 -0
  64. package/dist/types/modules/address/address.command.d.ts +2 -1
  65. package/dist/types/modules/address/styles/register-styles.d.ts +1 -0
  66. package/dist/types/modules/cart/cart.commands.d.ts +4 -4
  67. package/dist/types/modules/cart/styles/register-styles.d.ts +1 -0
  68. package/dist/types/modules/checkout/checkout.commands.d.ts +26 -10
  69. package/dist/types/modules/checkout/checkout.component.d.ts +2 -0
  70. package/dist/types/modules/checkout/components/checkout-billing.component.d.ts +2 -2
  71. package/dist/types/modules/checkout/components/checkout-completed.component.d.ts +3 -0
  72. package/dist/types/modules/checkout/components/checkout-header.component.d.ts +1 -0
  73. package/dist/types/modules/checkout/components/checkout-item-quantity.component.d.ts +3 -0
  74. package/dist/types/modules/checkout/components/checkout-items.component.d.ts +4 -3
  75. package/dist/types/modules/checkout/components/checkout-payment.component.d.ts +1 -1
  76. package/dist/types/modules/checkout/components/checkout-presale-countdown.component.d.ts +14 -1
  77. package/dist/types/modules/checkout/components/checkout-presale-expired.component.d.ts +7 -1
  78. package/dist/types/modules/checkout/components/checkout-stripe-form.component.d.ts +2 -1
  79. package/dist/types/modules/checkout/components/checkout-tips.component.d.ts +2 -2
  80. package/dist/types/modules/checkout/components/promo-pc-gc.component.d.ts +0 -2
  81. package/dist/types/modules/checkout/constant.d.ts +3 -0
  82. package/dist/types/modules/checkout/styles/register-styles.d.ts +1 -0
  83. package/dist/types/modules/product/components/product-add-to-cart-section.component.d.ts +1 -0
  84. package/dist/types/modules/product/components/product-description.component.d.ts +1 -0
  85. package/dist/types/modules/product/components/product-image-carousel.component.d.ts +3 -0
  86. package/dist/types/modules/product/components/product-options.component.d.ts +2 -1
  87. package/dist/types/modules/product/components/product-retailers-carousel.component.d.ts +3 -0
  88. package/dist/types/modules/product/components/product-retailers-popup-list.component.d.ts +5 -2
  89. package/dist/types/modules/product/product.commands.d.ts +3 -3
  90. package/dist/types/modules/product/styles/register-styles.d.ts +1 -0
  91. package/dist/types/modules/product-list/components/card-components/index.d.ts +5 -0
  92. package/dist/types/modules/product-list/components/card-components/product-badge.d.ts +9 -0
  93. package/dist/types/modules/product-list/components/card-components/product-button.d.ts +11 -0
  94. package/dist/types/modules/product-list/components/card-components/product-price-and-personalization.d.ts +13 -0
  95. package/dist/types/modules/product-list/components/card-components/product-quantity-selector.d.ts +10 -0
  96. package/dist/types/modules/product-list/components/card-components/product-sizes-list.d.ts +13 -0
  97. package/dist/types/modules/product-list/components/filter-components/index.d.ts +7 -0
  98. package/dist/types/modules/product-list/components/filter-components/product-list-apply-filter-button.d.ts +1 -0
  99. package/dist/types/modules/product-list/components/filter-components/product-list-chip.d.ts +5 -0
  100. package/dist/types/modules/product-list/components/filter-components/product-list-filters-chips.d.ts +13 -0
  101. package/dist/types/modules/product-list/components/filter-components/product-list-fulfillment-filter.d.ts +14 -0
  102. package/dist/types/modules/product-list/components/{product-list-filters-subcomponents/product-list-price-filter.components.d.ts → filter-components/product-list-price-filter.d.ts} +1 -1
  103. package/dist/types/modules/product-list/components/filter-components/product-list-toggle-filters.d.ts +7 -0
  104. package/dist/types/modules/product-list/components/index.d.ts +6 -2
  105. package/dist/types/modules/product-list/components/product-list-card-loading.component.d.ts +3 -1
  106. package/dist/types/modules/product-list/components/product-list-card.component.d.ts +39 -31
  107. package/dist/types/modules/product-list/components/product-list-engraving.component.d.ts +12 -0
  108. package/dist/types/modules/product-list/components/product-list-filters.component.d.ts +55 -36
  109. package/dist/types/modules/product-list/components/product-list-product-engraving-lines.component.d.ts +22 -0
  110. package/dist/types/modules/product-list/components/product-list-product-pre-cart.component.d.ts +50 -0
  111. package/dist/types/modules/product-list/components/product-list-search.component.d.ts +25 -0
  112. package/dist/types/modules/product-list/product-list-filter.utils.d.ts +8 -0
  113. package/dist/types/modules/product-list/product-list-query-params.utils.d.ts +3 -0
  114. package/dist/types/modules/product-list/product-list.commands.d.ts +23 -8
  115. package/dist/types/modules/product-list/product-list.component.d.ts +14 -47
  116. package/dist/types/modules/product-list/product-list.constants.d.ts +38 -0
  117. package/dist/types/modules/product-list/product-list.interface.d.ts +20 -35
  118. package/dist/types/modules/product-list/styles/product-list-card.style.d.ts +1 -0
  119. package/dist/types/modules/product-list/styles/product-list-filters.style.d.ts +1 -0
  120. package/dist/types/modules/product-list/styles/register-styles.d.ts +1 -0
  121. package/dist/types/modules/theme-provider/constants/component-groupings.d.ts +1 -0
  122. package/dist/types/modules/theme-provider/constants/css-variable-mappings.d.ts +1 -1
  123. package/dist/types/modules/theme-provider/services/style-registry.service.d.ts +16 -0
  124. package/dist/types/modules/theme-provider/services/stylesheet-generator.service.d.ts +0 -1
  125. package/dist/types/modules/theme-provider/styles/register-styles.d.ts +1 -0
  126. package/dist/types/modules/theme-provider/theme-provider.service.d.ts +2 -2
  127. package/dist/types/modules/ui-components/drawer/drawer.component.d.ts +1 -0
  128. package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +6 -1
  129. package/dist/types/modules/ui-components/engraving/engraving-view.component.d.ts +6 -1
  130. package/dist/types/modules/ui-components/input/index.d.ts +0 -1
  131. package/dist/types/modules/ui-components/input/input.component.d.ts +8 -1
  132. package/dist/types/modules/ui-components/lce-element/lce-element.component.d.ts +2 -1
  133. package/dist/types/modules/ui-components/promo-code-ticker/promo-code-ticker.component.d.ts +1 -1
  134. package/dist/types/modules/ui-components/ui.commands.d.ts +5 -1
  135. package/dist/types/ssr/stub.checkout.d.ts +6 -0
  136. package/dist/types/ssr/stub.d.ts +10 -0
  137. package/dist/types/static/icon/check.icon.d.ts +2 -0
  138. package/dist/types/static/icon/index.d.ts +1 -0
  139. package/dist/types/utils/dom-compat.d.ts +2 -0
  140. package/dist/types/utils/format.d.ts +0 -14
  141. package/dist/types/utils/product-selection.d.ts +16 -0
  142. package/dist/types/utils/product.d.ts +15 -0
  143. package/docs/v1/README.md +210 -0
  144. package/docs/v1/api/actions/address-actions.md +286 -0
  145. package/docs/v1/api/actions/cart-actions.md +357 -0
  146. package/docs/v1/api/actions/checkout-actions.md +525 -0
  147. package/docs/v1/api/actions/product-actions.md +204 -0
  148. package/docs/v1/api/client.md +517 -0
  149. package/docs/v1/api/configuration.md +532 -0
  150. package/docs/v1/api/injection-methods.md +292 -0
  151. package/docs/v1/api/typescript-types.md +419 -0
  152. package/docs/v1/api/ui-helpers.md +200 -0
  153. package/docs/v1/examples/advanced-patterns.md +199 -0
  154. package/docs/v1/examples/checkout-flow.md +90 -0
  155. package/docs/v1/examples/custom-theming.md +63 -0
  156. package/docs/v1/examples/multi-product-page.md +90 -0
  157. package/docs/v1/examples/simple-product-page.md +89 -0
  158. package/docs/v1/getting-started/concepts.md +502 -0
  159. package/docs/v1/getting-started/installation.md +328 -0
  160. package/docs/v1/getting-started/quick-start.md +405 -0
  161. package/docs/v1/guides/address-component.md +435 -0
  162. package/docs/v1/guides/best-practices.md +365 -0
  163. package/docs/v1/guides/cart-component.md +725 -0
  164. package/docs/v1/guides/checkout-component.md +670 -0
  165. package/docs/v1/guides/events.md +926 -0
  166. package/docs/v1/guides/product-component.md +731 -0
  167. package/docs/v1/guides/product-list-component.md +631 -0
  168. package/docs/v1/guides/theming.md +213 -0
  169. package/docs/v1/integration/angular.md +39 -0
  170. package/docs/v1/integration/laravel.md +41 -0
  171. package/docs/v1/integration/nextjs.md +69 -0
  172. package/docs/v1/integration/proxy-setup.md +106 -0
  173. package/docs/v1/integration/react.md +64 -0
  174. package/docs/v1/integration/vanilla-js.md +84 -0
  175. package/docs/v1/integration/vue.md +58 -0
  176. package/docs/v1/reference/browser-support.md +45 -0
  177. package/docs/v1/reference/error-handling.md +75 -0
  178. package/docs/v1/reference/performance.md +52 -0
  179. package/docs/v1/reference/troubleshooting.md +136 -0
  180. package/package.json +33 -37
  181. package/dist/types/elements-builder-client.d.ts +0 -2
  182. package/dist/types/elements-client.d.ts +0 -2
  183. package/dist/types/enums/cloud.enum.d.ts +0 -106
  184. package/dist/types/interfaces/cloud/catalog.interface.d.ts +0 -42
  185. package/dist/types/interfaces/cloud/checkout.interface.d.ts +0 -218
  186. package/dist/types/interfaces/cloud/core.interface.d.ts +0 -22
  187. package/dist/types/interfaces/cloud/index.d.ts +0 -4
  188. package/dist/types/interfaces/cloud/retailer.interface.d.ts +0 -67
  189. package/dist/types/interfaces/cloud/user.interface.d.ts +0 -100
  190. package/dist/types/interfaces/core.interface.d.ts +0 -111
  191. package/dist/types/modules/checkout/components/checkout.type.d.ts +0 -4
  192. package/dist/types/modules/product-list/components/product-list-filters-subcomponents/index.d.ts +0 -6
  193. package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-apply-filter-button.component.d.ts +0 -1
  194. package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-delivery-options-filter.components.d.ts +0 -16
  195. package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-search.component.d.ts +0 -16
  196. package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-toggle-filters.components.d.ts +0 -18
  197. package/dist/types/modules/theme-provider/styles/address/index.d.ts +0 -1
  198. package/dist/types/modules/theme-provider/styles/cart/index.d.ts +0 -1
  199. package/dist/types/modules/theme-provider/styles/checkout/index.d.ts +0 -1
  200. package/dist/types/modules/theme-provider/styles/product/index.d.ts +0 -3
  201. package/dist/types/modules/theme-provider/styles/product-list/index.d.ts +0 -1
  202. package/dist/types/modules/theme-provider/styles/ui/index.d.ts +0 -3
  203. package/dist/types/modules/ui-components/input/birthdate-input.component.d.ts +0 -53
  204. package/dist/types/utils/helper.d.ts +0 -28
  205. package/docs/ACTIONS.md +0 -1300
  206. package/docs/BROWSER_SUPPORT.md +0 -279
  207. package/docs/CONFIGURATION.md +0 -853
  208. package/docs/DOCUMENTATION_INDEX.md +0 -311
  209. package/docs/EVENTS.md +0 -798
  210. package/docs/PROXY.md +0 -228
  211. package/docs/THEMING.md +0 -592
  212. package/docs/TROUBLESHOOTING.md +0 -793
  213. package/umd/elements.js +0 -1
  214. /package/dist/types/{auto-initialize.d.ts → auto-initialize/main.d.ts} +0 -0
  215. /package/dist/types/modules/{theme-provider/styles/address → address/styles}/address.style.d.ts +0 -0
  216. /package/dist/types/modules/{theme-provider/styles/cart → cart/styles}/cart.style.d.ts +0 -0
  217. /package/dist/types/modules/{theme-provider/styles/checkout → checkout/styles}/checkout.style.d.ts +0 -0
  218. /package/dist/types/modules/{theme-provider/styles/product → product/styles}/image-carousel.style.d.ts +0 -0
  219. /package/dist/types/modules/{theme-provider/styles/product → product/styles}/product.style.d.ts +0 -0
  220. /package/dist/types/modules/{theme-provider/styles/product → product/styles}/retailers.style.d.ts +0 -0
  221. /package/dist/types/modules/product-list/components/{product-list-filters-subcomponents/product-list-checkbox-filter.components.d.ts → filter-components/product-list-checkbox-filter.d.ts} +0 -0
  222. /package/dist/types/modules/{theme-provider/styles/product-list → product-list/styles}/product-list.style.d.ts +0 -0
  223. /package/dist/types/modules/{theme-provider/styles/ui → ui-components/styles}/drawer.style.d.ts +0 -0
  224. /package/dist/types/modules/{theme-provider/styles/ui → ui-components/styles}/loading.style.d.ts +0 -0
  225. /package/dist/types/modules/{theme-provider/styles/ui → ui-components/styles}/promo-code-ticker.style.d.ts +0 -0
@@ -0,0 +1,89 @@
1
+ # Simple Product Page
2
+
3
+ A minimal, production-ready product page using the CDN build with a single Product component and the default cart drawer.
4
+
5
+ ## What You'll Build
6
+
7
+ - One product component
8
+ - Optional cart button with item count
9
+ - Default cart and checkout flow
10
+
11
+ ## Prerequisites
12
+
13
+ - LiquidCommerce API key
14
+ - One product identifier (UPC or grouping ID)
15
+
16
+ ## HTML (CDN)
17
+
18
+ ```html
19
+ <!DOCTYPE html>
20
+ <html lang="en">
21
+ <head>
22
+ <meta charset="UTF-8" />
23
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
24
+ <title>Simple Product Page</title>
25
+
26
+ <script
27
+ defer
28
+ data-liquid-commerce-elements
29
+ data-token="YOUR_API_KEY"
30
+ data-env="production"
31
+ data-container-1="product"
32
+ data-product-1="00619947000020"
33
+ data-cart-badge-button="header-cart"
34
+ type="text/javascript"
35
+ src="https://elements.reservebar-worker.workers.dev/all/elements.js"
36
+ ></script>
37
+
38
+ <style>
39
+ body {
40
+ font-family: Arial, sans-serif;
41
+ margin: 0;
42
+ padding: 0;
43
+ background: #f7f7f7;
44
+ }
45
+ header {
46
+ background: #fff;
47
+ padding: 16px 24px;
48
+ box-shadow: 0 2px 6px rgba(0,0,0,0.08);
49
+ display: flex;
50
+ justify-content: space-between;
51
+ align-items: center;
52
+ }
53
+ main {
54
+ max-width: 1100px;
55
+ margin: 24px auto;
56
+ padding: 0 24px;
57
+ }
58
+ #product {
59
+ background: #fff;
60
+ border-radius: 10px;
61
+ padding: 20px;
62
+ min-height: 600px;
63
+ }
64
+ </style>
65
+ </head>
66
+ <body>
67
+ <header>
68
+ <h1>Premium Spirits</h1>
69
+ <div id="header-cart"></div>
70
+ </header>
71
+
72
+ <main>
73
+ <div id="product"></div>
74
+ </main>
75
+ </body>
76
+ </html>
77
+ ```
78
+
79
+ ## What to Tweak Next
80
+
81
+ - Change the product identifier: `data-product-1="YOUR_PRODUCT_ID"`
82
+ - Add a second product (see [Multi-Product Page](./multi-product-page.md))
83
+ - Customize styling via theming (see [Theming Guide](../guides/theming.md))
84
+
85
+ ## Related Docs
86
+
87
+ - [Product Component](../guides/product-component.md)
88
+ - [Cart Component](../guides/cart-component.md)
89
+ - [Quick Start](../getting-started/quick-start.md)
@@ -0,0 +1,502 @@
1
+ # Core Concepts
2
+
3
+ Understanding these fundamental concepts will help you work effectively with the LiquidCommerce Elements SDK.
4
+
5
+ ## Web Components Architecture
6
+
7
+ The Elements SDK is built using **Web Components**, a set of web platform APIs that allow you to create custom, reusable HTML elements.
8
+
9
+ ### What Are Web Components?
10
+
11
+ Web Components are native browser features that provide:
12
+
13
+ 1. **Custom Elements** - Define your own HTML tags
14
+ 2. **Shadow DOM** - Encapsulated styling and markup
15
+ 3. **HTML Templates** - Reusable DOM fragments
16
+
17
+ ### Why Web Components?
18
+
19
+ **Framework Agnostic**
20
+ Works with any JavaScript framework or plain HTML:
21
+ - React, Vue, Angular, Svelte
22
+ - Vanilla JavaScript
23
+ - Static HTML pages
24
+ - Server-rendered pages
25
+
26
+ **Style Encapsulation**
27
+ Shadow DOM prevents CSS conflicts:
28
+ - SDK styles don't leak into your page
29
+ - Your page styles don't affect the SDK
30
+ - Components look consistent everywhere
31
+
32
+ **Future-Proof**
33
+ Built on web standards:
34
+ - No framework lock-in
35
+ - Works in modern browsers natively
36
+ - Follows platform evolution
37
+
38
+ ### How It Works
39
+
40
+ When you inject a product:
41
+
42
+ ```javascript
43
+ await client.injectProductElement([
44
+ { containerId: 'product', identifier: '00619947000020' }
45
+ ]);
46
+ ```
47
+
48
+ The SDK:
49
+ 1. Creates a custom element (e.g., `<product-lc>`)
50
+ 2. Attaches it to your container
51
+ 3. Renders content in Shadow DOM
52
+ 4. Registers event listeners
53
+
54
+ ## Client Initialization
55
+
56
+ The SDK client is the main interface for all operations.
57
+
58
+ ### Initialization Modes
59
+
60
+ #### Auto-Initialization (CDN)
61
+
62
+ When using the CDN, the SDK auto-initializes on page load:
63
+
64
+ ```html
65
+ <script
66
+ defer
67
+ data-liquid-commerce-elements
68
+ data-token="YOUR_API_KEY"
69
+ data-env="production"
70
+ type="text/javascript"
71
+ src="https://elements.reservebar-worker.workers.dev/all/elements.js"
72
+ ></script>
73
+ ```
74
+
75
+ The client becomes available globally under `window.LiquidCommerce.elements`.
76
+
77
+ #### Programmatic Initialization (NPM)
78
+
79
+ With NPM, you explicitly create the client:
80
+
81
+ ```javascript
82
+ import { Elements } from '@liquidcommerce/elements-sdk';
83
+
84
+ const client = await Elements('YOUR_API_KEY', {
85
+ env: 'production'
86
+ });
87
+ ```
88
+
89
+ ### Phased Initialization
90
+
91
+ The SDK uses a two-phase initialization strategy for optimal performance:
92
+
93
+ **Phase 1: Essential Services (Immediate)**
94
+ - Authentication
95
+ - Configuration loading
96
+ - Store initialization
97
+ - Theme setup
98
+ - Core component registration
99
+ - Telemetry / logger wiring
100
+ - Debug panel (if enabled)
101
+
102
+ **Phase 2: Deferred Services (next macrotask, via `setTimeout(…, 0)`)**
103
+ - Analytics (Google Tag Manager)
104
+ - Cart pre-loading
105
+ - Heavy component registration
106
+
107
+ This ensures fast initial page loads while still providing full functionality.
108
+
109
+ ### Client Ready Event
110
+
111
+ Listen for the client ready event to know when the SDK is initialized:
112
+
113
+ ```javascript
114
+ window.addEventListener('lce:actions.client_ready', (event) => {
115
+ console.log('SDK version:', event.detail.data.version);
116
+ console.log('Ready at:', event.detail.data.timestamp);
117
+
118
+ // Safe to use client
119
+ window.LiquidCommerce.elements.actions.cart.openCart();
120
+ });
121
+ ```
122
+
123
+ ## Declarative vs Programmatic
124
+
125
+ The SDK offers two approaches for component injection.
126
+
127
+ ### Declarative (HTML Attributes)
128
+
129
+ Configure components using HTML data attributes:
130
+
131
+ ```html
132
+ <script
133
+ defer
134
+ data-liquid-commerce-elements
135
+ data-token="YOUR_API_KEY"
136
+ data-container-1="product"
137
+ data-product-1="00619947000020"
138
+ type="text/javascript"
139
+ src="https://elements.reservebar-worker.workers.dev/all/elements.js"
140
+ ></script>
141
+
142
+ <div id="product"></div>
143
+ ```
144
+
145
+ **Advantages:**
146
+ - No JavaScript required
147
+ - Simple for static pages
148
+ - Automatic initialization
149
+
150
+ **Best for:**
151
+ - Static HTML sites
152
+ - CMS platforms (WordPress, Shopify)
153
+ - Quick prototypes
154
+
155
+ ### Programmatic (JavaScript API)
156
+
157
+ Use JavaScript methods to inject components:
158
+
159
+ ```javascript
160
+ const client = await Elements('YOUR_API_KEY', { env: 'production' });
161
+
162
+ await client.injectProductElement([
163
+ { containerId: 'product', identifier: '00619947000020' }
164
+ ]);
165
+ ```
166
+
167
+ **Advantages:**
168
+ - Dynamic product selection
169
+ - Conditional rendering
170
+ - Framework integration
171
+ - Full control over timing
172
+
173
+ **Best for:**
174
+ - Single-page applications
175
+ - Dynamic content
176
+ - React/Vue/Angular apps
177
+ - Complex interactions
178
+
179
+ ### Mixing Both Approaches
180
+
181
+ You can use declarative initialization and programmatic control:
182
+
183
+ ```html
184
+ <!-- Auto-initialize SDK -->
185
+ <script
186
+ defer
187
+ data-liquid-commerce-elements
188
+ data-token="YOUR_API_KEY"
189
+ data-env="production"
190
+ type="text/javascript"
191
+ src="https://elements.reservebar-worker.workers.dev/all/elements.js"
192
+ ></script>
193
+
194
+ <script>
195
+ // Later, add products programmatically
196
+ window.addEventListener('lce:actions.client_ready', async () => {
197
+ await window.LiquidCommerce.elements.injectProductElement([
198
+ { containerId: 'dynamic-product', identifier: selectedProductId }
199
+ ]);
200
+ });
201
+ </script>
202
+ ```
203
+
204
+ ## State Management
205
+
206
+ The SDK maintains its own internal state for cart, checkout, and user data.
207
+
208
+ ### Store Service
209
+
210
+ The SDK uses a centralized store service that:
211
+ - Maintains reactive state (in-memory, within a single tab)
212
+ - Persists data to localStorage
213
+ - Falls back to API storage
214
+
215
+ ### State Persistence
216
+
217
+ **Cart State:**
218
+ - Saved to localStorage
219
+ - Persists across sessions
220
+ - Survives page refreshes
221
+ - Other tabs pick up the persisted cart on their next load (no live cross-tab sync)
222
+
223
+ **Address State:**
224
+ - Saved when set by user
225
+ - Used for availability checking
226
+ - Cleared when user explicitly clears it
227
+
228
+ **Checkout State:**
229
+ - Created from cart
230
+ - Exists during checkout flow
231
+ - Cleared after order completion
232
+
233
+ ### Cross-Tab Persistence
234
+
235
+ State is persisted to `localStorage` keyed by device ID. The SDK does **not** register a `storage` listener, `BroadcastChannel`, or other inter-tab subscription, so there is **no live cross-tab synchronization** — a change made in one tab is only reflected in another already-open tab after that tab reloads (which re-runs the persisted-state load and re-fetches by the persisted cart ID).
236
+
237
+ ## Component Lifecycle
238
+
239
+ Understanding how components work helps with debugging and customization.
240
+
241
+ ### Injection Lifecycle
242
+
243
+ 1. **Validation** - Verify container exists
244
+ 2. **Creation** - Create Web Component
245
+ 3. **Attachment** - Add to DOM
246
+ 4. **Data Loading** - Fetch product/cart data
247
+ 5. **Rendering** - Display content
248
+ 6. **Event Setup** - Register listeners
249
+
250
+ ### Component Rerendering
251
+
252
+ Components automatically rerender when data changes:
253
+
254
+ ```javascript
255
+ // This triggers a rerender
256
+ await window.LiquidCommerce.elements.actions.cart.addProduct([...]);
257
+ // Cart component updates automatically
258
+ ```
259
+
260
+ Manual rerendering:
261
+
262
+ ```javascript
263
+ const components = window.LiquidCommerce.elements.getInjectedComponents();
264
+ // The Map is keyed by the container ID passed to inject* (with any leading '#' stripped),
265
+ // not a '<type>-<index>' string. For a component injected into id="product":
266
+ const productComponent = components.get('product');
267
+
268
+ // Force rerender
269
+ productComponent?.rerender();
270
+ ```
271
+
272
+ ### Component Removal
273
+
274
+ Components are removed when:
275
+ - Their container is removed from DOM
276
+ - Page navigation occurs
277
+ - You explicitly remove them
278
+
279
+ To clean up manually:
280
+
281
+ ```javascript
282
+ const container = document.getElementById('product');
283
+ container.innerHTML = ''; // Removes the component
284
+ ```
285
+
286
+ ## Event System
287
+
288
+ The SDK uses a publish-subscribe pattern for events.
289
+
290
+ ### Event Namespaces
291
+
292
+ All SDK events are namespaced to prevent conflicts:
293
+
294
+ ```javascript
295
+ // Action events (user interactions)
296
+ lce:actions.cart_opened
297
+ lce:actions.product_add_to_cart
298
+
299
+ // Form events (checkout forms)
300
+ lce:forms.customer
301
+ lce:forms.billing
302
+ ```
303
+
304
+ ### Event Flow
305
+
306
+ 1. User interacts with component
307
+ 2. Component publishes event
308
+ 3. SDK updates internal state
309
+ 4. Event bubbles to window
310
+ 5. Your code can listen and react
311
+
312
+ ### Subscribing to Events
313
+
314
+ ```javascript
315
+ window.addEventListener('lce:actions.cart_item_added', (event) => {
316
+ console.log('Item added:', event.detail.data);
317
+ // event.detail is { data, metadata }; payload fields live under .data:
318
+ // { cartId, itemId, fulfillmentId, partNumber, quantity, engravingLines? }
319
+ });
320
+ ```
321
+
322
+ See [Events Guide](../guides/events.md) for all available events.
323
+
324
+ ## Error Handling
325
+
326
+ The SDK is designed to fail gracefully and not crash your site.
327
+
328
+ ### Error Isolation
329
+
330
+ SDK errors are logged and also emitted as a `*_FAILED` event, then re-thrown so your code can catch them:
331
+
332
+ ```javascript
333
+ // The SDK emits CART_PRODUCT_ADD_FAILED and re-throws, so this catch runs
334
+ try {
335
+ await window.LiquidCommerce.elements.actions.cart.addProduct([/* invalid data */]);
336
+ } catch (error) {
337
+ console.log('This error is re-thrown by the SDK and caught here');
338
+ }
339
+
340
+ // Your page keeps working
341
+ console.log('Page still functional');
342
+ ```
343
+
344
+ ### Error Types
345
+
346
+ The SDK uses a custom `SDKError` class for all errors:
347
+
348
+ ```javascript
349
+ class SDKError extends Error {
350
+ constructor(message, reThrow = false) {
351
+ super(message);
352
+ this.name = 'SDKError';
353
+ this.isSdk = true;
354
+ this.reThrow = reThrow; // Whether to re-throw to the user
355
+ }
356
+ }
357
+ ```
358
+
359
+ ### Debug Mode
360
+
361
+ Enable debug mode for detailed logging:
362
+
363
+ ```javascript
364
+ const client = await Elements('YOUR_API_KEY', {
365
+ env: 'development',
366
+ debugMode: 'console' // or 'panel'
367
+ });
368
+ ```
369
+
370
+ **Debug Modes:**
371
+ - `'none'` - No debug output (production default)
372
+ - `'console'` - Log to browser console
373
+ - `'panel'` - Show debug panel on page
374
+
375
+ ## Security & API Keys
376
+
377
+ ### API Key Protection
378
+
379
+ Your API key is used for authentication but has limited privileges:
380
+
381
+ - ✅ Read product catalog
382
+ - ✅ Create carts and orders
383
+ - ✅ Process payments
384
+ - ❌ Access other merchants' data
385
+ - ❌ Modify product catalog
386
+ - ❌ Access admin functions
387
+
388
+ ### Environment Separation
389
+
390
+ Use different API keys per environment:
391
+
392
+ ```javascript
393
+ // Development
394
+ const client = await Elements('dev_key_abc123', {
395
+ env: 'development'
396
+ });
397
+
398
+ // Production
399
+ const client = await Elements('prod_key_xyz789', {
400
+ env: 'production'
401
+ });
402
+ ```
403
+
404
+ ### Proxy Configuration
405
+
406
+ To hide your API key and avoid ad blockers, use a proxy:
407
+
408
+ ```javascript
409
+ const client = await Elements('YOUR_API_KEY', {
410
+ env: 'production',
411
+ proxy: {
412
+ baseUrl: 'https://yourdomain.com/api/elements-proxy'
413
+ }
414
+ });
415
+ ```
416
+
417
+ See [Proxy Setup Guide](../integration/proxy-setup.md) for implementation details.
418
+
419
+ ## Browser Support
420
+
421
+ The SDK requires modern browser features:
422
+
423
+ **Minimum Versions:**
424
+ - Chrome 66+ (March 2018)
425
+ - Firefox 60+ (May 2018)
426
+ - Safari 12+ (September 2018)
427
+ - Edge 79+ (January 2020)
428
+
429
+ **Required Features:**
430
+ - Custom Elements (Web Components)
431
+ - Shadow DOM
432
+ - ES2018 JavaScript
433
+ - Fetch API
434
+ - LocalStorage
435
+
436
+ For older browsers, include polyfills:
437
+
438
+ ```html
439
+ <script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-bundle.js"></script>
440
+ <script data-liquid-commerce-elements ...></script>
441
+ ```
442
+
443
+ See [Browser Support](../reference/browser-support.md) for details.
444
+
445
+ ## Performance Considerations
446
+
447
+ The SDK is optimized for performance, but you can help:
448
+
449
+ ### Lazy Loading
450
+
451
+ Load the SDK script with `defer`:
452
+
453
+ ```html
454
+ <script defer data-liquid-commerce-elements ...></script>
455
+ ```
456
+
457
+ ### Tree Shaking
458
+
459
+ Use the checkout-only build when you don't need products:
460
+
461
+ ```javascript
462
+ import { ElementsCheckout } from '@liquidcommerce/elements-sdk/checkout';
463
+ ```
464
+
465
+ This reduces bundle size by ~60%.
466
+
467
+ ### Component Injection Timing
468
+
469
+ Inject components when needed, not all at once:
470
+
471
+ ```javascript
472
+ // Good: Inject visible products first
473
+ await client.injectProductElement([
474
+ { containerId: 'hero-product', identifier: '001' }
475
+ ]);
476
+
477
+ // Then inject others after a delay
478
+ setTimeout(async () => {
479
+ await client.injectProductElement([
480
+ { containerId: 'related-1', identifier: '002' },
481
+ { containerId: 'related-2', identifier: '003' }
482
+ ]);
483
+ }, 1000);
484
+ ```
485
+
486
+ ### Image Optimization
487
+
488
+ The SDK automatically:
489
+ - Lazy loads images
490
+ - Uses responsive images
491
+ - Implements carousel virtualization
492
+
493
+ ## Next Steps
494
+
495
+ Now that you understand the core concepts:
496
+
497
+ - **[Product Component](../guides/product-component.md)** - Learn about product displays
498
+ - **[Cart Component](../guides/cart-component.md)** - Understand cart functionality
499
+ - **[Checkout Component](../guides/checkout-component.md)** - Master the checkout flow
500
+ - **[Theming](../guides/theming.md)** - Customize the look and feel
501
+ - **[Events](../guides/events.md)** - React to user actions
502
+ - **[API Reference](../api/client.md)** - Explore all available methods