@preventive/upstream 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/advisories.d.ts CHANGED
@@ -19,6 +19,10 @@ export interface Package {
19
19
  // Bundler writes it (`3.3.6p108`). A `github` package takes a tag (`v4` its
20
20
  // whole line), a branch or a commit; an unversioned Swift pin is refused.
21
21
  versions: string[]
22
+ // A `github` package: true to ask its repository alone, its name sent to
23
+ // no other source (OSV), as for one not everyone may read. Any spelling
24
+ // saying so holds for all. Not for other ecosystems.
25
+ internal?: boolean
22
26
  }
23
27
 
24
28
  export interface AdvisoryOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preventive/upstream",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Minimal npm, crates.io, RubyGems, Soldeer, CocoaPods trunk, GitHub and git checkout clients",
5
5
  "type": "module",
6
6
  "exports": {
@@ -62,14 +62,19 @@ async function actionRows(asked, details) {
62
62
  }
63
63
 
64
64
  // GitHub repositories as dependencies: OSV's records of them as Actions,
65
- // and every range their own advisories list, whichever package it names.
65
+ // but of those `internal`, and every range their own advisories list,
66
+ // whichever package it names.
66
67
  export const GITHUB = {
67
68
  repositoryOnly: true,
68
69
  assertName: assertRepo,
69
70
  nameKey: (repo) => repo.toLowerCase(),
70
71
  assertVersion: assertion('a version or a branch name', isRefName),
71
- advisories: async (asked, { github, details, cache }) => (await Promise.all([
72
- actionRows(asked, details),
73
- repositoryAdvisories(github, asked, { repoOf: (repo) => repo, versionsIn: bySemver(coversPlaceholder), details, cache }),
74
- ])).flat(),
72
+ advisories: async (asked, { github, details, cache, internal }) => {
73
+ const external = new Map(asked)
74
+ for (const name of internal) external.delete(name)
75
+ return (await Promise.all([
76
+ actionRows(external, details),
77
+ repositoryAdvisories(github, asked, { repoOf: (repo) => repo, versionsIn: bySemver(coversPlaceholder), details, cache }),
78
+ ])).flat()
79
+ },
75
80
  }
@@ -14,17 +14,19 @@ const byNumbers = new Intl.Collator('en', { numeric: true }).compare
14
14
  const assertEcosystem = assertion(`one of ${Object.keys(ECOSYSTEMS).join(', ')}`, (value) => typeof value === 'string' && Object.hasOwn(ECOSYSTEMS, value))
15
15
  const assertVersions = assertion('a non-empty array', (value) => Array.isArray(value) && value.length > 0)
16
16
 
17
- // Ecosystem -> name -> { versions, github? }, every package checked first.
17
+ // Ecosystem -> name -> { versions, github?, internal? }, every package
18
+ // checked first. A name is internal where any of its spellings is.
18
19
  function collect(packages) {
19
20
  assert.ok(isIterable(packages), 'advisories: packages must be an iterable of { ecosystem, name, github?, versions }')
20
21
  const byEcosystem = new Map()
21
22
  const spelled = new Map()
22
23
  for (const pkg of packages) {
23
- assertArgs('advisories', pkg, { ecosystem: assertEcosystem, name: null, github: optional(assertRepo), versions: assertVersions }, 'package')
24
+ assertArgs('advisories', pkg, { ecosystem: assertEcosystem, name: null, github: optional(assertRepo), versions: assertVersions, internal: optional(assertBoolean) }, 'package')
24
25
  const { assertName, assertVersion, nameKey } = ECOSYSTEMS[pkg.ecosystem]
25
26
  assertName('advisories', 'package.name', pkg.name)
26
27
  for (const version of pkg.versions) assertVersion('advisories', 'package.versions', version)
27
28
  assert.ok(pkg.ecosystem !== 'github' || pkg.github === undefined, 'advisories: a github package is its own repository, and takes no package.github')
29
+ assert.ok(pkg.ecosystem === 'github' || pkg.internal === undefined, 'advisories: only a github package takes package.internal')
28
30
  const named = byEcosystem.get(pkg.ecosystem) ?? byEcosystem.set(pkg.ecosystem, new Map()).get(pkg.ecosystem)
29
31
  // A repository's name in any case, a Python package's as PEP 503
30
32
  // normalizes it: the first spelling stands.
@@ -33,6 +35,7 @@ function collect(packages) {
33
35
  const entry = named.get(name) ?? named.set(name, { versions: new Set() }).get(name)
34
36
  assert.ok(pkg.github === undefined || entry.github === undefined || sameName(entry.github, pkg.github), `advisories: ${pkg.name} is given two repositories`)
35
37
  entry.github ??= pkg.github
38
+ entry.internal ||= pkg.internal === true
36
39
  for (const version of pkg.versions) entry.versions.add(version)
37
40
  }
38
41
  return byEcosystem
@@ -90,7 +93,8 @@ export async function advisories(packages, options = {}) {
90
93
  const names = [...named.keys()].toSorted()
91
94
  const asked = new Map(names.map((name) => [name, [...named.get(name).versions].toSorted(compare)]))
92
95
  const known = new Map(names.filter((name) => named.get(name).github).map((name) => [name, named.get(name).github]))
93
- const rows = await find(asked, { github: options.github, repoAdvisories: options.repoAdvisories === true, details: options.details === true, osv: options.osv === true, known, cache: options.cache })
96
+ const internal = new Set(names.filter((name) => named.get(name).internal))
97
+ const rows = await find(asked, { github: options.github, repoAdvisories: options.repoAdvisories === true, details: options.details === true, osv: options.osv === true, known, internal, cache: options.cache })
94
98
  return oneRowPerAdvisory(rows.filter((row) => row.versions.length > 0), asked).map((row) => ({ ecosystem, ...row, ...(isMalware(row) && { malware: true }) }))
95
99
  }))
96
100
  return found.flat().toSorted((a, b) => order(a.ecosystem, b.ecosystem) || order(a.name, b.name))