@renovatebot/osv-offline 4.3.2 → 4.4.1
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 +28 -9
- package/dist/lib/download.js +5 -6
- package/dist/lib/osv-offline.js +2 -4
- package/dist/lib/split.js +8 -15
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -6,21 +6,40 @@
|
|
|
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
|
|
|
20
|
-
With `OSV_OFFLINE_DATABASE_FORMAT=split`, the databases are downloaded from the release of the latest database update (`https://github.com/renovatebot/osv-offline/releases/download/1-<
|
|
20
|
+
With `OSV_OFFLINE_DATABASE_FORMAT=split`, the databases are downloaded from the release of the latest database update (`https://github.com/renovatebot/osv-offline/releases/download/1-<yyyyMMddHHmmss>/`), as listed by the index on `https://renovatebot.github.io/osv-offline/`. When outgoing traffic is restricted, allow `github.com`, `release-assets.githubusercontent.com` (where the downloads redirect to) and `renovatebot.github.io`.
|
|
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
|
+
|
|
24
43
|
## License
|
|
25
44
|
|
|
26
45
|
This package is licensed under [the MIT license](https://opensource.org/licenses/MIT).
|
package/dist/lib/download.js
CHANGED
|
@@ -1,13 +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 } from '@renovatebot/osv-offline-db';
|
|
4
|
+
import debug from 'debug';
|
|
5
|
+
import fs from 'fs-extra';
|
|
6
|
+
import got from 'got';
|
|
6
7
|
import { DateTime } from 'luxon';
|
|
7
8
|
import ms from 'ms';
|
|
8
9
|
import { failure, success } from "./types.js";
|
|
9
10
|
import { extractZip } from "./unzip.js";
|
|
10
|
-
import debug from 'debug';
|
|
11
11
|
const logger = debug('osv-offline:download');
|
|
12
12
|
const defaultMaxAge = '1d';
|
|
13
13
|
/**
|
|
@@ -41,8 +41,7 @@ export async function tryDownloadDb() {
|
|
|
41
41
|
// ignored
|
|
42
42
|
}
|
|
43
43
|
if (stats !== undefined &&
|
|
44
|
-
DateTime.utc().diff(DateTime.fromJSDate(stats.mtime)).toMillis() <
|
|
45
|
-
getMaxAge()) {
|
|
44
|
+
DateTime.utc().diff(DateTime.fromJSDate(stats.mtime)).toMillis() < getMaxAge()) {
|
|
46
45
|
logger('Skipping download, databases are up-to-date.');
|
|
47
46
|
return success();
|
|
48
47
|
}
|
package/dist/lib/osv-offline.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OsvOfflineDb } from '@renovatebot/osv-offline-db';
|
|
2
|
+
import debug from 'debug';
|
|
2
3
|
import { tryDownloadDb } from "./download.js";
|
|
3
4
|
import { SplitDownloader } from "./split.js";
|
|
4
|
-
import debug from 'debug';
|
|
5
5
|
const logger = debug('osv-offline:download');
|
|
6
6
|
/**
|
|
7
7
|
* Whether the databases are downloaded in the split format, one ecosystem at a time, instead of as one zip.
|
|
@@ -11,9 +11,7 @@ function useSplitFormat() {
|
|
|
11
11
|
}
|
|
12
12
|
export class OsvOffline {
|
|
13
13
|
osvOfflineDb;
|
|
14
|
-
splitDownloader = useSplitFormat()
|
|
15
|
-
? new SplitDownloader()
|
|
16
|
-
: undefined;
|
|
14
|
+
splitDownloader = useSplitFormat() ? new SplitDownloader() : undefined;
|
|
17
15
|
constructor() {
|
|
18
16
|
logger('Initializing databases ...');
|
|
19
17
|
this.osvOfflineDb = OsvOfflineDb.create();
|
package/dist/lib/split.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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, getIndexFileName, parseSplitIndex, } from '@renovatebot/osv-offline-db';
|
|
8
|
+
import debug from 'debug';
|
|
9
|
+
import fs from 'fs-extra';
|
|
10
|
+
import got from 'got';
|
|
11
11
|
import { getMaxAge } from "./download.js";
|
|
12
12
|
const logger = debug('osv-offline:split');
|
|
13
13
|
const defaultIndexUrl = 'https://renovatebot.github.io/osv-offline/v2/index.json';
|
|
@@ -43,7 +43,7 @@ function getDatabaseFileName(ecosystem) {
|
|
|
43
43
|
return `${ecosystem.toLowerCase()}.nedb`;
|
|
44
44
|
}
|
|
45
45
|
function isNotFound(err) {
|
|
46
|
-
return
|
|
46
|
+
return err.response?.statusCode === 404;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Downloads the databases of the split format: each ecosystem on its first use, and again only when it changed.
|
|
@@ -94,10 +94,7 @@ export class SplitDownloader {
|
|
|
94
94
|
const age = stateStat ? Date.now() - stateStat.mtimeMs : Infinity;
|
|
95
95
|
// an mtime in the future, e.g. from clock skew, counts as outdated, so it can't extend the maximum age; a second
|
|
96
96
|
// of tolerance, as file times are more precise than Date.now()
|
|
97
|
-
if (stateStat &&
|
|
98
|
-
age > -1000 &&
|
|
99
|
-
age < this.maxAge &&
|
|
100
|
-
(await this.hasDatabase(ecosystem))) {
|
|
97
|
+
if (stateStat && age > -1000 && age < this.maxAge && (await this.hasDatabase(ecosystem))) {
|
|
101
98
|
logger(`Ecosystem '${ecosystem}' is up-to-date.`);
|
|
102
99
|
return stateStat.mtimeMs;
|
|
103
100
|
}
|
|
@@ -124,9 +121,7 @@ export class SplitDownloader {
|
|
|
124
121
|
return fetched;
|
|
125
122
|
}
|
|
126
123
|
const statePath = this.getStatePath(ecosystem);
|
|
127
|
-
const state = (await fs
|
|
128
|
-
.readJson(statePath)
|
|
129
|
-
.catch(() => null));
|
|
124
|
+
const state = (await fs.readJson(statePath).catch(() => null));
|
|
130
125
|
if (state?.database === files.database.sha256 &&
|
|
131
126
|
state.index === files.index.sha256 &&
|
|
132
127
|
(await this.hasDatabase(ecosystem))) {
|
|
@@ -165,9 +160,7 @@ export class SplitDownloader {
|
|
|
165
160
|
* Returns the index, fetching it when it's missing, older than the maximum age, or `refresh` is set.
|
|
166
161
|
*/
|
|
167
162
|
async getIndex(refresh) {
|
|
168
|
-
if (this.index &&
|
|
169
|
-
!refresh &&
|
|
170
|
-
Date.now() - this.index.fetched < this.maxAge) {
|
|
163
|
+
if (this.index && !refresh && Date.now() - this.index.fetched < this.maxAge) {
|
|
171
164
|
return this.index;
|
|
172
165
|
}
|
|
173
166
|
const url = new URL(this.indexUrl);
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renovatebot/osv-offline",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"main": "dist/index.js",
|
|
3
|
+
"version": "4.4.1",
|
|
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.
|
|
15
|
+
"@renovatebot/osv-offline-db": "4.4.1",
|
|
16
16
|
"debug": "^4.4.3",
|
|
17
17
|
"fs-extra": "^11.4.1",
|
|
18
18
|
"got": "^15.1.0",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"@types/ms": "2.1.0",
|
|
29
29
|
"@types/node": "24.19.2",
|
|
30
30
|
"@types/yauzl": "3.4.0",
|
|
31
|
-
"adm-zip": "0.6.1"
|
|
31
|
+
"adm-zip": "0.6.1",
|
|
32
|
+
"vitest": "4.1.12"
|
|
32
33
|
},
|
|
33
34
|
"engines": {
|
|
34
35
|
"node": ">=24.11.0",
|