Skip to content

Commit c239289

Browse files
jdufresneauvipy
andauthored
Require Node.js 18 and use crypto.randomUUID() (#317)
* Require Node.js 18 and use crypto.randomUUID() * Potential fix for pull request finding * Update nvmrc and package-lock.json --------- Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <auvipy@gmail.com>
1 parent 5d0b01d commit c239289

6 files changed

Lines changed: 7 additions & 37 deletions

File tree

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lts/erbium
1+
lts/hydrogen

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This means you cannot use the same SockJS server installed at multiple prefixes.
66
In practice this was confusing and not common.
77
* `websocket` option is deprecated, but still respected. Please use the new `transports` option.
8-
* Node.js `>= 6.5.0` is required.
8+
* Node.js `>= 18.0.0` is required.
99

1010
## Other Fixes/Changes
1111
* Convert from coffeescript to ES6.
@@ -19,7 +19,7 @@
1919
* Added `detach(server)` function to remove SockJS from a HTTP server instance.
2020
* Update dependencies.
2121
* Examples have been updated to use latest versions of libraries.
22-
22+
* Remove the internal UUID helper and use Node.js `crypto.randomUUID()` directly.
2323

2424
0.3.19
2525
======

lib/sockjs-connection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

3+
const crypto = require('crypto');
34
const debug = require('debug')('sockjs:connection');
45
const stream = require('stream');
5-
const { uuid } = require('./utils');
66

77
class SockJSConnection extends stream.Duplex {
88
constructor(session) {
99
super({ decodeStrings: false, encoding: 'utf8', readableObjectMode: true });
1010
this._session = session;
11-
this.id = uuid();
11+
this.id = crypto.randomUUID();
1212
this.headers = {};
1313
this.prefix = this._session.prefix;
1414
debug('new connection', this.id, this.prefix);

lib/utils.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,6 @@
22
const crypto = require('crypto');
33
const http = require('http');
44

5-
module.exports.uuid = function uuid() {
6-
// only available on Node v16.7+
7-
if (typeof crypto.randomUUID === 'function') {
8-
return crypto.randomUUID();
9-
}
10-
11-
const bytes = crypto.randomBytes(16);
12-
13-
// Per RFC 4122 §4.4:
14-
// Set version to 4 => xxxx -> 0100
15-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
16-
17-
// Set variant to RFC 4122 => 10xxxxxx
18-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
19-
20-
const hex = bytes.toString('hex');
21-
22-
return (
23-
hex.slice(0, 8) +
24-
'-' +
25-
hex.slice(8, 12) +
26-
'-' +
27-
hex.slice(12, 16) +
28-
'-' +
29-
hex.slice(16, 20) +
30-
'-' +
31-
hex.slice(20)
32-
);
33-
};
34-
355
// used in case of 'upgrade' requests where res is
366
// net.Socket instead of http.ServerResponse
377
module.exports.fake_response = function fake_response(req, res) {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
"postpublish": "git push origin --all && git push origin --tags"
4646
},
4747
"engines": {
48-
"node": ">=6.5.0"
48+
"node": ">=18.0.0"
4949
}
5050
}

0 commit comments

Comments
 (0)