web-ext 7.2.0 → 7.3.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 +2 -2
- package/lib/cmd/build.js +18 -36
- package/lib/cmd/build.js.map +1 -1
- package/lib/cmd/docs.js +1 -0
- package/lib/cmd/docs.js.map +1 -1
- package/lib/cmd/index.js +3 -5
- package/lib/cmd/index.js.map +1 -1
- package/lib/cmd/lint.js +28 -17
- package/lib/cmd/lint.js.map +1 -1
- package/lib/cmd/run.js +19 -23
- package/lib/cmd/run.js.map +1 -1
- package/lib/cmd/sign.js +80 -47
- package/lib/cmd/sign.js.map +1 -1
- package/lib/config.js +18 -29
- package/lib/config.js.map +1 -1
- package/lib/errors.js +8 -18
- package/lib/errors.js.map +1 -1
- package/lib/extension-runners/base.js +2 -0
- package/lib/extension-runners/base.js.map +1 -1
- package/lib/extension-runners/chromium.js +36 -62
- package/lib/extension-runners/chromium.js.map +1 -1
- package/lib/extension-runners/firefox-android.js +65 -102
- package/lib/extension-runners/firefox-android.js.map +1 -1
- package/lib/extension-runners/firefox-desktop.js +29 -42
- package/lib/extension-runners/firefox-desktop.js.map +1 -1
- package/lib/extension-runners/index.js +33 -46
- package/lib/extension-runners/index.js.map +1 -1
- package/lib/firefox/index.js +59 -52
- package/lib/firefox/index.js.map +1 -1
- package/lib/firefox/package-identifiers.js +2 -0
- package/lib/firefox/package-identifiers.js.map +1 -1
- package/lib/firefox/preferences.js +14 -15
- package/lib/firefox/preferences.js.map +1 -1
- package/lib/firefox/rdp-client.js +16 -64
- package/lib/firefox/rdp-client.js.map +1 -1
- package/lib/firefox/remote.js +15 -30
- package/lib/firefox/remote.js.map +1 -1
- package/lib/main.js +4 -2
- package/lib/main.js.map +1 -1
- package/lib/program.js +74 -76
- package/lib/program.js.map +1 -1
- package/lib/util/adb.js +33 -63
- package/lib/util/adb.js.map +1 -1
- package/lib/util/artifacts.js +3 -5
- package/lib/util/artifacts.js.map +1 -1
- package/lib/util/desktop-notifier.js +1 -0
- package/lib/util/desktop-notifier.js.map +1 -1
- package/lib/util/file-exists.js +1 -2
- package/lib/util/file-exists.js.map +1 -1
- package/lib/util/file-filter.js +17 -19
- package/lib/util/file-filter.js.map +1 -1
- package/lib/util/is-directory.js +2 -1
- package/lib/util/is-directory.js.map +1 -1
- package/lib/util/logger.js +7 -12
- package/lib/util/logger.js.map +1 -1
- package/lib/util/manifest.js +6 -13
- package/lib/util/manifest.js.map +1 -1
- package/lib/util/promisify.js +7 -3
- package/lib/util/promisify.js.map +1 -1
- package/lib/util/stdin.js +2 -0
- package/lib/util/stdin.js.map +1 -1
- package/lib/util/submit-addon.js +288 -0
- package/lib/util/submit-addon.js.map +1 -0
- package/lib/util/temp-dir.js +8 -18
- package/lib/util/temp-dir.js.map +1 -1
- package/lib/util/updates.js +1 -1
- package/lib/util/updates.js.map +1 -1
- package/lib/watcher.js +14 -9
- package/lib/watcher.js.map +1 -1
- package/package.json +16 -14
package/lib/util/manifest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","names":["path","fs","parseJSON","stripBom","stripJsonComments","InvalidManifest","createLogger","log","import","meta","url","getValidatedManifest","sourceDir","manifestFile","join","debug","manifestContents","readFile","encoding","error","manifestData","errors","name","push","version","applications","gecko","length","getManifestId","manifestApps","browser_specific_settings","apps","id","undefined"],"sources":["../../src/util/manifest.js"],"sourcesContent":["/* @flow */\nimport path from 'path';\n\nimport {fs} from 'mz';\nimport parseJSON from 'parse-json';\nimport stripBom from 'strip-bom';\nimport stripJsonComments from 'strip-json-comments';\n\nimport {InvalidManifest} from '../errors.js';\nimport {createLogger} from './logger.js';\n\nconst log = createLogger(import.meta.url);\n\n\n// getValidatedManifest helper types and implementation\n\nexport type ExtensionManifestApplications = {|\n gecko?: {|\n id?: string,\n strict_min_version?: string,\n strict_max_version?: string,\n update_url?: string,\n |},\n|};\n\nexport type ExtensionManifest = {|\n name: string,\n version: string,\n default_locale?: string,\n applications?: ExtensionManifestApplications,\n browser_specific_settings?: ExtensionManifestApplications,\n permissions?: Array<string>,\n|};\n\nexport default async function getValidatedManifest(\n sourceDir: string\n): Promise<ExtensionManifest> {\n const manifestFile = path.join(sourceDir, 'manifest.json');\n log.debug(`Validating manifest at ${manifestFile}`);\n\n let manifestContents;\n\n try {\n manifestContents = await fs.readFile(manifestFile, {encoding: 'utf-8'});\n } catch (error) {\n throw new InvalidManifest(\n `Could not read manifest.json file at ${manifestFile}: ${error}`);\n }\n\n manifestContents = stripBom(manifestContents);\n\n let manifestData;\n\n try {\n manifestData = parseJSON(stripJsonComments(manifestContents));\n } catch (error) {\n throw new InvalidManifest(\n `Error parsing manifest.json file at ${manifestFile}: ${error}`);\n }\n\n const errors = [];\n // This is just some basic validation of what web-ext needs, not\n // what Firefox will need to run the extension.\n // TODO: integrate with the addons-linter for actual validation.\n if (!manifestData.name) {\n errors.push('missing \"name\" property');\n }\n if (!manifestData.version) {\n errors.push('missing \"version\" property');\n }\n\n if (manifestData.applications && !manifestData.applications.gecko) {\n // Since the applications property only applies to gecko, make\n // sure 'gecko' exists when 'applications' is defined. This should\n // make introspection of gecko properties easier.\n errors.push('missing \"applications.gecko\" property');\n }\n\n if (errors.length) {\n throw new InvalidManifest(\n `Manifest at ${manifestFile} is invalid: ${errors.join('; ')}`);\n }\n\n return manifestData;\n}\n\n\nexport function getManifestId(manifestData: ExtensionManifest): string | void {\n const manifestApps = [\n manifestData.browser_specific_settings,\n manifestData.applications,\n ];\n for (const apps of manifestApps) {\n // If both bss and applicants contains a defined gecko property,\n // we prefer bss even if the id property isn't available.\n // This match what Firefox does in this particular scenario, see\n // https://searchfox.org/mozilla-central/rev/828f2319c0195d7f561ed35533aef6fe183e68e3/toolkit/mozapps/extensions/internal/XPIInstall.jsm#470-474,488\n if (apps?.gecko) {\n return apps.gecko.id;\n }\n }\n\n return undefined;\n}\n"],"mappings":"AACA,OAAOA,
|
|
1
|
+
{"version":3,"file":"manifest.js","names":["path","fs","parseJSON","stripBom","stripJsonComments","InvalidManifest","createLogger","log","import","meta","url","getValidatedManifest","sourceDir","manifestFile","join","debug","manifestContents","readFile","encoding","error","manifestData","errors","name","push","version","applications","gecko","length","getManifestId","manifestApps","browser_specific_settings","apps","id","undefined"],"sources":["../../src/util/manifest.js"],"sourcesContent":["/* @flow */\nimport path from 'path';\n\nimport {fs} from 'mz';\nimport parseJSON from 'parse-json';\nimport stripBom from 'strip-bom';\nimport stripJsonComments from 'strip-json-comments';\n\nimport {InvalidManifest} from '../errors.js';\nimport {createLogger} from './logger.js';\n\nconst log = createLogger(import.meta.url);\n\n\n// getValidatedManifest helper types and implementation\n\nexport type ExtensionManifestApplications = {|\n gecko?: {|\n id?: string,\n strict_min_version?: string,\n strict_max_version?: string,\n update_url?: string,\n |},\n|};\n\nexport type ExtensionManifest = {|\n name: string,\n version: string,\n default_locale?: string,\n applications?: ExtensionManifestApplications,\n browser_specific_settings?: ExtensionManifestApplications,\n permissions?: Array<string>,\n|};\n\nexport default async function getValidatedManifest(\n sourceDir: string\n): Promise<ExtensionManifest> {\n const manifestFile = path.join(sourceDir, 'manifest.json');\n log.debug(`Validating manifest at ${manifestFile}`);\n\n let manifestContents;\n\n try {\n manifestContents = await fs.readFile(manifestFile, {encoding: 'utf-8'});\n } catch (error) {\n throw new InvalidManifest(\n `Could not read manifest.json file at ${manifestFile}: ${error}`);\n }\n\n manifestContents = stripBom(manifestContents);\n\n let manifestData;\n\n try {\n manifestData = parseJSON(stripJsonComments(manifestContents));\n } catch (error) {\n throw new InvalidManifest(\n `Error parsing manifest.json file at ${manifestFile}: ${error}`);\n }\n\n const errors = [];\n // This is just some basic validation of what web-ext needs, not\n // what Firefox will need to run the extension.\n // TODO: integrate with the addons-linter for actual validation.\n if (!manifestData.name) {\n errors.push('missing \"name\" property');\n }\n if (!manifestData.version) {\n errors.push('missing \"version\" property');\n }\n\n if (manifestData.applications && !manifestData.applications.gecko) {\n // Since the applications property only applies to gecko, make\n // sure 'gecko' exists when 'applications' is defined. This should\n // make introspection of gecko properties easier.\n errors.push('missing \"applications.gecko\" property');\n }\n\n if (errors.length) {\n throw new InvalidManifest(\n `Manifest at ${manifestFile} is invalid: ${errors.join('; ')}`);\n }\n\n return manifestData;\n}\n\n\nexport function getManifestId(manifestData: ExtensionManifest): string | void {\n const manifestApps = [\n manifestData.browser_specific_settings,\n manifestData.applications,\n ];\n for (const apps of manifestApps) {\n // If both bss and applicants contains a defined gecko property,\n // we prefer bss even if the id property isn't available.\n // This match what Firefox does in this particular scenario, see\n // https://searchfox.org/mozilla-central/rev/828f2319c0195d7f561ed35533aef6fe183e68e3/toolkit/mozapps/extensions/internal/XPIInstall.jsm#470-474,488\n if (apps?.gecko) {\n return apps.gecko.id;\n }\n }\n\n return undefined;\n}\n"],"mappings":";AACA,OAAOA,IAAI,MAAM,MAAM;AAEvB,SAAQC,EAAE,QAAO,IAAI;AACrB,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,QAAQ,MAAM,WAAW;AAChC,OAAOC,iBAAiB,MAAM,qBAAqB;AAEnD,SAAQC,eAAe,QAAO,cAAc;AAC5C,SAAQC,YAAY,QAAO,aAAa;AAExC,MAAMC,GAAG,GAAGD,YAAY,CAACE,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC;;AAGzC;;AAoBA,eAAe,eAAeC,oBAAoB,CAChDC,SAAiB,EACW;EAC5B,MAAMC,YAAY,GAAGb,IAAI,CAACc,IAAI,CAACF,SAAS,EAAE,eAAe,CAAC;EAC1DL,GAAG,CAACQ,KAAK,CAAE,0BAAyBF,YAAa,EAAC,CAAC;EAEnD,IAAIG,gBAAgB;EAEpB,IAAI;IACFA,gBAAgB,GAAG,MAAMf,EAAE,CAACgB,QAAQ,CAACJ,YAAY,EAAE;MAACK,QAAQ,EAAE;IAAO,CAAC,CAAC;EACzE,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd,MAAM,IAAId,eAAe,CACtB,wCAAuCQ,YAAa,KAAIM,K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|
1
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
|
|
5
|
+
// promisify.custom is missing from the node types know to flow,
|
|
2
6
|
// and it triggers flow-check errors if used directly.
|
|
3
7
|
// By using the value exported here, flow-check passes successfully
|
|
4
8
|
// using a single FLOW_IGNORE suppress comment.
|
|
5
|
-
// $FlowIgnore: promisify.custom is missing in flow type signatures.
|
|
6
9
|
|
|
10
|
+
// $FlowIgnore: promisify.custom is missing in flow type signatures.
|
|
7
11
|
export const promisifyCustom = promisify.custom;
|
|
12
|
+
|
|
8
13
|
/*
|
|
9
14
|
* A small promisify helper to make it easier to customize a
|
|
10
15
|
* function promisified (using the 'util' module available in
|
|
@@ -16,7 +21,6 @@ export const promisifyCustom = promisify.custom;
|
|
|
16
21
|
* aCallbackBasedFn[promisify.custom] = multiArgsPromisedFn(tmp.dir);
|
|
17
22
|
* ...
|
|
18
23
|
*/
|
|
19
|
-
|
|
20
24
|
export function multiArgsPromisedFn(fn) {
|
|
21
25
|
return (...callerArgs) => {
|
|
22
26
|
return new Promise((resolve, reject) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promisify.js","names":["promisify","promisifyCustom","custom","multiArgsPromisedFn","fn","callerArgs","Promise","resolve","reject","err","rest"],"sources":["../../src/util/promisify.js"],"sourcesContent":["/* @flow */\n\nimport {promisify} from 'util';\n\n// promisify.custom is missing from the node types know to flow,\n// and it triggers flow-check errors if used directly.\n// By using the value exported here, flow-check passes successfully\n// using a single FLOW_IGNORE suppress comment.\n\n// $FlowIgnore: promisify.custom is missing in flow type signatures.\nexport const promisifyCustom = promisify.custom;\n\n/*\n * A small promisify helper to make it easier to customize a\n * function promisified (using the 'util' module available in\n * nodejs >= 8) to resolve to an array of results:\n *\n * import {promisify} from 'util';\n * import {multiArgsPromisedFn} from '../util/promisify';\n *\n * aCallbackBasedFn[promisify.custom] = multiArgsPromisedFn(tmp.dir);\n * ...\n */\nexport function multiArgsPromisedFn(fn: Function): Function {\n return (...callerArgs: Array<any>): Promise<any> => {\n return new Promise((resolve, reject) => {\n fn(...callerArgs, (err, ...rest) => {\n if (err) {\n reject(err);\n } else {\n resolve(rest);\n }\n });\n });\n };\n}\n"],"mappings":"AAEA,SAAQA,
|
|
1
|
+
{"version":3,"file":"promisify.js","names":["promisify","promisifyCustom","custom","multiArgsPromisedFn","fn","callerArgs","Promise","resolve","reject","err","rest"],"sources":["../../src/util/promisify.js"],"sourcesContent":["/* @flow */\n\nimport {promisify} from 'util';\n\n// promisify.custom is missing from the node types know to flow,\n// and it triggers flow-check errors if used directly.\n// By using the value exported here, flow-check passes successfully\n// using a single FLOW_IGNORE suppress comment.\n\n// $FlowIgnore: promisify.custom is missing in flow type signatures.\nexport const promisifyCustom = promisify.custom;\n\n/*\n * A small promisify helper to make it easier to customize a\n * function promisified (using the 'util' module available in\n * nodejs >= 8) to resolve to an array of results:\n *\n * import {promisify} from 'util';\n * import {multiArgsPromisedFn} from '../util/promisify';\n *\n * aCallbackBasedFn[promisify.custom] = multiArgsPromisedFn(tmp.dir);\n * ...\n */\nexport function multiArgsPromisedFn(fn: Function): Function {\n return (...callerArgs: Array<any>): Promise<any> => {\n return new Promise((resolve, reject) => {\n fn(...callerArgs, (err, ...rest) => {\n if (err) {\n reject(err);\n } else {\n resolve(rest);\n }\n });\n });\n };\n}\n"],"mappings":";;AAEA,SAAQA,SAAS,QAAO,MAAM;;AAE9B;AACA;AACA;AACA;;AAEA;AACA,OAAO,MAAMC,eAAe,GAAGD,SAAS,CAACE,MAAM;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmB,CAACC,EAAY,EAAY;EAC1D,OAAO,CAAC,GAAGC,UAAsB,KAAmB;IAClD,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtCJ,EAAE,CAAC,GAAGC,UAAU,EAAE,CAACI,GAAG,EAAE,GAAGC,IAAI,KAAK;QAClC,IAAID,GAAG,EAAE;UACPD,MAAM,CAACC,GAAG,CAAC;QACb,CAAC,MAAM;UACLF,OAAO,CAACG,IAAI,CAAC;QACf;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ,CAAC;AACH"}
|
package/lib/util/stdin.js
CHANGED
package/lib/util/stdin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdin.js","names":["isTTY","stream","setRawMode","rawMode"],"sources":["../../src/util/stdin.js"],"sourcesContent":["/* @flow */\n\nimport type {Readable} from 'stream';\n\nexport function isTTY(stream: Readable): boolean {\n // $FlowFixMe: flow complains that stream may not provide isTTY as a property.\n return stream.isTTY;\n}\n\nexport function setRawMode(stream: Readable, rawMode: boolean) {\n // $FlowFixMe: flow complains that stdin may not provide setRawMode.\n stream.setRawMode(rawMode);\n}\n"],"mappings":"AAIA,OAAO,SAASA,
|
|
1
|
+
{"version":3,"file":"stdin.js","names":["isTTY","stream","setRawMode","rawMode"],"sources":["../../src/util/stdin.js"],"sourcesContent":["/* @flow */\n\nimport type {Readable} from 'stream';\n\nexport function isTTY(stream: Readable): boolean {\n // $FlowFixMe: flow complains that stream may not provide isTTY as a property.\n return stream.isTTY;\n}\n\nexport function setRawMode(stream: Readable, rawMode: boolean) {\n // $FlowFixMe: flow complains that stdin may not provide setRawMode.\n stream.setRawMode(rawMode);\n}\n"],"mappings":";;AAIA,OAAO,SAASA,KAAK,CAACC,MAAgB,EAAW;EAC/C;EACA,OAAOA,MAAM,CAACD,KAAK;AACrB;AAEA,OAAO,SAASE,UAAU,CAACD,MAAgB,EAAEE,OAAgB,EAAE;EAC7D;EACAF,MAAM,CAACC,UAAU,CAACC,OAAO,CAAC;AAC5B"}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
|
|
2
|
+
import { createWriteStream, promises as fsPromises } from 'fs';
|
|
3
|
+
import { pipeline } from 'stream';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line no-shadow
|
|
7
|
+
import fetch, { FormData, fileFromSync, Response } from 'node-fetch';
|
|
8
|
+
import { SignJWT } from 'jose';
|
|
9
|
+
import { createLogger } from './../util/logger.js';
|
|
10
|
+
const log = createLogger(import.meta.url);
|
|
11
|
+
export class JwtApiAuth {
|
|
12
|
+
#apiKey;
|
|
13
|
+
#apiSecret;
|
|
14
|
+
#apiJwtExpiresIn;
|
|
15
|
+
constructor({
|
|
16
|
+
apiKey,
|
|
17
|
+
apiSecret,
|
|
18
|
+
apiJwtExpiresIn = 60 * 5 // 5 minutes
|
|
19
|
+
}) {
|
|
20
|
+
this.#apiKey = apiKey;
|
|
21
|
+
this.#apiSecret = apiSecret;
|
|
22
|
+
this.#apiJwtExpiresIn = apiJwtExpiresIn;
|
|
23
|
+
}
|
|
24
|
+
async signJWT() {
|
|
25
|
+
return new SignJWT({
|
|
26
|
+
iss: this.#apiKey
|
|
27
|
+
}).setProtectedHeader({
|
|
28
|
+
alg: 'HS256'
|
|
29
|
+
}).setIssuedAt()
|
|
30
|
+
// jose expects either:
|
|
31
|
+
// a number, which is treated an absolute timestamp - so must be after now, or
|
|
32
|
+
// a string, which is parsed as a relative time from now.
|
|
33
|
+
.setExpirationTime(`${this.#apiJwtExpiresIn}seconds`).sign(Uint8Array.from(Buffer.from(this.#apiSecret, 'utf8')));
|
|
34
|
+
}
|
|
35
|
+
async getAuthHeader() {
|
|
36
|
+
const authToken = await this.signJWT();
|
|
37
|
+
return `JWT ${authToken}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export default class Client {
|
|
41
|
+
constructor({
|
|
42
|
+
apiAuth,
|
|
43
|
+
baseUrl,
|
|
44
|
+
validationCheckInterval = 1000,
|
|
45
|
+
validationCheckTimeout = 300000,
|
|
46
|
+
// 5 minutes.
|
|
47
|
+
approvalCheckInterval = 1000,
|
|
48
|
+
approvalCheckTimeout = 900000,
|
|
49
|
+
// 15 minutes.
|
|
50
|
+
downloadDir = process.cwd()
|
|
51
|
+
}) {
|
|
52
|
+
this.apiAuth = apiAuth;
|
|
53
|
+
this.apiUrl = new URL('/addons/', baseUrl);
|
|
54
|
+
this.validationCheckInterval = validationCheckInterval;
|
|
55
|
+
this.validationCheckTimeout = validationCheckTimeout;
|
|
56
|
+
this.approvalCheckInterval = approvalCheckInterval;
|
|
57
|
+
this.approvalCheckTimeout = approvalCheckTimeout;
|
|
58
|
+
this.downloadDir = downloadDir;
|
|
59
|
+
}
|
|
60
|
+
fileFromSync(path) {
|
|
61
|
+
return fileFromSync(path);
|
|
62
|
+
}
|
|
63
|
+
nodeFetch(url, {
|
|
64
|
+
method,
|
|
65
|
+
headers,
|
|
66
|
+
body
|
|
67
|
+
}) {
|
|
68
|
+
return fetch(url, {
|
|
69
|
+
method,
|
|
70
|
+
headers,
|
|
71
|
+
body
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async doUploadSubmit(xpiPath, channel) {
|
|
75
|
+
const url = new URL('upload/', this.apiUrl);
|
|
76
|
+
const formData = new FormData();
|
|
77
|
+
formData.set('channel', channel);
|
|
78
|
+
formData.set('upload', this.fileFromSync(xpiPath));
|
|
79
|
+
const {
|
|
80
|
+
uuid
|
|
81
|
+
} = await this.fetchJson(url, 'POST', formData);
|
|
82
|
+
return this.waitForValidation(uuid);
|
|
83
|
+
}
|
|
84
|
+
waitRetry(successFunc, checkUrl, checkInterval, abortInterval, context) {
|
|
85
|
+
let checkTimeout;
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const abortTimeout = setTimeout(() => {
|
|
88
|
+
clearTimeout(checkTimeout);
|
|
89
|
+
reject(new Error(`${context}: timeout.`));
|
|
90
|
+
}, abortInterval);
|
|
91
|
+
const pollStatus = async () => {
|
|
92
|
+
try {
|
|
93
|
+
const responseData = await this.fetchJson(checkUrl, 'GET', undefined, 'Getting details failed.');
|
|
94
|
+
const success = successFunc(responseData);
|
|
95
|
+
if (success) {
|
|
96
|
+
clearTimeout(abortTimeout);
|
|
97
|
+
resolve(success);
|
|
98
|
+
} else {
|
|
99
|
+
// Still in progress, so wait for a while and try again.
|
|
100
|
+
checkTimeout = setTimeout(pollStatus, checkInterval);
|
|
101
|
+
}
|
|
102
|
+
} catch (err) {
|
|
103
|
+
clearTimeout(abortTimeout);
|
|
104
|
+
reject(err);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
pollStatus();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
waitForValidation(uuid) {
|
|
111
|
+
log.info('Waiting for Validation...');
|
|
112
|
+
return this.waitRetry(detailResponseData => {
|
|
113
|
+
if (!detailResponseData.processed) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
log.info('Validation results:', detailResponseData.validation);
|
|
117
|
+
if (detailResponseData.valid) {
|
|
118
|
+
return detailResponseData.uuid;
|
|
119
|
+
}
|
|
120
|
+
log.info('Validation failed.');
|
|
121
|
+
throw new Error('Validation failed, open the following URL for more information: ' + `${detailResponseData.url}`);
|
|
122
|
+
}, new URL(`upload/${uuid}/`, this.apiUrl), this.validationCheckInterval, this.validationCheckTimeout, 'Validation');
|
|
123
|
+
}
|
|
124
|
+
async doNewAddonSubmit(uuid, metaDataJson) {
|
|
125
|
+
const url = new URL('addon/', this.apiUrl);
|
|
126
|
+
const jsonData = {
|
|
127
|
+
...metaDataJson,
|
|
128
|
+
version: {
|
|
129
|
+
upload: uuid,
|
|
130
|
+
...metaDataJson.version
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
return this.fetchJson(url, 'POST', JSON.stringify(jsonData));
|
|
134
|
+
}
|
|
135
|
+
doNewAddonOrVersionSubmit(addonId, uuid, metaDataJson) {
|
|
136
|
+
const url = new URL(`addon/${addonId}/`, this.apiUrl);
|
|
137
|
+
const jsonData = {
|
|
138
|
+
...metaDataJson,
|
|
139
|
+
version: {
|
|
140
|
+
upload: uuid,
|
|
141
|
+
...metaDataJson.version
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
return this.fetch(url, 'PUT', JSON.stringify(jsonData));
|
|
145
|
+
}
|
|
146
|
+
waitForApproval(addonId, versionId) {
|
|
147
|
+
log.info('Waiting for Approval...');
|
|
148
|
+
return this.waitRetry(detailResponseData => {
|
|
149
|
+
const {
|
|
150
|
+
file
|
|
151
|
+
} = detailResponseData;
|
|
152
|
+
if (file && file.status === 'public') {
|
|
153
|
+
return file.url;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}, new URL(`addon/${addonId}/versions/${versionId}/`, this.apiUrl), this.approvalCheckInterval, this.approvalCheckTimeout, 'Approval');
|
|
157
|
+
}
|
|
158
|
+
async fetchJson(url, method = 'GET', body, errorMsg = 'Bad Request') {
|
|
159
|
+
const response = await this.fetch(url, method, body);
|
|
160
|
+
if (response.status < 200 || response.status >= 500) {
|
|
161
|
+
throw new Error(`${errorMsg}: ${response.statusText || response.status}.`);
|
|
162
|
+
}
|
|
163
|
+
const data = await response.json();
|
|
164
|
+
if (!response.ok) {
|
|
165
|
+
log.info('Server Response:', data);
|
|
166
|
+
throw new Error(`${errorMsg}: ${response.statusText || response.status}.`);
|
|
167
|
+
}
|
|
168
|
+
return data;
|
|
169
|
+
}
|
|
170
|
+
async fetch(url, method = 'GET', body) {
|
|
171
|
+
log.info(`Fetching URL: ${url.href}`);
|
|
172
|
+
let headers = {
|
|
173
|
+
Authorization: await this.apiAuth.getAuthHeader(),
|
|
174
|
+
Accept: 'application/json'
|
|
175
|
+
};
|
|
176
|
+
if (typeof body === 'string') {
|
|
177
|
+
headers = {
|
|
178
|
+
...headers,
|
|
179
|
+
'Content-Type': 'application/json'
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return this.nodeFetch(url, {
|
|
183
|
+
method,
|
|
184
|
+
body,
|
|
185
|
+
headers
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async downloadSignedFile(fileUrl, addonId) {
|
|
189
|
+
const filename = fileUrl.pathname.split('/').pop(); // get the name from fileUrl
|
|
190
|
+
const dest = `${this.downloadDir}/${filename}`;
|
|
191
|
+
try {
|
|
192
|
+
const response = await this.fetch(fileUrl);
|
|
193
|
+
if (!response.ok || !response.body) {
|
|
194
|
+
throw new Error(`response status was ${response.status}`);
|
|
195
|
+
}
|
|
196
|
+
await this.saveToFile(response.body, dest);
|
|
197
|
+
} catch (error) {
|
|
198
|
+
log.info(`Download of signed xpi failed: ${error}.`);
|
|
199
|
+
throw new Error(`Downloading ${filename} failed`);
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
id: addonId,
|
|
203
|
+
downloadedFiles: [filename]
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async saveToFile(contents, destPath) {
|
|
207
|
+
return promisify(pipeline)(contents, createWriteStream(destPath));
|
|
208
|
+
}
|
|
209
|
+
async postNewAddon(xpiPath, channel, savedIdPath, metaDataJson, saveIdToFileFunc = saveIdToFile) {
|
|
210
|
+
const uploadUuid = await this.doUploadSubmit(xpiPath, channel);
|
|
211
|
+
const versionObject = channel === 'listed' ? 'current_version' : 'latest_unlisted_version';
|
|
212
|
+
const {
|
|
213
|
+
guid: addonId,
|
|
214
|
+
[versionObject]: {
|
|
215
|
+
id: newVersionId
|
|
216
|
+
}
|
|
217
|
+
} = await this.doNewAddonSubmit(uploadUuid, metaDataJson);
|
|
218
|
+
await saveIdToFileFunc(savedIdPath, addonId);
|
|
219
|
+
log.info(`Generated extension ID: ${addonId}.`);
|
|
220
|
+
log.info('You must add the following to your manifest:');
|
|
221
|
+
log.info(`"browser_specific_settings": {"gecko": "${addonId}"}`);
|
|
222
|
+
const fileUrl = new URL(await this.waitForApproval(addonId, newVersionId));
|
|
223
|
+
return this.downloadSignedFile(fileUrl, addonId);
|
|
224
|
+
}
|
|
225
|
+
async putVersion(xpiPath, channel, addonId, metaDataJson) {
|
|
226
|
+
const uploadUuid = await this.doUploadSubmit(xpiPath, channel);
|
|
227
|
+
await this.doNewAddonOrVersionSubmit(addonId, uploadUuid, metaDataJson);
|
|
228
|
+
const url = new URL(`addon/${addonId}/versions/?filter=all_with_unlisted`, this.apiUrl);
|
|
229
|
+
const {
|
|
230
|
+
results: [{
|
|
231
|
+
id: newVersionId
|
|
232
|
+
}]
|
|
233
|
+
} = await this.fetchJson(url);
|
|
234
|
+
const fileUrl = new URL(await this.waitForApproval(addonId, newVersionId));
|
|
235
|
+
return this.downloadSignedFile(fileUrl, addonId);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
export async function signAddon({
|
|
239
|
+
apiKey,
|
|
240
|
+
apiSecret,
|
|
241
|
+
amoBaseUrl,
|
|
242
|
+
timeout,
|
|
243
|
+
id,
|
|
244
|
+
xpiPath,
|
|
245
|
+
downloadDir,
|
|
246
|
+
channel,
|
|
247
|
+
savedIdPath,
|
|
248
|
+
metaDataJson = {},
|
|
249
|
+
SubmitClient = Client,
|
|
250
|
+
ApiAuthClass = JwtApiAuth
|
|
251
|
+
}) {
|
|
252
|
+
try {
|
|
253
|
+
const stats = await fsPromises.stat(xpiPath);
|
|
254
|
+
if (!stats.isFile()) {
|
|
255
|
+
throw new Error(`not a file: ${xpiPath}`);
|
|
256
|
+
}
|
|
257
|
+
} catch (statError) {
|
|
258
|
+
throw new Error(`error with ${xpiPath}: ${statError}`);
|
|
259
|
+
}
|
|
260
|
+
let baseUrl;
|
|
261
|
+
try {
|
|
262
|
+
baseUrl = new URL(amoBaseUrl);
|
|
263
|
+
} catch (err) {
|
|
264
|
+
throw new Error(`Invalid AMO API base URL: ${amoBaseUrl}`);
|
|
265
|
+
}
|
|
266
|
+
const client = new SubmitClient({
|
|
267
|
+
apiAuth: new ApiAuthClass({
|
|
268
|
+
apiKey,
|
|
269
|
+
apiSecret
|
|
270
|
+
}),
|
|
271
|
+
baseUrl,
|
|
272
|
+
validationCheckTimeout: timeout,
|
|
273
|
+
approvalCheckTimeout: timeout,
|
|
274
|
+
downloadDir
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// We specifically need to know if `id` has not been passed as a parameter because
|
|
278
|
+
// it's the indication that a new add-on should be created, rather than a new version.
|
|
279
|
+
if (id === undefined) {
|
|
280
|
+
return client.postNewAddon(xpiPath, channel, savedIdPath, metaDataJson);
|
|
281
|
+
}
|
|
282
|
+
return client.putVersion(xpiPath, channel, id, metaDataJson);
|
|
283
|
+
}
|
|
284
|
+
export async function saveIdToFile(filePath, id) {
|
|
285
|
+
await fsPromises.writeFile(filePath, ['# This file was created by https://github.com/mozilla/web-ext', '# Your auto-generated extension ID for addons.mozilla.org is:', id.toString()].join('\n'));
|
|
286
|
+
log.debug(`Saved auto-generated ID ${id} to ${filePath}`);
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=submit-addon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submit-addon.js","names":["createWriteStream","promises","fsPromises","pipeline","promisify","fetch","FormData","fileFromSync","Response","SignJWT","createLogger","log","import","meta","url","JwtApiAuth","apiKey","apiSecret","apiJwtExpiresIn","constructor","signJWT","iss","setProtectedHeader","alg","setIssuedAt","setExpirationTime","sign","Uint8Array","from","Buffer","getAuthHeader","authToken","Client","apiAuth","baseUrl","validationCheckInterval","validationCheckTimeout","approvalCheckInterval","approvalCheckTimeout","downloadDir","process","cwd","apiUrl","URL","path","nodeFetch","method","headers","body","doUploadSubmit","xpiPath","channel","formData","set","uuid","fetchJson","waitForValidation","waitRetry","successFunc","checkUrl","checkInterval","abortInterval","context","checkTimeout","Promise","resolve","reject","abortTimeout","setTimeout","clearTimeout","Error","pollStatus","responseData","undefined","success","err","info","detailResponseData","processed","validation","valid","doNewAddonSubmit","metaDataJson","jsonData","version","upload","JSON","stringify","doNewAddonOrVersionSubmit","addonId","waitForApproval","versionId","file","status","errorMsg","response","statusText","data","json","ok","href","Authorization","Accept","downloadSignedFile","fileUrl","filename","pathname","split","pop","dest","saveToFile","error","id","downloadedFiles","contents","destPath","postNewAddon","savedIdPath","saveIdToFileFunc","saveIdToFile","uploadUuid","versionObject","guid","newVersionId","putVersion","results","signAddon","amoBaseUrl","timeout","SubmitClient","ApiAuthClass","stats","stat","isFile","statError","client","filePath","writeFile","toString","join","debug"],"sources":["../../src/util/submit-addon.js"],"sourcesContent":["/* @flow */\nimport { createWriteStream, promises as fsPromises } from 'fs';\nimport { pipeline } from 'stream';\nimport { promisify } from 'util';\n\n// eslint-disable-next-line no-shadow\nimport fetch, { FormData, fileFromSync, Response } from 'node-fetch';\nimport { SignJWT } from 'jose';\n\nimport {createLogger} from './../util/logger.js';\n\nconst log = createLogger(import.meta.url);\n\nexport type SignResult = {|\n id: string,\n downloadedFiles: Array<string>,\n|};\n\nexport interface ApiAuth {\n getAuthHeader(): Promise<string>\n}\n\nexport class JwtApiAuth {\n #apiKey: string;\n #apiSecret: string;\n #apiJwtExpiresIn: number;\n\n constructor({\n apiKey,\n apiSecret,\n apiJwtExpiresIn = 60 * 5, // 5 minutes\n }: {apiKey: string, apiSecret: string, apiJwtExpiresIn?: number}) {\n this.#apiKey = apiKey;\n this.#apiSecret = apiSecret;\n this.#apiJwtExpiresIn = apiJwtExpiresIn;\n }\n\n async signJWT(): Promise<string> {\n return new SignJWT({ iss: this.#apiKey })\n .setProtectedHeader({ alg: 'HS256' })\n .setIssuedAt()\n // jose expects either:\n // a number, which is treated an absolute timestamp - so must be after now, or\n // a string, which is parsed as a relative time from now.\n .setExpirationTime(`${this.#apiJwtExpiresIn}seconds`)\n .sign(Uint8Array.from(Buffer.from(this.#apiSecret, 'utf8')));\n }\n\n async getAuthHeader(): Promise<string> {\n const authToken = await this.signJWT();\n return `JWT ${authToken}`;\n }\n}\n\ntype ClientConstructorParams = {|\n apiAuth: ApiAuth,\n baseUrl: URL,\n validationCheckInterval?: number,\n validationCheckTimeout?: number,\n approvalCheckInterval?: number,\n approvalCheckTimeout?: number,\n downloadDir?: string,\n|};\n\nexport default class Client {\n apiAuth: ApiAuth;\n apiUrl: URL;\n validationCheckInterval: number;\n validationCheckTimeout: number;\n approvalCheckInterval: number;\n approvalCheckTimeout: number;\n downloadDir: string;\n\n constructor({\n apiAuth,\n baseUrl,\n validationCheckInterval = 1000,\n validationCheckTimeout = 300000, // 5 minutes.\n approvalCheckInterval = 1000,\n approvalCheckTimeout = 900000, // 15 minutes.\n downloadDir = process.cwd(),\n }: ClientConstructorParams) {\n this.apiAuth = apiAuth;\n this.apiUrl = new URL('/addons/', baseUrl);\n this.validationCheckInterval = validationCheckInterval;\n this.validationCheckTimeout = validationCheckTimeout;\n this.approvalCheckInterval = approvalCheckInterval;\n this.approvalCheckTimeout = approvalCheckTimeout;\n this.downloadDir = downloadDir;\n }\n\n fileFromSync(path: string): File {\n return fileFromSync(path);\n }\n\n nodeFetch(\n url: URL,\n { method, headers, body }: {\n method: string,\n headers: { [key: string]: string },\n body?: typeof FormData | string\n }\n ): Promise<typeof Response> {\n return fetch(url, { method, headers, body });\n }\n\n async doUploadSubmit(xpiPath: string, channel: string): Promise<string> {\n const url = new URL('upload/', this.apiUrl);\n const formData = new FormData();\n formData.set('channel', channel);\n formData.set('upload', this.fileFromSync(xpiPath));\n const { uuid } = await this.fetchJson(url, 'POST', formData);\n return this.waitForValidation(uuid);\n }\n\n waitRetry(\n successFunc: (detailResponseData: any) => string | null,\n checkUrl: URL,\n checkInterval: number,\n abortInterval: number,\n context: string,\n ): Promise<string> {\n let checkTimeout;\n\n return new Promise((resolve, reject) => {\n const abortTimeout = setTimeout(() => {\n clearTimeout(checkTimeout);\n reject(new Error(`${context}: timeout.`));\n }, abortInterval);\n\n const pollStatus = async () => {\n try {\n const responseData = await this.fetchJson(\n checkUrl, 'GET', undefined, 'Getting details failed.');\n\n const success = successFunc(responseData);\n if (success) {\n clearTimeout(abortTimeout);\n resolve(success);\n } else {\n // Still in progress, so wait for a while and try again.\n checkTimeout = setTimeout(pollStatus, checkInterval);\n }\n } catch (err) {\n clearTimeout(abortTimeout);\n reject(err);\n }\n };\n\n pollStatus();\n });\n }\n\n waitForValidation(uuid: string): Promise<string> {\n log.info('Waiting for Validation...');\n return this.waitRetry(\n (detailResponseData): string | null => {\n if (!detailResponseData.processed) {\n return null;\n }\n\n log.info('Validation results:', detailResponseData.validation);\n if (detailResponseData.valid) {\n return detailResponseData.uuid;\n }\n\n log.info('Validation failed.');\n throw new Error(\n 'Validation failed, open the following URL for more information: ' +\n `${detailResponseData.url}`\n );\n },\n new URL(`upload/${uuid}/`, this.apiUrl),\n this.validationCheckInterval,\n this.validationCheckTimeout,\n 'Validation',\n );\n }\n\n async doNewAddonSubmit(uuid: string, metaDataJson: Object): Promise<any> {\n const url = new URL('addon/', this.apiUrl);\n const jsonData = {\n ...metaDataJson, version: { upload: uuid, ...metaDataJson.version },\n };\n return this.fetchJson(url, 'POST', JSON.stringify(jsonData));\n }\n\n doNewAddonOrVersionSubmit(\n addonId: string,\n uuid: string,\n metaDataJson: Object,\n ): Promise<typeof Response> {\n const url = new URL(`addon/${addonId}/`, this.apiUrl);\n const jsonData = {\n ...metaDataJson, version: { upload: uuid, ...metaDataJson.version },\n };\n return this.fetch(url, 'PUT', JSON.stringify(jsonData));\n }\n\n waitForApproval(addonId: string, versionId: number): Promise<string> {\n log.info('Waiting for Approval...');\n return this.waitRetry(\n (detailResponseData): string | null => {\n const {file} = detailResponseData;\n if (file && file.status === 'public') {\n return file.url;\n }\n\n return null;\n },\n new URL(`addon/${addonId}/versions/${versionId}/`, this.apiUrl),\n this.approvalCheckInterval,\n this.approvalCheckTimeout,\n 'Approval',\n );\n }\n\n async fetchJson(\n url: URL,\n method: string = 'GET',\n body?: typeof FormData | string,\n errorMsg: string = 'Bad Request'\n ): Promise<any> {\n const response = await this.fetch(url, method, body);\n if (response.status < 200 || response.status >= 500) {\n throw new Error(\n `${errorMsg}: ${response.statusText || response.status}.`\n );\n }\n const data = await response.json();\n\n if (!response.ok) {\n log.info('Server Response:', data);\n throw new Error(\n `${errorMsg}: ${response.statusText || response.status}.`);\n }\n return data;\n }\n\n async fetch(\n url: URL,\n method: string = 'GET',\n body?: typeof FormData | string,\n ): Promise<typeof Response> {\n log.info(`Fetching URL: ${url.href}`);\n let headers = {\n Authorization: await this.apiAuth.getAuthHeader(),\n Accept: 'application/json',\n };\n if (typeof body === 'string') {\n headers = {\n ...headers,\n 'Content-Type': 'application/json',\n };\n }\n return this.nodeFetch(url, { method, body, headers });\n }\n\n async downloadSignedFile(\n fileUrl: URL,\n addonId: string\n ): Promise<SignResult> {\n const filename = fileUrl.pathname.split('/').pop(); // get the name from fileUrl\n const dest = `${this.downloadDir}/${filename}`;\n try {\n const response = await this.fetch(fileUrl);\n if (!response.ok || !response.body) {\n throw new Error(`response status was ${response.status}`);\n }\n await this.saveToFile(response.body, dest);\n } catch (error) {\n log.info(`Download of signed xpi failed: ${error}.`);\n throw new Error(`Downloading ${filename} failed`);\n }\n return {\n id: addonId,\n downloadedFiles: [filename],\n };\n }\n\n async saveToFile(\n contents: typeof Response.body, destPath: string): Promise<any> {\n return promisify(pipeline)(contents, createWriteStream(destPath));\n }\n\n async postNewAddon(\n xpiPath: string,\n channel: string,\n savedIdPath: string,\n metaDataJson: Object,\n saveIdToFileFunc: (string, string) => Promise<void> = saveIdToFile,\n ): Promise<SignResult> {\n const uploadUuid = await this.doUploadSubmit(xpiPath, channel);\n\n const versionObject =\n channel === 'listed' ? 'current_version' : 'latest_unlisted_version';\n const {\n guid: addonId,\n [versionObject]: {id: newVersionId},\n } = await this.doNewAddonSubmit(uploadUuid, metaDataJson);\n\n await saveIdToFileFunc(savedIdPath, addonId);\n log.info(`Generated extension ID: ${addonId}.`);\n log.info('You must add the following to your manifest:');\n log.info(`\"browser_specific_settings\": {\"gecko\": \"${addonId}\"}`);\n\n const fileUrl = new URL(await this.waitForApproval(addonId, newVersionId));\n\n return this.downloadSignedFile(fileUrl, addonId);\n }\n\n async putVersion(\n xpiPath: string,\n channel: string,\n addonId: string,\n metaDataJson: Object\n ): Promise<SignResult> {\n const uploadUuid = await this.doUploadSubmit(xpiPath, channel);\n\n await this.doNewAddonOrVersionSubmit(addonId, uploadUuid, metaDataJson);\n\n const url = new URL(\n `addon/${addonId}/versions/?filter=all_with_unlisted`, this.apiUrl\n );\n const {results: [{id: newVersionId}]} = await this.fetchJson(url);\n\n const fileUrl = new URL(await this.waitForApproval(addonId, newVersionId));\n\n return this.downloadSignedFile(fileUrl, addonId);\n }\n}\n\ntype signAddonParams = {|\n apiKey: string,\n apiSecret: string,\n amoBaseUrl: string,\n timeout: number,\n id?: string,\n xpiPath: string,\n downloadDir: string,\n channel: string,\n savedIdPath: string,\n metaDataJson?: Object,\n SubmitClient?: typeof Client,\n ApiAuthClass?: typeof JwtApiAuth,\n|}\n\nexport async function signAddon({\n apiKey,\n apiSecret,\n amoBaseUrl,\n timeout,\n id,\n xpiPath,\n downloadDir,\n channel,\n savedIdPath,\n metaDataJson = {},\n SubmitClient = Client,\n ApiAuthClass = JwtApiAuth,\n}: signAddonParams): Promise<SignResult> {\n try {\n const stats = await fsPromises.stat(xpiPath);\n\n if (!stats.isFile()) {\n throw new Error(`not a file: ${xpiPath}`);\n }\n } catch (statError) {\n throw new Error(`error with ${xpiPath}: ${statError}`);\n }\n\n let baseUrl;\n try {\n baseUrl = new URL(amoBaseUrl);\n } catch (err) {\n throw new Error(`Invalid AMO API base URL: ${amoBaseUrl}`);\n }\n\n const client = new SubmitClient({\n apiAuth: new ApiAuthClass({ apiKey, apiSecret }),\n baseUrl,\n validationCheckTimeout: timeout,\n approvalCheckTimeout: timeout,\n downloadDir,\n });\n\n // We specifically need to know if `id` has not been passed as a parameter because\n // it's the indication that a new add-on should be created, rather than a new version.\n if (id === undefined) {\n return client.postNewAddon(xpiPath, channel, savedIdPath, metaDataJson);\n }\n\n return client.putVersion(xpiPath, channel, id, metaDataJson);\n}\n\nexport async function saveIdToFile(\n filePath: string, id: string\n): Promise<void> {\n await fsPromises.writeFile(filePath, [\n '# This file was created by https://github.com/mozilla/web-ext',\n '# Your auto-generated extension ID for addons.mozilla.org is:',\n id.toString(),\n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/B,CAAC,CAAC,OAAOpD,GAAG,EAAE;IACZ,MAAM,IAAIL,KAAK,CAAE,6BAA4ByD,UAAW,EAAC,CAAC;EAC5D;EAEA,MAAMQ,MAAM,GAAG,IAAIN,YAAY,CAAC;IAC9BhG,OAAO,EAAE,IAAIiG,YAAY,CAAC;MAAElH,MAAM;MAAEC;IAAU,CAAC,CAAC;IAChDiB,OAAO;IACPE,sBAAsB,EAAE4F,OAAO;IAC/B1F,oBAAoB,EAAE0F,OAAO;IAC7BzF;EACF,CAAC,CAAC;;EAEF;EACA;EACA,IAAIyE,EAAE,KAAKvC,SAAS,EAAE;IACpB,OAAO8D,MAAM,CAACnB,YAAY,CAAClE,OAAO,EAAEC,OAAO,EAAEkE,WAAW,EAAEnC,YAAY,CAAC;EACzE;EAEA,OAAOqD,MAAM,CAACX,UAAU,CAAC1E,OAAO,EAAEC,OAAO,EAAE6D,EAAE,EAAE9B,YAAY,CAAC;AAC9D;AAEA,OAAO,eAAeqC,YAAY,CAChCiB,QAAgB,EAAExB,EAAU,EACb;EACf,MAAM9G,UAAU,CAACuI,SAAS,CAACD,QAAQ,EAAE,CACnC,+DAA+D,EAC/D,+DAA+D,EAC/DxB,EAAE,CAAC0B,QAAQ,EAAE,CACd,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;EAEbhI,GAAG,CAACiI,KAAK,CAAE,2BAA0B5B,EAAG,OAAMwB,QAAS,EAAC,CAAC;AAC3D"}
|
package/lib/util/temp-dir.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import { promisify } from 'util';
|
|
2
3
|
import tmp from 'tmp';
|
|
3
4
|
import { createLogger } from './logger.js';
|
|
@@ -5,6 +6,7 @@ import { multiArgsPromisedFn, promisifyCustom } from './promisify.js';
|
|
|
5
6
|
const log = createLogger(import.meta.url);
|
|
6
7
|
tmp.dir[promisifyCustom] = multiArgsPromisedFn(tmp.dir);
|
|
7
8
|
const createTempDir = promisify(tmp.dir);
|
|
9
|
+
|
|
8
10
|
/*
|
|
9
11
|
* Work with a self-destructing temporary directory in a promise chain.
|
|
10
12
|
*
|
|
@@ -20,13 +22,13 @@ const createTempDir = promisify(tmp.dir);
|
|
|
20
22
|
* );
|
|
21
23
|
*
|
|
22
24
|
*/
|
|
23
|
-
|
|
24
25
|
export function withTempDir(makePromise) {
|
|
25
26
|
const tmpDir = new TempDir();
|
|
26
27
|
return tmpDir.create().then(() => {
|
|
27
28
|
return makePromise(tmpDir);
|
|
28
29
|
}).catch(tmpDir.errorHandler()).then(tmpDir.successHandler());
|
|
29
30
|
}
|
|
31
|
+
|
|
30
32
|
/*
|
|
31
33
|
* Work with a self-destructing temporary directory object.
|
|
32
34
|
*
|
|
@@ -42,18 +44,16 @@ export function withTempDir(makePromise) {
|
|
|
42
44
|
* .then(tmpDir.successHandler());
|
|
43
45
|
*
|
|
44
46
|
*/
|
|
45
|
-
|
|
46
47
|
export class TempDir {
|
|
47
48
|
constructor() {
|
|
48
49
|
this._path = undefined;
|
|
49
50
|
this._removeTempDir = undefined;
|
|
50
51
|
}
|
|
52
|
+
|
|
51
53
|
/*
|
|
52
54
|
* Returns a promise that is fulfilled when the temp directory has
|
|
53
55
|
* been created.
|
|
54
56
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
57
|
create() {
|
|
58
58
|
return createTempDir({
|
|
59
59
|
prefix: 'tmp-web-ext-',
|
|
@@ -61,31 +61,27 @@ export class TempDir {
|
|
|
61
61
|
unsafeCleanup: true
|
|
62
62
|
}).then(([tmpPath, removeTempDir]) => {
|
|
63
63
|
this._path = tmpPath;
|
|
64
|
-
|
|
65
64
|
this._removeTempDir = () => new Promise((resolve, reject) => {
|
|
66
65
|
// `removeTempDir` parameter is a `next` callback which
|
|
67
66
|
// is called once the dir has been removed.
|
|
68
67
|
const next = err => err ? reject(err) : resolve();
|
|
69
|
-
|
|
70
68
|
removeTempDir(next);
|
|
71
69
|
});
|
|
72
|
-
|
|
73
70
|
log.debug(`Created temporary directory: ${this.path()}`);
|
|
74
71
|
return this;
|
|
75
72
|
});
|
|
76
73
|
}
|
|
74
|
+
|
|
77
75
|
/*
|
|
78
76
|
* Get the absolute path of the temp directory.
|
|
79
77
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
78
|
path() {
|
|
83
79
|
if (!this._path) {
|
|
84
80
|
throw new Error('You cannot access path() before calling create()');
|
|
85
81
|
}
|
|
86
|
-
|
|
87
82
|
return this._path;
|
|
88
83
|
}
|
|
84
|
+
|
|
89
85
|
/*
|
|
90
86
|
* Returns a callback that will catch an error, remove
|
|
91
87
|
* the temporary directory, and throw the error.
|
|
@@ -93,41 +89,35 @@ export class TempDir {
|
|
|
93
89
|
* This is intended for use in a promise like
|
|
94
90
|
* Promise().catch(tmp.errorHandler())
|
|
95
91
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
92
|
errorHandler() {
|
|
99
93
|
return async error => {
|
|
100
94
|
await this.remove();
|
|
101
95
|
throw error;
|
|
102
96
|
};
|
|
103
97
|
}
|
|
98
|
+
|
|
104
99
|
/*
|
|
105
100
|
* Returns a callback that will remove the temporary direcotry.
|
|
106
101
|
*
|
|
107
102
|
* This is intended for use in a promise like
|
|
108
103
|
* Promise().then(tmp.successHandler())
|
|
109
104
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
105
|
successHandler() {
|
|
113
106
|
return async promiseResult => {
|
|
114
107
|
await this.remove();
|
|
115
108
|
return promiseResult;
|
|
116
109
|
};
|
|
117
110
|
}
|
|
111
|
+
|
|
118
112
|
/*
|
|
119
113
|
* Remove the temp directory.
|
|
120
114
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
115
|
remove() {
|
|
124
116
|
if (!this._removeTempDir) {
|
|
125
117
|
return;
|
|
126
118
|
}
|
|
127
|
-
|
|
128
119
|
log.debug(`Removing temporary directory: ${this.path()}`);
|
|
129
120
|
return this._removeTempDir && this._removeTempDir();
|
|
130
121
|
}
|
|
131
|
-
|
|
132
122
|
}
|
|
133
123
|
//# sourceMappingURL=temp-dir.js.map
|
package/lib/util/temp-dir.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temp-dir.js","names":["promisify","tmp","createLogger","multiArgsPromisedFn","promisifyCustom","log","import","meta","url","dir","createTempDir","withTempDir","makePromise","tmpDir","TempDir","create","then","catch","errorHandler","successHandler","constructor","_path","undefined","_removeTempDir","prefix","unsafeCleanup","tmpPath","removeTempDir","Promise","resolve","reject","next","err","debug","path","Error","error","remove","promiseResult"],"sources":["../../src/util/temp-dir.js"],"sourcesContent":["/* @flow */\nimport {promisify} from 'util';\n\nimport tmp from 'tmp';\n\nimport {createLogger} from './logger.js';\nimport {multiArgsPromisedFn, promisifyCustom} from './promisify.js';\n\nconst log = createLogger(import.meta.url);\n\nexport type MakePromiseCallback = (tmpDir: TempDir) => any;\n\ntmp.dir[promisifyCustom] = multiArgsPromisedFn(tmp.dir);\n\nconst createTempDir = promisify(tmp.dir);\n\n/*\n * Work with a self-destructing temporary directory in a promise chain.\n *\n * The directory will be destroyed when the promise chain is finished\n * (whether there was an error or not).\n *\n * Usage:\n *\n * withTempDir(\n * (tmpDir) =>\n * doSomething(tmpDir.path())\n * .then(...)\n * );\n *\n */\nexport function withTempDir(makePromise: MakePromiseCallback): Promise<any> {\n const tmpDir = new TempDir();\n return tmpDir.create()\n .then(() => {\n return makePromise(tmpDir);\n })\n .catch(tmpDir.errorHandler())\n .then(tmpDir.successHandler());\n}\n\n/*\n * Work with a self-destructing temporary directory object.\n *\n * It is safer to use withTempDir() instead but if you know\n * what you're doing you can use it directly like:\n *\n * let tmpDir = new TempDir();\n * tmpDir.create()\n * .then(() => {\n * // work with tmpDir.path()\n * })\n * .catch(tmpDir.errorHandler())\n * .then(tmpDir.successHandler());\n *\n */\nexport class TempDir {\n _path: string | void;\n _removeTempDir: Function | void;\n\n constructor() {\n this._path = undefined;\n this._removeTempDir = undefined;\n }\n\n /*\n * Returns a promise that is fulfilled when the temp directory has\n * been created.\n */\n create(): Promise<TempDir> {\n return createTempDir(\n {\n prefix: 'tmp-web-ext-',\n // This allows us to remove a non-empty tmp dir.\n unsafeCleanup: true,\n })\n .then(([tmpPath, removeTempDir]) => {\n this._path = tmpPath;\n this._removeTempDir = () => new Promise((resolve, reject) => {\n // `removeTempDir` parameter is a `next` callback which\n // is called once the dir has been removed.\n const next = (err) => err ? reject(err) : resolve();\n removeTempDir(next);\n });\n log.debug(`Created temporary directory: ${this.path()}`);\n return this;\n });\n }\n\n /*\n * Get the absolute path of the temp directory.\n */\n path(): string {\n if (!this._path) {\n throw new Error('You cannot access path() before calling create()');\n }\n return this._path;\n }\n\n /*\n * Returns a callback that will catch an error, remove\n * the temporary directory, and throw the error.\n *\n * This is intended for use in a promise like\n * Promise().catch(tmp.errorHandler())\n */\n errorHandler(): Function {\n return async (error) => {\n await this.remove();\n throw error;\n };\n }\n\n /*\n * Returns a callback that will remove the temporary direcotry.\n *\n * This is intended for use in a promise like\n * Promise().then(tmp.successHandler())\n */\n successHandler(): Function {\n return async (promiseResult) => {\n await this.remove();\n return promiseResult;\n };\n }\n\n /*\n * Remove the temp directory.\n */\n remove(): Promise<void> | void {\n if (!this._removeTempDir) {\n return;\n }\n log.debug(`Removing temporary directory: ${this.path()}`);\n return this._removeTempDir && this._removeTempDir();\n }\n\n}\n"],"mappings":"AACA,SAAQA,
|
|
1
|
+
{"version":3,"file":"temp-dir.js","names":["promisify","tmp","createLogger","multiArgsPromisedFn","promisifyCustom","log","import","meta","url","dir","createTempDir","withTempDir","makePromise","tmpDir","TempDir","create","then","catch","errorHandler","successHandler","constructor","_path","undefined","_removeTempDir","prefix","unsafeCleanup","tmpPath","removeTempDir","Promise","resolve","reject","next","err","debug","path","Error","error","remove","promiseResult"],"sources":["../../src/util/temp-dir.js"],"sourcesContent":["/* @flow */\nimport {promisify} from 'util';\n\nimport tmp from 'tmp';\n\nimport {createLogger} from './logger.js';\nimport {multiArgsPromisedFn, promisifyCustom} from './promisify.js';\n\nconst log = createLogger(import.meta.url);\n\nexport type MakePromiseCallback = (tmpDir: TempDir) => any;\n\ntmp.dir[promisifyCustom] = multiArgsPromisedFn(tmp.dir);\n\nconst createTempDir = promisify(tmp.dir);\n\n/*\n * Work with a self-destructing temporary directory in a promise chain.\n *\n * The directory will be destroyed when the promise chain is finished\n * (whether there was an error or not).\n *\n * Usage:\n *\n * withTempDir(\n * (tmpDir) =>\n * doSomething(tmpDir.path())\n * .then(...)\n * );\n *\n */\nexport function withTempDir(makePromise: MakePromiseCallback): Promise<any> {\n const tmpDir = new TempDir();\n return tmpDir.create()\n .then(() => {\n return makePromise(tmpDir);\n })\n .catch(tmpDir.errorHandler())\n .then(tmpDir.successHandler());\n}\n\n/*\n * Work with a self-destructing temporary directory object.\n *\n * It is safer to use withTempDir() instead but if you know\n * what you're doing you can use it directly like:\n *\n * let tmpDir = new TempDir();\n * tmpDir.create()\n * .then(() => {\n * // work with tmpDir.path()\n * })\n * .catch(tmpDir.errorHandler())\n * .then(tmpDir.successHandler());\n *\n */\nexport class TempDir {\n _path: string | void;\n _removeTempDir: Function | void;\n\n constructor() {\n this._path = undefined;\n this._removeTempDir = undefined;\n }\n\n /*\n * Returns a promise that is fulfilled when the temp directory has\n * been created.\n */\n create(): Promise<TempDir> {\n return createTempDir(\n {\n prefix: 'tmp-web-ext-',\n // This allows us to remove a non-empty tmp dir.\n unsafeCleanup: true,\n })\n .then(([tmpPath, removeTempDir]) => {\n this._path = tmpPath;\n this._removeTempDir = () => new Promise((resolve, reject) => {\n // `removeTempDir` parameter is a `next` callback which\n // is called once the dir has been removed.\n const next = (err) => err ? reject(err) : resolve();\n removeTempDir(next);\n });\n log.debug(`Created temporary directory: ${this.path()}`);\n return this;\n });\n }\n\n /*\n * Get the absolute path of the temp directory.\n */\n path(): string {\n if (!this._path) {\n throw new Error('You cannot access path() before calling create()');\n }\n return this._path;\n }\n\n /*\n * Returns a callback that will catch an error, remove\n * the temporary directory, and throw the error.\n *\n * This is intended for use in a promise like\n * Promise().catch(tmp.errorHandler())\n */\n errorHandler(): Function {\n return async (error) => {\n await this.remove();\n throw error;\n };\n }\n\n /*\n * Returns a callback that will remove the temporary direcotry.\n *\n * This is intended for use in a promise like\n * Promise().then(tmp.successHandler())\n */\n successHandler(): Function {\n return async (promiseResult) => {\n await this.remove();\n return promiseResult;\n };\n }\n\n /*\n * Remove the temp directory.\n */\n remove(): Promise<void> | void {\n if (!this._removeTempDir) {\n return;\n }\n log.debug(`Removing temporary directory: ${this.path()}`);\n return this._removeTempDir && this._removeTempDir();\n }\n\n}\n"],"mappings":";AACA,SAAQA,SAAS,QAAO,MAAM;AAE9B,OAAOC,GAAG,MAAM,KAAK;AAErB,SAAQC,YAAY,QAAO,aAAa;AACxC,SAAQC,mBAAmB,EAAEC,eAAe,QAAO,gBAAgB;AAEnE,MAAMC,GAAG,GAAGH,YAAY,CAACI,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC;AAIzCP,GAAG,CAACQ,GAAG,CAACL,eAAe,CAAC,GAAGD,mBAAmB,CAACF,GAAG,CAACQ,GAAG,CAAC;AAEvD,MAAMC,aAAa,GAAGV,SAAS,CAACC,GAAG,CAACQ,GAAG,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,WAAW,CAACC,WAAgC,EAAgB;EAC1E,MAAMC,MAAM,GAAG,IAAIC,OAAO,EAAE;EAC5B,OAAOD,MAAM,CAACE,MAAM,EAAE,CACnBC,IAAI,CAAC,MAAM;IACV,OAAOJ,WAAW,CAACC,MAAM,CAAC;EAC5B,CAAC,CAAC,CACDI,KAAK,CAACJ,MAAM,CAACK,YAAY,EAAE,CAAC,CAC5BF,IAAI,CAACH,MAAM,CAACM,cAAc,EAAE,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAML,OAAO,CAAC;EA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AAc,EAAE;MACxB;IACF;IACAlB,GAAG,CAAC4B,KAAK,CAAE,iCAAgC,IAAI,CAACC,IAAI,EAAG,EAAC,CAAC;IACzD,OAAO,IAAI,CAACX,cAAc,IAAI,IAAI,CAACA,cAAc,EAAE;EACrD;AAEF"}
|
package/lib/util/updates.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import defaultUpdateNotifier from 'update-notifier';
|
|
2
3
|
export function checkForUpdates({
|
|
3
4
|
version,
|
|
@@ -10,7 +11,6 @@ export function checkForUpdates({
|
|
|
10
11
|
updateNotifier({
|
|
11
12
|
pkg,
|
|
12
13
|
updateCheckInterval: 1000 * 60 * 60 * 24 * 3 // 3 days,
|
|
13
|
-
|
|
14
14
|
}).notify();
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=updates.js.map
|
package/lib/util/updates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updates.js","names":["defaultUpdateNotifier","checkForUpdates","version","updateNotifier","pkg","name","updateCheckInterval","notify"],"sources":["../../src/util/updates.js"],"sourcesContent":["/* @flow */\nimport defaultUpdateNotifier from 'update-notifier';\n\ntype CheckForUpdatesParams = {|\n version: string,\n updateNotifier?: typeof defaultUpdateNotifier,\n|};\n\nexport function checkForUpdates(\n {\n version,\n updateNotifier = defaultUpdateNotifier,\n }: CheckForUpdatesParams\n) {\n const pkg = {name: 'web-ext', version};\n\n updateNotifier({\n pkg,\n updateCheckInterval: 1000 * 60 * 60 * 24 * 3, // 3 days,\n }).notify();\n}\n"],"mappings":"AACA,OAAOA,
|
|
1
|
+
{"version":3,"file":"updates.js","names":["defaultUpdateNotifier","checkForUpdates","version","updateNotifier","pkg","name","updateCheckInterval","notify"],"sources":["../../src/util/updates.js"],"sourcesContent":["/* @flow */\nimport defaultUpdateNotifier from 'update-notifier';\n\ntype CheckForUpdatesParams = {|\n version: string,\n updateNotifier?: typeof defaultUpdateNotifier,\n|};\n\nexport function checkForUpdates(\n {\n version,\n updateNotifier = defaultUpdateNotifier,\n }: CheckForUpdatesParams\n) {\n const pkg = {name: 'web-ext', version};\n\n updateNotifier({\n pkg,\n updateCheckInterval: 1000 * 60 * 60 * 24 * 3, // 3 days,\n }).notify();\n}\n"],"mappings":";AACA,OAAOA,qBAAqB,MAAM,iBAAiB;AAOnD,OAAO,SAASC,eAAe,CAC7B;EACEC,OAAO;EACPC,cAAc,GAAGH;AACI,CAAC,EACxB;EACA,MAAMI,GAAG,GAAG;IAACC,IAAI,EAAE,SAAS;IAAEH;EAAO,CAAC;EAEtCC,cAAc,CAAC;IACbC,GAAG;IACHE,mBAAmB,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAE;EAChD,CAAC,CAAC,CAACC,MAAM,EAAE;AACb"}
|