@hapi/nes 12.0.2 → 12.0.5
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/lib/client.js +4 -0
- package/lib/index.js +37 -37
- package/lib/listener.js +11 -11
- package/lib/socket.js +2 -1
- package/package.json +16 -7
package/lib/client.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const Cryptiles = require('@hapi/cryptiles');
|
|
4
4
|
const Hoek = require('@hapi/hoek');
|
|
5
5
|
const Iron = require('@hapi/iron');
|
|
6
|
-
const
|
|
6
|
+
const Validate = require('@hapi/validate');
|
|
7
7
|
const Ws = require('ws');
|
|
8
8
|
|
|
9
9
|
const Client = require('./client');
|
|
@@ -38,53 +38,53 @@ const internals = {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
internals.schema =
|
|
42
|
-
onConnection:
|
|
43
|
-
onDisconnection:
|
|
44
|
-
onMessage:
|
|
45
|
-
auth:
|
|
46
|
-
endpoint:
|
|
47
|
-
id:
|
|
48
|
-
type:
|
|
41
|
+
internals.schema = Validate.object({
|
|
42
|
+
onConnection: Validate.function(), // async function (socket) {}
|
|
43
|
+
onDisconnection: Validate.function(), // function (socket) {}
|
|
44
|
+
onMessage: Validate.function(), // async function (socket, message) { return data; } // Or throw errors
|
|
45
|
+
auth: Validate.object({
|
|
46
|
+
endpoint: Validate.string().required(),
|
|
47
|
+
id: Validate.string(),
|
|
48
|
+
type: Validate.valid('cookie', 'token', 'direct').required(),
|
|
49
49
|
route: [
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
Validate.object(),
|
|
51
|
+
Validate.string()
|
|
52
52
|
],
|
|
53
|
-
cookie:
|
|
54
|
-
isSecure:
|
|
55
|
-
isHttpOnly:
|
|
56
|
-
isSameSite:
|
|
57
|
-
path:
|
|
58
|
-
domain:
|
|
59
|
-
ttl:
|
|
60
|
-
iron:
|
|
61
|
-
password:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
cookie: Validate.string().required(),
|
|
54
|
+
isSecure: Validate.boolean(),
|
|
55
|
+
isHttpOnly: Validate.boolean(),
|
|
56
|
+
isSameSite: Validate.valid('Strict', 'Lax').allow(false),
|
|
57
|
+
path: Validate.string().allow(null),
|
|
58
|
+
domain: Validate.string().allow(null),
|
|
59
|
+
ttl: Validate.number().allow(null),
|
|
60
|
+
iron: Validate.object(),
|
|
61
|
+
password: Validate.alternatives([
|
|
62
|
+
Validate.string(),
|
|
63
|
+
Validate.binary(),
|
|
64
|
+
Validate.object()
|
|
65
65
|
]),
|
|
66
|
-
index:
|
|
67
|
-
timeout:
|
|
68
|
-
maxConnectionsPerUser:
|
|
69
|
-
minAuthVerifyInterval:
|
|
66
|
+
index: Validate.boolean(),
|
|
67
|
+
timeout: Validate.number().integer().min(1).allow(false),
|
|
68
|
+
maxConnectionsPerUser: Validate.number().integer().min(1).allow(false).when('index', { is: true, otherwise: Validate.valid(false) }),
|
|
69
|
+
minAuthVerifyInterval: Validate.number().integer().allow(false).when('...heartbeat', {
|
|
70
70
|
is: false,
|
|
71
|
-
then:
|
|
72
|
-
otherwise:
|
|
71
|
+
then: Validate.number().min(1),
|
|
72
|
+
otherwise: Validate.number().min(Validate.ref('...heartbeat.interval'))
|
|
73
73
|
})
|
|
74
74
|
})
|
|
75
75
|
.allow(false)
|
|
76
76
|
.required(),
|
|
77
|
-
headers:
|
|
77
|
+
headers: Validate.array().items(Validate.string().lowercase()).min(1).allow('*', null),
|
|
78
78
|
payload: {
|
|
79
|
-
maxChunkChars:
|
|
79
|
+
maxChunkChars: Validate.number().integer().min(1).allow(false)
|
|
80
80
|
},
|
|
81
|
-
heartbeat:
|
|
82
|
-
interval:
|
|
83
|
-
timeout:
|
|
81
|
+
heartbeat: Validate.object({
|
|
82
|
+
interval: Validate.number().integer().min(1).required(),
|
|
83
|
+
timeout: Validate.number().integer().min(1).less(Validate.ref('interval')).required()
|
|
84
84
|
})
|
|
85
85
|
.allow(false),
|
|
86
|
-
maxConnections:
|
|
87
|
-
origin:
|
|
86
|
+
maxConnections: Validate.number().integer().min(1).allow(false),
|
|
87
|
+
origin: Validate.array().items(Validate.string()).single().min(1)
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
|
|
@@ -107,7 +107,7 @@ exports.plugin = {
|
|
|
107
107
|
settings.auth.minAuthVerifyInterval = (settings.heartbeat ? settings.heartbeat.interval : internals.defaults.heartbeat.interval);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
Validate.assert(settings, internals.schema, 'Invalid nes configuration');
|
|
111
111
|
|
|
112
112
|
// Authentication endpoint
|
|
113
113
|
|
package/lib/listener.js
CHANGED
|
@@ -4,7 +4,7 @@ const Boom = require('@hapi/boom');
|
|
|
4
4
|
const Bounce = require('@hapi/bounce');
|
|
5
5
|
const Call = require('@hapi/call');
|
|
6
6
|
const Hoek = require('@hapi/hoek');
|
|
7
|
-
const
|
|
7
|
+
const Validate = require('@hapi/validate');
|
|
8
8
|
const Ws = require('ws');
|
|
9
9
|
|
|
10
10
|
const Socket = require('./socket');
|
|
@@ -199,15 +199,15 @@ internals.Listener.prototype._broadcast = function (update, options) {
|
|
|
199
199
|
};
|
|
200
200
|
|
|
201
201
|
|
|
202
|
-
internals.subSchema =
|
|
203
|
-
filter:
|
|
204
|
-
onSubscribe:
|
|
205
|
-
onUnsubscribe:
|
|
206
|
-
auth:
|
|
207
|
-
mode:
|
|
208
|
-
scope:
|
|
209
|
-
entity:
|
|
210
|
-
index:
|
|
202
|
+
internals.subSchema = Validate.object({
|
|
203
|
+
filter: Validate.func(), // async function (path, update, options), where options: { credentials, params }, returns true, false, { override }, or throws an error
|
|
204
|
+
onSubscribe: Validate.func(), // async function (socket, path, params)
|
|
205
|
+
onUnsubscribe: Validate.func(), // async function (socket, path, params)
|
|
206
|
+
auth: Validate.object({
|
|
207
|
+
mode: Validate.string().valid('required', 'optional'),
|
|
208
|
+
scope: Validate.array().items(Validate.string()).single().min(1),
|
|
209
|
+
entity: Validate.valid('user', 'app', 'any'),
|
|
210
|
+
index: Validate.boolean()
|
|
211
211
|
})
|
|
212
212
|
.allow(false)
|
|
213
213
|
});
|
|
@@ -216,7 +216,7 @@ internals.subSchema = Joi.object({
|
|
|
216
216
|
internals.Listener.subscription = function (path, options) {
|
|
217
217
|
|
|
218
218
|
Hoek.assert(path, 'Subscription missing path');
|
|
219
|
-
|
|
219
|
+
Validate.assert(options, internals.subSchema, 'Invalid subscription options: ' + path);
|
|
220
220
|
|
|
221
221
|
const settings = Hoek.clone(options || {});
|
|
222
222
|
|
package/lib/socket.js
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hapi/nes",
|
|
3
3
|
"description": "WebSocket adapter plugin for hapi routes",
|
|
4
|
-
"version": "12.0.
|
|
4
|
+
"version": "12.0.5",
|
|
5
5
|
"repository": "git://github.com/hapijs/nes",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=12.0.0"
|
|
8
|
+
},
|
|
6
9
|
"main": "lib/index.js",
|
|
7
10
|
"files": [
|
|
8
11
|
"lib"
|
|
@@ -12,21 +15,27 @@
|
|
|
12
15
|
"plugin",
|
|
13
16
|
"websocket"
|
|
14
17
|
],
|
|
18
|
+
"eslintConfig": {
|
|
19
|
+
"extends": [
|
|
20
|
+
"plugin:@hapi/module"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
15
23
|
"dependencies": {
|
|
16
24
|
"@hapi/boom": "9.x.x",
|
|
17
25
|
"@hapi/bounce": "2.x.x",
|
|
18
|
-
"@hapi/call": "
|
|
26
|
+
"@hapi/call": "8.x.x",
|
|
19
27
|
"@hapi/cryptiles": "5.x.x",
|
|
20
28
|
"@hapi/hoek": "9.x.x",
|
|
21
29
|
"@hapi/iron": "6.x.x",
|
|
22
|
-
"@hapi/
|
|
23
|
-
"@hapi/
|
|
24
|
-
"ws": "
|
|
30
|
+
"@hapi/teamwork": "5.x.x",
|
|
31
|
+
"@hapi/validate": "1.x.x",
|
|
32
|
+
"ws": "^7.3.1"
|
|
25
33
|
},
|
|
26
34
|
"devDependencies": {
|
|
27
35
|
"@hapi/code": "8.x.x",
|
|
28
|
-
"@hapi/
|
|
29
|
-
"@hapi/
|
|
36
|
+
"@hapi/eslint-plugin": "^5.0.0",
|
|
37
|
+
"@hapi/hapi": "20.x.x",
|
|
38
|
+
"@hapi/lab": "24.x.x"
|
|
30
39
|
},
|
|
31
40
|
"scripts": {
|
|
32
41
|
"test": "lab -a @hapi/code -t 100 -L -m 10000",
|