web-push-notifications 3.44.7 → 3.44.9

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 (224) hide show
  1. package/core/Pushwoosh.d.ts +199 -0
  2. package/core/Pushwoosh.types.d.ts +213 -0
  3. package/core/Safari.types.d.ts +17 -0
  4. package/core/constants.d.ts +41 -0
  5. package/core/events.types.d.ts +55 -0
  6. package/core/functions.d.ts +5 -0
  7. package/core/legacyEventsMap.d.ts +5 -0
  8. package/core/logger.d.ts +14 -0
  9. package/core/modules/EventBus/EventBus.d.ts +10 -0
  10. package/core/storage.d.ts +27 -0
  11. package/helpers/logger.d.ts +11 -0
  12. package/helpers/pwlogger/Logger.constants.d.ts +21 -0
  13. package/helpers/pwlogger/Logger.d.ts +37 -0
  14. package/helpers/pwlogger/Logger.types.d.ts +44 -0
  15. package/helpers/pwlogger/handlers/handler-console/handler-console.d.ts +2 -0
  16. package/{src/helpers/unescape.ts → helpers/unescape.d.ts} +1 -18
  17. package/models/InboxMessages.d.ts +82 -0
  18. package/models/InboxMessages.types.d.ts +83 -0
  19. package/models/NotificationPayload.d.ts +39 -0
  20. package/models/NotificationPayload.types.d.ts +63 -0
  21. package/modules/Api/Api.d.ts +45 -0
  22. package/modules/Api/Api.types.d.ts +7 -0
  23. package/modules/ApiClient/ApiClient.d.ts +29 -0
  24. package/modules/ApiClient/ApiClient.types.d.ts +188 -0
  25. package/modules/Data/Data.d.ts +76 -0
  26. package/modules/DateModule.d.ts +27 -0
  27. package/modules/InboxMessagesPublic.d.ts +64 -0
  28. package/modules/PlatformChecker/PlatformChecker.d.ts +45 -0
  29. package/modules/PlatformChecker/PlatformChecker.types.d.ts +5 -0
  30. package/modules/storage/Storage.d.ts +63 -0
  31. package/{src/modules/storage/Storage.types.ts → modules/storage/Storage.types.d.ts} +7 -25
  32. package/modules/storage/Store.d.ts +22 -0
  33. package/modules/storage/migrations/26-11-2018.d.ts +2 -0
  34. package/modules/storage/migrations/MigrationExecutor.d.ts +9 -0
  35. package/modules/storage/migrations/Migrations.d.ts +15 -0
  36. package/modules/storage/migrations/constants.d.ts +6 -0
  37. package/modules/storage/migrations/helpers.d.ts +7 -0
  38. package/modules/storage/migrations/initial.d.ts +2 -0
  39. package/modules/storage/version.d.ts +2 -0
  40. package/npm.js +2 -0
  41. package/npm.js.map +1 -0
  42. package/package.json +1 -1
  43. package/service-worker.d.ts +1 -0
  44. package/service-worker.js +2 -0
  45. package/service-worker.js.map +1 -0
  46. package/services/PushService/PushService.types.d.ts +64 -0
  47. package/services/PushService/drivers/PushServiceDefault/PushServiceDefault.d.ts +29 -0
  48. package/{src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.types.ts → services/PushService/drivers/PushServiceDefault/PushServiceDefault.types.d.ts} +1 -1
  49. package/services/PushService/drivers/PushServiceSafari/PushServiceSafari.d.ts +21 -0
  50. package/services/PushService/drivers/PushServiceSafari/PushServiceSafari.types.d.ts +4 -0
  51. package/widget-inbox.js +2 -0
  52. package/widget-inbox.js.map +1 -0
  53. package/widget-subscribe-popup.js +2 -0
  54. package/widget-subscribe-popup.js.map +1 -0
  55. package/widget-subscription-button.js +2 -0
  56. package/widget-subscription-button.js.map +1 -0
  57. package/widget-subscription-prompt.d.ts +2 -0
  58. package/widget-subscription-prompt.js +2 -0
  59. package/widget-subscription-prompt.js.map +1 -0
  60. package/widgets/Inbox/InboxWidget.d.ts +49 -0
  61. package/widgets/Inbox/constants.d.ts +7 -0
  62. package/widgets/Inbox/helpers.d.ts +4 -0
  63. package/widgets/Inbox/inbox_widget.types.d.ts +34 -0
  64. package/widgets/Inbox/widgetTemplates.d.ts +4 -0
  65. package/widgets/SubscribePopup/SubscribePopup.d.ts +20 -0
  66. package/widgets/SubscribePopup/constants.d.ts +6 -0
  67. package/widgets/SubscribePopup/helpers.d.ts +1 -0
  68. package/widgets/SubscribePopup/popupTemplates.d.ts +9 -0
  69. package/widgets/SubscribePopup/types/subscribe-popup.d.ts +43 -0
  70. package/widgets/SubscriptionButton/bell.d.ts +2 -0
  71. package/widgets/SubscriptionButton/constants.d.ts +7 -0
  72. package/widgets/SubscriptionButton/index.d.ts +90 -0
  73. package/widgets/SubscriptionButton/positioning.d.ts +11 -0
  74. package/widgets/SubscriptionButton/subscribe_widget.types.d.ts +35 -0
  75. package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.constants.d.ts +1 -0
  76. package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.d.ts +14 -0
  77. package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.helpers.d.ts +3 -0
  78. package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.types.d.ts +19 -0
  79. package/widgets/SubscriptionPrompt/constants.d.ts +21 -0
  80. package/widgets/SubscriptionPrompt/helpers.d.ts +5 -0
  81. package/worker/global.d.ts +16 -0
  82. package/worker/notification.d.ts +9 -0
  83. package/worker/worker.types.d.ts +4 -0
  84. package/.editorconfig +0 -11
  85. package/.gitlab-ci.yml +0 -193
  86. package/babel.config.js +0 -7
  87. package/ci/cdn/Dockerfile +0 -12
  88. package/ci/dev/Dockerfile +0 -30
  89. package/ci/dev/rootfs/entrypoint.sh +0 -18
  90. package/ci/dev/rootfs/entrypoint.sh.d/nginx.sh +0 -6
  91. package/ci/dev/rootfs/entrypoint.sh.d/supervisor.sh +0 -5
  92. package/ci/dev/rootfs/etc/nginx/_real_ip.conf +0 -2
  93. package/ci/dev/rootfs/etc/nginx/conf.d/default.conf +0 -20
  94. package/ci/dev/rootfs/etc/supervisor.d/nginx.ini +0 -11
  95. package/ci/github/Dockerfile +0 -59
  96. package/ci/github/release-zip.js +0 -61
  97. package/ci/npm/Dockerfile +0 -22
  98. package/config/config.js +0 -24
  99. package/config/configBuilder.js +0 -126
  100. package/config/helpers.js +0 -9
  101. package/config/index.js +0 -1
  102. package/develop/README.md +0 -42
  103. package/develop/favicon.png +0 -0
  104. package/develop/index.html +0 -511
  105. package/eslint.config.mjs +0 -114
  106. package/public/index.d.ts +0 -337
  107. package/scripts/zip.js +0 -26
  108. package/src/core/Pushwoosh.ts +0 -768
  109. package/src/core/Pushwoosh.types.ts +0 -254
  110. package/src/core/Safari.types.ts +0 -26
  111. package/src/core/constants.ts +0 -58
  112. package/src/core/events.types.ts +0 -46
  113. package/src/core/functions.ts +0 -33
  114. package/src/core/legacyEventsMap.ts +0 -64
  115. package/src/core/logger.ts +0 -64
  116. package/src/core/modules/EventBus/EventBus.ts +0 -66
  117. package/src/core/storage.ts +0 -254
  118. package/src/helpers/logger.ts +0 -81
  119. package/src/helpers/pwlogger/Logger.constants.ts +0 -31
  120. package/src/helpers/pwlogger/Logger.ts +0 -218
  121. package/src/helpers/pwlogger/Logger.types.ts +0 -66
  122. package/src/helpers/pwlogger/handlers/handler-console/handler-console.ts +0 -40
  123. package/src/models/InboxMessages.ts +0 -202
  124. package/src/models/InboxMessages.types.ts +0 -111
  125. package/src/models/NotificationPayload.ts +0 -216
  126. package/src/models/NotificationPayload.types.ts +0 -65
  127. package/src/modules/Api/Api.ts +0 -386
  128. package/src/modules/Api/Api.types.ts +0 -7
  129. package/src/modules/ApiClient/ApiClient.ts +0 -153
  130. package/src/modules/ApiClient/ApiClient.types.ts +0 -222
  131. package/src/modules/Data/Data.ts +0 -345
  132. package/src/modules/DateModule.ts +0 -53
  133. package/src/modules/InboxMessagesPublic.ts +0 -222
  134. package/src/modules/PlatformChecker/PlatformChecker.ts +0 -170
  135. package/src/modules/PlatformChecker/PlatformChecker.types.ts +0 -5
  136. package/src/modules/storage/Storage.ts +0 -164
  137. package/src/modules/storage/Store.ts +0 -104
  138. package/src/modules/storage/migrations/26-11-2018.ts +0 -25
  139. package/src/modules/storage/migrations/MigrationExecutor.ts +0 -31
  140. package/src/modules/storage/migrations/Migrations.ts +0 -41
  141. package/src/modules/storage/migrations/constants.ts +0 -8
  142. package/src/modules/storage/migrations/helpers.ts +0 -16
  143. package/src/modules/storage/migrations/initial.ts +0 -47
  144. package/src/modules/storage/version.ts +0 -2
  145. package/src/pushwoosh-web-notifications.ts +0 -47
  146. package/src/pushwoosh-widget-inbox.ts +0 -8
  147. package/src/pushwoosh-widget-subscribe-popup.ts +0 -9
  148. package/src/pushwoosh-widget-subscription-button.ts +0 -8
  149. package/src/pushwoosh-widget-subscription-prompt.ts +0 -6
  150. package/src/service-worker.ts +0 -455
  151. package/src/services/PushService/PushService.types.ts +0 -74
  152. package/src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.ts +0 -235
  153. package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.ts +0 -125
  154. package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.types.ts +0 -4
  155. package/src/widget-subscription-prompt.ts +0 -33
  156. package/src/widgets/Inbox/InboxWidget.ts +0 -564
  157. package/src/widgets/Inbox/constants.ts +0 -49
  158. package/src/widgets/Inbox/css/inboxWidgetStyle.css +0 -274
  159. package/src/widgets/Inbox/helpers.ts +0 -63
  160. package/src/widgets/Inbox/inbox.d.ts +0 -9
  161. package/src/widgets/Inbox/inbox_widget.types.ts +0 -41
  162. package/src/widgets/Inbox/widgetTemplates.ts +0 -55
  163. package/src/widgets/SubscribePopup/SubscribePopup.ts +0 -241
  164. package/src/widgets/SubscribePopup/constants.ts +0 -66
  165. package/src/widgets/SubscribePopup/helpers.ts +0 -11
  166. package/src/widgets/SubscribePopup/popupTemplates.ts +0 -24
  167. package/src/widgets/SubscribePopup/styles/popup.css +0 -226
  168. package/src/widgets/SubscribePopup/types/subscribe-popup.ts +0 -68
  169. package/src/widgets/SubscriptionButton/assets/css/main.css +0 -205
  170. package/src/widgets/SubscriptionButton/bell.ts +0 -67
  171. package/src/widgets/SubscriptionButton/constants.ts +0 -28
  172. package/src/widgets/SubscriptionButton/index.ts +0 -377
  173. package/src/widgets/SubscriptionButton/positioning.ts +0 -165
  174. package/src/widgets/SubscriptionButton/subscribe_widget.types.ts +0 -53
  175. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.constants.ts +0 -1
  176. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.helpers.ts +0 -110
  177. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.ts +0 -102
  178. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.types.ts +0 -23
  179. package/src/widgets/SubscriptionPrompt/constants.ts +0 -22
  180. package/src/widgets/SubscriptionPrompt/helpers.ts +0 -42
  181. package/src/widgets/widgets.d.ts +0 -4
  182. package/src/worker/global.ts +0 -36
  183. package/src/worker/notification.ts +0 -34
  184. package/src/worker/worker.types.ts +0 -4
  185. package/test/__helpers__/apiHelpers.ts +0 -22
  186. package/test/__helpers__/keyValueHelpers.ts +0 -15
  187. package/test/__helpers__/platformHelpers.ts +0 -54
  188. package/test/__helpers__/sinonHelpers.ts +0 -7
  189. package/test/__helpers__/storageHelpers.ts +0 -56
  190. package/test/__mocks__/apiRequests.ts +0 -26
  191. package/test/__mocks__/idbMock.ts +0 -12
  192. package/test/__mocks__/idbObjectStoreMock.ts +0 -38
  193. package/test/__mocks__/inboxMessages.ts +0 -292
  194. package/test/__mocks__/models/inboxModel.ts +0 -71
  195. package/test/__mocks__/modules/apiClientModule.ts +0 -18
  196. package/test/__mocks__/modules/dateModule.ts +0 -34
  197. package/test/__mocks__/modules/inboxParamsModule.ts +0 -21
  198. package/test/__mocks__/modules/paramsBuilder.ts +0 -12
  199. package/test/__mocks__/modules/paramsModule.ts +0 -35
  200. package/test/__mocks__/modules/payloadBuilderModule.ts +0 -15
  201. package/test/__mocks__/modules/storageModule.ts +0 -58
  202. package/test/__mocks__/navigator.ts +0 -38
  203. package/test/__mocks__/notification.ts +0 -84
  204. package/test/__mocks__/pushwoosh.ts +0 -12
  205. package/test/__mocks__/userAgents +0 -8
  206. package/test/functions.test.ts +0 -22
  207. package/test/ignore-html.js +0 -6
  208. package/test/mocha.opts +0 -6
  209. package/test/modules/DateModule/unit.test.ts +0 -80
  210. package/test/modules/storage/Storage/unit.test.ts +0 -180
  211. package/test/modules/storage/Store/unit.test.ts +0 -192
  212. package/testRegister.js +0 -24
  213. package/tsconfig.json +0 -31
  214. package/webpack.config.js +0 -163
  215. /package/{src/core/modules/EventBus/index.ts → core/modules/EventBus/index.d.ts} +0 -0
  216. /package/{src/helpers/pwlogger/index.ts → helpers/pwlogger/index.d.ts} +0 -0
  217. /package/{src/modules/PlatformChecker/index.ts → modules/PlatformChecker/index.d.ts} +0 -0
  218. /package/{src/npm.ts → npm.d.ts} +0 -0
  219. /package/{src/services/PushService/PushService.ts → services/PushService/PushService.d.ts} +0 -0
  220. /package/{src/widget-inbox.ts → widget-inbox.d.ts} +0 -0
  221. /package/{src/widget-subscribe-popup.ts → widget-subscribe-popup.d.ts} +0 -0
  222. /package/{src/widget-subscription-button.ts → widget-subscription-button.d.ts} +0 -0
  223. /package/{src/widgets/Inbox/index.ts → widgets/Inbox/index.d.ts} +0 -0
  224. /package/{src/widgets/SubscribePopup/index.ts → widgets/SubscribePopup/index.d.ts} +0 -0
@@ -1,102 +0,0 @@
1
- import { SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE } from './SubscriptionPromptWidget.constants';
2
- import { getHTML, getStyles } from './SubscriptionPromptWidget.helpers';
3
- import { type ISubscriptionPromptWidgetParams } from './SubscriptionPromptWidget.types';
4
- import { type Pushwoosh } from '../../core/Pushwoosh';
5
-
6
- export class SubscriptionPromptWidget {
7
- private readonly pw: Pushwoosh;
8
-
9
- constructor(pw: Pushwoosh) {
10
- this.pw = pw;
11
- };
12
-
13
- public init(params: ISubscriptionPromptWidgetParams): void {
14
- const rootElement = this.getRootElement();
15
-
16
- // if root element not exist
17
- // create widget
18
- if (!rootElement) {
19
- const html = getHTML(params);
20
- const styles = getStyles(params);
21
-
22
- // append popup to body
23
- document.body.insertAdjacentHTML('beforeend', html);
24
-
25
- // append styles to head
26
- document.head.appendChild(styles);
27
- }
28
-
29
- this.addEventListeners();
30
- }
31
-
32
- public show(): void {
33
- const rootElement = this.getRootElementWithCheckExist();
34
- this.pw.dispatchEvent('show-subscription-widget', {});
35
-
36
- rootElement.classList.add(`${SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE}_show`);
37
- }
38
-
39
- public hide(): void {
40
- const rootElement = this.getRootElementWithCheckExist();
41
-
42
- if (rootElement.classList.contains(`${SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE}_show`)) {
43
- this.pw.dispatchEvent('hide-subscription-widget', {});
44
- rootElement.classList.remove(`${SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE}_show`);
45
- }
46
- }
47
-
48
- private getRootElement(): HTMLElement | null {
49
- return document.getElementById(`${SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE}-root`);
50
- }
51
-
52
- private getRootElementWithCheckExist(): HTMLElement {
53
- const element = this.getRootElement();
54
-
55
- if (!element) {
56
- throw new Error(`Can't find element by id "${SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE}-root", please use method init first.`);
57
- }
58
-
59
- return element;
60
- }
61
-
62
- private getDeclineButtonWithCheckExist(): HTMLButtonElement {
63
- const element = document.getElementById(`${SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE}-decline`) as HTMLButtonElement;
64
-
65
- if (!element) {
66
- throw new Error(`Can't find element by id "${SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE}-decline", please use method init first.`);
67
- }
68
-
69
- return element;
70
- }
71
-
72
- private getAcceptButtonWithCheckExist(): HTMLButtonElement {
73
- const element = document.getElementById(`${SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE}-accept`) as HTMLButtonElement;
74
-
75
- if (!element) {
76
- throw new Error(`Can't find element by id "${SUBSCRIPTION_PROMPT_WIDGET_NAMESPACE}-accept", please use method init first.`);
77
- }
78
-
79
- return element;
80
- }
81
-
82
- private addEventListeners(): void {
83
- const rootElement = this.getRootElementWithCheckExist();
84
- const declineElement = this.getDeclineButtonWithCheckExist();
85
- const acceptElement = this.getAcceptButtonWithCheckExist();
86
-
87
- document.addEventListener('click', (event) => {
88
- if (!rootElement.contains((event.target as HTMLElement))) {
89
- this.hide();
90
- }
91
- });
92
-
93
- declineElement.addEventListener('click', () => {
94
- this.hide();
95
- });
96
-
97
- acceptElement.addEventListener('click', () => {
98
- this.hide();
99
- this.pw.subscribe();
100
- });
101
- }
102
- }
@@ -1,23 +0,0 @@
1
- export interface ISubscriptionPromptWidgetParams {
2
- headerText: string;
3
- headerTextColor: string;
4
- subheaderText?: string;
5
- subheaderTextColor?: string;
6
-
7
- buttonAcceptText: string;
8
- buttonAcceptTextColor: string;
9
- buttonAcceptRound: string;
10
- buttonAcceptBackgroundColor: string;
11
- buttonAcceptBorderColor: string;
12
-
13
- buttonCancelText: string;
14
- buttonCancelTextColor: string;
15
- buttonCancelRound: string;
16
- buttonCancelBackgroundColor: string;
17
- buttonCancelBorderColor: string;
18
-
19
- cappingCount: number;
20
- cappingDelay: number;
21
-
22
- backgroundColor: string;
23
- }
@@ -1,22 +0,0 @@
1
- export const SUBSCRIPTION_WIDGET_USE_CASE_NOT_SET = 'not-set';
2
- export const SUBSCRIPTION_WIDGET_USE_CASE_DEFAULT = 'default';
3
-
4
- export const SUBSCRIPTION_PROMPT_WIDGET_DEFAULT_CONFIG = {
5
- headerText: 'Subscribe to our news',
6
- headerTextColor: '#000000',
7
- subheaderText: 'Don\'t miss out on the latest news and updates!',
8
- subheaderTextColor: '#000000',
9
- buttonAcceptText: 'Agree',
10
- buttonAcceptTextColor: '#1A72E8',
11
- buttonAcceptRound: '4px',
12
- buttonAcceptBackgroundColor: '#FFFFFF',
13
- buttonAcceptBorderColor: '#E3E4E8',
14
- buttonCancelText: 'Deny',
15
- buttonCancelTextColor: '#1A72E8',
16
- buttonCancelRound: '4px',
17
- buttonCancelBackgroundColor: '#FFFFFF',
18
- buttonCancelBorderColor: '#E3E4E8',
19
- cappingCount: 3,
20
- cappingDelay: 1000 * 60 * 60 * 4, // time in ms
21
- backgroundColor: '#FFFFFF',
22
- };
@@ -1,42 +0,0 @@
1
- import { SUBSCRIPTION_PROMPT_WIDGET_DEFAULT_CONFIG } from './constants';
2
- import type { ISubscriptionPromptWidgetParams } from './SubscriptionPromptWidget.types';
3
- import type { Pushwoosh } from '../../core/Pushwoosh';
4
-
5
- export const getWidgetConfig = (features: any): ISubscriptionPromptWidgetParams => {
6
- // get config by features from get config method
7
- const currentConfig = features['subscription_prompt_widget'] && features['subscription_prompt_widget'].params;
8
-
9
- // merge current config with capping defaults
10
- const configWithDefaultCapping: ISubscriptionPromptWidgetParams = {
11
- cappingCount: SUBSCRIPTION_PROMPT_WIDGET_DEFAULT_CONFIG.cappingCount,
12
- cappingDelay: SUBSCRIPTION_PROMPT_WIDGET_DEFAULT_CONFIG.cappingDelay,
13
- ...currentConfig,
14
- };
15
-
16
- // if current config is not exist show with default values
17
- return currentConfig
18
- ? configWithDefaultCapping
19
- : SUBSCRIPTION_PROMPT_WIDGET_DEFAULT_CONFIG;
20
- };
21
-
22
- export const checkCanShowByCapping = async (widgetConfig: ISubscriptionPromptWidgetParams, pw: Pushwoosh): Promise<boolean> => {
23
- const currentTime = new Date().getTime();
24
- const displayCount = await pw.data.getPromptDisplayCount();
25
- const lastSeenTime = await pw.data.getPromptLastSeenTime();
26
-
27
- // can show by max display count
28
- const canShowByCapping = widgetConfig.cappingCount > displayCount;
29
-
30
- // can show last seen time
31
- const canShowByLastTime = currentTime - lastSeenTime > widgetConfig.cappingDelay;
32
-
33
- return canShowByCapping && canShowByLastTime;
34
- };
35
-
36
- export const updateCappingParams = async (pw: Pushwoosh): Promise<void> => {
37
- const displayCount = await pw.data.getPromptDisplayCount();
38
- const currentTime = new Date().getTime();
39
-
40
- await pw.data.setPromptDisplayCount(displayCount + 1);
41
- await pw.data.setPromptLastSeenTime(currentTime);
42
- };
@@ -1,4 +0,0 @@
1
- declare module '*.css' {
2
- const content: string;
3
- export default content;
4
- }
@@ -1,36 +0,0 @@
1
- import { isFunction } from '../core/functions';
2
- import { type EventBus } from '../core/modules/EventBus';
3
- import { type TPWCanWaitCallback } from '../core/Pushwoosh.types';
4
- import { type Api } from '../modules/Api/Api';
5
- import { type Data } from '../modules/Data/Data';
6
-
7
- export default class WorkerPushwooshGlobal {
8
- public readonly eventBus: EventBus;
9
- public readonly api: Api;
10
- public readonly data: Data;
11
-
12
- constructor(eventBus: EventBus, data: Data, api: Api) {
13
- this.eventBus = eventBus;
14
- this.data = data;
15
- this.api = api;
16
- }
17
-
18
- _listeners: { [key: string]: TPWCanWaitCallback[] } = {};
19
-
20
- push(f: ['onPush', TPWCanWaitCallback]) {
21
- if (Array.isArray(f) && f[0] === 'onPush' && isFunction(f[1])) {
22
- if (!this._listeners[f[0]]) {
23
- this._listeners[f[0]] = [];
24
- }
25
- this._listeners[f[0]].push(f[1]);
26
- }
27
- }
28
-
29
- getListeners(eventName: string) {
30
- return this._listeners[eventName] || [];
31
- }
32
-
33
- public async initApi() {
34
- return Promise.resolve();
35
- }
36
- }
@@ -1,34 +0,0 @@
1
- declare const self: ServiceWorkerGlobalScope;
2
-
3
- export default class PushwooshNotification {
4
- private _canceled = false;
5
-
6
- private readonly showNotificationOptions: NotificationOptions;
7
- private readonly body: string;
8
- private readonly title: string;
9
-
10
- constructor(
11
- showNotificationOptions: NotificationOptions,
12
- body: string,
13
- title: string,
14
- ) {
15
- this.showNotificationOptions = showNotificationOptions;
16
- this.body = body;
17
- this.title = title;
18
- }
19
-
20
- async show() {
21
- if (this._canceled) {
22
- return;
23
- }
24
-
25
- const showNotificationOptions = this.showNotificationOptions;
26
- if (!showNotificationOptions.silent) {
27
- await self.registration.showNotification(this.title, showNotificationOptions);
28
- }
29
- }
30
-
31
- cancel() {
32
- this._canceled = true;
33
- }
34
- }
@@ -1,4 +0,0 @@
1
- export interface PushSubscriptionChangeEvent extends ExtendableEvent {
2
- readonly newSubscription: PushSubscription | null;
3
- readonly oldSubscription: PushSubscription | null;
4
- }
@@ -1,22 +0,0 @@
1
- import apiCall from '../../src/modules/api/apiCall';
2
- import * as sinon from 'sinon';
3
-
4
-
5
- export async function errorApiCall(
6
- apiMethodMock: string,
7
- responseMock: {},
8
- requestMock: {} = {request: {}}
9
- ): Promise<any> {
10
- (global as any).fetch = sinon.fake.resolves(responseMock);
11
-
12
- let res;
13
- try {
14
- res = await apiCall(apiMethodMock, requestMock);
15
- }
16
- catch (e) {
17
- res = e;
18
- }
19
-
20
- delete (global as any).fetch;
21
- return res;
22
- }
@@ -1,15 +0,0 @@
1
- import { type SinonSandbox } from 'sinon';
2
-
3
- import { keyValue } from '../../src/core/storage';
4
-
5
- export function keyValueStub(
6
- sandbox: SinonSandbox,
7
- stubArgs: Array<any>,
8
- resultMock: any,
9
- method: 'get' | 'set' | 'extend' | 'getAll',
10
- ) {
11
- const keyValueStub = sandbox.stub(keyValue, method);
12
- keyValueStub
13
- .withArgs(...stubArgs)
14
- .returns(resultMock);
15
- }
@@ -1,54 +0,0 @@
1
- import {edgeUserAgent, firefoxUserAgent, macOSPlatform, operaUserAgent, safariUserAgent} from "../__mocks__/navigator";
2
-
3
- declare const window: any;
4
- declare const navigator: any;
5
-
6
-
7
- const chromeUserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36';
8
-
9
-
10
- export function setChromeProps() {
11
- navigator.userAgent = chromeUserAgent;
12
- navigator.vendor = 'Google Inc.';
13
- }
14
-
15
- export function cleanPlatformProps() {
16
- // clean window platform props
17
- delete window.PushManager;
18
- delete window.Notification;
19
- delete window.safari;
20
- delete window.Promise;
21
-
22
- // clean navigator platform props
23
- delete navigator.serviceWorker;
24
- delete navigator.platform;
25
- delete navigator.vendor;
26
- navigator.userAgent = '';
27
- }
28
-
29
- export function setServiceWorkerAvailabilityProps() {
30
- navigator.serviceWorker = {};
31
- window.PushManager = {};
32
- window.Notification = {};
33
- }
34
-
35
- export function setSafariProps() {
36
- navigator.userAgent = safariUserAgent;
37
- window.safari = {};
38
- }
39
-
40
- export function setOperaProps() {
41
- navigator.userAgent = operaUserAgent;
42
- }
43
-
44
- export function setFirefoxProps() {
45
- (navigator as any).userAgent = firefoxUserAgent;
46
- }
47
-
48
- export function setEdgeProps() {
49
- navigator.userAgent = edgeUserAgent;
50
- }
51
-
52
- export function setMacPlatformProps() {
53
- navigator.platform = macOSPlatform;
54
- }
@@ -1,7 +0,0 @@
1
- import {SinonSandbox} from 'sinon';
2
-
3
-
4
- export function clearSandbox(sandbox: SinonSandbox) {
5
- sandbox.restore();
6
- sandbox.resetHistory();
7
- }
@@ -1,56 +0,0 @@
1
- import * as sinon from 'sinon';
2
- import {SinonSandbox, SinonSpy} from 'sinon';
3
-
4
- import Storage from '../../src/modules/storage/Storage';
5
- import * as storeModule from '../../src/modules/storage/Store';
6
-
7
-
8
- // Storage helpers
9
-
10
- export function getDbStubHelper(sandbox: SinonSandbox, storage: Storage) {
11
- const closeDbFake = sinon.fake();
12
- const getDbStub = sandbox.stub(storage, 'getDB')
13
- .callsFake(function getDbMock() {
14
- return { close: closeDbFake } as any;
15
- });
16
-
17
- return [getDbStub, closeDbFake];
18
- }
19
-
20
-
21
- export function getStoreStubHelper(sandbox: SinonSandbox) {
22
- const putFake = sinon.fake();
23
- const deleteFake = sinon.fake();
24
- const getFake = sinon.fake();
25
- const getAllFake = sinon.fake();
26
- const countFake = sinon.fake();
27
- const countByIndexFake = sinon.fake();
28
- const indexSetterFake = sinon.fake();
29
-
30
- function StoreMock() {
31
- this.put = putFake;
32
- this.delete = deleteFake;
33
- this.get = getFake;
34
- this.getAll = getAllFake;
35
- this.count = countFake;
36
- this.countByIndex = countByIndexFake;
37
-
38
- Object.defineProperty(this,'index', {
39
- set: indexSetterFake
40
- });
41
- }
42
-
43
- const storeStub = sandbox.stub(storeModule, 'default')
44
- .callsFake(StoreMock);
45
-
46
- return {
47
- storeStub,
48
- putFake,
49
- deleteFake,
50
- getFake,
51
- getAllFake,
52
- countFake,
53
- countByIndexFake,
54
- indexSetterFake
55
- }
56
- }
@@ -1,26 +0,0 @@
1
- import {appCodeMock, hwidMock, userIdMock} from './modules/paramsModule';
2
- import {lastRequestCodeMock, lastRequestTimeMock} from './modules/inboxParamsModule';
3
-
4
-
5
- export const getInboxMessagesRequestMock: IGetInboxMessagesRequest = {
6
- application: appCodeMock,
7
- hwid: hwidMock,
8
- userId: hwidMock,
9
- count: undefined,
10
- last_request_time: lastRequestTimeMock,
11
- last_code: lastRequestCodeMock
12
- };
13
-
14
- export const inboxIdMock = 'test_inbox_id';
15
- export const inboxStatusTimestampMock = 1544086800000;
16
- export const statusMock: TInboxMessageStatus = 2;
17
- export const deviceTypeMock = 11; // Chrome platform type
18
- export const inboxStatusRequestMock: IInboxStatusRequest = {
19
- application: appCodeMock,
20
- hwid: hwidMock,
21
- userId: userIdMock,
22
- inbox_code: inboxIdMock,
23
- time: inboxStatusTimestampMock,
24
- status: statusMock,
25
- device_type: deviceTypeMock
26
- };
@@ -1,12 +0,0 @@
1
- import StoreMock from './idbObjectStoreMock';
2
-
3
-
4
- export default class DbMock {
5
- transaction() {
6
- return this;
7
- }
8
-
9
- objectStore(storeName: string) {
10
- return new StoreMock(storeName);
11
- }
12
- }
@@ -1,38 +0,0 @@
1
- import * as sinon from 'sinon';
2
- import {SinonSpy} from 'sinon';
3
-
4
-
5
- export default class StoreMock {
6
- name: string;
7
-
8
- _containsFake: any = sinon.fake.returns(true);
9
- _indexFake: SinonSpy | {[key: string]: SinonSpy} = sinon.fake();
10
-
11
- private validIndexNames = ['test_index_name'];
12
-
13
- put = sinon.fake();
14
- delete = sinon.fake();
15
- get = sinon.fake();
16
- getAll = sinon.fake();
17
- count = sinon.fake();
18
- index: SinonSpy = sinon.fake();
19
-
20
- constructor(name: string) {
21
- this.name = name;
22
- }
23
-
24
- set containsFake(containsFake: SinonSpy) {
25
- this._containsFake = containsFake;
26
- }
27
-
28
- get indexNames() {
29
- const that = this;
30
- return {
31
- contains: that._containsFake
32
- }
33
- }
34
-
35
- setIndexFake(indexFake: SinonSpy) {
36
- this.index = indexFake;
37
- }
38
- }