Comparing version 3.5.3 to 3.5.4
@@ -0,1 +1,7 @@ | ||
### 3.5.4 | ||
* Apply latest nlm generator - **[@markowsiak](https://github.com/markowsiak)** [#79](https://github.com/groupon/gofer/pull/79) | ||
- [`9ea499a`](https://github.com/groupon/gofer/commit/9ea499a2b914f8c27e74da75d7952802df26c550) **chore:** apply latest generator | ||
### 3.5.3 | ||
@@ -2,0 +8,0 @@ |
@@ -32,2 +32,3 @@ /* | ||
*/ | ||
'use strict'; | ||
@@ -38,4 +39,11 @@ | ||
this.message = 'API Request returned a response outside the status code range ' + | ||
'(code: ' + statusCode + ', range: [' + min + ', ' + max + '])'; | ||
this.message = | ||
'API Request returned a response outside the status code range ' + | ||
'(code: ' + | ||
statusCode + | ||
', range: [' + | ||
min + | ||
', ' + | ||
max + | ||
'])'; | ||
this.headers = headers; | ||
@@ -78,3 +86,10 @@ this.statusCode = statusCode; | ||
StatusCodeError.create = function createError(statusCode, min, max, headers, method, url) { | ||
StatusCodeError.create = function createError( | ||
statusCode, | ||
min, | ||
max, | ||
headers, | ||
method, | ||
url | ||
) { | ||
var error; | ||
@@ -81,0 +96,0 @@ switch (statusCode) { |
@@ -32,3 +32,6 @@ /* | ||
*/ | ||
'use strict'; | ||
/* eslint-env browser */ | ||
/* global URLSearchParams */ | ||
@@ -55,7 +58,7 @@ var Url = require('url'); | ||
function _callJSON(res) { | ||
function callJSON(res) { | ||
return res.json(); | ||
} | ||
function _callText(res) { | ||
function callText(res) { | ||
return res.text(); | ||
@@ -67,3 +70,3 @@ } | ||
value: function json() { | ||
return this.then(_callJSON); | ||
return this.then(callJSON); | ||
}, | ||
@@ -74,3 +77,3 @@ }, | ||
value: function text() { | ||
return this.then(_callText); | ||
return this.then(callText); | ||
}, | ||
@@ -82,6 +85,8 @@ }, | ||
function isValidBody(body) { | ||
return body === undefined || | ||
return ( | ||
body === undefined || | ||
typeof body === 'string' || | ||
(typeof FormData !== 'undefined' && body instanceof FormData) || | ||
(typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams); | ||
(typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams) | ||
); | ||
} | ||
@@ -99,11 +104,10 @@ | ||
var filtered = {}; | ||
var queryKeys = Object.keys(query) | ||
.filter(function ensureSet(key) { | ||
var value = query[key]; | ||
var isSet = value !== null && value !== undefined; | ||
if (isSet) { | ||
filtered[key] = value; | ||
} | ||
return isSet; | ||
}); | ||
var queryKeys = Object.keys(query).filter(function ensureSet(key) { | ||
var value = query[key]; | ||
var isSet = value !== null && value !== undefined; | ||
if (isSet) { | ||
filtered[key] = value; | ||
} | ||
return isSet; | ||
}); | ||
@@ -132,3 +136,4 @@ if (queryKeys.length === 0) return ''; | ||
throw new TypeError( | ||
'Invalid status code ' + JSON.stringify(value) + ', not a number'); | ||
'Invalid status code ' + JSON.stringify(value) + ', not a number' | ||
); | ||
} | ||
@@ -154,4 +159,3 @@ return value; | ||
function isAcceptableStatus(code) { | ||
return (min === false || code >= min) && | ||
(max === false || code <= max); | ||
return (min === false || code >= min) && (max === false || code <= max); | ||
} | ||
@@ -181,3 +185,9 @@ | ||
var error = StatusCodeError.create( | ||
code, min, max, response.headers, options.method || 'GET', url); | ||
code, | ||
min, | ||
max, | ||
response.headers, | ||
options.method || 'GET', | ||
url | ||
); | ||
@@ -189,3 +199,4 @@ function rejectWithBody(body) { | ||
return response.text() | ||
return response | ||
.text() | ||
.then(parseErrorBody) | ||
@@ -207,3 +218,4 @@ .then(null, noop) | ||
throw new TypeError( | ||
'Invalid timeout ' + JSON.stringify(value) + ', not a number'); | ||
'Invalid timeout ' + JSON.stringify(value) + ', not a number' | ||
); | ||
} | ||
@@ -215,3 +227,3 @@ return value; | ||
function _fetch(url, options) { | ||
function fetchUrl(url, options) { | ||
if (typeof url !== 'string') { | ||
@@ -239,5 +251,7 @@ throw new TypeError('url has to be a string'); | ||
throw new TypeError( | ||
'Invalid form body (' + typeof form + ', expected object)'); | ||
'Invalid form body (' + typeof form + ', expected object)' | ||
); | ||
} | ||
defaultHeaders['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; | ||
defaultHeaders['Content-Type'] = | ||
'application/x-www-form-urlencoded;charset=UTF-8'; | ||
body = qsParser.stringify(form); | ||
@@ -250,3 +264,4 @@ } | ||
} else if (auth !== null && typeof auth === 'object') { | ||
defaultHeaders.Authorization = 'Basic ' + btoa(auth.username + ':' + auth.password); | ||
defaultHeaders.Authorization = | ||
'Basic ' + btoa(auth.username + ':' + auth.password); | ||
} | ||
@@ -300,2 +315,2 @@ | ||
module.exports = _fetch; | ||
module.exports = fetchUrl; |
@@ -32,3 +32,5 @@ /* | ||
*/ | ||
'use strict'; | ||
var http = require('http'); | ||
@@ -65,5 +67,8 @@ var https = require('https'); | ||
function isValidBody(body) { | ||
return body === undefined || | ||
Buffer.isBuffer(body) || typeof body === 'string' || | ||
(body && typeof body.pipe === 'function'); | ||
return ( | ||
body === undefined || | ||
Buffer.isBuffer(body) || | ||
typeof body === 'string' || | ||
(body && typeof body.pipe === 'function') | ||
); | ||
} | ||
@@ -97,11 +102,10 @@ | ||
var filtered = {}; | ||
var queryKeys = Object.keys(query) | ||
.filter(function ensureSet(key) { | ||
var value = query[key]; | ||
var isSet = value !== null && value !== undefined; | ||
if (isSet) { | ||
filtered[key] = value; | ||
} | ||
return isSet; | ||
}); | ||
var queryKeys = Object.keys(query).filter(function ensureSet(key) { | ||
var value = query[key]; | ||
var isSet = value !== null && value !== undefined; | ||
if (isSet) { | ||
filtered[key] = value; | ||
} | ||
return isSet; | ||
}); | ||
@@ -139,7 +143,12 @@ if (queryKeys.length === 0) return ''; | ||
return ( | ||
(options.clientName || 'noServiceName') + '/' + | ||
(options.clientVersion || 'noServiceVersion') + ' (' + | ||
(options.appName || 'noAppName') + '/' + | ||
(options.appSha || 'noAppSha') + '; ' + | ||
(options.fqdn || 'noFQDN') + ')' | ||
(options.clientName || 'noServiceName') + | ||
'/' + | ||
(options.clientVersion || 'noServiceVersion') + | ||
' (' + | ||
(options.appName || 'noAppName') + | ||
'/' + | ||
(options.appSha || 'noAppSha') + | ||
'; ' + | ||
(options.fqdn || 'noFQDN') + | ||
')' | ||
); | ||
@@ -152,3 +161,4 @@ } | ||
throw new TypeError( | ||
'Invalid timeout ' + JSON.stringify(value) + ', not a number'); | ||
'Invalid timeout ' + JSON.stringify(value) + ', not a number' | ||
); | ||
} | ||
@@ -167,3 +177,4 @@ return value; | ||
throw new TypeError( | ||
'Invalid status code ' + JSON.stringify(value) + ', not a number'); | ||
'Invalid status code ' + JSON.stringify(value) + ', not a number' | ||
); | ||
} | ||
@@ -175,3 +186,3 @@ return value; | ||
function _fetch(urlObj, options) { | ||
function fetchUrlObj(urlObj, options) { | ||
if (options.baseUrl && typeof options.baseUrl === 'string') { | ||
@@ -195,5 +206,7 @@ urlObj = applyBaseUrl(urlObj, options.baseUrl); | ||
throw new TypeError( | ||
'Invalid form body (' + typeof form + ', expected object)'); | ||
'Invalid form body (' + typeof form + ', expected object)' | ||
); | ||
} | ||
defaultHeaders['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; | ||
defaultHeaders['Content-Type'] = | ||
'application/x-www-form-urlencoded;charset=UTF-8'; | ||
body = qsParser.stringify(form); | ||
@@ -240,3 +253,5 @@ } | ||
method: method, | ||
path: replacePathParams(urlObj.pathname, options.pathParams) + generateSearch(urlObj.query, options.qs), | ||
path: | ||
replacePathParams(urlObj.pathname, options.pathParams) + | ||
generateSearch(urlObj.query, options.qs), | ||
headers: filterHeaders(assign(defaultHeaders, options.headers)), | ||
@@ -246,3 +261,6 @@ auth: unifyAuth(options.auth || urlObj.auth), | ||
body: body, | ||
connectTimeout: defaultTimeout(options.connectTimeout, DEFAULT_CONNECT_TIMEOUT), | ||
connectTimeout: defaultTimeout( | ||
options.connectTimeout, | ||
DEFAULT_CONNECT_TIMEOUT | ||
), | ||
timeout: defaultTimeout(options.timeout, DEFAULT_TIMEOUT), | ||
@@ -272,5 +290,5 @@ completionTimeout: defaultTimeout(options.completionTimeout, 0), | ||
} | ||
return nodeify(_fetch(parseUrl(url), options || {}), callback); | ||
return nodeify(fetchUrlObj(parseUrl(url), options || {}), callback); | ||
} | ||
module.exports = fetch; |
@@ -32,3 +32,5 @@ /* | ||
*/ | ||
'use strict'; | ||
var isObjectLike = require('lodash/isObjectLike'); | ||
@@ -49,8 +51,12 @@ var isPlainObject = require('lodash/isPlainObject'); | ||
var serviceDefaults = config[serviceName] || {}; | ||
this.defaults = merge({ | ||
serviceName: serviceName, | ||
clientVersion: clientVersion, | ||
clientName: clientName, | ||
endpointDefaults: {}, | ||
}, globalDefaults, serviceDefaults); | ||
this.defaults = merge( | ||
{ | ||
serviceName: serviceName, | ||
clientVersion: clientVersion, | ||
clientName: clientName, | ||
endpointDefaults: {}, | ||
}, | ||
globalDefaults, | ||
serviceDefaults | ||
); | ||
} | ||
@@ -61,4 +67,3 @@ module.exports = Gofer; | ||
Gofer.prototype.with = | ||
function withOverrides(overrides) { | ||
Gofer.prototype.with = function withOverrides(overrides) { | ||
var cloned = this.clone(); | ||
@@ -74,4 +79,3 @@ merge(cloned.defaults, overrides); | ||
*/ | ||
Gofer.prototype.clone = | ||
function clone() { | ||
Gofer.prototype.clone = function clone() { | ||
var Client = this.constructor || Gofer; | ||
@@ -82,5 +86,5 @@ var config = { globalDefaults: this.defaults }; | ||
// eslint-disable-next-line no-underscore-dangle | ||
Gofer.prototype._mappers = []; | ||
Gofer.prototype.addOptionMapper = | ||
function addOptionMapper(mapper) { | ||
Gofer.prototype.addOptionMapper = function addOptionMapper(mapper) { | ||
this._mappers = this._mappers.concat(mapper); | ||
@@ -107,8 +111,13 @@ }; | ||
Gofer.prototype._prepareOptions = | ||
function _prepareOptions(defaults, options) { | ||
// eslint-disable-next-line no-underscore-dangle | ||
Gofer.prototype._prepareOptions = function _prepareOptions(defaults, options) { | ||
var endpointName = options.endpointName || defaults.endpointName; | ||
var mergedOptions = mergeWith({}, this.defaults, defaults, | ||
var mergedOptions = mergeWith( | ||
{}, | ||
this.defaults, | ||
defaults, | ||
this.defaults.endpointDefaults[endpointName], | ||
options, preventComplexMerge); | ||
options, | ||
preventComplexMerge | ||
); | ||
return this._mappers.reduce(applyOptionMapper, mergedOptions); | ||
@@ -124,4 +133,3 @@ }; | ||
['get', 'put', 'post', 'patch', 'del', 'head'] | ||
.forEach(function withVerb(verb) { | ||
['get', 'put', 'post', 'patch', 'del', 'head'].forEach(function withVerb(verb) { | ||
var httpMethod = verb === 'del' ? 'DELETE' : verb.toUpperCase(); | ||
@@ -132,4 +140,3 @@ Gofer.prototype[verb] = fetchWithDefaults({ method: httpMethod }); | ||
Gofer.prototype.registerEndpoint = | ||
function registerEndpoint(name, endpointFn) { | ||
Gofer.prototype.registerEndpoint = function registerEndpoint(name, endpointFn) { | ||
Object.defineProperty(this, name, { | ||
@@ -147,4 +154,3 @@ configurable: true, | ||
Gofer.prototype.registerEndpoints = | ||
function registerEndpoints(endpointMap) { | ||
Gofer.prototype.registerEndpoints = function registerEndpoints(endpointMap) { | ||
Object.keys(endpointMap).forEach(function register(name) { | ||
@@ -151,0 +157,0 @@ this.registerEndpoint(name, endpointMap[name]); |
@@ -32,2 +32,3 @@ /* | ||
*/ | ||
'use strict'; | ||
@@ -34,0 +35,0 @@ |
@@ -32,2 +32,3 @@ /* | ||
*/ | ||
'use strict'; | ||
@@ -51,2 +52,3 @@ | ||
clearImmediate(handle); | ||
// eslint-disable-next-line no-underscore-dangle | ||
handle._onImmediate = noop; | ||
@@ -89,11 +91,11 @@ } | ||
function _callJSON(res) { | ||
function callJSON(res) { | ||
return res.json(); | ||
} | ||
function _callText(res) { | ||
function callText(res) { | ||
return res.text(); | ||
} | ||
function _callRawBody(res) { | ||
function callRawBody(res) { | ||
return res.rawBody(); | ||
@@ -114,3 +116,3 @@ } | ||
value: function json() { | ||
return this.then(_callJSON); | ||
return this.then(callJSON); | ||
}, | ||
@@ -121,3 +123,3 @@ }, | ||
value: function text() { | ||
return this.then(_callText); | ||
return this.then(callText); | ||
}, | ||
@@ -128,3 +130,3 @@ }, | ||
value: function rawBody() { | ||
return this.then(_callRawBody); | ||
return this.then(callRawBody); | ||
}, | ||
@@ -145,3 +147,3 @@ }, | ||
function request_(options, resolve, reject) { | ||
function requestFunc(options, resolve, reject) { | ||
var host = options.host; | ||
@@ -153,4 +155,4 @@ var setHost = options.setHost; | ||
var req_ = null; | ||
var res_ = null; | ||
var reqObj = null; | ||
var resObj = null; | ||
var connectTimer = null; | ||
@@ -179,5 +181,5 @@ var responseTimer = null; | ||
if (req_ !== null) { | ||
req_.abort(); | ||
req_ = null; | ||
if (reqObj !== null) { | ||
reqObj.abort(); | ||
reqObj = null; | ||
} | ||
@@ -188,6 +190,6 @@ reject(error); | ||
function emitError(error) { | ||
if (res_) { | ||
res_.emit('error', error); | ||
} else if (req_) { | ||
req_.emit('error', error); | ||
if (resObj) { | ||
resObj.emit('error', error); | ||
} else if (reqObj) { | ||
reqObj.emit('error', error); | ||
} | ||
@@ -199,4 +201,3 @@ } | ||
var max = options.maxStatusCode; | ||
return (min === false || code >= min) && | ||
(max === false || code <= max); | ||
return (min === false || code >= min) && (max === false || code <= max); | ||
} | ||
@@ -206,5 +207,11 @@ | ||
var error = StatusCodeError.create( | ||
res_.statusCode, options.minStatusCode, options.maxStatusCode, | ||
res_.headers, options.method, fullUrl); | ||
res_.rawBody() | ||
resObj.statusCode, | ||
options.minStatusCode, | ||
options.maxStatusCode, | ||
resObj.headers, | ||
options.method, | ||
fullUrl | ||
); | ||
resObj | ||
.rawBody() | ||
.then(parseErrorBody) | ||
@@ -224,5 +231,5 @@ .then(null, noop) | ||
res_ = Object.defineProperties(res, resProperties); | ||
res_.url = fullUrl; | ||
res_.on('error', failAndAbort); | ||
resObj = Object.defineProperties(res, resProperties); | ||
resObj.url = fullUrl; | ||
resObj.on('error', failAndAbort); | ||
@@ -233,3 +240,3 @@ if (!isAcceptableStatus(res.statusCode)) { | ||
debug('<- %s %s', res.statusCode, fullUrl); | ||
resolve(res_); | ||
resolve(resObj); | ||
} | ||
@@ -239,3 +246,3 @@ } | ||
function isConnecting() { | ||
return !!(req_ && req_.socket && req_.socket.readable === false); | ||
return !!(reqObj && reqObj.socket && reqObj.socket.readable === false); | ||
} | ||
@@ -280,3 +287,3 @@ | ||
socketTimer = null; | ||
if (req_ && req_.socket && req_.socket.readable) { | ||
if (reqObj && reqObj.socket && reqObj.socket.readable) { | ||
onResponseTimedOut('ESOCKETTIMEDOUT'); | ||
@@ -297,3 +304,3 @@ } | ||
function onRequest(req) { | ||
req_ = req; | ||
reqObj = req; | ||
@@ -332,5 +339,5 @@ if (options.completionTimeout > 0) { | ||
function request(options) { | ||
var result = new Bluebird(request_.bind(null, options)); | ||
var result = new Bluebird(requestFunc.bind(null, options)); | ||
return Object.defineProperties(result, reqProperties); | ||
} | ||
module.exports = request; |
@@ -32,3 +32,5 @@ /* | ||
*/ | ||
'use strict'; | ||
var zlib = require('zlib'); | ||
@@ -39,4 +41,5 @@ | ||
function getStreamForResponse(res) { | ||
var encoding = | ||
(res.headers['content-encoding'] || 'identity').trim().toLowerCase(); | ||
var encoding = (res.headers['content-encoding'] || 'identity') | ||
.trim() | ||
.toLowerCase(); | ||
@@ -105,4 +108,3 @@ switch (encoding) { | ||
value: function text() { | ||
return new Bluebird(readBody.bind(this.stream())) | ||
.then(toString); | ||
return new Bluebird(readBody.bind(this.stream())).then(toString); | ||
}, | ||
@@ -109,0 +111,0 @@ }, |
@@ -32,3 +32,5 @@ /* | ||
*/ | ||
'use strict'; | ||
var url = require('url'); | ||
@@ -57,3 +59,3 @@ | ||
// For the pathname, we join. E.g. http://host/v2 + /my-resource | ||
pathname: (basePath + (urlObj.pathname || '')) || '/', | ||
pathname: basePath + (urlObj.pathname || '') || '/', | ||
query: urlObj.query, | ||
@@ -60,0 +62,0 @@ }; |
{ | ||
"name": "gofer", | ||
"version": "3.5.3", | ||
"version": "3.5.4", | ||
"description": "A general purpose service client library", | ||
@@ -15,3 +15,3 @@ "license": "BSD-3-Clause", | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/groupon/gofer" | ||
"url": "https://github.com/groupon/gofer" | ||
}, | ||
@@ -42,8 +42,12 @@ "bugs": { | ||
"assertive": "^2.1.0", | ||
"eslint": "^1.0.0", | ||
"eslint-config-groupon": "^2.0.0", | ||
"eslint": "^4.7.1", | ||
"eslint-config-groupon": "^5.0.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-node": "^5.2.1", | ||
"eslint-plugin-prettier": "^2.2.0", | ||
"form-data": "^1.0.0-rc4", | ||
"mocha": "^2.0.0", | ||
"mocha": "^3.1.2", | ||
"mochify": "^2.17.0", | ||
"nlm": "^3.0.0", | ||
"prettier": "^1.6.1", | ||
"promise": "^7.1.1", | ||
@@ -50,0 +54,0 @@ "self-signed": "^1.3.1", |
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
62469
1274
14