Skip to content

Commit ef69d36

Browse files
committedOct 12, 2023
deps: npm-registry-fetch@16.1.0
1 parent ed8c553 commit ef69d36

File tree

5 files changed

+61
-29
lines changed

5 files changed

+61
-29
lines changed
 

‎node_modules/npm-registry-fetch/lib/auth.js

+50-14
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const npa = require('npm-package-arg')
44
const { URL } = require('url')
55

66
// Find the longest registry key that is used for some kind of auth
7-
// in the options.
8-
const regKeyFromURI = (uri, opts) => {
7+
// in the options. Returns the registry key and the auth config.
8+
const regFromURI = (uri, opts) => {
99
const parsed = new URL(uri)
1010
// try to find a config key indicating we have auth for this registry
1111
// can be one of :_authToken, :_auth, :_password and :username, or
@@ -14,23 +14,40 @@ const regKeyFromURI = (uri, opts) => {
1414
// stopping when we reach '//'.
1515
let regKey = `//${parsed.host}${parsed.pathname}`
1616
while (regKey.length > '//'.length) {
17+
const authKey = hasAuth(regKey, opts)
1718
// got some auth for this URI
18-
if (hasAuth(regKey, opts)) {
19-
return regKey
19+
if (authKey) {
20+
return { regKey, authKey }
2021
}
2122

2223
// can be either //host/some/path/:_auth or //host/some/path:_auth
2324
// walk up by removing EITHER what's after the slash OR the slash itself
2425
regKey = regKey.replace(/([^/]+|\/)$/, '')
2526
}
27+
return { regKey: false, authKey: null }
2628
}
2729

28-
const hasAuth = (regKey, opts) => (
29-
opts[`${regKey}:_authToken`] ||
30-
opts[`${regKey}:_auth`] ||
31-
opts[`${regKey}:username`] && opts[`${regKey}:_password`] ||
32-
opts[`${regKey}:certfile`] && opts[`${regKey}:keyfile`]
33-
)
30+
// Not only do we want to know if there is auth, but if we are calling `npm
31+
// logout` we want to know what config value specifically provided it. This is
32+
// so we can look up where the config came from to delete it (i.e. user vs
33+
// project)
34+
const hasAuth = (regKey, opts) => {
35+
if (opts[`${regKey}:_authToken`]) {
36+
return '_authToken'
37+
}
38+
if (opts[`${regKey}:_auth`]) {
39+
return '_auth'
40+
}
41+
if (opts[`${regKey}:username`] && opts[`${regKey}:_password`]) {
42+
// 'password' can be inferred to also be present
43+
return 'username'
44+
}
45+
if (opts[`${regKey}:certfile`] && opts[`${regKey}:keyfile`]) {
46+
// 'keyfile' can be inferred to also be present
47+
return 'certfile'
48+
}
49+
return false
50+
}
3451

3552
const sameHost = (a, b) => {
3653
const parsedA = new URL(a)
@@ -63,11 +80,14 @@ const getAuth = (uri, opts = {}) => {
6380
if (!uri) {
6481
throw new Error('URI is required')
6582
}
66-
const regKey = regKeyFromURI(uri, forceAuth || opts)
83+
const { regKey, authKey } = regFromURI(uri, forceAuth || opts)
6784

6885
// we are only allowed to use what's in forceAuth if specified
6986
if (forceAuth && !regKey) {
7087
return new Auth({
88+
// if we force auth we don't want to refer back to anything in config
89+
regKey: false,
90+
authKey: null,
7191
scopeAuthKey: null,
7292
token: forceAuth._authToken || forceAuth.token,
7393
username: forceAuth.username,
@@ -88,8 +108,8 @@ const getAuth = (uri, opts = {}) => {
88108
// registry where we logged in, but the same auth SHOULD be sent
89109
// to that artifact host, then we track where it was coming in from,
90110
// and warn the user if we get a 4xx error on it.
91-
const scopeAuthKey = regKeyFromURI(registry, opts)
92-
return new Auth({ scopeAuthKey })
111+
const { regKey: scopeAuthKey, authKey: _authKey } = regFromURI(registry, opts)
112+
return new Auth({ scopeAuthKey, regKey: scopeAuthKey, authKey: _authKey })
93113
}
94114
}
95115

@@ -104,6 +124,8 @@ const getAuth = (uri, opts = {}) => {
104124

105125
return new Auth({
106126
scopeAuthKey: null,
127+
regKey,
128+
authKey,
107129
token,
108130
auth,
109131
username,
@@ -114,8 +136,22 @@ const getAuth = (uri, opts = {}) => {
114136
}
115137

116138
class Auth {
117-
constructor ({ token, auth, username, password, scopeAuthKey, certfile, keyfile }) {
139+
constructor ({
140+
token,
141+
auth,
142+
username,
143+
password,
144+
scopeAuthKey,
145+
certfile,
146+
keyfile,
147+
regKey,
148+
authKey,
149+
}) {
150+
// same as regKey but only present for scoped auth. Should have been named scopeRegKey
118151
this.scopeAuthKey = scopeAuthKey
152+
// `${regKey}:${authKey}` will get you back to the auth config that gave us auth
153+
this.regKey = regKey
154+
this.authKey = authKey
119155
this.token = null
120156
this.auth = null
121157
this.isBasicAuth = false

‎node_modules/npm-registry-fetch/lib/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ function regFetch (uri, /* istanbul ignore next */ opts_ = {}) {
166166
return Promise.resolve(body).then(doFetch)
167167
}
168168

169+
module.exports.getAuth = getAuth
170+
169171
module.exports.json = fetchJSON
170172
function fetchJSON (uri, opts) {
171173
return regFetch(uri, opts).then(res => res.json())

‎node_modules/npm-registry-fetch/package.json

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-registry-fetch",
3-
"version": "16.0.0",
3+
"version": "16.1.0",
44
"description": "Fetch-based http client for use with npm registry APIs",
55
"main": "lib",
66
"files": [
@@ -41,7 +41,7 @@
4141
},
4242
"devDependencies": {
4343
"@npmcli/eslint-config": "^4.0.0",
44-
"@npmcli/template-oss": "4.18.0",
44+
"@npmcli/template-oss": "4.19.0",
4545
"cacache": "^18.0.0",
4646
"nock": "^13.2.4",
4747
"require-inject": "^1.4.4",
@@ -61,13 +61,7 @@
6161
},
6262
"templateOSS": {
6363
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
64-
"version": "4.18.0",
65-
"publish": "true",
66-
"ciVersions": [
67-
"16.14.0",
68-
"16.x",
69-
"18.0.0",
70-
"18.x"
71-
]
64+
"version": "4.19.0",
65+
"publish": "true"
7266
}
7367
}

‎package-lock.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
"npm-package-arg": "^11.0.1",
140140
"npm-pick-manifest": "^9.0.0",
141141
"npm-profile": "^9.0.0",
142-
"npm-registry-fetch": "^16.0.0",
142+
"npm-registry-fetch": "^16.1.0",
143143
"npm-user-validate": "^2.0.0",
144144
"npmlog": "^7.0.1",
145145
"p-map": "^4.0.0",
@@ -10927,9 +10927,9 @@
1092710927
}
1092810928
},
1092910929
"node_modules/npm-registry-fetch": {
10930-
"version": "16.0.0",
10931-
"resolved": "https://registry.npmjs.org/npm-registry-fetch/-/npm-registry-fetch-16.0.0.tgz",
10932-
"integrity": "sha512-JFCpAPUpvpwfSydv99u85yhP68rNIxSFmDpNbNnRWKSe3gpjHnWL8v320gATwRzjtgmZ9Jfe37+ZPOLZPwz6BQ==",
10930+
"version": "16.1.0",
10931+
"resolved": "https://registry.npmjs.org/npm-registry-fetch/-/npm-registry-fetch-16.1.0.tgz",
10932+
"integrity": "sha512-PQCELXKt8Azvxnt5Y85GseQDJJlglTFM9L9U9gkv2y4e9s0k3GVDdOx3YoB6gm2Do0hlkzC39iCGXby+Wve1Bw==",
1093310933
"inBundle": true,
1093410934
"dependencies": {
1093510935
"make-fetch-happen": "^13.0.0",

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"npm-package-arg": "^11.0.1",
102102
"npm-pick-manifest": "^9.0.0",
103103
"npm-profile": "^9.0.0",
104-
"npm-registry-fetch": "^16.0.0",
104+
"npm-registry-fetch": "^16.1.0",
105105
"npm-user-validate": "^2.0.0",
106106
"npmlog": "^7.0.1",
107107
"p-map": "^4.0.0",

0 commit comments

Comments
 (0)
Please sign in to comment.