addons-scanner-utils 7.1.0 → 8.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.
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import fs from 'fs';
3
4
  import { Request, RequestHandler } from 'express';
4
- import download from 'download';
5
+ import fetch from 'node-fetch';
5
6
  declare type ApiError = Error & {
6
7
  extraInfo?: string;
7
8
  status?: number;
@@ -17,7 +18,7 @@ export declare type RequestWithFiles = Request & {
17
18
  };
18
19
  export declare type FunctionConfig = {
19
20
  _console?: typeof console;
20
- _download?: typeof download;
21
+ _fetch?: typeof fetch;
21
22
  _process?: typeof process;
22
23
  _unlinkFile?: typeof fs.promises.unlink;
23
24
  apiKeyEnvVarName?: string;
@@ -26,5 +27,5 @@ export declare type FunctionConfig = {
26
27
  tmpDir?: string;
27
28
  xpiFilename?: string;
28
29
  };
29
- export declare const createExpressApp: ({ _console, _download, _process, _unlinkFile, apiKeyEnvVarName, requiredApiKeyParam, requiredDownloadUrlParam, tmpDir, xpiFilename, }?: FunctionConfig) => (handler: RequestHandler) => import("express-serve-static-core").Express;
30
+ export declare const createExpressApp: ({ _console, _fetch, _process, _unlinkFile, apiKeyEnvVarName, requiredApiKeyParam, requiredDownloadUrlParam, tmpDir, xpiFilename, }?: FunctionConfig) => (handler: RequestHandler) => import("express-serve-static-core").Express;
30
31
  export {};
package/dist/functions.js CHANGED
@@ -16,9 +16,12 @@ exports.createExpressApp = exports.createApiError = void 0;
16
16
  const fs_1 = __importDefault(require("fs"));
17
17
  const os_1 = __importDefault(require("os"));
18
18
  const path_1 = __importDefault(require("path"));
19
+ const node_fs_1 = require("node:fs");
20
+ const node_stream_1 = require("node:stream");
21
+ const node_util_1 = require("node:util");
19
22
  const express_1 = __importDefault(require("express"));
20
23
  const body_parser_1 = __importDefault(require("body-parser"));
21
- const download_1 = __importDefault(require("download"));
24
+ const node_fetch_1 = __importDefault(require("node-fetch"));
22
25
  const safe_compare_1 = __importDefault(require("safe-compare"));
23
26
  const createApiError = ({ message, extraInfo, status = 500, }) => {
24
27
  const error = new Error(message);
@@ -27,7 +30,7 @@ const createApiError = ({ message, extraInfo, status = 500, }) => {
27
30
  return error;
28
31
  };
29
32
  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) => {
33
+ const createExpressApp = ({ _console = console, _fetch = node_fetch_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) => {
31
34
  const app = (0, express_1.default)();
32
35
  const allowedOrigin = _process.env.ALLOWED_ORIGIN || null;
33
36
  if (!allowedOrigin) {
@@ -90,8 +93,13 @@ const createExpressApp = ({ _console = console, _download = download_1.default,
90
93
  return;
91
94
  }
92
95
  try {
93
- yield _download(downloadURL, tmpDir, { filename: xpiFilename });
94
96
  const xpiFilepath = path_1.default.join(tmpDir, xpiFilename);
97
+ const streamPipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
98
+ const response = yield _fetch(downloadURL);
99
+ if (!response.ok) {
100
+ throw new Error(`unexpected response ${response.statusText}`);
101
+ }
102
+ yield streamPipeline(response.body, (0, node_fs_1.createWriteStream)(xpiFilepath));
95
103
  req.xpiFilepath = xpiFilepath;
96
104
  // Add a listener that will run code after the response is sent.
97
105
  res.on('finish', () => {
package/dist/io/base.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Readable } from 'stream';
3
4
  import { Stderr } from '../stdio';
4
5
  declare type ScanFileFunction = (_path: string, isDirectory: boolean) => boolean;
package/dist/io/crx.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import defaultFs from 'fs';
3
4
  import yauzl, { ZipFile } from 'yauzl';
4
5
  import { IOBaseConstructorParams } from './base';
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Readable } from 'stream';
3
4
  import { IOBase, IOBaseConstructorParams } from './base';
4
5
  import { walkPromise } from './utils';
package/dist/io/xpi.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Readable } from 'stream';
3
4
  import yauzl, { Entry, ZipFile } from 'yauzl';
4
5
  import { IOBaseConstructorParams, IOBase } from './base';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "addons-scanner-utils",
3
- "version": "7.1.0",
3
+ "version": "8.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",
@@ -18,20 +18,16 @@
18
18
  "yauzl": "2.10.0"
19
19
  },
20
20
  "peerDependencies": {
21
- "@types/download": "8.0.1",
22
- "body-parser": "1.20.0",
23
- "download": "8.0.0",
24
- "express": "4.18.1",
21
+ "body-parser": "1.20.1",
22
+ "express": "4.18.2",
23
+ "node-fetch": "2.6.7",
25
24
  "safe-compare": "1.1.4"
26
25
  },
27
26
  "peerDependenciesMeta": {
28
- "@types/download": {
29
- "optional": true
30
- },
31
27
  "body-parser": {
32
28
  "optional": true
33
29
  },
34
- "download": {
30
+ "node-fetch": {
35
31
  "optional": true
36
32
  },
37
33
  "express": {
@@ -43,29 +39,29 @@
43
39
  },
44
40
  "devDependencies": {
45
41
  "@types/common-tags": "^1.8.0",
46
- "@types/download": "8.0.1",
47
- "@types/express": "4.17.13",
48
- "@types/jest": "^28.0.0",
42
+ "@types/express": "4.17.14",
43
+ "@types/jest": "^29.0.0",
49
44
  "@types/node": "^14.0.0",
45
+ "@types/node-fetch": "^2.6.2",
50
46
  "@types/safe-compare": "^1.1.0",
51
47
  "@types/sinon": "^10.0.0",
52
48
  "@types/supertest": "^2.0.8",
53
49
  "@typescript-eslint/eslint-plugin": "^5.0.0",
54
50
  "@typescript-eslint/parser": "^5.0.0",
55
- "body-parser": "1.20.0",
56
- "download": "8.0.0",
51
+ "body-parser": "1.20.1",
57
52
  "eslint": "^8.1.0",
58
53
  "eslint-config-amo": "^5.0.0",
59
54
  "eslint-plugin-amo": "^1.10.2",
60
- "express": "4.18.1",
61
- "jest": "^28.0.0",
55
+ "express": "4.18.2",
56
+ "jest": "^29.0.0",
57
+ "node-fetch": "2.6.7",
62
58
  "prettier": "2.7.1",
63
59
  "pretty-quick": "^3.0.0",
64
60
  "rimraf": "^3.0.0",
65
61
  "safe-compare": "1.1.4",
66
62
  "sinon": "^14.0.0",
67
63
  "supertest": "^6.0.0",
68
- "ts-jest": "^28.0.0",
64
+ "ts-jest": "^29.0.0",
69
65
  "type-coverage": "^2.3.0",
70
66
  "typescript": "^4.0.0"
71
67
  },