addons-scanner-utils 3.0.0 → 4.0.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/dist/functions.js +4 -2
- package/dist/stdio.js +8 -4
- package/dist/test-helpers.js +10 -5
- package/package.json +16 -9
package/dist/functions.js
CHANGED
|
@@ -20,13 +20,14 @@ const express_1 = __importDefault(require("express"));
|
|
|
20
20
|
const body_parser_1 = __importDefault(require("body-parser"));
|
|
21
21
|
const download_1 = __importDefault(require("download"));
|
|
22
22
|
const safe_compare_1 = __importDefault(require("safe-compare"));
|
|
23
|
-
|
|
23
|
+
const createApiError = ({ message, extraInfo, status = 500, }) => {
|
|
24
24
|
const error = new Error(message);
|
|
25
25
|
error.status = status;
|
|
26
26
|
error.extraInfo = extraInfo;
|
|
27
27
|
return error;
|
|
28
28
|
};
|
|
29
|
-
exports.
|
|
29
|
+
exports.createApiError = createApiError;
|
|
30
|
+
const createExpressApp = ({ _console = console, _download = download_1.default, _process = process, _unlinkFile = fs_1.default.promises.unlink, apiKeyEnvVarName = 'LAMBDA_API_KEY', requiredApiKeyParam = 'api_key', requiredDownloadUrlParam = 'download_url', tmpDir = os_1.default.tmpdir(), xpiFilename = 'input.xpi', } = {}) => (handler) => {
|
|
30
31
|
const app = express_1.default();
|
|
31
32
|
const allowedOrigin = _process.env.ALLOWED_ORIGIN || null;
|
|
32
33
|
if (!allowedOrigin) {
|
|
@@ -126,3 +127,4 @@ exports.createExpressApp = ({ _console = console, _download = download_1.default
|
|
|
126
127
|
});
|
|
127
128
|
return app;
|
|
128
129
|
};
|
|
130
|
+
exports.createExpressApp = createExpressApp;
|
package/dist/stdio.js
CHANGED
|
@@ -6,7 +6,7 @@ exports.createInMemoryStdout = exports.createConsoleStdout = exports.createInMem
|
|
|
6
6
|
// `verboseLevel` argument (and the number of `-v` passed to the CLI).
|
|
7
7
|
//
|
|
8
8
|
// By default, only errors are shown.
|
|
9
|
-
|
|
9
|
+
const createConsoleStderr = ({ _console = console, programName, verboseLevel = 0, }) => {
|
|
10
10
|
const logWithPrefix = (message) => {
|
|
11
11
|
_console.error(`${programName}: ${message}`);
|
|
12
12
|
};
|
|
@@ -29,7 +29,8 @@ exports.createConsoleStderr = ({ _console = console, programName, verboseLevel =
|
|
|
29
29
|
};
|
|
30
30
|
return stderr;
|
|
31
31
|
};
|
|
32
|
-
exports.
|
|
32
|
+
exports.createConsoleStderr = createConsoleStderr;
|
|
33
|
+
const createInMemoryStderr = () => {
|
|
33
34
|
return {
|
|
34
35
|
messages: {
|
|
35
36
|
debug: [],
|
|
@@ -47,16 +48,18 @@ exports.createInMemoryStderr = () => {
|
|
|
47
48
|
},
|
|
48
49
|
};
|
|
49
50
|
};
|
|
51
|
+
exports.createInMemoryStderr = createInMemoryStderr;
|
|
50
52
|
// `stdout` should be used for final outputs, and usually once at the end of
|
|
51
53
|
// the command.
|
|
52
|
-
|
|
54
|
+
const createConsoleStdout = ({ _console = console } = {}) => {
|
|
53
55
|
return {
|
|
54
56
|
write(message) {
|
|
55
57
|
_console.log(message);
|
|
56
58
|
},
|
|
57
59
|
};
|
|
58
60
|
};
|
|
59
|
-
exports.
|
|
61
|
+
exports.createConsoleStdout = createConsoleStdout;
|
|
62
|
+
const createInMemoryStdout = () => {
|
|
60
63
|
return {
|
|
61
64
|
output: '',
|
|
62
65
|
write(message) {
|
|
@@ -64,3 +67,4 @@ exports.createInMemoryStdout = () => {
|
|
|
64
67
|
},
|
|
65
68
|
};
|
|
66
69
|
};
|
|
70
|
+
exports.createInMemoryStdout = createInMemoryStdout;
|
package/dist/test-helpers.js
CHANGED
|
@@ -2,19 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createFakeZipFile = exports.createFakeFsStats = exports.readStringFromStream = exports.createFakeStderr = exports.createFakeStdout = void 0;
|
|
4
4
|
const yauzl_1 = require("yauzl");
|
|
5
|
-
|
|
5
|
+
const createFakeStdout = () => {
|
|
6
6
|
return {
|
|
7
7
|
write: jest.fn(),
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
exports.
|
|
10
|
+
exports.createFakeStdout = createFakeStdout;
|
|
11
|
+
const createFakeStderr = () => {
|
|
11
12
|
return {
|
|
12
13
|
debug: jest.fn(),
|
|
13
14
|
error: jest.fn(),
|
|
14
15
|
info: jest.fn(),
|
|
15
16
|
};
|
|
16
17
|
};
|
|
17
|
-
exports.
|
|
18
|
+
exports.createFakeStderr = createFakeStderr;
|
|
19
|
+
const readStringFromStream = (readStream, encoding) => {
|
|
18
20
|
return new Promise((resolve, reject) => {
|
|
19
21
|
let content = '';
|
|
20
22
|
readStream.on('readable', () => {
|
|
@@ -30,15 +32,17 @@ exports.readStringFromStream = (readStream, encoding) => {
|
|
|
30
32
|
readStream.on('error', reject);
|
|
31
33
|
});
|
|
32
34
|
};
|
|
33
|
-
exports.
|
|
35
|
+
exports.readStringFromStream = readStringFromStream;
|
|
36
|
+
const createFakeFsStats = ({ isFile = false, isDirectory = false, } = {}) => {
|
|
34
37
|
return {
|
|
35
38
|
isDirectory: () => isDirectory,
|
|
36
39
|
isFile: () => isFile,
|
|
37
40
|
};
|
|
38
41
|
};
|
|
42
|
+
exports.createFakeFsStats = createFakeFsStats;
|
|
39
43
|
class FakeRandomAccessReader extends yauzl_1.RandomAccessReader {
|
|
40
44
|
}
|
|
41
|
-
|
|
45
|
+
const createFakeZipFile = ({ autoClose = true, centralDirectoryOffset = 0, comment = '', decodeStrings = true,
|
|
42
46
|
// This is set to `1` to avoid an error with `RandomAccessReader.unref()`
|
|
43
47
|
// because we are using a `FakeRandomAccessReader`
|
|
44
48
|
entryCount = 1, fileSize = 0,
|
|
@@ -47,3 +51,4 @@ entryCount = 1, fileSize = 0,
|
|
|
47
51
|
lazyEntries = true, reader = new FakeRandomAccessReader(), validateEntrySizes = true, } = {}) => {
|
|
48
52
|
return new yauzl_1.ZipFile(reader, centralDirectoryOffset, fileSize, entryCount, comment, autoClose, lazyEntries, decodeStrings, validateEntrySizes);
|
|
49
53
|
};
|
|
54
|
+
exports.createFakeZipFile = createFakeZipFile;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "addons-scanner-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Various addons related helpers to build CLIs.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,21 +10,24 @@
|
|
|
10
10
|
"author": "Mozilla Add-ons Team",
|
|
11
11
|
"license": "MPL-2.0",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@types/download": "6.2.4",
|
|
14
13
|
"@types/yauzl": "2.9.1",
|
|
15
|
-
"body-parser": "1.19.0",
|
|
16
14
|
"common-tags": "1.8.0",
|
|
17
|
-
"download": "8.0.0",
|
|
18
|
-
"express": "4.17.1",
|
|
19
15
|
"first-chunk-stream": "3.0.0",
|
|
20
|
-
"safe-compare": "1.1.4",
|
|
21
16
|
"strip-bom-stream": "4.0.0",
|
|
22
|
-
"upath": "2.0.
|
|
17
|
+
"upath": "2.0.1",
|
|
23
18
|
"yauzl": "2.10.0"
|
|
24
19
|
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@types/download": "6.2.4",
|
|
22
|
+
"body-parser": "1.19.0",
|
|
23
|
+
"download": "8.0.0",
|
|
24
|
+
"express": "4.17.1",
|
|
25
|
+
"safe-compare": "1.1.4"
|
|
26
|
+
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@types/common-tags": "^1.8.0",
|
|
27
|
-
"@types/
|
|
29
|
+
"@types/download": "6.2.4",
|
|
30
|
+
"@types/express": "4.17.9",
|
|
28
31
|
"@types/jest": "^26.0.0",
|
|
29
32
|
"@types/node": "^12.7.5",
|
|
30
33
|
"@types/safe-compare": "^1.1.0",
|
|
@@ -32,17 +35,21 @@
|
|
|
32
35
|
"@types/supertest": "^2.0.8",
|
|
33
36
|
"@typescript-eslint/eslint-plugin": "^4.0.0",
|
|
34
37
|
"@typescript-eslint/parser": "^4.0.0",
|
|
38
|
+
"body-parser": "1.19.0",
|
|
35
39
|
"codecov": "^3.5.0",
|
|
40
|
+
"download": "8.0.0",
|
|
36
41
|
"eslint": "^7.0.0",
|
|
37
42
|
"eslint-config-amo": "^3.0.0",
|
|
38
43
|
"eslint-config-prettier": "^6.3.0",
|
|
39
44
|
"eslint-plugin-amo": "^1.10.2",
|
|
45
|
+
"express": "4.17.1",
|
|
40
46
|
"jest": "^26.0.0",
|
|
41
47
|
"prettier": "2.1.2",
|
|
42
48
|
"pretty-quick": "^3.0.0",
|
|
43
49
|
"rimraf": "^3.0.0",
|
|
50
|
+
"safe-compare": "1.1.4",
|
|
44
51
|
"sinon": "^9.0.0",
|
|
45
|
-
"supertest": "^
|
|
52
|
+
"supertest": "^6.0.0",
|
|
46
53
|
"ts-jest": "^26.0.0",
|
|
47
54
|
"type-coverage": "^2.3.0",
|
|
48
55
|
"typescript": "^4.0.0"
|