@vltpkg/security-archive 1.0.3 → 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/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { LRUCache } from 'lru-cache';
2
2
  import type { DepID } from '@vltpkg/dep-id';
3
+ import type { NodeLike } from '@vltpkg/types';
3
4
  import type { PackageReportData, SecurityArchiveLike, SecurityArchiveRefreshOptions } from './types.ts';
4
5
  export * from './types.ts';
5
- export declare const targetSecurityRegisty = "https://registry.npmjs.org/";
6
+ export declare const npmRegistryURL = "https://registry.npmjs.org/";
6
7
  export type JSONItemResponse = {
7
8
  namespace?: `@{string}`;
8
9
  name: string;
@@ -38,6 +39,12 @@ export type SecurityArchiveOptions = LRUCache.OptionsBase<DepID, PackageReportDa
38
39
  */
39
40
  retries?: number;
40
41
  };
42
+ /**
43
+ * Socket.dev only has reports for the public npm ecosystem. Eligible
44
+ * when the node's origin is `https://registry.npmjs.org/` or the URL
45
+ * configured as `registries.npm`.
46
+ */
47
+ export declare const usesNpmRegistry: (node: NodeLike) => boolean;
41
48
  export declare const version: string;
42
49
  /**
43
50
  * A database of security information for given packages from a list of nodes.
package/dist/index.js CHANGED
@@ -8,27 +8,35 @@ import pRetry, { AbortError } from 'p-retry';
8
8
  import { loadPackageJson } from 'package-json-from-dist';
9
9
  import { asDepID, splitDepID, baseDepID } from '@vltpkg/dep-id';
10
10
  import { error } from '@vltpkg/error-cause';
11
+ import { defaultRegistryName } from '@vltpkg/spec';
11
12
  import { XDG } from '@vltpkg/xdg';
12
13
  import { asPackageReportData } from "./types.js";
13
14
  import { __CODE_SPLIT_SCRIPT_NAME } from "./update-expired.js";
14
15
  export * from "./types.js";
15
16
  const SOCKET_API_V0_URL = 'https://api.socket.dev/v0/purl?alerts=true';
16
17
  const SOCKET_PUBLIC_API_TOKEN = 'sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api';
17
- export const targetSecurityRegisty = 'https://registry.npmjs.org/';
18
+ export const npmRegistryURL = 'https://registry.npmjs.org/';
19
+ const normalizeRegistryURL = (url) => url.endsWith('/') ? url : `${url}/`;
20
+ const nodeRegistryURL = (node) => {
21
+ const [type, reg] = splitDepID(node.id);
22
+ if (type !== 'registry')
23
+ return;
24
+ const url = /^https?:\/\//.test(reg) ? reg : node.options.registries?.[reg];
25
+ return url ? normalizeRegistryURL(url) : undefined;
26
+ };
18
27
  /**
19
- * Only the public npm registry has information available in the
20
- * socket.dev API. This function checks if a given depID is pointing
21
- * to the public npm registry and returns `true` if it does.
28
+ * Socket.dev only has reports for the public npm ecosystem. Eligible
29
+ * when the node's origin is `https://registry.npmjs.org/` or the URL
30
+ * configured as `registries.npm`.
22
31
  */
23
- const usesTargetRegistry = (node) => {
24
- const depID = node.id;
25
- const specOptions = node.options;
26
- const [nodeType, nodeRegistry] = splitDepID(depID);
27
- if (nodeType !== 'registry') {
32
+ export const usesNpmRegistry = (node) => {
33
+ const origin = nodeRegistryURL(node);
34
+ if (!origin)
28
35
  return false;
29
- }
30
- const reg = specOptions.registries?.[nodeRegistry];
31
- return reg === targetSecurityRegisty;
36
+ if (origin === npmRegistryURL)
37
+ return true;
38
+ const npmAlias = node.options.registries?.[defaultRegistryName];
39
+ return !!npmAlias && normalizeRegistryURL(npmAlias) === origin;
32
40
  };
33
41
  // Loads the version number to be used in the User-Agent header
34
42
  export const { version } = loadPackageJson(import.meta.filename, process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON);
@@ -211,10 +219,9 @@ export class SecurityArchive extends LRUCache {
211
219
  const queue = new Set();
212
220
  for (const node of this.#nodesByID.values()) {
213
221
  const normalizedId = baseDepID(node.id);
214
- // only queue up valid public registry
215
- // references that are missing from the archive
222
+ // only queue npm-ecosystem registry refs missing from the archive
216
223
  // also skips any pkg marked as expired
217
- if (usesTargetRegistry(node) &&
224
+ if (usesNpmRegistry(node) &&
218
225
  !this.has(normalizedId) &&
219
226
  !this.#expired.has(normalizedId)) {
220
227
  const purl = `pkg:npm/${node.name}@${node.version}`;
@@ -318,12 +325,12 @@ export class SecurityArchive extends LRUCache {
318
325
  }
319
326
  }
320
327
  /**
321
- * Validates that all public-registry packages in the nodes
328
+ * Validates that all npm-ecosystem packages in the nodes
322
329
  * have a valid report data in the current in-memory cache.
323
330
  */
324
331
  #validateReportData() {
325
332
  for (const node of this.#nodesByID.values()) {
326
- if (usesTargetRegistry(node)) {
333
+ if (usesNpmRegistry(node)) {
327
334
  if (!this.has(baseDepID(node.id))) {
328
335
  this.ok = false;
329
336
  return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/security-archive",
3
3
  "description": "A database of security information of packages",
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -13,11 +13,11 @@
13
13
  "url": "http://vlt.sh"
14
14
  },
15
15
  "dependencies": {
16
- "@vltpkg/dep-id": "1.0.3",
17
- "@vltpkg/error-cause": "1.0.3",
18
- "@vltpkg/spec": "1.0.3",
19
- "@vltpkg/types": "1.0.3",
20
- "@vltpkg/xdg": "1.0.3",
16
+ "@vltpkg/dep-id": "1.0.5",
17
+ "@vltpkg/error-cause": "1.0.5",
18
+ "@vltpkg/spec": "1.0.5",
19
+ "@vltpkg/types": "1.0.5",
20
+ "@vltpkg/xdg": "1.0.5",
21
21
  "lru-cache": "^11.2.4",
22
22
  "p-retry": "^7.1.1",
23
23
  "package-json-from-dist": "^1.0.1"