From 7021d02f2fdd05c3f0c0859660197104392b82d9 Mon Sep 17 00:00:00 2001 From: Valentin Genev Date: Wed, 9 Sep 2020 10:38:52 +0300 Subject: [PATCH] Feature/#1615 content headers (#240) * added support for resource versions * updated dependencies Co-authored-by: Valentin --- package-lock.json | 57 ++++++++++++++++++++++++++--------------------- package.json | 6 ++--- src/lib/util.js | 7 +++++- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6aecd827..abae467d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "quoting-service", - "version": "11.0.3", + "version": "11.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1690,9 +1690,9 @@ } }, "@mojaloop/central-services-shared": { - "version": "11.3.2", - "resolved": "https://registry.npmjs.org/@mojaloop/central-services-shared/-/central-services-shared-11.3.2.tgz", - "integrity": "sha512-2ZAZsYpZgp50O9h6cqtUjC3ozIjFDqjCmduyUaxk9BjfInTBTG+8SMZNrzhWKVGm2wgDmTpSpvo778g3GPyGdQ==", + "version": "11.3.3", + "resolved": "https://registry.npmjs.org/@mojaloop/central-services-shared/-/central-services-shared-11.3.3.tgz", + "integrity": "sha512-2LuqxEiTSUsC0rh1I5xCZ+ZuspqEaUhoxAd9TMAmD5cz02/D2gNZl7DW0J0cUXgakmWrFqD1r958ayQFAa89qg==", "requires": { "@hapi/catbox": "11.1.1", "@hapi/catbox-memory": "5.0.0", @@ -1713,6 +1713,7 @@ "mustache": "4.0.1", "openapi-backend": "3.5.2", "raw-body": "2.4.1", + "rc": "1.2.8", "uuid4": "2.0.2" }, "dependencies": { @@ -1750,10 +1751,27 @@ "protobufjs": "6.9.0", "rc": "1.2.8", "serialize-error": "4.1.0", + "sinon": "9.0.2", "traceparent": "1.0.0", "tslib": "2.0.0", "uuid4": "2.0.2", "winston": "3.3.3" + }, + "dependencies": { + "sinon": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.0.2.tgz", + "integrity": "sha512-0uF8Q/QHkizNUmbK3LRFqx5cpTttEVXudywY9Uwzy8bTfZUhljZ7ARzSxnRHWYWtVTeh4Cw+tTb3iU21FQVO9A==", + "requires": { + "@sinonjs/commons": "^1.7.2", + "@sinonjs/fake-timers": "^6.0.1", + "@sinonjs/formatio": "^5.0.1", + "@sinonjs/samsam": "^5.0.3", + "diff": "^4.0.2", + "nise": "^4.0.1", + "supports-color": "^7.1.0" + } + } } }, "@mojaloop/ml-number": { @@ -1943,7 +1961,6 @@ "version": "1.8.1", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.1.tgz", "integrity": "sha512-892K+kWUUi3cl+LlqEWIDrhvLgdL79tECi8JZUyq6IviKy/DNhuzCRlbHUjxK89f4ypPMMaFnFuR9Ie6DoIMsw==", - "dev": true, "requires": { "type-detect": "4.0.8" } @@ -1952,7 +1969,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-6.0.1.tgz", "integrity": "sha512-MZPUxrmFubI36XS1DI3qmI0YdN1gks62JtFZvxR67ljjSNCeK6U08Zx4msEWOXuofgqUt6zPHSi1H9fbjR/NRA==", - "dev": true, "requires": { "@sinonjs/commons": "^1.7.0" } @@ -1961,7 +1977,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-5.0.1.tgz", "integrity": "sha512-KaiQ5pBf1MpS09MuA0kp6KBQt2JUOQycqVG1NZXvzeaXe5LGFqAKueIS0bw4w0P9r7KuBSVdUk5QjXsUdu2CxQ==", - "dev": true, "requires": { "@sinonjs/commons": "^1", "@sinonjs/samsam": "^5.0.2" @@ -1971,7 +1986,6 @@ "version": "5.1.0", "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.1.0.tgz", "integrity": "sha512-42nyaQOVunX5Pm6GRJobmzbS7iLI+fhERITnETXzzwDZh+TtDr/Au3yAvXVjFmZ4wEUaE4Y3NFZfKv0bV0cbtg==", - "dev": true, "requires": { "@sinonjs/commons": "^1.6.0", "lodash.get": "^4.4.2", @@ -1981,8 +1995,7 @@ "@sinonjs/text-encoding": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz", - "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", - "dev": true + "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==" }, "@szmarczak/http-timer": { "version": "1.1.2", @@ -3778,8 +3791,7 @@ "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" }, "diff-sequences": { "version": "25.2.6", @@ -5506,8 +5518,7 @@ "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, "has-symbols": { "version": "1.0.1", @@ -8903,8 +8914,7 @@ "just-extend": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.1.0.tgz", - "integrity": "sha512-ApcjaOdVTJ7y4r08xI5wIqpvwS48Q0PBG4DJROcEkH1f8MdAiNFyFxz3xoL0LWAVwjrwPYZdVHHxhRHcx/uGLA==", - "dev": true + "integrity": "sha512-ApcjaOdVTJ7y4r08xI5wIqpvwS48Q0PBG4DJROcEkH1f8MdAiNFyFxz3xoL0LWAVwjrwPYZdVHHxhRHcx/uGLA==" }, "jwa": { "version": "1.4.1", @@ -9762,7 +9772,6 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/nise/-/nise-4.0.4.tgz", "integrity": "sha512-bTTRUNlemx6deJa+ZyoCUTRvH3liK5+N6VQZ4NIw90AgDXY6iPnsqplNFf6STcj+ePk0H/xqxnP75Lr0J0Fq3A==", - "dev": true, "requires": { "@sinonjs/commons": "^1.7.0", "@sinonjs/fake-timers": "^6.0.0", @@ -9932,9 +9941,9 @@ } }, "npm-check-updates": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-8.1.0.tgz", - "integrity": "sha512-cIB3oUkCEzz5kuOXgly8OygBLKacRBWwQJwt+fmSiSj7+jDHBVbdi1EH9O43tqP8XRUhrKIYt5dQroeSwJ/K8g==", + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-8.1.1.tgz", + "integrity": "sha512-8YxCG/ExD9HdcvflEfPrvEeonkAc+1OZCbZ9ExANkDRqMrolOMHC52eJyQlF4bsFMAAtT3nS1EOjkCRaDaOiHQ==", "dev": true, "requires": { "chalk": "^4.1.0", @@ -10930,7 +10939,6 @@ "version": "1.8.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", - "dev": true, "requires": { "isarray": "0.0.1" }, @@ -10938,8 +10946,7 @@ "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", - "dev": true + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" } } }, @@ -12758,7 +12765,6 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", - "dev": true, "requires": { "has-flag": "^4.0.0" } @@ -13118,8 +13124,7 @@ "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" }, "type-fest": { "version": "0.3.1", diff --git a/package.json b/package.json index 52fa2935..0d49250d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "quoting-service", "description": "Quoting Service hosted by a scheme", "license": "Apache-2.0", - "version": "11.0.3", + "version": "11.1.0", "author": "ModusBox", "contributors": [ "James Bush ", @@ -62,7 +62,7 @@ "@hapi/hapi": "20.0.0", "@mojaloop/central-services-error-handling": "10.6.0", "@mojaloop/central-services-logger": "10.6.0", - "@mojaloop/central-services-shared": "11.3.2", + "@mojaloop/central-services-shared": "11.3.3", "@mojaloop/event-sdk": "10.6.0", "@mojaloop/ml-number": "8.2.0", "@mojaloop/sdk-standard-components": "10.3.2", @@ -86,7 +86,7 @@ "jest": "26.4.2", "jest-junit": "11.1.0", "npm-audit-resolver": "2.2.1", - "npm-check-updates": "8.1.0", + "npm-check-updates": "8.1.1", "nyc": "15.1.0", "pre-commit": "1.2.2", "proxyquire": "2.1.3", diff --git a/src/lib/util.js b/src/lib/util.js index 67c93c66..f21508f3 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -36,6 +36,7 @@ const util = require('util') const crypto = require('crypto') const Enum = require('@mojaloop/central-services-shared').Enum const Logger = require('@mojaloop/central-services-logger') +const resourceVersions = require('@mojaloop/central-services-shared').Util.resourceVersions const failActionHandler = async (request, h, err) => { Logger.error(`validation failure: ${getStackOrInspect}`) @@ -125,8 +126,12 @@ function removeEmptyKeys (originalObject) { * @returns {object} */ function generateRequestHeaders (headers, noAccept) { + let contentTypeHeader = headers['content-type'] || headers['Content-Type'] + if (Enum.Http.Headers.GENERAL.CONTENT_TYPE.regex.test(contentTypeHeader) && !!resourceVersions.quotes.contentVersion) { + contentTypeHeader = `application/vnd.interoperability.quotes+json;version=${resourceVersions.quotes.contentVersion}` + } const ret = { - 'Content-Type': headers['content-type'] || headers['Content-Type'], + 'Content-Type': contentTypeHeader, Date: headers.date, 'FSPIOP-Source': headers['fspiop-source'], 'FSPIOP-Destination': headers['fspiop-destination'],