npm-registry-fetch
Advanced tools
Comparing version 3.2.1 to 3.3.0
@@ -5,2 +5,17 @@ # Change Log | ||
<a name="3.3.0"></a> | ||
# [3.3.0](https://github.com/npm/registry-fetch/compare/v3.2.1...v3.3.0) (2018-08-21) | ||
### Bug Fixes | ||
* **query:** stop including undefined keys ([4718b1b](https://github.com/npm/registry-fetch/commit/4718b1b)) | ||
### Features | ||
* **otp:** use heuristic detection for malformed EOTP responses ([f035194](https://github.com/npm/registry-fetch/commit/f035194)) | ||
<a name="3.2.1"></a> | ||
@@ -7,0 +22,0 @@ ## [3.2.1](https://github.com/npm/registry-fetch/compare/v3.2.0...v3.2.1) (2018-08-16) |
@@ -73,4 +73,5 @@ 'use strict' | ||
.then(body => { | ||
let parsed = body | ||
try { | ||
body = JSON.parse(body.toString('utf8')) | ||
parsed = JSON.parse(body.toString('utf8')) | ||
} catch (e) {} | ||
@@ -83,16 +84,21 @@ if (res.status === 401 && res.headers.get('www-authenticate')) { | ||
throw new errors.HttpErrorAuthIPAddress( | ||
method, res, body, opts.spec | ||
method, res, parsed, opts.spec | ||
) | ||
} else if (auth.indexOf('otp') !== -1) { | ||
throw new errors.HttpErrorAuthOTP( | ||
method, res, body, opts.spec | ||
method, res, parsed, opts.spec | ||
) | ||
} else { | ||
throw new errors.HttpErrorAuthUnknown( | ||
method, res, body, opts.spec | ||
method, res, parsed, opts.spec | ||
) | ||
} | ||
} else if (res.status === 401 && /one-time pass/.test(body.toString('utf8'))) { | ||
// Heuristic for malformed OTP responses that don't include the www-authenticate header. | ||
throw new errors.HttpErrorAuthOTP( | ||
method, res, parsed, opts.spec | ||
) | ||
} else { | ||
throw new errors.HttpErrorGeneral( | ||
method, res, body, opts.spec | ||
method, res, parsed, opts.spec | ||
) | ||
@@ -99,0 +105,0 @@ } |
21
index.js
@@ -59,9 +59,16 @@ 'use strict' | ||
} | ||
const parsed = url.parse(uri) | ||
parsed.search = '?' + qs.stringify( | ||
parsed.query | ||
? Object.assign(qs.parse(parsed.query), q) | ||
: q | ||
) | ||
uri = url.format(parsed) | ||
Object.keys(q).forEach(key => { | ||
if (q[key] === undefined) { | ||
delete q[key] | ||
} | ||
}) | ||
if (Object.keys(q).length) { | ||
const parsed = url.parse(uri) | ||
parsed.search = '?' + qs.stringify( | ||
parsed.query | ||
? Object.assign(qs.parse(parsed.query), q) | ||
: q | ||
) | ||
uri = url.format(parsed) | ||
} | ||
} | ||
@@ -68,0 +75,0 @@ return opts.Promise.resolve(body).then(body => fetch(uri, { |
{ | ||
"name": "npm-registry-fetch", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Fetch-based http client for use with npm registry APIs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
36995
465