Skip to content

Commit

Permalink
chore: bump dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherry committed Feb 27, 2023
1 parent 006ab14 commit f758ce2
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 84 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';
const validate = require('./lib/validate');

module.exports = function networkErrorLogging(options){
module.exports = function networkErrorLogging(options) {
validate(options);

const headerValue = JSON.stringify(options);

return function networkErrorLogging(req, res, next){
return function networkErrorLogging(req, res, next) {
res.setHeader('NEL', headerValue);
return next();
};
};
};
36 changes: 18 additions & 18 deletions lib/validate.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
'use strict';

function isObject(value){
function isObject(value) {
return Object.prototype.toString.call(value) === '[object Object]';
}

module.exports = function validate(options){
if(!isObject(options)){
module.exports = function validate(options) {
if(!isObject(options)) {
throw new Error('NEL must be called with an object argument.');
}
if((options.report_to) !== undefined && typeof(options.report_to) !== 'string'){
if((options.report_to) !== undefined && typeof(options.report_to) !== 'string') {
throw new TypeError('The `report_to` parameter must be a string if set.');
}
if(options.include_subdomains && typeof(options.include_subdomains) !== 'boolean'){
if(options.include_subdomains && typeof(options.include_subdomains) !== 'boolean') {
throw new Error('The `include_subdomains` parameter must be a boolean if set.');
}
if(!options.max_age){
if(!options.max_age) {
throw new Error('The `max_age` parameter is required.');
}
if(typeof(options.max_age) !== 'number' || options.max_age <= 0){
if(typeof(options.max_age) !== 'number' || options.max_age <= 0) {
throw new Error('The `max_age` parameter must be a positive integer.');
}
if(options.success_fraction && (typeof(options.success_fraction) !== 'number' || options.success_fraction < 0 || options.success_fraction > 1)){
if(options.success_fraction && (typeof(options.success_fraction) !== 'number' || options.success_fraction < 0 || options.success_fraction > 1)) {
throw new Error('The `success_fraction` parameter must be a positive integer between 0.0 and 1.0.');
}
if(options.failure_fraction && (typeof(options.failure_fraction) !== 'number' || options.failure_fraction < 0 || options.failure_fraction > 1)){
if(options.failure_fraction && (typeof(options.failure_fraction) !== 'number' || options.failure_fraction < 0 || options.failure_fraction > 1)) {
throw new Error('The `failure_fraction` parameter must be a positive integer between 0.0 and 1.0.');
}
if(options.request_headers && !Array.isArray(options.request_headers)){
if(options.request_headers && !Array.isArray(options.request_headers)) {
throw new Error('The `request_headers` parameter must be an array of strings');
}
if(options.request_headers && Array.isArray(options.request_headers)){
for(const header of options.request_headers){
if(typeof(header) !== 'string'){
if(options.request_headers && Array.isArray(options.request_headers)) {
for(const header of options.request_headers) {
if(typeof(header) !== 'string') {
throw new TypeError('The `request_headers` parameter must only contain strings.');
}
}
}
if(options.response_headers && !Array.isArray(options.response_headers)){
if(options.response_headers && !Array.isArray(options.response_headers)) {
throw new Error('The `response_headers` parameter must be an array of strings');
}
if(options.response_headers && Array.isArray(options.response_headers)){
for(const header of options.response_headers){
if(typeof(header) !== 'string'){
if(options.response_headers && Array.isArray(options.response_headers)) {
for(const header of options.response_headers) {
if(typeof(header) !== 'string') {
throw new TypeError('The `response_headers` parameter must only contain strings.');
}
}
}
};
};
Loading

0 comments on commit f758ce2

Please sign in to comment.