@flagship.io/js-sdk
Version:
56 lines (55 loc) • 3.11 kB
TypeScript
import { IHttpClient, IHttpResponse } from '../utils/HttpClient';
import { IEmotionAI } from './IEmotionAI';
import { EAIConfig } from '../type.local';
import { IVisitorEvent } from './hit/IVisitorEvent';
import { IPageView } from './hit/IPageView';
import { IFlagshipConfig } from '../config/IFlagshipConfig';
import { EAIScore, TroubleshootingLabel } from '../types';
import { VisitorAbstract } from '../visitor/VisitorAbstract';
import { VisitorEvent } from './hit/VisitorEvent';
import { HttpError } from '../utils/HttpError.ts';
type ConstructorParam = {
httpClient: IHttpClient;
sdkConfig: IFlagshipConfig;
eAIConfig: EAIConfig | undefined;
};
export declare abstract class CommonEmotionAI implements IEmotionAI {
protected _EAIScore?: EAIScore;
protected _EAIScoreChecked: boolean;
protected _httpClient: IHttpClient;
protected _sdkConfig: IFlagshipConfig;
protected _eAIConfig?: EAIConfig;
protected _isEAIDataCollecting: boolean;
protected _fetchEAIScorePromise?: Promise<IHttpResponse>;
protected _startScoringTimestamp: number;
protected _scoringIntervalId?: NodeJS.Timeout;
protected _onEAICollectStatusChange?: (status: boolean) => void;
protected _visitor: VisitorAbstract;
/**
* Indicates whether EAI data has been collected
*/
protected _startCollectingEAIDataTimestamp: number;
constructor({ httpClient, sdkConfig, eAIConfig }: ConstructorParam);
init(visitor: VisitorAbstract): void;
onEAICollectStatusChange(callback: (status: boolean) => void): void;
get EAIScore(): EAIScore | undefined;
get EAIScoreChecked(): boolean;
abstract cleanup(): void;
protected setIsEAIDataCollected(isCollected: boolean): Promise<void>;
protected isEAIDataCollected(): Promise<boolean>;
protected sendEAIScoreTroubleshooting(eAIScore?: EAIScore, endpoint?: string): void;
protected sendRequestTroubleshooting(response: IHttpResponse, label: TroubleshootingLabel, endpoint?: string, method?: string, apiKeys?: Record<string, boolean | string | number>, eAIScore?: EAIScore): void;
protected sendRequestTroubleshootingError(error: HttpError, label: TroubleshootingLabel, endpoint?: string, apiKeys?: Record<string, boolean | string | number>): void;
protected sendCollectingTroubleshooting(timestamp: number, label: TroubleshootingLabel, score?: EAIScore): void;
protected sendCollectingUsageHit(label: TroubleshootingLabel): void;
fetchEAIScore(noCache?: boolean): Promise<EAIScore | undefined>;
protected abstract startCollectingEAIData(visitorId: string, currentPage?: Omit<IPageView, 'toApiKeys'>): Promise<void>;
protected abstract removeListeners(): void;
collectEAIEventsAsync(currentPage?: Omit<IPageView, 'toApiKeys'>): Promise<void>;
reportPageView(pageView: IPageView): Promise<void>;
protected sendEAIEvent(event: IVisitorEvent | IPageView): Promise<void>;
protected finalizeDataCollection(isCollected: boolean): void;
protected stopCollectingEAIData(): void;
reportVisitorEvent(visitorEvent: VisitorEvent): Promise<void>;
}
export {};