Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ot06/be-utils

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ot06/be-utils - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15

dist/constants/HEADERS.js

11

dist/expressMiddlewares/index.js

@@ -14,10 +14,19 @@ 'use strict';

var _constants = require("../constants");
var _expressHttpContext = _interopRequireDefault(require("express-http-context"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var {
HEADER_PROPS
} = _constants.HEADERS;
var expressMiddlerwares = {
RequestHandler: _requestHandler.default,
RouteHandler: _RouteHandler.default,
ResponseHandler: _ResponseHandler.default
ResponseHandler: _ResponseHandler.default,
HEADER_PROPS,
httpContext: _expressHttpContext.default
};
var _default = expressMiddlerwares;
exports.default = _default;

@@ -8,4 +8,10 @@ 'use strict';

var _ResponseBody = _interopRequireDefault(require("../classes/ResponseBody"));
var _expressHttpContext = _interopRequireDefault(require("express-http-context"));
var _nanoid = require("nanoid");
var _classes = require("../classes");
var _constants = require("../constants");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -20,2 +26,5 @@

var DEFAULT_CONFIG = {};
var {
EXTRACT_HEADERS
} = _constants.HEADERS;

@@ -27,2 +36,3 @@ class RequestHandler {

this.asyncWrapper = this.asyncWrapper.bind(this);
this.extractHeaders = this.extractHeaders.bind(this);
}

@@ -47,3 +57,3 @@

if (error.constructor.name === _ResponseBody.default.name) {
if (error.constructor.name === _classes.ResponseBody.name) {
responseBody = error;

@@ -62,4 +72,40 @@ } else if (error.getResponseBody && typeof error.getResponseBody === 'function') {

extractHeaders(request, response, next) {
var {
headers = {},
query = {}
} = request;
EXTRACT_HEADERS.forEach(HEADER => {
var {
HEADER_KEY,
QUERY_KEY,
PROP,
GENERATE_RANDOM
} = HEADER;
var value = _extractFromHeader(headers, HEADER_KEY);
if (QUERY_KEY) {
value = value || query[QUERY_KEY];
}
if (!value && GENERATE_RANDOM) {
value = (0, _nanoid.nanoid)();
}
_expressHttpContext.default.set(PROP, value);
});
return process.nextTick(next);
}
}
exports.default = RequestHandler;
exports.default = RequestHandler;
function _extractFromHeader() {
var headers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var value = headers[key] || '';
value = value || headers[key.toLowerCase()] || '';
return value;
}

@@ -8,4 +8,8 @@ 'use strict';

var _ResponseBody = _interopRequireDefault(require("../classes/ResponseBody"));
var _expressHttpContext = _interopRequireDefault(require("express-http-context"));
var _classes = require("../classes");
var _constants = require("../constants");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -20,2 +24,6 @@

var DEFAULT_CONFIG = {};
var {
SET_HEADERS,
EXPOSE_HEADERS
} = _constants.HEADERS;

@@ -28,2 +36,3 @@ class ResponseHandler {

this.handleError = this.handleError.bind(this);
this.setHeaders = this.setHeaders.bind(this);
}

@@ -44,3 +53,3 @@

var _error = new _ResponseBody.default(404, message);
var _error = new _classes.ResponseBody(404, message);

@@ -56,3 +65,3 @@ response.body = _error;

if (error && error.constructor.name === _ResponseBody.default.name) {
if (error && error.constructor.name === _classes.ResponseBody.name) {
response.body = error;

@@ -76,3 +85,3 @@ return _sendResponse(request, response, next);

var responseBody = error.constructor.name === _ResponseBody.default.name ? error : new _ResponseBody.default(500, undefined, undefined, error);
var responseBody = error.constructor.name === _classes.ResponseBody.name ? error : new _classes.ResponseBody(500, undefined, undefined, error);
response.body = responseBody;

@@ -82,2 +91,10 @@ return this.handleResponse(request, response, next);

setHeaders(request, response, next) {
_setHeaders(response);
_exposeHeaders(response);
return process.nextTick(next);
}
}

@@ -94,3 +111,3 @@

if (!resBody || !statusCode) {
resBody = new _ResponseBody.default(500, 'Response Data Not Found!');
resBody = new _classes.ResponseBody(500, 'Response Data Not Found!');
}

@@ -108,2 +125,21 @@

response.status(statusCode).redirect(data);
}
function _exposeHeaders(response) {
var {
HEADER_KEY = '',
HEADER_VALUE = ''
} = EXPOSE_HEADERS || {};
response.set(HEADER_KEY, HEADER_VALUE);
}
function _setHeaders(request, response) {
SET_HEADERS.forEach(HEADER => {
var {
HEADER_KEY,
PROP
} = HEADER;
var value = _expressHttpContext.default.get(PROP) || '';
response.set(HEADER_KEY, value);
});
}

5

package.json
{
"name": "@ot06/be-utils",
"version": "0.0.14",
"version": "0.0.15",
"description": "Backend Utilities Module",

@@ -10,5 +10,6 @@ "main": "dist/index.js",

"dependencies": {
"express-http-context": "^1.2.4",
"lodash": "4.17.21",
"moment": "2.29.1",
"nanoid": "^3.1.22",
"nanoid": "^3.1.25",
"qs": "6.9.6",

@@ -15,0 +16,0 @@ "uuid": "^8.3.2"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc