web-push-notifications 3.40.3 → 3.44.2

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.
Files changed (149) hide show
  1. package/.editorconfig +11 -0
  2. package/.gitlab-ci.yml +190 -0
  3. package/babel.config.js +7 -0
  4. package/ci/cdn/Dockerfile +12 -0
  5. package/ci/dev/Dockerfile +30 -0
  6. package/ci/dev/rootfs/entrypoint.sh +18 -0
  7. package/ci/dev/rootfs/entrypoint.sh.d/nginx.sh +6 -0
  8. package/ci/dev/rootfs/entrypoint.sh.d/supervisor.sh +5 -0
  9. package/ci/dev/rootfs/etc/nginx/_real_ip.conf +2 -0
  10. package/ci/dev/rootfs/etc/nginx/conf.d/default.conf +20 -0
  11. package/ci/dev/rootfs/etc/supervisor.d/nginx.ini +11 -0
  12. package/ci/github/Dockerfile +59 -0
  13. package/ci/github/release-zip.js +61 -0
  14. package/ci/npm/Dockerfile +19 -0
  15. package/config/config.js +24 -0
  16. package/config/configBuilder.js +126 -0
  17. package/config/helpers.js +9 -0
  18. package/config/index.js +1 -0
  19. package/develop/README.md +42 -0
  20. package/develop/favicon.png +0 -0
  21. package/develop/index.html +511 -0
  22. package/eslint.config.mjs +114 -0
  23. package/package.json +4 -34
  24. package/{lib → public}/index.d.ts +10 -10
  25. package/scripts/zip.js +26 -0
  26. package/src/core/Pushwoosh.ts +768 -0
  27. package/src/core/Pushwoosh.types.ts +254 -0
  28. package/src/core/Safari.types.ts +26 -0
  29. package/src/core/constants.ts +58 -0
  30. package/src/core/events.types.ts +46 -0
  31. package/src/core/functions.ts +33 -0
  32. package/src/core/legacyEventsMap.ts +64 -0
  33. package/src/core/logger.ts +64 -0
  34. package/src/core/modules/EventBus/EventBus.ts +66 -0
  35. package/src/core/modules/EventBus/index.ts +1 -0
  36. package/src/core/storage.ts +254 -0
  37. package/src/helpers/logger.ts +81 -0
  38. package/src/helpers/pwlogger/Logger.constants.ts +31 -0
  39. package/src/helpers/pwlogger/Logger.ts +218 -0
  40. package/src/helpers/pwlogger/Logger.types.ts +66 -0
  41. package/src/helpers/pwlogger/handlers/handler-console/handler-console.ts +40 -0
  42. package/src/helpers/pwlogger/index.ts +2 -0
  43. package/src/helpers/unescape.ts +36 -0
  44. package/src/models/InboxMessages.ts +202 -0
  45. package/src/models/InboxMessages.types.ts +111 -0
  46. package/src/models/NotificationPayload.ts +216 -0
  47. package/src/models/NotificationPayload.types.ts +65 -0
  48. package/src/modules/Api/Api.ts +386 -0
  49. package/src/modules/Api/Api.types.ts +7 -0
  50. package/src/modules/ApiClient/ApiClient.ts +153 -0
  51. package/src/modules/ApiClient/ApiClient.types.ts +222 -0
  52. package/src/modules/Data/Data.ts +345 -0
  53. package/src/modules/DateModule.ts +53 -0
  54. package/src/modules/InboxMessagesPublic.ts +222 -0
  55. package/src/modules/PlatformChecker/PlatformChecker.ts +170 -0
  56. package/src/modules/PlatformChecker/PlatformChecker.types.ts +5 -0
  57. package/src/modules/PlatformChecker/index.ts +1 -0
  58. package/src/modules/storage/Storage.ts +164 -0
  59. package/src/modules/storage/Storage.types.ts +54 -0
  60. package/src/modules/storage/Store.ts +104 -0
  61. package/src/modules/storage/migrations/26-11-2018.ts +25 -0
  62. package/src/modules/storage/migrations/MigrationExecutor.ts +31 -0
  63. package/src/modules/storage/migrations/Migrations.ts +41 -0
  64. package/src/modules/storage/migrations/constants.ts +8 -0
  65. package/src/modules/storage/migrations/helpers.ts +16 -0
  66. package/src/modules/storage/migrations/initial.ts +47 -0
  67. package/src/modules/storage/version.ts +2 -0
  68. package/src/npm.ts +1 -0
  69. package/src/pushwoosh-web-notifications.ts +47 -0
  70. package/src/pushwoosh-widget-inbox.ts +8 -0
  71. package/src/pushwoosh-widget-subscribe-popup.ts +9 -0
  72. package/src/pushwoosh-widget-subscription-button.ts +8 -0
  73. package/src/pushwoosh-widget-subscription-prompt.ts +6 -0
  74. package/src/service-worker.ts +455 -0
  75. package/src/services/PushService/PushService.ts +2 -0
  76. package/src/services/PushService/PushService.types.ts +74 -0
  77. package/src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.ts +235 -0
  78. package/src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.types.ts +3 -0
  79. package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.ts +125 -0
  80. package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.types.ts +4 -0
  81. package/src/widget-inbox.ts +1 -0
  82. package/src/widget-subscribe-popup.ts +1 -0
  83. package/src/widget-subscription-button.ts +1 -0
  84. package/src/widget-subscription-prompt.ts +33 -0
  85. package/src/widgets/Inbox/InboxWidget.ts +564 -0
  86. package/src/widgets/Inbox/constants.ts +49 -0
  87. package/src/widgets/Inbox/css/inboxWidgetStyle.css +274 -0
  88. package/src/widgets/Inbox/helpers.ts +63 -0
  89. package/src/widgets/Inbox/inbox.d.ts +9 -0
  90. package/src/widgets/Inbox/inbox_widget.types.ts +41 -0
  91. package/src/widgets/Inbox/index.ts +1 -0
  92. package/src/widgets/Inbox/widgetTemplates.ts +55 -0
  93. package/src/widgets/SubscribePopup/SubscribePopup.ts +241 -0
  94. package/src/widgets/SubscribePopup/constants.ts +66 -0
  95. package/src/widgets/SubscribePopup/helpers.ts +11 -0
  96. package/src/widgets/SubscribePopup/index.ts +1 -0
  97. package/src/widgets/SubscribePopup/popupTemplates.ts +24 -0
  98. package/src/widgets/SubscribePopup/styles/popup.css +226 -0
  99. package/src/widgets/SubscribePopup/types/subscribe-popup.ts +68 -0
  100. package/src/widgets/SubscriptionButton/assets/css/main.css +205 -0
  101. package/src/widgets/SubscriptionButton/bell.ts +67 -0
  102. package/src/widgets/SubscriptionButton/constants.ts +28 -0
  103. package/src/widgets/SubscriptionButton/index.ts +377 -0
  104. package/src/widgets/SubscriptionButton/positioning.ts +165 -0
  105. package/src/widgets/SubscriptionButton/subscribe_widget.types.ts +53 -0
  106. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.constants.ts +1 -0
  107. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.helpers.ts +110 -0
  108. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.ts +102 -0
  109. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.types.ts +23 -0
  110. package/src/widgets/SubscriptionPrompt/constants.ts +22 -0
  111. package/src/widgets/SubscriptionPrompt/helpers.ts +42 -0
  112. package/src/widgets/widgets.d.ts +4 -0
  113. package/src/worker/global.ts +36 -0
  114. package/src/worker/notification.ts +34 -0
  115. package/src/worker/worker.types.ts +4 -0
  116. package/test/__helpers__/apiHelpers.ts +22 -0
  117. package/test/__helpers__/keyValueHelpers.ts +15 -0
  118. package/test/__helpers__/platformHelpers.ts +54 -0
  119. package/test/__helpers__/sinonHelpers.ts +7 -0
  120. package/test/__helpers__/storageHelpers.ts +56 -0
  121. package/test/__mocks__/apiRequests.ts +26 -0
  122. package/test/__mocks__/idbMock.ts +12 -0
  123. package/test/__mocks__/idbObjectStoreMock.ts +38 -0
  124. package/test/__mocks__/inboxMessages.ts +292 -0
  125. package/test/__mocks__/models/inboxModel.ts +71 -0
  126. package/test/__mocks__/modules/apiClientModule.ts +18 -0
  127. package/test/__mocks__/modules/dateModule.ts +34 -0
  128. package/test/__mocks__/modules/inboxParamsModule.ts +21 -0
  129. package/test/__mocks__/modules/paramsBuilder.ts +12 -0
  130. package/test/__mocks__/modules/paramsModule.ts +35 -0
  131. package/test/__mocks__/modules/payloadBuilderModule.ts +15 -0
  132. package/test/__mocks__/modules/storageModule.ts +58 -0
  133. package/test/__mocks__/navigator.ts +38 -0
  134. package/test/__mocks__/notification.ts +84 -0
  135. package/test/__mocks__/pushwoosh.ts +12 -0
  136. package/test/__mocks__/userAgents +8 -0
  137. package/test/functions.test.ts +22 -0
  138. package/test/ignore-html.js +6 -0
  139. package/test/mocha.opts +6 -0
  140. package/test/modules/DateModule/unit.test.ts +80 -0
  141. package/test/modules/storage/Storage/unit.test.ts +180 -0
  142. package/test/modules/storage/Store/unit.test.ts +192 -0
  143. package/testRegister.js +24 -0
  144. package/tsconfig.json +31 -0
  145. package/webpack.config.js +163 -0
  146. package/lib/index.js +0 -2
  147. package/lib/index.js.map +0 -1
  148. package/lib/service-worker.js +0 -2
  149. package/lib/service-worker.js.map +0 -1
@@ -0,0 +1,222 @@
1
+ import { type IInboxMessage } from '../../models/InboxMessages.types';
2
+
3
+ type TMethodCheckDevice = 'checkDevice';
4
+ type TMethodGetConfig = 'getConfig';
5
+ type TMethodApplicationOpen = 'applicationOpen';
6
+ type TMethodRegisterDevice = 'registerDevice';
7
+ type TMethodUnregisterDevice = 'unregisterDevice';
8
+ type TMethodDeleteDevice = 'deleteDevice';
9
+ type TMethodMessageDeliveryEvent = 'messageDeliveryEvent';
10
+ type TMethodPushStat = 'pushStat';
11
+ type TMethodSetTags = 'setTags';
12
+ type TMethodGetTags = 'getTags';
13
+ type TMethodRegisterUser = 'registerUser';
14
+ type TMethodRegisterEmail = 'registerEmail';
15
+ type TMethodRegisterEmailUser = 'registerEmailUser';
16
+ type TMethodSetEmailTags = 'setEmailTags';
17
+ type TMethodPostEvent = 'postEvent';
18
+ type TMethodGetInboxMessages = 'getInboxMessages';
19
+ type TMethodInboxStatus = 'inboxStatus';
20
+ type TMethodPageVisit = 'pageVisit';
21
+ type TMethodSetPurchase = 'setPurchase';
22
+
23
+ export interface IRequest {
24
+ application: string; // Pushwoosh application code.
25
+ hwid: string; // Unique string to identify the device.
26
+ userId: string; // The user ID to associate with event.
27
+ device_type: number; // 10 - safari, 11 - chrome, 12 - firefox.
28
+ device_model: string; // browser version.
29
+ timezone: number; // Timezone offset in seconds for the device.
30
+ language: string; // Language locale of the device. Must be a lowercase two-letter code according to ISO-639-1 standard.
31
+ v: string; // Web SDK version.
32
+ }
33
+
34
+ export interface IRequestEmail extends Omit<IRequest, 'hwid' | 'device_type'> {
35
+ email: string;
36
+ }
37
+
38
+ interface IRequestGetConfig extends IRequest {
39
+ features: string[]; // array of features names.
40
+ }
41
+
42
+ interface IRequestRegisterDevice extends IRequest {
43
+ push_token: string; // Push token for the device.
44
+ public_key?: string;
45
+ auth_token?: string;
46
+ }
47
+
48
+ interface IRequestRegisterUser extends IRequest {
49
+ ts_offset: number; // Timezone offset in seconds for the device. (aka timezone).
50
+ }
51
+
52
+ interface IRequestRegisterEmail extends IRequestEmail {
53
+ tags?: { [key: string]: any }; // email tags
54
+ ts_offset: number; // Timezone offset in seconds for the device. (aka timezone).
55
+ }
56
+
57
+ interface IRequestRegisterEmailUser extends IRequestEmail {
58
+ ts_offset: number; // Timezone offset in seconds for the device. (aka timezone).
59
+ }
60
+
61
+ interface IRequestSetEmailTags extends IRequestEmail {
62
+ tags: { [key: string]: any }; // email tags
63
+ }
64
+
65
+ interface IRequestPostEvent extends IRequest {
66
+ event: string; // Event name.
67
+ attributes?: { [key: string]: any };
68
+ timestampUTC?: number; // Timestamp in UTC.
69
+ timestampCurrent?: number; // Timestamp in local time.
70
+ }
71
+
72
+ interface IRequestMessageDeliveryEvent extends IRequest {
73
+ hash: string; // message hash,
74
+ metaData: { [key: string]: any }; // meta data
75
+ }
76
+
77
+ interface IRequestPushStat extends IRequest {
78
+ hash: string; // message hash
79
+ metaData: { [key: string]: any }; // meta data
80
+ }
81
+
82
+ interface IRequestSetTags extends IRequest {
83
+ tags: {
84
+ [key: string]: any;
85
+ };
86
+ }
87
+
88
+ interface IRequestGetInboxMessages extends IRequest {
89
+ userId: string; // use hwid or other custom string if no userId
90
+ last_code: string; // For pagination purpose. "next" parameter from response. For first request send empty string
91
+ count?: number; // optional, default messages count on page
92
+ last_request_time: number; // for update new messages counter. UTC
93
+ }
94
+
95
+ interface IRequestInboxStatus extends IRequest {
96
+ userId: string; // use hwid or other custom string if no userId
97
+ inbox_code: string; // order. Ugly logic for fast development.
98
+ time: number; // timestamp utc
99
+ status: number;
100
+ hash?: string; // ??
101
+ device_type: number; // platform type from Pushwoosh system
102
+ }
103
+
104
+ interface IRequestPageVisit extends IRequest {
105
+ title: string;
106
+ url_path: string;
107
+ url: string;
108
+ }
109
+
110
+ interface IRequestSetPurchase extends IRequest {
111
+ transactionDate: string;
112
+ quantity: number;
113
+ currency: string;
114
+ productIdentifier: string;
115
+ price: number;
116
+ }
117
+
118
+ type IResponse = void;
119
+
120
+ interface IResponseCheckDevice {
121
+ exist: boolean; // exist device token
122
+ push_token_exist: boolean; // exist push token
123
+ }
124
+
125
+ interface IResponseGetConfig {
126
+ features: {
127
+ page_visit?: {
128
+ entrypoint: string;
129
+ enabled: boolean;
130
+ };
131
+ vapid_key?: string;
132
+ web_in_apps?: {
133
+ enabled: boolean;
134
+ };
135
+ events?: string[];
136
+ subscription_prompt?: {
137
+ useCase: 'not-set' | 'default' | 'not-used';
138
+ };
139
+ };
140
+ }
141
+
142
+ interface IResponseGetTags {
143
+ result: {
144
+ [key: string]: any;
145
+ };
146
+ }
147
+
148
+ interface IResponsePostEvent {
149
+ code?: string;
150
+ }
151
+
152
+ interface IResponseGetInboxMessages {
153
+ messages: Array<IInboxMessage>;
154
+ next: string; // pagination code
155
+ deleted: Array<string>; // array of notifications codes deleted from cp
156
+ new_inbox: number; // inbox messages created since last request time
157
+ }
158
+
159
+ export type TMethod =
160
+ | TMethodCheckDevice
161
+ | TMethodGetConfig
162
+ | TMethodApplicationOpen
163
+ | TMethodRegisterDevice
164
+ | TMethodUnregisterDevice
165
+ | TMethodDeleteDevice
166
+ | TMethodMessageDeliveryEvent
167
+ | TMethodPushStat
168
+ | TMethodSetTags
169
+ | TMethodGetTags
170
+ | TMethodRegisterUser
171
+ | TMethodRegisterEmail
172
+ | TMethodRegisterEmailUser
173
+ | TMethodSetEmailTags
174
+ | TMethodPostEvent
175
+ | TMethodGetInboxMessages
176
+ | TMethodInboxStatus
177
+ | TMethodPageVisit
178
+ | TMethodSetPurchase;
179
+
180
+ export interface IMapRequest {
181
+ checkDevice: IRequest;
182
+ getConfig: IRequestGetConfig;
183
+ applicationOpen: IRequest;
184
+ registerDevice: IRequestRegisterDevice;
185
+ unregisterDevice: IRequest;
186
+ deleteDevice: IRequest;
187
+ messageDeliveryEvent: IRequestMessageDeliveryEvent;
188
+ pushStat: IRequestPushStat;
189
+ setTags: IRequestSetTags;
190
+ getTags: IRequest;
191
+ registerUser: IRequestRegisterUser;
192
+ registerEmail: IRequestRegisterEmail;
193
+ registerEmailUser: IRequestRegisterEmailUser;
194
+ setEmailTags: IRequestSetEmailTags;
195
+ postEvent: IRequestPostEvent;
196
+ getInboxMessages: IRequestGetInboxMessages;
197
+ inboxStatus: IRequestInboxStatus;
198
+ pageVisit: IRequestPageVisit;
199
+ setPurchase: IRequestSetPurchase;
200
+ }
201
+
202
+ export interface IMapResponse {
203
+ checkDevice: IResponseCheckDevice;
204
+ getConfig: IResponseGetConfig;
205
+ applicationOpen: IRequest;
206
+ registerDevice: IResponse;
207
+ unregisterDevice: IResponse;
208
+ deleteDevice: IResponse;
209
+ messageDeliveryEvent: IResponse;
210
+ pushStat: IResponse;
211
+ setTags: IResponse;
212
+ getTags: IResponseGetTags;
213
+ registerUser: IResponse;
214
+ registerEmail: IResponse;
215
+ registerEmailUser: IResponse;
216
+ setEmailTags: IResponse;
217
+ postEvent: IResponsePostEvent;
218
+ getInboxMessages: IResponseGetInboxMessages;
219
+ inboxStatus: IResponse;
220
+ pageVisit: IResponse;
221
+ setPurchase: IResponse;
222
+ }
@@ -0,0 +1,345 @@
1
+ import * as CONSTANTS from '../../core/constants';
2
+ import { keyValue } from '../../core/storage';
3
+
4
+ export class Data {
5
+ private readonly store: typeof keyValue;
6
+
7
+ constructor(store: typeof keyValue = keyValue) {
8
+ this.store = store;
9
+ }
10
+
11
+ public async clearAll(): Promise<void> {
12
+ await this.store.set('params.applicationCode', undefined);
13
+ await this.store.set('params.hwid', undefined);
14
+ await this.store.set('params.deviceType', undefined);
15
+ await this.store.set('params.deviceModel', undefined);
16
+ await this.store.set('params.language', undefined);
17
+ await this.store.set('params.apiEntrypoint', undefined);
18
+ await this.store.set('params.tokens', undefined);
19
+ await this.store.set('params.applicationServerKey', undefined);
20
+ await this.store.set('params.senderId', undefined);
21
+ await this.store.set('params.webSitePushId', undefined);
22
+ await this.store.set('params.defaultNotificationImage', undefined);
23
+ await this.store.set('params.defaultNotificationTitle', undefined);
24
+ await this.store.set('params.userId', undefined);
25
+ await this.store.set('params.email', undefined);
26
+ await this.store.set('params.userIdWasChanged', undefined);
27
+
28
+ await this.store.set('params.isLastPermissionStatus', undefined);
29
+ await this.store.set('params.isManualUnsubscribed', undefined);
30
+ await this.store.set('params.isCommunicationDisabled', undefined);
31
+ await this.store.set('params.isDropAllData', undefined);
32
+
33
+ await this.store.set('params.sdkVersion', undefined);
34
+ await this.store.set('params.serviceWorkerVersion', undefined);
35
+ await this.store.set('params.serviceWorkerUrl', undefined);
36
+ await this.store.set('params.serviceWorkerScope', undefined);
37
+
38
+ await this.store.set('params.lastOpenMessage', undefined);
39
+ await this.store.set('params.lastOpenApplicationTime', undefined);
40
+
41
+ await this.store.set('params.features', undefined);
42
+
43
+ await this.store.set('params.init', undefined);
44
+ }
45
+
46
+ public async setApplicationCode(application: string): Promise<void> {
47
+ await this.store.set('params.applicationCode', application);
48
+ }
49
+
50
+ public async getApplicationCode(): Promise<string> {
51
+ return await this.store.get('params.applicationCode');
52
+ }
53
+
54
+ public async setApiToken(token: string): Promise<string> {
55
+ return await this.store.set('params.apiToken', token);
56
+ }
57
+
58
+ public async getApiToken(): Promise<string> {
59
+ return await this.store.get('params.apiToken');
60
+ }
61
+
62
+ public async setHwid(hwid: string): Promise<void> {
63
+ await this.store.set('params.hwid', hwid);
64
+ }
65
+
66
+ public async getHwid(): Promise<string> {
67
+ return await this.store.get('params.hwid');
68
+ }
69
+
70
+ public async setDeviceType(type: number): Promise<void> {
71
+ await this.store.set('params.deviceType', type);
72
+ }
73
+
74
+ public async getDeviceType(): Promise<number> {
75
+ return await this.store.get('params.deviceType');
76
+ }
77
+
78
+ public async setDeviceModel(model: string): Promise<void> {
79
+ await this.store.set('params.deviceModel', model);
80
+ }
81
+
82
+ public async getDeviceModel(): Promise<string> {
83
+ return await this.store.get('params.deviceModel');
84
+ }
85
+
86
+ public async setLanguage(language: string): Promise<void> {
87
+ await this.store.set('params.language', language);
88
+ }
89
+
90
+ public async getLanguage(): Promise<string> {
91
+ return await this.store.get('params.language', 'en');
92
+ }
93
+
94
+ public async setApiEntrypoint(url: string): Promise<void> {
95
+ await this.store.set('params.apiEntrypoint', url);
96
+ }
97
+
98
+ public async getApiEntrypoint(): Promise<string> {
99
+ return await this.store.get('params.apiEntrypoint', CONSTANTS.DEFAULT_API_URL);
100
+ }
101
+
102
+ public async setTokens(tokens: any): Promise<void> {
103
+ await this.store.set('params.tokens', tokens);
104
+ }
105
+
106
+ public getTokens(): Promise<any> {
107
+ return this.store.get('params.tokens');
108
+ }
109
+
110
+ public async setApplicationServerKey(key: string): Promise<void> {
111
+ await this.store.set('params.applicationServerKey', key);
112
+ }
113
+
114
+ public async getApplicationServerKey(): Promise<string | undefined> {
115
+ return await this.store.get('params.applicationServerKey');
116
+ }
117
+
118
+ public async setIsVapidChanged(status: boolean): Promise<void> {
119
+ await this.store.set('params.isVapidChanged', status);
120
+ }
121
+
122
+ public async getIsVapidChanged(): Promise<boolean> {
123
+ return await this.store.get('params.isVapidChanged', false);
124
+ }
125
+
126
+ public async setWebSitePushId(senderId: string): Promise<void> {
127
+ await this.store.set('params.webSitePushId', senderId);
128
+ }
129
+
130
+ public async getWebSitePushId(): Promise<string> {
131
+ return await this.store.get('params.webSitePushId');
132
+ }
133
+
134
+ public async setDefaultNotificationImage(url?: string): Promise<void> {
135
+ await this.store.set('params.defaultNotificationImage', url);
136
+ }
137
+
138
+ public async getDefaultNotificationImage(): Promise<string> {
139
+ return await this.store.get('params.defaultNotificationImage', CONSTANTS.DEFAULT_NOTIFICATION_IMAGE);
140
+ }
141
+
142
+ public async setDefaultNotificationTitle(text?: string): Promise<void> {
143
+ await this.store.set('params.defaultNotificationTitle', text);
144
+ }
145
+
146
+ public async getDefaultNotificationTitle(): Promise<string> {
147
+ return await this.store.get('params.defaultNotificationTitle', CONSTANTS.DEFAULT_NOTIFICATION_TITLE);
148
+ }
149
+
150
+ public async setUserId(userId?: string | number): Promise<void> {
151
+ if (!userId) {
152
+ await this.store.set('params.userId', undefined);
153
+
154
+ return;
155
+ }
156
+
157
+ await this.store.set('params.userId', userId.toString());
158
+ }
159
+
160
+ public async getUserId(): Promise<string | undefined> {
161
+ return await this.store.get('params.userId');
162
+ }
163
+
164
+ public async setStatusUserIdWasChanged(status: boolean): Promise<void> {
165
+ await this.store.set('params.userIdWasChanged', status);
166
+ }
167
+
168
+ public async getStatusUserIdWasChanged(): Promise<boolean> {
169
+ return await this.store.get('params.userIdWasChanged', false);
170
+ }
171
+
172
+ public async setEmail(email?: string): Promise<void> {
173
+ if (!email) {
174
+ await this.store.set('params.email', undefined);
175
+
176
+ return;
177
+ }
178
+
179
+ await this.store.set('params.email', email.toString());
180
+ }
181
+
182
+ public async getEmail(): Promise<string | undefined> {
183
+ return await this.store.get('params.email');
184
+ }
185
+
186
+ public async setStatusEmailWasChanged(status: boolean): Promise<void> {
187
+ await this.store.set('params.emailWasChanged', status);
188
+ }
189
+
190
+ public async getStatusEmailWasChanged(): Promise<boolean> {
191
+ return await this.store.get('params.emailWasChanged', false);
192
+ }
193
+
194
+ public async setLastPermissionStatus(status: NotificationPermission): Promise<void> {
195
+ await this.store.set('params.isLastPermissionStatus', status);
196
+ }
197
+
198
+ public async getLastPermissionStatus(): Promise<NotificationPermission | undefined> {
199
+ return await this.store.get('params.isLastPermissionStatus');
200
+ }
201
+
202
+ public async setStatusManualUnsubscribed(status: boolean): Promise<void> {
203
+ await this.store.set('params.isManualUnsubscribed', status);
204
+ }
205
+
206
+ public getStatusManualUnsubscribed(): Promise<boolean> {
207
+ return this.store.get('params.isManualUnsubscribed', false);
208
+ }
209
+
210
+ public async setStatusCommunicationDisabled(status: boolean): Promise<void> {
211
+ await this.store.set('params.isCommunicationDisabled', status);
212
+ }
213
+
214
+ public getStatusCommunicationDisabled(): Promise<boolean> {
215
+ return this.store.get('params.isCommunicationDisabled', false);
216
+ }
217
+
218
+ public async setStatusDropAllData(status: boolean): Promise<void> {
219
+ await this.store.set('params.isDropAllData', status);
220
+ }
221
+
222
+ public getStatusDropAllData(): Promise<boolean> {
223
+ return this.store.get('params.isDropAllData', false);
224
+ }
225
+
226
+ public async setSdkVersion(version: string): Promise<void> {
227
+ await this.store.set('params.sdkVersion', version);
228
+ }
229
+
230
+ public async getSdkVersion(): Promise<string> {
231
+ return await this.store.get('params.sdkVersion');
232
+ }
233
+
234
+ public async setServiceWorkerVersion(version: string): Promise<void> {
235
+ await this.store.set('params.serviceWorkerVersion', version);
236
+ }
237
+
238
+ public getServiceWorkerVersion(): Promise<string> {
239
+ return this.store.get('params.serviceWorkerVersion');
240
+ }
241
+
242
+ public async setServiceWorkerUrl(url?: string | null): Promise<void> {
243
+ if (!url) {
244
+ return;
245
+ }
246
+
247
+ await this.store.set('params.serviceWorkerUrl', url);
248
+ }
249
+
250
+ public async getServiceWorkerUrl(): Promise<string> {
251
+ return await this.store.get('params.serviceWorkerUrl', CONSTANTS.DEFAULT_SERVICE_WORKER_URL);
252
+ }
253
+
254
+ public async setServiceWorkerScope(scope?: string): Promise<void> {
255
+ if (!scope) {
256
+ return;
257
+ }
258
+
259
+ await this.store.set('params.serviceWorkerScope', scope);
260
+ }
261
+
262
+ public async getServiceWorkerScope(): Promise<string> {
263
+ return await this.store.get('params.serviceWorkerScope');
264
+ }
265
+
266
+ public async setLastOpenMessage(message: any): Promise<void> {
267
+ await this.store.set('params.lastOpenMessage', message);
268
+ }
269
+
270
+ public getLastOpenMessage(): Promise<any> {
271
+ return this.store.get('params.lastOpenMessage');
272
+ }
273
+
274
+ public async setLastOpenApplicationTime(time: number): Promise<void> {
275
+ await this.store.set('params.lastOpenApplicationTime', time);
276
+ }
277
+
278
+ public async getLastOpenApplicationTime(): Promise<number> {
279
+ return await this.store.get('params.lastOpenApplicationTime');
280
+ }
281
+
282
+ public async setFeatures(features: any): Promise<void> {
283
+ await this.store.set('params.features', features);
284
+ }
285
+
286
+ public async getFeatures(): Promise<any> {
287
+ return await this.store.get('params.features');
288
+ }
289
+
290
+ public async setInitParams(params: any): Promise<any> {
291
+ await this.store.set('params.init', params);
292
+ }
293
+
294
+ public async getInitParams(): Promise<any> {
295
+ return await this.store.get('params.init');
296
+ }
297
+
298
+ public async setInboxLastRequestCode(lastCode: string): Promise<void> {
299
+ await this.store.set('params.inbox.lastRequestCode', lastCode);
300
+ }
301
+
302
+ public async getInboxLastRequestCode(): Promise<string> {
303
+ return await this.store.get('params.inbox.lastRequestCode', '');
304
+ }
305
+
306
+ public async setInboxLastRequestTime(lastRequestTime: number): Promise<void> {
307
+ await this.store.set('params.inbox.lastRequestTime', lastRequestTime);
308
+ }
309
+
310
+ public async getInboxLastRequestTime(): Promise<number> {
311
+ return this.store.get('params.inbox.lastRequestTime', 0);
312
+ }
313
+
314
+ public async setInboxNewMessagesCount(count: number): Promise<void> {
315
+ await this.store.set('params.inbox.newMessagesCount', count);
316
+ }
317
+
318
+ public async getInboxNewMessagesCount(): Promise<number> {
319
+ return this.store.get('params.inbox.newMessagesCount', 0);
320
+ }
321
+
322
+ public async setDelayedEvent(event: any): Promise<void> {
323
+ await this.store.set('params.delayedEvent', event);
324
+ }
325
+
326
+ public getDelayedEvent(): Promise<any> {
327
+ return this.store.get('params.delayedEvent');
328
+ }
329
+
330
+ public async setPromptDisplayCount(count: number): Promise<void> {
331
+ await this.store.set('params.promptDisplayCount', count);
332
+ }
333
+
334
+ public async getPromptDisplayCount(): Promise<number> {
335
+ return this.store.get('params.promptDisplayCount', 0);
336
+ }
337
+
338
+ public async setPromptLastSeenTime(time: number): Promise<void> {
339
+ await this.store.set('params.promptLastSeenTime', time);
340
+ }
341
+
342
+ public async getPromptLastSeenTime(): Promise<number> {
343
+ return this.store.get('params.promptLastSeenTime', 0);
344
+ }
345
+ }
@@ -0,0 +1,53 @@
1
+ export default class DateModule {
2
+ private _date: Date;
3
+
4
+ constructor(date: Date = new Date()) {
5
+ this._date = date;
6
+ }
7
+
8
+ set date(date: Date) {
9
+ this._date = date;
10
+ }
11
+
12
+ get date() {
13
+ return this._date;
14
+ }
15
+
16
+ /**
17
+ * Timestamp in UTC without milliseconds
18
+ */
19
+ getUtcTimestamp() {
20
+ return Math.floor((this.date.getTime() + this.date.getTimezoneOffset() * 60 * 1000) / 1000);
21
+ }
22
+
23
+ /**
24
+ * Current date timestamp without milliseconds
25
+ */
26
+ getTimestamp() {
27
+ return Math.round(this.date.getTime() / 1000);
28
+ }
29
+
30
+ /**
31
+ * Set date to local timezone
32
+ */
33
+ setLocal() {
34
+ const newDateTimestamp = this._date.getTime() - this.date.getTimezoneOffset() * 60 * 1000;
35
+ this._date = new Date(newDateTimestamp);
36
+ }
37
+
38
+ /**
39
+ * Add days to current date
40
+ * @param days
41
+ */
42
+ addDays(days: number) {
43
+ const newDateTimestamp = this._date.getTime() + days * 24 * 60 * 60 * 1000;
44
+ this._date = new Date(newDateTimestamp);
45
+ }
46
+
47
+ /**
48
+ * Get inbox fake order
49
+ */
50
+ getInboxFakeOrder(): string {
51
+ return (this._date.getTime() * 100 + 25 * 60 * 60 * 1000 * 100).toString();
52
+ }
53
+ }