web-push-notifications 3.40.1 → 3.44.1

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,511 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Web SDK test server</title>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <link rel="shortcut icon" href="develop/favicon.png" type="image/x-icon" />
8
+ <script>
9
+ var Pushwoosh = Pushwoosh || [];
10
+ Pushwoosh.push(["init", <%=htmlWebpackPlugin.options.externals.initParams%>]);
11
+ </script>
12
+ <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700&amp;subset=cyrillic" rel="stylesheet">
13
+ <style>
14
+ body {
15
+ font-family: 'Open Sans', sans-serif;
16
+ margin: 50px 25px;
17
+ }
18
+ .permission-status,
19
+ .subscription-status {
20
+ display: none;
21
+ }
22
+ .success {
23
+ color: green;
24
+ }
25
+ .error {
26
+ color: red;
27
+ }
28
+ textarea {
29
+ width: 100%;
30
+ box-sizing: border-box;
31
+ }
32
+ fieldset {
33
+ margin: 30px 0;
34
+ }
35
+ input, button, textarea {
36
+ font-family: inherit;
37
+ }
38
+ #actionSubscribe,
39
+ #denied {color: red;}
40
+ #actionUnsubscribe,
41
+ #granted {color: green;}
42
+ #prompt {color: blue;}
43
+
44
+ .page {
45
+ font-size: 14px;
46
+ padding: 0 20px;
47
+ margin: auto;
48
+ }
49
+
50
+ pre {
51
+ font-size: 12px;
52
+ }
53
+ </style>
54
+ </head>
55
+ <body>
56
+ <div class="page">
57
+ <h1><a href="/">Pushwoosh Web SDK</a> <span id="pwInbox">🔔</span></h1>
58
+
59
+ <p><em>Status === subscribed, when notifications permission granted and device registered.</em></p>
60
+
61
+ <p>
62
+ Permission:
63
+ <b id="prompt" class="permission-status">Prompt</b>
64
+ <b id="denied" class="permission-status">Denied</b>
65
+ <b id="granted" class="permission-status">Granted</b>
66
+ </p>
67
+ <p>
68
+ Status:
69
+ <b id="actionSubscribe" class="subscription-status">
70
+ Unsubscribed <br><br><button onclick="Pushwoosh.subscribe()">Subscribe</button>
71
+ </b>
72
+ <b id="actionUnsubscribe" class="subscription-status">
73
+ Subscribed <br><br><button onclick="Pushwoosh.unsubscribe()">Unsubscribe</button>
74
+ </b>
75
+ </p>
76
+
77
+ <p>Params:</p>
78
+ <table id="deviceParams" border="1" cellpadding="5" cellspacing="0" bordercolor="lightgrey">
79
+ <tbody></tbody>
80
+ </table>
81
+
82
+ <fieldset>
83
+ <legend>GDPR communication</legend>
84
+ <p>
85
+ <label for="GDPRSetCommunicationEnabled">
86
+ <input type="checkbox" id="GDPRSetCommunicationEnabled">
87
+ Set Communication Enabled
88
+ </label>
89
+ </p>
90
+ <button id="GDPRRemoveAllDeviceData">Remove All Device Data</button>
91
+ </fieldset>
92
+
93
+ <fieldset>
94
+ <legend>/postEvent</legend>
95
+ <form id="postEventForm">
96
+ <div class="success"></div>
97
+ <div class="error"></div>
98
+ <p>
99
+ <input type="text" name="event" placeholder="Specify event name..." required>
100
+ </p>
101
+ <p>
102
+ <textarea name="attributes" placeholder="Specify valid JSON with attributes..." cols="30" rows="10" required></textarea>
103
+ </p>
104
+ <button type="submit">Submit</button>
105
+ </form>
106
+ </fieldset>
107
+
108
+ <fieldset>
109
+ <legend>/registerUser</legend>
110
+ <form id="registerUserForm">
111
+ <div class="success"></div>
112
+ <div class="error"></div>
113
+ <p>
114
+ <input type="text" name="userId" placeholder="Specify userId..." required>
115
+ <button type="submit">Submit</button>
116
+ </p>
117
+ </form>
118
+ </fieldset>
119
+
120
+ <fieldset>
121
+ <legend>/registerEmail</legend>
122
+ <form id="registerEmailForm">
123
+ <div class="success"></div>
124
+ <div class="error"></div>
125
+ <p>
126
+ <input type="text" name="email" placeholder="Specify email..." required>
127
+ <button type="submit">Submit</button>
128
+ </p>
129
+ </form>
130
+ </fieldset>
131
+
132
+ <fieldset>
133
+ <legend>/setTags</legend>
134
+ <form id="setTagsForm">
135
+ <div class="success"></div>
136
+ <div class="error"></div>
137
+ <p>
138
+ <textarea
139
+ name="tags"
140
+ placeholder="Specify valid JSON..."
141
+ cols="30"
142
+ rows="10"
143
+ required
144
+ ></textarea>
145
+ </p>
146
+ <button type="submit">Submit</button>
147
+ </form>
148
+ </fieldset>
149
+
150
+ <script>
151
+ // On Load Event
152
+ Pushwoosh.push(['onLoad', function () {
153
+ console.log('Pushwoosh load!');
154
+ }]);
155
+
156
+ // Ready Event
157
+ Pushwoosh.push(function (api) {
158
+ console.log('Pushwoosh ready!');
159
+ });
160
+
161
+ // Subscribe Event
162
+ Pushwoosh.push(['onLoad', function (api) {
163
+ Pushwoosh.addEventHandler('subscribe', function (payload) {
164
+ console.log('Triggered event: subscribe');
165
+ });
166
+ }]);
167
+
168
+ // Unsubscribe Event
169
+ Pushwoosh.push(['onLoad', function (api) {
170
+ Pushwoosh.addEventHandler('unsubscribe', function (payload) {
171
+ console.log('Triggered event: unsubscribe');
172
+ });
173
+ }]);
174
+
175
+ // Subscription Widget Events
176
+ Pushwoosh.push(['onLoad', function (api) {
177
+ Pushwoosh.addEventHandler('show-subscription-widget', function (payload) {
178
+ console.log('Triggered event: show-subscription-widget');
179
+ });
180
+
181
+ Pushwoosh.addEventHandler('hide-subscription-widget', function (payload) {
182
+ console.log('Triggered event: hide-subscription-widget');
183
+ });
184
+ }]);
185
+
186
+ // Notification Permission Dialog Events
187
+ Pushwoosh.push(['onLoad', function (api) {
188
+ Pushwoosh.addEventHandler('show-notification-permission-dialog', function (payload) {
189
+ console.log('Triggered event: show-notification-permission-dialog');
190
+ });
191
+
192
+ Pushwoosh.addEventHandler('hide-notification-permission-dialog', function (payload) {
193
+ console.log('Triggered event: hide-notification-permission-dialog', payload.permission);
194
+ });
195
+ }]);
196
+
197
+ // Permission Events
198
+ Pushwoosh.push(['onLoad', function (api) {
199
+ Pushwoosh.addEventHandler('permission-default', function () {
200
+ console.log('Triggered event: permission-default');
201
+ });
202
+
203
+ Pushwoosh.addEventHandler('permission-denied', function () {
204
+ console.log('Triggered event: permission-denied');
205
+ });
206
+
207
+ Pushwoosh.addEventHandler('permission-granted', function () {
208
+ console.log('Triggered event: permission-granted');
209
+ });
210
+ }]);
211
+
212
+ // Receive Push Event
213
+ Pushwoosh.push(['onLoad', function (api) {
214
+ Pushwoosh.addEventHandler('receive-push', function (payload) {
215
+ console.log('Triggered event: receive-push', payload.notification);
216
+ });
217
+ }]);
218
+
219
+ // Notification Events
220
+ Pushwoosh.push(['onLoad', function (api) {
221
+ Pushwoosh.addEventHandler('open-notification', function (payload) {
222
+ console.log('Triggered event: open-notification', payload.notification);
223
+ });
224
+
225
+ Pushwoosh.addEventHandler('hide-notification', function (payload) {
226
+ console.log('Triggered event: hide-notification', payload.notification);
227
+ });
228
+ }]);
229
+
230
+ // In-Box Events
231
+ Pushwoosh.push(['onLoad', function (api) {
232
+ Pushwoosh.addEventHandler('receive-inbox-message', function (payload) {
233
+ console.log('Triggered event: receive-inbox-message', payload.message);
234
+ });
235
+
236
+ Pushwoosh.addEventHandler('update-inbox-messages', function (payload) {
237
+ console.log('Triggered event: receive-inbox-message', payload.messages);
238
+ });
239
+ }]);
240
+
241
+ Pushwoosh.push(function(api) {
242
+ console.log('EVENT: onReady', api);
243
+
244
+ Pushwoosh.isCommunicationEnabled().then(function(isEnabled) {
245
+ document.querySelector('#GDPRSetCommunicationEnabled').checked = isEnabled;
246
+ });
247
+
248
+ document.querySelector('#GDPRSetCommunicationEnabled').addEventListener('click', function (event) {
249
+ event.preventDefault();
250
+ Pushwoosh.setCommunicationEnabled(event.target.checked);
251
+ }, false);
252
+
253
+ document.querySelector('#GDPRRemoveAllDeviceData').addEventListener('click', function() {
254
+ Pushwoosh.removeAllDeviceData();
255
+ });
256
+
257
+ checkSubscription();
258
+ });
259
+
260
+ Pushwoosh.push(['onChangeCommunicationEnabled', function(api, isEnabled) {
261
+ console.log('EVENT: onChangeCommunicationEnabled', isEnabled);
262
+ document.querySelector('#GDPRSetCommunicationEnabled').checked = isEnabled;
263
+ }]);
264
+
265
+ Pushwoosh.push(['onSubscribe', function(api) {
266
+ console.log('EVENT: onSubscribe', api);
267
+ checkSubscription();
268
+ }]);
269
+
270
+ Pushwoosh.push(['onUnsubscribe', function(api) {
271
+ console.log('EVENT: onUnsubscribe', api);
272
+ checkSubscription();
273
+ }]);
274
+
275
+ Pushwoosh.push(['onRegister', function(api) {
276
+ console.log('EVENT: onRegister', api);
277
+ checkSubscription();
278
+ }]);
279
+
280
+ Pushwoosh.push(['onPermissionPrompt', function(api) {
281
+ console.log('EVENT: onPermissionPrompt', api);
282
+ toggleNodesVisibility('.permission-status', 'prompt');
283
+ }]);
284
+
285
+ Pushwoosh.push(['onPermissionDenied', function(api) {
286
+ console.log('EVENT: onPermissionDenied', api);
287
+ toggleNodesVisibility('.permission-status', 'denied');
288
+ checkSubscription();
289
+ }]);
290
+
291
+ Pushwoosh.push(['onPermissionGranted', function(api) {
292
+ console.log('EVENT: onPermissionGranted', api);
293
+ toggleNodesVisibility('.permission-status', 'granted');
294
+ checkSubscription();
295
+ }]);
296
+
297
+ Pushwoosh.push(['onPushDelivery', function(api, params) {
298
+ console.log('EVENT: onPushDelivery', api, params);
299
+ }]);
300
+
301
+ Pushwoosh.push(['onNotificationClick', function(api, params) {
302
+ console.log('EVENT: onNotificationClick', api, params);
303
+ }]);
304
+
305
+ Pushwoosh.push(['onNotificationClose', function(api, params) {
306
+ console.log('EVENT: onNotificationClose', api, params);
307
+ }]);
308
+
309
+ Pushwoosh.push(['onSWInitError', function(api) {
310
+ console.log('EVENT: onSWInitError', api);
311
+ }]);
312
+
313
+ Pushwoosh.push(['onPutNewMessageToInboxStore', function(api, message) {
314
+ console.log('EVENT: onPutNewMessageToInboxStore', message);
315
+ }]);
316
+
317
+ Pushwoosh.push(['onUpdateInboxMessages', function(api, pwinbox) {
318
+ pwinbox.loadMessages().then(function(messages) {
319
+ console.log('EVENT: onUpdateInboxMessages', messages);
320
+ })
321
+ }]);
322
+
323
+ Pushwoosh.push(['onShowNotificationPermissionDialog', function(api) {
324
+ console.log('EVENT: onShowNotificationPermissionDialog');
325
+ }]);
326
+
327
+ Pushwoosh.push(['onShowSubscriptionWidget', function(api) {
328
+ console.log('EVENT: onShowSubscriptionWidget');
329
+ }]);
330
+
331
+ Pushwoosh.push(['onHideSubscriptionWidget', function(api) {
332
+ console.log('EVENT: onHideSubscriptionWidget');
333
+ }]);
334
+
335
+ Pushwoosh.push(['onHideNotificationPermissionDialog', function(api, permission) {
336
+ console.log('EVENT: onHideNotificationPermissionDialog', permission);
337
+ checkSubscription();
338
+ }]);
339
+
340
+ function checkSubscription() {
341
+ Pushwoosh.isSubscribed().then(function (res) {
342
+ toggleNodesVisibility('.subscription-status', res ? 'actionUnsubscribe' : 'actionSubscribe');
343
+ }).catch(function (err) {
344
+ console.error('Is subscribed error', err);
345
+ });
346
+
347
+ Pushwoosh.getParams().then(function (params) {
348
+ var table = document.querySelector('#deviceParams tbody');
349
+ table.innerHTML = '';
350
+ Object.keys(params).map(function(key) {
351
+ var row = '<tr><td>'+key+'</td><td><pre>'+JSON.stringify(params[key], null, 2) || ''+'</pre></td></tr>';
352
+ table.insertAdjacentHTML('beforeend', row);
353
+ });
354
+ });
355
+ }
356
+
357
+ function toggleNodesVisibility(selector, id) {
358
+ var nodes = document.querySelectorAll(selector);
359
+ [].forEach.call(nodes, function (el) {
360
+ el.style.display = el.id === id ? 'inline' : 'none';
361
+ });
362
+ }
363
+
364
+ function toggleNodesVisibility(selector, id) {
365
+ var nodes = document.querySelectorAll(selector);
366
+ [].forEach.call(nodes, function(el) {
367
+ el.style.display = el.id === id ? 'inline' : 'none';
368
+ });
369
+ }
370
+
371
+ document.querySelector('#registerUserForm').addEventListener('submit', function(e) {
372
+ e.preventDefault();
373
+ var form = this;
374
+ var button = form.querySelector('button');
375
+ var input = form.querySelector('[name="userId"]');
376
+ var successNode = form.querySelector('.success');
377
+ var errorNode = form.querySelector('.error');
378
+ var userId = input.value;
379
+ button.setAttribute('disabled', 'disabled');
380
+ Pushwoosh.api.registerUser(userId)
381
+ .then(function() {
382
+ input.value = '';
383
+ errorNode.innerHTML = '';
384
+ successNode.innerHTML = 'Data successfully submitted ' + new Date();
385
+ })
386
+ .catch(function(err) {
387
+ successNode.innerHTML = '';
388
+ console.error(err);
389
+ errorNode.innerHTML = 'Got some error on submit. Check console for details.';
390
+ })
391
+ .then(function() {
392
+ button.removeAttribute('disabled');
393
+ });
394
+ });
395
+
396
+ document.querySelector('#registerEmailForm').addEventListener('submit', function(e) {
397
+ e.preventDefault();
398
+ var form = this;
399
+ var button = form.querySelector('button');
400
+ var input = form.querySelector('[name="email"]');
401
+ var successNode = form.querySelector('.success');
402
+ var errorNode = form.querySelector('.error');
403
+ var email = input.value;
404
+ button.setAttribute('disabled', 'disabled');
405
+ Pushwoosh.api.registerEmail(email)
406
+ .then(function() {
407
+ input.value = '';
408
+ errorNode.innerHTML = '';
409
+ successNode.innerHTML = 'Data successfully submitted ' + new Date();
410
+ })
411
+ .catch(function(err) {
412
+ successNode.innerHTML = '';
413
+ console.error(err);
414
+ errorNode.innerHTML = 'Got some error on submit. Check console for details.';
415
+ })
416
+ .then(function() {
417
+ button.removeAttribute('disabled');
418
+ });
419
+ });
420
+
421
+ document.querySelector('#setTagsForm').addEventListener('submit', function(e) {
422
+ e.preventDefault();
423
+ var form = this;
424
+ var button = form.querySelector('button');
425
+ var input = form.querySelector('[name="tags"]');
426
+ var successNode = form.querySelector('.success');
427
+ var errorNode = form.querySelector('.error');
428
+ var tags = input.value;
429
+
430
+ try {
431
+ tags = JSON.parse(tags);
432
+ errorNode.innerHTML = '';
433
+ }
434
+ catch (err) {
435
+ successNode.innerHTML = '';
436
+ console.error(err);
437
+ errorNode.innerHTML = 'JSON.parse error. Expected object: {[k: string]: any}';
438
+ return;
439
+ }
440
+
441
+ button.setAttribute('disabled', 'disabled');
442
+ Pushwoosh.api.setTags(tags)
443
+ .then(function(res) {
444
+ var skipped = res && res.skipped || null;
445
+ if (!skipped || !skipped.length) {
446
+ input.value = '';
447
+ errorNode.innerHTML = '';
448
+ successNode.innerHTML = 'Data successfully submitted ' + new Date();
449
+ } else {
450
+ successNode.innerHTML = '';
451
+ errorNode.innerHTML = skipped.map(function(item) {
452
+ return 'Skipped tag "' + item.tag + '", reason "' + item.reason + '".';
453
+ }).join('n\ ');
454
+ }
455
+ })
456
+ .catch(function(err) {
457
+ console.error(err);
458
+ successNode.innerHTML = '';
459
+ errorNode.innerHTML = 'Got some error on submit. Check console for details.';
460
+ })
461
+ .then(function() {
462
+ button.removeAttribute('disabled');
463
+ });
464
+ });
465
+
466
+ document.querySelector('#postEventForm').addEventListener('submit', function(e) {
467
+ e.preventDefault();
468
+ var form = this;
469
+ var button = form.querySelector('button');
470
+ var eventControl = form.querySelector('[name="event"]');
471
+ var attributesControl = form.querySelector('[name="attributes"]');
472
+ var successNode = form.querySelector('.success');
473
+ var errorNode = form.querySelector('.error');
474
+ var attributes = attributesControl.value;
475
+ var event = eventControl.value;
476
+
477
+ successNode.innerHTML = '';
478
+ errorNode.innerHTML = '';
479
+
480
+ if (!event) {
481
+ errorNode.innerHTML += 'Event name is required.';
482
+ return;
483
+ }
484
+
485
+ try {
486
+ attributes = JSON.parse(attributes);
487
+ }
488
+ catch (err) {
489
+ console.error(err);
490
+ errorNode.innerHTML = 'JSON.parse error. Expected object: {[k: string]: any}';
491
+ return;
492
+ }
493
+
494
+ button.setAttribute('disabled', 'disabled');
495
+
496
+ Pushwoosh.api.postEvent(event, attributes)
497
+ .then(function() {
498
+ successNode.innerHTML = 'Data successfully submitted ' + new Date();
499
+ })
500
+ .catch(function(err) {
501
+ errorNode.innerHTML += 'Got some error on submit. Check console for details.';
502
+ console.error(err);
503
+ })
504
+ .then(function() {
505
+ button.removeAttribute('disabled');
506
+ });
507
+ });
508
+ </script>
509
+ </div>
510
+ </body>
511
+ </html>
@@ -0,0 +1,114 @@
1
+ // @ts-check
2
+
3
+ import eslint from '@eslint/js';
4
+ import stylistic from '@stylistic/eslint-plugin';
5
+ import stylisticTs from '@stylistic/eslint-plugin-ts';
6
+ import importPlugin from 'eslint-plugin-import';
7
+ import tseslint from 'typescript-eslint';
8
+
9
+ export default tseslint.config(
10
+ eslint.configs.recommended,
11
+ importPlugin.flatConfigs.recommended,
12
+ ...tseslint.configs.recommended,
13
+ stylistic.configs.customize({
14
+ indent: 2,
15
+ quotes: 'single',
16
+ semi: true,
17
+ jsx: true,
18
+ braceStyle: '1tbs',
19
+ blockSpacing: true,
20
+ quoteProps: 'as-needed',
21
+ commaDangle: 'always-multiline',
22
+ arrowParens: 'always',
23
+ }),
24
+ {
25
+ plugins: {
26
+ // '@stylistic': stylistic.configs.customize(),
27
+ '@stylistic/ts': stylisticTs,
28
+ },
29
+ rules: {
30
+ 'max-len': [
31
+ 'error',
32
+ {
33
+ code: 160,
34
+ tabWidth: 2,
35
+ ignoreUrls: true,
36
+ ignoreComments: true,
37
+ ignoreStrings: true,
38
+ ignoreTemplateLiterals: true,
39
+ ignoreRegExpLiterals: true,
40
+ },
41
+ ],
42
+ '@stylistic/no-mixed-operators': 'off',
43
+ '@stylistic/multiline-ternary': 'off',
44
+ '@stylistic/ts/member-delimiter-style': [
45
+ 'error',
46
+ {
47
+ multiline: {
48
+ delimiter: 'semi',
49
+ requireLast: true,
50
+ },
51
+ singleline: {
52
+ delimiter: 'semi',
53
+ requireLast: false,
54
+ },
55
+ },
56
+ ],
57
+ '@typescript-eslint/ban-ts-comment': 'off',
58
+ '@typescript-eslint/consistent-type-imports': ['error', {
59
+ prefer: 'type-imports',
60
+ disallowTypeAnnotations: true,
61
+ fixStyle: 'inline-type-imports',
62
+ }],
63
+ '@typescript-eslint/no-explicit-any': 'off',
64
+ '@typescript-eslint/no-unused-vars': [
65
+ 'error',
66
+ {
67
+ argsIgnorePattern: '^_',
68
+ caughtErrorsIgnorePattern: '^_',
69
+ destructuredArrayIgnorePattern: '^_',
70
+ varsIgnorePattern: '^_',
71
+ },
72
+ ],
73
+ 'import/no-named-as-default': 'off',
74
+ 'import/no-unresolved': 'off',
75
+ 'import/order': [
76
+ 'error',
77
+ {
78
+ groups: [
79
+ 'builtin',
80
+ 'external',
81
+ 'internal',
82
+ ['parent', 'sibling'],
83
+ 'index',
84
+ ],
85
+ pathGroups: [
86
+ {
87
+ pattern: '@*',
88
+ group: 'external',
89
+ position: 'after',
90
+ },
91
+ {
92
+ pattern: '@pushwoosh/**',
93
+ group: 'external',
94
+ position: 'after',
95
+ },
96
+ {
97
+ pattern: '~/**',
98
+ group: 'internal',
99
+ position: 'after',
100
+ },
101
+ ],
102
+ pathGroupsExcludedImportTypes: ['builtin'],
103
+ 'newlines-between': 'always',
104
+ alphabetize: {
105
+ order: 'asc',
106
+ caseInsensitive: true,
107
+ },
108
+ },
109
+ ],
110
+ 'no-nested-ternary': 'error',
111
+ 'no-console': 'off',
112
+ },
113
+ },
114
+ );
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "web-push-notifications",
3
- "version": "3.40.1",
3
+ "version": "3.44.1",
4
4
  "description": "Pushwoosh web push notifications",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
5
+ "main": "npm.js",
6
+ "types": "npm.d.ts",
7
7
  "scripts": {
8
8
  "build": "webpack",
9
9
  "build:prod": "cross-env NODE_ENV=production webpack",
10
10
  "zip": "node scripts/zip.js",
11
11
  "release": "npm run build:prod && npm run zip",
12
- "start": "cross-env NODE_ENV=development webpack-dev-server --config-name dist --history-api-fallback",
12
+ "start": "cross-env NODE_ENV=development webpack-dev-server --config-name cdn --history-api-fallback",
13
13
  "check:types": "echo \"Run check:types\" && tsc --project tsconfig.json --skipLibCheck --emitDeclarationOnly false --noEmit",
14
14
  "check:lint": "echo \"Run check:lint\" && eslint ./src",
15
15
  "lint:fix": "echo \"Run lint:fix\" && eslint --fix ./src"
@@ -18,9 +18,6 @@
18
18
  "type": "git",
19
19
  "url": "git+https://github.com/Pushwoosh/web-push-notifications.git"
20
20
  },
21
- "files": [
22
- "lib"
23
- ],
24
21
  "keywords": [
25
22
  "pushwoosh",
26
23
  "web",
@@ -42,7 +39,6 @@
42
39
  "@types/eslint__js": "^8.42.3",
43
40
  "@types/node": "^22.14.1",
44
41
  "archiver": "^7.0.1",
45
- "autoprefixer": "^10.4.21",
46
42
  "babel-loader": "^10.0.0",
47
43
  "clean-webpack-plugin": "^4.0.0",
48
44
  "cross-env": "^7.0.3",
@@ -50,7 +46,6 @@
50
46
  "eslint": "^9.26.0",
51
47
  "eslint-plugin-import": "^2.31.0",
52
48
  "html-webpack-plugin": "^5.6.3",
53
- "postcss-loader": "^8.1.1",
54
49
  "raw-loader": "^4.0.2",
55
50
  "terser-webpack-plugin": "^5.3.14",
56
51
  "ts-loader": "^9.5.2",
@@ -61,30 +56,5 @@
61
56
  "webpack-cli": "^6.0.1",
62
57
  "webpack-dev-server": "^5.2.1",
63
58
  "webpack-merge": "^6.0.1"
64
- },
65
- "nyc": {
66
- "extension": [
67
- ".ts"
68
- ],
69
- "exclude": [
70
- "**/*.d.ts",
71
- "**/coverage/**",
72
- "**/test/**",
73
- "**/config/**",
74
- "**/assets/**",
75
- "testRegister.js",
76
- "webpack.config.js",
77
- "webpack.lib.config.js",
78
- "dist/**",
79
- "lib/",
80
- "develop/",
81
- "scripts/",
82
- "ci/",
83
- "node_modules/"
84
- ],
85
- "reporter": [
86
- "html"
87
- ],
88
- "all": true
89
59
  }
90
60
  }