@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.
- package/README.md +83 -2750
- package/dist/index.checkout.esm.js +6877 -6825
- package/dist/index.esm.js +11384 -10940
- package/dist/types/auto-initialize/shared-utils.d.ts +5 -0
- package/dist/types/constants/core.constant.d.ts +0 -4
- package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +1 -0
- package/dist/types/enums/core.enum.d.ts +11 -0
- package/dist/types/interfaces/configs/product-list.interface.d.ts +2 -2
- package/dist/types/modules/address/address-input.component.d.ts +11 -0
- package/dist/types/modules/product-list/components/card-components/index.d.ts +3 -0
- package/dist/types/modules/product-list/components/card-components/product-badge.d.ts +8 -0
- package/dist/types/modules/product-list/components/card-components/product-fulfillments.d.ts +2 -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-title.d.ts +6 -0
- package/dist/types/modules/product-list/components/index.d.ts +1 -0
- package/dist/types/modules/product-list/components/product-list-engraving.component.d.ts +5 -1
- package/dist/types/modules/product-list/components/product-list-product-pre-cart.component.d.ts +28 -0
- package/dist/types/modules/product-list/components/product-list-retailers.component.d.ts +10 -2
- package/dist/types/modules/product-list/product-list-card.component.d.ts +0 -5
- package/dist/types/modules/product-list/product-list.commands.d.ts +11 -2
- package/dist/types/modules/product-list/product-list.interface.d.ts +1 -0
- package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +11 -2
- package/docs/gitbook/actions.md +160 -0
- package/docs/gitbook/address.md +48 -0
- package/docs/gitbook/cart.md +65 -0
- package/docs/gitbook/checkout.md +131 -0
- package/docs/gitbook/events.md +137 -0
- package/docs/gitbook/overview.md +166 -0
- package/docs/gitbook/product.md +64 -0
- package/docs/gitbook/quick-start-guide.md +393 -0
- package/docs/v1/README.md +210 -0
- package/docs/v1/api/actions/address-actions.md +281 -0
- package/docs/v1/api/actions/cart-actions.md +337 -0
- package/docs/v1/api/actions/checkout-actions.md +387 -0
- package/docs/v1/api/actions/product-actions.md +115 -0
- package/docs/v1/api/client.md +482 -0
- package/docs/v1/api/configuration.md +1 -0
- package/docs/v1/api/injection-methods.md +247 -0
- package/docs/v1/api/typescript-types.md +1 -0
- package/docs/v1/api/ui-helpers.md +200 -0
- package/docs/v1/examples/advanced-patterns.md +96 -0
- package/docs/v1/examples/checkout-flow.md +91 -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 +507 -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 +431 -0
- package/docs/v1/guides/best-practices.md +324 -0
- package/docs/v1/guides/cart-component.md +737 -0
- package/docs/v1/guides/checkout-component.md +672 -0
- package/docs/v1/guides/events.md +191 -0
- package/docs/v1/guides/product-component.md +686 -0
- package/docs/v1/guides/product-list-component.md +598 -0
- package/docs/v1/guides/theming.md +216 -0
- package/docs/v1/integration/angular.md +39 -0
- package/docs/v1/integration/laravel.md +41 -0
- package/docs/v1/integration/nextjs.md +60 -0
- package/docs/v1/integration/proxy-setup.md +89 -0
- package/docs/v1/integration/react.md +64 -0
- package/docs/v1/integration/vanilla-js.md +84 -0
- package/docs/v1/integration/vue.md +34 -0
- package/docs/v1/reference/browser-support.md +35 -0
- package/docs/v1/reference/error-handling.md +70 -0
- package/docs/v1/reference/performance.md +54 -0
- package/docs/v1/reference/troubleshooting.md +64 -0
- package/package.json +1 -1
- package/docs/ACTIONS.md +0 -1301
- package/docs/BROWSER_SUPPORT.md +0 -279
- package/docs/CONFIGURATION.md +0 -997
- package/docs/DOCUMENTATION_INDEX.md +0 -319
- package/docs/EVENTS.md +0 -798
- package/docs/PROXY.md +0 -228
- package/docs/THEMING.md +0 -681
- package/docs/TROUBLESHOOTING.md +0 -793
|
@@ -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...
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Injection Methods API
|
|
2
|
+
|
|
3
|
+
Methods for injecting SDK components into your page.
|
|
4
|
+
|
|
5
|
+
## injectProductElement()
|
|
6
|
+
|
|
7
|
+
Inject one or more product displays.
|
|
8
|
+
|
|
9
|
+
### Signature
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
injectProductElement(params: IInjectProductElement[]): Promise<IInjectedComponent[]>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Parameters
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
interface IInjectProductElement {
|
|
19
|
+
containerId: string; // ID of container element
|
|
20
|
+
identifier: string; // Product Identifier
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Example
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
await client.injectProductElement([
|
|
28
|
+
{ containerId: 'product-1', identifier: '00619947000020' },
|
|
29
|
+
{ containerId: 'product-2', identifier: '08504405135' }
|
|
30
|
+
]);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Returns
|
|
34
|
+
|
|
35
|
+
Array of injected component objects.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## injectAddressElement()
|
|
40
|
+
|
|
41
|
+
Inject standalone address component.
|
|
42
|
+
|
|
43
|
+
### Signature
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
injectAddressElement(
|
|
47
|
+
containerId: string,
|
|
48
|
+
options?: IAddressOptions
|
|
49
|
+
): Promise<IInjectedComponent | null>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Example
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
await client.injectAddressElement('address-container', {
|
|
56
|
+
onAddressSet: (address) => {
|
|
57
|
+
console.log('Address set:', address);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## injectCartElement()
|
|
65
|
+
|
|
66
|
+
Inject standalone cart (rarely needed - cart drawer is automatic).
|
|
67
|
+
|
|
68
|
+
### Signature
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
injectCartElement(containerId: string): Promise<IInjectedComponent | null>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Example
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
await client.injectCartElement('cart-container');
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## injectCheckoutElement()
|
|
83
|
+
|
|
84
|
+
Inject hosted checkout page.
|
|
85
|
+
|
|
86
|
+
### Signature
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
injectCheckoutElement(params: IInjectCheckoutParams): Promise<IInjectedComponent | null>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Parameters
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
interface IInjectCheckoutParams {
|
|
96
|
+
containerId: string;
|
|
97
|
+
checkoutId?: string; // Optional checkout token to load
|
|
98
|
+
hideHeader?: boolean; // Hide checkout header
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Example
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
await client.injectCheckoutElement({
|
|
106
|
+
containerId: 'checkout',
|
|
107
|
+
checkoutId: 'cart_abc123',
|
|
108
|
+
hideHeader: false
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## injectProductList()
|
|
115
|
+
|
|
116
|
+
Inject product catalog/listing.
|
|
117
|
+
|
|
118
|
+
### Signature
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
injectProductList(params: IInjectProductListParams): Promise<void>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Parameters
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
interface IInjectProductListParams {
|
|
128
|
+
containerId: string;
|
|
129
|
+
rows?: number; // Default: 3
|
|
130
|
+
columns?: number; // Default: 4
|
|
131
|
+
filters?: ProductListFilterType[];
|
|
132
|
+
productUrl?: string; // URL pattern with {identifier}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Example
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
await client.injectProductList({
|
|
140
|
+
containerId: 'products',
|
|
141
|
+
rows: 4,
|
|
142
|
+
columns: 3,
|
|
143
|
+
filters: ['price', 'brand', 'category'],
|
|
144
|
+
productUrl: '/product/{identifier}'
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## injectProductListSearch()
|
|
151
|
+
|
|
152
|
+
Inject product search box.
|
|
153
|
+
|
|
154
|
+
### Signature
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
injectProductListSearch(params: IInjectProductListSearchParams): Promise<void>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Parameters
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
interface IInjectProductListSearchParams {
|
|
164
|
+
containerId: string;
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Example
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
await client.injectProductListSearch({
|
|
172
|
+
containerId: 'search-box'
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## injectProductListFilters()
|
|
179
|
+
|
|
180
|
+
Inject product filter panel.
|
|
181
|
+
|
|
182
|
+
### Signature
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
injectProductListFilters(params: IInjectProductListFiltersParams): Promise<void>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Parameters
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
interface IInjectProductListFiltersParams {
|
|
192
|
+
containerId: string;
|
|
193
|
+
filters: ProductListFilterType[];
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Example
|
|
198
|
+
|
|
199
|
+
```javascript
|
|
200
|
+
await client.injectProductListFilters({
|
|
201
|
+
containerId: 'filters',
|
|
202
|
+
filters: ['price', 'brand', 'fulfillment']
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Component Management
|
|
209
|
+
|
|
210
|
+
### getInjectedComponents()
|
|
211
|
+
|
|
212
|
+
Retrieve all injected components.
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
getInjectedComponents(): Map<string, IInjectedComponent>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
const components = client.getInjectedComponents();
|
|
220
|
+
|
|
221
|
+
// Get specific component
|
|
222
|
+
const product = components.get('product-1');
|
|
223
|
+
|
|
224
|
+
// Rerender component
|
|
225
|
+
product.rerender();
|
|
226
|
+
|
|
227
|
+
// Get container element
|
|
228
|
+
const container = product.getElement();
|
|
229
|
+
|
|
230
|
+
// Get component type
|
|
231
|
+
const type = product.getType(); // 'product'
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### IInjectedComponent Interface
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
interface IInjectedComponent {
|
|
238
|
+
getType(): ComponentType;
|
|
239
|
+
getElement(): HTMLElement;
|
|
240
|
+
rerender(): void;
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## See Also
|
|
245
|
+
|
|
246
|
+
- [Client API](./client.md)
|
|
247
|
+
- [Component Guides](../guides/)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
to be created...
|