Skip to content

Commit 01eef03

Browse files
authored
* Allow web-login donecheck to cancel opener promise * set 'npm-use-webauthn' header depending on option
1 parent 2953983 commit 01eef03

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

node_modules/npm-profile/lib/index.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const fetch = require('npm-registry-fetch')
44
const { HttpErrorBase } = require('npm-registry-fetch/lib/errors')
5+
const EventEmitter = require('events')
56
const os = require('os')
67
const { URL } = require('url')
78
const log = require('proc-log')
@@ -59,6 +60,9 @@ const webAuth = (opener, opts, body) => {
5960
...opts,
6061
method: 'POST',
6162
body,
63+
headers: {
64+
'npm-use-webauthn': opts.authType === 'webauthn',
65+
},
6266
}).then(res => {
6367
return Promise.all([res, res.json()])
6468
}).then(([res, content]) => {
@@ -70,8 +74,23 @@ const webAuth = (opener, opts, body) => {
7074
return content
7175
}).then(({ doneUrl, loginUrl }) => {
7276
log.verbose('web auth', 'opening url pair')
73-
return opener(loginUrl).then(
74-
() => webAuthCheckLogin(doneUrl, { ...opts, cache: false })
77+
78+
const doneEmitter = new EventEmitter()
79+
80+
const openPromise = opener(loginUrl, doneEmitter)
81+
const webAuthCheckPromise = webAuthCheckLogin(doneUrl, { ...opts, cache: false })
82+
.then(authResult => {
83+
log.verbose('web auth', 'done-check finished')
84+
85+
// cancel open prompt if it's present
86+
doneEmitter.emit('abort')
87+
88+
return authResult
89+
})
90+
91+
return Promise.all([openPromise, webAuthCheckPromise]).then(
92+
// pick the auth result and pass it along
93+
([, authResult]) => authResult
7594
)
7695
}).catch(er => {
7796
if ((er.statusCode >= 400 && er.statusCode <= 499) || er.statusCode === 500) {

node_modules/npm-profile/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-profile",
3-
"version": "6.0.3",
3+
"version": "6.1.0",
44
"description": "Library for updating an npmjs.com profile",
55
"keywords": [],
66
"author": "GitHub Inc.",
@@ -20,7 +20,7 @@
2020
],
2121
"devDependencies": {
2222
"@npmcli/eslint-config": "^3.0.1",
23-
"@npmcli/template-oss": "3.4.1",
23+
"@npmcli/template-oss": "3.4.2",
2424
"nock": "^13.2.4",
2525
"tap": "^16.0.1"
2626
},
@@ -44,6 +44,6 @@
4444
},
4545
"templateOSS": {
4646
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
47-
"version": "3.4.1"
47+
"version": "3.4.2"
4848
}
4949
}

package-lock.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"npm-install-checks": "^5.0.0",
134134
"npm-package-arg": "^9.0.2",
135135
"npm-pick-manifest": "^7.0.1",
136-
"npm-profile": "^6.0.3",
136+
"npm-profile": "^6.1.0",
137137
"npm-registry-fetch": "^13.1.1",
138138
"npm-user-validate": "^1.0.1",
139139
"npmlog": "^6.0.2",
@@ -5173,9 +5173,9 @@
51735173
}
51745174
},
51755175
"node_modules/npm-profile": {
5176-
"version": "6.0.3",
5177-
"resolved": "https://registry.npmjs.org/npm-profile/-/npm-profile-6.0.3.tgz",
5178-
"integrity": "sha512-TVeHhnol2Iemud+Sr70/uqax5LnLJ9y361w+m5+Z7WYV2B1t6FhRDxDu72+yYYTvsgshkhnXEqbPjuD87kYXfA==",
5176+
"version": "6.1.0",
5177+
"resolved": "https://registry.npmjs.org/npm-profile/-/npm-profile-6.1.0.tgz",
5178+
"integrity": "sha512-JHnBzSqS9xPa0M3g90zhaGElSVdxoAipGkraBaM6Jph2XiSiwFN1HmfRTqndYhDkXia2hWRWl8O5RbDvae++GA==",
51795179
"inBundle": true,
51805180
"dependencies": {
51815181
"npm-registry-fetch": "^13.0.1",
@@ -13646,9 +13646,9 @@
1364613646
}
1364713647
},
1364813648
"npm-profile": {
13649-
"version": "6.0.3",
13650-
"resolved": "https://registry.npmjs.org/npm-profile/-/npm-profile-6.0.3.tgz",
13651-
"integrity": "sha512-TVeHhnol2Iemud+Sr70/uqax5LnLJ9y361w+m5+Z7WYV2B1t6FhRDxDu72+yYYTvsgshkhnXEqbPjuD87kYXfA==",
13649+
"version": "6.1.0",
13650+
"resolved": "https://registry.npmjs.org/npm-profile/-/npm-profile-6.1.0.tgz",
13651+
"integrity": "sha512-JHnBzSqS9xPa0M3g90zhaGElSVdxoAipGkraBaM6Jph2XiSiwFN1HmfRTqndYhDkXia2hWRWl8O5RbDvae++GA==",
1365213652
"requires": {
1365313653
"npm-registry-fetch": "^13.0.1",
1365413654
"proc-log": "^2.0.0"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"npm-install-checks": "^5.0.0",
103103
"npm-package-arg": "^9.0.2",
104104
"npm-pick-manifest": "^7.0.1",
105-
"npm-profile": "^6.0.3",
105+
"npm-profile": "^6.1.0",
106106
"npm-registry-fetch": "^13.1.1",
107107
"npm-user-validate": "^1.0.1",
108108
"npmlog": "^6.0.2",

0 commit comments

Comments
 (0)