Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to validate and other package updates #311

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Cryptiles = require('@hapi/cryptiles');
const Hoek = require('@hapi/hoek');
const Iron = require('@hapi/iron');
const Joi = require('@hapi/joi');
const Validate = require('@hapi/validate');
const Ws = require('ws');

const Client = require('./client');
Expand Down Expand Up @@ -38,53 +38,53 @@ const internals = {
};


internals.schema = Joi.object({
onConnection: Joi.function(), // async function (socket) {}
onDisconnection: Joi.function(), // function (socket) {}
onMessage: Joi.function(), // async function (socket, message) { return data; } // Or throw errors
auth: Joi.object({
endpoint: Joi.string().required(),
id: Joi.string(),
type: Joi.valid('cookie', 'token', 'direct').required(),
internals.schema = Validate.object({
onConnection: Validate.function(), // async function (socket) {}
onDisconnection: Validate.function(), // function (socket) {}
onMessage: Validate.function(), // async function (socket, message) { return data; } // Or throw errors
auth: Validate.object({
endpoint: Validate.string().required(),
id: Validate.string(),
type: Validate.valid('cookie', 'token', 'direct').required(),
route: [
Joi.object(),
Joi.string()
Validate.object(),
Validate.string()
],
cookie: Joi.string().required(),
isSecure: Joi.boolean(),
isHttpOnly: Joi.boolean(),
isSameSite: Joi.valid('Strict', 'Lax').allow(false),
path: Joi.string().allow(null),
domain: Joi.string().allow(null),
ttl: Joi.number().allow(null),
iron: Joi.object(),
password: Joi.alternatives([
Joi.string(),
Joi.binary(),
Joi.object()
cookie: Validate.string().required(),
isSecure: Validate.boolean(),
isHttpOnly: Validate.boolean(),
isSameSite: Validate.valid('Strict', 'Lax').allow(false),
path: Validate.string().allow(null),
domain: Validate.string().allow(null),
ttl: Validate.number().allow(null),
iron: Validate.object(),
password: Validate.alternatives([
Validate.string(),
Validate.binary(),
Validate.object()
]),
index: Joi.boolean(),
timeout: Joi.number().integer().min(1).allow(false),
maxConnectionsPerUser: Joi.number().integer().min(1).allow(false).when('index', { is: true, otherwise: Joi.valid(false) }),
minAuthVerifyInterval: Joi.number().integer().allow(false).when('...heartbeat', {
index: Validate.boolean(),
timeout: Validate.number().integer().min(1).allow(false),
maxConnectionsPerUser: Validate.number().integer().min(1).allow(false).when('index', { is: true, otherwise: Validate.valid(false) }),
minAuthVerifyInterval: Validate.number().integer().allow(false).when('...heartbeat', {
is: false,
then: Joi.number().min(1),
otherwise: Joi.number().min(Joi.ref('...heartbeat.interval'))
then: Validate.number().min(1),
otherwise: Validate.number().min(Validate.ref('...heartbeat.interval'))
})
})
.allow(false)
.required(),
headers: Joi.array().items(Joi.string().lowercase()).min(1).allow('*', null),
headers: Validate.array().items(Validate.string().lowercase()).min(1).allow('*', null),
payload: {
maxChunkChars: Joi.number().integer().min(1).allow(false)
maxChunkChars: Validate.number().integer().min(1).allow(false)
},
heartbeat: Joi.object({
interval: Joi.number().integer().min(1).required(),
timeout: Joi.number().integer().min(1).less(Joi.ref('interval')).required()
heartbeat: Validate.object({
interval: Validate.number().integer().min(1).required(),
timeout: Validate.number().integer().min(1).less(Validate.ref('interval')).required()
})
.allow(false),
maxConnections: Joi.number().integer().min(1).allow(false),
origin: Joi.array().items(Joi.string()).single().min(1)
maxConnections: Validate.number().integer().min(1).allow(false),
origin: Validate.array().items(Validate.string()).single().min(1)
});


Expand All @@ -107,7 +107,7 @@ exports.plugin = {
settings.auth.minAuthVerifyInterval = (settings.heartbeat ? settings.heartbeat.interval : internals.defaults.heartbeat.interval);
}

Joi.assert(settings, internals.schema, 'Invalid nes configuration');
Validate.assert(settings, internals.schema, 'Invalid nes configuration');

// Authentication endpoint

Expand Down
22 changes: 11 additions & 11 deletions lib/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Boom = require('@hapi/boom');
const Bounce = require('@hapi/bounce');
const Call = require('@hapi/call');
const Hoek = require('@hapi/hoek');
const Joi = require('@hapi/joi');
const Validate = require('@hapi/validate');
const Ws = require('ws');

const Socket = require('./socket');
Expand Down Expand Up @@ -199,15 +199,15 @@ internals.Listener.prototype._broadcast = function (update, options) {
};


internals.subSchema = Joi.object({
filter: Joi.func(), // async function (path, update, options), where options: { credentials, params }, returns true, false, { override }, or throws an error
onSubscribe: Joi.func(), // async function (socket, path, params)
onUnsubscribe: Joi.func(), // async function (socket, path, params)
auth: Joi.object({
mode: Joi.string().valid('required', 'optional'),
scope: Joi.array().items(Joi.string()).single().min(1),
entity: Joi.valid('user', 'app', 'any'),
index: Joi.boolean()
internals.subSchema = Validate.object({
filter: Validate.func(), // async function (path, update, options), where options: { credentials, params }, returns true, false, { override }, or throws an error
onSubscribe: Validate.func(), // async function (socket, path, params)
onUnsubscribe: Validate.func(), // async function (socket, path, params)
auth: Validate.object({
mode: Validate.string().valid('required', 'optional'),
scope: Validate.array().items(Validate.string()).single().min(1),
entity: Validate.valid('user', 'app', 'any'),
index: Validate.boolean()
})
.allow(false)
});
Expand All @@ -216,7 +216,7 @@ internals.subSchema = Joi.object({
internals.Listener.subscription = function (path, options) {

Hoek.assert(path, 'Subscription missing path');
Joi.assert(options, internals.subSchema, 'Invalid subscription options: ' + path);
Validate.assert(options, internals.subSchema, 'Invalid subscription options: ' + path);

const settings = Hoek.clone(options || {});

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
"@hapi/cryptiles": "5.x.x",
"@hapi/hoek": "9.x.x",
"@hapi/iron": "6.x.x",
"@hapi/joi": "17.x.x",
"@hapi/teamwork": "4.x.x",
"ws": "6.x.x"
"@hapi/teamwork": "5.x.x",
"@hapi/validate": "1.x.x",
"ws": "^7.3.1"
},
"devDependencies": {
"@hapi/code": "8.x.x",
"@hapi/hapi": "19.x.x",
"@hapi/lab": "22.x.x"
"@hapi/lab": "23.x.x"
},
"scripts": {
"test": "lab -a @hapi/code -t 100 -L -m 10000",
Expand Down