web-push-notifications
Version:
Pushwoosh web push notifications
203 lines (202 loc) • 6.31 kB
TypeScript
import { type EventHandlerMap, type EventName } from './events.types';
import { type IInitParams, type PWInput } from './Pushwoosh.types';
import { Api } from '../modules/Api/Api';
import { Data } from '../modules/Data/Data';
import InboxMessagesPublic from '../modules/InboxMessagesPublic';
import { PlatformChecker } from '../modules/PlatformChecker';
import { type IPushService } from '../services/PushService/PushService.types';
export declare class Pushwoosh {
ready: boolean;
initParams: IInitParams;
private readonly eventBus;
readonly data: Data;
private readonly apiClient;
private isCommunicationDisabled?;
readonly api: Api;
driver: IPushService;
platformChecker: PlatformChecker;
pwinbox: InboxMessagesPublic;
private inboxModel;
moduleRegistry: Record<string, any>;
constructor();
/**
* Add Web SDK Event Handler.
* Alias to addEventHandler method of EventBus module.
*
* @public
* @readonly
*
* @param {string} name - name of Web SDK event.
* @param {function} handler - handler of Web SDK event.
*
* @returns {void}
*/
addEventHandler: <Name extends EventName>(name: Name, handler: EventHandlerMap[Name]) => void;
/**
* Remove Web SDK Event Handler.
* Alias to removeEventHandler method of EventBus module.
*
* @public
* @readonly
*
* @param {string} name - name of Web SDK event.
* @param {function} handler - handler of Web SDK event.
*
* @returns {void}
*/
removeEventHandler: <Name extends EventName>(name: Name, handler: EventHandlerMap[Name]) => void;
/**
* Dispatch Web SDK Event.
* Alias to dispatchEvent method of EventBus module.
*
* @public
* @readonly
*
* @param {string} name - name of Web SDK event.
* @param {object} payload - event payload.
*
* @returns {string} - event id.
*/
dispatchEvent: <Name extends EventName>(name: Name, payload: Omit<Parameters<EventHandlerMap[Name]>[0], "eventId"> & {
eventId?: string;
}) => string;
/**
* Method that puts the stored error/info messages to browser console.
* @type {{showLog: (() => Promise<any>); showKeyValues: (() => Promise<any>); showMessages: (() => Promise<any>)}}
*/
debug: {
showLog(): Promise<void>;
showKeyValues(): Promise<void>;
showMessages(): Promise<void>;
};
/**
* Polymorph PW method.
* Can get array in format [string, params | callback] or function.
*
* // with callback:
* Pushwoosh.push(['onNotificationClick', function(api, payload) {
* // click on the notificationn
* }]);
*
* // with function:
* Pushwoosh.push(function(api) {
* // this is a bit easier way to subscribe to onReady
* });
*
* // with params:
* // initiates Pushwoosh service and notification subscription
* Pushwoosh.push(['init', {
* applicationCode: 'XXXXX-XXXXX',
* // see more about params in documentation
* // https://docs.pushwoosh.com/docs/web-push-sdk-30#section-integration
* }]);
*
* @param command
*/
push(command: PWInput): void;
/**
* Method initializes the permission dialog on the device
* and registers through the API in case the device hasn't been registered before.
* @returns {Promise<void>}
*/
subscribe(isForceSubscribe?: boolean): Promise<void>;
/**
* Unsubscribe device.
* @returns {Promise<void>}
*/
unsubscribe(): Promise<void>;
/**
* force subscribe if there was a manual unsubscribe
* @returns {Promise<void>}
*/
forceSubscribe(): Promise<void>;
/**
* Check device's registration status
* @returns {boolean}
*/
isDeviceRegistered(): boolean;
isDeviceUnregistered(): boolean;
/**
* Check device's subscription status
* @returns {Promise<boolean>}
*/
isSubscribed(): Promise<boolean>;
/**
* Check current communication state
* @returns {Promise<boolean>}
*/
isCommunicationEnabled(): Promise<boolean>;
/**
* Send "GDPRConsent" postEvent and depends on param "isEnabled"
* device will be registered/unregistered from all communication channels.
* @param {boolean} isEnabled
* @returns {Promise<void>}
*/
setCommunicationEnabled(isEnabled?: boolean): Promise<void>;
/**
* Send "GDPRDelete" postEvent and remove all device device data from Pushwoosh.
* @returns {Promise<void>}
*/
removeAllDeviceData(): Promise<void>;
/**
* Method returns hardware id.
* @returns {Promise<string>}
*/
getHWID(): Promise<string>;
/**
* Method returns push token.
* @returns {Promise<string>}
*/
getPushToken(): Promise<string | undefined>;
/**
* Method returns userId
* @returns {Promise<string | null>}
*/
getUserId(): Promise<string | undefined>;
/**
* Method returns an object with all params.
*/
getParams(): Promise<IInitParams>;
/**
* Method returns true if notifications available.
* @returns {boolean}
*/
isAvailableNotifications(): boolean;
sendStatisticsVisitedPage(): Promise<void>;
private initialize;
private finishInit;
private ensureHwid;
private isUserIdChanged;
/**
* Default process during PW initialization.
* Init API. Subscription to notifications.
* Emit delayed events.
*/
private defaultProcess;
/**
*
* @param {MessageEvent} event
*/
private onServiceWorkerMessage;
/**
* Check device's session and call the appOpen method,
* no more than once an hour.
* Force need to Safari await subscribe status
* @param {boolean} isForce
* @returns {Promise<void>}
*/
private open;
private sendData;
private loadConfig;
private initPushNotifications;
private initDriver;
sendPostEventVisitedPage(): void;
/**
* @private
*
* @param {string} type - legacy event type
* @param {function} handler - legacy handler
*/
private subscribeToLegacyEvents;
private emitLegacyEventsFromServiceWorker;
}