npm-registry-fetch
Advanced tools
Comparing version 8.1.5 to 9.0.0
16
auth.js
@@ -8,3 +8,4 @@ 'use strict' | ||
function getAuth (registry, opts_ = {}) { | ||
if (!registry) { throw new Error('registry is required') } | ||
if (!registry) | ||
throw new Error('registry is required') | ||
const opts = opts_.forceAuth ? opts_.forceAuth : { ...defaultOpts, ...opts_ } | ||
@@ -23,5 +24,5 @@ const AUTH = {} | ||
doKey('always-auth', 'alwaysAuth') | ||
if (AUTH.password) { | ||
if (AUTH.password) | ||
AUTH.password = Buffer.from(AUTH.password, 'base64').toString('utf8') | ||
} | ||
if (AUTH._auth && !(AUTH.username && AUTH.password)) { | ||
@@ -38,8 +39,7 @@ let auth = Buffer.from(AUTH._auth, 'base64').toString() | ||
function addKey (opts, obj, scope, key, objKey) { | ||
if (opts[key]) { | ||
if (opts[key]) | ||
obj[objKey || key] = opts[key] | ||
} | ||
if (scope && opts[`${scope}:${key}`]) { | ||
if (scope && opts[`${scope}:${key}`]) | ||
obj[objKey || key] = opts[`${scope}:${key}`] | ||
} | ||
} | ||
@@ -55,5 +55,5 @@ | ||
pathname: parsed.pathname, | ||
slashes: true | ||
slashes: true, | ||
}) | ||
return url.format(new url.URL('.', formatted)).replace(/^[^:]+:/, '') | ||
} |
@@ -11,5 +11,5 @@ 'use strict' | ||
const opts = { ...defaultOpts, ...opts_ } | ||
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) { | ||
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) | ||
opts.log.notice('', res.headers.get('npm-notice')) | ||
} | ||
checkWarnings(res, registry, opts) | ||
@@ -39,5 +39,5 @@ if (res.status >= 400) { | ||
const url = new URL(res.url) | ||
if (url.password) { | ||
if (url.password) | ||
url.password = '***' | ||
} | ||
urlStr = url.toString() | ||
@@ -63,3 +63,4 @@ } catch (er) { | ||
for (const [key, value] of Object.entries(res.headers.raw())) { | ||
if (key.toLowerCase() !== 'warning') { continue } | ||
if (key.toLowerCase() !== 'warning') | ||
continue | ||
value.forEach(w => { | ||
@@ -72,3 +73,3 @@ const match = w.match(WARNING_REGEXP) | ||
message: match[3], | ||
date: new Date(match[4]) | ||
date: new Date(match[4]), | ||
} | ||
@@ -80,7 +81,6 @@ } | ||
if (warnings['199']) { | ||
if (warnings['199'].message.match(/ENOTFOUND/)) { | ||
if (warnings['199'].message.match(/ENOTFOUND/)) | ||
opts.log.warn('registry', `Using stale data from ${registry} because the host is inaccessible -- are you offline?`) | ||
} else { | ||
else | ||
opts.log.warn('registry', `Unexpected warning for ${registry}: ${warnings['199'].message}`) | ||
} | ||
} | ||
@@ -87,0 +87,0 @@ if (warnings['111']) { |
@@ -21,3 +21,3 @@ const pkg = require('./package.json') | ||
process.platform | ||
})` | ||
})`, | ||
} |
@@ -11,7 +11,6 @@ 'use strict' | ||
var index = basePath.indexOf('_rewrite') | ||
if (index === -1) { | ||
if (index === -1) | ||
index = basePath.length - 1 | ||
} else { | ||
else | ||
index++ | ||
} | ||
return decodeURIComponent(basePath[index]) | ||
@@ -18,0 +17,0 @@ } |
63
index.js
@@ -28,7 +28,6 @@ 'use strict' | ||
...defaultOpts, | ||
...opts_ | ||
...opts_, | ||
} | ||
const registry = opts.registry = ( | ||
(opts.spec && pickRegistry(opts.spec, opts)) || | ||
(opts.publishConfig && opts.publishConfig.registry) || | ||
opts.registry || | ||
@@ -61,5 +60,4 @@ /* istanbul ignore next */ | ||
body = JSON.stringify(body) | ||
} else if (body && !headers['content-type']) { | ||
} else if (body && !headers['content-type']) | ||
headers['content-type'] = 'application/octet-stream' | ||
} | ||
@@ -73,5 +71,4 @@ if (opts.gzip) { | ||
body = body.pipe(gz) | ||
} else if (!bodyIsPromise) { | ||
} else if (!bodyIsPromise) | ||
body = new zlib.Gzip().end(body).concat() | ||
} | ||
} | ||
@@ -82,10 +79,8 @@ | ||
if (opts.query) { | ||
const q = typeof opts.query === 'string' | ||
? qs.parse(opts.query) | ||
const q = typeof opts.query === 'string' ? qs.parse(opts.query) | ||
: opts.query | ||
Object.keys(q).forEach(key => { | ||
if (q[key] !== undefined) { | ||
if (q[key] !== undefined) | ||
parsed.searchParams.set(key, q[key]) | ||
} | ||
}) | ||
@@ -125,6 +120,6 @@ uri = url.format(parsed) | ||
minTimeout: opts.fetchRetryMintimeout, | ||
maxTimeout: opts.fetchRetryMaxtimeout | ||
maxTimeout: opts.fetchRetryMaxtimeout, | ||
}, | ||
strictSSL: opts.strictSSL, | ||
timeout: opts.timeout || 30 * 1000 | ||
timeout: opts.timeout || 30 * 1000, | ||
}).then(res => checkResponse( | ||
@@ -160,13 +155,7 @@ method, res, registry, startTime, opts | ||
if (!registry && opts.scope) { | ||
if (!registry && opts.scope) | ||
registry = opts[opts.scope.replace(/^@?/, '@') + ':registry'] | ||
} | ||
if (!registry && opts.publishConfig) { | ||
registry = opts.publishConfig.registry | ||
} | ||
if (!registry) { | ||
if (!registry) | ||
registry = opts.registry || 'https://registry.npmjs.org/' | ||
} | ||
@@ -177,9 +166,6 @@ return registry | ||
function getCacheMode (opts) { | ||
return opts.offline | ||
? 'only-if-cached' | ||
: opts.preferOffline | ||
? 'force-cache' | ||
: opts.preferOnline | ||
? 'no-cache' | ||
: 'default' | ||
return opts.offline ? 'only-if-cached' | ||
: opts.preferOffline ? 'force-cache' | ||
: opts.preferOnline ? 'no-cache' | ||
: 'default' | ||
} | ||
@@ -190,16 +176,13 @@ | ||
'npm-in-ci': !!opts.isFromCI, | ||
'user-agent': opts.userAgent | ||
'user-agent': opts.userAgent, | ||
}, opts.headers || {}) | ||
if (opts.projectScope) { | ||
if (opts.projectScope) | ||
headers['npm-scope'] = opts.projectScope | ||
} | ||
if (opts.npmSession) { | ||
if (opts.npmSession) | ||
headers['npm-session'] = opts.npmSession | ||
} | ||
if (opts.npmCommand) { | ||
if (opts.npmCommand) | ||
headers['npm-command'] = opts.npmCommand | ||
} | ||
@@ -213,5 +196,5 @@ const auth = getAuth(registry, opts) | ||
) | ||
if (shouldAuth && auth.token) { | ||
if (shouldAuth && auth.token) | ||
headers.authorization = `Bearer ${auth.token}` | ||
} else if (shouldAuth && auth.username && auth.password) { | ||
else if (shouldAuth && auth.username && auth.password) { | ||
const encoded = Buffer.from( | ||
@@ -221,9 +204,9 @@ `${auth.username}:${auth.password}`, 'utf8' | ||
headers.authorization = `Basic ${encoded}` | ||
} else if (shouldAuth && auth._auth) { | ||
} else if (shouldAuth && auth._auth) | ||
headers.authorization = `Basic ${auth._auth}` | ||
} | ||
if (shouldAuth && auth.otp) { | ||
if (shouldAuth && auth.otp) | ||
headers['npm-otp'] = auth.otp | ||
} | ||
return headers | ||
} |
{ | ||
"name": "npm-registry-fetch", | ||
"version": "8.1.5", | ||
"version": "9.0.0", | ||
"description": "Fetch-based http client for use with npm registry APIs", | ||
"main": "index.js", | ||
"files": [ | ||
"*.js", | ||
"lib" | ||
"*.js" | ||
], | ||
"scripts": { | ||
"postrelease": "npm publish", | ||
"posttest": "standard", | ||
"prepublishOnly": "git push --follow-tags", | ||
"prerelease": "npm t", | ||
"release": "standard-version -s", | ||
"test": "tap" | ||
"eslint": "eslint", | ||
"lint": "npm run eslint -- *.js test/*.js", | ||
"lintfix": "npm run lint -- --fix", | ||
"prepublishOnly": "git push origin --follow-tags", | ||
"preversion": "npm test", | ||
"postversion": "npm publish", | ||
"test": "tap", | ||
"posttest": "npm run lint" | ||
}, | ||
"repository": "https://github.com/npm/registry-fetch", | ||
"repository": "https://github.com/npm/npm-registry-fetch", | ||
"keywords": [ | ||
@@ -42,2 +43,7 @@ "npm", | ||
"cacache": "^15.0.0", | ||
"eslint": "^6.8.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-node": "^10.0.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"mkdirp": "^0.5.1", | ||
@@ -49,4 +55,2 @@ "nock": "^11.7.0", | ||
"ssri": "^8.0.0", | ||
"standard": "^14.3.3", | ||
"standard-version": "^7.1.0", | ||
"tap": "^14.10.7" | ||
@@ -53,0 +57,0 @@ }, |
# npm-registry-fetch | ||
[![npm version](https://img.shields.io/npm/v/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch) | ||
[![license](https://img.shields.io/npm/l/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch) | ||
[![Travis](https://img.shields.io/travis/npm/npm-registry-fetch/latest.svg)](https://travis-ci.org/npm/npm-registry-fetch) | ||
[![AppVeyor](https://img.shields.io/appveyor/ci/npm/npm-registry-fetch/latest.svg)](https://ci.appveyor.com/project/npm/npm-registry-fetch) | ||
[![Coverage Status](https://coveralls.io/repos/github/npm/npm-registry-fetch/badge.svg?branch=latest)](https://coveralls.io/github/npm/npm-registry-fetch?branch=latest) | ||
[`npm-registry-fetch`](https://github.com/npm/npm-registry-fetch) is a Node.js | ||
@@ -10,0 +4,0 @@ library that implements a `fetch`-like API for accessing npm registry APIs |
@@ -13,3 +13,3 @@ 'use strict' | ||
pause: noop, | ||
resume: noop | ||
resume: noop, | ||
} |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
1
2
48035
13
446
630