From a501863ac412d631f84eff216de4b330e7fd8d3e Mon Sep 17 00:00:00 2001 From: Cezary Nowak Date: Mon, 9 Jan 2023 17:46:19 +0100 Subject: [PATCH] 1.7.1 --- .npmignore | 5 +++++ example/package.json | 6 +++--- index.js | 27 +++++++++++++++++++-------- package.json | 16 +++++++--------- 4 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..33d75e3 --- /dev/null +++ b/.npmignore @@ -0,0 +1,5 @@ +example/ +.git/ +README.md +.editorconfig +.gitignore diff --git a/example/package.json b/example/package.json index f839ca5..36ba76d 100644 --- a/example/package.json +++ b/example/package.json @@ -13,8 +13,8 @@ "license": "ISC", "homepage": "https://github.com/CezaryDanielNowak/node-api-cache-proxy", "dependencies": { - "express": "4.13.3", - "node-api-cache-proxy": "0.6.2", - "open": "0.0.5" + "express": "4.18.2", + "node-api-cache-proxy": "0.7.1", + "open": "8.4.0" } } diff --git a/index.js b/index.js index 13717d1..9ea5ed2 100644 --- a/index.js +++ b/index.js @@ -6,8 +6,6 @@ var extract = require('url-querystring') var filendir = require('filendir') var fs = require('fs') var getRawBody = require('raw-body') -var MD5 = require('crypto-js/md5'); -var objectAssign = require('object-assign') var omit = require('object.omit') var packageJson = require('./package.json') var path = require('path') @@ -15,6 +13,18 @@ var request = require('request') var sanitize = require('sanitize-filename') var zlib = require('zlib') +var { createHash } = require('node:crypto'); + +/** + * Returns an MD5 hash for the given `content`. + * + * @param {String} content + * @returns {String} + */ +function MD5(content) { + return createHash('md5').update(content).digest('hex') +} + var MODULE_NAME = 'api-cache-proxy' var log = console.log.bind(console, '[' + MODULE_NAME + '] ') @@ -38,7 +48,7 @@ var defaultConfig = { timeout: false } -objectAssign(APICache.prototype, { +Object.assign(APICache.prototype, { _createEnvelope: function(response, responseBody, requestBody) { var excludeRequestHeaders = [ 'content-encoding', // content is unpacked, content-encoding doesn't apply anymore, @@ -225,7 +235,7 @@ function APICache(config) { assert(config, 'APICache requres config provided') assert(config.apiUrl, 'APICache: provide apiUrl') - this.config = objectAssign({}, defaultConfig, config) + this.config = Object.assign({}, defaultConfig, config) var handleRequest = function(req, res) { var url = this._getApiURL(req) @@ -245,9 +255,6 @@ function APICache(config) { }) .on('error', function(err) { that.onError(apiReq, res, reqBodyRef.requestBody, resolve, reject) - promise.catch(function() { - log('API Error', url, err) - }) }) } else { req.pipe(apiReq).pipe(res) @@ -271,7 +278,11 @@ function APICache(config) { return promise } - return objectAssign(handleRequest.bind(this), this) + promise.catch(function() { + log('API Error', url, err) + }) + + return Object.assign(handleRequest.bind(this), this) } module.exports = APICache diff --git a/package.json b/package.json index 73b0a9d..f844dd2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-api-cache-proxy", - "version": "0.6.4", + "version": "0.7.1", "description": "Cache requests in nodejs", "main": "index.js", "scripts": { @@ -17,14 +17,12 @@ }, "homepage": "https://github.com/CezaryDanielNowak/node-api-cache-proxy#readme", "dependencies": { - "assert": "1.4.1", - "crypto-js": "3.1.9-1", - "filendir": "1.0.0", - "object-assign": "4.1.1", - "object.omit": "2.0.0", - "raw-body": "2.3.0", - "request": "2.81.0", - "sanitize-filename": "1.6.1", + "assert": "2.0.0", + "filendir": "2.0.1", + "object.omit": "3.0.0", + "raw-body": "2.5.1", + "request": "2.88.2", + "sanitize-filename": "1.6.3", "url-querystring": "2.1.1" } }