web-push-notifications 3.44.6 → 3.44.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/Pushwoosh.d.ts +199 -0
- package/core/Pushwoosh.types.d.ts +213 -0
- package/core/Safari.types.d.ts +17 -0
- package/core/constants.d.ts +41 -0
- package/core/events.types.d.ts +55 -0
- package/core/functions.d.ts +5 -0
- package/core/legacyEventsMap.d.ts +5 -0
- package/core/logger.d.ts +14 -0
- package/core/modules/EventBus/EventBus.d.ts +10 -0
- package/core/storage.d.ts +27 -0
- package/helpers/logger.d.ts +11 -0
- package/helpers/pwlogger/Logger.constants.d.ts +21 -0
- package/helpers/pwlogger/Logger.d.ts +37 -0
- package/helpers/pwlogger/Logger.types.d.ts +44 -0
- package/helpers/pwlogger/handlers/handler-console/handler-console.d.ts +2 -0
- package/{src/helpers/unescape.ts → helpers/unescape.d.ts} +1 -18
- package/models/InboxMessages.d.ts +82 -0
- package/models/InboxMessages.types.d.ts +83 -0
- package/models/NotificationPayload.d.ts +39 -0
- package/models/NotificationPayload.types.d.ts +63 -0
- package/modules/Api/Api.d.ts +45 -0
- package/modules/Api/Api.types.d.ts +7 -0
- package/modules/ApiClient/ApiClient.d.ts +29 -0
- package/modules/ApiClient/ApiClient.types.d.ts +188 -0
- package/modules/Data/Data.d.ts +76 -0
- package/modules/DateModule.d.ts +27 -0
- package/modules/InboxMessagesPublic.d.ts +64 -0
- package/modules/PlatformChecker/PlatformChecker.d.ts +45 -0
- package/modules/PlatformChecker/PlatformChecker.types.d.ts +5 -0
- package/modules/storage/Storage.d.ts +63 -0
- package/{src/modules/storage/Storage.types.ts → modules/storage/Storage.types.d.ts} +7 -25
- package/modules/storage/Store.d.ts +22 -0
- package/modules/storage/migrations/26-11-2018.d.ts +2 -0
- package/modules/storage/migrations/MigrationExecutor.d.ts +9 -0
- package/modules/storage/migrations/Migrations.d.ts +15 -0
- package/modules/storage/migrations/constants.d.ts +6 -0
- package/modules/storage/migrations/helpers.d.ts +7 -0
- package/modules/storage/migrations/initial.d.ts +2 -0
- package/modules/storage/version.d.ts +2 -0
- package/npm.js +2 -0
- package/npm.js.map +1 -0
- package/package.json +1 -1
- package/service-worker.d.ts +1 -0
- package/service-worker.js +2 -0
- package/service-worker.js.map +1 -0
- package/services/PushService/PushService.types.d.ts +64 -0
- package/services/PushService/drivers/PushServiceDefault/PushServiceDefault.d.ts +29 -0
- package/{src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.types.ts → services/PushService/drivers/PushServiceDefault/PushServiceDefault.types.d.ts} +1 -1
- package/services/PushService/drivers/PushServiceSafari/PushServiceSafari.d.ts +21 -0
- package/services/PushService/drivers/PushServiceSafari/PushServiceSafari.types.d.ts +4 -0
- package/widget-inbox.js +2 -0
- package/widget-inbox.js.map +1 -0
- package/widget-subscribe-popup.js +2 -0
- package/widget-subscribe-popup.js.map +1 -0
- package/widget-subscription-button.js +2 -0
- package/widget-subscription-button.js.map +1 -0
- package/widget-subscription-prompt.d.ts +2 -0
- package/widget-subscription-prompt.js +2 -0
- package/widget-subscription-prompt.js.map +1 -0
- package/widgets/Inbox/InboxWidget.d.ts +49 -0
- package/widgets/Inbox/constants.d.ts +7 -0
- package/widgets/Inbox/helpers.d.ts +4 -0
- package/widgets/Inbox/inbox_widget.types.d.ts +34 -0
- package/widgets/Inbox/widgetTemplates.d.ts +4 -0
- package/widgets/SubscribePopup/SubscribePopup.d.ts +20 -0
- package/widgets/SubscribePopup/constants.d.ts +6 -0
- package/widgets/SubscribePopup/helpers.d.ts +1 -0
- package/widgets/SubscribePopup/popupTemplates.d.ts +9 -0
- package/widgets/SubscribePopup/types/subscribe-popup.d.ts +43 -0
- package/widgets/SubscriptionButton/bell.d.ts +2 -0
- package/widgets/SubscriptionButton/constants.d.ts +7 -0
- package/widgets/SubscriptionButton/index.d.ts +90 -0
- package/widgets/SubscriptionButton/positioning.d.ts +11 -0
- package/widgets/SubscriptionButton/subscribe_widget.types.d.ts +35 -0
- package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.constants.d.ts +1 -0
- package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.d.ts +14 -0
- package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.helpers.d.ts +3 -0
- package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.types.d.ts +19 -0
- package/widgets/SubscriptionPrompt/constants.d.ts +21 -0
- package/widgets/SubscriptionPrompt/helpers.d.ts +5 -0
- package/worker/global.d.ts +16 -0
- package/worker/notification.d.ts +9 -0
- package/worker/worker.types.d.ts +4 -0
- package/.editorconfig +0 -11
- package/.gitlab-ci.yml +0 -193
- package/babel.config.js +0 -7
- package/ci/cdn/Dockerfile +0 -12
- package/ci/dev/Dockerfile +0 -30
- package/ci/dev/rootfs/entrypoint.sh +0 -18
- package/ci/dev/rootfs/entrypoint.sh.d/nginx.sh +0 -6
- package/ci/dev/rootfs/entrypoint.sh.d/supervisor.sh +0 -5
- package/ci/dev/rootfs/etc/nginx/_real_ip.conf +0 -2
- package/ci/dev/rootfs/etc/nginx/conf.d/default.conf +0 -20
- package/ci/dev/rootfs/etc/supervisor.d/nginx.ini +0 -11
- package/ci/github/Dockerfile +0 -59
- package/ci/github/release-zip.js +0 -61
- package/ci/npm/Dockerfile +0 -22
- package/config/config.js +0 -24
- package/config/configBuilder.js +0 -126
- package/config/helpers.js +0 -9
- package/config/index.js +0 -1
- package/develop/README.md +0 -42
- package/develop/favicon.png +0 -0
- package/develop/index.html +0 -511
- package/eslint.config.mjs +0 -114
- package/public/index.d.ts +0 -337
- package/scripts/zip.js +0 -26
- package/src/core/Pushwoosh.ts +0 -768
- package/src/core/Pushwoosh.types.ts +0 -254
- package/src/core/Safari.types.ts +0 -26
- package/src/core/constants.ts +0 -58
- package/src/core/events.types.ts +0 -46
- package/src/core/functions.ts +0 -33
- package/src/core/legacyEventsMap.ts +0 -64
- package/src/core/logger.ts +0 -64
- package/src/core/modules/EventBus/EventBus.ts +0 -66
- package/src/core/storage.ts +0 -254
- package/src/helpers/logger.ts +0 -81
- package/src/helpers/pwlogger/Logger.constants.ts +0 -31
- package/src/helpers/pwlogger/Logger.ts +0 -218
- package/src/helpers/pwlogger/Logger.types.ts +0 -66
- package/src/helpers/pwlogger/handlers/handler-console/handler-console.ts +0 -40
- package/src/models/InboxMessages.ts +0 -202
- package/src/models/InboxMessages.types.ts +0 -111
- package/src/models/NotificationPayload.ts +0 -216
- package/src/models/NotificationPayload.types.ts +0 -65
- package/src/modules/Api/Api.ts +0 -386
- package/src/modules/Api/Api.types.ts +0 -7
- package/src/modules/ApiClient/ApiClient.ts +0 -153
- package/src/modules/ApiClient/ApiClient.types.ts +0 -222
- package/src/modules/Data/Data.ts +0 -345
- package/src/modules/DateModule.ts +0 -53
- package/src/modules/InboxMessagesPublic.ts +0 -222
- package/src/modules/PlatformChecker/PlatformChecker.ts +0 -170
- package/src/modules/PlatformChecker/PlatformChecker.types.ts +0 -5
- package/src/modules/storage/Storage.ts +0 -164
- package/src/modules/storage/Store.ts +0 -104
- package/src/modules/storage/migrations/26-11-2018.ts +0 -25
- package/src/modules/storage/migrations/MigrationExecutor.ts +0 -31
- package/src/modules/storage/migrations/Migrations.ts +0 -41
- package/src/modules/storage/migrations/constants.ts +0 -8
- package/src/modules/storage/migrations/helpers.ts +0 -16
- package/src/modules/storage/migrations/initial.ts +0 -47
- package/src/modules/storage/version.ts +0 -2
- package/src/pushwoosh-web-notifications.ts +0 -47
- package/src/pushwoosh-widget-inbox.ts +0 -8
- package/src/pushwoosh-widget-subscribe-popup.ts +0 -9
- package/src/pushwoosh-widget-subscription-button.ts +0 -8
- package/src/pushwoosh-widget-subscription-prompt.ts +0 -6
- package/src/service-worker.ts +0 -455
- package/src/services/PushService/PushService.types.ts +0 -74
- package/src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.ts +0 -235
- package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.ts +0 -125
- package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.types.ts +0 -4
- package/src/widget-subscription-prompt.ts +0 -33
- package/src/widgets/Inbox/InboxWidget.ts +0 -564
- package/src/widgets/Inbox/constants.ts +0 -49
- package/src/widgets/Inbox/css/inboxWidgetStyle.css +0 -274
- package/src/widgets/Inbox/helpers.ts +0 -63
- package/src/widgets/Inbox/inbox.d.ts +0 -9
- package/src/widgets/Inbox/inbox_widget.types.ts +0 -41
- package/src/widgets/Inbox/widgetTemplates.ts +0 -55
- package/src/widgets/SubscribePopup/SubscribePopup.ts +0 -241
- package/src/widgets/SubscribePopup/constants.ts +0 -66
- package/src/widgets/SubscribePopup/helpers.ts +0 -11
- package/src/widgets/SubscribePopup/popupTemplates.ts +0 -24
- package/src/widgets/SubscribePopup/styles/popup.css +0 -226
- package/src/widgets/SubscribePopup/types/subscribe-popup.ts +0 -68
- package/src/widgets/SubscriptionButton/assets/css/main.css +0 -205
- package/src/widgets/SubscriptionButton/bell.ts +0 -67
- package/src/widgets/SubscriptionButton/constants.ts +0 -28
- package/src/widgets/SubscriptionButton/index.ts +0 -377
- package/src/widgets/SubscriptionButton/positioning.ts +0 -165
- package/src/widgets/SubscriptionButton/subscribe_widget.types.ts +0 -53
- package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.constants.ts +0 -1
- package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.helpers.ts +0 -110
- package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.ts +0 -102
- package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.types.ts +0 -23
- package/src/widgets/SubscriptionPrompt/constants.ts +0 -22
- package/src/widgets/SubscriptionPrompt/helpers.ts +0 -42
- package/src/widgets/widgets.d.ts +0 -4
- package/src/worker/global.ts +0 -36
- package/src/worker/notification.ts +0 -34
- package/src/worker/worker.types.ts +0 -4
- package/test/__helpers__/apiHelpers.ts +0 -22
- package/test/__helpers__/keyValueHelpers.ts +0 -15
- package/test/__helpers__/platformHelpers.ts +0 -54
- package/test/__helpers__/sinonHelpers.ts +0 -7
- package/test/__helpers__/storageHelpers.ts +0 -56
- package/test/__mocks__/apiRequests.ts +0 -26
- package/test/__mocks__/idbMock.ts +0 -12
- package/test/__mocks__/idbObjectStoreMock.ts +0 -38
- package/test/__mocks__/inboxMessages.ts +0 -292
- package/test/__mocks__/models/inboxModel.ts +0 -71
- package/test/__mocks__/modules/apiClientModule.ts +0 -18
- package/test/__mocks__/modules/dateModule.ts +0 -34
- package/test/__mocks__/modules/inboxParamsModule.ts +0 -21
- package/test/__mocks__/modules/paramsBuilder.ts +0 -12
- package/test/__mocks__/modules/paramsModule.ts +0 -35
- package/test/__mocks__/modules/payloadBuilderModule.ts +0 -15
- package/test/__mocks__/modules/storageModule.ts +0 -58
- package/test/__mocks__/navigator.ts +0 -38
- package/test/__mocks__/notification.ts +0 -84
- package/test/__mocks__/pushwoosh.ts +0 -12
- package/test/__mocks__/userAgents +0 -8
- package/test/functions.test.ts +0 -22
- package/test/ignore-html.js +0 -6
- package/test/mocha.opts +0 -6
- package/test/modules/DateModule/unit.test.ts +0 -80
- package/test/modules/storage/Storage/unit.test.ts +0 -180
- package/test/modules/storage/Store/unit.test.ts +0 -192
- package/testRegister.js +0 -24
- package/tsconfig.json +0 -31
- package/webpack.config.js +0 -163
- /package/{src/core/modules/EventBus/index.ts → core/modules/EventBus/index.d.ts} +0 -0
- /package/{src/helpers/pwlogger/index.ts → helpers/pwlogger/index.d.ts} +0 -0
- /package/{src/modules/PlatformChecker/index.ts → modules/PlatformChecker/index.d.ts} +0 -0
- /package/{src/npm.ts → npm.d.ts} +0 -0
- /package/{src/services/PushService/PushService.ts → services/PushService/PushService.d.ts} +0 -0
- /package/{src/widget-inbox.ts → widget-inbox.d.ts} +0 -0
- /package/{src/widget-subscribe-popup.ts → widget-subscribe-popup.d.ts} +0 -0
- /package/{src/widget-subscription-button.ts → widget-subscription-button.d.ts} +0 -0
- /package/{src/widgets/Inbox/index.ts → widgets/Inbox/index.d.ts} +0 -0
- /package/{src/widgets/SubscribePopup/index.ts → widgets/SubscribePopup/index.d.ts} +0 -0
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { type INotificationButton } from '../models/NotificationPayload.types';
|
|
2
|
-
import { type ISubscribePopupConfig } from '../widgets/SubscribePopup/types/subscribe-popup';
|
|
3
|
-
|
|
4
|
-
export type PushwooshApiResponse = {
|
|
5
|
-
status_code: number;
|
|
6
|
-
status_message: string;
|
|
7
|
-
response?: any;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type TPWPermission = 'denied' | 'granted' | 'default';
|
|
11
|
-
|
|
12
|
-
export interface IPWDriverAPIParams {
|
|
13
|
-
hwid: string;
|
|
14
|
-
pushToken?: string;
|
|
15
|
-
publicKey?: string;
|
|
16
|
-
authToken?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface TPWAPIParams extends IPWDriverAPIParams {
|
|
20
|
-
applicationCode: string;
|
|
21
|
-
pushwooshApiUrl?: string;
|
|
22
|
-
deviceType: number;
|
|
23
|
-
deviceModel: string;
|
|
24
|
-
language: string;
|
|
25
|
-
userId?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface TPWLastOpenMessage {
|
|
29
|
-
messageHash?: string;
|
|
30
|
-
expiry: number;
|
|
31
|
-
url?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface PushManager {
|
|
35
|
-
permissionState(options: PushSubscriptionOptions): Promise<TPWPermission>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface PushSubscription {
|
|
39
|
-
unsubscribe(): Promise<boolean>;
|
|
40
|
-
subscriptionId: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface IPWDriver {
|
|
44
|
-
initWorker?(): Promise<any>;
|
|
45
|
-
getPermission(): Promise<TPWPermission>;
|
|
46
|
-
isSubscribed(): Promise<boolean>;
|
|
47
|
-
askSubscribe(eventEmitter?: any): Promise<any>;
|
|
48
|
-
unsubscribe(): Promise<any>;
|
|
49
|
-
getAPIParams(): Promise<IPWDriverAPIParams>;
|
|
50
|
-
onApiReady?(api: any): void;
|
|
51
|
-
isNeedUnsubscribe?(): Promise<boolean>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface ITooltipText {
|
|
55
|
-
successSubscribe?: string;
|
|
56
|
-
needSubscribe?: string;
|
|
57
|
-
blockSubscribe?: string;
|
|
58
|
-
alreadySubscribed?: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface ISubscribeWidget {
|
|
62
|
-
enable: boolean;
|
|
63
|
-
position?: string;
|
|
64
|
-
bgColor?: string;
|
|
65
|
-
bellColor?: string;
|
|
66
|
-
shadow?: string;
|
|
67
|
-
size?: string;
|
|
68
|
-
indent?: string;
|
|
69
|
-
zIndex?: string;
|
|
70
|
-
tooltipText?: ITooltipText;
|
|
71
|
-
buttonImage?: string;
|
|
72
|
-
contentImages?: Record<string, string>;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export type IWidgetPosition = 'left' | 'right' | 'top' | 'bottom';
|
|
76
|
-
|
|
77
|
-
export interface IInboxWidget {
|
|
78
|
-
enable: boolean;
|
|
79
|
-
triggerId?: string;
|
|
80
|
-
position?: IWidgetPosition;
|
|
81
|
-
appendTo?: string;
|
|
82
|
-
title?: string;
|
|
83
|
-
bgColor?: string;
|
|
84
|
-
textColor?: string;
|
|
85
|
-
fontFamily?: string;
|
|
86
|
-
borderRadius?: number;
|
|
87
|
-
borderColor?: string;
|
|
88
|
-
badgeBgColor?: string;
|
|
89
|
-
badgeTextColor?: string;
|
|
90
|
-
widgetWidth?: number;
|
|
91
|
-
zIndex?: number;
|
|
92
|
-
messageTitleColor?: string;
|
|
93
|
-
timeTextColor?: string;
|
|
94
|
-
emptyInboxTitle?: string;
|
|
95
|
-
emptyInboxText?: string;
|
|
96
|
-
emptyInboxIconUrl?: string;
|
|
97
|
-
emptyInboxTitleColor?: string;
|
|
98
|
-
emptyInboxTextColor?: string;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface IInitParams {
|
|
102
|
-
applicationCode: string;
|
|
103
|
-
apiToken?: string;
|
|
104
|
-
serviceWorkerUrl?: string | null;
|
|
105
|
-
safariWebsitePushID?: string;
|
|
106
|
-
autoSubscribe?: boolean;
|
|
107
|
-
pushwooshUrl?: string;
|
|
108
|
-
pushwooshApiUrl?: string;
|
|
109
|
-
defaultNotificationImage?: string;
|
|
110
|
-
defaultNotificationTitle?: string;
|
|
111
|
-
logLevel?: string;
|
|
112
|
-
userId?: string;
|
|
113
|
-
email?: string;
|
|
114
|
-
scope?: string;
|
|
115
|
-
tags?: { [key: string]: any };
|
|
116
|
-
driversSettings?: {
|
|
117
|
-
worker?: {
|
|
118
|
-
serviceWorkerUrl?: string;
|
|
119
|
-
applicationServerPublicKey?: string;
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
subscribeWidget?: ISubscribeWidget;
|
|
123
|
-
inboxWidget?: IInboxWidget;
|
|
124
|
-
subscribePopup?: ISubscribePopupConfig;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export interface IInitParamsWithDefaults extends IInitParams {
|
|
128
|
-
autoSubscribe: boolean;
|
|
129
|
-
pushwooshUrl: string;
|
|
130
|
-
deviceType: number;
|
|
131
|
-
serviceWorkerUrl: string | null;
|
|
132
|
-
tags: {
|
|
133
|
-
Language: string;
|
|
134
|
-
'Device Model': string;
|
|
135
|
-
[key: string]: any;
|
|
136
|
-
};
|
|
137
|
-
driversSettings: {
|
|
138
|
-
worker: {
|
|
139
|
-
serviceWorkerUrl: string;
|
|
140
|
-
applicationServerPublicKey?: string;
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
subscribeWidget: ISubscribeWidget;
|
|
144
|
-
inboxWidget: IInboxWidget;
|
|
145
|
-
subscribePopup: ISubscribePopupConfig;
|
|
146
|
-
hwid: string;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export interface IPWParams extends IInitParamsWithDefaults {
|
|
150
|
-
applicationCode: string;
|
|
151
|
-
apiToken?: string;
|
|
152
|
-
defaultNotificationImage?: string;
|
|
153
|
-
defaultNotificationTitle?: string;
|
|
154
|
-
logLevel?: 'error' | 'info' | 'debug';
|
|
155
|
-
pushwooshApiUrl?: string;
|
|
156
|
-
safariWebsitePushID?: string;
|
|
157
|
-
scope?: string;
|
|
158
|
-
userId?: string;
|
|
159
|
-
email?: string;
|
|
160
|
-
pushwooshUrl: string;
|
|
161
|
-
authToken?: string;
|
|
162
|
-
hwid: string;
|
|
163
|
-
publicKey?: string;
|
|
164
|
-
pushToken?: string;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export interface INotificationOptions extends NotificationOptions {
|
|
168
|
-
title: string;
|
|
169
|
-
messageHash: string;
|
|
170
|
-
openUrl: string;
|
|
171
|
-
url?: string;
|
|
172
|
-
inboxId: string;
|
|
173
|
-
|
|
174
|
-
image?: string;
|
|
175
|
-
code?: string;
|
|
176
|
-
buttons?: INotificationButton[];
|
|
177
|
-
customData?: { [key: string]: any };
|
|
178
|
-
metaData?: { [key: string]: any };
|
|
179
|
-
campaignCode?: string;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export type TPWCanWaitCallback = (f: any) => Promise<any> | any;
|
|
183
|
-
|
|
184
|
-
export interface IWorkerPushwooshGlobal {
|
|
185
|
-
push(listener: ['onPush', TPWCanWaitCallback]): void;
|
|
186
|
-
getListeners(eventName: string): TPWCanWaitCallback[];
|
|
187
|
-
eventBus: any;
|
|
188
|
-
api: any;
|
|
189
|
-
initApi: any;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export interface IPWBroadcastClientsParams {
|
|
193
|
-
type: string;
|
|
194
|
-
payload: any;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export type TWriteType = 'error' | 'apirequest' | 'info';
|
|
198
|
-
|
|
199
|
-
export interface ILogger {
|
|
200
|
-
setLevel(level: string): void;
|
|
201
|
-
error(...args: any[]): void;
|
|
202
|
-
info(...args: any[]): void;
|
|
203
|
-
debug(...args: any[]): void;
|
|
204
|
-
write(type: TWriteType, message: any, additional?: any): Promise<void>;
|
|
205
|
-
isManualLevel(): boolean;
|
|
206
|
-
[key: string]: any;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export type ListenerFn = (...args: Array<any>) => void | Promise<any>;
|
|
210
|
-
|
|
211
|
-
export type HandlerFn = (api: any, params?: any) => any;
|
|
212
|
-
|
|
213
|
-
export type TWorkerDriverParams = {
|
|
214
|
-
eventEmitter?: any;
|
|
215
|
-
scope?: string;
|
|
216
|
-
applicationCode: string;
|
|
217
|
-
serviceWorkerUrl: string | null;
|
|
218
|
-
applicationServerPublicKey?: string;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
export type TWorkerSafariDriverParams = {
|
|
222
|
-
eventEmitter?: any;
|
|
223
|
-
applicationCode: string;
|
|
224
|
-
webSitePushID: string;
|
|
225
|
-
pushwooshUrl: string;
|
|
226
|
-
pushwooshApiUrl?: string;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
export type TDoPushwooshMethod = (type: string, params: any, url?: string) => Promise<any>;
|
|
230
|
-
|
|
231
|
-
export type PWInput = PushOnReadyCallback | PushInitCallback | PushEventCallback;
|
|
232
|
-
export type PushOnReadyCallback = HandlerFn;
|
|
233
|
-
export type PushInitCallback = ['init', IInitParams];
|
|
234
|
-
export type PushEventCallback = [PWEvent, HandlerFn];
|
|
235
|
-
export type PWEvent =
|
|
236
|
-
| 'onLoad'
|
|
237
|
-
| 'onReady'
|
|
238
|
-
| 'onSubscribe'
|
|
239
|
-
| 'onUnsubscribe'
|
|
240
|
-
| 'onRegister'
|
|
241
|
-
| 'onSWInitError'
|
|
242
|
-
| 'onPermissionPrompt'
|
|
243
|
-
| 'onPermissionDenied'
|
|
244
|
-
| 'onPermissionGranted'
|
|
245
|
-
| 'onNotificationClick'
|
|
246
|
-
| 'onPushDelivery'
|
|
247
|
-
| 'onNotificationClose'
|
|
248
|
-
| 'onChangeCommunicationEnabled'
|
|
249
|
-
| 'onPutNewMessageToInboxStore'
|
|
250
|
-
| 'onUpdateInboxMessages'
|
|
251
|
-
| 'onShowNotificationPermissionDialog'
|
|
252
|
-
| 'onHideNotificationPermissionDialog'
|
|
253
|
-
| 'onShowSubscriptionWidget'
|
|
254
|
-
| 'onHideSubscriptionWidget';
|
package/src/core/Safari.types.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
interface IPushServiceSafariRequestPayload {
|
|
2
|
-
application: string;
|
|
3
|
-
hwid: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
interface IPushServiceSafariInfo {
|
|
7
|
-
permission: NotificationPermission;
|
|
8
|
-
deviceToken?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
-
interface Window {
|
|
13
|
-
safari: {
|
|
14
|
-
pushNotification: {
|
|
15
|
-
permission(siteId: string): IPushServiceSafariInfo;
|
|
16
|
-
requestPermission(
|
|
17
|
-
url: string,
|
|
18
|
-
id: string,
|
|
19
|
-
payload: IPushServiceSafariRequestPayload,
|
|
20
|
-
cb: (permission: IPushServiceSafariInfo) => void): void;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
26
|
-
declare const safari: typeof window.safari;
|
package/src/core/constants.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_SERVICE_WORKER_URL = '/pushwoosh-service-worker.js';
|
|
2
|
-
export const DEFAULT_API_URL = 'https://cp.pushwoosh.com/json/1.3/';
|
|
3
|
-
|
|
4
|
-
export const PERIOD_SEND_APP_OPEN = 3600000;
|
|
5
|
-
export const PERIOD_GOAL_EVENT = 86400000;
|
|
6
|
-
|
|
7
|
-
export const DEFAULT_NOTIFICATION_TITLE = 'Pushwoosh notification';
|
|
8
|
-
export const DEFAULT_NOTIFICATION_IMAGE = 'https://cp.pushwoosh.com/img/logo-medium.png';
|
|
9
|
-
|
|
10
|
-
// Keys
|
|
11
|
-
export const KEY_SHOW_SUBSCRIBE_WIDGET = 'WIDGET_SHOWED';
|
|
12
|
-
export const KEY_CLICK_SUBSCRIBE_WIDGET = 'WIDGET_CLICKED';
|
|
13
|
-
|
|
14
|
-
// Local storage keys
|
|
15
|
-
export const KEY_DEVICE_REGISTRATION_STATUS: string = 'deviceRegistrationStatus';
|
|
16
|
-
export const KEY_SAFARI_PREVIOUS_PERMISSION = 'safariPreviousPermission';
|
|
17
|
-
export const MANUAL_SET_LOGGER_LEVEL = 'PW_SET_LOGGER_LEVEL';
|
|
18
|
-
|
|
19
|
-
// Device registration status
|
|
20
|
-
export const DEVICE_REGISTRATION_STATUS_REGISTERED: string = 'registered';
|
|
21
|
-
export const DEVICE_REGISTRATION_STATUS_UNREGISTERED: string = 'unregistered';
|
|
22
|
-
|
|
23
|
-
// Permissions
|
|
24
|
-
export const PERMISSION_DENIED = 'denied';
|
|
25
|
-
export const PERMISSION_GRANTED = 'granted';
|
|
26
|
-
export const PERMISSION_PROMPT = 'default';
|
|
27
|
-
|
|
28
|
-
// Events
|
|
29
|
-
export const LEGACY_EVENT_ON_LOAD = 'onLoad';
|
|
30
|
-
export const LEGACY_EVENT_ON_READY = 'onReady';
|
|
31
|
-
export const LEGACY_EVENT_ON_SUBSCRIBE = 'onSubscribe';
|
|
32
|
-
export const LEGACY_EVENT_ON_UNSUBSCRIBE = 'onUnsubscribe';
|
|
33
|
-
export const LEGACY_EVENT_ON_REGISTER = 'onRegister';
|
|
34
|
-
export const LEGACY_EVENT_ON_PERMISSION_PROMPT = 'onPermissionPrompt';
|
|
35
|
-
export const LEGACY_EVENT_ON_PERMISSION_DENIED = 'onPermissionDenied';
|
|
36
|
-
export const LEGACY_EVENT_ON_PERMISSION_GRANTED = 'onPermissionGranted';
|
|
37
|
-
export const LEGACY_EVENT_ON_SW_INIT_ERROR = 'onSWInitError';
|
|
38
|
-
export const LEGACY_EVENT_ON_PUSH_DELIVERY = 'onPushDelivery';
|
|
39
|
-
export const LEGACY_EVENT_ON_NOTIFICATION_CLICK = 'onNotificationClick';
|
|
40
|
-
export const LEGACY_EVENT_ON_NOTIFICATION_CLOSE = 'onNotificationClose';
|
|
41
|
-
export const LEGACY_EVENT_ON_CHANGE_COMMUNICATION_ENABLED = 'onChangeCommunicationEnabled';
|
|
42
|
-
export const LEGACY_EVENT_ON_PUT_NEW_MESSAGE_TO_INBOX_STORE = 'onPutNewMessageToInboxStore';
|
|
43
|
-
export const LEGACY_EVENT_ON_UPDATE_INBOX_MESSAGES = 'onUpdateInboxMessages';
|
|
44
|
-
export const LEGACY_EVENT_ON_SHOW_NOTIFICATION_PERMISSION_DIALOG = 'onShowNotificationPermissionDialog';
|
|
45
|
-
export const LEGACY_EVENT_ON_HIDE_NOTIFICATION_PERMISSION_DIALOG = 'onHideNotificationPermissionDialog';
|
|
46
|
-
|
|
47
|
-
export const LEGACY_EVENT_ON_SHOW_SUBSCRIPTION_WIDGET = 'onShowSubscriptionWidget';
|
|
48
|
-
export const LEGACY_EVENT_ON_HIDE_SUBSCRIPTION_WIDGET = 'onHideSubscriptionWidget';
|
|
49
|
-
|
|
50
|
-
// Post Events
|
|
51
|
-
export const EVENT_SHOW_SUBSCRIBE_BUTTON = 'showSubscribeButton';
|
|
52
|
-
export const EVENT_CLICK_SUBSCRIBE_BUTTON = 'clickSubscribeButton';
|
|
53
|
-
export const EVENT_GDPR_CONSENT = 'GDPRConsent';
|
|
54
|
-
export const EVENT_GDPR_DELETE = 'GDPRDelete';
|
|
55
|
-
export const EVENT_PW_SITE_OPENED = 'PW_SiteOpened'; // for default events
|
|
56
|
-
|
|
57
|
-
// Page visited
|
|
58
|
-
export const PAGE_VISITED_URL = 'PAGE_VISITED_URL';
|
package/src/core/events.types.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export type EventPayload<Parameters extends Record<string, unknown>> = Parameters & Record<'eventId', string>;
|
|
2
|
-
export type EventHandler<Payload extends EventPayload<Record<string, unknown>>> = (payload: Payload) => void | Promise<void>;
|
|
3
|
-
|
|
4
|
-
export interface EventHandlerMap {
|
|
5
|
-
/* system events handlers map */
|
|
6
|
-
ready: EventHandler<EventPayload<Record<string, never>>>;
|
|
7
|
-
'change-enabled-communication': EventHandler<EventPayload<{ isEnabled: boolean }>>;
|
|
8
|
-
|
|
9
|
-
/* device events handlers map */
|
|
10
|
-
register: EventHandler<EventPayload<Record<string, never>>>;
|
|
11
|
-
unregister: EventHandler<EventPayload<Record<string, never>>>;
|
|
12
|
-
|
|
13
|
-
/* push notification events handlers map */
|
|
14
|
-
'show-subscription-widget': EventHandler<EventPayload<Record<string, never>>>;
|
|
15
|
-
'hide-subscription-widget': EventHandler<EventPayload<Record<string, never>>>;
|
|
16
|
-
'show-notification-permission-dialog': EventHandler<EventPayload<Record<string, never>>>;
|
|
17
|
-
'hide-notification-permission-dialog': EventHandler<EventPayload<{ permission: NotificationPermission }>>;
|
|
18
|
-
'permission-default': EventHandler<EventPayload<Record<string, never>>>;
|
|
19
|
-
'permission-denied': EventHandler<EventPayload<Record<string, never>>>;
|
|
20
|
-
'permission-granted': EventHandler<EventPayload<Record<string, never>>>;
|
|
21
|
-
'change-permission': EventHandler<EventPayload<{ permission: NotificationPermission }>>;
|
|
22
|
-
'initialize-service-worker': EventHandler<EventPayload<Record<string, never>>>;
|
|
23
|
-
'initialize-service-worker-error': EventHandler<EventPayload<{ error: Error }>>;
|
|
24
|
-
subscribe: EventHandler<EventPayload<Record<string, never>>>;
|
|
25
|
-
unsubscribe: EventHandler<EventPayload<Record<string, never>>>;
|
|
26
|
-
'receive-push': EventHandler<EventPayload<{ notification: unknown }>>;
|
|
27
|
-
'show-notification': EventHandler<EventPayload<{ notification: unknown }>>;
|
|
28
|
-
'open-notification': EventHandler<EventPayload<{ notification: unknown }>>;
|
|
29
|
-
'hide-notification': EventHandler<EventPayload<{ notification: unknown }>>;
|
|
30
|
-
|
|
31
|
-
/* inbox events handlers map */
|
|
32
|
-
'receive-inbox-message': EventHandler<EventPayload<{ message: unknown }>>;
|
|
33
|
-
'update-inbox-messages': EventHandler<EventPayload<{ messages: unknown }>>;
|
|
34
|
-
|
|
35
|
-
/* in-app events handlers map */
|
|
36
|
-
'receive-in-app-code': EventHandler<EventPayload<{ code: string }>>;
|
|
37
|
-
|
|
38
|
-
/* subscribe popup events */
|
|
39
|
-
'subscribe-popup-ready': EventHandler<EventPayload<Record<string, never>>>;
|
|
40
|
-
'subscribe-popup-show': EventHandler<EventPayload<Record<string, never>>>;
|
|
41
|
-
'subscribe-popup-hide': EventHandler<EventPayload<Record<string, never>>>;
|
|
42
|
-
'subscribe-popup-decline': EventHandler<EventPayload<Record<string, never>>>;
|
|
43
|
-
'subscribe-popup-accept': EventHandler<EventPayload<Record<string, never>>>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type EventName = keyof EventHandlerMap;
|
package/src/core/functions.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export function getGlobal() {
|
|
2
|
-
return globalThis;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
declare const __VERSION__: string;
|
|
6
|
-
export function getVersion() {
|
|
7
|
-
return __VERSION__;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// API bad behavior with demo app notification payload fix
|
|
11
|
-
export function parseSerializedNotificationParams(param: any, defaultValue?: any) {
|
|
12
|
-
if (typeof param === 'string') {
|
|
13
|
-
try {
|
|
14
|
-
return JSON.parse(param);
|
|
15
|
-
} catch (e) {
|
|
16
|
-
console.log(e);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return param === undefined && defaultValue !== undefined ? defaultValue : param;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Generates a UUID v4 string.
|
|
23
|
-
// This function first tries to use crypto.randomUUID, which is supported in browsers since 2022.
|
|
24
|
-
// If unavailable, it falls back to a manual UUID generation method.
|
|
25
|
-
// In 2027, consider simplifying this function by removing the fallback.
|
|
26
|
-
export function v4() {
|
|
27
|
-
return crypto.randomUUID?.() || 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
28
|
-
const r = (Math.random() * 16) | 0;
|
|
29
|
-
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const isFunction = (value: any): value is ((...args: any[]) => any) => typeof value === 'function';
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from './constants';
|
|
2
|
-
import type { EventName } from './events.types';
|
|
3
|
-
|
|
4
|
-
export const legacyEventsMap: Record<string, { name: EventName; prop?: string }> = {
|
|
5
|
-
[CONSTANTS.LEGACY_EVENT_ON_REGISTER]: {
|
|
6
|
-
name: 'register',
|
|
7
|
-
},
|
|
8
|
-
[CONSTANTS.LEGACY_EVENT_ON_SUBSCRIBE]: {
|
|
9
|
-
name: 'subscribe',
|
|
10
|
-
},
|
|
11
|
-
[CONSTANTS.LEGACY_EVENT_ON_UNSUBSCRIBE]: {
|
|
12
|
-
name: 'unsubscribe',
|
|
13
|
-
},
|
|
14
|
-
[CONSTANTS.LEGACY_EVENT_ON_SW_INIT_ERROR]: {
|
|
15
|
-
name: 'initialize-service-worker-error',
|
|
16
|
-
prop: 'error',
|
|
17
|
-
},
|
|
18
|
-
[CONSTANTS.LEGACY_EVENT_ON_PUSH_DELIVERY]: {
|
|
19
|
-
name: 'receive-push',
|
|
20
|
-
prop: 'notification',
|
|
21
|
-
},
|
|
22
|
-
[CONSTANTS.LEGACY_EVENT_ON_NOTIFICATION_CLICK]: {
|
|
23
|
-
name: 'open-notification',
|
|
24
|
-
prop: 'notification',
|
|
25
|
-
},
|
|
26
|
-
[CONSTANTS.LEGACY_EVENT_ON_NOTIFICATION_CLOSE]: {
|
|
27
|
-
name: 'hide-notification',
|
|
28
|
-
prop: 'notification',
|
|
29
|
-
},
|
|
30
|
-
[CONSTANTS.LEGACY_EVENT_ON_CHANGE_COMMUNICATION_ENABLED]: {
|
|
31
|
-
name: 'change-enabled-communication',
|
|
32
|
-
prop: 'isEnabled',
|
|
33
|
-
},
|
|
34
|
-
[CONSTANTS.LEGACY_EVENT_ON_PUT_NEW_MESSAGE_TO_INBOX_STORE]: {
|
|
35
|
-
name: 'receive-inbox-message',
|
|
36
|
-
prop: 'message',
|
|
37
|
-
},
|
|
38
|
-
[CONSTANTS.LEGACY_EVENT_ON_UPDATE_INBOX_MESSAGES]: {
|
|
39
|
-
name: 'update-inbox-messages',
|
|
40
|
-
prop: 'messages',
|
|
41
|
-
},
|
|
42
|
-
[CONSTANTS.LEGACY_EVENT_ON_SHOW_NOTIFICATION_PERMISSION_DIALOG]: {
|
|
43
|
-
name: 'show-notification-permission-dialog',
|
|
44
|
-
},
|
|
45
|
-
[CONSTANTS.LEGACY_EVENT_ON_HIDE_NOTIFICATION_PERMISSION_DIALOG]: {
|
|
46
|
-
name: 'hide-notification-permission-dialog',
|
|
47
|
-
prop: 'permission',
|
|
48
|
-
},
|
|
49
|
-
[CONSTANTS.LEGACY_EVENT_ON_SHOW_SUBSCRIPTION_WIDGET]: {
|
|
50
|
-
name: 'show-subscription-widget',
|
|
51
|
-
},
|
|
52
|
-
[CONSTANTS.LEGACY_EVENT_ON_HIDE_SUBSCRIPTION_WIDGET]: {
|
|
53
|
-
name: 'hide-subscription-widget',
|
|
54
|
-
},
|
|
55
|
-
[CONSTANTS.LEGACY_EVENT_ON_PERMISSION_DENIED]: {
|
|
56
|
-
name: 'permission-denied',
|
|
57
|
-
},
|
|
58
|
-
[CONSTANTS.LEGACY_EVENT_ON_PERMISSION_PROMPT]: {
|
|
59
|
-
name: 'permission-default',
|
|
60
|
-
},
|
|
61
|
-
[CONSTANTS.LEGACY_EVENT_ON_PERMISSION_GRANTED]: {
|
|
62
|
-
name: 'permission-granted',
|
|
63
|
-
},
|
|
64
|
-
};
|
package/src/core/logger.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { log as logStorage } from './storage';
|
|
2
|
-
|
|
3
|
-
const levels: { [key: string]: number } = {
|
|
4
|
-
error: 1,
|
|
5
|
-
info: 2,
|
|
6
|
-
debug: 3,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
let limitLevel = 3;
|
|
10
|
-
|
|
11
|
-
type TWriteType = 'error' | 'apirequest' | 'info';
|
|
12
|
-
|
|
13
|
-
interface ILogger {
|
|
14
|
-
setLevel(level: string): void;
|
|
15
|
-
error(...args: any[]): void;
|
|
16
|
-
info(...args: any[]): void;
|
|
17
|
-
debug(...args: any[]): void;
|
|
18
|
-
write(type: TWriteType, message: any, additional?: any): Promise<void>;
|
|
19
|
-
isManualLevel(): boolean;
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const Logger: ILogger = {
|
|
24
|
-
setLevel(level) {
|
|
25
|
-
if (!levels[level]) {
|
|
26
|
-
level = 'error';
|
|
27
|
-
}
|
|
28
|
-
limitLevel = levels[level];
|
|
29
|
-
},
|
|
30
|
-
write(type: TWriteType, message: any, additional?: any) {
|
|
31
|
-
if (type === 'error') {
|
|
32
|
-
this.error(message);
|
|
33
|
-
} else {
|
|
34
|
-
this.info(message);
|
|
35
|
-
}
|
|
36
|
-
return logStorage.add(type, message, additional);
|
|
37
|
-
},
|
|
38
|
-
} as ILogger;
|
|
39
|
-
|
|
40
|
-
Object.keys(levels).forEach((levelName: string) => {
|
|
41
|
-
const levelNumber = levels[levelName];
|
|
42
|
-
Logger[levelName] = (...args: any[]) => {
|
|
43
|
-
if (levelNumber <= limitLevel) {
|
|
44
|
-
console.groupCollapsed(levelName);
|
|
45
|
-
console.info('', ...args);
|
|
46
|
-
console.trace('trace');
|
|
47
|
-
console.groupEnd();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export function logAndThrowError(error: string) {
|
|
53
|
-
const logText = new Error(error);
|
|
54
|
-
Logger.write('error', logText, 'logAndThrowError');
|
|
55
|
-
throw logText;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function logAndRejectError(error: string, reject: (e: any) => void) {
|
|
59
|
-
const logText = new Error(error);
|
|
60
|
-
Logger.write('error', logText, 'logAndRejectError');
|
|
61
|
-
reject(logText);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { Logger };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { type EventHandlerMap, type EventName } from '../../events.types';
|
|
2
|
-
import { isFunction, v4 } from '../../functions';
|
|
3
|
-
|
|
4
|
-
type SavedEventHandlersMap = {
|
|
5
|
-
// TODO: fix me: https://github.com/microsoft/TypeScript/issues/36390
|
|
6
|
-
// [K in keyof EventHandlerMap]?: Array<EventHandlerMap[K]>
|
|
7
|
-
[K in keyof EventHandlerMap]?: Array<unknown>
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export class EventBus {
|
|
11
|
-
private readonly handlers: SavedEventHandlersMap;
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
this.handlers = {};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public addEventHandler = <Name extends EventName = EventName>(
|
|
18
|
-
name: Name,
|
|
19
|
-
handler: EventHandlerMap[Name],
|
|
20
|
-
): void => {
|
|
21
|
-
let savedEventHandlers = this.handlers[name];
|
|
22
|
-
if (!savedEventHandlers) {
|
|
23
|
-
savedEventHandlers = [];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
savedEventHandlers.push(handler);
|
|
27
|
-
this.handlers[name] = savedEventHandlers;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
public removeEventHandler = <Name extends EventName = EventName>(
|
|
31
|
-
name: Name,
|
|
32
|
-
handler: EventHandlerMap[Name],
|
|
33
|
-
): void => {
|
|
34
|
-
const savedEventHandlers = this.handlers[name];
|
|
35
|
-
if (!savedEventHandlers) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.handlers[name] = savedEventHandlers.filter((savedEventHandler) => (
|
|
40
|
-
savedEventHandler !== handler
|
|
41
|
-
));
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
public dispatchEvent = <Name extends EventName = EventName>(
|
|
45
|
-
name: Name,
|
|
46
|
-
payload: Omit<Parameters<EventHandlerMap[Name]>[0], 'eventId'> & { eventId?: string },
|
|
47
|
-
): string => {
|
|
48
|
-
const eventId = payload.eventId || v4();
|
|
49
|
-
const savedEventHandlers = this.handlers[name];
|
|
50
|
-
if (!savedEventHandlers) {
|
|
51
|
-
return eventId;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
savedEventHandlers.forEach((handler) => {
|
|
55
|
-
if (!isFunction(handler)) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
setTimeout(() => {
|
|
60
|
-
handler({ ...payload, eventId });
|
|
61
|
-
}, 0);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return eventId;
|
|
65
|
-
};
|
|
66
|
-
}
|