firebase-tools 10.1.1 → 10.1.2

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.
Files changed (60) hide show
  1. package/lib/accountExporter.js +9 -8
  2. package/lib/accountImporter.js +10 -8
  3. package/lib/bin/firebase.js +1 -1
  4. package/lib/commands/auth-export.js +26 -25
  5. package/lib/commands/auth-import.js +88 -78
  6. package/lib/commands/ext-configure.js +1 -1
  7. package/lib/commands/ext-dev-init.js +1 -1
  8. package/lib/commands/ext-dev-publish.js +1 -1
  9. package/lib/commands/ext-dev-register.js +1 -1
  10. package/lib/commands/ext-info.js +1 -1
  11. package/lib/commands/ext-install.js +1 -1
  12. package/lib/commands/ext-uninstall.js +1 -1
  13. package/lib/commands/ext-update.js +1 -1
  14. package/lib/commands/functions-config-clone.js +22 -23
  15. package/lib/commands/functions-config-get.js +22 -22
  16. package/lib/commands/functions-config-set.js +24 -22
  17. package/lib/commands/functions-config-unset.js +20 -22
  18. package/lib/commands/help.js +12 -12
  19. package/lib/commands/hosting-channel-create.js +1 -1
  20. package/lib/commands/hosting-channel-delete.js +2 -2
  21. package/lib/commands/hosting-channel-deploy.js +1 -1
  22. package/lib/commands/hosting-clone.js +1 -1
  23. package/lib/commands/login-ci.js +10 -10
  24. package/lib/commands/remoteconfig-versions-list.js +6 -1
  25. package/lib/commands/setup-emulators-database.js +8 -7
  26. package/lib/commands/setup-emulators-firestore.js +8 -7
  27. package/lib/commands/setup-emulators-pubsub.js +5 -4
  28. package/lib/commands/setup-emulators-storage.js +3 -2
  29. package/lib/commands/setup-emulators-ui.js +8 -7
  30. package/lib/commands/target-apply.js +17 -16
  31. package/lib/commands/target-clear.js +11 -10
  32. package/lib/commands/target-remove.js +10 -9
  33. package/lib/commands/target.js +20 -20
  34. package/lib/defaultCredentials.js +3 -3
  35. package/lib/deploy/functions/runtimes/golang/index.js +2 -1
  36. package/lib/emulator/downloadableEmulators.js +3 -2
  37. package/lib/emulator/functionsEmulator.js +6 -0
  38. package/lib/emulator/functionsEmulatorRuntime.js +4 -4
  39. package/lib/emulator/storage/rules/runtime.js +5 -4
  40. package/lib/extensions/askUserForConsent.js +1 -1
  41. package/lib/extensions/askUserForParam.js +1 -1
  42. package/lib/extensions/billingMigrationHelper.js +1 -1
  43. package/lib/extensions/changelog.js +1 -1
  44. package/lib/extensions/displayExtensionInfo.js +1 -1
  45. package/lib/extensions/extensionsApi.js +58 -112
  46. package/lib/extensions/extensionsHelper.js +19 -15
  47. package/lib/extensions/provisioningHelper.js +7 -10
  48. package/lib/extensions/resolveSource.js +5 -5
  49. package/lib/extensions/updateHelper.js +1 -1
  50. package/lib/extensions/warnings.js +1 -1
  51. package/lib/functionsConfig.js +4 -5
  52. package/lib/gcp/rules.js +18 -41
  53. package/lib/projectUtils.js +1 -1
  54. package/lib/remoteconfig/get.js +14 -8
  55. package/lib/remoteconfig/rollback.js +13 -6
  56. package/lib/remoteconfig/versionslist.js +13 -7
  57. package/npm-shrinkwrap.json +1225 -2019
  58. package/package.json +12 -9
  59. package/lib/commands/functions-config-legacy.js +0 -45
  60. package/lib/prepareFirebaseRules.js +0 -58
@@ -2,9 +2,13 @@
2
2
  var os = require("os");
3
3
  var path = require("path");
4
4
  var _ = require("lodash");
5
- var api = require("./api");
6
- var utils = require("./utils");
5
+ const { Client } = require("./apiv2");
6
+ const { googleOrigin } = require("./api");
7
7
  var { FirebaseError } = require("./error");
8
+ var utils = require("./utils");
9
+ const apiClient = new Client({
10
+ urlPrefix: googleOrigin,
11
+ });
8
12
  var EXPORTED_JSON_KEYS = [
9
13
  "localId",
10
14
  "email",
@@ -149,12 +153,9 @@ var serialExportUsers = function (projectId, options) {
149
153
  if (!options.timeoutRetryCount) {
150
154
  options.timeoutRetryCount = 0;
151
155
  }
152
- return api
153
- .request("POST", "/identitytoolkit/v3/relyingparty/downloadAccount", {
154
- auth: true,
155
- json: true,
156
- data: postBody,
157
- origin: api.googleOrigin,
156
+ return apiClient
157
+ .post("/identitytoolkit/v3/relyingparty/downloadAccount", postBody, {
158
+ skipLog: { resBody: true },
158
159
  })
159
160
  .then(function (ret) {
160
161
  options.timeoutRetryCount = 0;
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  var clc = require("cli-color");
3
3
  var _ = require("lodash");
4
- var api = require("./api");
4
+ const { Client } = require("./apiv2");
5
+ const { googleOrigin } = require("./api");
5
6
  const { logger } = require("./logger");
6
- var utils = require("./utils");
7
7
  var { FirebaseError } = require("./error");
8
+ var utils = require("./utils");
9
+ const apiClient = new Client({
10
+ urlPrefix: googleOrigin,
11
+ });
8
12
  var ALLOWED_JSON_KEYS = [
9
13
  "localId",
10
14
  "email",
@@ -266,12 +270,10 @@ var validateUserJson = function (userJson) {
266
270
  };
267
271
  var _sendRequest = function (projectId, userList, hashOptions) {
268
272
  logger.info("Starting importing " + userList.length + " account(s).");
269
- return api
270
- .request("POST", "/identitytoolkit/v3/relyingparty/uploadAccount", {
271
- auth: true,
272
- json: true,
273
- data: _genUploadAccountPostBody(projectId, userList, hashOptions),
274
- origin: api.googleOrigin,
273
+ const postData = _genUploadAccountPostBody(projectId, userList, hashOptions);
274
+ return apiClient
275
+ .post("/identitytoolkit/v3/relyingparty/uploadAccount", postData, {
276
+ skipLog: { body: true },
275
277
  })
276
278
  .then(function (ret) {
277
279
  if (ret.body.error) {
@@ -15,7 +15,7 @@ if (!semver.satisfies(nodeVersion, pkg.engines.node)) {
15
15
  const updateNotifier = require("update-notifier")({ pkg: pkg });
16
16
  const clc = require("cli-color");
17
17
  const TerminalRenderer = require("marked-terminal");
18
- const marked = require("marked");
18
+ const marked = require("marked").marked;
19
19
  marked.setOptions({
20
20
  renderer: new TerminalRenderer(),
21
21
  });
@@ -1,39 +1,40 @@
1
1
  "use strict";
2
- var clc = require("cli-color");
3
- var fs = require("fs");
4
- var os = require("os");
5
- var { Command } = require("../command");
6
- var accountExporter = require("../accountExporter");
7
- var needProjectId = require("../projectUtils").needProjectId;
8
- const { logger } = require("../logger");
9
- var { requirePermissions } = require("../requirePermissions");
10
- var MAX_BATCH_SIZE = 1000;
11
- var validateOptions = accountExporter.validateOptions;
12
- var serialExportUsers = accountExporter.serialExportUsers;
13
- module.exports = new Command("auth:export [dataFile]")
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const clc = require("cli-color");
4
+ const fs = require("fs");
5
+ const os = require("os");
6
+ const command_1 = require("../command");
7
+ const logger_1 = require("../logger");
8
+ const projectUtils_1 = require("../projectUtils");
9
+ const requirePermissions_1 = require("../requirePermissions");
10
+ const accountExporter_1 = require("../accountExporter");
11
+ const MAX_BATCH_SIZE = 1000;
12
+ exports.default = new command_1.Command("auth:export [dataFile]")
14
13
  .description("Export accounts from your Firebase project into a data file")
15
- .option("--format <format>", "Format of exported data (csv, json). Ignored if [dataFile] has format extension.")
16
- .before(requirePermissions, ["firebaseauth.users.get"])
17
- .action(function (dataFile, options) {
18
- var projectId = needProjectId(options);
19
- var checkRes = validateOptions(options, dataFile);
14
+ .option("--format <format>", "Format of exported data (csv, json). Ignored if <dataFile> has format extension.")
15
+ .before(requirePermissions_1.requirePermissions, ["firebaseauth.users.get"])
16
+ .action((dataFile, options) => {
17
+ const projectId = (0, projectUtils_1.needProjectId)(options);
18
+ const checkRes = (0, accountExporter_1.validateOptions)(options, dataFile);
20
19
  if (!checkRes.format) {
21
20
  return checkRes;
22
21
  }
23
- var exportOptions = checkRes;
24
- var writeStream = fs.createWriteStream(dataFile);
25
- if (exportOptions.format === "json") {
22
+ const writeStream = fs.createWriteStream(dataFile);
23
+ if (checkRes.format === "json") {
26
24
  writeStream.write('{"users": [' + os.EOL);
27
25
  }
28
- exportOptions.writeStream = writeStream;
29
- exportOptions.batchSize = MAX_BATCH_SIZE;
30
- logger.info("Exporting accounts to " + clc.bold(dataFile));
31
- return serialExportUsers(projectId, exportOptions).then(function () {
26
+ const exportOptions = {
27
+ format: checkRes.format,
28
+ writeStream,
29
+ batchSize: MAX_BATCH_SIZE,
30
+ };
31
+ logger_1.logger.info("Exporting accounts to " + clc.bold(dataFile));
32
+ return (0, accountExporter_1.serialExportUsers)(projectId, exportOptions).then(() => {
32
33
  if (exportOptions.format === "json") {
33
34
  writeStream.write("]}");
34
35
  }
35
36
  writeStream.end();
36
- return new Promise(function (resolve, reject) {
37
+ return new Promise((resolve, reject) => {
37
38
  writeStream.on("finish", resolve);
38
39
  writeStream.on("close", resolve);
39
40
  writeStream.on("error", reject);
@@ -1,21 +1,23 @@
1
1
  "use strict";
2
- var csv = require("csv-streamify");
3
- var clc = require("cli-color");
4
- var fs = require("fs");
5
- var jsonStream = require("JSONStream");
6
- var _ = require("lodash");
7
- var { Command } = require("../command");
8
- var accountImporter = require("../accountImporter");
9
- var needProjectId = require("../projectUtils").needProjectId;
10
- const { logger } = require("../logger");
11
- var { requirePermissions } = require("../requirePermissions");
12
- var utils = require("../utils");
13
- var MAX_BATCH_SIZE = 1000;
14
- var validateOptions = accountImporter.validateOptions;
15
- var validateUserJson = accountImporter.validateUserJson;
16
- var transArrayToUser = accountImporter.transArrayToUser;
17
- var serialImportUsers = accountImporter.serialImportUsers;
18
- module.exports = new Command("auth:import [dataFile]")
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const csv_parse_1 = require("csv-parse");
4
+ const Chain = require("stream-chain");
5
+ const clc = require("cli-color");
6
+ const fs = require("fs-extra");
7
+ const Pick = require("stream-json/filters/Pick");
8
+ const StreamArray = require("stream-json/streamers/StreamArray");
9
+ const command_1 = require("../command");
10
+ const error_1 = require("../error");
11
+ const logger_1 = require("../logger");
12
+ const projectUtils_1 = require("../projectUtils");
13
+ const requirePermissions_1 = require("../requirePermissions");
14
+ const accountImporter = require("../accountImporter");
15
+ const MAX_BATCH_SIZE = 1000;
16
+ const validateOptions = accountImporter.validateOptions;
17
+ const validateUserJson = accountImporter.validateUserJson;
18
+ const transArrayToUser = accountImporter.transArrayToUser;
19
+ const serialImportUsers = accountImporter.serialImportUsers;
20
+ module.exports = new command_1.Command("auth:import [dataFile]")
19
21
  .description("import users into your Firebase project from a data file(.csv or .json)")
20
22
  .option("--hash-algo <hashAlgo>", "specify the hash algorithm used in password for these accounts")
21
23
  .option("--hash-key <hashKey>", "specify the key used in hash algorithm")
@@ -27,81 +29,89 @@ module.exports = new Command("auth:import [dataFile]")
27
29
  .option("--dk-len <dkLen>", "specify derived key length for standard scrypt.")
28
30
  .option("--hash-input-order <hashInputOrder>", "specify the order of password and salt. Possible values are SALT_FIRST and PASSWORD_FIRST. " +
29
31
  "MD5, SHA1, SHA256, SHA512, HMAC_MD5, HMAC_SHA1, HMAC_SHA256, HMAC_SHA512 support this flag.")
30
- .before(requirePermissions, ["firebaseauth.users.create", "firebaseauth.users.update"])
31
- .action(function (dataFile, options) {
32
- var projectId = needProjectId(options);
33
- var checkRes = validateOptions(options);
32
+ .before(requirePermissions_1.requirePermissions, ["firebaseauth.users.create", "firebaseauth.users.update"])
33
+ .action(async (dataFile, options) => {
34
+ const projectId = (0, projectUtils_1.needProjectId)(options);
35
+ const checkRes = validateOptions(options);
34
36
  if (!checkRes.valid) {
35
37
  return checkRes;
36
38
  }
37
- var hashOptions = checkRes;
38
- if (!_.endsWith(dataFile, ".csv") && !_.endsWith(dataFile, ".json")) {
39
- return utils.reject("Data file must end with .csv or .json", { exit: 1 });
39
+ const hashOptions = checkRes;
40
+ if (!dataFile.endsWith(".csv") && !dataFile.endsWith(".json")) {
41
+ throw new error_1.FirebaseError("Data file must end with .csv or .json");
40
42
  }
41
- var stats = fs.statSync(dataFile);
42
- var fileSizeInBytes = stats.size;
43
- logger.info("Processing " + clc.bold(dataFile) + " (" + fileSizeInBytes + " bytes)");
44
- var inStream = fs.createReadStream(dataFile);
45
- var batches = [];
46
- var currentBatch = [];
47
- var counter = 0;
48
- return new Promise(function (resolve, reject) {
49
- var parser;
50
- if (dataFile.endsWith(".csv")) {
51
- parser = csv({ objectMode: true });
43
+ const stats = await fs.stat(dataFile);
44
+ const fileSizeInBytes = stats.size;
45
+ logger_1.logger.info(`Processing ${clc.bold(dataFile)} (${fileSizeInBytes} bytes)`);
46
+ const batches = [];
47
+ let currentBatch = [];
48
+ let counter = 0;
49
+ let userListArr = [];
50
+ const inStream = fs.createReadStream(dataFile);
51
+ if (dataFile.endsWith(".csv")) {
52
+ userListArr = await new Promise((resolve, reject) => {
53
+ const parser = (0, csv_parse_1.parse)();
52
54
  parser
53
- .on("data", function (line) {
54
- counter++;
55
- var user = transArrayToUser(line.map(function (str) {
56
- var newStr = str.trim().replace(/^["|'](.*)["|']$/, "$1");
57
- return newStr === "" ? undefined : newStr;
58
- }));
59
- if (user.error) {
60
- return reject("Line " + counter + " (" + line + ") has invalid data format: " + user.error);
61
- }
62
- currentBatch.push(user);
63
- if (currentBatch.length === MAX_BATCH_SIZE) {
64
- batches.push(currentBatch);
65
- currentBatch = [];
55
+ .on("readable", () => {
56
+ let record = [];
57
+ while ((record = parser.read()) !== null) {
58
+ counter++;
59
+ const trimmed = record.map((s) => {
60
+ const str = s.trim().replace(/^["|'](.*)["|']$/, "$1");
61
+ return str === "" ? undefined : str;
62
+ });
63
+ const user = transArrayToUser(trimmed);
64
+ const err = user.error;
65
+ if (err) {
66
+ return reject(new error_1.FirebaseError(`Line ${counter} (${record.join(",")}) has invalid data format: ${err}`));
67
+ }
68
+ currentBatch.push(user);
69
+ if (currentBatch.length === MAX_BATCH_SIZE) {
70
+ batches.push(currentBatch);
71
+ currentBatch = [];
72
+ }
66
73
  }
67
74
  })
68
- .on("end", function () {
75
+ .on("end", () => {
69
76
  if (currentBatch.length) {
70
77
  batches.push(currentBatch);
71
78
  }
72
- return resolve(batches);
79
+ resolve(batches);
73
80
  });
74
81
  inStream.pipe(parser);
75
- }
76
- else {
77
- parser = jsonStream.parse(["users", { emitKey: true }]);
78
- parser
79
- .on("data", function (pair) {
80
- counter++;
81
- var res = validateUserJson(pair.value);
82
- if (res.error) {
83
- return reject(res.error);
84
- }
85
- currentBatch.push(pair.value);
86
- if (currentBatch.length === MAX_BATCH_SIZE) {
87
- batches.push(currentBatch);
88
- currentBatch = [];
89
- }
90
- })
91
- .on("end", function () {
82
+ });
83
+ }
84
+ else {
85
+ userListArr = await new Promise((resolve, reject) => {
86
+ const pipeline = new Chain([
87
+ Pick.withParser({ filter: /^users$/ }),
88
+ StreamArray.streamArray(),
89
+ ({ value }) => {
90
+ counter++;
91
+ const user = validateUserJson(value);
92
+ const err = user.error;
93
+ if (err) {
94
+ throw new error_1.FirebaseError(`Validation Error: ${err}`);
95
+ }
96
+ currentBatch.push(user);
97
+ if (currentBatch.length === MAX_BATCH_SIZE) {
98
+ batches.push(currentBatch);
99
+ currentBatch = [];
100
+ }
101
+ },
102
+ ]);
103
+ pipeline.once("error", reject);
104
+ pipeline.on("finish", () => {
92
105
  if (currentBatch.length) {
93
106
  batches.push(currentBatch);
94
107
  }
95
- return resolve(batches);
108
+ resolve(batches);
96
109
  });
97
- inStream.pipe(parser);
98
- }
99
- }).then(function (userListArr) {
100
- logger.debug("Preparing to import", counter, "user records in", userListArr.length, "batches.");
101
- if (userListArr.length) {
102
- return serialImportUsers(projectId, hashOptions, userListArr, 0);
103
- }
104
- }, function (error) {
105
- return utils.reject(error, { exit: 1 });
106
- });
110
+ inStream.pipe(pipeline);
111
+ });
112
+ }
113
+ logger_1.logger.debug(`Preparing to import ${counter} user records in ${userListArr.length} batches.`);
114
+ if (userListArr.length) {
115
+ return serialImportUsers(projectId, hashOptions, userListArr, 0);
116
+ }
107
117
  });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const _ = require("lodash");
4
4
  const clc = require("cli-color");
5
- const marked = require("marked");
5
+ const { marked } = require("marked");
6
6
  const ora = require("ora");
7
7
  const TerminalRenderer = require("marked-terminal");
8
8
  const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
- const marked = require("marked");
5
+ const { marked } = require("marked");
6
6
  const TerminalRenderer = require("marked-terminal");
7
7
  const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
8
8
  const command_1 = require("../command");
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const clc = require("cli-color");
4
- const marked = require("marked");
4
+ const { marked } = require("marked");
5
5
  const TerminalRenderer = require("marked-terminal");
6
6
  const command_1 = require("../command");
7
7
  const extensionsHelper_1 = require("../extensions/extensionsHelper");
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const clc = require("cli-color");
4
- const marked = require("marked");
4
+ const { marked } = require("marked");
5
5
  const command_1 = require("../command");
6
6
  const extensionsApi_1 = require("../extensions/extensionsApi");
7
7
  const projectUtils_1 = require("../projectUtils");
@@ -10,7 +10,7 @@ const localHelper_1 = require("../extensions/localHelper");
10
10
  const logger_1 = require("../logger");
11
11
  const requirePermissions_1 = require("../requirePermissions");
12
12
  const utils = require("../utils");
13
- const marked = require("marked");
13
+ const { marked } = require("marked");
14
14
  const TerminalRenderer = require("marked-terminal");
15
15
  const FUNCTION_TYPE_REGEX = /\..+\.function/;
16
16
  exports.default = new command_1.Command("ext:info <extensionName>")
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const clc = require("cli-color");
4
- const marked = require("marked");
4
+ const { marked } = require("marked");
5
5
  const ora = require("ora");
6
6
  const TerminalRenderer = require("marked-terminal");
7
7
  const askUserForConsent = require("../extensions/askUserForConsent");
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const _ = require("lodash");
4
4
  const clc = require("cli-color");
5
5
  const ora = require("ora");
6
- const marked = require("marked");
6
+ const { marked } = require("marked");
7
7
  const TerminalRenderer = require("marked-terminal");
8
8
  const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
9
9
  const command_1 = require("../command");
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const clc = require("cli-color");
4
4
  const _ = require("lodash");
5
- const marked = require("marked");
5
+ const { marked } = require("marked");
6
6
  const ora = require("ora");
7
7
  const TerminalRenderer = require("marked-terminal");
8
8
  const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
@@ -1,18 +1,20 @@
1
1
  "use strict";
2
- var clc = require("cli-color");
3
- var { Command } = require("../command");
4
- var functionsConfig = require("../functionsConfig");
5
- var functionsConfigClone = require("../functionsConfigClone");
6
- var needProjectId = require("../projectUtils").needProjectId;
7
- var { requirePermissions } = require("../requirePermissions");
8
- var utils = require("../utils");
9
- const { logger } = require("../logger");
10
- module.exports = new Command("functions:config:clone")
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const clc = require("cli-color");
4
+ const command_1 = require("../command");
5
+ const error_1 = require("../error");
6
+ const logger_1 = require("../logger");
7
+ const projectUtils_1 = require("../projectUtils");
8
+ const requirePermissions_1 = require("../requirePermissions");
9
+ const functionsConfig = require("../functionsConfig");
10
+ const functionsConfigClone = require("../functionsConfigClone");
11
+ const utils = require("../utils");
12
+ exports.default = new command_1.Command("functions:config:clone")
11
13
  .description("clone environment config from another project")
12
14
  .option("--from <projectId>", "the project from which to clone configuration")
13
15
  .option("--only <keys>", "a comma-separated list of keys to clone")
14
16
  .option("--except <keys>", "a comma-separated list of keys to not clone")
15
- .before(requirePermissions, [
17
+ .before(requirePermissions_1.requirePermissions, [
16
18
  "runtimeconfig.configs.list",
17
19
  "runtimeconfig.configs.create",
18
20
  "runtimeconfig.configs.get",
@@ -25,29 +27,26 @@ module.exports = new Command("functions:config:clone")
25
27
  "runtimeconfig.variables.delete",
26
28
  ])
27
29
  .before(functionsConfig.ensureApi)
28
- .action(function (options) {
29
- var projectId = needProjectId(options);
30
+ .action(async (options) => {
31
+ const projectId = (0, projectUtils_1.needProjectId)(options);
30
32
  if (!options.from) {
31
- return utils.reject("Must specify a source project in " + clc.bold("--from <projectId>") + " option.");
33
+ throw new error_1.FirebaseError(`Must specify a source project in ${clc.bold("--from <projectId>")} option.`);
32
34
  }
33
35
  else if (options.from === projectId) {
34
- return utils.reject("From project and destination can't be the same project.");
36
+ throw new error_1.FirebaseError("From project and destination can't be the same project.");
35
37
  }
36
38
  else if (options.only && options.except) {
37
- return utils.reject("Cannot use both --only and --except at the same time.");
39
+ throw new error_1.FirebaseError("Cannot use both --only and --except at the same time.");
38
40
  }
39
- var only;
40
- var except;
41
+ let only = [];
42
+ let except = [];
41
43
  if (options.only) {
42
44
  only = options.only.split(",");
43
45
  }
44
46
  else if (options.except) {
45
47
  except = options.except.split(",");
46
48
  }
47
- return functionsConfigClone(options.from, projectId, only, except).then(function () {
48
- utils.logSuccess("Cloned functions config from " + clc.bold(options.from) + " into " + clc.bold(projectId));
49
- logger.info("\nPlease deploy your functions for the change to take effect by running " +
50
- clc.bold("firebase deploy --only functions") +
51
- "\n");
52
- });
49
+ await functionsConfigClone(options.from, projectId, only, except);
50
+ utils.logSuccess(`Cloned functions config from ${clc.bold(options.from)} into ${clc.bold(projectId)}`);
51
+ logger_1.logger.info(`\nPlease deploy your functions for the change to take effect by running ${clc.bold("firebase deploy --only functions")}\n`);
53
52
  });
@@ -1,34 +1,34 @@
1
1
  "use strict";
2
- var _ = require("lodash");
3
- var { Command } = require("../command");
4
- var needProjectId = require("../projectUtils").needProjectId;
5
- const { logger } = require("../logger");
6
- var { requirePermissions } = require("../requirePermissions");
7
- var functionsConfig = require("../functionsConfig");
8
- function _materialize(projectId, path) {
9
- if (_.isUndefined(path)) {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lodash_1 = require("lodash");
4
+ const path_1 = require("path");
5
+ const command_1 = require("../command");
6
+ const logger_1 = require("../logger");
7
+ const projectUtils_1 = require("../projectUtils");
8
+ const requirePermissions_1 = require("../requirePermissions");
9
+ const functionsConfig = require("../functionsConfig");
10
+ async function materialize(projectId, path) {
11
+ if (path === undefined) {
10
12
  return functionsConfig.materializeAll(projectId);
11
13
  }
12
- var parts = path.split(".");
13
- var configId = parts[0];
14
- var configName = _.join(["projects", projectId, "configs", configId], "/");
15
- return functionsConfig.materializeConfig(configName, {}).then(function (result) {
16
- var query = _.chain(parts).join(".").value();
17
- return query ? _.get(result, query) : result;
18
- });
14
+ const parts = path.split(".");
15
+ const configId = parts[0];
16
+ const configName = (0, path_1.join)("projects", projectId, "configs", configId);
17
+ const result = await functionsConfig.materializeConfig(configName, {});
18
+ const query = parts.join(".");
19
+ return query ? (0, lodash_1.get)(result, query) : result;
19
20
  }
20
- module.exports = new Command("functions:config:get [path]")
21
+ exports.default = new command_1.Command("functions:config:get [path]")
21
22
  .description("fetch environment config stored at the given path")
22
- .before(requirePermissions, [
23
+ .before(requirePermissions_1.requirePermissions, [
23
24
  "runtimeconfig.configs.list",
24
25
  "runtimeconfig.configs.get",
25
26
  "runtimeconfig.variables.list",
26
27
  "runtimeconfig.variables.get",
27
28
  ])
28
29
  .before(functionsConfig.ensureApi)
29
- .action(function (path, options) {
30
- return _materialize(needProjectId(options), path).then(function (result) {
31
- logger.info(JSON.stringify(result, null, 2));
32
- return result;
33
- });
30
+ .action(async (path, options) => {
31
+ const result = await materialize((0, projectUtils_1.needProjectId)(options), path);
32
+ logger_1.logger.info(JSON.stringify(result, null, 2));
33
+ return result;
34
34
  });
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
- var clc = require("cli-color");
3
- var { Command } = require("../command");
4
- var needProjectId = require("../projectUtils").needProjectId;
5
- var { requirePermissions } = require("../requirePermissions");
6
- const { logger } = require("../logger");
7
- var utils = require("../utils");
8
- var functionsConfig = require("../functionsConfig");
9
- module.exports = new Command("functions:config:set [values...]")
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const clc = require("cli-color");
4
+ const command_1 = require("../command");
5
+ const error_1 = require("../error");
6
+ const logger_1 = require("../logger");
7
+ const projectUtils_1 = require("../projectUtils");
8
+ const requirePermissions_1 = require("../requirePermissions");
9
+ const functionsConfig = require("../functionsConfig");
10
+ const utils = require("../utils");
11
+ exports.default = new command_1.Command("functions:config:set [values...]")
10
12
  .description("set environment config with key=value syntax")
11
- .before(requirePermissions, [
13
+ .before(requirePermissions_1.requirePermissions, [
12
14
  "runtimeconfig.configs.list",
13
15
  "runtimeconfig.configs.create",
14
16
  "runtimeconfig.configs.get",
@@ -21,20 +23,20 @@ module.exports = new Command("functions:config:set [values...]")
21
23
  "runtimeconfig.variables.delete",
22
24
  ])
23
25
  .before(functionsConfig.ensureApi)
24
- .action(function (args, options) {
26
+ .action(async (args, options) => {
25
27
  if (!args.length) {
26
- return utils.reject("Must supply at least one key/value pair, e.g. " + clc.bold('app.name="My App"'));
28
+ throw new error_1.FirebaseError(`Must supply at least one key/value pair, e.g. ${clc.bold('app.name="My App"')}`);
27
29
  }
28
- var projectId = needProjectId(options);
29
- var parsed = functionsConfig.parseSetArgs(args);
30
- var promises = [];
31
- parsed.forEach(function (item) {
30
+ const projectId = (0, projectUtils_1.needProjectId)(options);
31
+ const parsed = functionsConfig.parseSetArgs(args);
32
+ const promises = [];
33
+ for (const item of parsed) {
34
+ if (item.val === undefined) {
35
+ throw new error_1.FirebaseError(`Unexpected undefined value for varId "${item.varId}`, { exit: 2 });
36
+ }
32
37
  promises.push(functionsConfig.setVariablesRecursive(projectId, item.configId, item.varId, item.val));
33
- });
34
- return Promise.all(promises).then(function () {
35
- utils.logSuccess("Functions config updated.");
36
- logger.info("\nPlease deploy your functions for the change to take effect by running " +
37
- clc.bold("firebase deploy --only functions") +
38
- "\n");
39
- });
38
+ }
39
+ await Promise.all(promises);
40
+ utils.logSuccess("Functions config updated.");
41
+ logger_1.logger.info(`\nPlease deploy your functions for the change to take effect by running ${clc.bold("firebase deploy --only functions")}\n`);
40
42
  });