@npm-safe/core-dsh 1.0.5
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/LICENSE +204 -0
- package/dist/index.d.ts +513 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +711 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/anthropic.d.ts +47 -0
- package/dist/llm/anthropic.d.ts.map +1 -0
- package/dist/llm/anthropic.js +161 -0
- package/dist/llm/anthropic.js.map +1 -0
- package/dist/llm/gemini.d.ts +47 -0
- package/dist/llm/gemini.d.ts.map +1 -0
- package/dist/llm/gemini.js +165 -0
- package/dist/llm/gemini.js.map +1 -0
- package/dist/llm/llm-config.d.ts +97 -0
- package/dist/llm/llm-config.d.ts.map +1 -0
- package/dist/llm/llm-config.js +188 -0
- package/dist/llm/llm-config.js.map +1 -0
- package/dist/llm/parse.d.ts +95 -0
- package/dist/llm/parse.d.ts.map +1 -0
- package/dist/llm/parse.js +158 -0
- package/dist/llm/parse.js.map +1 -0
- package/dist/llm/provider.d.ts +122 -0
- package/dist/llm/provider.d.ts.map +1 -0
- package/dist/llm/provider.js +206 -0
- package/dist/llm/provider.js.map +1 -0
- package/dist/registry/client.d.ts +164 -0
- package/dist/registry/client.d.ts.map +1 -0
- package/dist/registry/client.js +378 -0
- package/dist/registry/client.js.map +1 -0
- package/dist/registry/types.d.ts +226 -0
- package/dist/registry/types.d.ts.map +1 -0
- package/dist/registry/types.js +32 -0
- package/dist/registry/types.js.map +1 -0
- package/dist/registry/validator.d.ts +87 -0
- package/dist/registry/validator.d.ts.map +1 -0
- package/dist/registry/validator.js +214 -0
- package/dist/registry/validator.js.map +1 -0
- package/dist/scanner/ci-scan.d.ts +82 -0
- package/dist/scanner/ci-scan.d.ts.map +1 -0
- package/dist/scanner/ci-scan.js +130 -0
- package/dist/scanner/ci-scan.js.map +1 -0
- package/dist/scanner/rule-config.d.ts +61 -0
- package/dist/scanner/rule-config.d.ts.map +1 -0
- package/dist/scanner/rule-config.js +103 -0
- package/dist/scanner/rule-config.js.map +1 -0
- package/dist/scanner/rule-loader.d.ts +28 -0
- package/dist/scanner/rule-loader.d.ts.map +1 -0
- package/dist/scanner/rule-loader.js +67 -0
- package/dist/scanner/rule-loader.js.map +1 -0
- package/dist/scanner/static-rules.d.ts +88 -0
- package/dist/scanner/static-rules.d.ts.map +1 -0
- package/dist/scanner/static-rules.js +723 -0
- package/dist/scanner/static-rules.js.map +1 -0
- package/dist/scanner/types.d.ts +177 -0
- package/dist/scanner/types.d.ts.map +1 -0
- package/dist/scanner/types.js +53 -0
- package/dist/scanner/types.js.map +1 -0
- package/dist/scheduler/rate-limiter.d.ts +74 -0
- package/dist/scheduler/rate-limiter.d.ts.map +1 -0
- package/dist/scheduler/rate-limiter.js +182 -0
- package/dist/scheduler/rate-limiter.js.map +1 -0
- package/dist/scheduler/refresh-scheduler.d.ts +201 -0
- package/dist/scheduler/refresh-scheduler.d.ts.map +1 -0
- package/dist/scheduler/refresh-scheduler.js +295 -0
- package/dist/scheduler/refresh-scheduler.js.map +1 -0
- package/dist/store/cache-manager.d.ts +166 -0
- package/dist/store/cache-manager.d.ts.map +1 -0
- package/dist/store/cache-manager.js +356 -0
- package/dist/store/cache-manager.js.map +1 -0
- package/dist/store/database.d.ts +81 -0
- package/dist/store/database.d.ts.map +1 -0
- package/dist/store/database.js +182 -0
- package/dist/store/database.js.map +1 -0
- package/dist/store/schema.d.ts +42 -0
- package/dist/store/schema.d.ts.map +1 -0
- package/dist/store/schema.js +126 -0
- package/dist/store/schema.js.map +1 -0
- package/dist/translator/provider.d.ts +152 -0
- package/dist/translator/provider.d.ts.map +1 -0
- package/dist/translator/provider.js +159 -0
- package/dist/translator/provider.js.map +1 -0
- package/dist/translator/types.d.ts +83 -0
- package/dist/translator/types.d.ts.map +1 -0
- package/dist/translator/types.js +58 -0
- package/dist/translator/types.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the npm registry API v2.
|
|
3
|
+
*
|
|
4
|
+
* This module provides {@link NpmRegistryClient}, a thin wrapper around the
|
|
5
|
+
* global `fetch` (available in Node 18+) that adds:
|
|
6
|
+
*
|
|
7
|
+
* - **Timeout**: each request is aborted after 10 seconds via an
|
|
8
|
+
* `AbortController`.
|
|
9
|
+
* - **Retry with exponential backoff**: failed requests (network errors or
|
|
10
|
+
* non-2xx responses) are retried up to 3 times with delays of 1s, 2s, and
|
|
11
|
+
* 4s between attempts.
|
|
12
|
+
* - **Compression**: the `Accept-Encoding` header advertises gzip and
|
|
13
|
+
* deflate support.
|
|
14
|
+
* - **User-Agent**: a customisable UA header is sent on every request.
|
|
15
|
+
* - **Typed errors**: non-success responses and unrecoverable failures are
|
|
16
|
+
* surfaced as {@link NpmRegistryError} carrying the HTTP status code and
|
|
17
|
+
* status text.
|
|
18
|
+
*
|
|
19
|
+
* The client intentionally contains **no caching** and **no rate limiting**
|
|
20
|
+
* — those concerns are delegated to dedicated modules layered on top.
|
|
21
|
+
*
|
|
22
|
+
* @module registry/client
|
|
23
|
+
*/
|
|
24
|
+
import { NpmRegistryError } from './types.js';
|
|
25
|
+
import { ProxyAgent } from 'undici';
|
|
26
|
+
/**
|
|
27
|
+
* Default registry base URL used when no `baseUrl` is supplied to the
|
|
28
|
+
* constructor.
|
|
29
|
+
*/
|
|
30
|
+
const DEFAULT_BASE_URL = 'https://registry.npmjs.org';
|
|
31
|
+
/**
|
|
32
|
+
* Default User-Agent string sent when no `userAgent` is supplied. Includes
|
|
33
|
+
* the package name and a Node version hint so the registry can identify the
|
|
34
|
+
* client.
|
|
35
|
+
*/
|
|
36
|
+
const DEFAULT_USER_AGENT = '@npm-safe/core (https://npmjs.org)';
|
|
37
|
+
/**
|
|
38
|
+
* Per-request timeout in milliseconds. Each fetch attempt is aborted if it
|
|
39
|
+
* does not complete within this window.
|
|
40
|
+
*/
|
|
41
|
+
const REQUEST_TIMEOUT_MS = 10_000;
|
|
42
|
+
/**
|
|
43
|
+
* Number of attempts made before giving up. The first attempt plus
|
|
44
|
+
* {@link RETRY_BACKOFF_MS}.length - 1 retries equals this value.
|
|
45
|
+
*/
|
|
46
|
+
const MAX_ATTEMPTS = 3;
|
|
47
|
+
/**
|
|
48
|
+
* Exponential backoff delays (in milliseconds) applied between retry
|
|
49
|
+
* attempts. The first attempt is immediate; subsequent attempts wait for the
|
|
50
|
+
* corresponding entry in this array before retrying.
|
|
51
|
+
*/
|
|
52
|
+
const RETRY_BACKOFF_MS = [1_000, 2_000, 4_000];
|
|
53
|
+
/**
|
|
54
|
+
* Resolve a proxy URL from the environment. Conventional proxy variables
|
|
55
|
+
* are checked in a case-insensitive manner. Returns `undefined` when no
|
|
56
|
+
* proxy is configured.
|
|
57
|
+
*/
|
|
58
|
+
function envProxyUrl() {
|
|
59
|
+
const candidates = [
|
|
60
|
+
process.env.HTTPS_PROXY,
|
|
61
|
+
process.env.https_proxy,
|
|
62
|
+
process.env.HTTP_PROXY,
|
|
63
|
+
process.env.http_proxy,
|
|
64
|
+
process.env.ALL_PROXY,
|
|
65
|
+
process.env.all_proxy,
|
|
66
|
+
];
|
|
67
|
+
for (const candidate of candidates) {
|
|
68
|
+
if (candidate && candidate.trim().length > 0)
|
|
69
|
+
return candidate;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parse the `NO_PROXY` environment variable into a set of lowercased
|
|
75
|
+
* hostnames (and optional `*` wildcard). Empty entries are ignored.
|
|
76
|
+
*/
|
|
77
|
+
function parseNoProxy() {
|
|
78
|
+
const raw = process.env.NO_PROXY ?? process.env.no_proxy ?? '';
|
|
79
|
+
return new Set(raw
|
|
80
|
+
.split(',')
|
|
81
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
82
|
+
.filter((entry) => entry.length > 0));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Determine whether a hostname should bypass the configured proxy per the
|
|
86
|
+
* `NO_PROXY` list. Exact matches, suffix matches (`.example.com` covers
|
|
87
|
+
* `api.example.com`), and the `*` wildcard all bypass.
|
|
88
|
+
*/
|
|
89
|
+
function isNoProxyHost(host, noProxy) {
|
|
90
|
+
if (noProxy.has('*'))
|
|
91
|
+
return true;
|
|
92
|
+
for (const entry of noProxy) {
|
|
93
|
+
const normalized = entry.startsWith('.') ? entry.slice(1) : entry;
|
|
94
|
+
if (host === normalized)
|
|
95
|
+
return true;
|
|
96
|
+
if (host.endsWith(`.${normalized}`))
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Sleep for the given number of milliseconds. Resolves once the timer
|
|
103
|
+
* elapses; never rejects.
|
|
104
|
+
*
|
|
105
|
+
* @param ms - Duration to sleep in milliseconds.
|
|
106
|
+
* @returns A promise that resolves after the delay.
|
|
107
|
+
*/
|
|
108
|
+
function sleep(ms) {
|
|
109
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* HTTP client for the npm registry.
|
|
113
|
+
*
|
|
114
|
+
* Construct an instance once and reuse it across calls — the client holds no
|
|
115
|
+
* per-request mutable state beyond the configured base URL and User-Agent.
|
|
116
|
+
* All public methods are async and return parsed, typed JSON payloads.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const client = new NpmRegistryClient();
|
|
121
|
+
* const meta = await client.getPackageMetadata('lodash');
|
|
122
|
+
* const manifest = await client.getVersionManifest('lodash', '4.17.21');
|
|
123
|
+
* const hits = await client.searchPackages('security', 10);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export class NpmRegistryClient {
|
|
127
|
+
/** Base URL (no trailing slash) prepended to every request path. */
|
|
128
|
+
baseUrl;
|
|
129
|
+
/** User-Agent header value sent on every request. */
|
|
130
|
+
userAgent;
|
|
131
|
+
/** Explicit proxy URL from constructor options (highest priority). */
|
|
132
|
+
proxyUrl;
|
|
133
|
+
/** Proxy dispatchers keyed by proxy URL, lazily created. */
|
|
134
|
+
proxyAgents = new Map();
|
|
135
|
+
/** Hosts that must bypass the proxy. */
|
|
136
|
+
noProxyHosts;
|
|
137
|
+
/**
|
|
138
|
+
* @param options - Optional configuration overriding the defaults.
|
|
139
|
+
* @param options.baseUrl - Registry base URL. Defaults to
|
|
140
|
+
* `https://registry.npmjs.org`. A trailing slash is stripped.
|
|
141
|
+
* @param options.userAgent - User-Agent header value. Defaults to a
|
|
142
|
+
* string identifying `@npm-safe/core`.
|
|
143
|
+
* @param options.proxy - Proxy URL (e.g. `http://127.0.0.1:7897`). When
|
|
144
|
+
* omitted, the conventional environment variables are consulted.
|
|
145
|
+
*/
|
|
146
|
+
constructor(options) {
|
|
147
|
+
const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
|
|
148
|
+
// Strip a single trailing slash so callers may pass either form.
|
|
149
|
+
this.baseUrl =
|
|
150
|
+
baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
|
151
|
+
this.userAgent = options?.userAgent ?? DEFAULT_USER_AGENT;
|
|
152
|
+
this.proxyUrl = options?.proxy ?? envProxyUrl();
|
|
153
|
+
this.noProxyHosts = parseNoProxy();
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Resolve the fetch `dispatcher` to use for a request URL.
|
|
157
|
+
*
|
|
158
|
+
* Returns `undefined` when no proxy is configured or the hostname is in
|
|
159
|
+
* the `NO_PROXY` list; otherwise returns a lazily created
|
|
160
|
+
* {@link Dispatcher} for the active proxy.
|
|
161
|
+
*
|
|
162
|
+
* @param url - Fully-qualified request URL.
|
|
163
|
+
* @returns A proxy dispatcher, or `undefined` to use the default fetch.
|
|
164
|
+
*/
|
|
165
|
+
getDispatcher(url) {
|
|
166
|
+
let host = '';
|
|
167
|
+
try {
|
|
168
|
+
host = new URL(url).hostname.toLowerCase();
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
if (isNoProxyHost(host, this.noProxyHosts))
|
|
174
|
+
return undefined;
|
|
175
|
+
const proxy = this.proxyUrl;
|
|
176
|
+
if (!proxy)
|
|
177
|
+
return undefined;
|
|
178
|
+
let agent = this.proxyAgents.get(proxy);
|
|
179
|
+
if (!agent) {
|
|
180
|
+
agent = new ProxyAgent(proxy);
|
|
181
|
+
this.proxyAgents.set(proxy, agent);
|
|
182
|
+
}
|
|
183
|
+
return agent;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Fetch the full packument (metadata) for a package.
|
|
187
|
+
*
|
|
188
|
+
* Issues `GET {baseUrl}/{name}` and returns the parsed
|
|
189
|
+
* {@link PackageMetadata} document, which includes all published versions,
|
|
190
|
+
* dist-tags, and the readme.
|
|
191
|
+
*
|
|
192
|
+
* @param name - Package name (scoped names include the leading `@`).
|
|
193
|
+
* @param options - Optional request options. `options.signal` is forwarded
|
|
194
|
+
* to the underlying fetch as part of a combined abort signal; an external
|
|
195
|
+
* abort settles the promise promptly with an `AbortError` `DOMException`
|
|
196
|
+
* (no retry).
|
|
197
|
+
* @returns The full package metadata document.
|
|
198
|
+
* @throws {NpmRegistryError} When the request fails after all retries or
|
|
199
|
+
* the registry returns a non-2xx status.
|
|
200
|
+
* @throws {DOMException} With name `AbortError` when `options.signal` is
|
|
201
|
+
* aborted.
|
|
202
|
+
*/
|
|
203
|
+
async getPackageMetadata(name, options) {
|
|
204
|
+
return this.request(`${this.baseUrl}/${encodeName(name)}`, options);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Fetch the abbreviated packument for a single published version.
|
|
208
|
+
*
|
|
209
|
+
* Issues `GET {baseUrl}/{name}/{version}` and returns the parsed
|
|
210
|
+
* {@link AbbreviatedVersion} manifest.
|
|
211
|
+
*
|
|
212
|
+
* @param name - Package name (scoped names include the leading `@`).
|
|
213
|
+
* @param version - Semver version string (e.g. `4.17.21`).
|
|
214
|
+
* @returns The abbreviated version manifest.
|
|
215
|
+
* @throws {NpmRegistryError} When the request fails after all retries or
|
|
216
|
+
* the registry returns a non-2xx status.
|
|
217
|
+
*/
|
|
218
|
+
async getVersionManifest(name, version) {
|
|
219
|
+
return this.request(`${this.baseUrl}/${encodeName(name)}/${encodeURIComponent(version)}`);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Search the registry for packages matching a text query.
|
|
223
|
+
*
|
|
224
|
+
* Issues `GET {baseUrl}/-/v1/search?text={query}&size={size}` and returns
|
|
225
|
+
* the array of {@link SearchResult} hits. The `size` parameter caps the
|
|
226
|
+
* number of results (the registry imposes its own upper bound).
|
|
227
|
+
*
|
|
228
|
+
* @param query - Free-text search query.
|
|
229
|
+
* @param options - Optional search options. `options.size` caps the number
|
|
230
|
+
* of results (defaults to 20); `options.signal` is forwarded to the
|
|
231
|
+
* underlying fetch as part of a combined abort signal.
|
|
232
|
+
* @returns An array of search-result hits, ordered by relevance.
|
|
233
|
+
* @throws {NpmRegistryError} When the request fails after all retries or
|
|
234
|
+
* the registry returns a non-2xx status.
|
|
235
|
+
* @throws {DOMException} With name `AbortError` when `options.signal` is
|
|
236
|
+
* aborted.
|
|
237
|
+
*/
|
|
238
|
+
async searchPackages(query, options) {
|
|
239
|
+
const size = options?.size ?? 20;
|
|
240
|
+
const url = `${this.baseUrl}/-/v1/search?text=${encodeURIComponent(query)}&size=${encodeURIComponent(String(size))}`;
|
|
241
|
+
const body = await this.request(url, options);
|
|
242
|
+
// Normalise the raw response into the public SearchResult shape. The
|
|
243
|
+
// registry omits `searchScore` on some responses, so default to the
|
|
244
|
+
// final score when absent.
|
|
245
|
+
return body.objects.map((hit) => ({
|
|
246
|
+
package: hit.package,
|
|
247
|
+
score: hit.score,
|
|
248
|
+
searchScore: hit.searchScore ?? hit.score.final,
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Perform a single HTTP GET against `url` with timeout and retry.
|
|
253
|
+
*
|
|
254
|
+
* The request is retried up to {@link MAX_ATTEMPTS} times with exponential
|
|
255
|
+
* backoff (1s, 2s, 4s). A retry is attempted when:
|
|
256
|
+
*
|
|
257
|
+
* - The fetch rejects (network error, DNS failure, abort due to the owned
|
|
258
|
+
* timeout controller).
|
|
259
|
+
* - The response status is not in the 2xx range.
|
|
260
|
+
*
|
|
261
|
+
* On the final attempt the underlying error (or a new
|
|
262
|
+
* {@link NpmRegistryError} for non-2xx responses) is rethrown.
|
|
263
|
+
*
|
|
264
|
+
* **Cooperative cancellation**: when `options.signal` is supplied it is
|
|
265
|
+
* combined with the per-request timeout controller via `AbortSignal.any`.
|
|
266
|
+
* An external abort (`options.signal` aborted) breaks the retry loop
|
|
267
|
+
* immediately and rethrows `DOMException('The operation was aborted.',
|
|
268
|
+
* 'AbortError')` with NO retry — the abort is never swallowed as a
|
|
269
|
+
* retryable timeout. Only the owned timeout controller keeps the existing
|
|
270
|
+
* wrap-as-`NpmRegistryError` + retry behaviour.
|
|
271
|
+
*
|
|
272
|
+
* @typeParam T - Expected shape of the parsed JSON response.
|
|
273
|
+
* @param url - Fully-qualified URL to fetch.
|
|
274
|
+
* @param options - Optional request options. `options.signal` is an
|
|
275
|
+
* external abort signal forwarded by callers.
|
|
276
|
+
* @returns The parsed JSON response body typed as `T`.
|
|
277
|
+
* @throws {NpmRegistryError} When all attempts are exhausted or the
|
|
278
|
+
* registry returns a non-2xx status on the final attempt.
|
|
279
|
+
* @throws {DOMException} With name `AbortError` when `options.signal` is
|
|
280
|
+
* aborted.
|
|
281
|
+
*/
|
|
282
|
+
async request(url, options) {
|
|
283
|
+
let lastError = null;
|
|
284
|
+
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
285
|
+
// An already-aborted external signal short-circuits before any
|
|
286
|
+
// backoff sleep or fetch attempt: the abort must settle promptly
|
|
287
|
+
// with AbortError and must NOT be retried.
|
|
288
|
+
if (options?.signal?.aborted) {
|
|
289
|
+
throw new DOMException('The operation was aborted.', 'AbortError');
|
|
290
|
+
}
|
|
291
|
+
// Back off before every retry (skip on the first attempt).
|
|
292
|
+
if (attempt > 1) {
|
|
293
|
+
await sleep(RETRY_BACKOFF_MS[attempt - 2]);
|
|
294
|
+
}
|
|
295
|
+
const controller = new AbortController();
|
|
296
|
+
const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
297
|
+
try {
|
|
298
|
+
const dispatcher = this.getDispatcher(url);
|
|
299
|
+
// Combine the owned timeout controller with the external abort
|
|
300
|
+
// signal so either one aborts the fetch. When no external signal
|
|
301
|
+
// is supplied the owned controller is used directly.
|
|
302
|
+
const combinedSignal = options?.signal
|
|
303
|
+
? AbortSignal.any([controller.signal, options.signal])
|
|
304
|
+
: controller.signal;
|
|
305
|
+
const init = {
|
|
306
|
+
method: 'GET',
|
|
307
|
+
headers: {
|
|
308
|
+
Accept: 'application/json',
|
|
309
|
+
'Accept-Encoding': 'gzip, deflate',
|
|
310
|
+
'User-Agent': this.userAgent,
|
|
311
|
+
},
|
|
312
|
+
signal: combinedSignal,
|
|
313
|
+
};
|
|
314
|
+
if (dispatcher) {
|
|
315
|
+
// undici's fetch accepts a `dispatcher` option to route the request
|
|
316
|
+
// through a custom agent (e.g. a proxy).
|
|
317
|
+
init.dispatcher = dispatcher;
|
|
318
|
+
}
|
|
319
|
+
const response = await fetch(url, init);
|
|
320
|
+
if (!response.ok) {
|
|
321
|
+
const statusText = response.statusText;
|
|
322
|
+
const message = `Registry request to ${url} failed: ${response.status} ${statusText}`;
|
|
323
|
+
const error = new NpmRegistryError(message, response.status, statusText);
|
|
324
|
+
lastError = error;
|
|
325
|
+
// Non-2xx is retryable: continue to the next attempt.
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
return (await response.json());
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
// An abort triggered by the EXTERNAL signal must break the retry
|
|
332
|
+
// loop and propagate as AbortError — it is never a retryable
|
|
333
|
+
// timeout. This is the cooperative-cancellation contract.
|
|
334
|
+
if (options?.signal?.aborted) {
|
|
335
|
+
throw new DOMException('The operation was aborted.', 'AbortError');
|
|
336
|
+
}
|
|
337
|
+
// An abort triggered by our OWN timeout controller is surfaced as
|
|
338
|
+
// an NpmRegistryError so callers see a consistent error type, and
|
|
339
|
+
// remains retryable.
|
|
340
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
341
|
+
lastError = new NpmRegistryError(`Registry request to ${url} timed out after ${REQUEST_TIMEOUT_MS}ms.`);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
lastError = error;
|
|
345
|
+
}
|
|
346
|
+
// Network/parse errors are retryable: continue to the next attempt.
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
finally {
|
|
350
|
+
clearTimeout(timeoutId);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// All attempts exhausted. Rethrow the last captured error, wrapping
|
|
354
|
+
// non-NpmRegistryError values so callers always see a typed error.
|
|
355
|
+
if (lastError instanceof NpmRegistryError) {
|
|
356
|
+
throw lastError;
|
|
357
|
+
}
|
|
358
|
+
if (lastError instanceof Error) {
|
|
359
|
+
throw new NpmRegistryError(`Registry request to ${url} failed after ${MAX_ATTEMPTS} attempts: ${lastError.message}`);
|
|
360
|
+
}
|
|
361
|
+
throw new NpmRegistryError(`Registry request to ${url} failed after ${MAX_ATTEMPTS} attempts.`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Percent-encode a package name for use in a registry URL path segment.
|
|
366
|
+
*
|
|
367
|
+
* Scoped names (`@scope/name`) are encoded so the embedded `/` becomes
|
|
368
|
+
* `%2F`, producing a single path segment. The npm registry accepts both the
|
|
369
|
+
* raw and percent-encoded forms; the encoded form is used here to avoid any
|
|
370
|
+
* ambiguity with path separators.
|
|
371
|
+
*
|
|
372
|
+
* @param name - Package name (scoped names include the leading `@`).
|
|
373
|
+
* @returns The percent-encoded name safe for use in a URL path.
|
|
374
|
+
*/
|
|
375
|
+
function encodeName(name) {
|
|
376
|
+
return encodeURIComponent(name);
|
|
377
|
+
}
|
|
378
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/registry/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAOH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGpC;;;GAGG;AACH,MAAM,gBAAgB,GAAG,4BAA4B,CAAC;AAEtD;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,oCAAoC,CAAC;AAEhE;;;GAGG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC;;;GAGG;AACH,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB;;;;GAIG;AACH,MAAM,gBAAgB,GAA0B,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAEtE;;;;GAIG;AACH,SAAS,WAAW;IAClB,MAAM,UAAU,GAAG;QACjB,OAAO,CAAC,GAAG,CAAC,WAAW;QACvB,OAAO,CAAC,GAAG,CAAC,WAAW;QACvB,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,OAAO,CAAC,GAAG,CAAC,SAAS;QACrB,OAAO,CAAC,GAAG,CAAC,SAAS;KACtB,CAAC;IACF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,SAAS,CAAC;IACjE,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,SAAS,YAAY;IACnB,MAAM,GAAG,GAA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AAC;QAClB,CAAC;QACD,IAAI,SAAS,YAAY,KAAK,EAAE,CAAC;YAC/B,MAAM,IAAI,gBAAgB,CACxB,uBAAuB,GAAG,iBAAiB,YAAY,cAAc,SAAS,CAAC,OAAO,EAAE,CACzF,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,gBAAgB,CACxB,uBAAuB,GAAG,iBAAiB,YAAY,YAAY,CACpE,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for the npm registry API v2.
|
|
3
|
+
*
|
|
4
|
+
* This file is the foundational types module for the registry package. It
|
|
5
|
+
* contains no runtime code and no local imports — only type declarations
|
|
6
|
+
* describing the shapes returned by the npm registry's JSON endpoints
|
|
7
|
+
* (package metadata, abbreviated packuments, search results) plus the
|
|
8
|
+
* utility types used across the registry layer.
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A person or entity associated with a package, either as an author or a
|
|
14
|
+
* maintainer. npm accepts both the structured form and a free-form string.
|
|
15
|
+
*/
|
|
16
|
+
export type PackagePerson = {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly email?: string;
|
|
19
|
+
readonly url?: string;
|
|
20
|
+
} | string;
|
|
21
|
+
/**
|
|
22
|
+
* Repository descriptor for a package. May be a structured object with a
|
|
23
|
+
* type and url, or a shorthand string (e.g. `github:user/repo`).
|
|
24
|
+
*/
|
|
25
|
+
export type PackageRepository = {
|
|
26
|
+
readonly type: string;
|
|
27
|
+
readonly url: string;
|
|
28
|
+
} | string;
|
|
29
|
+
/**
|
|
30
|
+
* Distribution metadata attached to a published package version. Returned
|
|
31
|
+
* by the registry under the `dist` key of each version entry.
|
|
32
|
+
*/
|
|
33
|
+
export interface DistMetadata {
|
|
34
|
+
/** Subresource Integrity (SRI) hash, e.g. `sha512-...`. */
|
|
35
|
+
readonly integrity?: string;
|
|
36
|
+
/** Legacy SHA-1 hex digest of the tarball. */
|
|
37
|
+
readonly shasum?: string;
|
|
38
|
+
/** Absolute URL to the downloadable `.tgz` tarball. */
|
|
39
|
+
readonly tarball: string;
|
|
40
|
+
/** Number of files contained in the tarball. */
|
|
41
|
+
readonly fileCount?: number;
|
|
42
|
+
/** Unpacked size of the tarball contents in bytes. */
|
|
43
|
+
readonly unpackedSize?: number;
|
|
44
|
+
/** Cryptographic signatures attached to the tarball. */
|
|
45
|
+
readonly signatures?: ReadonlyArray<{
|
|
46
|
+
readonly keyid: string;
|
|
47
|
+
readonly sig: string;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Abbreviated packument for a single published version. This is the shape
|
|
52
|
+
* used by the registry's abbreviated metadata endpoint and by the `versions`
|
|
53
|
+
* map inside {@link PackageMetadata}.
|
|
54
|
+
*/
|
|
55
|
+
export interface AbbreviatedVersion {
|
|
56
|
+
/** Package name (scoped names include the leading `@`). */
|
|
57
|
+
readonly name: string;
|
|
58
|
+
/** Semver version string. */
|
|
59
|
+
readonly version: string;
|
|
60
|
+
/** Legacy SHA-1 hex digest (mirrored from `dist.shasum`). */
|
|
61
|
+
readonly shasum?: string;
|
|
62
|
+
/** Subresource Integrity hash (mirrored from `dist.integrity`). */
|
|
63
|
+
readonly integrity?: string;
|
|
64
|
+
/** Runtime dependency ranges keyed by package name. */
|
|
65
|
+
readonly dependencies?: Readonly<Record<string, string>>;
|
|
66
|
+
/** Development-only dependency ranges keyed by package name. */
|
|
67
|
+
readonly devDependencies?: Readonly<Record<string, string>>;
|
|
68
|
+
/** Optional dependency ranges keyed by package name. */
|
|
69
|
+
readonly optionalDependencies?: Readonly<Record<string, string>>;
|
|
70
|
+
/** Peer dependency ranges keyed by package name. */
|
|
71
|
+
readonly peerDependencies?: Readonly<Record<string, string>>;
|
|
72
|
+
/** Names of bundled dependencies. */
|
|
73
|
+
readonly bundleDependencies?: ReadonlyArray<string>;
|
|
74
|
+
/** Deprecation message; presence marks the version as deprecated. */
|
|
75
|
+
readonly deprecated?: string;
|
|
76
|
+
/** Whether the version ships an install lifecycle script. */
|
|
77
|
+
readonly hasInstallScript?: boolean;
|
|
78
|
+
/** Whether the version ships an npm-shrinkwrap.json. */
|
|
79
|
+
readonly hasShrinkwrap?: boolean;
|
|
80
|
+
/** Distribution metadata for the tarball. */
|
|
81
|
+
readonly dist: DistMetadata;
|
|
82
|
+
/** Engine constraints keyed by engine name (e.g. `node`, `npm`). */
|
|
83
|
+
readonly engines?: Readonly<Record<string, string>>;
|
|
84
|
+
/** Internal flag mirroring {@link hasShrinkwrap}. */
|
|
85
|
+
readonly _hasShrinkwrap?: boolean;
|
|
86
|
+
/** Lifecycle scripts keyed by script name. */
|
|
87
|
+
readonly scripts?: Readonly<Record<string, string>>;
|
|
88
|
+
/** Executable binaries exposed by the package, keyed by bin name. */
|
|
89
|
+
readonly bin?: Readonly<Record<string, string>>;
|
|
90
|
+
/** Legacy directory layout descriptors. */
|
|
91
|
+
readonly directories?: Readonly<Record<string, string>>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Full package metadata (packument) as returned by the registry's
|
|
95
|
+
* `GET /{package}` endpoint. The `versions` map is keyed by semver version
|
|
96
|
+
* string and contains abbreviated version entries.
|
|
97
|
+
*/
|
|
98
|
+
export interface PackageMetadata {
|
|
99
|
+
/** Package name (scoped names include the leading `@`). */
|
|
100
|
+
readonly name: string;
|
|
101
|
+
/** ISO-8601 timestamp of the most recent modification. */
|
|
102
|
+
readonly modified: string;
|
|
103
|
+
/** Distribution tags keyed by tag name (e.g. `latest`) pointing to versions. */
|
|
104
|
+
readonly 'dist-tags': Readonly<Record<string, string>>;
|
|
105
|
+
/** All published versions keyed by semver version string. */
|
|
106
|
+
readonly versions: Readonly<Record<string, AbbreviatedVersion>>;
|
|
107
|
+
/** Short human-readable description. */
|
|
108
|
+
readonly description?: string;
|
|
109
|
+
/** URL to the package's homepage. */
|
|
110
|
+
readonly homepage?: string;
|
|
111
|
+
/** Source repository descriptor. */
|
|
112
|
+
readonly repository?: PackageRepository;
|
|
113
|
+
/** Search/discoverability keywords. */
|
|
114
|
+
readonly keywords?: ReadonlyArray<string>;
|
|
115
|
+
/** Original package author. */
|
|
116
|
+
readonly author?: PackagePerson;
|
|
117
|
+
/** Current maintainers of the package. */
|
|
118
|
+
readonly maintainers?: ReadonlyArray<{
|
|
119
|
+
readonly name: string;
|
|
120
|
+
readonly email: string;
|
|
121
|
+
}>;
|
|
122
|
+
/** SPDX license identifier or license text. */
|
|
123
|
+
readonly license?: string;
|
|
124
|
+
/** Full readme contents. */
|
|
125
|
+
readonly readme?: string;
|
|
126
|
+
/** Filename of the readme (e.g. `README.md`). */
|
|
127
|
+
readonly readmeFilename?: string;
|
|
128
|
+
/** Publication timestamps keyed by version (plus `created`/`modified`). */
|
|
129
|
+
readonly time?: Readonly<Record<string, string>>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* A single hit from the registry's `GET /-/v1/search` endpoint.
|
|
133
|
+
*/
|
|
134
|
+
export interface SearchResult {
|
|
135
|
+
/** The package document portion of the search hit. */
|
|
136
|
+
readonly package: {
|
|
137
|
+
/** Package name (scoped names include the leading `@`). */
|
|
138
|
+
readonly name: string;
|
|
139
|
+
/** Scope of the package without the `@`, or empty string if unscoped. */
|
|
140
|
+
readonly scope: string;
|
|
141
|
+
/** Semver version of the hit (typically the latest). */
|
|
142
|
+
readonly version: string;
|
|
143
|
+
/** Short human-readable description. */
|
|
144
|
+
readonly description?: string;
|
|
145
|
+
/** Search/discoverability keywords. */
|
|
146
|
+
readonly keywords?: ReadonlyArray<string>;
|
|
147
|
+
/** ISO-8601 publication timestamp of the version. */
|
|
148
|
+
readonly date: string;
|
|
149
|
+
/** Canonical links for the package. */
|
|
150
|
+
readonly links: {
|
|
151
|
+
/** URL to the package page on the registry. */
|
|
152
|
+
readonly npm: string;
|
|
153
|
+
/** URL to the package's homepage. */
|
|
154
|
+
readonly homepage?: string;
|
|
155
|
+
/** URL to the source repository. */
|
|
156
|
+
readonly repository?: string;
|
|
157
|
+
/** URL to the issue tracker. */
|
|
158
|
+
readonly bugs?: string;
|
|
159
|
+
};
|
|
160
|
+
/** Publisher of the version. */
|
|
161
|
+
readonly publisher: {
|
|
162
|
+
readonly username: string;
|
|
163
|
+
readonly email: string;
|
|
164
|
+
};
|
|
165
|
+
/** Maintainers of the package. */
|
|
166
|
+
readonly maintainers: ReadonlyArray<{
|
|
167
|
+
readonly username: string;
|
|
168
|
+
readonly email: string;
|
|
169
|
+
}>;
|
|
170
|
+
};
|
|
171
|
+
/** Search relevance and quality scores. */
|
|
172
|
+
readonly score: {
|
|
173
|
+
/** Aggregated final score in the range [0, 1]. */
|
|
174
|
+
readonly final: number;
|
|
175
|
+
/** Breakdown of the final score into sub-scores. */
|
|
176
|
+
readonly detail: {
|
|
177
|
+
/** Quality sub-score in the range [0, 1]. */
|
|
178
|
+
readonly quality: number;
|
|
179
|
+
/** Popularity sub-score in the range [0, 1]. */
|
|
180
|
+
readonly popularity: number;
|
|
181
|
+
/** Maintenance sub-score in the range [0, 1]. */
|
|
182
|
+
readonly maintenance: number;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
/** Internal search score used for ranking; may differ from `score.final`. */
|
|
186
|
+
readonly searchScore: number;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Error thrown by registry clients when a request fails or returns a
|
|
190
|
+
* non-success status. Carries the HTTP status code and status text when
|
|
191
|
+
* available so callers can branch on specific failure modes.
|
|
192
|
+
*/
|
|
193
|
+
export declare class NpmRegistryError extends Error {
|
|
194
|
+
readonly statusCode?: number | undefined;
|
|
195
|
+
readonly statusText?: string | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* @param message - Human-readable error message.
|
|
198
|
+
* @param statusCode - HTTP status code from the response, if any.
|
|
199
|
+
* @param statusText - HTTP status text from the response, if any.
|
|
200
|
+
*/
|
|
201
|
+
constructor(message: string, statusCode?: number | undefined, statusText?: string | undefined);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Outcome of validating a package identifier or version string.
|
|
205
|
+
*/
|
|
206
|
+
export interface ValidationResult {
|
|
207
|
+
/** `true` when the validated value is acceptable. */
|
|
208
|
+
readonly valid: boolean;
|
|
209
|
+
/** Human-readable explanation when {@link valid} is `false`. */
|
|
210
|
+
readonly reason?: string;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* A parsed package identifier combining name, optional scope, and optional
|
|
214
|
+
* version into a single immutable value.
|
|
215
|
+
*/
|
|
216
|
+
export interface PackageIdentifier {
|
|
217
|
+
/** Package name without scope prefix. */
|
|
218
|
+
readonly name: string;
|
|
219
|
+
/** Semver version string, if specified. */
|
|
220
|
+
readonly version?: string;
|
|
221
|
+
/** Scope without the leading `@`, if the package is scoped. */
|
|
222
|
+
readonly scope?: string;
|
|
223
|
+
/** Fully-qualified name: `@scope/name` when scoped, otherwise `name`. */
|
|
224
|
+
readonly fullName: string;
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/registry/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB,GACD,MAAM,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GACzB;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CA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AAED;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;aAQvB,UAAU,CAAC,EAAE,MAAM;aACnB,UAAU,CAAC,EAAE,MAAM;IARrC;;;;OAIG;gBAED,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,UAAU,CAAC,EAAE,MAAM,YAAA;CAKtC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for the npm registry API v2.
|
|
3
|
+
*
|
|
4
|
+
* This file is the foundational types module for the registry package. It
|
|
5
|
+
* contains no runtime code and no local imports — only type declarations
|
|
6
|
+
* describing the shapes returned by the npm registry's JSON endpoints
|
|
7
|
+
* (package metadata, abbreviated packuments, search results) plus the
|
|
8
|
+
* utility types used across the registry layer.
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Error thrown by registry clients when a request fails or returns a
|
|
14
|
+
* non-success status. Carries the HTTP status code and status text when
|
|
15
|
+
* available so callers can branch on specific failure modes.
|
|
16
|
+
*/
|
|
17
|
+
export class NpmRegistryError extends Error {
|
|
18
|
+
statusCode;
|
|
19
|
+
statusText;
|
|
20
|
+
/**
|
|
21
|
+
* @param message - Human-readable error message.
|
|
22
|
+
* @param statusCode - HTTP status code from the response, if any.
|
|
23
|
+
* @param statusText - HTTP status text from the response, if any.
|
|
24
|
+
*/
|
|
25
|
+
constructor(message, statusCode, statusText) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.statusCode = statusCode;
|
|
28
|
+
this.statusText = statusText;
|
|
29
|
+
this.name = 'NpmRegistryError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/registry/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA4LH;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAQvB;IACA;IARlB;;;;OAIG;IACH,YACE,OAAe,EACC,UAAmB,EACnB,UAAmB;QAEnC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,eAAU,GAAV,UAAU,CAAS;QACnB,eAAU,GAAV,UAAU,CAAS;QAGnC,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|