@liquidcommerce/elements-sdk 2.7.0 → 2.7.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.
Files changed (81) hide show
  1. package/README.md +83 -2750
  2. package/dist/index.checkout.esm.js +6898 -6837
  3. package/dist/index.esm.js +11463 -10993
  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/base-component.service.d.ts +2 -1
  7. package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +1 -0
  8. package/dist/types/enums/core.enum.d.ts +11 -0
  9. package/dist/types/interfaces/configs/product-list.interface.d.ts +2 -2
  10. package/dist/types/interfaces/core.interface.d.ts +5 -4
  11. package/dist/types/modules/address/address-input.component.d.ts +11 -0
  12. package/dist/types/modules/checkout/components/checkout-stripe-form.component.d.ts +2 -1
  13. package/dist/types/modules/product-list/components/card-components/index.d.ts +3 -0
  14. package/dist/types/modules/product-list/components/card-components/product-badge.d.ts +8 -0
  15. package/dist/types/modules/product-list/components/card-components/product-fulfillments.d.ts +2 -0
  16. package/dist/types/modules/product-list/components/card-components/product-price-and-personalization.d.ts +13 -0
  17. package/dist/types/modules/product-list/components/card-components/product-title.d.ts +6 -0
  18. package/dist/types/modules/product-list/components/index.d.ts +1 -0
  19. package/dist/types/modules/product-list/components/product-list-engraving.component.d.ts +5 -1
  20. package/dist/types/modules/product-list/components/product-list-product-pre-cart.component.d.ts +28 -0
  21. package/dist/types/modules/product-list/components/product-list-retailers.component.d.ts +10 -2
  22. package/dist/types/modules/product-list/product-list-card.component.d.ts +0 -5
  23. package/dist/types/modules/product-list/product-list.commands.d.ts +11 -2
  24. package/dist/types/modules/product-list/product-list.interface.d.ts +1 -0
  25. package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +11 -2
  26. package/dist/types/modules/ui-components/lce-element/lce-element.component.d.ts +2 -1
  27. package/dist/types/utils/dom-compat.d.ts +2 -0
  28. package/docs/gitbook/actions.md +964 -0
  29. package/docs/gitbook/address.md +48 -0
  30. package/docs/gitbook/cart.md +65 -0
  31. package/docs/gitbook/checkout.md +131 -0
  32. package/docs/gitbook/events.md +1765 -0
  33. package/docs/gitbook/overview.md +166 -0
  34. package/docs/gitbook/product.md +64 -0
  35. package/docs/gitbook/quick-start-guide.md +393 -0
  36. package/docs/v1/README.md +210 -0
  37. package/docs/v1/api/actions/address-actions.md +281 -0
  38. package/docs/v1/api/actions/cart-actions.md +337 -0
  39. package/docs/v1/api/actions/checkout-actions.md +387 -0
  40. package/docs/v1/api/actions/product-actions.md +115 -0
  41. package/docs/v1/api/client.md +482 -0
  42. package/docs/v1/api/configuration.md +1 -0
  43. package/docs/v1/api/injection-methods.md +247 -0
  44. package/docs/v1/api/typescript-types.md +1 -0
  45. package/docs/v1/api/ui-helpers.md +200 -0
  46. package/docs/v1/examples/advanced-patterns.md +96 -0
  47. package/docs/v1/examples/checkout-flow.md +91 -0
  48. package/docs/v1/examples/custom-theming.md +63 -0
  49. package/docs/v1/examples/multi-product-page.md +90 -0
  50. package/docs/v1/examples/simple-product-page.md +89 -0
  51. package/docs/v1/getting-started/concepts.md +507 -0
  52. package/docs/v1/getting-started/installation.md +328 -0
  53. package/docs/v1/getting-started/quick-start.md +405 -0
  54. package/docs/v1/guides/address-component.md +431 -0
  55. package/docs/v1/guides/best-practices.md +324 -0
  56. package/docs/v1/guides/cart-component.md +737 -0
  57. package/docs/v1/guides/checkout-component.md +672 -0
  58. package/docs/v1/guides/events.md +926 -0
  59. package/docs/v1/guides/product-component.md +686 -0
  60. package/docs/v1/guides/product-list-component.md +598 -0
  61. package/docs/v1/guides/theming.md +216 -0
  62. package/docs/v1/integration/angular.md +39 -0
  63. package/docs/v1/integration/laravel.md +41 -0
  64. package/docs/v1/integration/nextjs.md +60 -0
  65. package/docs/v1/integration/proxy-setup.md +89 -0
  66. package/docs/v1/integration/react.md +64 -0
  67. package/docs/v1/integration/vanilla-js.md +84 -0
  68. package/docs/v1/integration/vue.md +34 -0
  69. package/docs/v1/reference/browser-support.md +44 -0
  70. package/docs/v1/reference/error-handling.md +70 -0
  71. package/docs/v1/reference/performance.md +54 -0
  72. package/docs/v1/reference/troubleshooting.md +64 -0
  73. package/package.json +1 -1
  74. package/docs/ACTIONS.md +0 -1301
  75. package/docs/BROWSER_SUPPORT.md +0 -279
  76. package/docs/CONFIGURATION.md +0 -997
  77. package/docs/DOCUMENTATION_INDEX.md +0 -319
  78. package/docs/EVENTS.md +0 -798
  79. package/docs/PROXY.md +0 -228
  80. package/docs/THEMING.md +0 -681
  81. package/docs/TROUBLESHOOTING.md +0 -793
@@ -0,0 +1,115 @@
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
+ interface IBaseProductEventData {
25
+ identifier: string;
26
+ name: string;
27
+ description: string;
28
+ price: number; // in cents
29
+ selectedSize: IProductSize;
30
+ selectedFulfillmentType: FulfillmentType;
31
+ selectedRetailer: IRetailer;
32
+ quantity: number;
33
+ images: string[];
34
+ brand: string;
35
+ category: string;
36
+ // ... additional fields
37
+ }
38
+ ```
39
+
40
+ ### Example
41
+
42
+ ```javascript
43
+ const productData = window.elements.actions.product.getDetails('00619947000020');
44
+
45
+ console.log(productData.name); // "Premium Whiskey"
46
+ console.log(productData.price / 100); // 49.99
47
+ console.log(productData.selectedSize.name); // "750ml"
48
+ console.log(productData.quantity); // 1
49
+ ```
50
+
51
+ ### Errors
52
+
53
+ **Throws `SDKError` if:**
54
+ - Identifier is empty or invalid
55
+ - Product has not been loaded yet
56
+ - Product does not exist
57
+
58
+ ```javascript
59
+ try {
60
+ const data = window.elements.actions.product.getDetails('invalid_id');
61
+ } catch (error) {
62
+ console.error('Product not found:', error.message);
63
+ }
64
+ ```
65
+
66
+ ### Use Cases
67
+
68
+ #### Display Product Info Elsewhere
69
+
70
+ ```javascript
71
+ const product = window.elements.actions.product.getDetails('00619947000020');
72
+
73
+ document.getElementById('product-name').textContent = product.name;
74
+ document.getElementById('product-price').textContent = `$${product.price / 100}`;
75
+ ```
76
+
77
+ #### Sync with Analytics
78
+
79
+ ```javascript
80
+ window.addEventListener('lce:actions.product_loaded', () => {
81
+ const product = window.elements.actions.product.getDetails('00619947000020');
82
+
83
+ gtag('event', 'view_item', {
84
+ items: [{
85
+ item_id: product.identifier,
86
+ item_name: product.name,
87
+ price: product.price / 100,
88
+ item_brand: product.brand
89
+ }]
90
+ });
91
+ });
92
+ ```
93
+
94
+ #### Custom Product Comparison
95
+
96
+ ```javascript
97
+ const product1 = window.elements.actions.product.getDetails('00619947000020');
98
+ const product2 = window.elements.actions.product.getDetails('08504405135');
99
+
100
+ if (product1.price < product2.price) {
101
+ console.log(`${product1.name} is cheaper`);
102
+ }
103
+ ```
104
+
105
+ ## Notes
106
+
107
+ - Product must be injected and loaded before calling `getDetails()`
108
+ - Data is synchronous - returns immediately
109
+ - Prices are always in cents (divide by 100 for dollars)
110
+ - Selected values reflect current user selection in the component
111
+
112
+ ## See Also
113
+
114
+ - [Product Component Guide](../../guides/product-component.md)
115
+ - [Product Events](../../guides/events.md#product-events)
@@ -0,0 +1,482 @@
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
+ ## Configuration
68
+
69
+ ### ILiquidCommerceElementsConfig
70
+
71
+ Complete configuration interface for the full SDK.
72
+
73
+ ```typescript
74
+ interface ILiquidCommerceElementsConfig {
75
+ // Required
76
+ env: ElementsEnv; // 'development' | 'staging' | 'production'
77
+
78
+ // Optional
79
+ debugMode?: DebugMode; // 'none' | 'console' | 'panel'
80
+ customTheme?: IClientCustomThemeConfig;
81
+ promoTicker?: IPromoTicker[];
82
+ proxy?: IElementsProxyConfig;
83
+ checkout?: ILiquidCommerceElementsCheckoutConfig;
84
+ development?: ILiquidCommerceElementsDevelopmentConfig;
85
+ }
86
+ ```
87
+
88
+ #### Environment
89
+
90
+ ```typescript
91
+ type ElementsEnv = 'development' | 'staging' | 'production';
92
+ ```
93
+
94
+ Determines which API environment to use.
95
+
96
+ #### Debug Mode
97
+
98
+ ```typescript
99
+ type DebugMode = 'none' | 'console' | 'panel';
100
+ ```
101
+
102
+ - `'none'`: No debug output (production default)
103
+ - `'console'`: Log debug info to browser console
104
+ - `'panel'`: Show debug panel on page
105
+
106
+ #### Custom Theme
107
+
108
+ ```typescript
109
+ interface IClientCustomThemeConfig {
110
+ global?: UpdateComponentGlobalConfigs;
111
+ product?: UpdateProductComponent;
112
+ address?: UpdateAddressComponent;
113
+ cart?: UpdateCartComponent;
114
+ checkout?: UpdateCheckoutComponent;
115
+ }
116
+ ```
117
+
118
+ See [Configuration Reference](./configuration.md) for detailed theme options.
119
+
120
+ #### Promo Ticker
121
+
122
+ ```typescript
123
+ interface IPromoTicker {
124
+ promoCode: string;
125
+ text: string[];
126
+ separator: string;
127
+ activeFrom: string; // ISO 8601 UTC format
128
+ activeUntil: string; // ISO 8601 UTC format
129
+ }
130
+ ```
131
+
132
+ **Example:**
133
+
134
+ ```javascript
135
+ promoTicker: [{
136
+ promoCode: 'SUMMER20',
137
+ text: ['20% Off Summer Sale', 'Free Shipping on $50+'],
138
+ separator: '•',
139
+ activeFrom: '2026-06-01T00:00:00Z',
140
+ activeUntil: '2026-08-31T23:59:59Z'
141
+ }]
142
+ ```
143
+
144
+ #### Proxy Configuration
145
+
146
+ ```typescript
147
+ interface IElementsProxyConfig {
148
+ baseUrl: string;
149
+ headers?: Record<string, string>;
150
+ }
151
+ ```
152
+
153
+ **Example:**
154
+
155
+ ```javascript
156
+ proxy: {
157
+ baseUrl: 'https://yoursite.com/api/elements-proxy',
158
+ headers: {
159
+ 'X-Custom-Header': 'value'
160
+ }
161
+ }
162
+ ```
163
+
164
+ See [Proxy Setup Guide](../integration/proxy-setup.md) for implementation.
165
+
166
+ #### Checkout Configuration
167
+
168
+ ```typescript
169
+ interface ILiquidCommerceElementsCheckoutConfig {
170
+ pageUrl: string; // URL pattern with {token} placeholder
171
+ }
172
+ ```
173
+
174
+ **Example:**
175
+
176
+ ```javascript
177
+ checkout: {
178
+ pageUrl: 'https://yoursite.com/checkout?lce_checkout={token}'
179
+ }
180
+ ```
181
+
182
+ #### Development Configuration
183
+
184
+ ```typescript
185
+ interface ILiquidCommerceElementsDevelopmentConfig {
186
+ customApiUrl?: string;
187
+ paymentMethodId?: string;
188
+ openShadowDom?: boolean;
189
+ }
190
+ ```
191
+
192
+ **Example:**
193
+
194
+ ```javascript
195
+ development: {
196
+ customApiUrl: 'http://localhost:3000/api',
197
+ paymentMethodId: 'pm_test_123', // For testing without Stripe form
198
+ openShadowDom: true // Disable Shadow DOM for debugging
199
+ }
200
+ ```
201
+
202
+ ## Global Access
203
+
204
+ After initialization, the client is available globally:
205
+
206
+ ```javascript
207
+ window.elements
208
+ ```
209
+
210
+ This allows access from anywhere in your application:
211
+
212
+ ```javascript
213
+ // From any script
214
+ window.elements.actions.cart.openCart();
215
+ ```
216
+
217
+ ## Client Ready Event
218
+
219
+ Listen for client initialization:
220
+
221
+ ```javascript
222
+ window.addEventListener('lce:actions.client_ready', ( event ) => {
223
+ const { isReady, version, timestamp } = event.detail.data;
224
+
225
+ console.log(`Elements SDK v${version} ready`);
226
+
227
+ // Safe to use client
228
+ window.elements.injectProductElement([...]);
229
+ });
230
+ ```
231
+
232
+ ## Client Interface
233
+
234
+ ### ILiquidCommerceElementsClient
235
+
236
+ The main client interface:
237
+
238
+ ```typescript
239
+ interface ILiquidCommerceElementsClient {
240
+ // Injection methods
241
+ injectProductElement(params: IInjectProductElement[]): Promise<IInjectedComponent[]>;
242
+
243
+ injectAddressElement(containerId: string, options?: IAddressOptions): Promise<IInjectedComponent | null>;
244
+
245
+ injectCartElement(containerId: string): Promise<IInjectedComponent | null>;
246
+
247
+ injectCheckoutElement(params: IInjectCheckoutParams): Promise<IInjectedComponent | null>;
248
+
249
+ injectProductList(params: IInjectProductListParams): Promise<void>;
250
+
251
+ injectProductListSearch(params: IInjectProductListSearchParams): Promise<void>;
252
+
253
+ injectProductListFilters(params: IInjectProductListFiltersParams): Promise<void>;
254
+
255
+ // UI methods
256
+ ui: ILiquidCommerceElementsUIMethod;
257
+
258
+ // Actions
259
+ actions: ILiquidCommerceElementsActions;
260
+
261
+ // Component management
262
+ getInjectedComponents(): Map<string, IInjectedComponent>;
263
+ }
264
+ ```
265
+
266
+ ## Methods Overview
267
+
268
+ ### Injection Methods
269
+
270
+ - `injectProductElement()` - Inject product displays
271
+ - `injectAddressElement()` - Inject address input
272
+ - `injectCartElement()` - Inject cart (rarely needed)
273
+ - `injectCheckoutElement()` - Inject checkout
274
+ - `injectProductList()` - Inject product catalog
275
+ - `injectProductListSearch()` - Inject search box
276
+ - `injectProductListFilters()` - Inject filter panel
277
+
278
+ See [Injection Methods](./injection-methods.md) for details.
279
+
280
+ ### UI Methods
281
+
282
+ - `ui.cartButton()` - Add cart button
283
+ - `ui.floatingCartButton()` - Add floating cart button
284
+ - `ui.cartSubtotal()` - Display cart subtotal
285
+ - `ui.cartItemsCount()` - Display item count
286
+
287
+ See [UI Helpers](./ui-helpers.md) for details.
288
+
289
+ ### Actions
290
+
291
+ - `actions.product.*` - Product actions
292
+ - `actions.address.*` - Address actions
293
+ - `actions.cart.*` - Cart actions
294
+ - `actions.checkout.*` - Checkout actions
295
+
296
+ See [Actions](./actions/) for details.
297
+
298
+ ### Component Management
299
+
300
+ ```javascript
301
+ // Get all injected components
302
+ const components = client.getInjectedComponents();
303
+
304
+ // Get specific component
305
+ const productComponent = components.get('product-1');
306
+
307
+ // Component methods
308
+ productComponent.getType(); // 'product'
309
+ productComponent.getElement(); // <div id="product-1">...</div>
310
+ productComponent.rerender(); // Force rerender
311
+ ```
312
+
313
+ ## Error Handling
314
+
315
+ ### SDKError
316
+
317
+ All SDK errors use the custom `SDKError` class:
318
+
319
+ ```typescript
320
+ class SDKError extends Error {
321
+ constructor(message: string, reThrow?: boolean);
322
+
323
+ name: 'SDKError';
324
+ isSdk: boolean;
325
+ reThrow: boolean;
326
+ }
327
+ ```
328
+ ### Catching Errors
329
+
330
+ ```javascript
331
+ try {
332
+ await client.injectProductElement([
333
+ { containerId: 'product', identifier: 'invalid_id' }
334
+ ]);
335
+ } catch (error) {
336
+ if (error.name === 'SDKError') {
337
+ console.error('SDK Error:', error);
338
+ }
339
+ }
340
+ ```
341
+
342
+ ### Error Isolation
343
+
344
+ The SDK catches and contains its own errors:
345
+
346
+ ```javascript
347
+ // Even if SDK throws, your app continues
348
+ window.elements.actions.cart.addProduct([/* invalid */]);
349
+
350
+ // Your code still runs
351
+ console.log('App still working');
352
+ ```
353
+
354
+ ## TypeScript Support
355
+
356
+ ### Importing Types
357
+
358
+ ```typescript
359
+ import { Elements } from '@liquidcommerce/elements-sdk';
360
+ import type {
361
+ ILiquidCommerceElementsClient,
362
+ ILiquidCommerceElementsConfig,
363
+ IInjectProductElement,
364
+ IInjectedComponent
365
+ } from '@liquidcommerce/elements-sdk';
366
+
367
+ const config: ILiquidCommerceElementsConfig = {
368
+ env: 'production'
369
+ };
370
+
371
+ const client: ILiquidCommerceElementsClient = await Elements('KEY', config);
372
+ ```
373
+
374
+ ### Type Exports
375
+
376
+ All public interfaces are exported from the main package:
377
+
378
+ ```typescript
379
+ import type {
380
+ // Client types
381
+ ILiquidCommerceElementsClient,
382
+ ILiquidCommerceElementsConfig,
383
+
384
+ // Injection types
385
+ IInjectProductElement,
386
+ IInjectCheckoutParams,
387
+ IInjectedComponent,
388
+
389
+ // Action types
390
+ IProductActions,
391
+ ICartActions,
392
+ ICheckoutActions,
393
+ IAddressActions,
394
+ IAddProductParams,
395
+
396
+ // Configuration types
397
+ IClientCustomThemeConfig,
398
+ IComponentGlobalConfigs,
399
+ IProductComponent,
400
+ ICartComponent,
401
+ ICheckoutComponent,
402
+ IAddressComponent,
403
+
404
+ // Enum types
405
+ ElementsEnv,
406
+ DebugMode,
407
+ FulfillmentType,
408
+ ComponentType
409
+ } from '@liquidcommerce/elements-sdk';
410
+ ```
411
+
412
+ See [TypeScript Types](./typescript-types.md) for complete type reference.
413
+
414
+ ## Best Practices
415
+
416
+ ### Single Client Instance
417
+
418
+ Create one client instance and reuse it:
419
+
420
+ ```javascript
421
+ // Good
422
+ const client = await Elements('KEY', { env: 'production' });
423
+ await client.injectProductElement([...]);
424
+ await client.injectCartElement('cart');
425
+
426
+ // Bad - creates multiple instances
427
+ await Elements('KEY', { env: 'production' });
428
+ await Elements('KEY', { env: 'production' });
429
+ ```
430
+
431
+ ### Use Global Access
432
+
433
+ After initialization, use `window.elements`:
434
+
435
+ ```javascript
436
+ // Initialize once
437
+ await Elements('KEY', { env: 'production' });
438
+
439
+ // Use globally
440
+ window.elements.actions.cart.openCart();
441
+ window.elements.ui.cartButton('cart-btn');
442
+ ```
443
+
444
+ ### Check Client Ready
445
+
446
+ Wait for client ready before using:
447
+
448
+ ```javascript
449
+ if (window.elements) {
450
+ // Client is ready
451
+ window.elements.actions.cart.openCart();
452
+ } else {
453
+ // Wait for client ready
454
+ window.addEventListener('lce:actions.client_ready', () => {
455
+ window.elements.actions.cart.openCart();
456
+ });
457
+ }
458
+ ```
459
+
460
+ ### Handle Initialization Failures
461
+
462
+ ```javascript
463
+ const client = await Elements('KEY', { env: 'production' });
464
+
465
+ if (!client) {
466
+ console.error('Failed to initialize Elements SDK');
467
+ // Show fallback UI or error message
468
+ showErrorPage();
469
+ return;
470
+ }
471
+
472
+ // Client initialized successfully
473
+ await client.injectProductElement([...]);
474
+ ```
475
+
476
+ ## See Also
477
+
478
+ - [Injection Methods](./injection-methods.md) - Component injection API
479
+ - [UI Helpers](./ui-helpers.md) - UI helper methods
480
+ - [Actions](./actions/) - Action APIs
481
+ - [Configuration](./configuration.md) - Configuration options
482
+ - [TypeScript Types](./typescript-types.md) - Type definitions
@@ -0,0 +1 @@
1
+ to be created...