@vltpkg/security-archive 1.0.7 → 1.0.9

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/browser.d.ts CHANGED
@@ -1,6 +1,14 @@
1
+ import type { NodeLike } from '@vltpkg/types';
1
2
  import type { PackageReportData, SecurityArchiveLike } from './types.ts';
2
3
  import type { DepID } from '@vltpkg/dep-id';
3
4
  export * from './types.ts';
5
+ export declare const npmRegistryURL = "https://registry.npmjs.org/";
6
+ /**
7
+ * Socket.dev only has reports for the public npm ecosystem. Eligible
8
+ * when the node's origin is `https://registry.npmjs.org/` or the URL
9
+ * configured as `registries.npm`.
10
+ */
11
+ export declare const usesNpmRegistry: (node: NodeLike) => boolean;
4
12
  /**
5
13
  * A database of security information for given packages in a graph.
6
14
  */
@@ -9,6 +17,23 @@ export declare class SecurityArchive extends Map<DepID, PackageReportData> imple
9
17
  * Whether the security archive is valid.
10
18
  */
11
19
  ok: boolean;
20
+ /**
21
+ * Get the report data for a node, keyed by its base {@link DepID}.
22
+ */
23
+ get(depId: DepID): PackageReportData | undefined;
24
+ /**
25
+ * Check for report data, keyed by the base {@link DepID}.
26
+ */
27
+ has(depId: DepID): boolean;
28
+ /**
29
+ * Store report data for a node, keyed by its base {@link DepID} so
30
+ * peer-suffixed copies of the same package share one entry.
31
+ */
32
+ set(depId: DepID, data: PackageReportData): this;
33
+ /**
34
+ * Delete the report data stored under the base {@link DepID}.
35
+ */
36
+ delete(depId: DepID): boolean;
12
37
  /**
13
38
  * Loads a security archive from a valid JSON dump.
14
39
  */
package/dist/browser.js CHANGED
@@ -1,7 +1,31 @@
1
- import { asDepID } from '@vltpkg/dep-id/browser';
1
+ import { asDepID, baseDepID, splitDepID, } from '@vltpkg/dep-id/browser';
2
2
  import { error } from '@vltpkg/error-cause';
3
+ import { defaultRegistryName } from '@vltpkg/spec/browser';
3
4
  import { asPackageReportData } from "./types.js";
4
5
  export * from "./types.js";
6
+ export const npmRegistryURL = 'https://registry.npmjs.org/';
7
+ const normalizeRegistryURL = (url) => url.endsWith('/') ? url : `${url}/`;
8
+ const nodeRegistryURL = (node) => {
9
+ const [type, reg] = splitDepID(node.id);
10
+ if (type !== 'registry')
11
+ return;
12
+ const url = /^https?:\/\//.test(reg) ? reg : node.options.registries?.[reg];
13
+ return url ? normalizeRegistryURL(url) : undefined;
14
+ };
15
+ /**
16
+ * Socket.dev only has reports for the public npm ecosystem. Eligible
17
+ * when the node's origin is `https://registry.npmjs.org/` or the URL
18
+ * configured as `registries.npm`.
19
+ */
20
+ export const usesNpmRegistry = (node) => {
21
+ const origin = nodeRegistryURL(node);
22
+ if (!origin)
23
+ return false;
24
+ if (origin === npmRegistryURL)
25
+ return true;
26
+ const npmAlias = node.options.registries?.[defaultRegistryName];
27
+ return !!npmAlias && normalizeRegistryURL(npmAlias) === origin;
28
+ };
5
29
  const isObj = (o) => !!o && typeof o === 'object';
6
30
  const isSecurityArchiveJSON = (json) => isObj(json) &&
7
31
  Object.entries(json).every(([key, value]) => typeof key === 'string' && isObj(value));
@@ -19,6 +43,31 @@ export class SecurityArchive extends Map {
19
43
  * Whether the security archive is valid.
20
44
  */
21
45
  ok = false;
46
+ /**
47
+ * Get the report data for a node, keyed by its base {@link DepID}.
48
+ */
49
+ get(depId) {
50
+ return super.get(baseDepID(depId));
51
+ }
52
+ /**
53
+ * Check for report data, keyed by the base {@link DepID}.
54
+ */
55
+ has(depId) {
56
+ return super.has(baseDepID(depId));
57
+ }
58
+ /**
59
+ * Store report data for a node, keyed by its base {@link DepID} so
60
+ * peer-suffixed copies of the same package share one entry.
61
+ */
62
+ set(depId, data) {
63
+ return super.set(baseDepID(depId), data);
64
+ }
65
+ /**
66
+ * Delete the report data stored under the base {@link DepID}.
67
+ */
68
+ delete(depId) {
69
+ return super.delete(baseDepID(depId));
70
+ }
22
71
  /**
23
72
  * Loads a security archive from a valid JSON dump.
24
73
  */
package/dist/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { LRUCache } from 'lru-cache';
2
2
  import type { DepID } from '@vltpkg/dep-id';
3
- import type { NodeLike } from '@vltpkg/types';
4
3
  import type { PackageReportData, SecurityArchiveLike, SecurityArchiveRefreshOptions } from './types.ts';
5
4
  export * from './types.ts';
6
- export declare const npmRegistryURL = "https://registry.npmjs.org/";
5
+ export { npmRegistryURL, usesNpmRegistry } from './browser.ts';
7
6
  export type JSONItemResponse = {
8
7
  namespace?: `@{string}`;
9
8
  name: string;
@@ -39,12 +38,6 @@ export type SecurityArchiveOptions = LRUCache.OptionsBase<DepID, PackageReportDa
39
38
  */
40
39
  retries?: number;
41
40
  };
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;
48
41
  export declare const version: string;
49
42
  /**
50
43
  * A database of security information for given packages from a list of nodes.
@@ -74,6 +67,23 @@ export declare class SecurityArchive extends LRUCache<DepID, PackageReportData>
74
67
  */
75
68
  static get defaultTtl(): number;
76
69
  constructor(options?: SecurityArchiveOptions);
70
+ /**
71
+ * Get the report data for a node, keyed by its base {@link DepID}.
72
+ */
73
+ get(k: DepID, options?: Parameters<LRUCache<DepID, PackageReportData>['get']>[1]): PackageReportData | undefined;
74
+ /**
75
+ * Check for report data, keyed by the base {@link DepID}.
76
+ */
77
+ has(k: DepID): boolean;
78
+ /**
79
+ * Store report data for a node, keyed by its base {@link DepID} so
80
+ * peer-suffixed copies of the same package share one entry.
81
+ */
82
+ set(k: DepID, v: PackageReportData, setOptions?: Parameters<LRUCache<DepID, PackageReportData>['set']>[2]): this;
83
+ /**
84
+ * Delete the report data stored under the base {@link DepID}.
85
+ */
86
+ delete(k: DepID): boolean;
77
87
  /**
78
88
  * Starts the security archive by providing an array of {@link NodeLike} instances,
79
89
  * its registry-based nodes are going to be used as valid potential entries.
package/dist/index.js CHANGED
@@ -6,38 +6,16 @@ import { dirname } from 'node:path';
6
6
  import { LRUCache } from 'lru-cache';
7
7
  import pRetry, { AbortError } from 'p-retry';
8
8
  import { loadPackageJson } from 'package-json-from-dist';
9
- import { asDepID, splitDepID, baseDepID } from '@vltpkg/dep-id';
9
+ import { asDepID, baseDepID } from '@vltpkg/dep-id';
10
10
  import { error } from '@vltpkg/error-cause';
11
- import { defaultRegistryName } from '@vltpkg/spec';
12
11
  import { XDG } from '@vltpkg/xdg';
13
12
  import { asPackageReportData } from "./types.js";
14
13
  import { __CODE_SPLIT_SCRIPT_NAME } from "./update-expired.js";
14
+ import { usesNpmRegistry } from "./browser.js";
15
15
  export * from "./types.js";
16
+ export { npmRegistryURL, usesNpmRegistry } from "./browser.js";
16
17
  const SOCKET_API_V0_URL = 'https://api.socket.dev/v0/purl?alerts=true';
17
18
  const SOCKET_PUBLIC_API_TOKEN = 'sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api';
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
- };
27
- /**
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`.
31
- */
32
- export const usesNpmRegistry = (node) => {
33
- const origin = nodeRegistryURL(node);
34
- if (!origin)
35
- return false;
36
- if (origin === npmRegistryURL)
37
- return true;
38
- const npmAlias = node.options.registries?.[defaultRegistryName];
39
- return !!npmAlias && normalizeRegistryURL(npmAlias) === origin;
40
- };
41
19
  // Loads the version number to be used in the User-Agent header
42
20
  export const { version } = loadPackageJson(import.meta.filename, process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON);
43
21
  /**
@@ -90,6 +68,31 @@ export class SecurityArchive extends LRUCache {
90
68
  options.path ?? new XDG('vlt').cache('security-archive.db');
91
69
  this.#retries = options.retries ?? 3;
92
70
  }
71
+ /**
72
+ * Get the report data for a node, keyed by its base {@link DepID}.
73
+ */
74
+ get(k, options) {
75
+ return super.get(baseDepID(k), options);
76
+ }
77
+ /**
78
+ * Check for report data, keyed by the base {@link DepID}.
79
+ */
80
+ has(k) {
81
+ return super.has(baseDepID(k));
82
+ }
83
+ /**
84
+ * Store report data for a node, keyed by its base {@link DepID} so
85
+ * peer-suffixed copies of the same package share one entry.
86
+ */
87
+ set(k, v, setOptions) {
88
+ return super.set(baseDepID(k), v, setOptions);
89
+ }
90
+ /**
91
+ * Delete the report data stored under the base {@link DepID}.
92
+ */
93
+ delete(k) {
94
+ return super.delete(baseDepID(k));
95
+ }
93
96
  /**
94
97
  * Retrieves a node using its name and version.
95
98
  */
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.7",
4
+ "version": "1.0.9",
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.7",
17
- "@vltpkg/error-cause": "1.0.7",
18
- "@vltpkg/spec": "1.0.7",
19
- "@vltpkg/types": "1.0.7",
20
- "@vltpkg/xdg": "1.0.7",
16
+ "@vltpkg/dep-id": "1.0.9",
17
+ "@vltpkg/error-cause": "1.0.9",
18
+ "@vltpkg/spec": "1.0.9",
19
+ "@vltpkg/types": "1.0.9",
20
+ "@vltpkg/xdg": "1.0.9",
21
21
  "lru-cache": "^11.2.4",
22
22
  "p-retry": "^7.1.1",
23
23
  "package-json-from-dist": "^1.0.1"