@everymundo/promise-data-to
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -6,2 +6,3 @@ 'use strict' | ||
const { parseJson } = require('@everymundo/json-utils') | ||
const { parseUrl } = require('../lib/parse-url') | ||
@@ -45,3 +46,3 @@ const validateEndpointProtocol = endpointKey => (endpoint) => { | ||
endpoints.forEach((endpoint, ix) => { | ||
const { protocol, hostname, port, path, auth } = require('url').parse(endpoint) | ||
const { protocol, hostname, port, path, auth } = parseUrl(endpoint) | ||
const configs = { | ||
@@ -48,0 +49,0 @@ http: protos[protocol], |
@@ -5,3 +5,3 @@ 'use strict' | ||
const protos = { 'http:': require('http'), 'https:': require('https') } | ||
const parseUrl = require('url').parse | ||
const { parseUrl } = require('../lib/parse-url') | ||
@@ -17,11 +17,20 @@ const urlToEndpoint = (url, headers = {}) => { | ||
host: hostname, | ||
headers, | ||
headers: {}, | ||
search, | ||
port, | ||
path, | ||
endpoint: url | ||
endpoint: url, | ||
compress: false | ||
} | ||
if (!(headers instanceof Object)) configs.headers = {} | ||
if (headers && headers instanceof Object) { | ||
Object.entries(headers).forEach(([headerName, headerValue]) => { | ||
configs.headers[headerName.toLowerCase()] = '' + headerValue | ||
}) | ||
if ('content-encoding' in configs.headers) { | ||
configs.compress = configs.headers['content-encoding'] | ||
} | ||
} | ||
// auth | ||
@@ -28,0 +37,0 @@ if (auth) { |
{ | ||
"name": "@everymundo/promise-data-to", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "This is a helper to perform POST requests using promises and no external dependencies", | ||
@@ -12,3 +12,3 @@ "main": "index.js", | ||
"check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100", | ||
"check-lint": "standard --env=mocha *.js lib/*.js spec/*.js spec/lib/*.js", | ||
"check-lint": "standard --env=mocha *.js lib/*.js test/*.js test/lib/*.js", | ||
"fix-lint": "standard --env=mocha --fix *.js lib/*.js test/*.js", | ||
@@ -45,6 +45,6 @@ "test": "RETRY_TIMEOUT_MS= MAX_RETRY_ATTEMPTS= SIMULATE= mocha" | ||
"ghooks": "^2.0.4", | ||
"mocha": "^6.1.4", | ||
"mocha": "^6.2.0", | ||
"nyc": "^14.1.1", | ||
"sinon": "^7.3.2", | ||
"standard": "^12.0.1" | ||
"sinon": "^7.4.1", | ||
"standard": "^13.1.0" | ||
}, | ||
@@ -51,0 +51,0 @@ "dependencies": { |
@@ -78,3 +78,3 @@ 'require strict' | ||
path: '/some/path', | ||
port: null, | ||
port: '', | ||
compress: undefined | ||
@@ -105,3 +105,3 @@ }] | ||
path: '/some/path', | ||
port: null, | ||
port: '', | ||
compress: undefined | ||
@@ -134,3 +134,3 @@ }] | ||
path: '/some/path', | ||
port: null, | ||
port: '', | ||
compress: undefined | ||
@@ -167,3 +167,3 @@ }] | ||
path: '/some/path', | ||
port: null, | ||
port: '', | ||
compress: 'gzip' | ||
@@ -202,3 +202,3 @@ }] | ||
path: '/some/path', | ||
port: null, | ||
port: '', | ||
compress: undefined | ||
@@ -245,3 +245,3 @@ }] | ||
path: '/some/path', | ||
port: null, | ||
port: '', | ||
compress: undefined | ||
@@ -284,3 +284,3 @@ }] | ||
path: '/some/path', | ||
port: null, | ||
port: '', | ||
compress: undefined | ||
@@ -287,0 +287,0 @@ }] |
@@ -107,4 +107,3 @@ 'require strict' | ||
it('should success when status is between 200 and 299 using http', () => { | ||
const | ||
data = { a: 1, b: 2, c: 3 } | ||
const data = { a: 1, b: 2, c: 3 } | ||
@@ -121,3 +120,4 @@ const expectedData = JSON.stringify(data) | ||
const { promiseDataTo } = loadLib() | ||
return promiseDataTo(config, data) | ||
const customConfig = { ...config, headers: undefined } | ||
return promiseDataTo(customConfig, data) | ||
.then((stats) => { | ||
@@ -124,0 +124,0 @@ expect(stats.code).to.equal(200) |
@@ -7,3 +7,3 @@ 'require strict' | ||
describe('index.js', () => { | ||
const url = require('url') | ||
const { parseUrl } = require('../lib/parse-url') | ||
const sinon = require('sinon') | ||
@@ -41,3 +41,3 @@ const { expect } = require('chai') | ||
const config = url.parse('http://test.com/somepath') | ||
const config = parseUrl('http://test.com/somepath') | ||
@@ -53,3 +53,3 @@ return promiseGet(config) | ||
const config = url.parse('http://test.com/somepath') | ||
const config = parseUrl('http://test.com/somepath') | ||
// eslint-disable-next-line one-var-declaration-per-line | ||
@@ -56,0 +56,0 @@ let protocol, http, host, port, query, path, endpoint, headers, agent, maxRetry |
@@ -62,4 +62,5 @@ 'require strict' | ||
path: '/some/path', | ||
port: null, | ||
search: null | ||
port: '', | ||
search: '', | ||
compress: false | ||
} | ||
@@ -83,4 +84,5 @@ | ||
path: '/some/path', | ||
port: null, | ||
search: null | ||
port: '', | ||
search: '', | ||
compress: false | ||
} | ||
@@ -107,4 +109,5 @@ | ||
path: '/some/path', | ||
port: null, | ||
search: null | ||
port: '', | ||
search: '', | ||
compress: false | ||
} | ||
@@ -130,4 +133,5 @@ | ||
path: '/some/path', | ||
port: null, | ||
search: null | ||
port: '', | ||
search: '', | ||
compress: false | ||
} | ||
@@ -137,2 +141,25 @@ | ||
}) | ||
context('when content-encoding is passed as gzip', () => { | ||
it('should return compress as "gzip"', () => { | ||
const headers = { 'Content-Encoding': 'gzip' } | ||
const endpointUrl = 'http://test.com/some/path' | ||
const result = urlToEndpoint(endpointUrl, headers) | ||
const expected = { | ||
http, | ||
endpoint: 'http://test.com/some/path', | ||
headers: { | ||
'content-encoding': 'gzip' | ||
}, | ||
host: 'test.com', | ||
path: '/some/path', | ||
port: '', | ||
search: '', | ||
compress: 'gzip' | ||
} | ||
expect(result).to.deep.equal(expected) | ||
}) | ||
}) | ||
}) | ||
@@ -143,4 +170,4 @@ | ||
const headers = '' | ||
const endpointUrl = 'http://test.com/some/path' | ||
const result = urlToEndpoint(endpointUrl, headers) | ||
const endpoint = 'http://test.com/some/path' | ||
const result = urlToEndpoint(endpoint, headers) | ||
@@ -153,4 +180,5 @@ const expected = { | ||
path: '/some/path', | ||
port: null, | ||
search: null | ||
port: '', | ||
search: '', | ||
compress: false | ||
} | ||
@@ -157,0 +185,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56297
23
1473