UNPKG

@croct/plug

Version:

A fully-featured devkit for building natively personalized applications.

110 lines (106 loc) 5.12 kB
import { SessionFacade } from '@croct/sdk/facade/sessionFacade'; import { UserFacade } from '@croct/sdk/facade/userFacade'; import { TrackerFacade } from '@croct/sdk/facade/trackerFacade'; import { EvaluatorFacade, EvaluationOptions } from '@croct/sdk/facade/evaluatorFacade'; import { Configuration as Configuration$1 } from '@croct/sdk/facade/sdkFacade'; import { Optional } from '@croct/sdk/utilityTypes'; import { ExternalTrackingEventType, ExternalTrackingEventPayload, ExternalTrackingEvent } from '@croct/sdk/trackingEvents'; import { FetchOptions as FetchOptions$1 } from '@croct/sdk/facade/contentFetcherFacade'; import { FetchResponseOptions, FetchResponse as FetchResponse$1 } from '@croct/sdk/contentFetcher'; import { TokenStore } from '@croct/sdk/token'; import { SdkEventManager } from './sdk/index.cjs'; import { VersionedSlotId, SlotContent } from './slot.cjs'; import { JsonValue, JsonObject } from '@croct/json/mutable'; import { Tab } from '@croct/sdk/tab'; import { CidAssigner } from '@croct/sdk/cid'; import { Logger } from '@croct/sdk/logging'; interface PluginSdk { readonly version: string; readonly appId: string; readonly plug: Plug; readonly tracker: TrackerFacade; readonly evaluator: EvaluatorFacade; readonly user: UserFacade; readonly session: SessionFacade; readonly tab: Tab; readonly userTokenStore: TokenStore; readonly previewTokenStore: TokenStore; readonly cidAssigner: CidAssigner; readonly eventManager: SdkEventManager; getLogger(...namespace: string[]): Logger; getTabStorage(...namespace: string[]): Storage; getBrowserStorage(...namespace: string[]): Storage; } interface PluginArguments<T = any> { options: T; sdk: PluginSdk; } interface PluginFactory<T = any> { (args: PluginArguments<T>): Plugin; } interface Plugin { enable(): Promise<void> | void; disable?(): Promise<void> | void; } interface PluginConfigurations { [key: string]: any; } type Configuration = Optional<Configuration$1, 'appId'> & { plugins?: PluginConfigurations; }; type FetchOptions<T> = Omit<FetchOptions$1, 'version'> & { fallback?: T; }; type FetchResponse<I extends VersionedSlotId, C extends JsonObject = JsonObject, F = never, O extends FetchResponseOptions = FetchResponseOptions> = Optional<FetchResponse$1<SlotContent<I, C> | F, O>, 'metadata'>; interface Plug { readonly tracker: TrackerFacade; readonly user: UserFacade; readonly session: SessionFacade; readonly initialized: boolean; readonly flushed: Promise<this>; readonly plugged: Promise<this>; plug(configuration: Configuration): void; isAnonymous(): boolean; getUserId(): string | null; identify(userId: string): void; anonymize(): void; setToken(token: string): void; unsetToken(): void; track<T extends ExternalTrackingEventType>(type: T, payload: ExternalTrackingEventPayload<T>): Promise<ExternalTrackingEvent<T>>; evaluate<T extends JsonValue>(expression: string, options?: EvaluationOptions): Promise<T>; fetch<I extends VersionedSlotId, O extends FetchResponseOptions>(slotId: I, options?: O & FetchOptions<SlotContent<I>>): Promise<FetchResponse<I, JsonObject, never, O>>; fetch<F, I extends VersionedSlotId, O extends FetchResponseOptions>(slotId: I, options?: O & FetchOptions<SlotContent<I> | F>): Promise<FetchResponse<I, JsonObject, F, O>>; unplug(): Promise<void>; } declare class GlobalPlug implements Plug { static readonly GLOBAL: GlobalPlug; private pluginFactories; private instance?; private plugins; private initialize; private ready; constructor(); extend(name: string, plugin: PluginFactory): void; plug(configuration?: Configuration): void; get initialized(): boolean; get plugged(): Promise<this>; get flushed(): Promise<this>; private get sdk(); get tracker(): TrackerFacade; get evaluator(): EvaluatorFacade; get user(): UserFacade; get session(): SessionFacade; isAnonymous(): boolean; getUserId(): string | null; identify(userId: string): void; anonymize(): void; setToken(token: string): void; unsetToken(): void; track<T extends ExternalTrackingEventType>(type: T, payload: ExternalTrackingEventPayload<T>): Promise<ExternalTrackingEvent<T>>; evaluate<T extends JsonValue>(query: string, options?: EvaluationOptions): Promise<T>; test(expression: string, options?: EvaluationOptions): Promise<boolean>; fetch<I extends VersionedSlotId, O extends FetchResponseOptions>(slotId: I, options?: O & FetchOptions<SlotContent<I>>): Promise<FetchResponse<I, JsonObject, never, O>>; fetch<F, I extends VersionedSlotId, O extends FetchResponseOptions>(slotId: I, options?: O & FetchOptions<SlotContent<I> | F>): Promise<FetchResponse<I, JsonObject, F, O>>; unplug(): Promise<void>; } export { type Configuration as C, type FetchResponse as F, GlobalPlug as G, type Plug as P, type Plugin as a, type PluginArguments as b, type PluginFactory as c, type PluginSdk as d, type FetchOptions as e, type PluginConfigurations as f };