Skip to content

Commit

Permalink
Update dependencies and adapt code
Browse files Browse the repository at this point in the history
Summary of relevant changes

@hapi/joi v16
- Changes in allow() and valid()
  No longer accepts array arguments. Must pass each value as a separate argument.
  See hapijs/joi#2037
- Change error in sync validate() result to undefined instead of null when there is no error
  See hapijs/joi#2036
  See hapijs/joi#2037

@hapi/hapi v19
  - No joi schema compiler is loaded by default and must be explicitly
  loaded using server.validator()
  See hapijs/hapi#4017
  See https://hapi.dev/api/?v=19.1.0#-servervalidatorvalidator

@hapi/boom v8
  - Change new Boom() to new Boom.Boom()
  See hapijs/boom#253
  • Loading branch information
romankaravia committed Feb 7, 2020
1 parent ece8be2 commit 54ef376
Show file tree
Hide file tree
Showing 11 changed files with 720 additions and 787 deletions.
1,421 changes: 679 additions & 742 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@
},
"homepage": "https://github.com/nzzdev/Q-server#readme",
"dependencies": {
"@hapi/boom": "^7.4.3",
"@hapi/bounce": "^1.3.1",
"@hapi/hoek": "^8.2.5",
"@hapi/inert": "^5.2.2",
"@hapi/joi": "^15.1.1",
"@hapi/mimos": "^4.1.1",
"@hapi/vision": "^5.5.4",
"@hapi/wreck": "^15.1.0",
"ajv": "^6.10.2",
"aws-sdk": "^2.541.0",
"@hapi/boom": "^9.0.0",
"@hapi/bounce": "^2.0.0",
"@hapi/hoek": "^9.0.2",
"@hapi/inert": "^6.0.1",
"@hapi/joi": "^17.1.0",
"@hapi/mimos": "^5.0.0",
"@hapi/vision": "^6.0.0",
"@hapi/wreck": "^17.0.0",
"ajv": "^6.11.0",
"aws-sdk": "^2.613.0",
"clone": "^2.1.2",
"deepmerge": "^4.0.0",
"deepmerge": "^4.2.2",
"hasha": "^5.1.0",
"json-schema-ref-parser": "^7.1.1",
"json-schema-ref-parser": "^7.1.3",
"keycdn": "^0.2.2",
"nano": "^8.1.0",
"node-fetch": "^2.6.0",
"puppeteer": "^1.20.0",
"slugify": "^1.3.5",
"uuid": "^3.3.3"
"puppeteer": "^2.1.1",
"slugify": "^1.3.6",
"uuid": "^3.4.0"
},
"devDependencies": {
"@hapi/code": "^6.0.0",
"@hapi/hapi": "^18.4.0",
"@hapi/lab": "^20.3.2",
"@hapi/code": "^8.0.1",
"@hapi/hapi": "^19.1.0",
"@hapi/lab": "^22.0.3",
"confidence": "^4.0.2",
"pouchdb-server": "^4.2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/core/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = {
if (err.isBoom) {
throw err;
}
throw new Boom(err.description, { statusCode: err.statusCode });
throw new Boom.Boom(err.description, { statusCode: err.statusCode });
}
});

Expand Down
2 changes: 1 addition & 1 deletion plugins/core/editor/configSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const target = Joi.object().pattern(
label: Joi.string().required(),
type: Joi.string()
.required()
.valid(["web", "AMP", "image", "application/json", "application/pdf"]),
.valid("web", "AMP", "image", "application/json", "application/pdf"),
context: Joi.object().keys({
stylesheets: Joi.array().items(
Joi.object().keys({ url: Joi.string().uri() })
Expand Down
2 changes: 1 addition & 1 deletion plugins/core/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
allowUnknown: true
}
);
if (targetConfigValidationResult.error !== null) {
if (targetConfigValidationResult.error) {
throw new Error(targetConfigValidationResult.error);
}

Expand Down
12 changes: 6 additions & 6 deletions plugins/core/rendering-info/configSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ const target = Joi.object().pattern(
label: Joi.string().required(),
type: Joi.string()
.required()
.valid(["web", "AMP", "image", "application/json", "application/pdf"]),
.valid("web", "AMP", "image", "application/json", "application/pdf"),
additionalRenderingInfo: Joi.object().when("type", {
is: Joi.string()
.required()
.valid(["web", "json"]),
.valid("web", "json"),
then: Joi.optional(),
otherwise: Joi.forbidden()
}),
processRenderingInfo: Joi.optional().allow([
processRenderingInfo: Joi.optional().allow(
Joi.func().arity(1),
Joi.array().items(Joi.func().arity(1))
])
)
})
);

Expand All @@ -28,10 +28,10 @@ const toolEndpoint = Joi.alternatives().try(
url: Joi.string().optional(),
additionalRenderingInfo: Joi.object().optional(),
toolRuntimeConfig: Joi.object().optional(),
processRenderingInfo: Joi.optional().allow([
processRenderingInfo: Joi.optional().allow(
Joi.func().arity(1),
Joi.array().items(Joi.func().arity(1))
])
)
})
.without("path", ["url"])
.without("url", ["path"]),
Expand Down
4 changes: 2 additions & 2 deletions plugins/core/rendering-info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ module.exports = {
allowUnknown: true
}
);
if (targetConfigValidationResult.error !== null) {
if (targetConfigValidationResult.error) {
throw new Error(targetConfigValidationResult.error);
}

Expand All @@ -233,7 +233,7 @@ module.exports = {
allowUnknown: true
}
);
if (toolEndpointConfigValidationResult.error !== null) {
if (toolEndpointConfigValidationResult.error) {
throw new Error(
`failed to validate toolEndpoint config: ${JSON.stringify(
endpointConfig
Expand Down
2 changes: 1 addition & 1 deletion plugins/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
(err, data) => {
if (err) {
return reject(
new Boom("error", { statusCode: err.statusCode })
new Boom.Boom("error", { statusCode: err.statusCode })
);
}
return resolve(
Expand Down
18 changes: 6 additions & 12 deletions plugins/screenshot/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ async function getScreenshotResponse(server, h, params, item) {
});

if (response.statusCode !== 200) {
throw new Boom(
`Failed to get renderingInfo to load in headless chrome for screenshot for ${
item.tool
} and ${params.target} with the error: ${response.statusMessage}`,
throw new Boom.Boom(
`Failed to get renderingInfo to load in headless chrome for screenshot for ${item.tool} and ${params.target} with the error: ${response.statusMessage}`,
{
statusCode: response.statusCode
}
Expand Down Expand Up @@ -99,9 +97,7 @@ async function getScreenshotResponse(server, h, params, item) {

if (params.format === "png") {
const screenshotBuffer = await getScreenshotImage(
`${server.info.protocol}://localhost:${
server.info.port
}/screenshot/empty-page.html`,
`${server.info.protocol}://localhost:${server.info.port}/screenshot/empty-page.html`,
renderingInfo.markup,
scripts,
stylesheets,
Expand All @@ -113,9 +109,7 @@ async function getScreenshotResponse(server, h, params, item) {
return imageResponse;
} else if (params.format === "json") {
const screenshotInfo = await getScreenshotInfo(
`${server.info.protocol}://localhost:${
server.info.port
}/screenshot/empty-page.html`,
`${server.info.protocol}://localhost:${server.info.port}/screenshot/empty-page.html`,
renderingInfo.markup,
scripts,
stylesheets,
Expand All @@ -136,7 +130,7 @@ module.exports = {
validate: {
params: {
id: Joi.string().required(),
format: Joi.string().valid(["json", "png"])
format: Joi.string().valid("json", "png")
},
query: queryFormat,
options: {
Expand Down Expand Up @@ -173,7 +167,7 @@ module.exports = {
options: {
validate: {
params: {
format: Joi.string().valid(["json", "png"])
format: Joi.string().valid("json", "png")
},
payload: {
item: Joi.object().required(),
Expand Down
5 changes: 2 additions & 3 deletions test/mock/tool1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const server = Hapi.server({
cors: true
}
});
server.validator(Joi);

const schema = {
$schema: "http://json-schema.org/draft-04/schema#",
Expand Down Expand Up @@ -84,9 +85,7 @@ server.route({
},
handler: function(request, h) {
return {
markup: `<h1>${request.payload.item.title} - itemStateInDb: ${
request.payload.itemStateInDb
}</h1>`,
markup: `<h1>${request.payload.item.title} - itemStateInDb: ${request.payload.itemStateInDb}</h1>`,
stylesheets: [
{
name: "mockstyle"
Expand Down
3 changes: 3 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Hapi = require("@hapi/hapi");
const Joi = require("@hapi/joi");

function getServer() {
let server = Hapi.server({
Expand All @@ -12,6 +13,8 @@ function getServer() {
}
});

server.validator(Joi);

// mock the auth strategy
server.auth.scheme("mock", function(server, options) {
return {
Expand Down

0 comments on commit 54ef376

Please sign in to comment.