@liquidcommerce/elements-sdk 2.7.0 → 2.7.1

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 (76) hide show
  1. package/README.md +83 -2750
  2. package/dist/index.checkout.esm.js +6877 -6825
  3. package/dist/index.esm.js +11384 -10940
  4. package/dist/types/auto-initialize/shared-utils.d.ts +5 -0
  5. package/dist/types/constants/core.constant.d.ts +0 -4
  6. package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +1 -0
  7. package/dist/types/enums/core.enum.d.ts +11 -0
  8. package/dist/types/interfaces/configs/product-list.interface.d.ts +2 -2
  9. package/dist/types/modules/address/address-input.component.d.ts +11 -0
  10. package/dist/types/modules/product-list/components/card-components/index.d.ts +3 -0
  11. package/dist/types/modules/product-list/components/card-components/product-badge.d.ts +8 -0
  12. package/dist/types/modules/product-list/components/card-components/product-fulfillments.d.ts +2 -0
  13. package/dist/types/modules/product-list/components/card-components/product-price-and-personalization.d.ts +13 -0
  14. package/dist/types/modules/product-list/components/card-components/product-title.d.ts +6 -0
  15. package/dist/types/modules/product-list/components/index.d.ts +1 -0
  16. package/dist/types/modules/product-list/components/product-list-engraving.component.d.ts +5 -1
  17. package/dist/types/modules/product-list/components/product-list-product-pre-cart.component.d.ts +28 -0
  18. package/dist/types/modules/product-list/components/product-list-retailers.component.d.ts +10 -2
  19. package/dist/types/modules/product-list/product-list-card.component.d.ts +0 -5
  20. package/dist/types/modules/product-list/product-list.commands.d.ts +11 -2
  21. package/dist/types/modules/product-list/product-list.interface.d.ts +1 -0
  22. package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +11 -2
  23. package/docs/gitbook/actions.md +160 -0
  24. package/docs/gitbook/address.md +48 -0
  25. package/docs/gitbook/cart.md +65 -0
  26. package/docs/gitbook/checkout.md +131 -0
  27. package/docs/gitbook/events.md +137 -0
  28. package/docs/gitbook/overview.md +166 -0
  29. package/docs/gitbook/product.md +64 -0
  30. package/docs/gitbook/quick-start-guide.md +393 -0
  31. package/docs/v1/README.md +210 -0
  32. package/docs/v1/api/actions/address-actions.md +281 -0
  33. package/docs/v1/api/actions/cart-actions.md +337 -0
  34. package/docs/v1/api/actions/checkout-actions.md +387 -0
  35. package/docs/v1/api/actions/product-actions.md +115 -0
  36. package/docs/v1/api/client.md +482 -0
  37. package/docs/v1/api/configuration.md +1 -0
  38. package/docs/v1/api/injection-methods.md +247 -0
  39. package/docs/v1/api/typescript-types.md +1 -0
  40. package/docs/v1/api/ui-helpers.md +200 -0
  41. package/docs/v1/examples/advanced-patterns.md +96 -0
  42. package/docs/v1/examples/checkout-flow.md +91 -0
  43. package/docs/v1/examples/custom-theming.md +63 -0
  44. package/docs/v1/examples/multi-product-page.md +90 -0
  45. package/docs/v1/examples/simple-product-page.md +89 -0
  46. package/docs/v1/getting-started/concepts.md +507 -0
  47. package/docs/v1/getting-started/installation.md +328 -0
  48. package/docs/v1/getting-started/quick-start.md +405 -0
  49. package/docs/v1/guides/address-component.md +431 -0
  50. package/docs/v1/guides/best-practices.md +324 -0
  51. package/docs/v1/guides/cart-component.md +737 -0
  52. package/docs/v1/guides/checkout-component.md +672 -0
  53. package/docs/v1/guides/events.md +191 -0
  54. package/docs/v1/guides/product-component.md +686 -0
  55. package/docs/v1/guides/product-list-component.md +598 -0
  56. package/docs/v1/guides/theming.md +216 -0
  57. package/docs/v1/integration/angular.md +39 -0
  58. package/docs/v1/integration/laravel.md +41 -0
  59. package/docs/v1/integration/nextjs.md +60 -0
  60. package/docs/v1/integration/proxy-setup.md +89 -0
  61. package/docs/v1/integration/react.md +64 -0
  62. package/docs/v1/integration/vanilla-js.md +84 -0
  63. package/docs/v1/integration/vue.md +34 -0
  64. package/docs/v1/reference/browser-support.md +35 -0
  65. package/docs/v1/reference/error-handling.md +70 -0
  66. package/docs/v1/reference/performance.md +54 -0
  67. package/docs/v1/reference/troubleshooting.md +64 -0
  68. package/package.json +1 -1
  69. package/docs/ACTIONS.md +0 -1301
  70. package/docs/BROWSER_SUPPORT.md +0 -279
  71. package/docs/CONFIGURATION.md +0 -997
  72. package/docs/DOCUMENTATION_INDEX.md +0 -319
  73. package/docs/EVENTS.md +0 -798
  74. package/docs/PROXY.md +0 -228
  75. package/docs/THEMING.md +0 -681
  76. package/docs/TROUBLESHOOTING.md +0 -793
@@ -0,0 +1,281 @@
1
+ # Address Actions API
2
+
3
+ Address actions allow you to programmatically manage the delivery location.
4
+
5
+ ## actions.address.setAddressByPlacesId()
6
+
7
+ Set address using a Google Places ID.
8
+
9
+ ### Signature
10
+
11
+ ```typescript
12
+ setAddressByPlacesId(placesId: string): Promise<void>
13
+ ```
14
+
15
+ ### Parameters
16
+
17
+ | Parameter | Type | Required | Description |
18
+ |-----------|------|----------|-------------|
19
+ | `placesId` | string | Yes | Google Places ID |
20
+
21
+ ### Example
22
+
23
+ ```javascript
24
+ await window.elements.actions.address.setAddressByPlacesId(
25
+ 'ChIJOwg_06VPwokRYv534QaPC8g'
26
+ );
27
+ ```
28
+
29
+ ### How to Get Places ID
30
+
31
+ Visit [Google Place IDs](https://developers.google.com/maps/documentation/places/web-service/place-id#find-id) for details on obtaining a Places ID.
32
+
33
+ ---
34
+
35
+ ## actions.address.setAddressManually()
36
+
37
+ Set address manually without Google Places.
38
+
39
+ ### Signature
40
+
41
+ ```typescript
42
+ setAddressManually(
43
+ address: IAddressAddress,
44
+ coordinates: IAddressCoordinates
45
+ ): Promise<void>
46
+ ```
47
+
48
+ ### Parameters
49
+
50
+ ```typescript
51
+ interface IAddressAddress {
52
+ one: string; // Street address
53
+ two?: string; // Apt, suite, etc. (optional)
54
+ city: string; // City name
55
+ state: string; // Two-letter state code
56
+ zip: string; // ZIP/postal code
57
+ }
58
+
59
+ interface IAddressCoordinates {
60
+ latitude: number; // -90 to 90
61
+ longitude: number; // -180 to 180
62
+ }
63
+ ```
64
+
65
+ ### Example
66
+
67
+ ```javascript
68
+ await window.elements.actions.address.setAddressManually(
69
+ {
70
+ one: '123 Main Street',
71
+ two: 'Apt 4',
72
+ city: 'New York',
73
+ state: 'NY',
74
+ zip: '10001'
75
+ },
76
+ {
77
+ latitude: 40.7128,
78
+ longitude: -74.0060
79
+ }
80
+ );
81
+ ```
82
+
83
+ ### Validation
84
+
85
+ The SDK validates:
86
+ - All required fields are present
87
+ - State is 2-letter code
88
+ - Latitude is between -90 and 90
89
+ - Longitude is between -180 and 180
90
+
91
+ ### Errors
92
+
93
+ **Throws `SDKError` if:**
94
+ - Required fields are missing
95
+ - Coordinates are out of range
96
+ - Address format is invalid
97
+
98
+ ---
99
+
100
+ ## actions.address.clear()
101
+
102
+ Remove the current address.
103
+
104
+ ### Signature
105
+
106
+ ```typescript
107
+ clear(): Promise<void>
108
+ ```
109
+
110
+ ### Example
111
+
112
+ ```javascript
113
+ await window.elements.actions.address.clear();
114
+ ```
115
+
116
+ ### Effects
117
+
118
+ - Clears stored address
119
+ - Products will prompt for address on next add-to-cart
120
+ - Cart/checkout require re-entering address
121
+
122
+ ---
123
+
124
+ ## actions.address.getDetails()
125
+
126
+ Retrieve the current address.
127
+
128
+ ### Signature
129
+
130
+ ```typescript
131
+ getDetails(): IAddressData | null
132
+ ```
133
+
134
+ ### Returns
135
+
136
+ ```typescript
137
+ interface IAddressData {
138
+ id: string; // Google Places ID or generated ID
139
+ address: {
140
+ one: string;
141
+ two?: string;
142
+ city: string;
143
+ state: string;
144
+ zip: string;
145
+ };
146
+ coordinates: {
147
+ latitude: number;
148
+ longitude: number;
149
+ };
150
+ formattedAddress: string;
151
+ }
152
+ ```
153
+
154
+ Returns `null` if no address is set.
155
+
156
+ ### Example
157
+
158
+ ```javascript
159
+ const address = window.elements.actions.address.getDetails();
160
+
161
+ if (address) {
162
+ console.log('Current address:', address.formattedAddress);
163
+ console.log('Coordinates:', address.coordinates);
164
+ } else {
165
+ console.log('No address set');
166
+ }
167
+ ```
168
+
169
+ ### Use Cases
170
+
171
+ #### Check if Address is Set
172
+
173
+ ```javascript
174
+ if (!window.elements.actions.address.getDetails()) {
175
+ // Prompt user to set address
176
+ showAddressPrompt();
177
+ }
178
+ ```
179
+
180
+ #### Display Current Address
181
+
182
+ ```javascript
183
+ const address = window.elements.actions.address.getDetails();
184
+
185
+ if (address) {
186
+ document.getElementById('current-address').textContent =
187
+ address.formattedAddress;
188
+ }
189
+ ```
190
+ ## Events
191
+
192
+ Address actions trigger events:
193
+
194
+ ```javascript
195
+ // Address updated
196
+ window.addEventListener('lce:actions.address_updated', (event) => {
197
+ const { address, coordinates, formattedAddress } = event.detail.data;
198
+ console.log('Address set:', formattedAddress);
199
+ });
200
+
201
+ // Address cleared
202
+ window.addEventListener('lce:actions.address_cleared', () => {
203
+ console.log('Address cleared');
204
+ });
205
+
206
+ // Address failed
207
+ window.addEventListener('lce:actions.address_failed', (event) => {
208
+ console.error('Address error:', event.detail.data.error);
209
+ });
210
+ ```
211
+
212
+ ## Best Practices
213
+
214
+ ### Use Places ID When Available
215
+
216
+ Google Places provides accurate geocoding:
217
+
218
+ ```javascript
219
+ // Good - accurate and validated
220
+ await window.elements.actions.address.setAddressByPlacesId(placesId);
221
+
222
+ // Less ideal - requires manual geocoding
223
+ await window.elements.actions.address.setAddressManually(address, coords);
224
+ ```
225
+
226
+ ### Validate Manual Addresses
227
+
228
+ When using manual address entry:
229
+
230
+ ```javascript
231
+ async function setManualAddress(address, coords) {
232
+ // Validate format
233
+ if (!address.one || !address.city || !address.state || !address.zip) {
234
+ throw new Error('Missing required fields');
235
+ }
236
+
237
+ // Validate state
238
+ if (!/^[A-Z]{2}$/.test(address.state)) {
239
+ throw new Error('State must be 2-letter code');
240
+ }
241
+
242
+ // Validate ZIP
243
+ if (!/^\d{5}(-\d{4})?$/.test(address.zip)) {
244
+ throw new Error('Invalid ZIP code');
245
+ }
246
+
247
+ await window.elements.actions.address.setAddressManually(address, coords);
248
+ }
249
+ ```
250
+
251
+ ### Handle Errors
252
+
253
+ ```javascript
254
+ try {
255
+ await window.elements.actions.address.setAddressByPlacesId(placesId);
256
+ showSuccess('Address saved!');
257
+ } catch (error) {
258
+ console.error('Failed to set address:', error);
259
+ showError('Unable to set that address. Please try again.');
260
+ }
261
+ ```
262
+
263
+ ### Set Address Early
264
+
265
+ Set address as soon as possible in user flow:
266
+
267
+ ```javascript
268
+ window.addEventListener('lce:actions.client_ready', () => {
269
+ if (!window.elements.actions.address.getDetails()) {
270
+ // Prompt for address on first visit
271
+ showAddressModal();
272
+ }
273
+ });
274
+ ```
275
+
276
+ ## See Also
277
+
278
+ - [Address Component Guide](../../guides/address-component.md)
279
+ - [Address Events](../../guides/events.md#address-events)
280
+ - [Product Component](../../guides/product-component.md#address-requirement)
281
+ - [Cart Component](../../guides/cart-component.md#address-requirement)
@@ -0,0 +1,337 @@
1
+ # Cart Actions API
2
+
3
+ Cart actions allow you to programmatically control the shopping cart.
4
+
5
+ ## actions.cart.openCart()
6
+
7
+ Open the cart drawer.
8
+
9
+ ### Signature
10
+
11
+ ```typescript
12
+ openCart(): void
13
+ ```
14
+
15
+ ### Example
16
+
17
+ ```javascript
18
+ window.elements.actions.cart.openCart();
19
+ ```
20
+
21
+ ---
22
+
23
+ ## actions.cart.closeCart()
24
+
25
+ Close the cart drawer.
26
+
27
+ ### Signature
28
+
29
+ ```typescript
30
+ closeCart(): void
31
+ ```
32
+
33
+ ### Example
34
+
35
+ ```javascript
36
+ window.elements.actions.cart.closeCart();
37
+ ```
38
+
39
+ ---
40
+
41
+ ## actions.cart.toggleCart()
42
+
43
+ Toggle the cart drawer open/closed.
44
+
45
+ ### Signature
46
+
47
+ ```typescript
48
+ toggleCart(): void
49
+ ```
50
+
51
+ ### Example
52
+
53
+ ```javascript
54
+ // Add to your cart button
55
+ document.getElementById('cart-btn').addEventListener('click', () => {
56
+ window.elements.actions.cart.toggleCart();
57
+ });
58
+ ```
59
+
60
+ ---
61
+
62
+ ## actions.cart.addProduct()
63
+
64
+ Add products to the cart programmatically.
65
+
66
+ ### Signature
67
+
68
+ ```typescript
69
+ addProduct(params: IAddProductParams[], openCart?: boolean): Promise<void>
70
+ ```
71
+
72
+ ### Parameters
73
+
74
+ | Parameter | Type | Required | Description |
75
+ |-----------|------|----------|-------------|
76
+ | `params` | IAddProductParams[] | Yes | Array of products to add |
77
+ | `openCart` | boolean | No | Open cart after adding (default: false) |
78
+
79
+ ```typescript
80
+ interface IAddProductParams {
81
+ identifier: string; // Product UPC, SKU, or ID
82
+ fulfillmentType: FulfillmentType; // 'shipping' or 'onDemand'
83
+ quantity: number; // Number of items
84
+ }
85
+ ```
86
+
87
+ ### Example
88
+
89
+ ```javascript
90
+ // Add single product
91
+ await window.elements.actions.cart.addProduct([
92
+ {
93
+ identifier: '00619947000020',
94
+ fulfillmentType: 'shipping',
95
+ quantity: 1
96
+ }
97
+ ], true); // Open cart after adding
98
+
99
+ // Add multiple products
100
+ await window.elements.actions.cart.addProduct([
101
+ {
102
+ identifier: '00619947000020',
103
+ fulfillmentType: 'shipping',
104
+ quantity: 2
105
+ },
106
+ {
107
+ identifier: '08504405135',
108
+ fulfillmentType: 'onDemand',
109
+ quantity: 1
110
+ }
111
+ ]);
112
+ ```
113
+
114
+ ### Address Requirement
115
+
116
+ If no address is set, the SDK automatically:
117
+ 1. Opens address input drawer
118
+ 2. Waits for user to set address
119
+ 3. Retries add-to-cart operation
120
+
121
+ ### Errors
122
+
123
+ **Throws `SDKError` if:**
124
+ - Identifier is invalid
125
+ - Fulfillment type is not `'shipping'` or `'onDemand'`
126
+ - Quantity is less than 1
127
+ - Product is not available
128
+ - Product is a presale item
129
+
130
+ ---
131
+
132
+ ## actions.cart.applyPromoCode()
133
+
134
+ Apply a promo code to the cart.
135
+
136
+ ### Signature
137
+
138
+ ```typescript
139
+ applyPromoCode(promoCode: string): Promise<void>
140
+ ```
141
+
142
+ ### Parameters
143
+
144
+ | Parameter | Type | Required | Description |
145
+ |-----------|------|----------|-------------|
146
+ | `promoCode` | string | Yes | Promo code to apply |
147
+
148
+ ### Example
149
+
150
+ ```javascript
151
+ try {
152
+ await window.elements.actions.cart.applyPromoCode('SUMMER20');
153
+ console.log('Promo code applied successfully');
154
+ } catch (error) {
155
+ console.error('Invalid promo code:', error);
156
+ }
157
+ ```
158
+
159
+ ### Notes
160
+
161
+ - Code is automatically normalized (trimmed, uppercased)
162
+ - Promo codes must be enabled in configuration
163
+ - Only one promo code can be active at a time
164
+ - Applying a new code replaces the existing one
165
+
166
+ ---
167
+
168
+ ## actions.cart.removePromoCode()
169
+
170
+ Remove the active promo code.
171
+
172
+ ### Signature
173
+
174
+ ```typescript
175
+ removePromoCode(): Promise<void>
176
+ ```
177
+
178
+ ### Example
179
+
180
+ ```javascript
181
+ await window.elements.actions.cart.removePromoCode();
182
+ ```
183
+
184
+ ---
185
+
186
+ ## actions.cart.resetCart()
187
+
188
+ Clear all items from the cart.
189
+
190
+ ### Signature
191
+
192
+ ```typescript
193
+ resetCart(): Promise<void>
194
+ ```
195
+
196
+ ### Example
197
+
198
+ ```javascript
199
+ await window.elements.actions.cart.resetCart();
200
+ console.log('Cart cleared');
201
+ ```
202
+
203
+ ### Warning
204
+
205
+ This permanently removes all cart items. There is no undo.
206
+
207
+ ---
208
+
209
+ ## actions.cart.getDetails()
210
+
211
+ Retrieve current cart information.
212
+
213
+ ### Signature
214
+
215
+ ```typescript
216
+ getDetails(): IBaseCartEventData
217
+ ```
218
+
219
+ ### Returns
220
+
221
+ ```typescript
222
+ interface IBaseCartEventData {
223
+ cartId: string;
224
+ items: ICartItem[];
225
+ subtotal: number; // in cents
226
+ total: number; // in cents
227
+ itemsCount: number;
228
+ itemsQuantity: number;
229
+ promoCode?: {
230
+ code: string;
231
+ discount: number; // in cents
232
+ };
233
+ retailers: IRetailer[];
234
+ // ... additional fields
235
+ }
236
+ ```
237
+
238
+ ### Example
239
+
240
+ ```javascript
241
+ const cart = window.elements.actions.cart.getDetails();
242
+
243
+ console.log(`Cart ID: ${cart.cartId}`);
244
+ console.log(`Items: ${cart.itemsCount}`);
245
+ console.log(`Subtotal: $${cart.subtotal / 100}`);
246
+ console.log(`Total: $${cart.total / 100}`);
247
+
248
+ if (cart.promoCode) {
249
+ console.log(`Discount: $${cart.promoCode.discount / 100}`);
250
+ }
251
+ ```
252
+
253
+ ### Use Cases
254
+
255
+ #### Display Cart Summary
256
+
257
+ ```javascript
258
+ function updateCartSummary() {
259
+ const cart = window.elements.actions.cart.getDetails();
260
+
261
+ document.getElementById('cart-count').textContent = cart.itemsCount;
262
+ document.getElementById('cart-total').textContent = `$${cart.total / 100}`;
263
+ }
264
+
265
+ // Update on cart changes
266
+ window.addEventListener('lce:actions.cart_updated', updateCartSummary);
267
+ ```
268
+
269
+ #### Check Cart Before Checkout
270
+
271
+ ```javascript
272
+ document.getElementById('checkout-btn').addEventListener('click', () => {
273
+ const cart = window.elements.actions.cart.getDetails();
274
+
275
+ if (cart.itemsCount === 0) {
276
+ alert('Your cart is empty');
277
+ return;
278
+ }
279
+
280
+ window.elements.actions.checkout.openCheckout();
281
+ });
282
+ ```
283
+
284
+ #### Track Cart Value
285
+
286
+ ```javascript
287
+ const cart = window.elements.actions.cart.getDetails();
288
+
289
+ gtag('event', 'view_cart', {
290
+ value: cart.total / 100,
291
+ currency: 'USD',
292
+ items: cart.items.map(item => ({
293
+ item_id: item.identifier,
294
+ quantity: item.quantity
295
+ }))
296
+ });
297
+ ```
298
+
299
+ ## Events
300
+
301
+ Cart actions trigger events that you can listen for:
302
+
303
+ ```javascript
304
+ // Item added
305
+ window.addEventListener('lce:actions.cart_item_added', (event) => {
306
+ console.log('Item added:', event.detail.data);
307
+ });
308
+
309
+ // Cart updated
310
+ window.addEventListener('lce:actions.cart_updated', (event) => {
311
+ console.log('Cart updated:', event.detail.data);
312
+ });
313
+
314
+ // Promo code applied
315
+ window.addEventListener('lce:actions.cart_promo_code_applied', (event) => {
316
+ console.log('Promo applied:', event.detail.data);
317
+ });
318
+
319
+ // Product add success
320
+ window.addEventListener('lce:actions.cart_product_add_success', (event) => {
321
+ console.log('Products added:', event.detail.data);
322
+ });
323
+
324
+ // Product add failed
325
+ window.addEventListener('lce:actions.cart_product_add_failed', (event) => {
326
+ console.error('Failed to add:', event.detail.data);
327
+ });
328
+ ```
329
+
330
+ See [Events Guide](../../guides/events.md) for all cart events.
331
+
332
+ ## See Also
333
+
334
+ - [Cart Component Guide](../../guides/cart-component.md)
335
+ - [Cart Events](../../guides/events.md#cart-events)
336
+ - [Product Actions](./product-actions.md)
337
+ - [Checkout Actions](./checkout-actions.md)