@vltpkg/registry-client 1.6.4 → 1.8.0

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 CHANGED
@@ -173,6 +173,13 @@ export type RegistryClientRequestOptions = Omit<Dispatcher.RequestOptions, 'meth
173
173
  * @internal
174
174
  */
175
175
  forceRevalidate?: boolean | 'background';
176
+ /**
177
+ * Milliseconds the host gets to accept the connection. Unset: as long
178
+ * as the OS waits (minutes, for a host that drops packets). An abort
179
+ * can't end that wait, so a caller that would give up on such a host
180
+ * sets this. Such requests use a connection pool of their own.
181
+ */
182
+ connectTimeout?: number;
176
183
  };
177
184
  /**
178
185
  * The `User-Agent` header sent with every request. Re-exported from
package/dist/index.js CHANGED
@@ -64,20 +64,24 @@ export { userAgent };
64
64
  // of body handling.
65
65
  // keepAliveTimeoutThreshold: undici default. Values >= the server's
66
66
  // Keep-Alive hint (Node http: timeout=5) reset the socket every response.
67
+ const connectOptions = {
68
+ timeout: 600_000,
69
+ keepAlive: true,
70
+ keepAliveInitialDelay: 30_000,
71
+ sessionTimeout: 600,
72
+ };
67
73
  const agentOptions = {
68
74
  bodyTimeout: 600_000,
69
75
  headersTimeout: 600_000,
70
76
  keepAliveMaxTimeout: 1_200_000,
71
77
  keepAliveTimeout: 600_000,
72
- connect: {
73
- timeout: 600_000,
74
- keepAlive: true,
75
- keepAliveInitialDelay: 30_000,
76
- sessionTimeout: 600,
77
- },
78
+ connect: connectOptions,
78
79
  connections: Math.min(128, Math.max(64, (availableParallelism() - 1) * 8)),
79
80
  pipelining: 1,
80
81
  };
82
+ // a url's path without trailing slashes, and its query: `/` at the
83
+ // root of a host, as a request needs one
84
+ const requestPath = (u) => (u.pathname.replace(/\/+$/, '') || '/') + u.search;
81
85
  const xdg = new XDG('vlt');
82
86
  const defaultCacheMaxSize = 256 * 1024 * 1024;
83
87
  const parseCacheMaxSize = (raw) => {
@@ -100,6 +104,23 @@ export class RegistryClient {
100
104
  // request() calls not settled yet, awaited by drain()
101
105
  #inFlight = new Set();
102
106
  #signal;
107
+ #retryOptions;
108
+ // connectTimeout -> the agent whose connections get it
109
+ #agents = new Map();
110
+ /** what a request is sent with: its own `connectTimeout`, if any */
111
+ #agent(connectTimeout) {
112
+ if (connectTimeout === undefined)
113
+ return this.agent;
114
+ let agent = this.#agents.get(connectTimeout);
115
+ if (!agent) {
116
+ agent = new RetryAgent(getDispatcher({
117
+ ...agentOptions,
118
+ connect: { ...connectOptions, timeout: connectTimeout },
119
+ }), this.#retryOptions);
120
+ this.#agents.set(connectTimeout, agent);
121
+ }
122
+ return agent;
123
+ }
103
124
  /** the request's own signal joined with the client's */
104
125
  #withSignal(own) {
105
126
  const c = this.#signal;
@@ -132,7 +153,7 @@ export class RegistryClient {
132
153
  },
133
154
  });
134
155
  const dispatch = getDispatcher(agentOptions);
135
- this.agent = new RetryAgent(dispatch, {
156
+ this.#retryOptions = {
136
157
  maxRetries,
137
158
  timeoutFactor,
138
159
  minTimeout,
@@ -149,7 +170,8 @@ export class RegistryClient {
149
170
  'EPIPE',
150
171
  'UND_ERR_SOCKET',
151
172
  ],
152
- });
173
+ };
174
+ this.agent = new RetryAgent(dispatch, this.#retryOptions);
153
175
  }
154
176
  /**
155
177
  * Fetch the entire set of a paginated list of objects
@@ -626,14 +648,14 @@ export class RegistryClient {
626
648
  ...options,
627
649
  signal: this.#withSignal(options.signal),
628
650
  method: options.method ?? 'GET',
629
- path: u.pathname.replace(/\/+$/, '') + u.search,
651
+ path: requestPath(u),
630
652
  origin: u.origin,
631
653
  headers: addHeader(addHeader(addHeader(options.headers, 'accept-encoding', 'gzip;q=1.0, identity;q=0.5'), 'user-agent', userAgent), 'npm-session', this.#session),
632
654
  };
633
655
  o.headers = addHeader(o.headers, 'authorization', await getTokenByURL(String(u), this.identity, this.registryKeys, this.defaultRegistryKey));
634
656
  logRequest(url, 'start', { method: o.method });
635
657
  const requestStart = Date.now();
636
- const response = await this.agent.request(o);
658
+ const response = await this.#agent(options.connectTimeout).request(o);
637
659
  logRequest(url, 'complete', {
638
660
  method: o.method,
639
661
  statusCode: response.statusCode,
@@ -725,7 +747,7 @@ export class RegistryClient {
725
747
  const redirected = redirections.size > 0;
726
748
  redirections.add(String(url));
727
749
  // eslint-disable-next-line @typescript-eslint/no-deprecated -- deprecated for callers; this is the one place that sets it
728
- options.path = u.pathname.replace(/\/+$/, '') + u.search;
750
+ options.path = requestPath(u);
729
751
  options.origin = u.origin;
730
752
  options.headers = addHeader(addHeader(addHeader(options.headers, 'accept-encoding', 'gzip;q=1.0, identity;q=0.5'), 'user-agent', userAgent), 'npm-session', this.#session);
731
753
  if (otp) {
@@ -742,9 +764,9 @@ export class RegistryClient {
742
764
  // will remove if we don't have a token.
743
765
  options.headers = addHeader(options.headers, 'authorization', await getTokenByURL(String(u), this.identity, this.registryKeys, this.defaultRegistryKey));
744
766
  }
745
- let response = null;
767
+ let response;
746
768
  try {
747
- response = await this.agent.request(options);
769
+ response = await this.#agent(options.connectTimeout).request(options);
748
770
  /* c8 ignore start */
749
771
  }
750
772
  catch (er) {
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.6.4",
4
+ "version": "1.8.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -13,27 +13,27 @@
13
13
  "url": "http://vlt.sh"
14
14
  },
15
15
  "dependencies": {
16
- "@vltpkg/cache": "1.6.4",
17
- "@vltpkg/cache-unzip": "1.6.4",
18
- "@vltpkg/error-cause": "1.6.4",
19
- "@vltpkg/keychain": "1.6.4",
20
- "@vltpkg/output": "1.6.4",
21
- "@vltpkg/types": "1.6.4",
22
- "@vltpkg/url-open": "1.6.4",
23
- "@vltpkg/user-agent": "1.6.4",
24
- "@vltpkg/xdg": "1.6.4",
16
+ "@vltpkg/cache": "1.8.0",
17
+ "@vltpkg/cache-unzip": "1.8.0",
18
+ "@vltpkg/error-cause": "1.8.0",
19
+ "@vltpkg/keychain": "1.8.0",
20
+ "@vltpkg/output": "1.8.0",
21
+ "@vltpkg/types": "1.8.0",
22
+ "@vltpkg/url-open": "1.8.0",
23
+ "@vltpkg/user-agent": "1.8.0",
24
+ "@vltpkg/xdg": "1.8.0",
25
25
  "cache-control-parser": "^2.0.6",
26
26
  "undici": "^7.16.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@eslint/js": "^9.39.1",
29
+ "@eslint/js": "^10.0.1",
30
30
  "@types/node": "^22.19.2",
31
- "eslint": "^9.39.1",
31
+ "eslint": "^10.14.0",
32
32
  "prettier": "^3.7.4",
33
33
  "tap": "^21.8.0",
34
34
  "typedoc": "~0.27.9",
35
35
  "typescript": "5.7.3",
36
- "typescript-eslint": "^8.49.0"
36
+ "typescript-eslint": "^8.56.0"
37
37
  },
38
38
  "license": "BSD-2-Clause-Patent",
39
39
  "engines": {