@liquidcommerce/elements-sdk 2.4.0 → 2.4.2
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 +107 -40
- package/dist/index.esm.js +9893 -9243
- package/dist/types/core/client/client-action.service.d.ts +3 -2
- package/dist/types/core/pubsub/interfaces/cart.interface.d.ts +1 -0
- package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +46 -6
- package/dist/types/core/pubsub/interfaces/product.interface.d.ts +43 -1
- package/dist/types/core/singleton-manager.service.d.ts +3 -3
- package/dist/types/core/store/interfaces/cart.interface.d.ts +1 -0
- package/dist/types/core/store/interfaces/product.interface.d.ts +18 -6
- package/dist/types/elements-base-client.d.ts +49 -0
- package/dist/types/elements-builder-client.d.ts +2 -0
- package/dist/types/elements-client-helper.d.ts +3 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.umd.d.ts +2 -2
- package/dist/types/interfaces/cloud/product.interface.d.ts +2 -0
- package/dist/types/interfaces/configs/checkout.interface.d.ts +1 -1
- package/dist/types/interfaces/core.interface.d.ts +32 -17
- package/dist/types/modules/cart/components/index.d.ts +2 -0
- package/dist/types/modules/theme-provider/services/font-manager.service.d.ts +1 -0
- package/dist/types/modules/ui-components/lce-element/lce-element.component.d.ts +2 -0
- package/docs/ACTIONS.md +86 -48
- package/docs/CONFIGURATION.md +134 -10
- package/docs/EVENTS.md +270 -37
- package/docs/TROUBLESHOOTING.md +19 -2
- package/package.json +6 -6
- package/umd/elements.js +1 -1
package/README.md
CHANGED
|
@@ -207,8 +207,7 @@ By default, you get a floating cart button. Here's how to customize it:
|
|
|
207
207
|
data-liquid-commerce-elements
|
|
208
208
|
data-token="YOUR_API_KEY"
|
|
209
209
|
data-env="production"
|
|
210
|
-
data-cart-
|
|
211
|
-
data-show-cart-items
|
|
210
|
+
data-cart-badge-button="header-cart"
|
|
212
211
|
src="https://assets-elements.liquidcommerce.us/all/elements.js"
|
|
213
212
|
></script>
|
|
214
213
|
```
|
|
@@ -220,7 +219,7 @@ By default, you get a floating cart button. Here's how to customize it:
|
|
|
220
219
|
data-liquid-commerce-elements
|
|
221
220
|
data-token="YOUR_API_KEY"
|
|
222
221
|
data-env="production"
|
|
223
|
-
data-
|
|
222
|
+
data-cart-button-hidden
|
|
224
223
|
src="https://assets-elements.liquidcommerce.us/all/elements.js"
|
|
225
224
|
></script>
|
|
226
225
|
```
|
|
@@ -324,9 +323,15 @@ Here's every available data attribute:
|
|
|
324
323
|
data-env="production|staging|development|local"
|
|
325
324
|
|
|
326
325
|
<!-- Cart Button -->
|
|
327
|
-
data-cart-
|
|
328
|
-
data-
|
|
329
|
-
data-
|
|
326
|
+
data-cart-button="container-id"
|
|
327
|
+
data-cart-badge-button="container-id"
|
|
328
|
+
data-cart-button-hidden
|
|
329
|
+
|
|
330
|
+
<!-- Cart Button with Position Prefixes -->
|
|
331
|
+
data-cart-button="above:.logo"
|
|
332
|
+
data-cart-badge-button="below:#header"
|
|
333
|
+
data-cart-button="inside:.nav"
|
|
334
|
+
data-cart-badge-button="replace:.old-cart"
|
|
330
335
|
|
|
331
336
|
<!-- Products (Method 1: Direct) -->
|
|
332
337
|
data-container-1="div-id"
|
|
@@ -392,7 +397,7 @@ pnpm add @liquidcommerce/elements-sdk
|
|
|
392
397
|
});
|
|
393
398
|
|
|
394
399
|
// Inject components
|
|
395
|
-
await client.injectProductElement([
|
|
400
|
+
const components = await client.injectProductElement([
|
|
396
401
|
{ containerId: 'pdp-1', identifier: '00619947000020' }
|
|
397
402
|
]);
|
|
398
403
|
|
|
@@ -559,15 +564,20 @@ promoTicker: [
|
|
|
559
564
|
|
|
560
565
|
### Component Injection
|
|
561
566
|
|
|
562
|
-
Inject SDK components into your page containers.
|
|
567
|
+
Inject SDK components into your page containers. All injection methods return wrapper objects that provide component control.
|
|
563
568
|
|
|
564
569
|
#### Products
|
|
565
570
|
|
|
566
571
|
```js
|
|
567
|
-
await client.injectProductElement([
|
|
572
|
+
const components = await client.injectProductElement([
|
|
568
573
|
{ containerId: 'pdp-1', identifier: '00619947000020' },
|
|
569
574
|
{ containerId: 'pdp-2', identifier: '00832889005513' }
|
|
570
575
|
]);
|
|
576
|
+
|
|
577
|
+
// Returns: IInjectedComponent[] - Array of component wrappers
|
|
578
|
+
// components[0].rerender() - Rerender the first component
|
|
579
|
+
// components[0].getElement() - Get the container element
|
|
580
|
+
// components[0].getType() - Get component type
|
|
571
581
|
```
|
|
572
582
|
|
|
573
583
|
**Identifier types:** UPC, product ID, or Salsify grouping ID
|
|
@@ -575,7 +585,12 @@ await client.injectProductElement([
|
|
|
575
585
|
#### Cart
|
|
576
586
|
|
|
577
587
|
```js
|
|
578
|
-
await client.injectCartElement('cart-container');
|
|
588
|
+
const component = await client.injectCartElement('cart-container');
|
|
589
|
+
|
|
590
|
+
// Returns: IInjectedComponent | null - Component wrapper or null if failed
|
|
591
|
+
// component.rerender() - Rerender the component
|
|
592
|
+
// component.getElement() - Get the container element
|
|
593
|
+
// component.getType() - Get component type
|
|
579
594
|
```
|
|
580
595
|
|
|
581
596
|
**Use case:** Dedicated cart page
|
|
@@ -583,7 +598,12 @@ await client.injectCartElement('cart-container');
|
|
|
583
598
|
#### Checkout
|
|
584
599
|
|
|
585
600
|
```js
|
|
586
|
-
await client.injectCheckoutElement('checkout-container');
|
|
601
|
+
const component = await client.injectCheckoutElement('checkout-container');
|
|
602
|
+
|
|
603
|
+
// Returns: IInjectedComponent | null - Component wrapper or null if failed
|
|
604
|
+
// component.rerender() - Rerender the component
|
|
605
|
+
// component.getElement() - Get the container element
|
|
606
|
+
// component.getType() - Get component type
|
|
587
607
|
```
|
|
588
608
|
|
|
589
609
|
**Use case:** Dedicated checkout page
|
|
@@ -591,11 +611,51 @@ await client.injectCheckoutElement('checkout-container');
|
|
|
591
611
|
#### Address
|
|
592
612
|
|
|
593
613
|
```js
|
|
594
|
-
await client.injectAddressElement('address-container');
|
|
614
|
+
const component = await client.injectAddressElement('address-container');
|
|
615
|
+
|
|
616
|
+
// Returns: IInjectedComponent | null - Component wrapper or null if failed
|
|
617
|
+
// component.rerender() - Rerender the component
|
|
618
|
+
// component.getElement() - Get the container element
|
|
619
|
+
// component.getType() - Get component type
|
|
595
620
|
```
|
|
596
621
|
|
|
597
622
|
**Use case:** Shipping address collection page
|
|
598
623
|
|
|
624
|
+
#### Access All Injected Components
|
|
625
|
+
|
|
626
|
+
```js
|
|
627
|
+
// Get all injected components
|
|
628
|
+
const injectedComponents = client.getInjectedComponents();
|
|
629
|
+
|
|
630
|
+
// Access specific components by container ID
|
|
631
|
+
const productComponent = injectedComponents.get('product-container-1');
|
|
632
|
+
const cartComponent = injectedComponents.get('cart-container');
|
|
633
|
+
|
|
634
|
+
// Iterate through all components
|
|
635
|
+
injectedComponents.forEach((component, containerId) => {
|
|
636
|
+
console.log(`Container: ${containerId}, Type: ${component.getType()}`);
|
|
637
|
+
|
|
638
|
+
// Rerender specific components
|
|
639
|
+
if (component.getType() === 'product') {
|
|
640
|
+
component.rerender();
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
// Get all components of a specific type
|
|
645
|
+
const productComponents = Array.from(injectedComponents.values())
|
|
646
|
+
.filter(component => component.getType() === 'product');
|
|
647
|
+
|
|
648
|
+
// Rerender all components of a type
|
|
649
|
+
productComponents.forEach(component => component.rerender());
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
**Returns:** `Map<string, IInjectedComponent>` - Map of container IDs to component wrappers
|
|
653
|
+
|
|
654
|
+
**Use cases:**
|
|
655
|
+
- Debugging and inspecting injected components
|
|
656
|
+
- Bulk operations on multiple components
|
|
657
|
+
- Component management and cleanup
|
|
658
|
+
|
|
599
659
|
### UI Helpers
|
|
600
660
|
|
|
601
661
|
Create standalone UI elements that integrate with the SDK.
|
|
@@ -661,10 +721,12 @@ client.builder.updateCheckoutComponent(checkoutTheme);
|
|
|
661
721
|
client.builder.updateAddressComponent(addressTheme);
|
|
662
722
|
|
|
663
723
|
// Builder injection methods (same as regular methods)
|
|
664
|
-
await client.builder.injectProductElement(params);
|
|
665
|
-
await client.builder.injectCartElement(containerId);
|
|
666
|
-
await client.builder.injectCheckoutElement(containerId);
|
|
667
|
-
await client.builder.injectAddressElement(containerId);
|
|
724
|
+
const components = await client.builder.injectProductElement(params);
|
|
725
|
+
const component = await client.builder.injectCartElement(containerId);
|
|
726
|
+
const checkoutComponent = await client.builder.injectCheckoutElement(containerId);
|
|
727
|
+
const addressComponent = await client.builder.injectAddressElement(containerId);
|
|
728
|
+
|
|
729
|
+
// All return IInjectedComponent wrapper objects with rerender(), getElement(), getType() methods
|
|
668
730
|
```
|
|
669
731
|
|
|
670
732
|
## 🎬 Actions
|
|
@@ -683,7 +745,8 @@ const actions = window.elements.actions;
|
|
|
683
745
|
```js
|
|
684
746
|
// Get product details
|
|
685
747
|
const product = actions.product.getDetails('product-123');
|
|
686
|
-
console.log(product.
|
|
748
|
+
console.log(product.name, product.brand, product.region, product.variety);
|
|
749
|
+
console.log(product.priceInfo, product.description, product.tastingNotes);
|
|
687
750
|
```
|
|
688
751
|
|
|
689
752
|
### Address Actions
|
|
@@ -784,7 +847,7 @@ await actions.cart.removePromoCode();
|
|
|
784
847
|
|
|
785
848
|
// Get cart details
|
|
786
849
|
const cart = actions.cart.getDetails();
|
|
787
|
-
console.log(cart.total, cart.
|
|
850
|
+
console.log(cart.itemCount, cart.amounts.total, cart.amounts.giftCardTotal);
|
|
788
851
|
|
|
789
852
|
// Reset cart
|
|
790
853
|
await actions.cart.resetCart();
|
|
@@ -856,12 +919,10 @@ window.addEventListener('lce:actions.checkout_gift_card_failed', function(event)
|
|
|
856
919
|
|
|
857
920
|
// Get checkout details (safe, non-sensitive data only)
|
|
858
921
|
const checkout = actions.checkout.getDetails();
|
|
859
|
-
console.log(
|
|
860
|
-
console.log(
|
|
861
|
-
console.log(
|
|
862
|
-
console.log(
|
|
863
|
-
console.log('Has promo code:', checkout.hasPromoCode);
|
|
864
|
-
console.log('Has gift cards:', checkout.hasGiftCards);
|
|
922
|
+
console.log(checkout.itemCount, checkout.amounts.total, checkout.isGift);
|
|
923
|
+
console.log(checkout.hasAgeVerify, checkout.hasPromoCode, checkout.hasGiftCards);
|
|
924
|
+
console.log(checkout.acceptedAccountCreation, checkout.billingSameAsShipping);
|
|
925
|
+
console.log(checkout.marketingPreferences);
|
|
865
926
|
|
|
866
927
|
// Configure checkout options
|
|
867
928
|
await actions.checkout.toggleBillingSameAsShipping(true);
|
|
@@ -877,13 +938,14 @@ The SDK emits real-time events for all user interactions. Listen to these events
|
|
|
877
938
|
```js
|
|
878
939
|
// Listen for specific events
|
|
879
940
|
window.addEventListener('lce:actions.product_add_to_cart', function(event) {
|
|
880
|
-
const
|
|
881
|
-
console.log('Added to cart:',
|
|
941
|
+
const data = event.detail.data;
|
|
942
|
+
console.log('Added to cart:', data.identifier);
|
|
882
943
|
|
|
883
944
|
// Your custom logic here
|
|
884
945
|
analytics.track('Product Added', {
|
|
885
|
-
|
|
886
|
-
|
|
946
|
+
identifier: data.identifier,
|
|
947
|
+
quantity: data.quantity,
|
|
948
|
+
upc: data.upc
|
|
887
949
|
});
|
|
888
950
|
});
|
|
889
951
|
|
|
@@ -900,7 +962,7 @@ window.elements.onAllActions((data, metadata) => {
|
|
|
900
962
|
### Available Events
|
|
901
963
|
|
|
902
964
|
#### Product Events
|
|
903
|
-
- `lce:actions.product_loaded` - Product component loaded
|
|
965
|
+
- `lce:actions.product_loaded` - Product component loaded with comprehensive product details (region, country, abv, proof, age, variety, vintage, descriptions, tasting notes)
|
|
904
966
|
- `lce:actions.product_add_to_cart` - Item added to cart
|
|
905
967
|
- `lce:actions.product_quantity_increase` - Quantity increased
|
|
906
968
|
- `lce:actions.product_quantity_decrease` - Quantity decreased
|
|
@@ -908,6 +970,7 @@ window.elements.onAllActions((data, metadata) => {
|
|
|
908
970
|
- `lce:actions.product_fulfillment_type_changed` - Delivery method changed
|
|
909
971
|
|
|
910
972
|
#### Cart Events
|
|
973
|
+
- `lce:actions.cart_loaded` - Cart data loaded with complete cart information (itemCount, all amounts including giftCardTotal, detailed item data)
|
|
911
974
|
- `lce:actions.cart_opened` - Cart displayed
|
|
912
975
|
- `lce:actions.cart_closed` - Cart hidden
|
|
913
976
|
- `lce:actions.cart_updated` - Cart contents changed
|
|
@@ -916,6 +979,7 @@ window.elements.onAllActions((data, metadata) => {
|
|
|
916
979
|
- `lce:actions.cart_reset` - Cart cleared
|
|
917
980
|
|
|
918
981
|
#### Checkout Events
|
|
982
|
+
- `lce:actions.checkout_loaded` - Checkout data loaded with comprehensive details (acceptedAccountCreation, hasSubstitutionPolicy, billingSameAsShipping, marketing preferences, detailed items)
|
|
919
983
|
- `lce:actions.checkout_opened` - Checkout started
|
|
920
984
|
- `lce:actions.checkout_closed` - Checkout abandoned
|
|
921
985
|
- `lce:actions.checkout_submit_started` - Order submission began
|
|
@@ -928,7 +992,7 @@ window.elements.onAllActions((data, metadata) => {
|
|
|
928
992
|
- `lce:actions.address_updated` - Address information changed
|
|
929
993
|
- `lce:actions.address_cleared` - Address removed
|
|
930
994
|
|
|
931
|
-
See [`docs/EVENTS.md`](docs/EVENTS.md) for complete event reference with implementation examples.
|
|
995
|
+
See [`docs/EVENTS.md`](docs/EVENTS.md) for complete event reference with all available fields and implementation examples.
|
|
932
996
|
|
|
933
997
|
## 🎨 Themes & Customization
|
|
934
998
|
|
|
@@ -1376,11 +1440,12 @@ The SDK uses a centralized store for all state management. Access state data via
|
|
|
1376
1440
|
```js
|
|
1377
1441
|
// Get current cart state
|
|
1378
1442
|
const cart = await client.actions.cart.getDetails();
|
|
1379
|
-
console.log(cart.
|
|
1443
|
+
console.log(cart.itemCount, cart.amounts.total, cart.amounts.giftCardTotal);
|
|
1380
1444
|
|
|
1381
1445
|
// Get current checkout state
|
|
1382
1446
|
const checkout = await client.actions.checkout.getDetails();
|
|
1383
|
-
console.log(checkout.total, checkout.
|
|
1447
|
+
console.log(checkout.amounts.total, checkout.isGift, checkout.acceptedAccountCreation);
|
|
1448
|
+
console.log(checkout.billingSameAsShipping, checkout.marketingPreferences);
|
|
1384
1449
|
|
|
1385
1450
|
// Get current address
|
|
1386
1451
|
const address = await client.actions.address.getDetails();
|
|
@@ -1388,7 +1453,8 @@ console.log(address.formattedAddress, address.coordinates);
|
|
|
1388
1453
|
|
|
1389
1454
|
// Get product details
|
|
1390
1455
|
const product = await client.actions.product.getDetails('00619947000020');
|
|
1391
|
-
console.log(product.name, product.
|
|
1456
|
+
console.log(product.name, product.region, product.variety, product.vintage);
|
|
1457
|
+
console.log(product.description, product.tastingNotes);
|
|
1392
1458
|
```
|
|
1393
1459
|
|
|
1394
1460
|
**State is persistent:** Cart and address data persist across page reloads using localStorage.
|
|
@@ -1400,8 +1466,8 @@ All SDK interactions emit events through a centralized event system:
|
|
|
1400
1466
|
```js
|
|
1401
1467
|
// Subscribe to specific event
|
|
1402
1468
|
window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
1403
|
-
const
|
|
1404
|
-
console.log('Cart changed
|
|
1469
|
+
const { previous, current } = event.detail.data;
|
|
1470
|
+
console.log('Cart changed from', previous.amounts.total, 'to', current.amounts.total);
|
|
1405
1471
|
});
|
|
1406
1472
|
|
|
1407
1473
|
// Subscribe to all action events
|
|
@@ -1579,9 +1645,10 @@ Components are created on-demand using a factory pattern:
|
|
|
1579
1645
|
|
|
1580
1646
|
```js
|
|
1581
1647
|
// When you call:
|
|
1582
|
-
await client.injectProductElement([
|
|
1648
|
+
const components = await client.injectProductElement([
|
|
1583
1649
|
{ containerId: 'pdp-1', identifier: 'product-123' }
|
|
1584
1650
|
]);
|
|
1651
|
+
// Returns: IInjectedComponent[] - Array of component wrappers
|
|
1585
1652
|
|
|
1586
1653
|
// The SDK:
|
|
1587
1654
|
// 1. Creates a ProductComponent instance
|
|
@@ -1713,7 +1780,7 @@ export default function ProductPage({ productId }: { productId: string }) {
|
|
|
1713
1780
|
env: 'production'
|
|
1714
1781
|
});
|
|
1715
1782
|
|
|
1716
|
-
await client.injectProductElement([
|
|
1783
|
+
const components = await client.injectProductElement([
|
|
1717
1784
|
{ containerId: 'product-container', identifier: productId }
|
|
1718
1785
|
]);
|
|
1719
1786
|
|
|
@@ -1785,7 +1852,7 @@ await client.injectProductElement([
|
|
|
1785
1852
|
|
|
1786
1853
|
// cart-page.js
|
|
1787
1854
|
const client = await getElementsClient();
|
|
1788
|
-
await client.injectCartElement('cart-container');
|
|
1855
|
+
const cartComponent = await client.injectCartElement('cart-container');
|
|
1789
1856
|
```
|
|
1790
1857
|
|
|
1791
1858
|
---
|
|
@@ -2074,7 +2141,7 @@ await client.actions.cart.addProduct([...]);
|
|
|
2074
2141
|
// ❌ Don't repeatedly fetch the same data
|
|
2075
2142
|
async function showCartTotal() {
|
|
2076
2143
|
const cart = await client.actions.cart.getDetails();
|
|
2077
|
-
return cart.total;
|
|
2144
|
+
return cart.amounts.total;
|
|
2078
2145
|
}
|
|
2079
2146
|
|
|
2080
2147
|
// ✅ Use UI helpers that auto-update
|
|
@@ -2084,7 +2151,7 @@ client.ui.cartItemsCount('cart-count-display');
|
|
|
2084
2151
|
// Or cache and listen to updates
|
|
2085
2152
|
let cachedCart = await client.actions.cart.getDetails();
|
|
2086
2153
|
window.addEventListener('lce:actions.cart_updated', (event) => {
|
|
2087
|
-
cachedCart = event.detail.data;
|
|
2154
|
+
cachedCart = event.detail.data.current;
|
|
2088
2155
|
});
|
|
2089
2156
|
```
|
|
2090
2157
|
|