@ninetailed/experience.js-plugin-preview
Version:
Ninetailed SDK plugin for preview
101 lines (100 loc) • 4.34 kB
TypeScript
import { Reference, AllowedVariableType } from '@ninetailed/experience.js-shared';
import { ExperienceConfiguration, PROFILE_CHANGE, HasExperienceSelectionMiddleware, BuildExperienceSelectionMiddleware, HasChangesModificationMiddleware, BuildChangesModificationMiddleware, type ProfileChangedPayload, type InterestedInProfileChange } from '@ninetailed/experience.js';
import type { ExposedAudienceDefinition, PreviewBridgeOptions } from '@ninetailed/experience.js-preview-bridge';
import { type EventHandler, NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
import { WidgetContainerOptions } from './WidgetContainer';
export declare const NINETAILED_PREVIEW_EVENTS: {
previewAudiences: string;
previewTraits: string;
};
type NinetailedPreviewPluginOptions = {
experiences: ExperienceConfiguration[];
audiences: ExposedAudienceDefinition[];
onOpenExperienceEditor?: (experience: ExperienceConfiguration) => void;
onOpenAudienceEditor?: (audience: ExposedAudienceDefinition) => void;
} & PreviewBridgeOptions & WidgetContainerOptions;
export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements HasExperienceSelectionMiddleware<Reference, Reference>, HasChangesModificationMiddleware, InterestedInProfileChange {
private readonly options;
name: string;
private isOpen;
private readonly experiences;
private readonly audienceDefinitions;
private audienceOverwrites;
private experienceVariantIndexOverwrites;
private variableOverwrites;
private profile;
private changes;
private container;
private bridge;
/**
* Since several instances of the plugin can be created, we need to make sure only one is marked as active.
*/
private isActiveInstance;
private onChangeEmitter;
private readonly onOpenExperienceEditor;
private readonly onOpenAudienceEditor;
private clientId;
private environment;
constructor(options: NinetailedPreviewPluginOptions);
initialize: () => Promise<void>;
loaded: () => boolean;
[PROFILE_CHANGE]: EventHandler<ProfileChangedPayload>;
open(): void;
close(): void;
toggle(): void;
activateAudience(id: string): void;
deactivateAudience(id: string): void;
resetAudience(id: string): void;
setExperienceVariant({ experienceId, variantIndex, }: {
experienceId: string;
variantIndex: number;
}): void;
resetExperience(experienceId: string): void;
reset(): void;
/**
* Implements the HasChangesModificationMiddleware interface
* Returns a middleware function that applies variable overwrites to changes
*/
getChangesModificationMiddleware: BuildChangesModificationMiddleware;
/**
* Sets a variable value override for preview
*/
setVariableValue({ experienceId, key, value, variantIndex, }: {
experienceId: string;
key: string;
value: AllowedVariableType;
variantIndex: number;
}): void;
getExperienceSelectionMiddleware: BuildExperienceSelectionMiddleware<Reference, Reference>;
openExperienceEditor(experience: ExperienceConfiguration): void;
/**
* @deprecated This method will be removed in a future release. Use `openExperienceEditor` instead to see the experience insights.
*/
openExperienceAnalytics(experience: ExperienceConfiguration): void;
openAudienceEditor(audience: ExposedAudienceDefinition): void;
private get pluginApi();
private get windowApi();
private isKnownAudience;
private get potentialAudiences();
private get activeAudiences();
private calculateExperienceVariantIndexes;
private get apiExperienceVariantIndexes();
private get experienceVariantIndexes();
/**
* Get the override key for a variable
*/
private getOverrideKey;
/**
* Get effective changes by applying overrides - compute on demand
*/
private getEffectiveChanges;
private onChange;
private onProfileChange;
/**
* Handles changes from the SDK and applies any variable overrides.
* This should be called whenever the original changes are updated.
*/
private onChangesChange;
private setCredentials;
}
export {};