UNPKG

rox-ssr

Version:

Rollout.io ROX JS SDK Client for SSR

214 lines (213 loc) 8 kB
import { Flag } from './flag'; import { RoxString } from './string'; import { RoxNumber } from './number'; export { Flag } from './flag'; export { RoxString } from './string'; export { RoxNumber } from './number'; declare global { interface Window { rolloutData: any; } } export interface RoxContainer { [key: string]: Flag | RoxNumber | RoxString; } export declare enum RoxFetcherStatus { AppliedFromEmbedded = "APPLIED_FROM_EMBEDDED", AppliedFromCache = "APPLIED_FROM_CACHE", AppliedFromNetwork = "APPLIED_FROM_NETWORK", ErrorFetchFailed = "ERROR_FETCH_FAILED" } export interface RoxFetcherResult { fetcherStatus: RoxFetcherStatus; creationDate: Date; hasChanges: boolean; errorDetails?: string; clientData?: string; } export interface RoxReporting { name: string; value: string; } export interface RoxExperiment { identifier: string; name: string; isArchived: boolean; labels: string[]; } export interface SelfManagedOptions { serverURL: string; analyticsURL: string; pushUpdateURL?: string; configurationURL?: string; stateURL?: string; } export interface RoxSetupOptions { version?: string; configurationFetchedHandler?(fetcherResult: RoxFetcherResult): void; debugLevel?: 'verbose'; impressionHandler?(reporting: RoxReporting, context: any): void; platform?: string; fetchIntervalInSec?: number; disableNetworkFetch?: boolean; dynamicPropertyRuleHandler?(propName: string, context: any): object; /** * Do not listen to flag configuration changes. * Users will only get new flag configuration after reloading the webapp in the browser */ disablePushUpdateListener?: boolean; devModeSecret?: string; /** * Set Roxy's URL for automated tests or local development. * * https://support.rollout.io/docs/microservices-automated-testing-and-local-development */ roxy?: string; selfManaged?: SelfManagedOptions; disableSignatureVerification?: boolean; } export interface dynamicApi { /** * Getting boolean value of a flag */ isEnabled(nameSpacedFlagName: string, defaultValue: boolean, context?: any): boolean; /** * Getting string value of a RoxString flag */ value(nameSpacedFlagName: string, defaultValue: string, context?: any): string; /** * Getting string value of a RoxNumber flag */ getNumber(nameSpacedFlagName: string, defaultValue: number, context?: any): string; } export interface overrides { /** * Sets an override value on a specific flag, this function accepts two parameters flag name ( * full flag name including namespace) and desired value (from type String). * This function also saves the override value on the local device disk, * so it is "remembered" for the next the SDK is loaded to production. * * https://support.rollout.io/docs/javascript-browser-api#section--rox-overrides-setoverride- * * Note that for boolean flag we still give the value as a string. */ setOverride(nameSpacedFlagName: string, value: string): void; /** * Clears the override value from the flag (and the disk). * * https://support.rollout.io/docs/javascript-browser-api#section--rox-overrides-clearoverride- */ clearOverride(nameSpacedFlagName: string): void; /** * Clears all override values */ clearAllOverrides(): void; getOriginalValue(nameSpacedFlagName: string): string; /** * full flag name including namespace * * https://support.rollout.io/docs/javascript-browser-api#section--rox-overrides-hasoverride- */ hasOverride(nameSpacedFlagName: string): boolean; } export declare enum RoxOverridesPosition { TopLeft = "top left", TopRight = "top right", BottomLeft = "bottom left", BottomRight = "bottom right" } export declare class _RoxClient { /** * Dynamic API is an alternative to Rollout static API for defining flags on the * different container objects and accessing them from that container object. * https://support.rollout.io/docs/dynamic-api */ dynamicApi: dynamicApi; /** * Override: Should only be used for development purposes (QA - Feature dev - e2e) * * When you override an existing flag value using the Rox.overrides.setOverride method, * the SDK will disregard existing configuration coming from the dashboard and will * serialize the override on disk this value will be loaded and override the flag * right after you call Rox.setup. To clear the override from the cache you need to * call the Rox.overrides.clearOverride method. * * One can refer to the javascript-browser-api for this feature: * https://support.rollout.io/docs/javascript-browser-api#section--rox-overrides- */ overrides: overrides; private alreadyInitialized; private _configurationFetchedHandlers; private _rolloutData; private _initialSetup; private _confFetchedHandlers; private _impressionHandlers; /** * The register function should be called before the call to Rox.setup() * * https://support.rollout.io/docs/nodejs-api#section-register */ register(namespace: string, roxContainer: RoxContainer): void; /** * The register function should be called before the call to Rox.setup() * * https://support.rollout.io/docs/nodejs-api#section-register */ register(roxContainer: RoxContainer): void; setup(apiKey: string, options?: RoxSetupOptions): Promise<void>; private _confFetchedHandler; private _impressionsHandler; /** * Initiate connection with Rox servers for the application identified by the application key. * The registered containers will be synced and Rox entities will get the appropriate values. * * https://support.rollout.io/docs/nodejs-api#section-setup */ _setup(apiKey: string, options?: RoxSetupOptions): Promise<void>; /** * Set Global Context. * You can think of Global Context as a default context * * https://support.rollout.io/docs/nodejs-api#section-setcontext */ setContext(globalContext: any): void; setCustomNumberProperty(name: string, value: number | ((context?: any) => number)): void; setCustomStringProperty(name: string, value: string | ((context?: any) => string)): void; setCustomBooleanProperty(name: string, value: boolean | ((context?: any) => boolean)): void; setCustomDateProperty(name: string, value: Date | ((context?: any) => Date)): void; setCustomSemverProperty(name: string, value: string | ((context?: any) => string)): void; /** * Pulls the latest configuration and flag values down from the Rollout servers * * https://support.rollout.io/docs/nodejs-api#section-fetch */ fetch(): void; /** * Opens the flag override view, providing a debug UI for the application's set of * feature flags. * This is only available in a browser context * https://support.rollout.io/docs/javascript-browser-api#section-showoverrides */ showOverrides(position?: RoxOverridesPosition): void; private _configurationFetchedHandler; /** * The Rollout configuration data. This is intended to be called on the server side * and passed to the browser to hydrate Rollout's configuration data on browser side. * @example React example * import {Rox} from 'rox-ssr'; * // ... * // Your component render() method * render() { * return ( * <html> * <head> * <script type='text/javascript' * dangerouslySetInnerHTML={{ __html: `window.rolloutData = ${Rox.rolloutData};` }} /> * <head> * </html>) * } */ get rolloutData(): string; get flags(): ReadonlyArray<Flag | RoxString | RoxNumber>; } export declare const Rox: _RoxClient;