u-wave-announce 0.5.3 → 0.6.0-alpha.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.
package/package.json CHANGED
@@ -1,24 +1,25 @@
1
1
  {
2
2
  "name": "u-wave-announce",
3
3
  "description": "Announce your üWave server's existence to the world.",
4
- "version": "0.5.3",
4
+ "version": "0.6.0-alpha.2",
5
5
  "author": "Renée Kooi <renee@kooi.me>",
6
+ "type": "module",
6
7
  "dependencies": {
7
- "debug": "^4.3.2",
8
- "libsodium-wrappers": "^0.7.8",
9
- "node-fetch": "^2.6.0",
10
- "strip-indent": "^3.0.0"
8
+ "libsodium-wrappers": "^0.8.0",
9
+ "node-fetch": "^3.3.1",
10
+ "strip-indent": "^4.0.0"
11
11
  },
12
12
  "engines": {
13
- "node": ">= 12"
13
+ "node": ">= 24"
14
14
  },
15
15
  "license": "MIT",
16
16
  "main": "./src/plugin.js",
17
+ "exports": {
18
+ ".": "./src/plugin.js",
19
+ "./package.json": "./package.json"
20
+ },
17
21
  "repository": {
18
22
  "git": "https://github.com/u-wave/hub.git",
19
23
  "directory": "plugin"
20
- },
21
- "scripts": {
22
- "test": "node test"
23
24
  }
24
25
  }
package/src/plugin.js CHANGED
@@ -1,22 +1,8 @@
1
- 'use strict';
2
-
3
- const { promisify } = require('util');
4
- const randomBytes = promisify(require('crypto').randomBytes);
5
- const fetch = require('node-fetch');
6
- const stripIndent = require('strip-indent');
7
- const debug = require('debug')('uwave:announce');
8
- const sodium = require('./signatures');
9
- const pkg = require('../package.json');
10
-
11
- /**
12
- * Fallback logger implementation for üWave Core versions that do
13
- * not come with a logger yet.
14
- */
15
- const debugLogger = {
16
- debug,
17
- info: debug,
18
- error: debug,
19
- };
1
+ import { randomBytes } from 'node:crypto';
2
+ import fetch from 'node-fetch';
3
+ import stripIndent from 'strip-indent';
4
+ import pkg from '../package.json' with { type: 'json' };
5
+ import * as sodium from './signatures.js';
20
6
 
21
7
  const optionsSchema = {
22
8
  type: 'object',
@@ -103,28 +89,14 @@ function stripSlashes(url) {
103
89
  async function getAnnounceData(uw, options) {
104
90
  const url = stripSlashes(options.url);
105
91
 
106
- // TODO add something to üWave Core so we don't have to manually populate
107
- // the relationships.
108
92
  const entry = await uw.booth.getCurrentEntry();
109
- if (entry) {
110
- if (entry.execPopulate) {
111
- entry.populate('user media.media');
112
- await entry.execPopulate();
113
- } else {
114
- await entry.populate('user media.media');
115
- }
116
- }
117
93
 
118
94
  // TODO add something to üWave Core so we don't have to manually ask Redis for
119
95
  // this information. Currently üWave Core may register duplicates in this
120
96
  // list, too, which is a bit annoying!
121
97
  // TODO add guest users here too.
122
98
  const onlineUserIDs = await uw.redis.lrange('users', 0, -1);
123
- const onlineUsersMap = {};
124
- onlineUserIDs.forEach((id) => {
125
- onlineUsersMap[id] = true;
126
- });
127
- const usersCount = Object.keys(onlineUsersMap).length;
99
+ const usersCount = new Set(onlineUserIDs).size;
128
100
 
129
101
  return {
130
102
  name: options.name,
@@ -154,7 +126,7 @@ async function getAnnounceData(uw, options) {
154
126
  async function getOrGenerateSeed(uw) {
155
127
  const options = await uw.config.get(optionsSchema['uw:key']);
156
128
  if (!options.seed) {
157
- options.seed = (await randomBytes(32)).toString('hex');
129
+ options.seed = randomBytes(32).toString('hex');
158
130
  await uw.config.set(optionsSchema['uw:key'], options);
159
131
  }
160
132
  return Buffer.from(options.seed, 'hex');
@@ -163,10 +135,7 @@ async function getOrGenerateSeed(uw) {
163
135
  async function announcePlugin(uw, staticOptions) {
164
136
  uw.config.register(optionsSchema['uw:key'], optionsSchema);
165
137
 
166
- // üWave Core 0.5.0 and up have a `pino` logger
167
- const logger = uw.logger
168
- ? uw.logger.child({ ns: 'uwave:announce' })
169
- : debugLogger;
138
+ const logger = uw.logger.child({ ns: 'uwave:announce' });
170
139
 
171
140
  const seed = staticOptions.seed || await getOrGenerateSeed(uw);
172
141
  // This takes up to a few 100 ms but it is a one-time startup cost…
@@ -233,4 +202,4 @@ async function announcePlugin(uw, staticOptions) {
233
202
  });
234
203
  }
235
204
 
236
- module.exports = announcePlugin;
205
+ export default announcePlugin;
package/src/signatures.js CHANGED
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
1
  // Based on https://github.com/mafintosh/sodium-signatures/blob/master/index.js
4
- const sodium = require('libsodium-wrappers');
2
+ import sodium from 'libsodium-wrappers';
5
3
 
6
- async function keyPair(seed) {
4
+ export async function keyPair(seed) {
7
5
  await sodium.ready;
8
6
 
9
7
  const { publicKey, privateKey } = seed
@@ -16,18 +14,12 @@ async function keyPair(seed) {
16
14
  return { publicKey, secretKey };
17
15
  }
18
16
 
19
- async function sign(message, secretKey) {
17
+ export async function sign(message, secretKey) {
20
18
  await sodium.ready;
21
19
  return sodium.crypto_sign_detached(message, secretKey);
22
20
  }
23
21
 
24
- async function verify(message, signature, publicKey) {
22
+ export async function verify(message, signature, publicKey) {
25
23
  await sodium.ready;
26
24
  return sodium.crypto_sign_verify_detached(signature, message, publicKey);
27
25
  }
28
-
29
- module.exports = {
30
- keyPair,
31
- sign,
32
- verify,
33
- };
package/test.js CHANGED
@@ -1,9 +1,5 @@
1
- 'use strict';
1
+ import assert from 'node:assert';
2
+ import plugin from './src/plugin.js';
2
3
 
3
- const assert = require('assert');
4
-
5
- assert.doesNotThrow(() => {
6
- // Just to make sure it does not crash :)
7
- // eslint-disable-next-line global-require
8
- require('./src/plugin');
9
- });
4
+ // Just to make sure it does not crash :)
5
+ assert.ok(plugin);