@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.
- package/README.md +84 -2520
- package/dist/index.checkout.esm.js +16940 -0
- package/dist/index.esm.js +24189 -20939
- package/dist/ssr-stub.checkout.esm.js +18 -0
- package/dist/ssr-stub.esm.js +270 -0
- package/dist/types/auto-initialize/checkout.d.ts +2 -0
- package/dist/types/auto-initialize/shared-utils.d.ts +50 -0
- package/dist/types/{elements-base-client.d.ts → clients/base.d.ts} +15 -2
- package/dist/types/clients/builder.d.ts +3 -0
- package/dist/types/clients/checkout.d.ts +6 -0
- package/dist/types/{elements-client-helper.d.ts → clients/helpers.d.ts} +2 -1
- package/dist/types/clients/main.d.ts +3 -0
- package/dist/types/constants/core.constant.d.ts +2 -6
- package/dist/types/core/api/api-client.service.d.ts +20 -18
- package/dist/types/core/api/api-result.d.ts +19 -0
- package/dist/types/core/api/auth-client.service.d.ts +37 -13
- package/dist/types/core/api/http-client.service.d.ts +0 -8
- package/dist/types/core/base-component.service.d.ts +2 -1
- package/dist/types/core/client/actions/base-action.service.d.ts +22 -0
- package/dist/types/core/client/actions/client-address-action.service.d.ts +18 -0
- package/dist/types/core/client/actions/client-cart-action.service.d.ts +38 -0
- package/dist/types/core/client/actions/client-checkout-action.service.d.ts +69 -0
- package/dist/types/core/client/actions/client-product-action.service.d.ts +15 -0
- package/dist/types/core/client/client-action.service.d.ts +6 -74
- package/dist/types/core/client/client-config.service.d.ts +8 -5
- package/dist/types/core/google-tag-manager.service.d.ts +2 -1
- package/dist/types/core/logger/logger.service.d.ts +1 -1
- package/dist/types/core/pubsub/interfaces/address.interface.d.ts +3 -0
- package/dist/types/core/pubsub/interfaces/cart.interface.d.ts +1 -1
- package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +36 -51
- package/dist/types/core/pubsub/interfaces/core.interface.d.ts +11 -6
- package/dist/types/core/pubsub/pubsub.service.d.ts +1 -2
- package/dist/types/core/singleton-manager.service.d.ts +12 -8
- package/dist/types/core/store/interfaces/cart.interface.d.ts +2 -3
- package/dist/types/core/store/interfaces/checkout.interface.d.ts +18 -108
- package/dist/types/core/store/interfaces/core.interface.d.ts +12 -2
- package/dist/types/core/store/interfaces/metadata.interface.d.ts +11 -0
- package/dist/types/core/store/interfaces/product-list.interface.d.ts +30 -0
- package/dist/types/core/store/interfaces/product.interface.d.ts +1 -0
- package/dist/types/core/store/store.constant.d.ts +5 -0
- package/dist/types/core/store/store.service.d.ts +1 -0
- package/dist/types/core/telemetry/telemetry.service.d.ts +1 -0
- package/dist/types/enums/core.enum.d.ts +39 -1
- package/dist/types/enums/index.d.ts +0 -1
- package/dist/types/index.checkout.d.ts +8 -0
- package/dist/types/index.checkout.umd.d.ts +4 -0
- package/dist/types/index.d.ts +8 -3
- package/dist/types/interfaces/api/cart.interface.d.ts +12 -7
- package/dist/types/interfaces/api/checkout.interface.d.ts +239 -0
- package/dist/types/interfaces/api/index.d.ts +5 -0
- package/dist/types/interfaces/api/product-list.interface.d.ts +39 -0
- package/dist/types/interfaces/api/product.interface.d.ts +10 -4
- package/dist/types/interfaces/client.interface.d.ts +72 -0
- package/dist/types/interfaces/component.interface.d.ts +7 -0
- package/dist/types/interfaces/config.interface.d.ts +40 -0
- package/dist/types/interfaces/configs/address.interface.d.ts +1 -1
- package/dist/types/interfaces/configs/cart.interface.d.ts +1 -1
- package/dist/types/interfaces/configs/checkout.interface.d.ts +2 -1
- package/dist/types/interfaces/configs/global.interface.d.ts +5 -3
- package/dist/types/interfaces/configs/index.d.ts +1 -0
- package/dist/types/interfaces/configs/product-list.interface.d.ts +49 -0
- package/dist/types/interfaces/configs/product.interface.d.ts +3 -1
- package/dist/types/interfaces/injection.interface.d.ts +49 -0
- package/dist/types/modules/address/address.command.d.ts +2 -1
- package/dist/types/modules/address/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/cart/cart.commands.d.ts +4 -4
- package/dist/types/modules/cart/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/checkout/checkout.commands.d.ts +26 -10
- package/dist/types/modules/checkout/checkout.component.d.ts +2 -0
- package/dist/types/modules/checkout/components/checkout-billing.component.d.ts +2 -2
- package/dist/types/modules/checkout/components/checkout-completed.component.d.ts +3 -0
- package/dist/types/modules/checkout/components/checkout-header.component.d.ts +1 -0
- package/dist/types/modules/checkout/components/checkout-item-quantity.component.d.ts +3 -0
- package/dist/types/modules/checkout/components/checkout-items.component.d.ts +4 -3
- package/dist/types/modules/checkout/components/checkout-payment.component.d.ts +1 -1
- package/dist/types/modules/checkout/components/checkout-presale-countdown.component.d.ts +14 -1
- package/dist/types/modules/checkout/components/checkout-presale-expired.component.d.ts +7 -1
- package/dist/types/modules/checkout/components/checkout-stripe-form.component.d.ts +2 -1
- package/dist/types/modules/checkout/components/checkout-tips.component.d.ts +2 -2
- package/dist/types/modules/checkout/components/promo-pc-gc.component.d.ts +0 -2
- package/dist/types/modules/checkout/constant.d.ts +3 -0
- package/dist/types/modules/checkout/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/product/components/product-add-to-cart-section.component.d.ts +1 -0
- package/dist/types/modules/product/components/product-description.component.d.ts +1 -0
- package/dist/types/modules/product/components/product-image-carousel.component.d.ts +3 -0
- package/dist/types/modules/product/components/product-options.component.d.ts +2 -1
- package/dist/types/modules/product/components/product-retailers-carousel.component.d.ts +3 -0
- package/dist/types/modules/product/components/product-retailers-popup-list.component.d.ts +5 -2
- package/dist/types/modules/product/product.commands.d.ts +3 -3
- package/dist/types/modules/product/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/product-list/components/card-components/index.d.ts +5 -0
- package/dist/types/modules/product-list/components/card-components/product-badge.d.ts +9 -0
- package/dist/types/modules/product-list/components/card-components/product-button.d.ts +11 -0
- package/dist/types/modules/product-list/components/card-components/product-price-and-personalization.d.ts +13 -0
- package/dist/types/modules/product-list/components/card-components/product-quantity-selector.d.ts +10 -0
- package/dist/types/modules/product-list/components/card-components/product-sizes-list.d.ts +13 -0
- package/dist/types/modules/product-list/components/filter-components/index.d.ts +7 -0
- package/dist/types/modules/product-list/components/filter-components/product-list-apply-filter-button.d.ts +1 -0
- package/dist/types/modules/product-list/components/filter-components/product-list-chip.d.ts +5 -0
- package/dist/types/modules/product-list/components/filter-components/product-list-filters-chips.d.ts +13 -0
- package/dist/types/modules/product-list/components/filter-components/product-list-fulfillment-filter.d.ts +14 -0
- 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
- package/dist/types/modules/product-list/components/filter-components/product-list-toggle-filters.d.ts +7 -0
- package/dist/types/modules/product-list/components/index.d.ts +6 -2
- package/dist/types/modules/product-list/components/product-list-card-loading.component.d.ts +3 -1
- package/dist/types/modules/product-list/components/product-list-card.component.d.ts +39 -31
- package/dist/types/modules/product-list/components/product-list-engraving.component.d.ts +12 -0
- package/dist/types/modules/product-list/components/product-list-filters.component.d.ts +55 -36
- package/dist/types/modules/product-list/components/product-list-product-engraving-lines.component.d.ts +22 -0
- package/dist/types/modules/product-list/components/product-list-product-pre-cart.component.d.ts +50 -0
- package/dist/types/modules/product-list/components/product-list-search.component.d.ts +25 -0
- package/dist/types/modules/product-list/product-list-filter.utils.d.ts +8 -0
- package/dist/types/modules/product-list/product-list-query-params.utils.d.ts +3 -0
- package/dist/types/modules/product-list/product-list.commands.d.ts +23 -8
- package/dist/types/modules/product-list/product-list.component.d.ts +14 -47
- package/dist/types/modules/product-list/product-list.constants.d.ts +38 -0
- package/dist/types/modules/product-list/product-list.interface.d.ts +20 -35
- package/dist/types/modules/product-list/styles/product-list-card.style.d.ts +1 -0
- package/dist/types/modules/product-list/styles/product-list-filters.style.d.ts +1 -0
- package/dist/types/modules/product-list/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/theme-provider/constants/component-groupings.d.ts +1 -0
- package/dist/types/modules/theme-provider/constants/css-variable-mappings.d.ts +1 -1
- package/dist/types/modules/theme-provider/services/style-registry.service.d.ts +16 -0
- package/dist/types/modules/theme-provider/services/stylesheet-generator.service.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/register-styles.d.ts +1 -0
- package/dist/types/modules/theme-provider/theme-provider.service.d.ts +2 -2
- package/dist/types/modules/ui-components/drawer/drawer.component.d.ts +1 -0
- package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +6 -1
- package/dist/types/modules/ui-components/engraving/engraving-view.component.d.ts +6 -1
- package/dist/types/modules/ui-components/input/index.d.ts +0 -1
- package/dist/types/modules/ui-components/input/input.component.d.ts +8 -1
- package/dist/types/modules/ui-components/lce-element/lce-element.component.d.ts +2 -1
- package/dist/types/modules/ui-components/promo-code-ticker/promo-code-ticker.component.d.ts +1 -1
- package/dist/types/modules/ui-components/ui.commands.d.ts +5 -1
- package/dist/types/ssr/stub.checkout.d.ts +6 -0
- package/dist/types/ssr/stub.d.ts +10 -0
- package/dist/types/static/icon/check.icon.d.ts +2 -0
- package/dist/types/static/icon/index.d.ts +1 -0
- package/dist/types/utils/dom-compat.d.ts +2 -0
- package/dist/types/utils/format.d.ts +0 -14
- package/dist/types/utils/product-selection.d.ts +16 -0
- package/dist/types/utils/product.d.ts +15 -0
- package/docs/v1/README.md +210 -0
- package/docs/v1/api/actions/address-actions.md +286 -0
- package/docs/v1/api/actions/cart-actions.md +357 -0
- package/docs/v1/api/actions/checkout-actions.md +525 -0
- package/docs/v1/api/actions/product-actions.md +204 -0
- package/docs/v1/api/client.md +517 -0
- package/docs/v1/api/configuration.md +532 -0
- package/docs/v1/api/injection-methods.md +292 -0
- package/docs/v1/api/typescript-types.md +419 -0
- package/docs/v1/api/ui-helpers.md +200 -0
- package/docs/v1/examples/advanced-patterns.md +199 -0
- package/docs/v1/examples/checkout-flow.md +90 -0
- package/docs/v1/examples/custom-theming.md +63 -0
- package/docs/v1/examples/multi-product-page.md +90 -0
- package/docs/v1/examples/simple-product-page.md +89 -0
- package/docs/v1/getting-started/concepts.md +502 -0
- package/docs/v1/getting-started/installation.md +328 -0
- package/docs/v1/getting-started/quick-start.md +405 -0
- package/docs/v1/guides/address-component.md +435 -0
- package/docs/v1/guides/best-practices.md +365 -0
- package/docs/v1/guides/cart-component.md +725 -0
- package/docs/v1/guides/checkout-component.md +670 -0
- package/docs/v1/guides/events.md +926 -0
- package/docs/v1/guides/product-component.md +731 -0
- package/docs/v1/guides/product-list-component.md +631 -0
- package/docs/v1/guides/theming.md +213 -0
- package/docs/v1/integration/angular.md +39 -0
- package/docs/v1/integration/laravel.md +41 -0
- package/docs/v1/integration/nextjs.md +69 -0
- package/docs/v1/integration/proxy-setup.md +106 -0
- package/docs/v1/integration/react.md +64 -0
- package/docs/v1/integration/vanilla-js.md +84 -0
- package/docs/v1/integration/vue.md +58 -0
- package/docs/v1/reference/browser-support.md +45 -0
- package/docs/v1/reference/error-handling.md +75 -0
- package/docs/v1/reference/performance.md +52 -0
- package/docs/v1/reference/troubleshooting.md +136 -0
- package/package.json +33 -37
- package/dist/types/elements-builder-client.d.ts +0 -2
- package/dist/types/elements-client.d.ts +0 -2
- package/dist/types/enums/cloud.enum.d.ts +0 -106
- package/dist/types/interfaces/cloud/catalog.interface.d.ts +0 -42
- package/dist/types/interfaces/cloud/checkout.interface.d.ts +0 -218
- package/dist/types/interfaces/cloud/core.interface.d.ts +0 -22
- package/dist/types/interfaces/cloud/index.d.ts +0 -4
- package/dist/types/interfaces/cloud/retailer.interface.d.ts +0 -67
- package/dist/types/interfaces/cloud/user.interface.d.ts +0 -100
- package/dist/types/interfaces/core.interface.d.ts +0 -111
- package/dist/types/modules/checkout/components/checkout.type.d.ts +0 -4
- package/dist/types/modules/product-list/components/product-list-filters-subcomponents/index.d.ts +0 -6
- package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-apply-filter-button.component.d.ts +0 -1
- package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-delivery-options-filter.components.d.ts +0 -16
- package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-search.component.d.ts +0 -16
- package/dist/types/modules/product-list/components/product-list-filters-subcomponents/product-list-toggle-filters.components.d.ts +0 -18
- package/dist/types/modules/theme-provider/styles/address/index.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/cart/index.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/checkout/index.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/product/index.d.ts +0 -3
- package/dist/types/modules/theme-provider/styles/product-list/index.d.ts +0 -1
- package/dist/types/modules/theme-provider/styles/ui/index.d.ts +0 -3
- package/dist/types/modules/ui-components/input/birthdate-input.component.d.ts +0 -53
- package/dist/types/utils/helper.d.ts +0 -28
- package/docs/ACTIONS.md +0 -1300
- package/docs/BROWSER_SUPPORT.md +0 -279
- package/docs/CONFIGURATION.md +0 -853
- package/docs/DOCUMENTATION_INDEX.md +0 -311
- package/docs/EVENTS.md +0 -798
- package/docs/PROXY.md +0 -228
- package/docs/THEMING.md +0 -592
- package/docs/TROUBLESHOOTING.md +0 -793
- package/umd/elements.js +0 -1
- /package/dist/types/{auto-initialize.d.ts → auto-initialize/main.d.ts} +0 -0
- /package/dist/types/modules/{theme-provider/styles/address → address/styles}/address.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/cart → cart/styles}/cart.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/checkout → checkout/styles}/checkout.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/product → product/styles}/image-carousel.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/product → product/styles}/product.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/product → product/styles}/retailers.style.d.ts +0 -0
- /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
- /package/dist/types/modules/{theme-provider/styles/product-list → product-list/styles}/product-list.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/ui → ui-components/styles}/drawer.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/ui → ui-components/styles}/loading.style.d.ts +0 -0
- /package/dist/types/modules/{theme-provider/styles/ui → ui-components/styles}/promo-code-ticker.style.d.ts +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# Product Actions API
|
|
2
|
+
|
|
3
|
+
Product actions allow you to programmatically retrieve product information.
|
|
4
|
+
|
|
5
|
+
## actions.product.getDetails()
|
|
6
|
+
|
|
7
|
+
Retrieve details of a loaded product.
|
|
8
|
+
|
|
9
|
+
### Signature
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
getDetails(identifier: string): IBaseProductEventData
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Parameters
|
|
16
|
+
|
|
17
|
+
| Parameter | Type | Required | Description |
|
|
18
|
+
|--------------|--------|----------|-------------------------|
|
|
19
|
+
| `identifier` | string | Yes | Product UPC, SKU, or ID |
|
|
20
|
+
|
|
21
|
+
### Returns
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// Inherits all IProduct fields except `sizes` (see below for the overridden `sizes` shape)
|
|
25
|
+
interface IBaseProductEventData {
|
|
26
|
+
identifier: string;
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
priceInfo: IProductPriceInfo | null; // { currency, minimum, average, maximum }
|
|
30
|
+
selectedSizeId: string | null;
|
|
31
|
+
selectedFulfillmentType: FulfillmentType;
|
|
32
|
+
selectedFulfillmentId: string | null;
|
|
33
|
+
productHasAvailability: boolean;
|
|
34
|
+
fulfillmentHasAvailability: boolean;
|
|
35
|
+
sizes: Record<string, IProductSizeEventData>;
|
|
36
|
+
images: string[];
|
|
37
|
+
brand: string;
|
|
38
|
+
category: string;
|
|
39
|
+
// ... additional IProduct fields
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Example
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const productData = window.LiquidCommerce.elements.actions.product.getDetails('00619947000020');
|
|
47
|
+
|
|
48
|
+
console.log(productData.name); // "Premium Whiskey"
|
|
49
|
+
console.log(productData.priceInfo?.minimum / 100); // 49.99
|
|
50
|
+
console.log(productData.sizes[productData.selectedSizeId]?.size); // "750ml"
|
|
51
|
+
console.log(productData.selectedSizeId); // "size_123"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Errors
|
|
55
|
+
|
|
56
|
+
**Throws `SDKError` if:**
|
|
57
|
+
- Identifier is empty or invalid
|
|
58
|
+
- Product has not been loaded yet (a non-existent product surfaces as this same error)
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
try {
|
|
62
|
+
const data = window.LiquidCommerce.elements.actions.product.getDetails('invalid_id');
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error('Product not found:', error.message);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Use Cases
|
|
69
|
+
|
|
70
|
+
#### Display Product Info Elsewhere
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
const product = window.LiquidCommerce.elements.actions.product.getDetails('00619947000020');
|
|
74
|
+
|
|
75
|
+
document.getElementById('product-name').textContent = product.name;
|
|
76
|
+
document.getElementById('product-price').textContent = `$${product.priceInfo?.minimum / 100}`;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### Sync with Analytics
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
window.addEventListener('lce:actions.product_loaded', () => {
|
|
83
|
+
const product = window.LiquidCommerce.elements.actions.product.getDetails('00619947000020');
|
|
84
|
+
|
|
85
|
+
gtag('event', 'view_item', {
|
|
86
|
+
items: [{
|
|
87
|
+
item_id: product.identifier,
|
|
88
|
+
item_name: product.name,
|
|
89
|
+
price: product.priceInfo?.minimum / 100,
|
|
90
|
+
item_brand: product.brand
|
|
91
|
+
}]
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Custom Product Comparison
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
const product1 = window.LiquidCommerce.elements.actions.product.getDetails('00619947000020');
|
|
100
|
+
const product2 = window.LiquidCommerce.elements.actions.product.getDetails('08504405135');
|
|
101
|
+
|
|
102
|
+
if (product1.priceInfo?.minimum < product2.priceInfo?.minimum) {
|
|
103
|
+
console.log(`${product1.name} is cheaper`);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## actions.product.getProductAvailabilityByState()
|
|
110
|
+
|
|
111
|
+
Check product availability across states.
|
|
112
|
+
|
|
113
|
+
### Signature
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
getProductAvailabilityByState(
|
|
117
|
+
identifiers: string[],
|
|
118
|
+
state?: string
|
|
119
|
+
): Promise<IProductAvailabilityResponse>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Parameters
|
|
123
|
+
|
|
124
|
+
| Parameter | Type | Required | Description |
|
|
125
|
+
|---------------|----------|----------|------------------------------------------|
|
|
126
|
+
| `identifiers` | string[] | Yes | Array of product UPCs, SKUs, or IDs |
|
|
127
|
+
| `state` | string | No | Two-letter state code (e.g., `'NY'`) |
|
|
128
|
+
|
|
129
|
+
### Returns
|
|
130
|
+
|
|
131
|
+
Resolves to an `IProductAvailabilityResponse`:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
interface IProductAvailabilityResponse {
|
|
135
|
+
products: IProduct[];
|
|
136
|
+
retailers: Record<string /* retailer ID */, IRetailer>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface IRetailer {
|
|
140
|
+
id: string;
|
|
141
|
+
name: string;
|
|
142
|
+
address: IRetailerAddress; // IAddressAddress & IAddressCoordinates
|
|
143
|
+
addressFormatted: string;
|
|
144
|
+
shippingFulfillment: IFulfillment | null;
|
|
145
|
+
onDemandFulfillment: IFulfillment | null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface IFulfillment {
|
|
149
|
+
id: string;
|
|
150
|
+
type: FulfillmentType; // 'shipping' | 'onDemand'
|
|
151
|
+
doesAllowGiftCards: boolean;
|
|
152
|
+
doesAllowPromos: boolean;
|
|
153
|
+
expectation: string;
|
|
154
|
+
engravingExpectation: string;
|
|
155
|
+
fee: number;
|
|
156
|
+
timezone: string;
|
|
157
|
+
hourStatus: { isOpen: boolean; openTime: string; isClosed: boolean; closeTime: string };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface IProduct {
|
|
161
|
+
id: string; name: string; description: string; htmlDescription: string;
|
|
162
|
+
images: string[]; brand: string; region: string; country: string;
|
|
163
|
+
material: string; abv: string; proof: string; age: string; color: string;
|
|
164
|
+
flavor: string; variety: string; appellation: string; vintage: string;
|
|
165
|
+
tastingNotes: string; catPath: string; category: string; classification: string;
|
|
166
|
+
type: string; subType: string; salsifyGrouping: string;
|
|
167
|
+
priceInfo: IProductPriceInfo | null; // { currency, minimum, average, maximum } — cents
|
|
168
|
+
sizes: Record<string /* size ID */, IProductSize>;
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Example
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
// Check availability in a specific state
|
|
176
|
+
const availabilityCA = await window.LiquidCommerce.elements.actions.product
|
|
177
|
+
.getProductAvailabilityByState(['00619947000020', '08504405135'], 'CA');
|
|
178
|
+
|
|
179
|
+
// Omit the state to query without a state filter
|
|
180
|
+
// (state: undefined is sent — the SDK does NOT derive it from the stored address)
|
|
181
|
+
const availability = await window.LiquidCommerce.elements.actions.product
|
|
182
|
+
.getProductAvailabilityByState(['00619947000020']);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Errors
|
|
186
|
+
|
|
187
|
+
**Throws `SDKError` if:**
|
|
188
|
+
- No identifiers provided or array is empty
|
|
189
|
+
- API request fails
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Notes
|
|
194
|
+
|
|
195
|
+
- Product must be injected and loaded before calling `getDetails()`
|
|
196
|
+
- `getDetails()` is synchronous - returns immediately
|
|
197
|
+
- `getProductAvailabilityByState()` is async - returns a Promise
|
|
198
|
+
- Prices are always in cents (divide by 100 for dollars)
|
|
199
|
+
- Selected values reflect current user selection in the component
|
|
200
|
+
|
|
201
|
+
## See Also
|
|
202
|
+
|
|
203
|
+
- [Product Component Guide](../../guides/product-component.md)
|
|
204
|
+
- [Product Events](../../guides/events.md#product-events)
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
# Client API
|
|
2
|
+
|
|
3
|
+
The Elements client is the main interface for interacting with the SDK. It provides methods for injecting components, managing UI elements, and performing actions.
|
|
4
|
+
|
|
5
|
+
## Initialization
|
|
6
|
+
|
|
7
|
+
### Elements()
|
|
8
|
+
|
|
9
|
+
Initialize the full SDK client.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
function Elements(
|
|
13
|
+
apiKey: string,
|
|
14
|
+
config: ILiquidCommerceElementsConfig
|
|
15
|
+
): Promise<ILiquidCommerceElementsClient | null>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Parameters:**
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Required | Description |
|
|
21
|
+
|-----------|-------------------------------|----------|-----------------------------|
|
|
22
|
+
| `apiKey` | string | Yes | Your LiquidCommerce API key |
|
|
23
|
+
| `config` | ILiquidCommerceElementsConfig | Yes | Configuration object |
|
|
24
|
+
|
|
25
|
+
**Returns:** Promise that resolves to the client instance, or `null` if initialization fails.
|
|
26
|
+
|
|
27
|
+
**Example:**
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
import { Elements } from '@liquidcommerce/elements-sdk';
|
|
31
|
+
|
|
32
|
+
const client = await Elements('YOUR_API_KEY', {
|
|
33
|
+
env: 'production',
|
|
34
|
+
debugMode: 'console',
|
|
35
|
+
customTheme: { /* theme config */ }
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### ElementsCheckout()
|
|
40
|
+
|
|
41
|
+
Initialize the checkout-only client (tree-shaken build).
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
function ElementsCheckout(
|
|
45
|
+
apiKey: string,
|
|
46
|
+
config: ILiquidCommerceElementsCheckoutClientConfig
|
|
47
|
+
): Promise<IElementsCheckoutClient | null>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Parameters:**
|
|
51
|
+
|
|
52
|
+
| Parameter | Type | Required | Description |
|
|
53
|
+
|-----------|---------------------------------------------|----------|-----------------------------|
|
|
54
|
+
| `apiKey` | string | Yes | Your LiquidCommerce API key |
|
|
55
|
+
| `config` | ILiquidCommerceElementsCheckoutClientConfig | Yes | Checkout configuration |
|
|
56
|
+
|
|
57
|
+
**Example:**
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
import { ElementsCheckout } from '@liquidcommerce/elements-sdk/checkout';
|
|
61
|
+
|
|
62
|
+
const client = await ElementsCheckout('YOUR_API_KEY', {
|
|
63
|
+
env: 'production'
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### ElementsBuilder()
|
|
68
|
+
|
|
69
|
+
Initialize the builder client, which exposes manual `inject*` / `update*` methods for fully programmatic composition.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
function ElementsBuilder(
|
|
73
|
+
apiKey: string,
|
|
74
|
+
config: ILiquidCommerceElementsBuilderConfig
|
|
75
|
+
): Promise<ILiquidCommerceElementsBuilderClient | null>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Parameters:**
|
|
79
|
+
|
|
80
|
+
| Parameter | Type | Required | Description |
|
|
81
|
+
|-----------|--------------------------------------|----------|-----------------------------|
|
|
82
|
+
| `apiKey` | string | Yes | Your LiquidCommerce API key |
|
|
83
|
+
| `config` | ILiquidCommerceElementsBuilderConfig | Yes | Builder configuration object (same shape as `ILiquidCommerceElementsConfig`) |
|
|
84
|
+
|
|
85
|
+
**Returns:** Promise that resolves to the builder client instance (`ILiquidCommerceElementsBuilderClient`), or `null` if initialization fails or it is called outside the browser.
|
|
86
|
+
|
|
87
|
+
**Example:**
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
import { ElementsBuilder } from '@liquidcommerce/elements-sdk';
|
|
91
|
+
|
|
92
|
+
const builder = await ElementsBuilder('YOUR_API_KEY', {
|
|
93
|
+
env: 'production'
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Configuration
|
|
98
|
+
|
|
99
|
+
### ILiquidCommerceElementsConfig
|
|
100
|
+
|
|
101
|
+
Complete configuration interface for the full SDK.
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
interface ILiquidCommerceElementsConfig {
|
|
105
|
+
// Optional
|
|
106
|
+
env?: ElementsEnv; // defaults to 'production' ('development' | 'staging' | 'production')
|
|
107
|
+
debugMode?: DebugMode; // 'none' | 'console' | 'panel'
|
|
108
|
+
customTheme?: IClientCustomThemeConfig;
|
|
109
|
+
promoTicker?: IPromoTicker[];
|
|
110
|
+
proxy?: IElementsProxyConfig;
|
|
111
|
+
checkout?: ILiquidCommerceElementsCheckoutConfig;
|
|
112
|
+
development?: ILiquidCommerceElementsDevelopmentConfig;
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### Environment
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
type ElementsEnv = 'development' | 'staging' | 'production';
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Determines which API environment to use.
|
|
123
|
+
|
|
124
|
+
#### Debug Mode
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
type DebugMode = 'none' | 'console' | 'panel';
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
- `'none'`: No debug output (production default)
|
|
131
|
+
- `'console'`: Log debug info to browser console
|
|
132
|
+
- `'panel'`: Show debug panel on page
|
|
133
|
+
|
|
134
|
+
#### Custom Theme
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
interface IClientCustomThemeConfig {
|
|
138
|
+
global?: UpdateComponentGlobalConfigs;
|
|
139
|
+
product?: UpdateProductComponent;
|
|
140
|
+
address?: UpdateAddressComponent;
|
|
141
|
+
cart?: UpdateCartComponent;
|
|
142
|
+
checkout?: UpdateCheckoutComponent;
|
|
143
|
+
productList?: UpdateProductListComponent;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
See [Configuration Reference](./configuration.md) for detailed theme options.
|
|
148
|
+
|
|
149
|
+
#### Promo Ticker
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
interface IPromoTicker {
|
|
153
|
+
promoCode: string;
|
|
154
|
+
text: string[];
|
|
155
|
+
separator: string;
|
|
156
|
+
activeFrom: string; // ISO 8601 UTC format
|
|
157
|
+
activeUntil: string; // ISO 8601 UTC format
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Example:**
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
promoTicker: [{
|
|
165
|
+
promoCode: 'SUMMER20',
|
|
166
|
+
text: ['20% Off Summer Sale', 'Free Shipping on $50+'],
|
|
167
|
+
separator: '•',
|
|
168
|
+
activeFrom: '2026-06-01T00:00:00Z',
|
|
169
|
+
activeUntil: '2026-08-31T23:59:59Z'
|
|
170
|
+
}]
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### Proxy Configuration
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
interface IElementsProxyConfig {
|
|
177
|
+
baseUrl: string;
|
|
178
|
+
headers?: Record<string, string>;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Example:**
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
proxy: {
|
|
186
|
+
baseUrl: 'https://yoursite.com/api/elements-proxy',
|
|
187
|
+
headers: {
|
|
188
|
+
'X-Custom-Header': 'value'
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
See [Proxy Setup Guide](../integration/proxy-setup.md) for implementation.
|
|
194
|
+
|
|
195
|
+
#### Checkout Configuration
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
interface ILiquidCommerceElementsCheckoutConfig {
|
|
199
|
+
pageUrl?: string; // Optional. URL pattern with {token} placeholder
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Example:**
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
checkout: {
|
|
207
|
+
pageUrl: 'https://yoursite.com/checkout?lce_checkout={token}'
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
#### Development Configuration
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
interface ILiquidCommerceElementsDevelopmentConfig {
|
|
215
|
+
customApiUrl?: string;
|
|
216
|
+
openShadowDom?: boolean;
|
|
217
|
+
mockMode?: boolean; // enable mock data responses (sends 'X-Liquid-Api-Mock-Mode' header)
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**Example:**
|
|
222
|
+
|
|
223
|
+
```javascript
|
|
224
|
+
development: {
|
|
225
|
+
customApiUrl: 'http://localhost:3000/api',
|
|
226
|
+
openShadowDom: true // Use an OPEN (inspectable) Shadow DOM instead of the default closed mode; forced off in production
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Global Access
|
|
231
|
+
|
|
232
|
+
After initialization, each client is available globally under the `window.LiquidCommerce` namespace:
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
window.LiquidCommerce.elements // full client (from Elements())
|
|
236
|
+
window.LiquidCommerce.elementsBuilder // builder client (from ElementsBuilder())
|
|
237
|
+
window.LiquidCommerce.elementsCheckout // checkout-only client (from ElementsCheckout())
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
This allows access from anywhere in your application:
|
|
241
|
+
|
|
242
|
+
```javascript
|
|
243
|
+
// From any script
|
|
244
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Client Ready Event
|
|
248
|
+
|
|
249
|
+
Listen for client initialization:
|
|
250
|
+
|
|
251
|
+
```javascript
|
|
252
|
+
window.addEventListener('lce:actions.client_ready', ( event ) => {
|
|
253
|
+
const { isReady, version, timestamp } = event.detail.data;
|
|
254
|
+
|
|
255
|
+
console.log(`Elements SDK v${version} ready`);
|
|
256
|
+
|
|
257
|
+
// Safe to use client
|
|
258
|
+
window.LiquidCommerce.elements.injectProductElement([...]);
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Client Interface
|
|
263
|
+
|
|
264
|
+
### ILiquidCommerceElementsClient
|
|
265
|
+
|
|
266
|
+
The main client interface:
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
interface ILiquidCommerceElementsClient {
|
|
270
|
+
// Injection methods
|
|
271
|
+
injectProductElement(params: IInjectProductElement[]): Promise<IInjectedComponent[]>;
|
|
272
|
+
|
|
273
|
+
injectAddressElement(containerId: string, options?: IAddressOptions): Promise<IInjectedComponent | null>;
|
|
274
|
+
|
|
275
|
+
injectCartElement(containerId: string): Promise<IInjectedComponent | null>;
|
|
276
|
+
|
|
277
|
+
injectCheckoutElement(params: IInjectCheckoutParams): Promise<IInjectedComponent | null>;
|
|
278
|
+
|
|
279
|
+
injectProductList(params: IInjectProductListParams): Promise<void>;
|
|
280
|
+
|
|
281
|
+
injectProductListSearch(params: IInjectProductListSearchParams): Promise<void>;
|
|
282
|
+
|
|
283
|
+
injectProductListFilters(params: IInjectProductListFiltersParams): Promise<void>;
|
|
284
|
+
|
|
285
|
+
// UI methods
|
|
286
|
+
ui: ILiquidCommerceElementsUIMethod;
|
|
287
|
+
|
|
288
|
+
// Actions
|
|
289
|
+
actions: ILiquidCommerceElementsActions;
|
|
290
|
+
|
|
291
|
+
// Component management
|
|
292
|
+
getInjectedComponents(): Map<string, IInjectedComponent>;
|
|
293
|
+
|
|
294
|
+
// Cleanup
|
|
295
|
+
destroy(): void;
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Methods Overview
|
|
300
|
+
|
|
301
|
+
### Injection Methods
|
|
302
|
+
|
|
303
|
+
- `injectProductElement()` - Inject product displays
|
|
304
|
+
- `injectAddressElement()` - Inject address input
|
|
305
|
+
- `injectCartElement()` - Inject cart (rarely needed)
|
|
306
|
+
- `injectCheckoutElement()` - Inject checkout
|
|
307
|
+
- `injectProductList()` - Inject product catalog
|
|
308
|
+
- `injectProductListSearch()` - Inject search box
|
|
309
|
+
- `injectProductListFilters()` - Inject filter panel
|
|
310
|
+
|
|
311
|
+
See [Injection Methods](./injection-methods.md) for details.
|
|
312
|
+
|
|
313
|
+
### UI Methods
|
|
314
|
+
|
|
315
|
+
- `ui.cartButton()` - Add cart button
|
|
316
|
+
- `ui.floatingCartButton()` - Add floating cart button
|
|
317
|
+
- `ui.cartSubtotal()` - Display cart subtotal
|
|
318
|
+
- `ui.cartItemsCount()` - Display item count
|
|
319
|
+
|
|
320
|
+
See [UI Helpers](./ui-helpers.md) for details.
|
|
321
|
+
|
|
322
|
+
### Actions
|
|
323
|
+
|
|
324
|
+
- `actions.product.*` - Product actions
|
|
325
|
+
- `actions.address.*` - Address actions
|
|
326
|
+
- `actions.cart.*` - Cart actions
|
|
327
|
+
- `actions.checkout.*` - Checkout actions
|
|
328
|
+
|
|
329
|
+
See [Actions](./actions/) for details.
|
|
330
|
+
|
|
331
|
+
### Component Management
|
|
332
|
+
|
|
333
|
+
```javascript
|
|
334
|
+
// Get all injected components
|
|
335
|
+
const components = client.getInjectedComponents();
|
|
336
|
+
|
|
337
|
+
// Get specific component
|
|
338
|
+
const productComponent = components.get('product-1');
|
|
339
|
+
|
|
340
|
+
// Component methods
|
|
341
|
+
productComponent.getType(); // 'product'
|
|
342
|
+
productComponent.getElement(); // <div id="product-1">...</div>
|
|
343
|
+
productComponent.rerender(); // Force rerender
|
|
344
|
+
productComponent.destroy(); // Remove from DOM and clean up
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### destroy()
|
|
348
|
+
|
|
349
|
+
Remove the client and all injected components, cleaning up event listeners and internal state.
|
|
350
|
+
|
|
351
|
+
```javascript
|
|
352
|
+
client.destroy();
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Error Handling
|
|
356
|
+
|
|
357
|
+
### SDKError
|
|
358
|
+
|
|
359
|
+
All SDK errors use the custom `SDKError` class:
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
class SDKError extends Error {
|
|
363
|
+
constructor(message: string, reThrow?: boolean);
|
|
364
|
+
|
|
365
|
+
name: 'SDKError';
|
|
366
|
+
isSdk: boolean;
|
|
367
|
+
reThrow: boolean;
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
### Catching Errors
|
|
371
|
+
|
|
372
|
+
```javascript
|
|
373
|
+
try {
|
|
374
|
+
await client.injectProductElement([
|
|
375
|
+
{ containerId: 'product', identifier: 'invalid_id' }
|
|
376
|
+
]);
|
|
377
|
+
} catch (error) {
|
|
378
|
+
if (error.name === 'SDKError') {
|
|
379
|
+
console.error('SDK Error:', error);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Error Isolation
|
|
385
|
+
|
|
386
|
+
The SDK catches and contains its own errors:
|
|
387
|
+
|
|
388
|
+
```javascript
|
|
389
|
+
// Even if SDK throws, your app continues
|
|
390
|
+
window.LiquidCommerce.elements.actions.cart.addProduct([/* invalid */]);
|
|
391
|
+
|
|
392
|
+
// Your code still runs
|
|
393
|
+
console.log('App still working');
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
## TypeScript Support
|
|
397
|
+
|
|
398
|
+
### Importing Types
|
|
399
|
+
|
|
400
|
+
```typescript
|
|
401
|
+
import { Elements } from '@liquidcommerce/elements-sdk';
|
|
402
|
+
import type {
|
|
403
|
+
ILiquidCommerceElementsClient,
|
|
404
|
+
ILiquidCommerceElementsConfig,
|
|
405
|
+
IInjectProductElement,
|
|
406
|
+
IInjectedComponent
|
|
407
|
+
} from '@liquidcommerce/elements-sdk';
|
|
408
|
+
|
|
409
|
+
const config: ILiquidCommerceElementsConfig = {
|
|
410
|
+
env: 'production'
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
const client: ILiquidCommerceElementsClient = await Elements('KEY', config);
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### Type Exports
|
|
417
|
+
|
|
418
|
+
All public interfaces are exported from the main package:
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
import type {
|
|
422
|
+
// Client types
|
|
423
|
+
ILiquidCommerceElementsClient,
|
|
424
|
+
ILiquidCommerceElementsConfig,
|
|
425
|
+
|
|
426
|
+
// Injection types
|
|
427
|
+
IInjectProductElement,
|
|
428
|
+
IInjectCheckoutParams,
|
|
429
|
+
IInjectedComponent,
|
|
430
|
+
|
|
431
|
+
// Configuration types
|
|
432
|
+
IClientCustomThemeConfig,
|
|
433
|
+
IComponentGlobalConfigs,
|
|
434
|
+
IProductComponent,
|
|
435
|
+
ICartComponent,
|
|
436
|
+
ICheckoutComponent,
|
|
437
|
+
IAddressComponent,
|
|
438
|
+
|
|
439
|
+
// Enum types
|
|
440
|
+
ElementsEnv,
|
|
441
|
+
DebugMode,
|
|
442
|
+
FulfillmentType,
|
|
443
|
+
ComponentType
|
|
444
|
+
} from '@liquidcommerce/elements-sdk';
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
See [TypeScript Types](./typescript-types.md) for complete type reference.
|
|
448
|
+
|
|
449
|
+
## Best Practices
|
|
450
|
+
|
|
451
|
+
### Single Client Instance
|
|
452
|
+
|
|
453
|
+
Create one client instance and reuse it:
|
|
454
|
+
|
|
455
|
+
```javascript
|
|
456
|
+
// Good
|
|
457
|
+
const client = await Elements('KEY', { env: 'production' });
|
|
458
|
+
await client.injectProductElement([...]);
|
|
459
|
+
await client.injectCartElement('cart');
|
|
460
|
+
|
|
461
|
+
// Bad - creates multiple instances
|
|
462
|
+
await Elements('KEY', { env: 'production' });
|
|
463
|
+
await Elements('KEY', { env: 'production' });
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### Use Global Access
|
|
467
|
+
|
|
468
|
+
After initialization, use `window.LiquidCommerce.elements`:
|
|
469
|
+
|
|
470
|
+
```javascript
|
|
471
|
+
// Initialize once
|
|
472
|
+
await Elements('KEY', { env: 'production' });
|
|
473
|
+
|
|
474
|
+
// Use globally
|
|
475
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
476
|
+
window.LiquidCommerce.elements.ui.cartButton('cart-btn');
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### Check Client Ready
|
|
480
|
+
|
|
481
|
+
Wait for client ready before using:
|
|
482
|
+
|
|
483
|
+
```javascript
|
|
484
|
+
if (window.LiquidCommerce?.elements) {
|
|
485
|
+
// Client is ready
|
|
486
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
487
|
+
} else {
|
|
488
|
+
// Wait for client ready
|
|
489
|
+
window.addEventListener('lce:actions.client_ready', () => {
|
|
490
|
+
window.LiquidCommerce.elements.actions.cart.openCart();
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
### Handle Initialization Failures
|
|
496
|
+
|
|
497
|
+
```javascript
|
|
498
|
+
const client = await Elements('KEY', { env: 'production' });
|
|
499
|
+
|
|
500
|
+
if (!client) {
|
|
501
|
+
console.error('Failed to initialize Elements SDK');
|
|
502
|
+
// Show fallback UI or error message
|
|
503
|
+
showErrorPage();
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Client initialized successfully
|
|
508
|
+
await client.injectProductElement([...]);
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
## See Also
|
|
512
|
+
|
|
513
|
+
- [Injection Methods](./injection-methods.md) - Component injection API
|
|
514
|
+
- [UI Helpers](./ui-helpers.md) - UI helper methods
|
|
515
|
+
- [Actions](./actions/) - Action APIs
|
|
516
|
+
- [Configuration](./configuration.md) - Configuration options
|
|
517
|
+
- [TypeScript Types](./typescript-types.md) - Type definitions
|