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;
}
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"
}
interface CouponPageDetectedEvent {
type: EventType.COUPON_PAGE_DETECTED;
data: {
autoApplyAvailable: boolean;
};
}
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;
}
interface UserGeneratedCodeEvent {
type: EventType.USER_GENERATED_CODE;
data: {
code: string;
};
}
type SdkEvent = CouponEntryCompletedEvent | CouponEntryFailedEvent | CouponEntryStartedEvent | CouponPageDetectedEvent | CouponPageNotDetectedEvent | CouponPageReadyEvent | CouponSessionCompletedEvent | CouponSessionFailedEvent | CouponSessionResumed | CouponSessionStarted | CouponSessionCancelledEvent | UserGeneratedCodeEvent;
type CouponProvider = (urlString: string) => Promise<SdkCoupon[]> | SdkCoupon[];
type TabDetails = {
tabId: number;
url: string;
};
type EventListener = (event: SdkEvent, tabId: number, tabDetails: TabDetails) => void;
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>;
isFillingCouponsOnTab(tabId: number): Promise<boolean>;
}
interface SleekWebExtCouponSdkOptions {
enableDebug: boolean;
loggerOverride: Logger;
envOverride: Record<string, string | undefined>;
addedAnalyticsProperties: Record<string, string | number | boolean>;
skipManifestValidation: boolean;
ignoreCssSelectors: string[] | undefined;
disableLogger: boolean;
}
declare function initializeSleekSdk(apiKey: string, options?: Partial<SleekWebExtCouponSdkOptions>): Promise<SleekWebExtCouponSdk>;
declare function getSdkInstance(): SleekWebExtCouponSdk;
Each event is fired per-tab when something coupon related happens in the SDK.