UNPKG

blast-client

Version:

blast client

117 lines (111 loc) 3.45 kB
import { ReactNode } from 'react'; type SubscribeFunctionType = (sub: PushSubscriptionJSON, userAgent: string, userId: string) => Promise<{ success: boolean; }>; type UserProfileType = { userId: string; username: string; name: string; verifiedBadge: "none" | "blue" | "gold"; profile: { url: string; }; }; type DialogNotificationType = { dialogId?: string; showNotification: boolean; title: string; content: string; sender_profile: UserProfileType; send_for: string[]; gets: { subscribeId: string; date: Date; }[]; clicks: { subscribeId: string; type: "confirm" | "dismiss" | "post_message"; content: string; date: Date; }[]; medias: { url: string; type: string; }[]; buttons: { content: string; event: "confirm" | "dismiss" | "post_message"; }[]; }; type DialogType = { dialogId?: string; title: string; content: string; buttons: DialogNotificationType["buttons"]; }; type DialogComponentsProps = { dialogs: DialogType[]; addGets: (dialogId: string, userId: string) => Promise<void>; }; type DialogProps = { dialogs: DialogType[]; addGets: (dialogId: string, userId: string) => Promise<void>; }; type BlastClientOptions = { swPath: string; publicKey: string; scope: string; subscribeUser: SubscribeFunctionType; onMessage?: (payload: { type: "subscribed" | "denied" | "error"; subscribe_id?: string; }) => void; time?: number; repeatCount?: number; }; interface BlastProviderProps extends BlastClientOptions { children: ReactNode; } type MessagePayload = { type: "subscribed" | "denied" | "error"; subscribe_id?: string; }; declare class Sw { private swPath; private publicKey; private scope; private initialized; private clickHandlerAttached; private onMessage?; private subscribeId?; constructor(swPath: string, publicKey: string, scope: string); private getOrCreateUserId; private requestNotificationPermission; private urlBase64ToUint8Array; private trigger; private registerServiceWorker; private getOrCreateSubscription; init(subscribeUser: SubscribeFunctionType, onMessage?: (payload: MessagePayload) => void, intervalMs?: number, repeatCount?: number): Promise<void>; clickNotification(setClick: (notificationId: string, subscribeId: string) => Promise<{ data: any; ok: boolean; }>, log?: boolean): Promise<void>; } declare class PluginBuilder { private sw; constructor(sw: Sw); clickNotification(setClick: (notificationId: string, subscribeId: string) => Promise<{ data: any; ok: boolean; }>, log?: boolean): Promise<void>; } declare class BlastClient { private sw; plugins: PluginBuilder | null; constructor(swPath: string, publicKey: string, scope: string); run(subscribeUser: SubscribeFunctionType, onMessage?: (payload: { type: "subscribed" | "denied" | "error"; subscribe_id?: string; }) => void, time?: number, repeatCount?: number): Promise<Error | "Auto inject complete">; } export { type BlastClientOptions, BlastClient as BlastClientType, type BlastProviderProps, type DialogComponentsProps, type DialogNotificationType, type DialogProps, type DialogType, type SubscribeFunctionType, type UserProfileType };