@vltpkg/registry-client 1.0.5 → 1.0.7

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.
@@ -145,7 +145,7 @@ export declare class CacheEntry {
145
145
  * and this static method will decode it into a CacheEntry representing
146
146
  * the cached response.
147
147
  */
148
- static decode(buffer: Uint8Array): CacheEntry;
148
+ static decode(buffer: Uint8Array, options?: CacheEntryOptions): CacheEntry;
149
149
  static isGzipEntry(buffer: Uint8Array): boolean;
150
150
  /**
151
151
  * Encode status + headers (no body) as they appear at the start of
@@ -500,7 +500,7 @@ export class CacheEntry {
500
500
  * and this static method will decode it into a CacheEntry representing
501
501
  * the cached response.
502
502
  */
503
- static decode(buffer) {
503
+ static decode(buffer, options = {}) {
504
504
  const parsed = CacheEntry.#parseHead(buffer);
505
505
  if (!parsed)
506
506
  return emptyCacheEntry;
@@ -510,6 +510,7 @@ export class CacheEntry {
510
510
  integrity: parsed.integrity,
511
511
  trustIntegrity: true,
512
512
  contentLength: body.byteLength,
513
+ ...options,
513
514
  });
514
515
  c.#fromCache = true;
515
516
  c.#headSize = parsed.headSize;
@@ -22,7 +22,7 @@ const handleBeforeExit = () => {
22
22
  for (const [path, r] of registered) {
23
23
  /* c8 ignore next */
24
24
  if (!r.size)
25
- return;
25
+ continue;
26
26
  const env = { ...process.env };
27
27
  if (compileCacheDir)
28
28
  env.NODE_COMPILE_CACHE ??= compileCacheDir;
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
@@ -154,12 +154,23 @@ export class RegistryClient {
154
154
  await deleteToken(registry, this.identity);
155
155
  }
156
156
  /**
157
- * Log into the registry specified
157
+ * Log into the registry specified.
158
+ *
159
+ * When a list of registries is provided, the web login flow runs once
160
+ * against the first of them, and the token it returns is saved for all
161
+ * of them. This is for registries that share credentials -- like the
162
+ * ones under a single vlt.io account -- where opening the browser once
163
+ * per registry would just be asking for the same token again.
158
164
  *
159
165
  * Does not return the token or expose it, just saves to the auth keychain
160
166
  * and returns void if it worked. Otherwise, error is raised.
161
167
  */
162
168
  async login(registry) {
169
+ const registries = Array.isArray(registry) ? registry : [registry];
170
+ const [first] = registries;
171
+ if (!first) {
172
+ throw error('No registry provided to log in against');
173
+ }
163
174
  // - make POST to '/-/v1/login'
164
175
  // - include a body of {} and npm-auth-type:web
165
176
  // - get a {doneUrl, authUrl}
@@ -167,7 +178,7 @@ export class RegistryClient {
167
178
  // - hang on the doneUrl until done
168
179
  //
169
180
  // if that fails: fall back to couchdb login
170
- const webLoginURL = new URL('-/v1/login', registryBase(registry));
181
+ const webLoginURL = new URL('-/v1/login', registryBase(first));
171
182
  const response = await this.request(webLoginURL, {
172
183
  method: 'POST',
173
184
  useCache: false,
@@ -181,7 +192,10 @@ export class RegistryClient {
181
192
  const challenge = getWebAuthChallenge(response.json());
182
193
  if (challenge) {
183
194
  const result = await this.webAuthOpener(challenge);
184
- await setToken(registry, `Bearer ${result.token}`, this.identity);
195
+ // sequential, because they all write to the same keychain file
196
+ for (const reg of registries) {
197
+ await setToken(reg, `Bearer ${result.token}`, this.identity);
198
+ }
185
199
  return;
186
200
  }
187
201
  }
@@ -217,7 +231,9 @@ export class RegistryClient {
217
231
  const hit = this.#decoded.get(buffer);
218
232
  if (hit)
219
233
  return hit;
220
- const entry = CacheEntry.decode(buffer);
234
+ const entry = CacheEntry.decode(buffer, {
235
+ 'stale-while-revalidate-factor': this.staleWhileRevalidateFactor,
236
+ });
221
237
  // statusCode 0 == undecodable, and a cached JSON body that fails
222
238
  // to parse is corrupt. Treat both as a total miss: the caller
223
239
  // refetches without conditional headers, so a fresh response
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.5",
4
+ "version": "1.0.7",
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.5",
17
- "@vltpkg/cache-unzip": "1.0.5",
18
- "@vltpkg/error-cause": "1.0.5",
19
- "@vltpkg/keychain": "1.0.5",
20
- "@vltpkg/output": "1.0.5",
21
- "@vltpkg/types": "1.0.5",
22
- "@vltpkg/url-open": "1.0.5",
23
- "@vltpkg/xdg": "1.0.5",
16
+ "@vltpkg/cache": "1.0.7",
17
+ "@vltpkg/cache-unzip": "1.0.7",
18
+ "@vltpkg/error-cause": "1.0.7",
19
+ "@vltpkg/keychain": "1.0.7",
20
+ "@vltpkg/output": "1.0.7",
21
+ "@vltpkg/types": "1.0.7",
22
+ "@vltpkg/url-open": "1.0.7",
23
+ "@vltpkg/xdg": "1.0.7",
24
24
  "cache-control-parser": "^2.0.6",
25
25
  "package-json-from-dist": "^1.0.1",
26
26
  "undici": "^7.16.0"