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;

// 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>;
    isFillingCouponsOnTab(tabId: number): Promise<boolean>;
}
// 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;
}

declare function initializeSleekSdk(apiKey: string, options?: Partial<SleekWebExtCouponSdkOptions>): Promise<SleekWebExtCouponSdk>;
declare function getSdkInstance(): SleekWebExtCouponSdk;

Event information

Each event is fired per-tab when something coupon related happens in the SDK.

In detail:

  • COUPON_PAGE_DETECTED - fired when the tab navigates to a page where CAA occurs.
  • COUPON_PAGE_NOT_DETECTED - fired by the SDK upon determining that the current web page does not support or allow CAA. This detection occurs as part of the evaluation process whenever a new page is loaded in the tab.
  • COUPON_SESSION_STARTED - fired when the SDK has begun automatically inputting coupons into the tab.
  • COUPON_ENTRY_STARTED - fired when a specific coupon has begun inputting into the tab.
  • COUPON_ENTRY_FAILED - fired when a specific coupon failed to input into the tab. This is when the SDK itself fails, not when the coupon “fails” (e.g. the coupon is invalid on the page but is correctly entered). Errors here are tracked on the Sleek side and indicate things like failure to click buttons, or input text. The extension gracefully handles these errors, showing the user error UI, when necessary.
  • COUPON_ENTRY_COMPLETED - fired when a specific coupon has finished inputting into the tab.
  • COUPON_SESSION_COMPLETED - fired when the entire “session” of CAA has completed. I.e. the entire set of coupons for a site are finished inputting.
  • COUPON_SESSION_FAILED - fired when an unexpected issue occurs during CAA (e.g. coupon provider does not supply any coupons).
  • COUPON_SESSION_RESUMED - fired when a tab reloads and CAA continues. Site specific, but stores like Bed Bath & Beyond reload the tab when a coupon is input. This event is fired since the UI and the couponing process continues on the tab after reload.
  • COUPON_SESSION_CANCELLED - fired when the current session of CAA is cancelled due to the user explicitly calling the cancelCouponsOnTab(tabId: number) SDK API or closing the tab where CAA was occurring.
  • USER_GENERATED_CODE - fired when the user inputs a coupon code into the tab manually after CAA has been completed.