@renovatebot/osv-offline 4.4.0 → 4.5.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/README.md +33 -8
- package/dist/lib/download.js +12 -14
- package/dist/lib/osv-offline.js +5 -8
- package/dist/lib/split.js +15 -23
- package/package.json +9 -10
package/README.md
CHANGED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
## Environment variables
|
|
8
8
|
|
|
9
|
-
| Name | Description
|
|
10
|
-
| -------------------------------- |
|
|
11
|
-
| `OSV_OFFLINE_ROOT_DIR` | Directory of the downloaded databases
|
|
12
|
-
| `OSV_OFFLINE_DATABASE_FORMAT` | `zip` downloads all databases as one zip; `split` downloads each ecosystem on its first query, and again only when it changed
|
|
13
|
-
| `OSV_OFFLINE_DATABASE_URL` | URL of the database zip
|
|
14
|
-
| `OSV_OFFLINE_DATABASE_INDEX_URL` | URL of the `index.json` of the split format
|
|
15
|
-
| `OSV_OFFLINE_DISABLE_DOWNLOAD` | Set to `true` to use the databases in `OSV_OFFLINE_ROOT_DIR` without downloading them
|
|
16
|
-
| `OSV_OFFLINE_MAX_AGE` | How old the downloaded databases may be before they are downloaded again, as
|
|
9
|
+
| Name | Description | Default |
|
|
10
|
+
| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
11
|
+
| `OSV_OFFLINE_ROOT_DIR` | Directory of the downloaded databases | `<tmpdir>/osv-offline` |
|
|
12
|
+
| `OSV_OFFLINE_DATABASE_FORMAT` | `zip` downloads all databases as one zip; `split` downloads each ecosystem on its first query, and again only when it changed | `zip` |
|
|
13
|
+
| `OSV_OFFLINE_DATABASE_URL` | URL of the database zip | `https://github.com/renovatebot/osv-offline/releases/latest/download/osv-offline.zip` |
|
|
14
|
+
| `OSV_OFFLINE_DATABASE_INDEX_URL` | URL of the `index.json` of the split format | `https://renovatebot.github.io/osv-offline/v2/index.json` |
|
|
15
|
+
| `OSV_OFFLINE_DISABLE_DOWNLOAD` | Set to `true` to use the databases in `OSV_OFFLINE_ROOT_DIR` without downloading them | - |
|
|
16
|
+
| `OSV_OFFLINE_MAX_AGE` | How old the downloaded databases may be before they are downloaded again, as an [`ms`](https://github.com/vercel/ms) duration such as `30m`, `4h` or `7d` | `1d` |
|
|
17
17
|
|
|
18
18
|
### Split format
|
|
19
19
|
|
|
@@ -21,6 +21,31 @@ With `OSV_OFFLINE_DATABASE_FORMAT=split`, the databases are downloaded from the
|
|
|
21
21
|
|
|
22
22
|
To mirror the split format, copy `index.json` without its `baseUrl` and the files it lists into one directory, and set `OSV_OFFLINE_DATABASE_INDEX_URL` to the mirrored `index.json`. Files are resolved relative to the index then.
|
|
23
23
|
|
|
24
|
+
### Without internet access
|
|
25
|
+
|
|
26
|
+
These variables also apply to [Renovate's `osvVulnerabilityAlerts`](https://docs.renovatebot.com/configuration-options/#osvvulnerabilityalerts), which uses this package.
|
|
27
|
+
|
|
28
|
+
`osv-offline` downloads the databases again once they're older than `OSV_OFFLINE_MAX_AGE`, one day by default. Set `OSV_OFFLINE_DISABLE_DOWNLOAD=true` to turn that off.
|
|
29
|
+
|
|
30
|
+
To use an internal mirror, copy `osv-offline.zip` from the [latest release](https://github.com/renovatebot/osv-offline/releases/latest) to an internal web server and set `OSV_OFFLINE_DATABASE_URL` to the copy. The databases are downloaded from there again after `OSV_OFFLINE_MAX_AGE`.
|
|
31
|
+
|
|
32
|
+
Without any downloads, extract the databases yourself and disable the download:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
export OSV_OFFLINE_ROOT_DIR=/var/lib/osv-offline
|
|
36
|
+
export OSV_OFFLINE_DISABLE_DOWNLOAD=true
|
|
37
|
+
unzip -o osv-offline.zip -d "$OSV_OFFLINE_ROOT_DIR"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- `OSV_OFFLINE_ROOT_DIR` needs one `<ecosystem>.nedb` per ecosystem, e.g. `npm.nedb`; the `<ecosystem>.idx.json` next to it is optional but recommended, as it makes opening the database about four times faster
|
|
41
|
+
- to update while Renovate runs, extract a newer zip into a temporary directory on the same file system and move the files into `OSV_OFFLINE_ROOT_DIR`, the `.idx.json` files before the `.nedb` files, so no database is read while it's written
|
|
42
|
+
|
|
43
|
+
## Logging
|
|
44
|
+
|
|
45
|
+
The packages log to the logger set with `configure({ logger })` of [`@containerbase/base`](https://www.npmjs.com/package/@containerbase/base), eg. a pino or Renovate logger.
|
|
46
|
+
Their messages start with `OSV:`, eg. for Renovate's `logLevelRemap`.
|
|
47
|
+
Without one, they log through [`debug`](https://github.com/debug-js/debug) (namespace `osv-offline:*`).
|
|
48
|
+
|
|
24
49
|
## License
|
|
25
50
|
|
|
26
51
|
This package is licensed under [the MIT license](https://opensource.org/licenses/MIT).
|
package/dist/lib/download.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import got from 'got';
|
|
3
1
|
import { pipeline } from 'node:stream/promises';
|
|
4
|
-
import { OsvOfflineDb } from '@renovatebot/osv-offline-db';
|
|
5
2
|
import path from 'path';
|
|
3
|
+
import { OsvOfflineDb, createLogger } from '@renovatebot/osv-offline-db';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import got from 'got';
|
|
6
6
|
import { DateTime } from 'luxon';
|
|
7
7
|
import ms from 'ms';
|
|
8
8
|
import { failure, success } from "./types.js";
|
|
9
9
|
import { extractZip } from "./unzip.js";
|
|
10
|
-
|
|
11
|
-
const logger = debug('osv-offline:download');
|
|
10
|
+
const logger = createLogger('osv-offline:download');
|
|
12
11
|
const defaultMaxAge = '1d';
|
|
13
12
|
/**
|
|
14
13
|
* Returns how many milliseconds old the local databases may be before they are downloaded again: `OSV_OFFLINE_MAX_AGE` (e.g. `4h`), or one day.
|
|
@@ -21,7 +20,7 @@ export function getMaxAge() {
|
|
|
21
20
|
// returns `undefined` for an invalid value, despite the type
|
|
22
21
|
const maxAge = ms(value);
|
|
23
22
|
if (maxAge === undefined) {
|
|
24
|
-
logger(`Invalid OSV_OFFLINE_MAX_AGE '${value}', using ${defaultMaxAge}.`);
|
|
23
|
+
logger.warn(`Invalid OSV_OFFLINE_MAX_AGE '${value}', using ${defaultMaxAge}.`);
|
|
25
24
|
return ms(defaultMaxAge);
|
|
26
25
|
}
|
|
27
26
|
return maxAge;
|
|
@@ -29,7 +28,7 @@ export function getMaxAge() {
|
|
|
29
28
|
export async function tryDownloadDb() {
|
|
30
29
|
await fs.ensureDir(OsvOfflineDb.rootDirectory);
|
|
31
30
|
if (process.env.OSV_OFFLINE_DISABLE_DOWNLOAD?.toLowerCase() === 'true') {
|
|
32
|
-
logger('Skipping database download.');
|
|
31
|
+
logger.debug('Skipping database download.');
|
|
33
32
|
return success();
|
|
34
33
|
}
|
|
35
34
|
// if local database exists and is younger than the maximum age, don't do any network requests
|
|
@@ -41,24 +40,23 @@ export async function tryDownloadDb() {
|
|
|
41
40
|
// ignored
|
|
42
41
|
}
|
|
43
42
|
if (stats !== undefined &&
|
|
44
|
-
DateTime.utc().diff(DateTime.fromJSDate(stats.mtime)).toMillis() <
|
|
45
|
-
|
|
46
|
-
logger('Skipping download, databases are up-to-date.');
|
|
43
|
+
DateTime.utc().diff(DateTime.fromJSDate(stats.mtime)).toMillis() < getMaxAge()) {
|
|
44
|
+
logger.debug('Skipping download, databases are up-to-date.');
|
|
47
45
|
return success();
|
|
48
46
|
}
|
|
49
47
|
// only download databases if local databases are missing or remote is newer
|
|
50
48
|
// download and extract into a temporary directory first, so a failed attempt leaves the current databases untouched
|
|
51
49
|
const tmpDir = await fs.mkdtemp(path.join(OsvOfflineDb.rootDirectory, '.download-'));
|
|
52
50
|
try {
|
|
53
|
-
logger('Downloading databases ...');
|
|
51
|
+
logger.trace('Downloading databases ...');
|
|
54
52
|
const databaseUrl = process.env.OSV_OFFLINE_DATABASE_URL ??
|
|
55
53
|
'https://github.com/renovatebot/osv-offline/releases/latest/download/osv-offline.zip';
|
|
56
54
|
const stream = got.stream(databaseUrl);
|
|
57
55
|
const tmpZipPath = path.join(tmpDir, 'osv-offline.zip');
|
|
58
56
|
const writeStream = fs.createWriteStream(tmpZipPath);
|
|
59
57
|
await pipeline(stream, writeStream);
|
|
60
|
-
logger('Downloading databases done.');
|
|
61
|
-
logger('Extracting databases ...');
|
|
58
|
+
logger.trace('Downloading databases done.');
|
|
59
|
+
logger.trace('Extracting databases ...');
|
|
62
60
|
const extractDir = path.join(tmpDir, 'extracted');
|
|
63
61
|
await fs.ensureDir(extractDir);
|
|
64
62
|
const files = await extractZip(tmpZipPath, extractDir);
|
|
@@ -68,7 +66,7 @@ export async function tryDownloadDb() {
|
|
|
68
66
|
}
|
|
69
67
|
// the zip's modification time marks the databases as up-to-date, so it's moved last
|
|
70
68
|
await fs.rename(tmpZipPath, path.join(OsvOfflineDb.rootDirectory, 'osv-offline.zip'));
|
|
71
|
-
logger('Extracting databases done.');
|
|
69
|
+
logger.trace('Extracting databases done.');
|
|
72
70
|
}
|
|
73
71
|
catch (err) {
|
|
74
72
|
return failure(err);
|
package/dist/lib/osv-offline.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { OsvOfflineDb } from '@renovatebot/osv-offline-db';
|
|
1
|
+
import { OsvOfflineDb, createLogger } from '@renovatebot/osv-offline-db';
|
|
2
2
|
import { tryDownloadDb } from "./download.js";
|
|
3
3
|
import { SplitDownloader } from "./split.js";
|
|
4
|
-
|
|
5
|
-
const logger = debug('osv-offline:download');
|
|
4
|
+
const logger = createLogger('osv-offline:download');
|
|
6
5
|
/**
|
|
7
6
|
* Whether the databases are downloaded in the split format, one ecosystem at a time, instead of as one zip.
|
|
8
7
|
*/
|
|
@@ -11,13 +10,11 @@ function useSplitFormat() {
|
|
|
11
10
|
}
|
|
12
11
|
export class OsvOffline {
|
|
13
12
|
osvOfflineDb;
|
|
14
|
-
splitDownloader = useSplitFormat()
|
|
15
|
-
? new SplitDownloader()
|
|
16
|
-
: undefined;
|
|
13
|
+
splitDownloader = useSplitFormat() ? new SplitDownloader() : undefined;
|
|
17
14
|
constructor() {
|
|
18
|
-
logger('Initializing databases ...');
|
|
15
|
+
logger.trace('Initializing databases ...');
|
|
19
16
|
this.osvOfflineDb = OsvOfflineDb.create();
|
|
20
|
-
logger('Initializing databases done.');
|
|
17
|
+
logger.trace('Initializing databases done.');
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
23
20
|
* Asynchronous code required as part of class instantiation
|
package/dist/lib/split.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { OsvOfflineDb, getIndexFileName, parseSplitIndex, } from '@renovatebot/osv-offline-db';
|
|
2
|
-
import debug from 'debug';
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
|
-
import got from 'got';
|
|
5
1
|
import { createHash } from 'node:crypto';
|
|
6
2
|
import { createWriteStream } from 'node:fs';
|
|
7
3
|
import path from 'node:path';
|
|
8
4
|
import { Transform } from 'node:stream';
|
|
9
5
|
import { pipeline } from 'node:stream/promises';
|
|
10
6
|
import { createZstdDecompress } from 'node:zlib';
|
|
7
|
+
import { OsvOfflineDb, createLogger, getIndexFileName, parseSplitIndex, } from '@renovatebot/osv-offline-db';
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import got from 'got';
|
|
11
10
|
import { getMaxAge } from "./download.js";
|
|
12
|
-
const logger =
|
|
11
|
+
const logger = createLogger('osv-offline:split');
|
|
13
12
|
const defaultIndexUrl = 'https://renovatebot.github.io/osv-offline/v2/index.json';
|
|
14
13
|
/** how long to wait before retrying a failed update, so an unreachable host isn't requested on every query */
|
|
15
14
|
const retryDelay = 5 * 60 * 1000;
|
|
@@ -43,7 +42,7 @@ function getDatabaseFileName(ecosystem) {
|
|
|
43
42
|
return `${ecosystem.toLowerCase()}.nedb`;
|
|
44
43
|
}
|
|
45
44
|
function isNotFound(err) {
|
|
46
|
-
return
|
|
45
|
+
return err.response?.statusCode === 404;
|
|
47
46
|
}
|
|
48
47
|
/**
|
|
49
48
|
* Downloads the databases of the split format: each ecosystem on its first use, and again only when it changed.
|
|
@@ -79,7 +78,7 @@ export class SplitDownloader {
|
|
|
79
78
|
if (!(await this.hasDatabase(ecosystem))) {
|
|
80
79
|
throw err;
|
|
81
80
|
}
|
|
82
|
-
logger(`Updating ecosystem '${ecosystem}' failed: ${String(err)}`);
|
|
81
|
+
logger.warn(`Updating ecosystem '${ecosystem}' failed: ${String(err)}`);
|
|
83
82
|
}
|
|
84
83
|
})();
|
|
85
84
|
this.checked.set(ecosystem, entry);
|
|
@@ -94,11 +93,8 @@ export class SplitDownloader {
|
|
|
94
93
|
const age = stateStat ? Date.now() - stateStat.mtimeMs : Infinity;
|
|
95
94
|
// an mtime in the future, e.g. from clock skew, counts as outdated, so it can't extend the maximum age; a second
|
|
96
95
|
// of tolerance, as file times are more precise than Date.now()
|
|
97
|
-
if (stateStat &&
|
|
98
|
-
|
|
99
|
-
age < this.maxAge &&
|
|
100
|
-
(await this.hasDatabase(ecosystem))) {
|
|
101
|
-
logger(`Ecosystem '${ecosystem}' is up-to-date.`);
|
|
96
|
+
if (stateStat && age > -1000 && age < this.maxAge && (await this.hasDatabase(ecosystem))) {
|
|
97
|
+
logger.trace(`Ecosystem '${ecosystem}' is up-to-date.`);
|
|
102
98
|
return stateStat.mtimeMs;
|
|
103
99
|
}
|
|
104
100
|
try {
|
|
@@ -109,7 +105,7 @@ export class SplitDownloader {
|
|
|
109
105
|
throw err;
|
|
110
106
|
}
|
|
111
107
|
// the index may be outdated, e.g. served by a caching proxy
|
|
112
|
-
logger(`File of ecosystem '${ecosystem}' not found, retrying ...`);
|
|
108
|
+
logger.debug(`File of ecosystem '${ecosystem}' not found, retrying ...`);
|
|
113
109
|
return await this.updateFromIndex(ecosystem, true);
|
|
114
110
|
}
|
|
115
111
|
}
|
|
@@ -120,22 +116,20 @@ export class SplitDownloader {
|
|
|
120
116
|
const { value: index, fetched } = await this.getIndex(refresh);
|
|
121
117
|
const files = index.ecosystems[ecosystem];
|
|
122
118
|
if (!files) {
|
|
123
|
-
logger(`No files for ecosystem '${ecosystem}' in the index.`);
|
|
119
|
+
logger.debug(`No files for ecosystem '${ecosystem}' in the index.`);
|
|
124
120
|
return fetched;
|
|
125
121
|
}
|
|
126
122
|
const statePath = this.getStatePath(ecosystem);
|
|
127
|
-
const state = (await fs
|
|
128
|
-
.readJson(statePath)
|
|
129
|
-
.catch(() => null));
|
|
123
|
+
const state = (await fs.readJson(statePath).catch(() => null));
|
|
130
124
|
if (state?.database === files.database.sha256 &&
|
|
131
125
|
state.index === files.index.sha256 &&
|
|
132
126
|
(await this.hasDatabase(ecosystem))) {
|
|
133
|
-
logger(`Ecosystem '${ecosystem}' is unchanged.`);
|
|
127
|
+
logger.trace(`Ecosystem '${ecosystem}' is unchanged.`);
|
|
134
128
|
// the files are as fresh as the index they were checked against
|
|
135
129
|
await fs.utimes(statePath, new Date(fetched), new Date(fetched));
|
|
136
130
|
return fetched;
|
|
137
131
|
}
|
|
138
|
-
logger(`Downloading ecosystem '${ecosystem}' ...`);
|
|
132
|
+
logger.trace(`Downloading ecosystem '${ecosystem}' ...`);
|
|
139
133
|
await fs.ensureDir(OsvOfflineDb.rootDirectory);
|
|
140
134
|
const tmpDir = await fs.mkdtemp(path.join(OsvOfflineDb.rootDirectory, '.download-'));
|
|
141
135
|
try {
|
|
@@ -154,7 +148,7 @@ export class SplitDownloader {
|
|
|
154
148
|
};
|
|
155
149
|
await fs.writeJson(statePath, newState);
|
|
156
150
|
await fs.utimes(statePath, new Date(fetched), new Date(fetched));
|
|
157
|
-
logger(`Downloading ecosystem '${ecosystem}' done.`);
|
|
151
|
+
logger.trace(`Downloading ecosystem '${ecosystem}' done.`);
|
|
158
152
|
return fetched;
|
|
159
153
|
}
|
|
160
154
|
finally {
|
|
@@ -165,9 +159,7 @@ export class SplitDownloader {
|
|
|
165
159
|
* Returns the index, fetching it when it's missing, older than the maximum age, or `refresh` is set.
|
|
166
160
|
*/
|
|
167
161
|
async getIndex(refresh) {
|
|
168
|
-
if (this.index &&
|
|
169
|
-
!refresh &&
|
|
170
|
-
Date.now() - this.index.fetched < this.maxAge) {
|
|
162
|
+
if (this.index && !refresh && Date.now() - this.index.fetched < this.maxAge) {
|
|
171
163
|
return this.index;
|
|
172
164
|
}
|
|
173
165
|
const url = new URL(this.indexUrl);
|
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renovatebot/osv-offline",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"main": "dist/index.js",
|
|
3
|
+
"version": "4.5.0",
|
|
5
4
|
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
5
|
"repository": {
|
|
11
6
|
"type": "git",
|
|
12
7
|
"url": "https://github.com/renovatebot/osv-offline.git"
|
|
13
8
|
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@renovatebot/osv-offline-db": "4.
|
|
16
|
-
"debug": "^4.4.3",
|
|
15
|
+
"@renovatebot/osv-offline-db": "4.5.0",
|
|
17
16
|
"fs-extra": "^11.4.1",
|
|
18
17
|
"got": "^15.1.0",
|
|
19
18
|
"luxon": "^3.7.2",
|
|
@@ -22,13 +21,13 @@
|
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
23
|
"@types/adm-zip": "0.6.0",
|
|
25
|
-
"@types/debug": "4.1.13",
|
|
26
24
|
"@types/fs-extra": "11.0.4",
|
|
27
25
|
"@types/luxon": "3.7.6",
|
|
28
26
|
"@types/ms": "2.1.0",
|
|
29
27
|
"@types/node": "24.19.2",
|
|
30
28
|
"@types/yauzl": "3.4.0",
|
|
31
|
-
"adm-zip": "0.6.1"
|
|
29
|
+
"adm-zip": "0.6.1",
|
|
30
|
+
"vitest": "4.1.12"
|
|
32
31
|
},
|
|
33
32
|
"engines": {
|
|
34
33
|
"node": ">=24.11.0",
|