UNPKG

@bringweb3/chrome-extension-kit

Version:

Crypto cashback integration kit for crypto outlets extension

135 lines (130 loc) 6.02 kB
interface Configuration$1 { getWalletAddress: () => Promise<WalletAddress>; walletAddressUpdateCallback?: (callback: () => void) => void; walletAddressListeners?: string[]; promptLogin: () => Promise<void>; lightTheme?: Style; darkTheme?: Style; theme: string; text: 'upper' | 'lower'; switchWallet: boolean; } /** * Initializes the content script for the Bring extension. * * @async * @function bringInitContentScript * @param {Object} configuration - The configuration object. * @param {Function} configuration.getWalletAddress - A function that returns a Promise resolving to the wallet address. * @param {Function} configuration.promptLogin - A function to prompt the user to login. * @param {string[]} configuration.walletAddressListeners - An optional array of strings representing wallet address listeners. * @param {Function} [configuration.walletAddressUpdateCallback] - An optional callback function for wallet address updates. * @param {Object} [configuration.lightTheme] - Optional light theme settings. * @param {Object} [configuration.darkTheme] - Optional dark theme settings. * @param {string} configuration.theme - The chosen theme, light | dark. * @param {string} configuration.text - The chosen case for some of the texts, upper | lower. * @throws {Error} Throws an error if any required configuration is missing. * @returns {Promise<void>} * * @description * This function sets up event listeners for wallet address changes, iframe messages, * and Chrome runtime messages. It handles actions such as getting the wallet address * and injecting iframes based on received messages. * * @example * bringInitContentScript({ * getWalletAddress: async () => '0x1234...', * promptLogin: () => { ... }, * walletAddressListeners: ["listener1", "listener2"], * theme: 'light', * text: 'lower', * lightTheme: { ... }, * darkTheme: { ... } * }); */ declare const bringInitContentScript: ({ getWalletAddress, promptLogin, walletAddressListeners, walletAddressUpdateCallback, lightTheme, darkTheme, theme, text, switchWallet }: Configuration$1) => Promise<void>; interface Configuration { identifier: string; apiEndpoint: string; whitelistEndpoint?: string; cashbackPagePath?: string; isEnabledByDefault: boolean; showNotifications?: boolean; notificationCallback?: () => void; } /** * Initializes the background script for the Bring extension. * * @async * @function bringInitBackground * @param {Object} configuration - The configuration object. * @param {string} configuration.identifier - The identifier for the extension. * @param {string} configuration.apiEndpoint - The API endpoint ('prod' or 'sandbox'). * @param {string} configuration.whitelistEndpoint - Endpoint for whitelist of redirect urls. * @param {string} [configuration.cashbackPagePath] - Optional path to the cashback page. * @param {boolean} [configuration.isEnabledByDefault] - Determine if the user see the popup by default. defaults to true. * @param {boolean} [configuration.showNotifications] - Determine if the extension should show notifications about new rewards. defaults to true. * @throws {Error} Throws an error if identifier or apiEndpoint is missing, or if apiEndpoint is invalid. * @returns {Promise<void>} * * @description * This function sets up the background processes for the Bring extension. It initializes * the API endpoint, sets up listeners for alarms, runtime messages, and tab updates. * It handles various actions such as opting out, closing notifications, injecting content * based on URL changes, and managing quiet domains. * * The function performs the following tasks: * - Validates and sets the API endpoint * - Updates the cache * - Sets up listeners for alarms to update cache periodically * - Handles runtime messages for opting out and closing notifications * - Monitors tab updates to inject content or show notifications based on URL changes * - Validates domains and manages quiet domains * * @example * bringInitBackground({ * identifier: '<bring_identifier>', * apiEndpoint: 'sandbox', * whitelistEndpoint: 'https://example.com/whitelist.json', * isEnabledByDefault: true, * cashbackPagePath: '/cashback.html' * }); */ declare const bringInitBackground: ({ identifier, apiEndpoint, cashbackPagePath, whitelistEndpoint, isEnabledByDefault, showNotifications, notificationCallback }: Configuration) => Promise<void>; interface TurnOff { isTurnedOff: boolean; } /** * Retrieves the current "turn off" status, true means turned off and false is turned on * * @returns A Promise resolving to the turn-off state * @throws Will reject if there's an error communicating with the background script */ declare const getTurnOff: () => Promise<TurnOff>; /** * Sets the opt-out status for the extension * * @param state - Boolean indicating whether to turn off (true) or turn on (false) * @returns A Promise resolving to the new turn-off state * @throws Will reject if there's an error communicating with the background script */ declare const setTurnOff: (state: boolean) => Promise<TurnOff>; interface PopupEnabled { isPopupEnabled: boolean; } /** * Retrieves the current "turn off" status, true means turned off and false is turned on * * @returns A Promise resolving to the turn-off state * @throws Will reject if there's an error communicating with the background script */ declare const getPopupEnabled: () => Promise<PopupEnabled>; /** * Sets if popup feature is enabled or disabled * * @param state - Boolean indicating whether popup feature is enabled (true) or disabled (false) * @returns A Promise resolving to the new turn-off state * @throws Will reject if there's an error communicating with the background script */ declare const setPopupEnabled: (state: boolean) => Promise<PopupEnabled>; export { bringInitBackground, bringInitContentScript, getPopupEnabled, getTurnOff, setPopupEnabled, setTurnOff };