@vltpkg/registry-client 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -2
- package/dist/index.js +25 -5
- package/dist/otplease.js +3 -1
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -131,12 +131,18 @@ export declare class RegistryClient {
|
|
|
131
131
|
*/
|
|
132
132
|
logout(registry: string): Promise<void>;
|
|
133
133
|
/**
|
|
134
|
-
* Log into the registry specified
|
|
134
|
+
* Log into the registry specified.
|
|
135
|
+
*
|
|
136
|
+
* When a list of registries is provided, the web login flow runs once
|
|
137
|
+
* against the first of them, and the token it returns is saved for all
|
|
138
|
+
* of them. This is for registries that share credentials -- like the
|
|
139
|
+
* ones under a single vlt.io account -- where opening the browser once
|
|
140
|
+
* per registry would just be asking for the same token again.
|
|
135
141
|
*
|
|
136
142
|
* Does not return the token or expose it, just saves to the auth keychain
|
|
137
143
|
* and returns void if it worked. Otherwise, error is raised.
|
|
138
144
|
*/
|
|
139
|
-
login(registry: string): Promise<void>;
|
|
145
|
+
login(registry: string | string[]): Promise<void>;
|
|
140
146
|
/**
|
|
141
147
|
* Given a {@link WebAuthChallenge}, open the `authUrl` in a browser and
|
|
142
148
|
* hang on the `doneUrl` until it returns a {@link TokenResponse} object.
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,8 @@ import { getTokenResponse } from "./token-response.js";
|
|
|
25
25
|
import { getWebAuthChallenge } from "./web-auth-challenge.js";
|
|
26
26
|
import { collectHeaders, readBody } from "./response.js";
|
|
27
27
|
import { oidc } from "./oidc.js";
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
const log = (msg) => console.error(msg);
|
|
28
30
|
export { CacheEntry, clearRuntimeTokens, deleteToken, getKC, getToken, getTokenByURL, isToken, keychains, normalizeRegistryKey, oidc, registryBase, runtimeTokens, setRuntimeToken, setToken, };
|
|
29
31
|
export const isCacheableMethod = (m) => m === 'GET' || m === 'HEAD';
|
|
30
32
|
export const cacheKey = (method, url) => `${method !== 'GET' ? method + ' ' : ''}${url}`;
|
|
@@ -154,12 +156,23 @@ export class RegistryClient {
|
|
|
154
156
|
await deleteToken(registry, this.identity);
|
|
155
157
|
}
|
|
156
158
|
/**
|
|
157
|
-
* Log into the registry specified
|
|
159
|
+
* Log into the registry specified.
|
|
160
|
+
*
|
|
161
|
+
* When a list of registries is provided, the web login flow runs once
|
|
162
|
+
* against the first of them, and the token it returns is saved for all
|
|
163
|
+
* of them. This is for registries that share credentials -- like the
|
|
164
|
+
* ones under a single vlt.io account -- where opening the browser once
|
|
165
|
+
* per registry would just be asking for the same token again.
|
|
158
166
|
*
|
|
159
167
|
* Does not return the token or expose it, just saves to the auth keychain
|
|
160
168
|
* and returns void if it worked. Otherwise, error is raised.
|
|
161
169
|
*/
|
|
162
170
|
async login(registry) {
|
|
171
|
+
const registries = Array.isArray(registry) ? registry : [registry];
|
|
172
|
+
const [first] = registries;
|
|
173
|
+
if (!first) {
|
|
174
|
+
throw error('No registry provided to log in against');
|
|
175
|
+
}
|
|
163
176
|
// - make POST to '/-/v1/login'
|
|
164
177
|
// - include a body of {} and npm-auth-type:web
|
|
165
178
|
// - get a {doneUrl, authUrl}
|
|
@@ -167,7 +180,7 @@ export class RegistryClient {
|
|
|
167
180
|
// - hang on the doneUrl until done
|
|
168
181
|
//
|
|
169
182
|
// if that fails: fall back to couchdb login
|
|
170
|
-
const webLoginURL = new URL('-/v1/login', registryBase(
|
|
183
|
+
const webLoginURL = new URL('-/v1/login', registryBase(first));
|
|
171
184
|
const response = await this.request(webLoginURL, {
|
|
172
185
|
method: 'POST',
|
|
173
186
|
useCache: false,
|
|
@@ -181,7 +194,10 @@ export class RegistryClient {
|
|
|
181
194
|
const challenge = getWebAuthChallenge(response.json());
|
|
182
195
|
if (challenge) {
|
|
183
196
|
const result = await this.webAuthOpener(challenge);
|
|
184
|
-
|
|
197
|
+
// sequential, because they all write to the same keychain file
|
|
198
|
+
for (const reg of registries) {
|
|
199
|
+
await setToken(reg, `Bearer ${result.token}`, this.identity);
|
|
200
|
+
}
|
|
185
201
|
return;
|
|
186
202
|
}
|
|
187
203
|
}
|
|
@@ -204,10 +220,14 @@ export class RegistryClient {
|
|
|
204
220
|
return result;
|
|
205
221
|
}),
|
|
206
222
|
urlOpen(authUrl, { signal }).catch((er) => {
|
|
223
|
+
// an aborted spawn is not a failure, e.g: login completed
|
|
224
|
+
// before the browser process exited
|
|
207
225
|
if (asError(er).name === 'AbortError')
|
|
208
226
|
return;
|
|
209
|
-
|
|
210
|
-
|
|
227
|
+
// the opener may exist but still fail to launch a browser,
|
|
228
|
+
// e.g: xdg-open on a headless server. Keep polling doneUrl so
|
|
229
|
+
// the user can complete the login by opening the url manually.
|
|
230
|
+
log(`Could not open a browser. Please open ${authUrl} manually.`);
|
|
211
231
|
}),
|
|
212
232
|
]);
|
|
213
233
|
/* c8 ignore stop */
|
package/dist/otplease.js
CHANGED
|
@@ -48,7 +48,9 @@ export const otplease = async (client, options, response) => {
|
|
|
48
48
|
const notice = String(npmNotice);
|
|
49
49
|
const match = otpChallengeNotice.exec(notice);
|
|
50
50
|
if (match?.[1]) {
|
|
51
|
-
|
|
51
|
+
// the opener may fail to launch a browser, e.g: xdg-open on a
|
|
52
|
+
// headless server. The url is printed in the notice below.
|
|
53
|
+
await urlOpen(match[1]).catch(() => { });
|
|
52
54
|
log(notice);
|
|
53
55
|
return {
|
|
54
56
|
retry: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/registry-client",
|
|
3
3
|
"description": "Fetch package artifacts and metadata from registries",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"url": "http://vlt.sh"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@vltpkg/cache": "1.0.
|
|
17
|
-
"@vltpkg/cache-unzip": "1.0.
|
|
18
|
-
"@vltpkg/error-cause": "1.0.
|
|
19
|
-
"@vltpkg/keychain": "1.0.
|
|
20
|
-
"@vltpkg/output": "1.0.
|
|
21
|
-
"@vltpkg/types": "1.0.
|
|
22
|
-
"@vltpkg/url-open": "1.0.
|
|
23
|
-
"@vltpkg/xdg": "1.0.
|
|
16
|
+
"@vltpkg/cache": "1.0.8",
|
|
17
|
+
"@vltpkg/cache-unzip": "1.0.8",
|
|
18
|
+
"@vltpkg/error-cause": "1.0.8",
|
|
19
|
+
"@vltpkg/keychain": "1.0.8",
|
|
20
|
+
"@vltpkg/output": "1.0.8",
|
|
21
|
+
"@vltpkg/types": "1.0.8",
|
|
22
|
+
"@vltpkg/url-open": "1.0.8",
|
|
23
|
+
"@vltpkg/xdg": "1.0.8",
|
|
24
24
|
"cache-control-parser": "^2.0.6",
|
|
25
25
|
"package-json-from-dist": "^1.0.1",
|
|
26
26
|
"undici": "^7.16.0"
|