import { N as TApiKey, f as TUrl, b as TNumericId } from '../chunks/utils-BPcZ5h8J.esm.js'; import 'lodash-es/debounce'; import 'lodash-es/isEqual'; type BeamConfigOptions = { apiKey: TApiKey; domain?: TUrl; chainId: TNumericId; storeId?: TNumericId; baseUrl?: TUrl; logUrl?: TUrl; plugins?: BeamPlugin[]; }; type BeamPlugin = { name: string; init: (config: BeamConfigOptions) => Promise; }; /** * BeamConfig is not exported, it should be accessed as a singleton via getConfig & init * @example * import { init, getConfig } from '@beamimpact/web-sdk/dist/integrations/beam' * // In setup script * const beam = await init({ apiKey: '', chainId: 1, storeId: 1, plugins: [] }) * // In other scripts that need to wait for Beam to be ready * const beam = getConfig() * await beam.readyPromise.then(() => doSomething()) * // OR * if (beam.status !== 'ready') { * beam.addEventListener('beamstatuschange', event => { * if (event.detail.status === 'ready') doSomething() * else if (event.detail.status === 'error') handleBeamError() * }) * } */ declare class BeamConfig extends EventTarget { #private; apiKey?: TApiKey; chainId?: TNumericId; storeId?: TNumericId; /** Domain to set Beam cookies on, used if store and checkout are on different subdomains */ domain?: TUrl; /** Beam server URL to make API requests */ baseUrl?: TUrl; /** Beam server URL for logging / errors */ logUrl?: TUrl; /** Alternative to adding event listener for beamstatuschange - resolves when Beam and all plugins are ready */ readyPromise: Promise; /** getConfig().addEventListener("beamstatuschange", ({detail}) => { console.log(detail.status) }) */ status: "pending" | "ready" | "error"; /** Plugins such as Statsig for A/B tests - Beam waits for all plugins to initialize before emitting ready status */ plugins: { [pluginName: string]: BeamPlugin; }; /** Sets up Beam in pending state. This is used for initial value of Beam config singleton, * which allows scripts to access and wait for "ready" promise or event before initialization script runs. * Use init() to set up Beam for use. */ constructor(options: Partial); /** Used by end users to set up Beam with config options and plugins. */ init(options: BeamConfigOptions): Promise; } /** * @example * import { init, getConfig } from '@beamimpact/web-sdk/dist/integrations/beam' * * const beam = await init({ * apiKey: '', * chainId: 1, * storeId: 1, * plugins: [ new StatsigPlugin({ statsigApiKey: '' }) ] * }) * * beam.plugins.statsig.logEvent('cart_updated', 100.00) */ declare const init: (beamConfigOptions: BeamConfigOptions) => Promise; /** * @example * // In scripts that need to wait for Beam to be ready * const beam = getConfig() * await beam.readyPromise * .then(() => doSomething(beam)) * .catch(err => handleBeamError(err)) * // OR * if (beam.status !== 'ready') { * beam.addEventListener('beamstatuschange', event => { * if (event.detail.status === 'ready') doSomething(beam) * else if (event.detail.status === 'error') handleBeamError(event.detail.error) * }) * } */ declare const getConfig: () => BeamConfig; export { getConfig, init }; export type { BeamConfigOptions, BeamPlugin };