@liquidcommerce/elements-sdk 2.4.1 → 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.
@@ -32,6 +32,7 @@ export interface ICheckoutActions {
32
32
  closeCheckout: () => void;
33
33
  toggleCheckout: () => void;
34
34
  addProduct: (params: IAddProductParams[], openCheckout?: boolean) => Promise<void>;
35
+ addPresaleProduct: (params: IAddProductParams) => Promise<void>;
35
36
  applyPromoCode: (promoCode: string) => Promise<void>;
36
37
  removePromoCode: () => Promise<void>;
37
38
  applyGiftCard: (code: string) => Promise<void>;
@@ -66,10 +66,12 @@ export interface ICheckoutGiftCardFailedEventData {
66
66
  export interface ICheckoutProductAddEventData {
67
67
  itemsAdded: number;
68
68
  identifiers: string[];
69
+ isPresale?: boolean;
69
70
  }
70
71
  export interface ICheckoutProductAddFailedEventData {
71
72
  identifiers: string[];
72
73
  error: string;
74
+ isPresale?: boolean;
73
75
  }
74
76
  export interface ICheckoutItemEventData {
75
77
  liquidId: string;
@@ -1,12 +1,12 @@
1
1
  import type { IClientConfigs } from '@/core/client/client-config.service';
2
- import type { LiquidCommerceElementsClientConstructor } from '@/interfaces/core.interface';
2
+ import type { LiquidCommerceElementsBuilderClientConstructor, LiquidCommerceElementsClientConstructor } from '@/interfaces/core.interface';
3
3
  export declare class SingletonManager {
4
4
  private static instances;
5
5
  private static clientConstructor;
6
6
  private static getInstances;
7
7
  private constructor();
8
- static setClientConstructor(lceConstructor: LiquidCommerceElementsClientConstructor): void;
9
- static getClientConstructor(): LiquidCommerceElementsClientConstructor | null;
8
+ static setClientConstructor(lceConstructor: LiquidCommerceElementsClientConstructor | LiquidCommerceElementsBuilderClientConstructor): void;
9
+ static getClientConstructor(): LiquidCommerceElementsClientConstructor | LiquidCommerceElementsBuilderClientConstructor | null;
10
10
  static getClassInstance<T>(className: string, instanceCreator: () => T): T;
11
11
  static getClient<T>(clientConfigs: IClientConfigs): Promise<T>;
12
12
  }
@@ -0,0 +1,49 @@
1
+ import { AuthService } from '@/core/auth.service';
2
+ import { ClientActionService } from '@/core/client/client-action.service';
3
+ import { ClientConfigService, type IClientConfigs } from '@/core/client/client-config.service';
4
+ import { CommandService } from '@/core/command/command.service';
5
+ import { DebugPanelService } from '@/core/debug-panel/debug-panel.service';
6
+ import { FingerPrintService } from '@/core/fingerprint.service';
7
+ import { GoogleTagManagerService } from '@/core/google-tag-manager.service';
8
+ import { LoggerFactory } from '@/core/logger/logger-factory';
9
+ import { StoreService } from '@/core/store';
10
+ import { TelemetryService } from '@/core/telemetry/telemetry.service';
11
+ import { type ComponentType } from '@/enums';
12
+ import type { IInjectedComponent, ILiquidCommerceElementsActions, IProcessInjectElementParams } from '@/interfaces/core.interface';
13
+ import { ApiClientService } from '@/modules/api-client';
14
+ import { ThemeProviderService } from '@/modules/theme-provider';
15
+ export declare abstract class ElementsBaseClient {
16
+ protected readonly authService: AuthService;
17
+ protected readonly clientConfig: ClientConfigService;
18
+ protected readonly store: StoreService;
19
+ protected readonly commands: CommandService;
20
+ protected readonly apiClient: ApiClientService;
21
+ protected readonly themeProvider: ThemeProviderService;
22
+ protected readonly fingerPrintService: FingerPrintService;
23
+ protected readonly googleTagManager: GoogleTagManagerService;
24
+ protected readonly clientAction: ClientActionService;
25
+ protected readonly telemetry: TelemetryService;
26
+ protected readonly debugPanel: DebugPanelService;
27
+ protected readonly logger: ReturnType<typeof LoggerFactory.get>;
28
+ protected clientPrepared: boolean;
29
+ protected componentFactoryInitialized: boolean;
30
+ protected cartDrawerCreated: boolean;
31
+ protected gtmInitialized: boolean;
32
+ protected injectedComponents: Map<string, IInjectedComponent>;
33
+ constructor(clientConfigs: IClientConfigs);
34
+ prepare(): Promise<void>;
35
+ private prepareEssentialServices;
36
+ private deferHeavyInitialization;
37
+ private initializeHeavyServices;
38
+ get actions(): ILiquidCommerceElementsActions;
39
+ protected processInjectElement(params: IProcessInjectElementParams): Promise<IInjectedComponent | null>;
40
+ protected ensureCartDrawerExists(): void;
41
+ protected ensureAllComponentsRegistered(): void;
42
+ protected createInjectedComponentWrapper(containerId: string, type: ComponentType, element: HTMLElement): IInjectedComponent;
43
+ protected rerenderInjectedComponentsByType(type: ComponentType): void;
44
+ protected isElementsEnabled(): boolean;
45
+ protected injectDisabledElementsError(containerId: string, componentName: ComponentType): void;
46
+ private registerEssentialComponents;
47
+ protected registerComponents(): void;
48
+ protected registerAllComponents(): void;
49
+ }
@@ -0,0 +1,2 @@
1
+ import type { ILiquidCommerceElementsBuilderClient, ILiquidCommerceElementsBuilderConfig } from '@/interfaces/core.interface';
2
+ export declare function ElementsBuilder(apiKey: string, config: ILiquidCommerceElementsBuilderConfig): Promise<ILiquidCommerceElementsBuilderClient | null>;
@@ -1 +1,4 @@
1
+ import { type ComponentType } from '@/enums';
1
2
  export declare function deepMergeConfigs<T extends Record<string, any>>(target: T, source: Partial<T>): T;
3
+ export declare const layoutFieldToComponentTypes: Map<string, ComponentType[]>;
4
+ export declare function getComponentTypesForLayoutFields(parentPath: string, layoutFields: Record<string, any>): ComponentType[];
@@ -1,3 +1,4 @@
1
+ export * from './elements-builder-client';
1
2
  export * from './elements-client';
2
3
  export * from './enums';
3
4
  export * from './interfaces/configs';
@@ -1,2 +1,2 @@
1
- import { Elements } from './index';
2
- export { Elements };
1
+ import { Elements, ElementsBuilder } from './index';
2
+ export { Elements, ElementsBuilder };
@@ -18,6 +18,7 @@ export interface ICheckoutLayout {
18
18
  drawerHeaderText: string;
19
19
  placeOrderButtonText: string;
20
20
  placeOrderButtonShowRequiredFields: boolean;
21
+ checkoutCompleted: ICheckoutCompleted;
21
22
  }
22
23
  export interface ICheckoutCompleted {
23
24
  customLogo: string;
@@ -25,7 +26,6 @@ export interface ICheckoutCompleted {
25
26
  }
26
27
  export interface ICheckoutTheme {
27
28
  backgroundColor: string;
28
- checkoutCompleted: ICheckoutCompleted;
29
29
  }
30
30
  export interface ICheckoutComponent {
31
31
  theme: ICheckoutTheme;
@@ -17,12 +17,17 @@ export interface IClientCustomThemeConfig {
17
17
  cart?: UpdateCartComponent;
18
18
  checkout?: UpdateCheckoutComponent;
19
19
  }
20
+ export interface ILiquidCommerceElementsBuilderConfig {
21
+ env?: ElementsEnv;
22
+ promoTicker?: IPromoTicker[];
23
+ customTheme?: IClientCustomThemeConfig;
24
+ debugMode?: DebugMode;
25
+ }
20
26
  export interface ILiquidCommerceElementsConfig {
21
27
  env?: ElementsEnv;
22
28
  promoTicker?: IPromoTicker[];
23
29
  customTheme?: IClientCustomThemeConfig;
24
30
  proxy?: IElementsProxyConfig;
25
- isBuilder?: boolean;
26
31
  debugMode?: DebugMode;
27
32
  }
28
33
  export interface IInjectProductElement {
@@ -34,17 +39,10 @@ export interface IBuilderInjectElementParams {
34
39
  containerId: string;
35
40
  [key: string]: any;
36
41
  }
37
- export interface ILiquidCommerceElementsBuilderMethod {
38
- updateComponentGlobalConfigs(configs: UpdateComponentGlobalConfigs): Promise<void>;
39
- updateProductComponent(configs: UpdateProductComponent): Promise<void>;
40
- updateAddressComponent(configs: UpdateAddressComponent): void;
41
- updateCartComponent(configs: UpdateCartComponent): void;
42
- updateCheckoutComponent(configs: UpdateCheckoutComponent): void;
43
- injectElement(params: IBuilderInjectElementParams): Promise<void>;
44
- injectProductElement(params: IInjectProductElement[]): Promise<void>;
45
- injectAddressElement(containerId: string, options?: IAddressOptions): Promise<void>;
46
- injectCartElement(containerId: string): Promise<void>;
47
- injectCheckoutElement(containerId: string): Promise<void>;
42
+ export interface IInjectedComponent {
43
+ getType(): ComponentType;
44
+ getElement(): HTMLElement;
45
+ rerender(): void;
48
46
  }
49
47
  export interface IProcessInjectElementParams {
50
48
  type: ComponentType;
@@ -64,13 +62,30 @@ export interface ILiquidCommerceElementsActions {
64
62
  cart: ICartActions;
65
63
  checkout: ICheckoutActions;
66
64
  }
65
+ export interface ILiquidCommerceElementsBuilderClient {
66
+ updateComponentGlobalConfigs(configs: UpdateComponentGlobalConfigs): Promise<void>;
67
+ updateProductComponent(configs: UpdateProductComponent): Promise<void>;
68
+ updateAddressComponent(configs: UpdateAddressComponent): void;
69
+ updateCartComponent(configs: UpdateCartComponent): void;
70
+ updateCheckoutComponent(configs: UpdateCheckoutComponent): void;
71
+ injectElement(params: IBuilderInjectElementParams): Promise<IInjectedComponent | null>;
72
+ injectProductElement(params: IInjectProductElement[]): Promise<IInjectedComponent[]>;
73
+ injectAddressElement(containerId: string, options?: IAddressOptions): Promise<IInjectedComponent | null>;
74
+ injectCartElement(containerId: string): Promise<IInjectedComponent | null>;
75
+ injectCheckoutElement(containerId: string, options?: {
76
+ simulatePresale?: boolean;
77
+ presaleExpiresInMinutes?: number;
78
+ }): Promise<IInjectedComponent | null>;
79
+ actions: ILiquidCommerceElementsActions;
80
+ }
67
81
  export interface ILiquidCommerceElementsClient {
68
- builder: ILiquidCommerceElementsBuilderMethod;
69
- injectProductElement(params: IInjectProductElement[]): Promise<void>;
70
- injectAddressElement(containerId: string, options?: IAddressOptions): Promise<void>;
71
- injectCartElement(containerId: string): Promise<void>;
72
- injectCheckoutElement(containerId: string): Promise<void>;
82
+ injectProductElement(params: IInjectProductElement[]): Promise<IInjectedComponent[]>;
83
+ injectAddressElement(containerId: string, options?: IAddressOptions): Promise<IInjectedComponent | null>;
84
+ injectCartElement(containerId: string): Promise<IInjectedComponent | null>;
85
+ injectCheckoutElement(containerId: string): Promise<IInjectedComponent | null>;
73
86
  ui: ILiquidCommerceElementsUIMethod;
74
87
  actions: ILiquidCommerceElementsActions;
88
+ getInjectedComponents(): Map<string, IInjectedComponent>;
75
89
  }
76
90
  export type LiquidCommerceElementsClientConstructor = new (clientConfigs: IClientConfigs) => ILiquidCommerceElementsClient;
91
+ export type LiquidCommerceElementsBuilderClientConstructor = new (clientConfigs: IClientConfigs) => ILiquidCommerceElementsBuilderClient;
@@ -1,5 +1,7 @@
1
1
  export * from './cart-body.component';
2
2
  export * from './cart-footer.component';
3
+ export * from './cart-fulfillment.component';
4
+ export * from './cart-fulfillment.component';
3
5
  export * from './cart-header.component';
4
6
  export * from './cart-item.component';
5
7
  export * from './cart-item-quantity-price.component';
@@ -2,6 +2,7 @@ import type { IFontFamily } from '@/interfaces/configs';
2
2
  export declare class FontManagerService {
3
3
  private googleFontsUrl;
4
4
  private defaultFontFamilies;
5
+ private readonly fontsLinkAttribute;
5
6
  loadGoogleFonts(fonts: IFontFamily[], globalDisplay?: string): void;
6
7
  updateGoogleFonts(fonts: IFontFamily[], globalDisplay?: string): void;
7
8
  private injectGoogleFontsResourceHints;
@@ -2,8 +2,10 @@ import type { ComponentType } from '@/enums';
2
2
  export declare class LceElementComponent extends HTMLElement {
3
3
  private _initialized;
4
4
  protected _container: ShadowRoot | null;
5
+ private _wrappedComponentRerender;
5
6
  constructor();
6
7
  initialize(contentType: ComponentType, contentElement: HTMLElement): void;
8
+ rerender(context?: string): void;
7
9
  private applyBasicStyles;
8
10
  private isCSSStyleSheetSupported;
9
11
  private applyThemeStyles;
package/docs/ACTIONS.md CHANGED
@@ -530,7 +530,43 @@ window.addEventListener('lce:actions.checkout_product_add_failed', function(even
530
530
  });
531
531
  ```
532
532
 
533
- **Real Business Use**: Perfect for "Buy Now" buttons, one-click purchasing, express checkout flows, or any scenario where you want to skip the cart and go straight to checkout.
533
+ #### Add Presale Product to Checkout
534
+ ```javascript
535
+ // Add a single presale product directly to checkout (bypasses cart, always opens checkout drawer)
536
+ // The method automatically validates product availability and fulfillment options
537
+ await actions.checkout.addPresaleProduct({
538
+ identifier: 'presale-product-123',
539
+ fulfillmentType: 'shipping',
540
+ quantity: 1
541
+ });
542
+
543
+ // Listen for success/failure feedback (same events as regular addProduct)
544
+ window.addEventListener('lce:actions.checkout_product_add_success', function(event) {
545
+ const { itemsAdded, identifiers, isPresale } = event.detail.data;
546
+ if (isPresale) {
547
+ console.log(`✅ Added ${itemsAdded} presale product to checkout:`, identifiers);
548
+ showSuccessMessage('Presale item ready for checkout!');
549
+ }
550
+ });
551
+
552
+ window.addEventListener('lce:actions.checkout_product_add_failed', function(event) {
553
+ const { identifiers, error, isPresale } = event.detail.data;
554
+ if (isPresale) {
555
+ console.log(`❌ Failed to add presale product to checkout:`, identifiers, error);
556
+ showErrorMessage('Could not proceed with presale checkout. Please try again.');
557
+ }
558
+ });
559
+ ```
560
+
561
+ **Key Features:**
562
+ - **Product Availability Validation**: Automatically fetches and validates product data
563
+ - **Fulfillment Type Support**: Checks if the requested fulfillment type is available
564
+ - **Presale Verification**: Ensures the product is actually a presale item
565
+ - **Always Opens Checkout**: Automatically opens checkout drawer after adding presale product
566
+ - **Address Requirement**: Opens address input if location is not available
567
+ - **Error Handling**: Comprehensive error handling with detailed feedback
568
+
569
+ **Real Business Use**: Perfect for "Buy Now" buttons, one-click purchasing, express checkout flows, or any scenario where you want to skip the cart and go straight to checkout. The `addPresaleProduct` method is specifically designed for presale items that need to bypass the regular cart flow and go directly to checkout.
534
570
 
535
571
  #### Pre-fill Customer Information
536
572
  ```javascript
@@ -308,34 +308,158 @@ data-env="production"
308
308
  data-debug-mode="console"
309
309
  ```
310
310
 
311
- #### `data-cart-id`
311
+ #### `data-cart-button`
312
312
 
313
313
  **Type:** `string`
314
314
 
315
- Container ID for cart button.
315
+ Container ID, CSS selector, or position-prefixed selector for simple cart button (no badge).
316
316
 
317
317
  ```html
318
- data-cart-id="header-cart"
318
+ <!-- Simple ID -->
319
+ data-cart-button="header-cart"
320
+
321
+ <!-- CSS Selector (from browser inspect tool) -->
322
+ data-cart-button=".header .nav-links"
323
+ data-cart-button="#main-navigation"
324
+
325
+ <!-- Position-prefixed selectors -->
326
+ data-cart-button="above:.header .logo" <!-- Place above the target -->
327
+ data-cart-button="below:#main-navigation" <!-- Place below the target -->
328
+ data-cart-button="replace:.old-cart" <!-- Replace the target -->
329
+ data-cart-button="inside:.header .nav" <!-- Place inside the target (default) -->
319
330
  ```
320
331
 
321
- #### `data-show-cart-items`
332
+ #### `data-cart-badge-button`
322
333
 
323
- **Type:** flag (no value)
334
+ **Type:** `string`
324
335
 
325
- Show item count on cart button.
336
+ Container ID, CSS selector, or position-prefixed selector for cart button with item count badge.
326
337
 
327
338
  ```html
328
- data-show-cart-items
339
+ <!-- Simple ID -->
340
+ data-cart-badge-button="header-cart"
341
+
342
+ <!-- CSS Selector (from browser inspect tool) -->
343
+ data-cart-badge-button=".header .nav-links"
344
+ data-cart-badge-button="#main-navigation"
345
+
346
+ <!-- Position-prefixed selectors -->
347
+ data-cart-badge-button="above:.header .logo" <!-- Place above the target -->
348
+ data-cart-badge-button="below:#main-navigation" <!-- Place below the target -->
349
+ data-cart-badge-button="replace:.old-cart" <!-- Replace the target -->
350
+ data-cart-badge-button="inside:.header .nav" <!-- Place inside the target (default) -->
329
351
  ```
330
352
 
331
- #### `data-hide-cart-floating-button`
353
+ **Position Prefixes:**
354
+ - `above:` - Place above the target element
355
+ - `below:` - Place below the target element
356
+ - `replace:` - Replace the target element
357
+ - `inside:` - Place inside the target element (default)
358
+
359
+ #### `data-cart-button-hidden`
332
360
 
333
361
  **Type:** flag (no value)
334
362
 
335
- Hide the default floating cart button.
363
+ Hide cart button completely.
336
364
 
337
365
  ```html
338
- data-hide-cart-floating-button
366
+ data-cart-button-hidden
367
+ ```
368
+
369
+ ### Cart Button Examples
370
+
371
+ **Simple cart button (no badge):**
372
+ ```html
373
+ <script
374
+ data-liquid-commerce-elements
375
+ data-token="your-api-key"
376
+ data-cart-button="header-cart"
377
+ src="elements.js">
378
+ </script>
379
+ ```
380
+
381
+ **Cart button with item count badge:**
382
+ ```html
383
+ <script
384
+ data-liquid-commerce-elements
385
+ data-token="your-api-key"
386
+ data-cart-badge-button="header-cart"
387
+ src="elements.js">
388
+ </script>
389
+ ```
390
+
391
+ **Using position-prefixed selectors:**
392
+ ```html
393
+ <!-- Place inside the target element (default) -->
394
+ <script
395
+ data-liquid-commerce-elements
396
+ data-token="your-api-key"
397
+ data-cart-badge-button="inside:.header .nav-links"
398
+ src="elements.js">
399
+ </script>
400
+
401
+ <!-- Place above the target element -->
402
+ <script
403
+ data-liquid-commerce-elements
404
+ data-token="your-api-key"
405
+ data-cart-button="above:.header .logo"
406
+ src="elements.js">
407
+ </script>
408
+
409
+ <!-- Place below the target element -->
410
+ <script
411
+ data-liquid-commerce-elements
412
+ data-token="your-api-key"
413
+ data-cart-badge-button="below:#main-navigation"
414
+ src="elements.js">
415
+ </script>
416
+
417
+ <!-- Replace the target element -->
418
+ <script
419
+ data-liquid-commerce-elements
420
+ data-token="your-api-key"
421
+ data-cart-button="replace:.old-cart-button"
422
+ src="elements.js">
423
+ </script>
424
+ ```
425
+
426
+ **No cart button:**
427
+ ```html
428
+ <script
429
+ data-liquid-commerce-elements
430
+ data-token="your-api-key"
431
+ data-cart-button-hidden
432
+ src="elements.js">
433
+ </script>
434
+ ```
435
+
436
+ **Default behavior (floating cart button with badge):**
437
+ ```html
438
+ <script
439
+ data-liquid-commerce-elements
440
+ data-token="your-api-key"
441
+ src="elements.js">
442
+ </script>
443
+ ```
444
+
445
+ ### Getting CSS Selectors from Browser
446
+
447
+ **Super Easy Method:**
448
+ 1. **Right-click** on any element where you want the cart button
449
+ 2. Select **"Inspect"** or **"Inspect Element"**
450
+ 3. In developer tools, **right-click** on the highlighted element
451
+ 4. Select **"Copy" → "Copy selector"**
452
+ 5. Paste the selector into your `data-cart-button` or `data-cart-badge-button` attribute
453
+
454
+ **Example:**
455
+ ```html
456
+ <!-- After copying selector from browser inspect tool -->
457
+ <script
458
+ data-liquid-commerce-elements
459
+ data-token="your-api-key"
460
+ data-cart-badge-button="body > div.container > header > nav > div.nav-links"
461
+ src="elements.js">
462
+ </script>
339
463
  ```
340
464
 
341
465
  ### Product Configuration
@@ -102,9 +102,26 @@ console.log('Container:', container); // Should not be null
102
102
  // 2. Wait for DOM
103
103
  window.addEventListener('DOMContentLoaded', async () => {
104
104
  const client = await Elements('YOUR_API_KEY', { env: 'production' });
105
- await client.injectProductElement([
105
+ const components = await client.injectProductElement([
106
106
  { containerId: 'product-container', identifier: 'product-123' }
107
107
  ]);
108
+
109
+ // Check if injection was successful
110
+ if (components.length > 0) {
111
+ console.log('Product component injected successfully');
112
+ // components[0].rerender() - Rerender if needed
113
+ // components[0].getElement() - Get container element
114
+ // components[0].getType() - Get component type
115
+ } else {
116
+ console.log('Product injection failed');
117
+ }
118
+
119
+ // Debug: Check all injected components
120
+ const allComponents = client.getInjectedComponents();
121
+ console.log('All injected components:', allComponents);
122
+ allComponents.forEach((component, containerId) => {
123
+ console.log(`Container: ${containerId}, Type: ${component.getType()}`);
124
+ });
108
125
  });
109
126
 
110
127
  // 3. Monitor product loading
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "LiquidCommerce Elements SDK",
4
4
  "license": "UNLICENSED",
5
5
  "author": "LiquidCommerce Team",
6
- "version": "2.4.1",
6
+ "version": "2.4.2",
7
7
  "homepage": "https://docs.liquidcommerce.co/elements-sdk",
8
8
  "repository": {
9
9
  "type": "git",
@@ -71,7 +71,7 @@
71
71
  "embeddable commerce"
72
72
  ],
73
73
  "devDependencies": {
74
- "@biomejs/biome": "2.2.6",
74
+ "@biomejs/biome": "2.2.7",
75
75
  "@commitlint/cli": "^20.1.0",
76
76
  "@commitlint/config-conventional": "^20.0.0",
77
77
  "@rollup/plugin-alias": "^5.1.1",
@@ -87,14 +87,14 @@
87
87
  "@semantic-release/npm": "^13.1.1",
88
88
  "@semantic-release/release-notes-generator": "^14.1.0",
89
89
  "@types/core-js": "^2.5.8",
90
- "@types/node": "^24.9.0",
90
+ "@types/node": "^24.9.1",
91
91
  "conventional-changelog-cli": "^5.0.0",
92
92
  "husky": "^9.1.7",
93
93
  "process": "^0.11.10",
94
94
  "rollup": "^4.52.5",
95
95
  "rollup-obfuscator": "^4.1.1",
96
96
  "rollup-plugin-typescript2": "^0.36.0",
97
- "semantic-release": "^24.2.9",
97
+ "semantic-release": "^25.0.1",
98
98
  "ts-node": "^10.9.2",
99
99
  "typescript": "^5.9.3"
100
100
  },