unified-datalayer
Version:
A multi-framework utility package for managing XP Data Layer events
69 lines (68 loc) • 2.38 kB
TypeScript
import DataLayer from "./DataLayer";
import { Product, ProductData, EventData, Cart_Product, CartProductData } from "./types";
/**
* BaseModule provides shared functionality for all data layer modules
*/
export declare abstract class BaseModule {
protected dataLayer: DataLayer;
constructor(dataLayer: DataLayer);
/**
* Pushes an event to the data layer
* @param eventName The name of the event
* @param eventData The data to include with the event
*/
pushEvent(eventName: string, eventData?: EventData): Promise<void>;
protected clearProducts(): void;
/**
* Formats a string by converting to lowercase and replacing spaces and certain
* special characters with hyphens while preserving apostrophes
*
* @param input - The string to format
* @returns The formatted string
*/
protected formatString(input: string): string;
/**
* Takes a Product object and correctly formats it according to ProductResp interface
*
* @param product - The ProductInput object
* @returns The correctly formatted Product object
*/
protected formatProduct(product: ProductData): Product;
protected formatCartItem(product: CartProductData): Cart_Product;
/**
* Validates that a string parameter meets requirements
*/
protected validateString(value: any, paramName: string, options?: {
required?: boolean;
allowEmpty?: boolean;
minLength?: number;
maxLength?: number;
pattern?: RegExp;
}): void;
/**
* Validates that a number parameter meets requirements
*/
protected validateNumber(value: any, paramName: string, options?: {
required?: boolean;
integer?: boolean;
min?: number;
max?: number;
positive?: boolean;
}): void;
/**
* Validates multiple arguments at once
*/
protected validateMultiple(validations: Array<{
value: any;
paramName: string;
type: "string" | "number";
options?: any;
}>): void;
/**
* Validates that input is of type ProductData
* @param data
* @param paramName
*/
protected validateProductData(data: any, paramName?: string): asserts data is ProductData;
protected validateCartProductData(data: any, paramName?: string): asserts data is CartProductData;
}