@vltpkg/security-archive 0.0.0-9 → 1.0.0-rc.2

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.
@@ -1,6 +1,6 @@
1
1
  import type { PackageReportData, SecurityArchiveLike } from './types.ts';
2
2
  import type { DepID } from '@vltpkg/dep-id';
3
- export type * from './types.ts';
3
+ export * from './types.ts';
4
4
  /**
5
5
  * A database of security information for given packages in a graph.
6
6
  */
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,mBAAmB,YAAY,CAAA;AAsB/B;;GAEG;AACH,qBAAa,eACX,SAAQ,GAAG,CAAC,KAAK,EAAE,iBAAiB,CACpC,YAAW,mBAAmB;IAE9B;;OAEG;IACH,EAAE,UAAQ;IAEV;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO;CAU1B"}
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,cAAc,YAAY,CAAA;AAsB1B;;GAEG;AACH,qBAAa,eACX,SAAQ,GAAG,CAAC,KAAK,EAAE,iBAAiB,CACpC,YAAW,mBAAmB;IAE9B;;OAEG;IACH,EAAE,UAAQ;IAEV;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO;CAU1B"}
@@ -1,6 +1,7 @@
1
1
  import { asDepID } from '@vltpkg/dep-id/browser';
2
2
  import { error } from '@vltpkg/error-cause';
3
3
  import { asPackageReportData } from "./types.js";
4
+ export * from "./types.js";
4
5
  const isObj = (o) => !!o && typeof o === 'object';
5
6
  const isSecurityArchiveJSON = (json) => isObj(json) &&
6
7
  Object.entries(json).every(([key, value]) => typeof key === 'string' && isObj(value));
@@ -1 +1 @@
1
- {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAUhD,MAAM,KAAK,GAAG,CAAC,CAAU,EAAgC,EAAE,CACzD,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAA;AAE9B,MAAM,qBAAqB,GAAG,CAC5B,IAAa,EACsB,EAAE,CACrC,KAAK,CAAC,IAAI,CAAC;IACX,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CACxB,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,CAC1D,CAAA;AAEH,MAAM,qBAAqB,GAAG,CAC5B,IAAa,EACc,EAAE;IAC7B,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,MAAM,KAAK,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAC/D,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,OAAO,eACX,SAAQ,GAA6B;IAGrC;;OAEG;IACH,EAAE,GAAG,KAAK,CAAA;IAEV;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,IAAa;QACvB,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,SAAS,CAAA;QAExC,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAA;QACrC,MAAM,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAA;QACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAA;QACvD,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { asDepID } from '@vltpkg/dep-id/browser'\nimport { error } from '@vltpkg/error-cause'\nimport { asPackageReportData } from './types.ts'\nimport type { JSONField } from '@vltpkg/types'\nimport type {\n PackageReportData,\n SecurityArchiveLike,\n} from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\n\nexport type * from './types.ts'\n\nconst isObj = (o: unknown): o is Record<string, unknown> =>\n !!o && typeof o === 'object'\n\nconst isSecurityArchiveJSON = (\n json: unknown,\n): json is Record<string, JSONField> =>\n isObj(json) &&\n Object.entries(json).every(\n ([key, value]) => typeof key === 'string' && isObj(value),\n )\n\nconst asSecurityArchiveJSON = (\n json: unknown,\n): Record<string, JSONField> => {\n if (!isSecurityArchiveJSON(json)) {\n throw error('Invalid security archive JSON', { found: json })\n }\n return json\n}\n\n/**\n * A database of security information for given packages in a graph.\n */\nexport class SecurityArchive\n extends Map<DepID, PackageReportData>\n implements SecurityArchiveLike\n{\n /**\n * Whether the security archive is valid.\n */\n ok = false\n\n /**\n * Loads a security archive from a valid JSON dump.\n */\n static load(dump: unknown) {\n if (dump === undefined) return undefined\n\n const archive = new SecurityArchive()\n const json = asSecurityArchiveJSON(dump)\n for (const [key, value] of Object.entries(json)) {\n archive.set(asDepID(key), asPackageReportData(value))\n }\n return archive\n }\n}\n"]}
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wB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,KAAK,CAAC,CAAC,CAAA;QACvD,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { asDepID } from '@vltpkg/dep-id/browser'\nimport { error } from '@vltpkg/error-cause'\nimport { asPackageReportData } from './types.ts'\nimport type { JSONField } from '@vltpkg/types'\nimport type {\n PackageReportData,\n SecurityArchiveLike,\n} from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\n\nexport * from './types.ts'\n\nconst isObj = (o: unknown): o is Record<string, unknown> =>\n !!o && typeof o === 'object'\n\nconst isSecurityArchiveJSON = (\n json: unknown,\n): json is Record<string, JSONField> =>\n isObj(json) &&\n Object.entries(json).every(\n ([key, value]) => typeof key === 'string' && isObj(value),\n )\n\nconst asSecurityArchiveJSON = (\n json: unknown,\n): Record<string, JSONField> => {\n if (!isSecurityArchiveJSON(json)) {\n throw error('Invalid security archive JSON', { found: json })\n }\n return json\n}\n\n/**\n * A database of security information for given packages in a graph.\n */\nexport class SecurityArchive\n extends Map<DepID, PackageReportData>\n implements SecurityArchiveLike\n{\n /**\n * Whether the security archive is valid.\n */\n ok = false\n\n /**\n * Loads a security archive from a valid JSON dump.\n */\n static load(dump: unknown) {\n if (dump === undefined) return undefined\n\n const archive = new SecurityArchive()\n const json = asSecurityArchiveJSON(dump)\n for (const [key, value] of Object.entries(json)) {\n archive.set(asDepID(key), asPackageReportData(value))\n }\n return archive\n }\n}\n"]}
@@ -7,9 +7,18 @@ export type JSONItemResponse = {
7
7
  namespace?: `@{string}`;
8
8
  name: string;
9
9
  version: string;
10
+ score: {
11
+ overall: number;
12
+ license: number;
13
+ maintenance: number;
14
+ quality: number;
15
+ supplyChain: number;
16
+ vulnerability: number;
17
+ };
10
18
  };
11
19
  export type DBReadEntry = {
12
20
  depID: string;
21
+ now: number;
13
22
  report: string;
14
23
  start: number;
15
24
  ttl: number;
@@ -31,7 +40,7 @@ export type SecurityArchiveOptions = LRUCache.OptionsBase<DepID, PackageReportDa
31
40
  };
32
41
  export declare const version: string;
33
42
  /**
34
- * A database of security information for given packages in a graph.
43
+ * A database of security information for given packages from a list of nodes.
35
44
  *
36
45
  * Using the SecurityArchive.refresh() method will update the local cache
37
46
  * with information from the socket.dev APIs or load from the local storage
@@ -41,8 +50,8 @@ export declare const version: string;
41
50
  export declare class SecurityArchive extends LRUCache<DepID, PackageReportData> implements SecurityArchiveLike {
42
51
  #private;
43
52
  /**
44
- * True if the refresh process was successful and report data
45
- * is available for all public registry packages in the graph.
53
+ * True if the refresh process was successful and report data is available
54
+ * for all public registry packages from the initial list of nodes.
46
55
  */
47
56
  ok: boolean;
48
57
  /**
@@ -59,13 +68,13 @@ export declare class SecurityArchive extends LRUCache<DepID, PackageReportData>
59
68
  static get defaultTtl(): number;
60
69
  constructor(options?: SecurityArchiveOptions);
61
70
  /**
62
- * Starts the security archive by providing a {@link GraphLike} instance,
71
+ * Starts the security archive by providing an array of {@link NodeLike} instances,
63
72
  * its registry-based nodes are going to be used as valid potential entries.
64
73
  *
65
74
  * Any entry that is missing from the persisted cached values are going
66
75
  * to be requested in a batch-request to the remote socket.dev API.
67
76
  */
68
- refresh({ graph, specOptions, }: SecurityArchiveRefreshOptions): Promise<void>;
77
+ refresh({ nodes }: SecurityArchiveRefreshOptions): Promise<void>;
69
78
  /**
70
79
  * Outputs the current in-memory cache as a JSON object.
71
80
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAOpC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAG3C,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,6BAA6B,EAC9B,MAAM,YAAY,CAAA;AAEnB,cAAc,YAAY,CAAA;AAM1B,eAAO,MAAM,qBAAqB,gCAAgC,CAAA;AAElE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,CAAC,EAAE,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AE,sBAAsB,GAAG,6BAA6B;IAOjE;;OAEG;IACH,MAAM,KAAK,UAAU,WAEpB;IAED;;OAEG;IACH,MAAM,KAAK,UAAU,WAEpB;gBAEW,OAAO,GAAE,sBAA2B;IA6QhD;;;;;;OAMG;IACG,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,6BAA6B;IA4DtD;;OAEG;IACH,MAAM;CAOP"}
package/dist/esm/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { DatabaseSync } from 'node:sqlite';
2
+ import { mkdirSync } from 'node:fs';
3
+ import { dirname } from 'node:path';
2
4
  import { LRUCache } from 'lru-cache';
3
5
  import pRetry, { AbortError } from 'p-retry';
4
6
  import { loadPackageJson } from 'package-json-from-dist';
5
- import { asDepID, splitDepID, joinDepIDTuple } from '@vltpkg/dep-id';
7
+ import { asDepID, splitDepID, baseDepID } from '@vltpkg/dep-id';
6
8
  import { error } from '@vltpkg/error-cause';
7
9
  import { XDG } from '@vltpkg/xdg';
8
10
  import { asPackageReportData } from "./types.js";
@@ -15,7 +17,9 @@ export const targetSecurityRegisty = 'https://registry.npmjs.org/';
15
17
  * socket.dev API. This function checks if a given depID is pointing
16
18
  * to the public npm registry and returns `true` if it does.
17
19
  */
18
- const usesTargetRegistry = (depID, specOptions) => {
20
+ const usesTargetRegistry = (node) => {
21
+ const depID = node.id;
22
+ const specOptions = node.options;
19
23
  const [nodeType, nodeRegistry] = splitDepID(depID);
20
24
  if (nodeType !== 'registry') {
21
25
  return false;
@@ -28,7 +32,7 @@ const usesTargetRegistry = (depID, specOptions) => {
28
32
  // Loads the version number to be used in the User-Agent header
29
33
  export const { version } = loadPackageJson(import.meta.filename, process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON);
30
34
  /**
31
- * A database of security information for given packages in a graph.
35
+ * A database of security information for given packages from a list of nodes.
32
36
  *
33
37
  * Using the SecurityArchive.refresh() method will update the local cache
34
38
  * with information from the socket.dev APIs or load from the local storage
@@ -36,12 +40,15 @@ export const { version } = loadPackageJson(import.meta.filename, process.env.__V
36
40
  * using the SecurityArchive.get() method.
37
41
  */
38
42
  export class SecurityArchive extends LRUCache {
39
- #fetchedDepIDs = new Set();
43
+ #expired = new Set();
44
+ #pUpdateExpired;
40
45
  #path;
41
46
  #retries;
47
+ #nodesByName = new Map();
48
+ #nodesByID = new Map();
42
49
  /**
43
- * True if the refresh process was successful and report data
44
- * is available for all public registry packages in the graph.
50
+ * True if the refresh process was successful and report data is available
51
+ * for all public registry packages from the initial list of nodes.
45
52
  */
46
53
  ok = false;
47
54
  /**
@@ -69,15 +76,27 @@ export class SecurityArchive extends LRUCache {
69
76
  max: SecurityArchive.defaultMax,
70
77
  ttl: SecurityArchive.defaultTtl,
71
78
  ...options,
79
+ allowStale: true,
72
80
  });
73
81
  this.#path =
74
82
  options.path ?? new XDG('vlt').cache('security-archive.db');
75
83
  this.#retries = options.retries ?? 3;
76
84
  }
85
+ /**
86
+ * Retrieves a node using its name and version.
87
+ */
88
+ #retrieveNodeByNameVersion(name, version) {
89
+ for (const node of this.#nodesByName.get(name) ?? []) {
90
+ if (node.version === version) {
91
+ return node;
92
+ }
93
+ }
94
+ }
77
95
  /**
78
96
  * Opens a connection to the database at the given path.
79
97
  */
80
98
  #openDatabase() {
99
+ mkdirSync(dirname(this.#path), { recursive: true });
81
100
  const db = new DatabaseSync(this.#path);
82
101
  db.exec('CREATE TABLE IF NOT EXISTS cache ' +
83
102
  '(depID TEXT PRIMARY KEY, report TEXT, ttl INTEGER, start INTEGER) ' +
@@ -86,50 +105,87 @@ export class SecurityArchive extends LRUCache {
86
105
  // while using less space and more efficient lookups
87
106
  // https://www.sqlite.org/withoutrowid.html
88
107
  'WITHOUT ROWID');
89
- db.exec('PRAGMA journal_mode = TRUNCATE');
108
+ db.exec('PRAGMA journal_mode = WAL');
90
109
  db.exec('PRAGMA synchronous = NORMAL');
91
110
  return db;
92
111
  }
93
112
  /**
94
113
  * Loads all valid items found in the database into the in-memory cache.
95
114
  */
96
- #loadItemsFromDatabase(db, graph) {
115
+ #loadItemsFromDatabase(db, nodes) {
97
116
  const depIDs = [];
98
- for (const node of graph.nodes.values()) {
99
- depIDs.push(`'${node.id}'`);
117
+ for (const node of nodes) {
118
+ depIDs.push(`'${baseDepID(node.id)}'`);
100
119
  }
101
120
  // retrieves from the db packages using their dep-id reference
102
121
  // and only include entries that have a valid TTL value
103
122
  const dbRead = db.prepare('SELECT depID, report, start, ttl, ' +
104
123
  `(SELECT UNIXEPOCH('subsecond') * 1000) as now ` +
105
124
  'FROM cache ' +
106
- `WHERE depID IN (${depIDs.join(',')}) ` +
107
- 'AND (start + ttl) > now');
125
+ `WHERE depID IN (${depIDs.join(',')})`);
126
+ // reset the list of expired entries
127
+ this.#expired.clear();
108
128
  for (const entry of dbRead.all()) {
109
- const { depID, report, start, ttl } = entry;
129
+ const { depID, now, report, start, ttl } = entry;
130
+ const id = baseDepID(asDepID(depID));
110
131
  try {
111
- this.set(asDepID(depID), asPackageReportData(JSON.parse(report)), {
132
+ this.set(id, asPackageReportData(JSON.parse(report)), {
112
133
  ttl,
113
134
  start,
114
135
  });
136
+ // stale values are queued up as expired for revalidation
137
+ if (start + ttl < now) {
138
+ this.#expired.add(id);
139
+ }
115
140
  }
116
141
  catch {
117
142
  // prune any invalid entries from the database
118
143
  db.prepare('DELETE FROM cache WHERE depID = ?').run(depID);
119
144
  }
120
145
  }
146
+ // TODO: we need to move this to a detached process in order for the
147
+ // cli commands that make usage of the security-archive, e.g: vlt ls,
148
+ // vlt query to not hang while waiting for stale-while-revalidate
149
+ // request to finish and close the db connection
150
+ this.#pUpdateExpired = this.#updateExpired(db);
151
+ }
152
+ /**
153
+ * Updates the database with renewed entries for expired packages.
154
+ */
155
+ async #updateExpired(db) {
156
+ const expiredQueue = new Set();
157
+ for (const depID of this.#expired) {
158
+ const node = this.#nodesByID.get(baseDepID(depID));
159
+ /* c8 ignore start */
160
+ if (!node?.version) {
161
+ // skip any missing node or nodes without a version, this
162
+ // should not happen, but some optional dependencies might
163
+ // end up in this state when reading from the lockfile
164
+ continue;
165
+ }
166
+ /* c8 ignore stop */
167
+ const purl = `pkg:npm/${node.name}@${node.version}`;
168
+ expiredQueue.add({ purl });
169
+ }
170
+ if (expiredQueue.size > 0) {
171
+ const res = await pRetry(() => this.#retrieveRemoteData(expiredQueue), { retries: this.#retries });
172
+ const ids = this.#loadFromNDJSON(res);
173
+ this.#storeNewItemsToDatabase(db, ids);
174
+ }
121
175
  }
122
176
  /**
123
177
  * Queues up all required packages that are missing from the archive.
124
178
  */
125
- #queueUpRequiredPackages(graph, specOptions) {
179
+ #queueUpRequiredPackages() {
126
180
  const queue = new Set();
127
- const nodes = graph.nodes.values();
128
- for (const node of nodes) {
181
+ for (const node of this.#nodesByID.values()) {
182
+ const normalizedId = baseDepID(node.id);
129
183
  // only queue up valid public registry
130
184
  // references that are missing from the archive
131
- if (usesTargetRegistry(node.id, specOptions) &&
132
- !this.has(node.id)) {
185
+ // also skips any pkg marked as expired
186
+ if (usesTargetRegistry(node) &&
187
+ !this.has(normalizedId) &&
188
+ !this.#expired.has(normalizedId)) {
133
189
  const purl = `pkg:npm/${node.name}@${node.version}`;
134
190
  queue.add({ purl });
135
191
  }
@@ -165,41 +221,55 @@ export class SecurityArchive extends LRUCache {
165
221
  }
166
222
  /**
167
223
  * Parses and load NDJSON data into the in-memory cache.
224
+ * Returns a set of dep ids that were successfully loaded.
168
225
  */
169
- #loadFromNDJSON(str, graph) {
226
+ #loadFromNDJSON(str) {
227
+ // builds a set of dep ids that were successfully fetched and loaded
228
+ const fetchedDepIDs = new Set();
170
229
  const json = str.split('}\n');
171
230
  for (const line of json) {
172
231
  if (!line.trim())
173
232
  continue;
174
233
  const data = JSON.parse(line + '}');
175
234
  const scope = data.namespace ? `${data.namespace}/` : '';
176
- const depID = joinDepIDTuple([
177
- 'registry',
178
- '',
179
- `${scope}${data.name}@${data.version}`,
180
- ]);
181
- const aliasedDepID = joinDepIDTuple([
182
- 'registry',
183
- 'npm',
184
- `${scope}${data.name}@${data.version}`,
185
- ]);
186
- const node = graph.nodes.get(depID) ?? graph.nodes.get(aliasedDepID);
235
+ const name = `${scope}${data.name}`;
236
+ const node = this.#retrieveNodeByNameVersion(name, data.version);
187
237
  if (node) {
188
- this.#fetchedDepIDs.add(node.id);
189
- this.set(node.id, asPackageReportData(data));
238
+ const normalizedId = baseDepID(node.id);
239
+ fetchedDepIDs.add(baseDepID(node.id));
240
+ // Calculate average score from all score components
241
+ const scoreComponents = [
242
+ data.score.license,
243
+ data.score.maintenance,
244
+ data.score.quality,
245
+ data.score.supplyChain,
246
+ data.score.vulnerability,
247
+ ];
248
+ const newAverageScore = Number((scoreComponents.reduce((sum, score) => sum + score, 0) /
249
+ scoreComponents.length).toFixed(2));
250
+ // Add average score to the score object
251
+ const scoreWithNewAverage = {
252
+ ...data.score,
253
+ overall: newAverageScore,
254
+ };
255
+ this.set(normalizedId, asPackageReportData({
256
+ ...data,
257
+ score: scoreWithNewAverage,
258
+ }));
190
259
  }
191
260
  else {
192
261
  // eslint-disable-next-line no-console
193
262
  console.warn(`security-archive: failed to find node for ${scope}${data.name}@${data.version} found in the response.`);
194
263
  }
195
264
  }
265
+ return fetchedDepIDs;
196
266
  }
197
267
  /**
198
268
  * Store new in-memory items to the database.
199
269
  */
200
- #storeNewItemsToDatabase(db) {
270
+ #storeNewItemsToDatabase(db, depIDs) {
201
271
  const insertData = [];
202
- for (const depID of this.#fetchedDepIDs) {
272
+ for (const depID of depIDs) {
203
273
  const entry = this.info(depID);
204
274
  if (entry?.start && entry.ttl) {
205
275
  insertData.push([
@@ -217,13 +287,13 @@ export class SecurityArchive extends LRUCache {
217
287
  }
218
288
  }
219
289
  /**
220
- * Validates that all public-registry packages in the graph
290
+ * Validates that all public-registry packages in the nodes
221
291
  * have a valid report data in the current in-memory cache.
222
292
  */
223
- #validateReportData(graph, specOptions) {
224
- for (const node of graph.nodes.values()) {
225
- if (usesTargetRegistry(node.id, specOptions)) {
226
- if (!this.has(node.id)) {
293
+ #validateReportData() {
294
+ for (const node of this.#nodesByID.values()) {
295
+ if (usesTargetRegistry(node)) {
296
+ if (!this.has(baseDepID(node.id))) {
227
297
  this.ok = false;
228
298
  return;
229
299
  }
@@ -232,36 +302,62 @@ export class SecurityArchive extends LRUCache {
232
302
  this.ok = true;
233
303
  }
234
304
  /**
235
- * Starts the security archive by providing a {@link GraphLike} instance,
305
+ * Starts the security archive by providing an array of {@link NodeLike} instances,
236
306
  * its registry-based nodes are going to be used as valid potential entries.
237
307
  *
238
308
  * Any entry that is missing from the persisted cached values are going
239
309
  * to be requested in a batch-request to the remote socket.dev API.
240
310
  */
241
- async refresh({ graph, specOptions, }) {
311
+ async refresh({ nodes }) {
242
312
  // should start by clearing the current in-memory cache
243
313
  this.clear();
244
314
  const db = this.#openDatabase();
315
+ // indexes nodes by name and id for quick lookup
316
+ this.#nodesByName.clear();
317
+ this.#nodesByID.clear();
318
+ for (const node of nodes) {
319
+ /* c8 ignore start */
320
+ const setByName = this.#nodesByName.get(node.name ?? '') ?? new Set();
321
+ setByName.add(node);
322
+ this.#nodesByName.set(node.name ?? '', setByName);
323
+ /* c8 ignore stop */
324
+ this.#nodesByID.set(baseDepID(node.id), node);
325
+ }
245
326
  try {
246
- this.#loadItemsFromDatabase(db, graph);
247
- const queue = this.#queueUpRequiredPackages(graph, specOptions);
327
+ this.#loadItemsFromDatabase(db, nodes);
328
+ const queue = this.#queueUpRequiredPackages();
248
329
  // only reach for the remote API if there are packages queued up
249
330
  if (queue.size > 0) {
250
331
  // Parse the response data
251
332
  const res = await pRetry(() => this.#retrieveRemoteData(queue), { retries: this.#retries });
252
- this.#loadFromNDJSON(res, graph);
253
- this.#storeNewItemsToDatabase(db);
333
+ const ids = this.#loadFromNDJSON(res);
334
+ this.#storeNewItemsToDatabase(db, ids);
254
335
  }
255
336
  // validates the refresh process was successful
256
- this.#validateReportData(graph, specOptions);
337
+ this.#validateReportData();
257
338
  }
258
339
  finally {
259
- db.exec('PRAGMA optimize');
260
- db.close();
261
- // TODO: at this point we could spawn a deref process to
262
- // remove entries with expired ttl values and vaccum the db
340
+ // TODO: once we move the stale-while-revalidate to a detached process
341
+ // the this.#close method no longer needs to be async
342
+ void this.#close(db);
263
343
  }
264
344
  }
345
+ /**
346
+ * Closes the database connection and cleans up the internal state.
347
+ */
348
+ async #close(db) {
349
+ // the revalidation of stale entries might not yet be completed
350
+ // so in case we have a pending promise for that, we need to wait
351
+ await this.#pUpdateExpired;
352
+ // close db connection
353
+ db.exec('PRAGMA optimize');
354
+ db.close();
355
+ // clean up internal state
356
+ this.#expired.clear();
357
+ this.#pUpdateExpired = undefined;
358
+ // TODO: at this point we could spawn a deref process to
359
+ // remove entries with expired ttl values and vaccum the db
360
+ }
265
361
  /**
266
362
  * Outputs the current in-memory cache as a JSON object.
267
363
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAUhD,cAAc,YAAY,CAAA;AAE1B,MAAM,iBAAiB,GAAG,4CAA4C,CAAA;AACtE,MAAM,uBAAuB,GAC3B,yDAAyD,CAAA;AAE3D,MAAM,CAAC,MAAM,qBAAqB,GAAG,6BAA6B,CAAA;AAoClE;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,CACzB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AI,CAAC,mBAAmB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;QAC9C,CAAC;gBAAS,CAAC;YACT,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;YAC1B,EAAE,CAAC,KAAK,EAAE,CAAA;YACV,wDAAwD;YACxD,2DAA2D;QAC7D,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,MAAM,GAAG,GAAqC,EAAE,CAAA;QAChD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YACvC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAA;QACxB,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF","sourcesContent":["import { DatabaseSync } from 'node:sqlite'\nimport { LRUCache } from 'lru-cache'\nimport pRetry, { AbortError } from 'p-retry'\nimport { loadPackageJson } from 'package-json-from-dist'\nimport { asDepID, splitDepID, joinDepIDTuple } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport { XDG } from '@vltpkg/xdg'\nimport { asPackageReportData } from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { GraphLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type {\n PackageReportData,\n SecurityArchiveLike,\n SecurityArchiveRefreshOptions,\n} from './types.ts'\n\nexport * from './types.ts'\n\nconst SOCKET_API_V0_URL = 'https://api.socket.dev/v0/purl?alerts=true'\nconst SOCKET_PUBLIC_API_TOKEN =\n 'sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api'\n\nexport const targetSecurityRegisty = 'https://registry.npmjs.org/'\n\nexport type JSONItemResponse = {\n namespace?: `@{string}`\n name: string\n version: string\n}\n\nexport type DBReadEntry = {\n depID: string\n report: string\n start: number\n ttl: number\n}\n\nexport type DBWriteEntry = [string, string, number, number]\n\nexport type SecurityArchiveOptions = LRUCache.OptionsBase<\n DepID,\n PackageReportData,\n unknown\n> & {\n /**\n * Security archive does not supports a fetch-on-demand model.\n */\n fetchMethod?: undefined\n /**\n * An optional value for the path in which to store the sqlite db.\n */\n path?: string\n /**\n * Number of retries attempts to reach the remote security API.\n */\n retries?: number\n}\n\n/**\n * Only the public npm registry has information available in the\n * socket.dev API. This function checks if a given depID is pointing\n * to the public npm registry and returns `true` if it does.\n */\nconst usesTargetRegistry = (\n depID: DepID,\n specOptions: SpecOptions,\n): boolean => {\n const [nodeType, nodeRegistry] = splitDepID(depID)\n\n if (nodeType !== 'registry') {\n return false\n }\n\n const reg =\n nodeRegistry === '' ?\n specOptions.registry\n : specOptions.registries?.[nodeRegistry]\n return reg === targetSecurityRegisty\n}\n\n// Loads the version number to be used in the User-Agent header\nexport const { version } = loadPackageJson(\n import.meta.filename,\n process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON,\n) as {\n version: string\n}\n\n/**\n * A database of security information for given packages in a graph.\n *\n * Using the SecurityArchive.refresh() method will update the local cache\n * with information from the socket.dev APIs or load from the local storage\n * if available. Information about package security is then available\n * using the SecurityArchive.get() method.\n */\nexport class SecurityArchive\n extends LRUCache<DepID, PackageReportData>\n implements SecurityArchiveLike\n{\n #fetchedDepIDs = new Set<DepID>()\n #path: string\n #retries: number\n\n /**\n * True if the refresh process was successful and report data\n * is available for all public registry packages in the graph.\n */\n ok = false\n\n /**\n * Creates a new security archive instance and starts the refresh process.\n */\n static async start(\n options: SecurityArchiveOptions & SecurityArchiveRefreshOptions,\n ) {\n const archive = new SecurityArchive(options)\n await archive.refresh(options)\n return archive\n }\n\n /**\n * By default, limits to 100K entries in the in-memory archive.\n */\n static get defaultMax() {\n return 100_000\n }\n\n /**\n * By default, entries are cached for 3 hours.\n */\n static get defaultTtl() {\n return 1000 * 60 * 60 * 3\n }\n\n constructor(options: SecurityArchiveOptions = {}) {\n super({\n max: SecurityArchive.defaultMax,\n ttl: SecurityArchive.defaultTtl,\n ...options,\n })\n\n this.#path =\n options.path ?? new XDG('vlt').cache('security-archive.db')\n this.#retries = options.retries ?? 3\n }\n\n /**\n * Opens a connection to the database at the given path.\n */\n #openDatabase(): DatabaseSync {\n const db = new DatabaseSync(this.#path)\n db.exec(\n 'CREATE TABLE IF NOT EXISTS cache ' +\n '(depID TEXT PRIMARY KEY, report TEXT, ttl INTEGER, start INTEGER) ' +\n // WITHOUT ROWID models a key=value storage,\n // enforcing depID must be unique and not null\n // while using less space and more efficient lookups\n // https://www.sqlite.org/withoutrowid.html\n 'WITHOUT ROWID',\n )\n db.exec('PRAGMA journal_mode = TRUNCATE')\n db.exec('PRAGMA synchronous = NORMAL')\n return db\n }\n\n /**\n * Loads all valid items found in the database into the in-memory cache.\n */\n #loadItemsFromDatabase(db: DatabaseSync, graph: GraphLike): void {\n const depIDs: string[] = []\n for (const node of graph.nodes.values()) {\n depIDs.push(`'${node.id}'`)\n }\n // retrieves from the db packages using their dep-id reference\n // and only include entries that have a valid TTL value\n const dbRead = db.prepare(\n 'SELECT depID, report, start, ttl, ' +\n `(SELECT UNIXEPOCH('subsecond') * 1000) as now ` +\n 'FROM cache ' +\n `WHERE depID IN (${depIDs.join(',')}) ` +\n 'AND (start + ttl) > now',\n )\n for (const entry of dbRead.all() as DBReadEntry[]) {\n const { depID, report, start, ttl } = entry\n try {\n this.set(\n asDepID(depID),\n asPackageReportData(JSON.parse(report)),\n {\n ttl,\n start,\n },\n )\n } catch {\n // prune any invalid entries from the database\n db.prepare('DELETE FROM cache WHERE depID = ?').run(depID)\n }\n }\n }\n\n /**\n * Queues up all required packages that are missing from the archive.\n */\n #queueUpRequiredPackages(\n graph: GraphLike,\n specOptions: SpecOptions,\n ): Set<Record<'purl', string>> {\n const queue = new Set<Record<'purl', string>>()\n const nodes = graph.nodes.values()\n for (const node of nodes) {\n // only queue up valid public registry\n // references that are missing from the archive\n if (\n usesTargetRegistry(node.id, specOptions) &&\n !this.has(node.id)\n ) {\n const purl = `pkg:npm/${node.name}@${node.version}`\n queue.add({ purl })\n }\n }\n return queue\n }\n\n /**\n * Fetches security information from the socket.dev API.\n * Returns a string of NDJSON data.\n */\n async #retrieveRemoteData(\n queue: Set<Record<'purl', string>>,\n ): Promise<string> {\n // fetch information from the socket.dev API\n const req = await fetch(SOCKET_API_V0_URL, {\n method: 'POST',\n headers: {\n Authorization: `Basic ${Buffer.from(`${SOCKET_PUBLIC_API_TOKEN}:`).toString('base64url')}`,\n 'User-Agent': `@vltpkg/security-archive/${version}`,\n },\n body: JSON.stringify({\n components: Array.from(queue),\n }),\n })\n // on missing valid auth or API, it should abort the retry logic\n if (req.status === 404) {\n throw new AbortError('Missing API')\n }\n // on any other error throws an error that will trigger retry\n if (!req.ok || !(req.status >= 200 && req.status <= 299)) {\n throw error('Failed to fetch security data', { response: req })\n }\n\n const str = await req.text()\n return str.trim() + '\\n'\n }\n\n /**\n * Parses and load NDJSON data into the in-memory cache.\n */\n #loadFromNDJSON(str: string, graph: GraphLike): void {\n const json = str.split('}\\n')\n for (const line of json) {\n if (!line.trim()) continue\n const data = JSON.parse(line + '}') as JSONItemResponse\n const scope = data.namespace ? `${data.namespace}/` : ''\n const depID = joinDepIDTuple([\n 'registry',\n '',\n `${scope}${data.name}@${data.version}`,\n ])\n const aliasedDepID = joinDepIDTuple([\n 'registry',\n 'npm',\n `${scope}${data.name}@${data.version}`,\n ])\n const node =\n graph.nodes.get(depID) ?? graph.nodes.get(aliasedDepID)\n if (node) {\n this.#fetchedDepIDs.add(node.id)\n this.set(node.id, asPackageReportData(data))\n } else {\n // eslint-disable-next-line no-console\n console.warn(\n `security-archive: failed to find node for ${scope}${data.name}@${data.version} found in the response.`,\n )\n }\n }\n }\n\n /**\n * Store new in-memory items to the database.\n */\n #storeNewItemsToDatabase(db: DatabaseSync): void {\n const insertData: DBWriteEntry[] = []\n for (const depID of this.#fetchedDepIDs) {\n const entry = this.info(depID)\n if (entry?.start && entry.ttl) {\n insertData.push([\n depID,\n JSON.stringify(entry.value),\n entry.start,\n entry.ttl,\n ])\n }\n }\n const dbWrite = db.prepare(\n 'INSERT OR REPLACE INTO cache (depID, report, start, ttl) ' +\n 'VALUES (?, ?, ?, ?)',\n )\n for (const data of insertData) {\n dbWrite.run(...data)\n }\n }\n\n /**\n * Validates that all public-registry packages in the graph\n * have a valid report data in the current in-memory cache.\n */\n #validateReportData(graph: GraphLike, specOptions: SpecOptions) {\n for (const node of graph.nodes.values()) {\n if (usesTargetRegistry(node.id, specOptions)) {\n if (!this.has(node.id)) {\n this.ok = false\n return\n }\n }\n }\n this.ok = true\n }\n\n /**\n * Starts the security archive by providing a {@link GraphLike} instance,\n * its registry-based nodes are going to be used as valid potential entries.\n *\n * Any entry that is missing from the persisted cached values are going\n * to be requested in a batch-request to the remote socket.dev API.\n */\n async refresh({\n graph,\n specOptions,\n }: SecurityArchiveRefreshOptions) {\n // should start by clearing the current in-memory cache\n this.clear()\n\n const db = this.#openDatabase()\n\n try {\n this.#loadItemsFromDatabase(db, graph)\n\n const queue = this.#queueUpRequiredPackages(graph, specOptions)\n // only reach for the remote API if there are packages queued up\n if (queue.size > 0) {\n // Parse the response data\n const res = await pRetry(\n () => this.#retrieveRemoteData(queue),\n { retries: this.#retries },\n )\n this.#loadFromNDJSON(res, graph)\n this.#storeNewItemsToDatabase(db)\n }\n\n // validates the refresh process was successful\n this.#validateReportData(graph, specOptions)\n } finally {\n db.exec('PRAGMA optimize')\n db.close()\n // TODO: at this point we could spawn a deref process to\n // remove entries with expired ttl values and vaccum the db\n }\n }\n\n /**\n * Outputs the current in-memory cache as a JSON object.\n */\n toJSON() {\n const obj: Record<DepID, PackageReportData> = {}\n for (const [key, value] of this.dump()) {\n obj[key] = value.value\n }\n return obj\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;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AC,MAAM,CAAC,EAAE,CAAC,CAAA;QACtB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,EAAgB;QAC3B,+DAA+D;QAC/D,iEAAiE;QACjE,MAAM,IAAI,CAAC,eAAe,CAAA;QAC1B,sBAAsB;QACtB,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;QAC1B,EAAE,CAAC,KAAK,EAAE,CAAA;QACV,0BAA0B;QAC1B,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;QACrB,IAAI,CAAC,eAAe,GAAG,SAAS,CAAA;QAChC,wDAAwD;QACxD,2DAA2D;IAC7D,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,MAAM,GAAG,GAAqC,EAAE,CAAA;QAChD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YACvC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAA;QACxB,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF","sourcesContent":["import { DatabaseSync } from 'node:sqlite'\nimport { mkdirSync } from 'node:fs'\nimport { dirname } from 'node:path'\nimport { LRUCache } from 'lru-cache'\nimport pRetry, { AbortError } from 'p-retry'\nimport { loadPackageJson } from 'package-json-from-dist'\nimport { asDepID, splitDepID, baseDepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport { XDG } from '@vltpkg/xdg'\nimport { asPackageReportData } from './types.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { NodeLike } from '@vltpkg/types'\nimport type {\n PackageReportData,\n SecurityArchiveLike,\n SecurityArchiveRefreshOptions,\n} from './types.ts'\n\nexport * from './types.ts'\n\nconst SOCKET_API_V0_URL = 'https://api.socket.dev/v0/purl?alerts=true'\nconst SOCKET_PUBLIC_API_TOKEN =\n 'sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api'\n\nexport const targetSecurityRegisty = 'https://registry.npmjs.org/'\n\nexport type JSONItemResponse = {\n namespace?: `@{string}`\n name: string\n version: string\n score: {\n overall: number\n license: number\n maintenance: number\n quality: number\n supplyChain: number\n vulnerability: number\n }\n}\n\nexport type DBReadEntry = {\n depID: string\n now: number\n report: string\n start: number\n ttl: number\n}\n\nexport type DBWriteEntry = [string, string, number, number]\n\nexport type SecurityArchiveOptions = LRUCache.OptionsBase<\n DepID,\n PackageReportData,\n unknown\n> & {\n /**\n * Security archive does not supports a fetch-on-demand model.\n */\n fetchMethod?: undefined\n /**\n * An optional value for the path in which to store the sqlite db.\n */\n path?: string\n /**\n * Number of retries attempts to reach the remote security API.\n */\n retries?: number\n}\n\n/**\n * Only the public npm registry has information available in the\n * socket.dev API. This function checks if a given depID is pointing\n * to the public npm registry and returns `true` if it does.\n */\nconst usesTargetRegistry = (node: NodeLike): boolean => {\n const depID = node.id\n const specOptions = node.options\n const [nodeType, nodeRegistry] = splitDepID(depID)\n\n if (nodeType !== 'registry') {\n return false\n }\n\n const reg =\n nodeRegistry === '' ?\n specOptions.registry\n : specOptions.registries?.[nodeRegistry]\n return reg === targetSecurityRegisty\n}\n\n// Loads the version number to be used in the User-Agent header\nexport const { version } = loadPackageJson(\n import.meta.filename,\n process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON,\n) as {\n version: string\n}\n\n/**\n * A database of security information for given packages from a list of nodes.\n *\n * Using the SecurityArchive.refresh() method will update the local cache\n * with information from the socket.dev APIs or load from the local storage\n * if available. Information about package security is then available\n * using the SecurityArchive.get() method.\n */\nexport class SecurityArchive\n extends LRUCache<DepID, PackageReportData>\n implements SecurityArchiveLike\n{\n #expired = new Set<DepID>()\n #pUpdateExpired: Promise<void> | undefined\n #path: string\n #retries: number\n #nodesByName = new Map<string, Set<NodeLike>>()\n #nodesByID = new Map<DepID, NodeLike>()\n\n /**\n * True if the refresh process was successful and report data is available\n * for all public registry packages from the initial list of nodes.\n */\n ok = false\n\n /**\n * Creates a new security archive instance and starts the refresh process.\n */\n static async start(\n options: SecurityArchiveOptions & SecurityArchiveRefreshOptions,\n ) {\n const archive = new SecurityArchive(options)\n await archive.refresh(options)\n return archive\n }\n\n /**\n * By default, limits to 100K entries in the in-memory archive.\n */\n static get defaultMax() {\n return 100_000\n }\n\n /**\n * By default, entries are cached for 3 hours.\n */\n static get defaultTtl() {\n return 1000 * 60 * 60 * 3\n }\n\n constructor(options: SecurityArchiveOptions = {}) {\n super({\n max: SecurityArchive.defaultMax,\n ttl: SecurityArchive.defaultTtl,\n ...options,\n allowStale: true,\n })\n\n this.#path =\n options.path ?? new XDG('vlt').cache('security-archive.db')\n this.#retries = options.retries ?? 3\n }\n\n /**\n * Retrieves a node using its name and version.\n */\n #retrieveNodeByNameVersion(\n name: string,\n version: string,\n ): NodeLike | undefined {\n for (const node of this.#nodesByName.get(name) ?? []) {\n if (node.version === version) {\n return node\n }\n }\n }\n\n /**\n * Opens a connection to the database at the given path.\n */\n #openDatabase(): DatabaseSync {\n mkdirSync(dirname(this.#path), { recursive: true })\n const db = new DatabaseSync(this.#path)\n db.exec(\n 'CREATE TABLE IF NOT EXISTS cache ' +\n '(depID TEXT PRIMARY KEY, report TEXT, ttl INTEGER, start INTEGER) ' +\n // WITHOUT ROWID models a key=value storage,\n // enforcing depID must be unique and not null\n // while using less space and more efficient lookups\n // https://www.sqlite.org/withoutrowid.html\n 'WITHOUT ROWID',\n )\n db.exec('PRAGMA journal_mode = WAL')\n db.exec('PRAGMA synchronous = NORMAL')\n return db\n }\n\n /**\n * Loads all valid items found in the database into the in-memory cache.\n */\n #loadItemsFromDatabase(db: DatabaseSync, nodes: NodeLike[]): void {\n const depIDs: string[] = []\n for (const node of nodes) {\n depIDs.push(`'${baseDepID(node.id)}'`)\n }\n // retrieves from the db packages using their dep-id reference\n // and only include entries that have a valid TTL value\n const dbRead = db.prepare(\n 'SELECT depID, report, start, ttl, ' +\n `(SELECT UNIXEPOCH('subsecond') * 1000) as now ` +\n 'FROM cache ' +\n `WHERE depID IN (${depIDs.join(',')})`,\n )\n // reset the list of expired entries\n this.#expired.clear()\n for (const entry of dbRead.all() as DBReadEntry[]) {\n const { depID, now, report, start, ttl } = entry\n const id = baseDepID(asDepID(depID))\n try {\n this.set(id, asPackageReportData(JSON.parse(report)), {\n ttl,\n start,\n })\n // stale values are queued up as expired for revalidation\n if (start + ttl < now) {\n this.#expired.add(id)\n }\n } catch {\n // prune any invalid entries from the database\n db.prepare('DELETE FROM cache WHERE depID = ?').run(depID)\n }\n }\n // TODO: we need to move this to a detached process in order for the\n // cli commands that make usage of the security-archive, e.g: vlt ls,\n // vlt query to not hang while waiting for stale-while-revalidate\n // request to finish and close the db connection\n this.#pUpdateExpired = this.#updateExpired(db)\n }\n\n /**\n * Updates the database with renewed entries for expired packages.\n */\n async #updateExpired(db: DatabaseSync): Promise<void> {\n const expiredQueue = new Set<Record<'purl', string>>()\n for (const depID of this.#expired) {\n const node = this.#nodesByID.get(baseDepID(depID))\n\n /* c8 ignore start */\n if (!node?.version) {\n // skip any missing node or nodes without a version, this\n // should not happen, but some optional dependencies might\n // end up in this state when reading from the lockfile\n continue\n }\n /* c8 ignore stop */\n\n const purl = `pkg:npm/${node.name}@${node.version}`\n expiredQueue.add({ purl })\n }\n if (expiredQueue.size > 0) {\n const res = await pRetry(\n () => this.#retrieveRemoteData(expiredQueue),\n { retries: this.#retries },\n )\n const ids = this.#loadFromNDJSON(res)\n this.#storeNewItemsToDatabase(db, ids)\n }\n }\n\n /**\n * Queues up all required packages that are missing from the archive.\n */\n #queueUpRequiredPackages(): Set<Record<'purl', string>> {\n const queue = new Set<Record<'purl', string>>()\n for (const node of this.#nodesByID.values()) {\n const normalizedId = baseDepID(node.id)\n // only queue up valid public registry\n // references that are missing from the archive\n // also skips any pkg marked as expired\n if (\n usesTargetRegistry(node) &&\n !this.has(normalizedId) &&\n !this.#expired.has(normalizedId)\n ) {\n const purl = `pkg:npm/${node.name}@${node.version}`\n queue.add({ purl })\n }\n }\n return queue\n }\n\n /**\n * Fetches security information from the socket.dev API.\n * Returns a string of NDJSON data.\n */\n async #retrieveRemoteData(\n queue: Set<Record<'purl', string>>,\n ): Promise<string> {\n // fetch information from the socket.dev API\n const req = await fetch(SOCKET_API_V0_URL, {\n method: 'POST',\n headers: {\n Authorization: `Basic ${Buffer.from(`${SOCKET_PUBLIC_API_TOKEN}:`).toString('base64url')}`,\n 'User-Agent': `@vltpkg/security-archive/${version}`,\n },\n body: JSON.stringify({\n components: Array.from(queue),\n }),\n })\n // on missing valid auth or API, it should abort the retry logic\n if (req.status === 404) {\n throw new AbortError('Missing API')\n }\n // on any other error throws an error that will trigger retry\n if (!req.ok || !(req.status >= 200 && req.status <= 299)) {\n throw error('Failed to fetch security data', { response: req })\n }\n\n const str = await req.text()\n return str.trim() + '\\n'\n }\n\n /**\n * Parses and load NDJSON data into the in-memory cache.\n * Returns a set of dep ids that were successfully loaded.\n */\n #loadFromNDJSON(str: string): Set<DepID> {\n // builds a set of dep ids that were successfully fetched and loaded\n const fetchedDepIDs = new Set<DepID>()\n const json = str.split('}\\n')\n for (const line of json) {\n if (!line.trim()) continue\n const data = JSON.parse(line + '}') as JSONItemResponse\n const scope = data.namespace ? `${data.namespace}/` : ''\n const name = `${scope}${data.name}`\n const node = this.#retrieveNodeByNameVersion(name, data.version)\n if (node) {\n const normalizedId = baseDepID(node.id)\n fetchedDepIDs.add(baseDepID(node.id))\n // Calculate average score from all score components\n const scoreComponents = [\n data.score.license,\n data.score.maintenance,\n data.score.quality,\n data.score.supplyChain,\n data.score.vulnerability,\n ]\n const newAverageScore = Number(\n (\n scoreComponents.reduce((sum, score) => sum + score, 0) /\n scoreComponents.length\n ).toFixed(2),\n )\n // Add average score to the score object\n const scoreWithNewAverage = {\n ...data.score,\n overall: newAverageScore,\n }\n this.set(\n normalizedId,\n asPackageReportData({\n ...data,\n score: scoreWithNewAverage,\n }),\n )\n } else {\n // eslint-disable-next-line no-console\n console.warn(\n `security-archive: failed to find node for ${scope}${data.name}@${data.version} found in the response.`,\n )\n }\n }\n return fetchedDepIDs\n }\n\n /**\n * Store new in-memory items to the database.\n */\n #storeNewItemsToDatabase(\n db: DatabaseSync,\n depIDs: Set<DepID>,\n ): void {\n const insertData: DBWriteEntry[] = []\n for (const depID of depIDs) {\n const entry = this.info(depID)\n if (entry?.start && entry.ttl) {\n insertData.push([\n depID,\n JSON.stringify(entry.value),\n entry.start,\n entry.ttl,\n ])\n }\n }\n const dbWrite = db.prepare(\n 'INSERT OR REPLACE INTO cache (depID, report, start, ttl) ' +\n 'VALUES (?, ?, ?, ?)',\n )\n for (const data of insertData) {\n dbWrite.run(...data)\n }\n }\n\n /**\n * Validates that all public-registry packages in the nodes\n * have a valid report data in the current in-memory cache.\n */\n #validateReportData() {\n for (const node of this.#nodesByID.values()) {\n if (usesTargetRegistry(node)) {\n if (!this.has(baseDepID(node.id))) {\n this.ok = false\n return\n }\n }\n }\n this.ok = true\n }\n\n /**\n * Starts the security archive by providing an array of {@link NodeLike} instances,\n * its registry-based nodes are going to be used as valid potential entries.\n *\n * Any entry that is missing from the persisted cached values are going\n * to be requested in a batch-request to the remote socket.dev API.\n */\n async refresh({ nodes }: SecurityArchiveRefreshOptions) {\n // should start by clearing the current in-memory cache\n this.clear()\n\n const db = this.#openDatabase()\n\n // indexes nodes by name and id for quick lookup\n this.#nodesByName.clear()\n this.#nodesByID.clear()\n for (const node of nodes) {\n /* c8 ignore start */\n const setByName =\n this.#nodesByName.get(node.name ?? '') ?? new Set()\n setByName.add(node)\n this.#nodesByName.set(node.name ?? '', setByName)\n /* c8 ignore stop */\n this.#nodesByID.set(baseDepID(node.id), node)\n }\n\n try {\n this.#loadItemsFromDatabase(db, nodes)\n\n const queue = this.#queueUpRequiredPackages()\n // only reach for the remote API if there are packages queued up\n if (queue.size > 0) {\n // Parse the response data\n const res = await pRetry(\n () => this.#retrieveRemoteData(queue),\n { retries: this.#retries },\n )\n const ids = this.#loadFromNDJSON(res)\n this.#storeNewItemsToDatabase(db, ids)\n }\n\n // validates the refresh process was successful\n this.#validateReportData()\n } finally {\n // TODO: once we move the stale-while-revalidate to a detached process\n // the this.#close method no longer needs to be async\n void this.#close(db)\n }\n }\n\n /**\n * Closes the database connection and cleans up the internal state.\n */\n async #close(db: DatabaseSync) {\n // the revalidation of stale entries might not yet be completed\n // so in case we have a pending promise for that, we need to wait\n await this.#pUpdateExpired\n // close db connection\n db.exec('PRAGMA optimize')\n db.close()\n // clean up internal state\n this.#expired.clear()\n this.#pUpdateExpired = undefined\n // TODO: at this point we could spawn a deref process to\n // remove entries with expired ttl values and vaccum the db\n }\n\n /**\n * Outputs the current in-memory cache as a JSON object.\n */\n toJSON() {\n const obj: Record<DepID, PackageReportData> = {}\n for (const [key, value] of this.dump()) {\n obj[key] = value.value\n }\n return obj\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  import type { DepID } from '@vltpkg/dep-id';
2
- import type { GraphLike } from '@vltpkg/graph';
3
- import type { SpecOptions } from '@vltpkg/spec';
2
+ import type { NodeLike } from '@vltpkg/types';
4
3
  /**
5
4
  * Parameter options for initializing a security archive.
6
5
  */
@@ -9,11 +8,7 @@ export type SecurityArchiveRefreshOptions = {
9
8
  * A @link{GraphLike} instance to find what packages the
10
9
  * security archive should have.
11
10
  */
12
- graph: GraphLike;
13
- /**
14
- * A @link{SpecOptions} instance to use for resolving dependencies.
15
- */
16
- specOptions: SpecOptions;
11
+ nodes: NodeLike[];
17
12
  };
18
13
  /**
19
14
  * An interface for interacting with a security archive.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C;;GAEG;AACH,MA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AAK,KAAK,CAAA;AAElB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,CAAU,EACS,EAAE;IACrB,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5B,MAAM,KAAK,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;IAC1D,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { GraphLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec'\n\n/**\n * Parameter options for initializing a security archive.\n */\nexport type SecurityArchiveRefreshOptions = {\n /**\n * A @link{GraphLike} instance to find what packages the\n * security archive should have.\n */\n graph: GraphLike\n /**\n * A @link{SpecOptions} instance to use for resolving dependencies.\n */\n specOptions: SpecOptions\n}\n\n/**\n * An interface for interacting with a security archive.\n */\nexport interface SecurityArchiveLike {\n get: (depId: DepID) => PackageReportData | undefined\n set: (depId: DepID, data: PackageReportData) => void\n delete: (depId: DepID) => void\n has: (depId: DepID) => boolean\n clear: () => void\n ok?: boolean\n}\n\nexport const isSecurityArchiveLike = (\n o: unknown,\n): o is SecurityArchiveLike =>\n typeof o === 'object' &&\n o != null &&\n 'get' in o &&\n 'set' in o &&\n 'delete' in o &&\n 'has' in o &&\n 'clear' in o\n\nexport const asSecurityArchiveLike = (\n o: unknown,\n): SecurityArchiveLike => {\n if (!isSecurityArchiveLike(o)) {\n throw error('Invalid security archive like', { found: o })\n }\n return o\n}\n\n/**\n * Package alert extra information.\n */\nexport type PackageAlertProps = {\n lastPublish: string\n cveId?: `CVE-${string}`\n cwes?: { id: `CWE-${string}` }[]\n}\n\n/**\n * A known alert for a given package.\n */\nexport type PackageAlert = {\n key: string\n type: string\n severity: 'low' | 'medium' | 'high' | 'critical'\n category: string\n props?: PackageAlertProps\n}\n\n/**\n * The scores for a given package\n */\nexport type PackageScore = {\n /**\n * The average of all score factors. (0-1)\n */\n overall: number\n /**\n * Score factors relating to package licensing (0-1)\n */\n license: number\n /**\n * Score factors relating to package maintenance (0-1)\n */\n maintenance: number\n /**\n * Score factors relating to code quality (0-1)\n */\n quality: number\n /**\n * Score factors relating to supply chain security (0-1)\n */\n supplyChain: number\n /**\n * Score factors relating to package vulnerabilities (0-1)\n */\n vulnerability: number\n}\n\n/**\n * The report data for a given package.\n */\nexport type PackageReportData = {\n id: string\n author: string[]\n size: number\n type: 'npm'\n namespace?: `@${string}`\n name: string\n version: string\n license: string\n alerts: PackageAlert[]\n score: PackageScore\n}\n\nexport const isPackageReportData = (\n o: unknown,\n): o is PackageReportData =>\n typeof o === 'object' &&\n o != null &&\n 'id' in o &&\n 'type' in o &&\n 'name' in o &&\n 'version' in o &&\n 'alerts' in o &&\n 'score' in o &&\n o.type === 'npm'\n\nexport const asPackageReportData = (\n o: unknown,\n): PackageReportData => {\n if (!isPackageReportData(o)) {\n throw error('Invalid package report data', { found: o })\n }\n return o\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AA2B3C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,CAAU,EACgB,EAAE,CAC5B,OAAO,CAAC,KAAK,QAAQ;IACrB,CAAC,IAAI,IAAI;IACT,KAAK,IAAI,CAAC;IACV,KAAK,IAAI,CAAC;IACV,QAAQ,IAAI,CAAC;IACb,KAAK,IAAI,CAAC;IACV,OAAO,IAAI,CAAC,CAAA;AAEd,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,CAAU,EACW,EAAE;IACvB,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9B,MAAM,KAAK,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;IAC5D,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAoED,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,CAAU,EACc,EAAE,CAC1B,OAAO,CAAC,KAAK,QAAQ;IACrB,CAAC,IAAI,IAAI;IACT,IAAI,IAAI,CAAC;IACT,MAAM,IAAI,CAAC;IACX,MAAM,IAAI,CAAC;IACX,SAAS,IAAI,CAAC;IACd,QAAQ,IAAI,CAAC;IACb,OAAO,IAAI,CAAC;IACZ,CAAC,CAAC,IAAI,KAAK,KAAK,CAAA;AAElB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,CAAU,EACS,EAAE;IACrB,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5B,MAAM,KAAK,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;IAC1D,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { NodeLike } from '@vltpkg/types'\n\n/**\n * Parameter options for initializing a security archive.\n */\nexport type SecurityArchiveRefreshOptions = {\n /**\n * A @link{GraphLike} instance to find what packages the\n * security archive should have.\n */\n nodes: NodeLike[]\n}\n\n/**\n * An interface for interacting with a security archive.\n */\nexport interface SecurityArchiveLike {\n get: (depId: DepID) => PackageReportData | undefined\n set: (depId: DepID, data: PackageReportData) => void\n delete: (depId: DepID) => void\n has: (depId: DepID) => boolean\n clear: () => void\n ok?: boolean\n}\n\nexport const isSecurityArchiveLike = (\n o: unknown,\n): o is SecurityArchiveLike =>\n typeof o === 'object' &&\n o != null &&\n 'get' in o &&\n 'set' in o &&\n 'delete' in o &&\n 'has' in o &&\n 'clear' in o\n\nexport const asSecurityArchiveLike = (\n o: unknown,\n): SecurityArchiveLike => {\n if (!isSecurityArchiveLike(o)) {\n throw error('Invalid security archive like', { found: o })\n }\n return o\n}\n\n/**\n * Package alert extra information.\n */\nexport type PackageAlertProps = {\n lastPublish: string\n cveId?: `CVE-${string}`\n cwes?: { id: `CWE-${string}` }[]\n}\n\n/**\n * A known alert for a given package.\n */\nexport type PackageAlert = {\n key: string\n type: string\n severity: 'low' | 'medium' | 'high' | 'critical'\n category: string\n props?: PackageAlertProps\n}\n\n/**\n * The scores for a given package\n */\nexport type PackageScore = {\n /**\n * The average of all score factors. (0-1)\n */\n overall: number\n /**\n * Score factors relating to package licensing (0-1)\n */\n license: number\n /**\n * Score factors relating to package maintenance (0-1)\n */\n maintenance: number\n /**\n * Score factors relating to code quality (0-1)\n */\n quality: number\n /**\n * Score factors relating to supply chain security (0-1)\n */\n supplyChain: number\n /**\n * Score factors relating to package vulnerabilities (0-1)\n */\n vulnerability: number\n}\n\n/**\n * The report data for a given package.\n */\nexport type PackageReportData = {\n id: string\n author: string[]\n size: number\n type: 'npm'\n namespace?: `@${string}`\n name: string\n version: string\n license: string\n alerts: PackageAlert[]\n score: PackageScore\n}\n\nexport const isPackageReportData = (\n o: unknown,\n): o is PackageReportData =>\n typeof o === 'object' &&\n o != null &&\n 'id' in o &&\n 'type' in o &&\n 'name' in o &&\n 'version' in o &&\n 'alerts' in o &&\n 'score' in o &&\n o.type === 'npm'\n\nexport const asPackageReportData = (\n o: unknown,\n): PackageReportData => {\n if (!isPackageReportData(o)) {\n throw error('Invalid package report data', { found: o })\n }\n return o\n}\n"]}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@vltpkg/security-archive",
3
3
  "description": "A database of security information of packages",
4
- "version": "0.0.0-9",
4
+ "version": "1.0.0-rc.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
8
8
  "directory": "src/security-archive"
9
9
  },
10
+ "author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
10
11
  "tshy": {
11
12
  "selfLink": false,
12
13
  "liveDev": true,
@@ -20,27 +21,26 @@
20
21
  }
21
22
  },
22
23
  "dependencies": {
23
- "lru-cache": "^11.0.2",
24
- "p-retry": "^6.2.1",
25
- "package-json-from-dist": "^1.0.0",
26
- "@vltpkg/dep-id": "0.0.0-9",
27
- "@vltpkg/graph": "0.0.0-9",
28
- "@vltpkg/spec": "0.0.0-9",
29
- "@vltpkg/error-cause": "0.0.0-9",
30
- "@vltpkg/types": "0.0.0-9",
31
- "@vltpkg/xdg": "0.0.0-9"
24
+ "lru-cache": "^11.1.0",
25
+ "p-retry": "^7.0.0",
26
+ "package-json-from-dist": "^1.0.1",
27
+ "@vltpkg/dep-id": "1.0.0-rc.2",
28
+ "@vltpkg/error-cause": "1.0.0-rc.2",
29
+ "@vltpkg/graph": "1.0.0-rc.2",
30
+ "@vltpkg/spec": "1.0.0-rc.2",
31
+ "@vltpkg/types": "1.0.0-rc.2",
32
+ "@vltpkg/xdg": "1.0.0-rc.2"
32
33
  },
33
34
  "devDependencies": {
34
- "@eslint/js": "^9.20.0",
35
- "@types/eslint__js": "^8.42.3",
36
- "@types/node": "^22.13.1",
37
- "eslint": "^9.20.0",
38
- "prettier": "^3.4.2",
35
+ "@eslint/js": "^9.34.0",
36
+ "@types/node": "^22.17.2",
37
+ "eslint": "^9.34.0",
38
+ "prettier": "^3.6.2",
39
39
  "tap": "^21.1.0",
40
40
  "tshy": "^3.0.2",
41
- "typedoc": "0.27.6",
41
+ "typedoc": "~0.27.9",
42
42
  "typescript": "5.7.3",
43
- "typescript-eslint": "^8.23.0"
43
+ "typescript-eslint": "^8.40.0"
44
44
  },
45
45
  "license": "BSD-2-Clause-Patent",
46
46
  "engines": {
@@ -78,6 +78,7 @@
78
78
  "snap": "tap",
79
79
  "test": "tap",
80
80
  "posttest": "tsc --noEmit",
81
+ "tshy": "tshy",
81
82
  "typecheck": "tsc --noEmit"
82
83
  }
83
84
  }