type PageClassification = 'cart' | 'checkout' | 'checkoutComplete' | 'collection' | 'customersAccount' | 'customersAuthentication' | 'customersOrders' | 'home' | 'product' | 'search' | 'other' | 'nonShopping';
type Product = {
name: string | null;
price: number | null;
currencyCode: string | null;
quantity: number | null;
imageUrls: string[] | null;
description: string | null;
categoryId: string | null;
categoryBreadcrumb: string | null;
categoryVersion: string | null;
brandName: string | null;
gtin: string | null;
mpn: string | null;
sku: string | null;
asin: string | null;
};
type SdkCoupon = {
id: string;
code: string;
passbackCoupon?: unknown;
};
interface Logger {
debug(message: string, args?: unknown): void;
info(message: string, args?: unknown): void;
warn(message: string, args?: unknown): void;
error(message: string, args?: unknown): void;
}
type ExtractProductsOnTabOptions = {
includeCategory?: boolean;
};
type Order = {
orderDate: string | null;
orderNumber: string | null;
orderTotal: string | null;
orderSubtotal: string | null;
orderTax: string | null;
orderShipping: string | null;
products: Array<{
name: string | null;
price: number | null;
currencyCode: string | null;
quantity: number | null;
imageUrls: string[] | null;
description: string | null;
categoryId: string | null;
categoryBreadcrumb: string | null;
categoryVersion: string | null;
brandName: string | null;
gtin: string | null;
mpn: string | null;
sku: string | null;
asin: string | null;
}> | null;
};
declare enum EventType {
COUPON_ENTRY_COMPLETED = "COUPON_ENTRY_COMPLETED",
COUPON_ENTRY_FAILED = "COUPON_ENTRY_FAILED",
COUPON_ENTRY_STARTED = "COUPON_ENTRY_STARTED",
COUPON_PAGE_DETECTED = "COUPON_PAGE_DETECTED",
COUPON_PAGE_NOT_DETECTED = "COUPON_PAGE_NOT_DETECTED",
COUPON_PAGE_READY = "COUPON_PAGE_READY",
COUPON_SESSION_COMPLETED = "COUPON_SESSION_COMPLETED",
COUPON_SESSION_FAILED = "COUPON_SESSION_FAILED",
COUPON_SESSION_RESUMED = "COUPON_SESSION_RESUMED",
COUPON_SESSION_STARTED = "COUPON_SESSION_STARTED",
COUPON_SESSION_CANCELLED = "COUPON_SESSION_CANCELLED",
USER_GENERATED_CODE = "USER_GENERATED_CODE",
PAGE_CLASSIFIED = "PAGE_CLASSIFIED",
ORDER_COMPLETED = "ORDER_COMPLETED"
}
/**
* @deprecated
*/
interface CouponPageDetectedEvent {
type: EventType.COUPON_PAGE_DETECTED;
data: {
autoApplyAvailable: boolean;
};
}
/**
* @deprecated
*/
interface CouponPageNotDetectedEvent {
type: EventType.COUPON_PAGE_NOT_DETECTED;
}
interface CouponSessionStarted {
type: EventType.COUPON_SESSION_STARTED;
data: {
sessionId: string;
coupons: SdkCoupon[];
};
}
interface CouponSessionResumed {
type: EventType.COUPON_SESSION_RESUMED;
data: {
sessionId: string;
coupons: SdkCoupon[];
coupon: SdkCoupon;
};
}
interface CouponSessionCompletedEvent {
type: EventType.COUPON_SESSION_COMPLETED;
data: {
sessionId: string;
coupons: SdkCoupon[];
bestCoupon?: SdkCoupon;
cartTotalAfter?: number;
cartTotalBefore?: number;
};
}
interface CouponSessionFailedEvent {
type: EventType.COUPON_SESSION_FAILED;
}
type CouponSessionCancelledReason = "user_requested" | "tab_closed" | "hostname_mismatch";
interface CouponSessionCancelledEvent {
type: EventType.COUPON_SESSION_CANCELLED;
data: {
sessionId: string;
coupons: SdkCoupon[];
lastCompletedCoupon?: SdkCoupon;
reason: CouponSessionCancelledReason;
};
}
interface CouponEntryStartedEvent {
type: EventType.COUPON_ENTRY_STARTED;
data: {
sessionId: string;
coupons: SdkCoupon[];
coupon: SdkCoupon;
cartTotalBefore: number;
reapplyingBestCoupon: boolean;
};
}
interface CouponEntryCompletedEvent {
type: EventType.COUPON_ENTRY_COMPLETED;
data: {
sessionId: string;
coupons: SdkCoupon[];
coupon: SdkCoupon;
cartTotalBefore: number;
cartTotalAfter: number;
reapplyingBestCoupon: boolean;
};
}
interface CouponEntryFailedEvent {
type: EventType.COUPON_ENTRY_FAILED;
data: {
sessionId: string;
coupons: SdkCoupon[];
coupon: SdkCoupon;
reapplyingBestCoupon: boolean;
};
}
interface CouponPageReadyEvent {
type: EventType.COUPON_PAGE_READY;
data: {
autoApplyAvailable: boolean;
};
}
interface UserGeneratedCodeEvent {
type: EventType.USER_GENERATED_CODE;
data: {
code: string;
};
}
interface PageClassifiedEvent {
type: EventType.PAGE_CLASSIFIED;
data: {
classification: PageClassification;
};
}
interface OrderCompletedEvent {
type: EventType.ORDER_COMPLETED;
data: {
order: Order;
};
}
type SdkEvent = CouponEntryCompletedEvent | CouponEntryFailedEvent | CouponEntryStartedEvent | CouponPageDetectedEvent | CouponPageNotDetectedEvent | CouponPageReadyEvent | CouponSessionCompletedEvent | CouponSessionFailedEvent | CouponSessionResumed | CouponSessionStarted | CouponSessionCancelledEvent | UserGeneratedCodeEvent | PageClassifiedEvent | OrderCompletedEvent;
type CouponProvider = (urlString: string) => Promise<SdkCoupon[]> | SdkCoupon[];
type TabDetails = {
tabId: number;
url: string;
};
type EventListener = (event: SdkEvent, tabId: number, tabDetails: TabDetails) => void;
// If provided, the order of usage for this coupon session will be:
// 1. coupons
// 2. couponProvider
// 3. The provider from `registerCouponProvider`.
type FillCouponsOnTabOptions = {
coupons: SdkCoupon[];
couponProvider: CouponProvider;
};
interface SleekWebExtCouponSdk {
registerEventListener(listener: EventListener): void;
registerCouponProvider(provider: CouponProvider): void;
fillCouponsOnTab(tabId: number, options?: Partial<FillCouponsOnTabOptions>): Promise<void>;
cancelCouponsOnTab(tabId: number): Promise<void>;
extractProductsOnTab(tabId: number, options?: ExtractProductsOnTabOptions): Promise<Product | Product[] | undefined>;
classifyPageOnTab(tabId: number): Promise<PageClassification | undefined>;
extractOrderOnTab(tabId: number): Promise<Order | undefined>;
}
// If provided, the SDK will use these overrides to determine if the page is eligible for coupon entry. e.g. if you want the SDK to apply coupons on MyProtein, you can provide an override for `www.myprotein.com` with a `pathnameRegex` of `/cart/` and a `readinessElementSelector` of `div[id='coupon-entry']`.
type CouponPageOverride = {
// The exact hostname of the site to override.
hostname: string;
// A regex that matches the pathname of the site to override.
pathnameRegex: string;
// A CSS selector that will be used to determine if the page is ready for coupon entry.
readinessElementSelector: string;
};
interface SleekWebExtCouponSdkOptions {
enableDebug: boolean;
loggerOverride: Logger;
envOverride: Record<string, string | undefined>;
couponPageOverrides: CouponPageOverride[];
addedAnalyticsProperties: Record<string, string | number | boolean>;
skipManifestValidation: boolean;
ignoreCssSelectors: string[];
disableLogger: boolean;
featureControls: Partial<{
emitPageClassification: boolean; // Must be true to emit the `PAGE_CLASSIFIED` event.
emitOrders: boolean; // Must be true to emit the `ORDER_COMPLETED` event.
}>;
}
declare function initializeSleekSdk(apiKey: string, options?: Partial<SleekWebExtCouponSdkOptions>): Promise<SleekWebExtCouponSdk>;
declare function getSdkInstance(): SleekWebExtCouponSdk;