import { FallbackFeatureOverride, RawFeatures } from './feature/features'; import { Feedback, FeedbackOptions, RequestFeedbackData } from './feedback/feedback'; import { ToolbarPosition } from './ui/types'; import { CompanyContext, UserContext } from './context'; import { HookArgs } from './hooksManager'; import { Logger } from './logger'; /** * (Internal) User context. * * @internal */ export type User = { /** * Identifier of the user. */ userId: string; /** * User attributes. */ attributes?: { /** * Name of the user. */ name?: string; /** * Email of the user. */ email?: string; /** * Avatar URL of the user. */ avatar?: string; /** * Custom attributes of the user. */ [key: string]: any; }; /** * Custom context of the user. */ context?: PayloadContext; }; /** * (Internal) Company context. * * @internal */ export type Company = { /** * User identifier. */ userId: string; /** * Company identifier. */ companyId: string; /** * Company attributes. */ attributes?: { /** * Name of the company. */ name?: string; /** * Custom attributes of the company. */ [key: string]: any; }; context?: PayloadContext; }; /** * Tracked event. */ export type TrackedEvent = { /** * Event name. */ event: string; /** * User identifier. */ userId: string; /** * Company identifier. */ companyId?: string; /** * Event attributes. */ attributes?: Record; /** * Custom context of the event. */ context?: PayloadContext; }; /** * (Internal) Custom context of the event. * * @internal */ export type PayloadContext = { /** * Whether the company and user associated with the event are active. */ active?: boolean; }; /** * BucketClient configuration. */ export interface Config { /** * Base URL of Bucket servers. */ apiBaseUrl: string; /** * Base URL of the Bucket web app. */ appBaseUrl: string; /** * Base URL of Bucket servers for SSE connections used by AutoFeedback. */ sseBaseUrl: string; /** * Whether to enable tracking. */ enableTracking: boolean; /** * Whether to enable offline mode. */ offline: boolean; } /** * Toolbar options. */ export type ToolbarOptions = boolean | { show?: boolean; position?: ToolbarPosition; }; /** * Feature definitions. */ export type FeatureDefinitions = Readonly>; /** * BucketClient initialization options. */ export type InitOptions = { /** * Publishable key for authentication */ publishableKey: string; /** * User related context. If you provide `id` Bucket will enrich the evaluation context with * user attributes on Bucket servers. */ user?: UserContext; /** * Company related context. If you provide `id` Bucket will enrich the evaluation context with * company attributes on Bucket servers. */ company?: CompanyContext; /** * Context not related to users or companies */ otherContext?: Record; /** * You can provide a logger to see the logs of the network calls. * This is undefined by default. * For debugging purposes you can just set the browser console to this property: * ```javascript * options.logger = window.console; * ``` */ logger?: Logger; /** * Base URL of Bucket servers. You can override this to use your mocked server. */ apiBaseUrl?: string; /** * Base URL of the Bucket web app. Links open ín this app by default. */ appBaseUrl?: string; /** * Whether to enable offline mode. Defaults to `false`. */ offline?: boolean; /** * Feature keys for which `isEnabled` should fallback to true * if SDK fails to fetch features from Bucket servers. If a record * is supplied instead of array, the values of each key represent the * configuration values and `isEnabled` is assume `true`. */ fallbackFeatures?: string[] | Record; /** * Timeout in milliseconds when fetching features */ timeoutMs?: number; /** * If set to true stale features will be returned while refetching features */ staleWhileRevalidate?: boolean; /** * If set, features will be cached between page loads for this duration */ expireTimeMs?: number; /** * Stale features will be returned if staleWhileRevalidate is true if no new features can be fetched */ staleTimeMs?: number; /** * When proxying requests, you may want to include credentials like cookies * so you can authorize the request in the proxy. * This option controls the `credentials` option of the fetch API. */ credentials?: "include" | "same-origin" | "omit"; /** * Base URL of Bucket servers for SSE connections used by AutoFeedback. */ sseBaseUrl?: string; /** * AutoFeedback specific configuration */ feedback?: FeedbackOptions; /** * Version of the SDK */ sdkVersion?: string; /** * Whether to enable tracking. Defaults to `true`. */ enableTracking?: boolean; /** * Toolbar configuration */ toolbar?: ToolbarOptions; }; /** * A remotely managed configuration value for a feature. */ export type FeatureRemoteConfig = { /** * The key of the matched configuration value. */ key: string; /** * The optional user-supplied payload data. */ payload: any; } | { key: undefined; payload: undefined; }; /** * Represents a feature. */ export interface Feature { /** * Result of feature flag evaluation. * Note: Does not take local overrides into account. */ isEnabled: boolean; config: FeatureRemoteConfig; /** * Function to send analytics events for this feature. */ track: () => Promise; /** * Function to request feedback for this feature. */ requestFeedback: (options: Omit) => void; /** * The current override status of isEnabled for the feature. */ isEnabledOverride: boolean | null; /** * Set the override status for isEnabled for the feature. * Set to `null` to remove the override. */ setIsEnabledOverride(isEnabled: boolean | null): void; } /** * BucketClient lets you interact with the Bucket API. */ export declare class BucketClient { private readonly publishableKey; private readonly context; private config; private requestFeedbackOptions; private readonly httpClient; private readonly autoFeedback; private autoFeedbackInit; private readonly featuresClient; readonly logger: Logger; private readonly hooks; /** * Create a new BucketClient instance. */ constructor(opts: InitOptions); /** * Initialize the Bucket SDK. * * Must be called before calling other SDK methods. */ initialize(): Promise; /** * Add an event listener * * @param type Type of events to listen for * @param handler The function to call when the event is triggered. * @returns A function to remove the hook. */ on(type: THookType, handler: (args0: HookArgs[THookType]) => void): () => void; /** * Remove an event listener * * @param type Type of event to remove. * @param handler The same function that was passed to `on`. * * @returns A function to remove the hook. */ off(type: THookType, handler: (args0: HookArgs[THookType]) => void): void; /** * Get the current configuration. */ getConfig(): Config; /** * Update the user context. * Performs a shallow merge with the existing user context. * Attempting to update the user ID will log a warning and be ignored. * * @param user */ updateUser(user: { [key: string]: string | number | undefined; }): Promise; /** * Update the company context. * Performs a shallow merge with the existing company context. * Attempting to update the company ID will log a warning and be ignored. * * @param company The company details. */ updateCompany(company: { [key: string]: string | number | undefined; }): Promise; /** * Update the company context. * Performs a shallow merge with the existing company context. * Updates to the company ID will be ignored. * * @param otherContext Additional context. */ updateOtherContext(otherContext: { [key: string]: string | number | undefined; }): Promise; /** * Track an event in Bucket. * * @param eventName The name of the event. * @param attributes Any attributes you want to attach to the event. */ track(eventName: string, attributes?: Record | null): Promise; /** * Submit user feedback to Bucket. Must include either `score` or `comment`, or both. * * @param payload The feedback details to submit. * @returns The server response. */ feedback(payload: Feedback): Promise; /** * Display the Bucket feedback form UI programmatically. * * This can be used to collect feedback from users in Bucket in cases where Automated Feedback Surveys isn't appropriate. * * @param options */ requestFeedback(options: RequestFeedbackData): void; /** * Returns a map of enabled features. * Accessing a feature will *not* send a check event * and `isEnabled` does not take any feature overrides * into account. * * @returns Map of features. */ getFeatures(): RawFeatures; /** * Return a feature. Accessing `isEnabled` or `config` will automatically send a `check` event. * @returns A feature. */ getFeature(key: string): Feature; private sendCheckEvent; /** * Stop the SDK. * This will stop any automated feedback surveys. * **/ stop(): Promise; /** * Send attributes to Bucket for the current user */ private user; /** * Send attributes to Bucket for the current company. */ private company; } //# sourceMappingURL=client.d.ts.map