npaw-plugin-nwf
Version:
NPAW's Plugin
192 lines (191 loc) • 6.75 kB
TypeScript
import FastDataService from './FastDataService';
import CoreOptions from './CoreOptions';
import CoreStorage from './storage/CoreStorage';
import { Method } from '../common/Constants';
import { Service } from './nqs/Services';
import { Consumer } from './utils/CoreConstants';
import NpawPluginOptions from './NpawPluginOptions';
import ExpirationManager from '../common/ExpirationManager';
export default class Core {
private static _instance;
private options;
private pluginOptions?;
private readonly coreStorage;
private readonly browserStorage;
private readonly fastDataService;
private nqsService;
private sendingOffline;
private isDestroyed;
private usingLegacy;
private commonVariables;
private registeredPeriodicPushes;
private coreEventListeners;
static getInstance(accountCode?: string, options?: NpawPluginOptions, forceNew?: boolean): Core;
private constructor();
/**
* @internal
*/
destroy(): void;
/**
* Return the NPAW Plugin versions
*/
static getPluginVersion(): string;
/**
* @internal
* @returns true if the pluginOptions.legacyPlugin contains a valid legacy plugin instance, false otherwhise
*/
isUsingLegacy(): boolean;
/**
* @internal
* @returns true if the /start or /init requests were sent, false otherwise
*/
wasStartSent(): boolean | undefined;
/**
* @internal
* @param legacyPlugin
*/
setLegacyPlugin(legacyPlugin: any): void;
/**
* Sets the option content.cdn on the legacy plugin if Active Switching is enabled
* @internal
* @param isAsEnabled true if Active Switching is enabled, false otherwhise
*/
setActiveSwitchingOnLegacy(isAsEnabled: boolean): void;
/**
* Fetches the current view code from the legacy plugin object from pluginOptions.legacyOptions
*
* @internal
* @returns The current view code from the legacy plugin
*/
getViewCode(): any;
/**
* @internal
* @returns The FastData server host if using the legacy plugin
*/
getLegacyFastDataHost(): any;
/**
* @internal
* @param options
*/
setOptions(options: object): void;
/**
* @internal
*/
getOptions(): CoreOptions;
/**
* @internal
* @returns the Core storage instance
*/
getCoreStorage(): CoreStorage;
/**
* Stores a common value for a product that might need to be used by other products
*
* @param productKey Product identifier (e.g. balancer)
* @param variableKey Variable identifier (e.g. balancer-id)
* @param value Value to be stored
*/
registerCommonVariable(productKey: string, variableKey: string, value: any): void;
/**
* Deletes a common variable for the specified product
* @param productKey Product identifier (e.g. balancer)
* @param variableKey Variable identifier (e.g. balancer-id)
*/
unregisterCommonVariable(productKey: string, variableKey: string): void;
/**
* Fetches the value stored for a product and variable identifiers
*
* @param productKey Product identifier (e.g. balancer)
* @param variableKey Variable identifier (e.g. balancer-id)
* @returns The value of the variable associated with the product or undefined if it is not set
*/
getCommonVariable(productKey: string, variableKey: string): any | undefined;
/**
* @internal
* @returns The FastData service instance
*/
getFastDataService(): FastDataService;
/**
*
* @returns The FastData service session token
*/
getFastDataSessionToken(): string;
getFastDataSessionHost(): string;
/**
* Refreshes the session token
*/
refreshSessionToken(): void;
/**
*
* @returns true if the session token is expired, false otherwise
*/
isSessionTokenExpired(): boolean;
/**
* Send data as soon as possible to NQS
*
* @internal
* @param consumer Consumer to where data will be sent
* @param service The path to where the request should be performed
* @param method The type of request to be performed (GET, POST, DELETE, ...)
* @param params Data to be sent
* @param body Request body
* @param onSuccessCallback Callback function to call if the request is successful
* @param onFailCallback Callback function to call if the request fails
*/
pushData(consumer: Consumer, service: Service, method: Method, params: any, onSuccessCallback?: () => void, onFailCallback?: () => void): void;
/**
* Periodically fetches data from the callback and sends it to NQS as soon as possible
*
* @internal
* @param consumer Consumer to where we will send data
* @param key Identifier key for the interval
* @param service The path to where the request should be performed
* @param interval The time between dataCallback executions in milliseconds
* @param method The type of request to be performed (GET, POST, DELETE, ...)
* @param dataCallback Callback function to retrieve the data that needs to be sent
* @param onSuccessCallback Callback function to run when request completes successfully
* @param onFailCallback Callback function to run when request fails
* @param expirationManager
*/
pushPeriodicDataFromCallback(consumer: Consumer, key: string, service: Service, interval: number, method: Method, dataCallback: () => any, onSuccessCallback?: () => void, onFailCallback?: () => void, expirationManager?: ExpirationManager): void;
/**
* Stops registered timer to push data
*
* @internal
* @param key Timer identifier
*/
unregisterPeriodicPush(key: string): void;
/**
* Stops all registered timers to push data
*
* @internal
*/
unregisterAllPeriodicPushes(): void;
/**
* Deletes offline entries older than 30 days
* @internal
*/
deleteOldOfflineEntries(): void;
/**
* Sends events that were stored due to offline configuration
*
* @internal
*/
sendOfflineEvents(): Promise<void>;
/**
* Deletes a view data from local storage
* @param viewId
* @private
*/
private deleteViewDataFromLocalStorage;
private handleDataToSend;
/**
* Subscribes a callback to events. These events can be triggered by calling throwEvent.
* @param listener A callback function that will receive event data.
*/
subscribeListener(listener: (eventType: any) => void): void;
/**
* Triggers a event to all subscribed listeners
* @param data The content of the event
*/
throwEvent(eventType: any): void;
}