nodebb-plugin-web-push 0.7.7 → 0.7.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.
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const user = require.main.require('./src/user');
3
+ const user = nodebb.require('./src/user');
4
+ const helpers = nodebb.require('./src/controllers/helpers');
4
5
 
5
6
  const subscriptions = require('./subscriptions');
6
7
 
7
- const helpers = require.main.require('./src/controllers/helpers');
8
-
9
8
  const Controllers = module.exports;
10
9
 
11
10
  Controllers.renderSettings = async function (req, res) {
@@ -21,7 +20,10 @@ Controllers.renderSettings = async function (req, res) {
21
20
  const payload = {
22
21
  ...res.locals.userData,
23
22
  title: '[[web-push:profile.label]]',
24
- breadcrumbs: helpers.buildBreadcrumbs([{ text: username, url: `/user/${userslug}` }, { text: '[[web-push:profile.label]]' }]),
23
+ breadcrumbs: helpers.buildBreadcrumbs([
24
+ { text: username, url: `/user/${userslug}` },
25
+ { text: '[[web-push:profile.label]]' },
26
+ ]),
25
27
  count,
26
28
  };
27
29
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const db = require.main.require('./src/database');
3
+ const db = nodebb.require('./src/database');
4
4
 
5
5
  const Subscriptions = module.exports;
6
6
 
package/library.js CHANGED
@@ -1,23 +1,24 @@
1
1
  'use strict';
2
2
 
3
- const nconf = require.main.require('nconf');
4
- const winston = require.main.require('winston');
5
3
  const webPush = require('web-push');
6
4
  const validator = require('validator');
7
5
 
8
- const db = require.main.require('./src/database');
9
- const user = require.main.require('./src/user');
10
- const meta = require.main.require('./src/meta');
11
- const utils = require.main.require('./src/utils');
12
- const translator = require.main.require('./src/translator');
13
- const notifications = require.main.require('./src/notifications');
6
+ const nconf = nodebb.require('nconf');
7
+ const winston = nodebb.require('winston');
8
+
9
+ const db = nodebb.require('./src/database');
10
+ const user = nodebb.require('./src/user');
11
+ const meta = nodebb.require('./src/meta');
12
+ const utils = nodebb.require('./src/utils');
13
+ const translator = nodebb.require('./src/translator');
14
+ const notifications = nodebb.require('./src/notifications');
15
+
16
+ const routeHelpers = nodebb.require('./src/routes/helpers');
14
17
 
15
18
  const controllers = require('./lib/controllers');
16
19
  const subscriptions = require('./lib/subscriptions');
17
20
 
18
- const routeHelpers = require.main.require('./src/routes/helpers');
19
-
20
- const plugin = {};
21
+ const plugin = module.exports;
21
22
 
22
23
  plugin.init = async (params) => {
23
24
  const { router, middleware/* , controllers */ } = params;
@@ -104,7 +105,8 @@ plugin.addRoutes = async ({ router, middleware, helpers }) => {
104
105
  const payload = await constructPayload({
105
106
  nid: utils.generateUUID(),
106
107
  bodyShort: 'Test notification',
107
- bodyLong: 'This is a test message sent from NodeBB',
108
+ // test notification shouln't show any html chars
109
+ bodyLong: 'This is a &lt;bdi&gt;test&lt;/bid&gt; message sent from <strong>NodeBB</strong>',
108
110
  path: `/me/web-push`,
109
111
  }, req.uid, userLang);
110
112
  await webPush.sendNotification(subscription, JSON.stringify(payload));
@@ -217,7 +219,7 @@ async function constructPayload(notification, uid, lang) {
217
219
  const { nid, mergeId, bodyShort, bodyLong, path } = notification;
218
220
 
219
221
  let [title, body] = await translator.translateKeys([bodyShort, bodyLong], lang);
220
- ([title, body] = [title, body].map(str => validator.unescape(utils.stripHTMLTags(str))));
222
+ ([title, body] = [title, body].map(str => utils.stripHTMLTags(utils.decodeHTMLEntities(str))));
221
223
  title = `${dir === 'rtl' ? '\u200f' : '\u200e'}${title}`;
222
224
  const tag = mergeId || nid;
223
225
  const url = `${nconf.get('url')}${path}`;
@@ -247,5 +249,3 @@ async function constructPayload(notification, uid, lang) {
247
249
  data: { url, icon, badge },
248
250
  };
249
251
  }
250
-
251
- module.exports = plugin;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nodebb-plugin-web-push",
3
- "version": "0.7.7",
4
- "description": "A starter kit for quickly creating NodeBB plugins",
3
+ "version": "0.7.9",
4
+ "description": "A plugin for adding native push notifications to NodeBB via the Web Push API.",
5
5
  "main": "library.js",
6
6
  "repository": {
7
7
  "type": "git",
@@ -35,16 +35,15 @@
35
35
  },
36
36
  "readmeFilename": "README.md",
37
37
  "nbbpm": {
38
- "compatibility": "^4.0.0"
38
+ "compatibility": "^4.12.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@commitlint/cli": "20.4.3",
42
- "@commitlint/config-angular": "20.4.3",
43
- "eslint": "^10.0.0",
44
- "eslint-config-nodebb": "^2.0.0",
45
- "eslint-plugin-import": "^2.31.0",
41
+ "@commitlint/cli": "21.0.2",
42
+ "@commitlint/config-angular": "21.0.2",
43
+ "@eslint/js": "^10.0.1",
44
+ "eslint-config-nodebb": "^2.0.2",
46
45
  "husky": "9.1.7",
47
- "lint-staged": "16.3.2"
46
+ "lint-staged": "17.0.8"
48
47
  },
49
48
  "dependencies": {
50
49
  "validator": "^13.12.0",
@@ -83,15 +83,15 @@ export async function init() {
83
83
  // as value for applicationServerKey in pushManager.subscribe yet
84
84
  // https://bugs.chromium.org/p/chromium/issues/detail?id=802280
85
85
  function urlBase64ToUint8Array(base64String) {
86
- var padding = '='.repeat((4 - (base64String.length % 4)) % 4);
87
- var base64 = (base64String + padding)
86
+ const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
87
+ const base64 = (base64String + padding)
88
88
  .replace(/-/g, '+')
89
89
  .replace(/_/g, '/');
90
90
 
91
- var rawData = window.atob(base64);
92
- var outputArray = new Uint8Array(rawData.length);
91
+ const rawData = window.atob(base64);
92
+ const outputArray = new Uint8Array(rawData.length);
93
93
 
94
- for (var i = 0; i < rawData.length; ++i) {
94
+ for (let i = 0; i < rawData.length; ++i) {
95
95
  outputArray[i] = rawData.charCodeAt(i);
96
96
  }
97
97
  return outputArray;
package/test/index.js CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  const assert = require('assert');
22
22
 
23
- const db = require.main.require('./test/mocks/databasemock');
23
+ const db = nodebb.require('./test/mocks/databasemock');
24
24
 
25
25
  describe('nodebb-plugin-web-push', () => {
26
26
  before(() => {