Skip to content

Latest commit

 

History

History
717 lines (394 loc) · 14.1 KB

README.md

File metadata and controls

717 lines (394 loc) · 14.1 KB

web-push-notifications

web-push-notifications

Index

Classes

Utility Interfaces

Type aliases

Variables

Firebase Functions

Other Functions

Push server API Functions

ServiceWorker Functions

Utility Functions

Object literals

Type aliases

DefaultValue

Ƭ DefaultValue: Primitive | Function | Record‹string, string›

Defined in src/utils/getLocalStorageParam.ts:3


RegisterConfig

Ƭ RegisterConfig: object

Defined in src/api/getConfig.ts:6

Type declaration:

  • appId: string | null

  • appName: AppName

  • appVersion: string | null

  • createAt: string | null

  • deviceToken: string | null

  • deviceType: DeviceType

  • timezone: number

  • updateAt: string | null

  • userId: string | null


SWRegistration

Ƭ SWRegistration: PushSubscription | Response | null | undefined | void

Defined in src/WebPush.ts:18


UnregisterConfig

Ƭ UnregisterConfig: object

Defined in src/api/getConfig.ts:18

Type declaration:

  • appId: string | null

  • appName: AppName

  • deviceType: DeviceType

Variables

Const API_REGISTER

API_REGISTER: "register" = "register"

Defined in src/constants/api.ts:19


Const API_REGISTER_SAFARI

API_REGISTER_SAFARI: "register-safari" = "register-safari"

Defined in src/constants/api.ts:20


Const API_SAFARI_APPLICATION_ID

API_SAFARI_APPLICATION_ID: "web-safari-push" = "web-safari-push"

Defined in src/constants/api.ts:25


Const API_SAFARI_ENDPOINT

API_SAFARI_ENDPOINT: "safari" = "safari"

Defined in src/constants/api.ts:24


Const API_UNREGISTER

API_UNREGISTER: "unregister" = "unregister"

Defined in src/constants/api.ts:21


Const API_UNREGISTER_SAFARI

API_UNREGISTER_SAFARI: "unregister-safari" = "unregister-safari"

Defined in src/constants/api.ts:22


Const API_URL

API_URL: "https://push.mirtesen.ru/api/push" = "https://push.mirtesen.ru/api/push"

Defined in src/constants/api.ts:1


Const API_WEB_PUSH_ID

API_WEB_PUSH_ID: "web.com.push" = "web.com.push"

Defined in src/constants/api.ts:27


Const APP_ID_PREFIX

APP_ID_PREFIX: string = ${PREFIX}_push_id

Defined in src/constants/api.ts:6


Const APP_INSTALL_DATE

APP_INSTALL_DATE: string = ${PREFIX}_push_install_date

Defined in src/constants/api.ts:8


Const APP_NAME_PREFIX

APP_NAME_PREFIX: string = ${PREFIX}_push_name

Defined in src/constants/api.ts:7


Const APP_VERSION_PREFIX

APP_VERSION_PREFIX: string = ${PREFIX}_push_version

Defined in src/constants/api.ts:5


Const DEFAULT_SW_PATH

DEFAULT_SW_PATH: "service-worker.js" = "service-worker.js"

Defined in src/constants/api.ts:17


Const FCM_TOKEN_PREFIX

FCM_TOKEN_PREFIX: string = ${PREFIX}_fcm_token

Defined in src/constants/api.ts:10


Const NOTIFICATIONS_ACCEPTED_EVENT

NOTIFICATIONS_ACCEPTED_EVENT: string = ${PREFIX}_notifications_accepted

Defined in src/constants/api.ts:14


Const NOTIFICATIONS_DECLINED_EVENT

NOTIFICATIONS_DECLINED_EVENT: string = ${PREFIX}_notifications_declined

Defined in src/constants/api.ts:15


Const PREFIX

PREFIX: "web_push_lib" = "web_push_lib"

Defined in src/constants/api.ts:2


Const PushInstaller

PushInstaller: WebPush‹› = new WebPush()

Defined in src/web-push-installer.ts:3


Const SHOW_NOTIFICATION

SHOW_NOTIFICATION: string = ${PREFIX}_show_notification

Defined in src/constants/signals.ts:3


Const SW_MESSAGE

SW_MESSAGE: string = ${PREFIX}_sw_message

Defined in src/constants/signals.ts:4


Const SW_PATH

SW_PATH: string = ${PREFIX}_sw_path

Defined in src/constants/api.ts:3


Const USER_ID_PREFIX

USER_ID_PREFIX: string = ${PREFIX}_user_id

Defined in src/constants/api.ts:12


info

info: info

Defined in src/WebPush.ts:20


Const publicVapidKey

publicVapidKey: "VAPID_KEY_FROM_CONSOLE" = "VAPID_KEY_FROM_CONSOLE"

Defined in src/constants/firebase.ts:1


warn

warn: warn

Defined in src/api/registerOnPushServer.ts:4

Defined in src/firebase/initFCM.ts:5

Defined in src/api/unregisterOnPushServer.ts:4

Defined in src/WebPush.ts:20

Defined in src/service-worker.ts:10

Firebase Functions

getFCMToken

getFCMToken(messaging: FirebaseMessaging): Promise‹object›

Defined in src/firebase/getFCMToken.ts:10

Generate or return existing Firebase Cloud Messaging device token

Parameters:

Name Type
messaging FirebaseMessaging

Returns: Promise‹object›


initFCM

initFCM(registration: ServiceWorkerRegistration): FirebaseMessaging

Defined in src/firebase/initFCM.ts:13

Initialize Firebase Cloud Messaging service Subscribe on device token refresh event

Parameters:

Name Type
registration ServiceWorkerRegistration

Returns: FirebaseMessaging


Other Functions

checkSafariNotificationPermission

checkSafariNotificationPermission(): Promise‹SafariPermission›

Defined in src/utils/checkPermission.ts:5

Returns: Promise‹SafariPermission›


checkServices

checkServices(): CheckServices

Defined in src/utils/checkServices.ts:11

Returns: CheckServices


checkStandardNotificationPermission

checkStandardNotificationPermission(): Promise‹boolean›

Defined in src/utils/checkPermission.ts:22

Returns: Promise‹boolean›


Const registerExternalScript

registerExternalScript(url: string, onLoad?: undefined | function): void

Defined in src/utils/registerExternalScript.ts:1

Parameters:

Name Type
url string
onLoad? undefined | function

Returns: void


Push server API Functions

getConfig

getConfig(type: "register" | "unregister"): object

Defined in src/api/getConfig.ts:82

Create configuration based on push server request type

Parameters:

Name Type Default
type "register" | "unregister" "register"

Returns: object

  • appId: string | null

  • appName: AppName

  • deviceType: DeviceType


getRegisterConfig

getRegisterConfig(): RegisterConfig

Defined in src/api/getConfig.ts:28

Create registration configuration based on push server request scheme

Returns: RegisterConfig


getUnregisterConfig

getUnregisterConfig(): UnregisterConfig

Defined in src/api/getConfig.ts:62

Create unregister configuration based on push server request scheme

Returns: UnregisterConfig


registerOnPushServer

registerOnPushServer(isSafari?: undefined | false | true): Promise‹Response | void›

Defined in src/api/registerOnPushServer.ts:11

Register on push server with provided configuration from getRegisterConfig output

Parameters:

Name Type
isSafari? undefined | false | true

Returns: Promise‹Response | void›


unregisterOnPushServer

unregisterOnPushServer(isSafari?: undefined | false | true): Promise‹Response | void›

Defined in src/api/unregisterOnPushServer.ts:11

Unegister on push server with provided configuration from getUnregisterConfig output

Parameters:

Name Type
isSafari? undefined | false | true

Returns: Promise‹Response | void›


ServiceWorker Functions

handleClientBroadcast

handleClientBroadcast(event: MessageEvent & ExtendableEvent): void

Defined in src/service-worker.ts:17

Handle message event with defined type from signals from main thread

Parameters:

Name Type
event MessageEvent & ExtendableEvent

Returns: void


handlePush

handlePush(event: PushEvent): void

Defined in src/service-worker.ts:41

Handle push message event (show notification)

Parameters:

Name Type
event PushEvent

Returns: void


Utility Functions

checkSubscription

checkSubscription(registration: ServiceWorkerRegistration, unsubscribe: boolean): Promise‹PushSubscription | null | void›

Defined in src/utils/checkSubscription.ts:9

Check/Set push notifications subscription

Parameters:

Name Type Default
registration ServiceWorkerRegistration -
unsubscribe boolean false

Returns: Promise‹PushSubscription | null | void›


getLocalStorageParam

getLocalStorageParam(key: string, defaultValue?: DefaultValue): string | null

Defined in src/utils/getLocalStorageParam.ts:10

Get option from local storage by defined key

Parameters:

Name Type
key string
defaultValue? DefaultValue

Returns: string | null


Const isFunction

isFunction<T>(entity: T): boolean

Defined in src/utils/isFunction.ts:6

Check if entity is function

Type parameters:

T

Parameters:

Name Type
entity T

Returns: boolean


localStorageParamsMapper

localStorageParamsMapper(params: Array‹Array‹DefaultValue››): Array‹string | null›

Defined in src/utils/getLocalStorageParam.ts:31

Get options from local storage by defined keys

Parameters:

Name Type
params Array‹Array‹DefaultValue››

Returns: Array‹string | null›


urlBase64ToUint8Array

urlBase64ToUint8Array(base64String: string): Uint8Array

Defined in src/utils/urlBase64ToUint8Array.ts:7

Converts base64 string to Uint8Array

Parameters:

Name Type Description
base64String string a public vavid key

Returns: Uint8Array

Object literals

Const config

config: object

Defined in src/constants/firebase.ts:2

apiKey

apiKey: string = "AIzaSyBlfEue1wp844Hwz16sfBU4dNKPRw941Ng"

Defined in src/constants/firebase.ts:3

appId

appId: string = "1:0000:web:aaa000000"

Defined in src/constants/firebase.ts:9

authDomain

authDomain: string = "your-push-account.firebaseapp.com"

Defined in src/constants/firebase.ts:4

databaseURL

databaseURL: string = "https://your-push-database.firebaseio.com"

Defined in src/constants/firebase.ts:5

measurementId

measurementId: string = "G-WM24X24"

Defined in src/constants/firebase.ts:10

messagingSenderId

messagingSenderId: string = "111111111"

Defined in src/constants/firebase.ts:8

projectId

projectId: string = "your-push-rpoject"

Defined in src/constants/firebase.ts:6

storageBucket

storageBucket: string = "your-push-storage-bucket.appspot.com"

Defined in src/constants/firebase.ts:7