addons-scanner-utils 11.0.0 → 12.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/const.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const ECMA_VERSION = 15;
1
+ export declare const ECMA_VERSION = 16;
package/dist/const.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ECMA_VERSION = void 0;
4
4
  // This is the ECMAScript version officially supported by AMO.
5
- exports.ECMA_VERSION = 15; // a.k.a. 2024
5
+ exports.ECMA_VERSION = 16; // a.k.a. 2025
@@ -1,10 +1,27 @@
1
+ /**
2
+ * Error object with HTTP status code and optional extra information.
3
+ *
4
+ * @property message - Error message
5
+ * @property extraInfo - Additional error details
6
+ * @property status - HTTP status code
7
+ */
1
8
  export type ApiError = Error & {
2
9
  extraInfo?: string;
3
10
  status: number;
4
11
  };
12
+ /**
13
+ * Parameters for creating an API error.
14
+ *
15
+ * @property message - Error message
16
+ * @property extraInfo - Additional error details
17
+ * @property status - HTTP status code (default: 500)
18
+ */
5
19
  export type CreateApiErrorParams = {
6
20
  message: string;
7
21
  extraInfo?: string;
8
22
  status?: number;
9
23
  };
24
+ /**
25
+ * Create API error object with status code and extra information.
26
+ */
10
27
  export declare const createApiError: ({ message, extraInfo, status, }: CreateApiErrorParams) => ApiError;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createApiError = void 0;
4
+ /**
5
+ * Create API error object with status code and extra information.
6
+ */
4
7
  const createApiError = ({ message, extraInfo, status = 500, }) => {
5
8
  const error = new Error(message);
6
9
  error.status = status;
@@ -1,14 +1,37 @@
1
1
  export declare const DEFAULT_DOWNLOAD_FILENAME = "input.xpi";
2
+ /**
3
+ * Error thrown when file download operations fail.
4
+ *
5
+ * @property status - HTTP status code
6
+ * @property extraInfo - Additional error details
7
+ */
2
8
  export declare class DownloadFileError extends Error {
3
9
  status: number;
4
10
  extraInfo?: string;
5
11
  constructor(message: string, extraInfo?: string, status?: number);
12
+ /**
13
+ * Convert this error to ApiError format.
14
+ */
6
15
  toApiError(): import("./api").ApiError;
7
16
  }
17
+ /**
18
+ * Parameters for downloading a file upload.
19
+ *
20
+ * @property downloadURL - URL to download from
21
+ * @property allowedOrigin - Allowed origin for the download URL
22
+ * @property tmpDir - Temporary directory for download (default: os.tmpdir())
23
+ * @property filename - Downloaded file name (default: 'input.xpi')
24
+ */
8
25
  export type DownloadFileUploadParams = {
9
26
  downloadURL: string;
10
27
  allowedOrigin: string;
11
28
  tmpDir?: string;
12
29
  filename?: string;
13
30
  };
31
+ /**
32
+ * Download a file from a URL to a temporary location.
33
+ *
34
+ * @returns Promise resolving to the file path of the downloaded file
35
+ * @throws DownloadFileError if the download fails or URL origin doesn't match
36
+ */
14
37
  export declare const downloadFileUpload: ({ downloadURL, allowedOrigin, tmpDir, filename, }: DownloadFileUploadParams) => Promise<string>;
@@ -20,6 +20,12 @@ const node_stream_1 = require("node:stream");
20
20
  const promises_1 = require("node:stream/promises");
21
21
  const api_1 = require("./api");
22
22
  exports.DEFAULT_DOWNLOAD_FILENAME = 'input.xpi';
23
+ /**
24
+ * Error thrown when file download operations fail.
25
+ *
26
+ * @property status - HTTP status code
27
+ * @property extraInfo - Additional error details
28
+ */
23
29
  class DownloadFileError extends Error {
24
30
  constructor(message, extraInfo, status = 500) {
25
31
  super(message);
@@ -27,6 +33,9 @@ class DownloadFileError extends Error {
27
33
  this.status = status;
28
34
  this.extraInfo = extraInfo;
29
35
  }
36
+ /**
37
+ * Convert this error to ApiError format.
38
+ */
30
39
  toApiError() {
31
40
  return (0, api_1.createApiError)({
32
41
  message: this.message,
@@ -36,6 +45,12 @@ class DownloadFileError extends Error {
36
45
  }
37
46
  }
38
47
  exports.DownloadFileError = DownloadFileError;
48
+ /**
49
+ * Download a file from a URL to a temporary location.
50
+ *
51
+ * @returns Promise resolving to the file path of the downloaded file
52
+ * @throws DownloadFileError if the download fails or URL origin doesn't match
53
+ */
39
54
  const downloadFileUpload = (_a) => __awaiter(void 0, [_a], void 0, function* ({ downloadURL, allowedOrigin, tmpDir = node_os_1.default.tmpdir(), filename = exports.DEFAULT_DOWNLOAD_FILENAME, }) {
40
55
  if (!downloadURL.startsWith(`${allowedOrigin}/`)) {
41
56
  throw new DownloadFileError(`download URL does not match allowed origin: ${allowedOrigin}`, undefined, 400);
@@ -1,12 +1,50 @@
1
1
  import { Request, RequestHandler } from 'express';
2
+ /**
3
+ * Extended Express request type with additional properties added by the
4
+ * middleware.
5
+ *
6
+ * @property rawBody - Raw request body buffer used for HMAC signature
7
+ * verification
8
+ */
2
9
  export type RequestWithExtraProps = Request & {
3
10
  rawBody?: Buffer;
4
11
  };
12
+ /**
13
+ * Configuration options for creating an Express application.
14
+ *
15
+ * @property _console - Console object for logging (for testing purposes)
16
+ * @property _process - Process object for environment variables (for testing
17
+ * purposes)
18
+ * @property apiKeyEnvVarName - Environment variable name for the API key
19
+ */
5
20
  export type FunctionConfig = {
6
21
  _console?: typeof console;
7
22
  _process?: typeof process;
8
23
  apiKeyEnvVarName?: string;
9
24
  };
25
+ /**
26
+ * Easily create a new scanner application with built-in authentication
27
+ * middleware. The middleware validates that the content-type is
28
+ * `application/json`, authenticates the request, and ensures the method is
29
+ * POST. Appropriate HTTP error codes are returned for various failure
30
+ * scenarios:
31
+ * - 400 (bad request)
32
+ * - 401 (unauthorized)
33
+ * - 404 (not found)
34
+ * - 405 (method not allowed)
35
+ * - 415 (unsupported media type)
36
+ * - 500 (internal server error)
37
+ *
38
+ * @remarks
39
+ * **Environment Variables:**
40
+ * - `LAMBDA_API_KEY` - Required. API key for authentication (configurable
41
+ * via `apiKeyEnvVarName`)
42
+ *
43
+ * **Authentication:**
44
+ * - Bearer token: `Authorization: Bearer <api_key>` (deprecated)
45
+ * - HMAC-SHA256: `Authorization: HMAC-SHA256 <digest>` (digest of request
46
+ * body)
47
+ */
10
48
  export declare const createExpressApp: ({ _console, _process, apiKeyEnvVarName, }?: FunctionConfig) => (handler: RequestHandler) => import("express-serve-static-core").Express;
11
49
  export * from './api';
12
50
  export * from './download';
@@ -32,6 +32,29 @@ const express_1 = __importDefault(require("express"));
32
32
  const body_parser_1 = __importDefault(require("body-parser"));
33
33
  const safe_compare_1 = __importDefault(require("safe-compare"));
34
34
  const api_1 = require("./api");
35
+ /**
36
+ * Easily create a new scanner application with built-in authentication
37
+ * middleware. The middleware validates that the content-type is
38
+ * `application/json`, authenticates the request, and ensures the method is
39
+ * POST. Appropriate HTTP error codes are returned for various failure
40
+ * scenarios:
41
+ * - 400 (bad request)
42
+ * - 401 (unauthorized)
43
+ * - 404 (not found)
44
+ * - 405 (method not allowed)
45
+ * - 415 (unsupported media type)
46
+ * - 500 (internal server error)
47
+ *
48
+ * @remarks
49
+ * **Environment Variables:**
50
+ * - `LAMBDA_API_KEY` - Required. API key for authentication (configurable
51
+ * via `apiKeyEnvVarName`)
52
+ *
53
+ * **Authentication:**
54
+ * - Bearer token: `Authorization: Bearer <api_key>` (deprecated)
55
+ * - HMAC-SHA256: `Authorization: HMAC-SHA256 <digest>` (digest of request
56
+ * body)
57
+ */
35
58
  const createExpressApp = ({ _console = console, _process = process, apiKeyEnvVarName = 'LAMBDA_API_KEY', } = {}) => (handler) => {
36
59
  const app = (0, express_1.default)();
37
60
  const apiKey = _process.env[apiKeyEnvVarName] || null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "addons-scanner-utils",
3
- "version": "11.0.0",
3
+ "version": "12.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",
@@ -14,7 +14,7 @@
14
14
  "first-chunk-stream": "3.0.0",
15
15
  "strip-bom-stream": "4.0.0",
16
16
  "upath": "2.0.1",
17
- "yauzl": "2.10.0"
17
+ "yauzl": "3.2.0"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "body-parser": "2.2.2",