firebase-tools 10.1.1 → 10.1.5

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 (87) hide show
  1. package/lib/accountExporter.js +9 -8
  2. package/lib/accountImporter.js +10 -8
  3. package/lib/apiv2.js +92 -48
  4. package/lib/archiveDirectory.js +63 -73
  5. package/lib/bin/firebase.js +1 -1
  6. package/lib/commands/auth-export.js +26 -25
  7. package/lib/commands/auth-import.js +88 -78
  8. package/lib/commands/ext-configure.js +1 -1
  9. package/lib/commands/ext-dev-init.js +1 -1
  10. package/lib/commands/ext-dev-publish.js +1 -1
  11. package/lib/commands/ext-dev-register.js +1 -1
  12. package/lib/commands/ext-dev-usage.js +3 -8
  13. package/lib/commands/ext-info.js +1 -1
  14. package/lib/commands/ext-install.js +1 -1
  15. package/lib/commands/ext-uninstall.js +1 -1
  16. package/lib/commands/ext-update.js +1 -1
  17. package/lib/commands/functions-config-clone.js +22 -23
  18. package/lib/commands/functions-config-get.js +22 -22
  19. package/lib/commands/functions-config-set.js +24 -22
  20. package/lib/commands/functions-config-unset.js +20 -22
  21. package/lib/commands/help.js +12 -12
  22. package/lib/commands/hosting-channel-create.js +1 -1
  23. package/lib/commands/hosting-channel-delete.js +2 -2
  24. package/lib/commands/hosting-channel-deploy.js +1 -1
  25. package/lib/commands/hosting-clone.js +1 -1
  26. package/lib/commands/login-ci.js +10 -10
  27. package/lib/commands/remoteconfig-versions-list.js +6 -1
  28. package/lib/commands/setup-emulators-database.js +8 -7
  29. package/lib/commands/setup-emulators-firestore.js +8 -7
  30. package/lib/commands/setup-emulators-pubsub.js +5 -4
  31. package/lib/commands/setup-emulators-storage.js +3 -2
  32. package/lib/commands/setup-emulators-ui.js +8 -7
  33. package/lib/commands/target-apply.js +17 -16
  34. package/lib/commands/target-clear.js +11 -10
  35. package/lib/commands/target-remove.js +10 -9
  36. package/lib/commands/target.js +20 -20
  37. package/lib/database/metadata.js +16 -24
  38. package/lib/defaultCredentials.js +3 -3
  39. package/lib/deploy/functions/backend.js +3 -1
  40. package/lib/deploy/functions/prepare.js +2 -2
  41. package/lib/deploy/functions/release/fabricator.js +4 -1
  42. package/lib/deploy/functions/runtimes/golang/index.js +2 -1
  43. package/lib/deploy/functions/validate.js +28 -1
  44. package/lib/deploy/hosting/convertConfig.js +45 -24
  45. package/lib/deploy/hosting/prepare.js +1 -1
  46. package/lib/emulator/downloadableEmulators.js +3 -2
  47. package/lib/emulator/functionsEmulator.js +9 -1
  48. package/lib/emulator/functionsEmulatorRuntime.js +4 -4
  49. package/lib/emulator/storage/apis/gcloud.js +2 -2
  50. package/lib/emulator/storage/files.js +8 -3
  51. package/lib/emulator/storage/rules/runtime.js +5 -4
  52. package/lib/extensions/askUserForConsent.js +1 -1
  53. package/lib/extensions/askUserForParam.js +1 -1
  54. package/lib/extensions/billingMigrationHelper.js +1 -1
  55. package/lib/extensions/changelog.js +1 -1
  56. package/lib/extensions/displayExtensionInfo.js +1 -1
  57. package/lib/extensions/extensionsApi.js +57 -112
  58. package/lib/extensions/extensionsHelper.js +20 -32
  59. package/lib/extensions/provisioningHelper.js +7 -10
  60. package/lib/extensions/resolveSource.js +5 -57
  61. package/lib/extensions/updateHelper.js +1 -15
  62. package/lib/extensions/utils.js +4 -2
  63. package/lib/extensions/warnings.js +1 -1
  64. package/lib/functionsConfig.js +4 -5
  65. package/lib/gcp/cloudbilling.js +8 -19
  66. package/lib/gcp/cloudfunctions.js +22 -46
  67. package/lib/gcp/cloudlogging.js +8 -11
  68. package/lib/gcp/cloudmonitoring.js +8 -5
  69. package/lib/gcp/cloudscheduler.js +7 -18
  70. package/lib/gcp/firedata.js +5 -4
  71. package/lib/gcp/firestore.js +5 -5
  72. package/lib/gcp/iam.js +18 -33
  73. package/lib/gcp/resourceManager.js +8 -13
  74. package/lib/gcp/rules.js +18 -41
  75. package/lib/gcp/runtimeconfig.js +31 -53
  76. package/lib/gcp/secretManager.js +21 -43
  77. package/lib/gcp/storage.js +25 -29
  78. package/lib/projectUtils.js +1 -1
  79. package/lib/remoteconfig/get.js +14 -8
  80. package/lib/remoteconfig/rollback.js +13 -6
  81. package/lib/remoteconfig/versionslist.js +13 -7
  82. package/npm-shrinkwrap.json +1706 -2525
  83. package/package.json +16 -11
  84. package/schema/firebase-config.json +387 -12
  85. package/templates/init/hosting/index.html +1 -1
  86. package/lib/commands/functions-config-legacy.js +0 -45
  87. package/lib/prepareFirebaseRules.js +0 -58
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const cli_color_1 = require("cli-color");
4
- const marked_1 = require("marked");
4
+ const { marked } = require("marked");
5
5
  const command_1 = require("../command");
6
6
  const utils_1 = require("../utils");
7
7
  const api_1 = require("../hosting/api");
@@ -38,7 +38,7 @@ exports.default = new command_1.Command("hosting:channel:delete <channelId>")
38
38
  await (0, api_1.removeAuthDomain)(projectId, channel.url);
39
39
  }
40
40
  catch (e) {
41
- (0, utils_1.logLabeledWarning)("hosting:channel", (0, marked_1.default)(`Unable to remove channel domain from Firebase Auth. Visit the Firebase Console at ${(0, utils_1.consoleUrl)(projectId, "/authentication/providers")}`));
41
+ (0, utils_1.logLabeledWarning)("hosting:channel", marked(`Unable to remove channel domain from Firebase Auth. Visit the Firebase Console at ${(0, utils_1.consoleUrl)(projectId, "/authentication/providers")}`));
42
42
  logger_1.logger.debug("[hosting] unable to remove auth domain", e);
43
43
  }
44
44
  }
@@ -12,7 +12,7 @@ const logger_1 = require("../logger");
12
12
  const requireConfig = require("../requireConfig");
13
13
  const expireUtils_1 = require("../hosting/expireUtils");
14
14
  const utils_1 = require("../utils");
15
- const marked = require("marked");
15
+ const { marked } = require("marked");
16
16
  const requireHostingSite_1 = require("../requireHostingSite");
17
17
  const LOG_TAG = "hosting:channel";
18
18
  exports.default = new command_1.Command("hosting:channel:deploy [channelId]")
@@ -7,7 +7,7 @@ const error_1 = require("../error");
7
7
  const api_1 = require("../hosting/api");
8
8
  const utils = require("../utils");
9
9
  const requireAuth_1 = require("../requireAuth");
10
- const marked = require("marked");
10
+ const { marked } = require("marked");
11
11
  const logger_1 = require("../logger");
12
12
  exports.default = new command_1.Command("hosting:clone <source> <targetChannel>")
13
13
  .description("clone a version from one site to another")
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
- var { Command } = require("../command");
3
- var clc = require("cli-color");
4
- var utils = require("../utils");
5
- const { logger } = require("../logger");
6
- var auth = require("../auth");
7
- module.exports = new Command("login:ci")
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 auth = require("../auth");
8
+ const utils = require("../utils");
9
+ exports.default = new command_1.Command("login:ci")
8
10
  .description("generate an access token for use in non-interactive environments")
9
11
  .option("--no-localhost", "copy and paste a code instead of starting a local server for authentication")
10
12
  .action(async (options) => {
11
13
  if (options.nonInteractive) {
12
- return utils.reject("Cannot run login:ci in non-interactive mode.", {
13
- exit: 1,
14
- });
14
+ throw new error_1.FirebaseError("Cannot run login:ci in non-interactive mode.");
15
15
  }
16
16
  const userCredentials = await auth.loginGoogle(options.localhost);
17
- logger.info();
17
+ logger_1.logger.info();
18
18
  utils.logSuccess("Success! Use this token to login on a CI server:\n\n" +
19
19
  clc.bold(userCredentials.tokens.refresh_token) +
20
20
  '\n\nExample: firebase deploy --token "$FIREBASE_TOKEN"\n');
@@ -6,11 +6,16 @@ const command_1 = require("../command");
6
6
  const projectUtils_1 = require("../projectUtils");
7
7
  const requireAuth_1 = require("../requireAuth");
8
8
  const requirePermissions_1 = require("../requirePermissions");
9
+ const utils_1 = require("../utils");
9
10
  const Table = require("cli-table");
10
11
  const tableHead = ["Update User", "Version Number", "Update Time"];
11
12
  function pushTableContents(table, version) {
12
13
  var _a;
13
- return table.push([(_a = version === null || version === void 0 ? void 0 : version.updateUser) === null || _a === void 0 ? void 0 : _a.email, version === null || version === void 0 ? void 0 : version.versionNumber, version === null || version === void 0 ? void 0 : version.updateTime]);
14
+ return table.push([
15
+ (_a = version.updateUser) === null || _a === void 0 ? void 0 : _a.email,
16
+ version.versionNumber,
17
+ version.updateTime ? (0, utils_1.datetimeString)(new Date(version.updateTime)) : "",
18
+ ]);
14
19
  }
15
20
  module.exports = new command_1.Command("remoteconfig:versions:list")
16
21
  .description("get a list of Remote Config template versions that have been published for a Firebase project")
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
- const { Command } = require("../command");
3
- const { Emulators } = require("../emulator/types");
4
- const { downloadEmulator } = require("../emulator/download");
5
- const NAME = Emulators.DATABASE;
6
- module.exports = new Command(`setup:emulators:${NAME}`)
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("../command");
4
+ const download_1 = require("../emulator/download");
5
+ const types_1 = require("../emulator/types");
6
+ const NAME = types_1.Emulators.DATABASE;
7
+ exports.default = new command_1.Command(`setup:emulators:${NAME}`)
7
8
  .description(`downloads the ${NAME} emulator`)
8
- .action((options) => {
9
- return downloadEmulator(NAME);
9
+ .action(() => {
10
+ return (0, download_1.downloadEmulator)(NAME);
10
11
  });
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
- const { Command } = require("../command");
3
- const { Emulators } = require("../emulator/types");
4
- const { downloadEmulator } = require("../emulator/download");
5
- const NAME = Emulators.FIRESTORE;
6
- module.exports = new Command(`setup:emulators:${NAME}`)
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("../command");
4
+ const download_1 = require("../emulator/download");
5
+ const types_1 = require("../emulator/types");
6
+ const NAME = types_1.Emulators.FIRESTORE;
7
+ exports.default = new command_1.Command(`setup:emulators:${NAME}`)
7
8
  .description(`downloads the ${NAME} emulator`)
8
- .action((options) => {
9
- return downloadEmulator(NAME);
9
+ .action(() => {
10
+ return (0, download_1.downloadEmulator)(NAME);
10
11
  });
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("../command");
4
- const { downloadEmulator } = require("../emulator/download");
5
- const EMULATOR_NAME = "pubsub";
6
- module.exports = new command_1.Command(`setup:emulators:${EMULATOR_NAME}`)
4
+ const download_1 = require("../emulator/download");
5
+ const types_1 = require("../emulator/types");
6
+ const EMULATOR_NAME = types_1.Emulators.PUBSUB;
7
+ exports.default = new command_1.Command(`setup:emulators:${EMULATOR_NAME}`)
7
8
  .description(`downloads the ${EMULATOR_NAME} emulator`)
8
9
  .action(() => {
9
- return downloadEmulator(EMULATOR_NAME);
10
+ return (0, download_1.downloadEmulator)(EMULATOR_NAME);
10
11
  });
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("../command");
4
4
  const download_1 = require("../emulator/download");
5
- const EMULATOR_NAME = "storage";
6
- module.exports = new command_1.Command(`setup:emulators:${EMULATOR_NAME}`)
5
+ const types_1 = require("../emulator/types");
6
+ const EMULATOR_NAME = types_1.Emulators.STORAGE;
7
+ exports.default = new command_1.Command(`setup:emulators:${EMULATOR_NAME}`)
7
8
  .description(`downloads the ${EMULATOR_NAME} emulator`)
8
9
  .action(() => {
9
10
  return (0, download_1.downloadEmulator)(EMULATOR_NAME);
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
- const { Command } = require("../command");
3
- const { Emulators } = require("../emulator/types");
4
- const { downloadEmulator } = require("../emulator/download");
5
- const NAME = Emulators.UI;
6
- module.exports = new Command(`setup:emulators:${NAME}`)
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("../command");
4
+ const download_1 = require("../emulator/download");
5
+ const types_1 = require("../emulator/types");
6
+ const NAME = types_1.Emulators.UI;
7
+ exports.default = new command_1.Command(`setup:emulators:${NAME}`)
7
8
  .description(`downloads the ${NAME} emulator`)
8
- .action((options) => {
9
- return downloadEmulator(NAME);
9
+ .action(() => {
10
+ return (0, download_1.downloadEmulator)(NAME);
10
11
  });
@@ -1,22 +1,23 @@
1
1
  "use strict";
2
- var _ = require("lodash");
3
- var clc = require("cli-color");
4
- var { Command } = require("../command");
5
- const { logger } = require("../logger");
6
- var requireConfig = require("../requireConfig");
7
- var utils = require("../utils");
8
- module.exports = new Command("target:apply <type> <name> <resources...>")
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const clc = require("cli-color");
4
+ const command_1 = require("../command");
5
+ const logger_1 = require("../logger");
6
+ const requireConfig = require("../requireConfig");
7
+ const utils = require("../utils");
8
+ const error_1 = require("../error");
9
+ exports.default = new command_1.Command("target:apply <type> <name> <resources...>")
9
10
  .description("apply a deploy target to a resource")
10
11
  .before(requireConfig)
11
- .action(function (type, name, resources, options) {
12
+ .action((type, name, resources, options) => {
12
13
  if (!options.project) {
13
- return utils.reject("Must have an active project to set deploy targets. Try " + clc.bold("firebase use --add"));
14
+ throw new error_1.FirebaseError(`Must have an active project to set deploy targets. Try ${clc.bold("firebase use --add")}`);
14
15
  }
15
- var changes = options.rc.applyTarget(options.project, type, name, resources);
16
- utils.logSuccess("Applied " + type + " target " + clc.bold(name) + " to " + clc.bold(resources.join(", ")));
17
- _.forEach(changes, function (change) {
18
- utils.logWarning("Previous target " + clc.bold(change.target) + " removed from " + clc.bold(change.resource));
19
- });
20
- logger.info();
21
- logger.info("Updated: " + name + " (" + options.rc.target(options.project, type, name).join(",") + ")");
16
+ const changes = options.rc.applyTarget(options.project, type, name, resources);
17
+ utils.logSuccess(`Applied ${type} target ${clc.bold(name)} to ${clc.bold(resources.join(", "))}`);
18
+ for (const change of changes) {
19
+ utils.logWarning(`Previous target ${clc.bold(change.target)} removed from ${clc.bold(change.resource)}`);
20
+ }
21
+ logger_1.logger.info();
22
+ logger_1.logger.info(`Updated: ${name} (${options.rc.target(options.project, type, name).join(",")})`);
22
23
  });
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
- var clc = require("cli-color");
3
- var { Command } = require("../command");
4
- var requireConfig = require("../requireConfig");
5
- var utils = require("../utils");
6
- module.exports = new Command("target:clear <type> <target>")
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const clc = require("cli-color");
4
+ const command_1 = require("../command");
5
+ const requireConfig = require("../requireConfig");
6
+ const utils = require("../utils");
7
+ exports.default = new command_1.Command("target:clear <type> <target>")
7
8
  .description("clear all resources from a named resource target")
8
9
  .before(requireConfig)
9
- .action(function (type, name, options) {
10
- var existed = options.rc.clearTarget(options.project, type, name);
10
+ .action((type, name, options) => {
11
+ const existed = options.rc.clearTarget(options.project, type, name);
11
12
  if (existed) {
12
- utils.logSuccess("Cleared " + type + " target " + clc.bold(name));
13
+ utils.logSuccess(`Cleared ${type} target ${clc.bold(name)}`);
13
14
  }
14
15
  else {
15
- utils.logWarning("No action taken. No " + type + " target found named " + clc.bold(name));
16
+ utils.logWarning(`No action taken. No ${type} target found named ${clc.bold(name)}`);
16
17
  }
17
- return Promise.resolve(existed);
18
+ return existed;
18
19
  });
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
- var clc = require("cli-color");
3
- var { Command } = require("../command");
4
- var requireConfig = require("../requireConfig");
5
- var utils = require("../utils");
6
- module.exports = new Command("target:remove <type> <resource>")
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const clc = require("cli-color");
4
+ const command_1 = require("../command");
5
+ const requireConfig = require("../requireConfig");
6
+ const utils = require("../utils");
7
+ exports.default = new command_1.Command("target:remove <type> <resource>")
7
8
  .description("remove a resource target")
8
9
  .before(requireConfig)
9
- .action(function (type, resource, options) {
10
- var name = options.rc.removeTarget(options.project, type, resource);
10
+ .action((type, resource, options) => {
11
+ const name = options.rc.removeTarget(options.project, type, resource);
11
12
  if (name) {
12
- utils.logSuccess("Removed " + type + " target " + clc.bold(name) + " from " + clc.bold(resource));
13
+ utils.logSuccess(`Removed ${type} target ${clc.bold(name)} from ${clc.bold(resource)}`);
13
14
  }
14
15
  else {
15
- utils.logWarning("No action taken. No target found for " + type + " resource " + clc.bold(resource));
16
+ utils.logWarning(`No action taken. No target found for ${type} resource ${clc.bold(resource)}`);
16
17
  }
17
18
  return Promise.resolve(name);
18
19
  });
@@ -1,33 +1,33 @@
1
1
  "use strict";
2
- var _ = require("lodash");
3
- var clc = require("cli-color");
4
- var { Command } = require("../command");
5
- const { logger } = require("../logger");
6
- var requireConfig = require("../requireConfig");
7
- var utils = require("../utils");
8
- function _logTargets(type, targets) {
9
- logger.info(clc.cyan("[ " + type + " ]"));
10
- _.forEach(targets, function (resources, name) {
11
- logger.info(name, "(" + (resources || []).join(",") + ")");
12
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const clc = require("cli-color");
4
+ const command_1 = require("../command");
5
+ const logger_1 = require("../logger");
6
+ const requireConfig = require("../requireConfig");
7
+ const utils = require("../utils");
8
+ function logTargets(type, targets) {
9
+ logger_1.logger.info(clc.cyan("[ " + type + " ]"));
10
+ for (const [name, resources] of Object.entries(targets)) {
11
+ logger_1.logger.info(name, "(" + (resources || []).join(",") + ")");
12
+ }
13
13
  }
14
- module.exports = new Command("target [type]")
14
+ exports.default = new command_1.Command("target [type]")
15
15
  .description("display configured deploy targets for the current project")
16
16
  .before(requireConfig)
17
- .action(function (type, options) {
17
+ .action((type, options) => {
18
18
  if (!options.project) {
19
19
  return utils.reject("No active project, cannot list deploy targets.");
20
20
  }
21
- logger.info("Resource targets for", clc.bold(options.project) + ":");
22
- logger.info();
21
+ logger_1.logger.info("Resource targets for", clc.bold(options.project) + ":");
22
+ logger_1.logger.info();
23
23
  if (type) {
24
- var targets = options.rc.targets(options.project, type);
25
- _logTargets(type, targets);
26
- return Promise.resolve(targets);
24
+ const targets = options.rc.targets(options.project, type);
25
+ logTargets(type, targets);
26
+ return targets;
27
27
  }
28
28
  const allTargets = options.rc.allTargets(options.project);
29
29
  for (const [targetType, targetName] of Object.entries(allTargets)) {
30
- _logTargets(targetType, targetName);
30
+ logTargets(targetType, targetName);
31
31
  }
32
- return Promise.resolve(allTargets);
32
+ return allTargets;
33
33
  });
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setRulesetLabels = exports.createRuleset = exports.getRulesetLabels = exports.getRuleset = exports.listAllRulesets = void 0;
4
- const api = require("../api");
4
+ const api_1 = require("../api");
5
+ const apiv2_1 = require("../apiv2");
5
6
  const logger_1 = require("../logger");
6
7
  const utils = require("../utils");
7
8
  function handleErrorResponse(response) {
@@ -13,12 +14,9 @@ function handleErrorResponse(response) {
13
14
  code: 2,
14
15
  });
15
16
  }
17
+ const apiClient = new apiv2_1.Client({ urlPrefix: api_1.rtdbMetadataOrigin });
16
18
  async function listAllRulesets(databaseName) {
17
- const response = await api.request("GET", `/namespaces/${databaseName}/rulesets`, {
18
- auth: true,
19
- origin: api.rtdbMetadataOrigin,
20
- json: true,
21
- });
19
+ const response = await apiClient.get(`/namespaces/${databaseName}/rulesets`, { resolveOnHTTPError: true });
22
20
  if (response.status === 200) {
23
21
  return response.body.rulesets;
24
22
  }
@@ -26,11 +24,7 @@ async function listAllRulesets(databaseName) {
26
24
  }
27
25
  exports.listAllRulesets = listAllRulesets;
28
26
  async function getRuleset(databaseName, rulesetId) {
29
- const response = await api.request("GET", `/namespaces/${databaseName}/rulesets/${rulesetId}`, {
30
- auth: true,
31
- origin: api.rtdbMetadataOrigin,
32
- json: true,
33
- });
27
+ const response = await apiClient.get(`/namespaces/${databaseName}/rulesets/${rulesetId}`, { resolveOnHTTPError: true });
34
28
  if (response.status === 200) {
35
29
  return response.body;
36
30
  }
@@ -38,9 +32,8 @@ async function getRuleset(databaseName, rulesetId) {
38
32
  }
39
33
  exports.getRuleset = getRuleset;
40
34
  async function getRulesetLabels(databaseName) {
41
- const response = await api.request("GET", `/namespaces/${databaseName}/ruleset_labels`, {
42
- auth: true,
43
- origin: api.rtdbMetadataOrigin,
35
+ const response = await apiClient.get(`/namespaces/${databaseName}/ruleset_labels`, {
36
+ resolveOnHTTPError: true,
44
37
  });
45
38
  if (response.status === 200) {
46
39
  return response.body;
@@ -49,23 +42,22 @@ async function getRulesetLabels(databaseName) {
49
42
  }
50
43
  exports.getRulesetLabels = getRulesetLabels;
51
44
  async function createRuleset(databaseName, source) {
52
- const response = await api.request("POST", `/.settings/rulesets.json`, {
53
- auth: true,
54
- origin: utils.addSubdomain(api.realtimeOrigin, databaseName),
55
- json: false,
56
- data: source,
45
+ const localApiClient = new apiv2_1.Client({
46
+ urlPrefix: utils.addSubdomain(api_1.realtimeOrigin, databaseName),
57
47
  });
48
+ const response = await localApiClient.post(`/.settings/rulesets.json`, source, { resolveOnHTTPError: true });
58
49
  if (response.status === 200) {
59
- return JSON.parse(response.body).id;
50
+ return response.body.id;
60
51
  }
61
52
  return handleErrorResponse(response);
62
53
  }
63
54
  exports.createRuleset = createRuleset;
64
55
  async function setRulesetLabels(databaseName, labels) {
65
- const response = await api.request("PUT", `/.settings/ruleset_labels.json`, {
66
- auth: true,
67
- origin: utils.addSubdomain(api.realtimeOrigin, databaseName),
68
- data: labels,
56
+ const localApiClient = new apiv2_1.Client({
57
+ urlPrefix: utils.addSubdomain(api_1.realtimeOrigin, databaseName),
58
+ });
59
+ const response = await localApiClient.put(`/.settings/ruleset_labels.json`, labels, {
60
+ resolveOnHTTPError: true,
69
61
  });
70
62
  if (response.status === 200) {
71
63
  return response.body;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.clearCredentials = exports.getCredentialPathAsync = void 0;
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
- const api = require("./api");
6
+ const api_1 = require("./api");
7
7
  const logger_1 = require("./logger");
8
8
  async function getCredentialPathAsync(account) {
9
9
  const filePath = credFilePath(account.user);
@@ -43,8 +43,8 @@ exports.clearCredentials = clearCredentials;
43
43
  function getCredential(tokens) {
44
44
  if (tokens.refresh_token) {
45
45
  return {
46
- client_id: api.clientId,
47
- client_secret: api.clientSecret,
46
+ client_id: api_1.clientId,
47
+ client_secret: api_1.clientSecret,
48
48
  refresh_token: tokens.refresh_token,
49
49
  type: "authorized_user",
50
50
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compareFunctions = exports.missingEndpoint = exports.hasEndpoint = exports.regionalEndpoints = exports.matchingBackend = exports.someEndpoint = exports.allEndpoints = exports.checkAvailability = exports.existingBackend = exports.scheduleIdForFunction = exports.functionName = exports.isEmptyBackend = exports.of = exports.empty = exports.isTaskQueueTriggered = exports.isScheduleTriggered = exports.isEventTriggered = exports.isHttpsTriggered = exports.SCHEDULED_FUNCTION_LABEL = exports.memoryOptionDisplayName = exports.endpointTriggerType = void 0;
3
+ exports.compareFunctions = exports.missingEndpoint = exports.hasEndpoint = exports.regionalEndpoints = exports.matchingBackend = exports.someEndpoint = exports.allEndpoints = exports.checkAvailability = exports.existingBackend = exports.scheduleIdForFunction = exports.functionName = exports.isEmptyBackend = exports.of = exports.empty = exports.isTaskQueueTriggered = exports.isScheduleTriggered = exports.isEventTriggered = exports.isHttpsTriggered = exports.SCHEDULED_FUNCTION_LABEL = exports.MIN_MEMORY_FOR_CONCURRENCY = exports.DEFAULT_MEMORY = exports.memoryOptionDisplayName = exports.endpointTriggerType = void 0;
4
4
  const gcf = require("../../gcp/cloudfunctions");
5
5
  const gcfV2 = require("../../gcp/cloudfunctionsv2");
6
6
  const utils = require("../../utils");
@@ -36,6 +36,8 @@ function memoryOptionDisplayName(option) {
36
36
  }[option];
37
37
  }
38
38
  exports.memoryOptionDisplayName = memoryOptionDisplayName;
39
+ exports.DEFAULT_MEMORY = 256;
40
+ exports.MIN_MEMORY_FOR_CONCURRENCY = 2048;
39
41
  exports.SCHEDULED_FUNCTION_LABEL = Object.freeze({ deployment: "firebase-schedule" });
40
42
  function isHttpsTriggered(triggered) {
41
43
  return {}.hasOwnProperty.call(triggered, "httpsTrigger");
@@ -27,7 +27,7 @@ function hasDotenv(opts) {
27
27
  return previews_1.previews.dotenv && functionsEnv.hasUserEnvs(opts);
28
28
  }
29
29
  async function maybeEnableAR(projectId) {
30
- if (previews_1.previews.artifactregistry) {
30
+ if (!previews_1.previews.artifactregistry) {
31
31
  return ensureApiEnabled.check(projectId, "artifactregistry.googleapis.com", "functions", true);
32
32
  }
33
33
  await ensureApiEnabled.ensure(projectId, "artifactregistry.googleapis.com", "functions");
@@ -113,7 +113,7 @@ async function prepare(context, options, payload) {
113
113
  await Promise.all(Object.values(wantBackend.requiredAPIs).map((api) => {
114
114
  return ensureApiEnabled.ensure(projectId, api, "functions", false);
115
115
  }));
116
- validate.functionIdsAreValid(backend.allEndpoints(wantBackend));
116
+ validate.endpointsAreValid(wantBackend);
117
117
  context.filters = (0, functionsDeployHelper_1.getFilterGroups)(options);
118
118
  const matchingBackend = backend.matchingBackend(wantBackend, (endpoint) => {
119
119
  return (0, functionsDeployHelper_1.functionMatchesAnyGroup)(endpoint, context.filters);
@@ -242,7 +242,10 @@ class Fabricator {
242
242
  .catch(rethrowAs(endpoint, "set invoker"));
243
243
  }
244
244
  }
245
- await this.setConcurrency(endpoint, serviceName, endpoint.concurrency || DEFAULT_GCFV2_CONCURRENCY);
245
+ const mem = endpoint.availableMemoryMb || backend.DEFAULT_MEMORY;
246
+ if (mem >= backend.MIN_MEMORY_FOR_CONCURRENCY && endpoint.concurrency != 1) {
247
+ await this.setConcurrency(endpoint, serviceName, endpoint.concurrency || DEFAULT_GCFV2_CONCURRENCY);
248
+ }
246
249
  }
247
250
  async updateV1Function(endpoint, scraper) {
248
251
  var _a;
@@ -82,12 +82,13 @@ class Delegate {
82
82
  return Promise.resolve(() => Promise.resolve());
83
83
  }
84
84
  serve(port, adminPort, envs) {
85
+ var _a;
85
86
  const childProcess = spawn("go", ["run", "./autogen"], {
86
87
  env: Object.assign(Object.assign({}, envs), { PORT: port.toString(), ADMIN_PORT: adminPort.toString(), HOME: process.env.HOME, PATH: process.env.PATH, GOPATH: process.env.GOPATH }),
87
88
  cwd: this.sourceDir,
88
89
  stdio: ["ignore", "pipe", "inherit"],
89
90
  });
90
- childProcess.stdout.on("data", (chunk) => {
91
+ (_a = childProcess.stdout) === null || _a === void 0 ? void 0 : _a.on("data", (chunk) => {
91
92
  logger_1.logger.debug(chunk.toString());
92
93
  });
93
94
  return Promise.resolve(async () => {
@@ -1,10 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.functionIdsAreValid = exports.functionsDirectoryExists = void 0;
3
+ exports.functionIdsAreValid = exports.functionsDirectoryExists = exports.endpointsAreValid = void 0;
4
4
  const path = require("path");
5
5
  const clc = require("cli-color");
6
6
  const error_1 = require("../../error");
7
7
  const fsutils = require("../../fsutils");
8
+ const backend = require("./backend");
9
+ function endpointsAreValid(wantBackend) {
10
+ functionIdsAreValid(backend.allEndpoints(wantBackend));
11
+ const gcfV1WithConcurrency = backend
12
+ .allEndpoints(wantBackend)
13
+ .filter((endpoint) => (endpoint.concurrency || 1) != 1 && endpoint.platform == "gcfv1")
14
+ .map((endpoint) => endpoint.id);
15
+ if (gcfV1WithConcurrency.length) {
16
+ const msg = `Cannot set concurrency on the functions ${gcfV1WithConcurrency.join(",")} because they are GCF gen 1`;
17
+ throw new error_1.FirebaseError(msg);
18
+ }
19
+ const tooSmallForConcurrency = backend
20
+ .allEndpoints(wantBackend)
21
+ .filter((endpoint) => {
22
+ if ((endpoint.concurrency || 1) == 1) {
23
+ return false;
24
+ }
25
+ const mem = endpoint.availableMemoryMb || backend.DEFAULT_MEMORY;
26
+ return mem < backend.MIN_MEMORY_FOR_CONCURRENCY;
27
+ })
28
+ .map((endpoint) => endpoint.id);
29
+ if (tooSmallForConcurrency.length) {
30
+ const msg = `Cannot set concurency on the functions ${tooSmallForConcurrency.join(",")} because they have fewer than 2GB memory`;
31
+ throw new error_1.FirebaseError(msg);
32
+ }
33
+ }
34
+ exports.endpointsAreValid = endpointsAreValid;
8
35
  function functionsDirectoryExists(sourceDir, projectDir) {
9
36
  if (!fsutils.dirExistsSync(sourceDir)) {
10
37
  const sourceDirName = path.relative(projectDir, sourceDir);