firebase-tools 9.17.0 → 9.21.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.
Files changed (95) hide show
  1. package/CHANGELOG.md +3 -7
  2. package/lib/api.js +1 -0
  3. package/lib/apiv2.js +5 -3
  4. package/lib/appdistribution/client.js +84 -72
  5. package/lib/appdistribution/distribution.js +8 -26
  6. package/lib/appdistribution/options-parser-util.js +51 -0
  7. package/lib/command.js +1 -1
  8. package/lib/commands/appdistribution-distribute.js +74 -91
  9. package/lib/commands/appdistribution-testers-add.js +18 -0
  10. package/lib/commands/appdistribution-testers-remove.js +32 -0
  11. package/lib/commands/crashlytics-symbols-upload.js +146 -0
  12. package/lib/commands/ext-configure.js +9 -1
  13. package/lib/commands/ext-dev-extension-delete.js +2 -1
  14. package/lib/commands/ext-dev-publish.js +11 -4
  15. package/lib/commands/ext-dev-unpublish.js +12 -4
  16. package/lib/commands/ext-install.js +115 -48
  17. package/lib/commands/ext-uninstall.js +6 -0
  18. package/lib/commands/ext-update.js +61 -18
  19. package/lib/commands/functions-config-export.js +115 -0
  20. package/lib/commands/functions-delete.js +45 -25
  21. package/lib/commands/functions-list.js +54 -0
  22. package/lib/commands/functions-log.js +5 -22
  23. package/lib/commands/hosting-channel-deploy.js +6 -4
  24. package/lib/commands/index.js +12 -0
  25. package/lib/deploy/functions/backend.js +118 -121
  26. package/lib/deploy/functions/checkIam.js +8 -8
  27. package/lib/deploy/functions/containerCleaner.js +5 -1
  28. package/lib/deploy/functions/deploy.js +11 -15
  29. package/lib/deploy/functions/functionsDeployHelper.js +3 -68
  30. package/lib/deploy/functions/prepare.js +67 -33
  31. package/lib/deploy/functions/pricing.js +17 -17
  32. package/lib/deploy/functions/prompts.js +24 -41
  33. package/lib/deploy/functions/release/executor.js +39 -0
  34. package/lib/deploy/functions/release/fabricator.js +362 -0
  35. package/lib/deploy/functions/release/index.js +69 -0
  36. package/lib/deploy/functions/release/planner.js +159 -0
  37. package/lib/deploy/functions/release/reporter.js +162 -0
  38. package/lib/deploy/functions/release/sourceTokenScraper.js +28 -0
  39. package/lib/deploy/functions/release/timer.js +14 -0
  40. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +102 -126
  41. package/lib/deploy/functions/runtimes/node/parseTriggers.js +34 -50
  42. package/lib/deploy/functions/triggerRegionHelper.js +40 -0
  43. package/lib/deploy/functions/validate.js +1 -24
  44. package/lib/downloadUtils.js +37 -0
  45. package/lib/emulator/auth/apiSpec.js +1788 -403
  46. package/lib/emulator/auth/handlers.js +6 -5
  47. package/lib/emulator/auth/operations.js +439 -40
  48. package/lib/emulator/auth/server.js +32 -11
  49. package/lib/emulator/auth/state.js +205 -5
  50. package/lib/emulator/auth/widget_ui.js +2 -2
  51. package/lib/emulator/download.js +2 -31
  52. package/lib/emulator/downloadableEmulators.js +7 -7
  53. package/lib/emulator/emulatorLogger.js +0 -3
  54. package/lib/emulator/events/types.js +16 -0
  55. package/lib/emulator/functionsEmulator.js +117 -20
  56. package/lib/emulator/functionsEmulatorRuntime.js +46 -121
  57. package/lib/emulator/functionsEmulatorShared.js +51 -7
  58. package/lib/emulator/functionsEmulatorShell.js +1 -1
  59. package/lib/emulator/pubsubEmulator.js +61 -40
  60. package/lib/emulator/storage/cloudFunctions.js +37 -7
  61. package/lib/extensions/askUserForConsent.js +16 -13
  62. package/lib/extensions/askUserForParam.js +72 -3
  63. package/lib/extensions/billingMigrationHelper.js +1 -11
  64. package/lib/extensions/changelog.js +2 -1
  65. package/lib/extensions/displayExtensionInfo.js +35 -33
  66. package/lib/extensions/emulator/optionsHelper.js +3 -3
  67. package/lib/extensions/emulator/triggerHelper.js +2 -32
  68. package/lib/extensions/extensionsApi.js +67 -94
  69. package/lib/extensions/extensionsHelper.js +49 -35
  70. package/lib/extensions/paramHelper.js +79 -36
  71. package/lib/extensions/refs.js +59 -0
  72. package/lib/extensions/secretsUtils.js +58 -0
  73. package/lib/extensions/updateHelper.js +21 -45
  74. package/lib/extensions/warnings.js +1 -7
  75. package/lib/functional.js +64 -0
  76. package/lib/functions/env.js +26 -13
  77. package/lib/functions/functionslog.js +40 -0
  78. package/lib/functions/runtimeConfigExport.js +137 -0
  79. package/lib/gcp/cloudfunctions.js +46 -38
  80. package/lib/gcp/cloudfunctionsv2.js +47 -47
  81. package/lib/gcp/cloudlogging.js +27 -21
  82. package/lib/gcp/cloudscheduler.js +22 -16
  83. package/lib/gcp/pubsub.js +1 -9
  84. package/lib/gcp/secretManager.js +111 -0
  85. package/lib/gcp/storage.js +16 -0
  86. package/lib/previews.js +1 -1
  87. package/lib/requireInteractive.js +12 -0
  88. package/lib/utils.js +30 -1
  89. package/package.json +5 -4
  90. package/lib/deploy/functions/deploymentPlanner.js +0 -113
  91. package/lib/deploy/functions/deploymentTimer.js +0 -23
  92. package/lib/deploy/functions/errorHandler.js +0 -75
  93. package/lib/deploy/functions/release.js +0 -116
  94. package/lib/deploy/functions/tasks.js +0 -324
  95. package/lib/functionsDelete.js +0 -60
@@ -12,10 +12,12 @@ const billingMigrationHelper_1 = require("../extensions/billingMigrationHelper")
12
12
  const checkProjectBilling_1 = require("../extensions/checkProjectBilling");
13
13
  const cloudbilling_1 = require("../gcp/cloudbilling");
14
14
  const extensionsApi = require("../extensions/extensionsApi");
15
+ const secretsUtils = require("../extensions/secretsUtils");
15
16
  const provisioningHelper = require("../extensions/provisioningHelper");
16
17
  const extensionsHelper_1 = require("../extensions/extensionsHelper");
17
18
  const paramHelper = require("../extensions/paramHelper");
18
19
  const updateHelper_1 = require("../extensions/updateHelper");
20
+ const refs = require("../extensions/refs");
19
21
  const projectUtils_1 = require("../projectUtils");
20
22
  const requirePermissions_1 = require("../requirePermissions");
21
23
  const utils = require("../utils");
@@ -42,6 +44,8 @@ exports.default = new command_1.Command("ext:update <extensionInstanceId> [updat
42
44
  ])
43
45
  .before(extensionsHelper_1.ensureExtensionsApiEnabled)
44
46
  .before(checkMinRequiredVersion_1.checkMinRequiredVersion, "extMinVersion")
47
+ .withForce()
48
+ .option("--params <paramsFile>", "name of params variables file with .env format.")
45
49
  .action(async (instanceId, updateSource, options) => {
46
50
  const spinner = ora.default(`Updating ${clc.bold(instanceId)}. This usually takes 3 to 5 minutes...`);
47
51
  try {
@@ -56,12 +60,12 @@ exports.default = new command_1.Command("ext:update <extensionInstanceId> [updat
56
60
  }
57
61
  throw err;
58
62
  }
59
- const existingSpec = _.get(existingInstance, "config.source.spec");
63
+ const existingSpec = existingInstance.config.source.spec;
60
64
  if (existingInstance.config.source.state === "DELETED") {
61
65
  throw new error_1.FirebaseError(`Instance '${clc.bold(instanceId)}' cannot be updated anymore because the underlying extension was unpublished from Firebase's registry of extensions. Going forward, you will only be able to re-configure or uninstall this instance.`);
62
66
  }
63
- const existingParams = _.get(existingInstance, "config.params");
64
- const existingSource = _.get(existingInstance, "config.source.name");
67
+ const existingParams = existingInstance.config.params;
68
+ const existingSource = existingInstance.config.source.name;
65
69
  if (existingInstance.config.extensionRef) {
66
70
  updateSource = updateHelper_1.inferUpdateSource(updateSource, existingInstance.config.extensionRef);
67
71
  }
@@ -75,60 +79,99 @@ exports.default = new command_1.Command("ext:update <extensionInstanceId> [updat
75
79
  switch (newSourceOrigin) {
76
80
  case extensionsHelper_1.SourceOrigin.LOCAL:
77
81
  if (previews_1.previews.extdev) {
78
- newSourceName = await updateHelper_1.updateFromLocalSource(projectId, instanceId, updateSource, existingSpec, existingSource);
82
+ newSourceName = await updateHelper_1.updateFromLocalSource(projectId, instanceId, updateSource, existingSpec);
79
83
  break;
80
84
  }
81
85
  case extensionsHelper_1.SourceOrigin.URL:
82
86
  if (previews_1.previews.extdev) {
83
- newSourceName = await updateHelper_1.updateFromUrlSource(projectId, instanceId, updateSource, existingSpec, existingSource);
87
+ newSourceName = await updateHelper_1.updateFromUrlSource(projectId, instanceId, updateSource, existingSpec);
84
88
  break;
85
89
  }
86
90
  case extensionsHelper_1.SourceOrigin.PUBLISHED_EXTENSION_VERSION:
87
- newSourceName = await updateHelper_1.updateToVersionFromPublisherSource(projectId, instanceId, updateSource, existingSpec, existingSource);
91
+ newSourceName = await updateHelper_1.updateToVersionFromPublisherSource(projectId, instanceId, updateSource, existingSpec);
88
92
  break;
89
93
  case extensionsHelper_1.SourceOrigin.PUBLISHED_EXTENSION:
90
- newSourceName = await updateHelper_1.updateFromPublisherSource(projectId, instanceId, updateSource, existingSpec, existingSource);
94
+ newSourceName = await updateHelper_1.updateFromPublisherSource(projectId, instanceId, updateSource, existingSpec);
91
95
  break;
92
96
  default:
93
97
  throw new error_1.FirebaseError(`Unknown source '${clc.bold(updateSource)}.'`);
94
98
  }
99
+ if (!(await extensionsHelper_1.confirm({
100
+ nonInteractive: options.nonInteractive,
101
+ force: options.force,
102
+ default: true,
103
+ }))) {
104
+ throw new error_1.FirebaseError(`Update cancelled.`);
105
+ }
95
106
  const newSource = await extensionsApi.getSource(newSourceName);
96
107
  const newSpec = newSource.spec;
97
108
  if (![extensionsHelper_1.SourceOrigin.LOCAL, extensionsHelper_1.SourceOrigin.URL].includes(newSourceOrigin) &&
98
109
  existingSpec.version === newSpec.version) {
99
110
  utils.logLabeledBullet(extensionsHelper_1.logPrefix, `${clc.bold(instanceId)} is already up to date. Its version is ${clc.bold(existingSpec.version)}.`);
100
- const retry = await updateHelper_1.retryUpdate();
111
+ const retry = await extensionsHelper_1.confirm({
112
+ nonInteractive: options.nonInteractive,
113
+ force: options.force,
114
+ default: false,
115
+ });
101
116
  if (!retry) {
102
117
  utils.logLabeledBullet(extensionsHelper_1.logPrefix, "Update aborted.");
103
118
  return;
104
119
  }
105
120
  }
106
- await updateHelper_1.displayChanges(existingSpec, newSpec);
121
+ await updateHelper_1.displayChanges({
122
+ spec: existingSpec,
123
+ newSpec: newSpec,
124
+ nonInteractive: options.nonInteractive,
125
+ force: options.force,
126
+ });
107
127
  await provisioningHelper.checkProductsProvisioned(projectId, newSpec);
108
- if (newSpec.billingRequired) {
128
+ const usesSecrets = secretsUtils.usesSecrets(newSpec);
129
+ if (newSpec.billingRequired || usesSecrets) {
109
130
  const enabled = await cloudbilling_1.checkBillingEnabled(projectId);
131
+ billingMigrationHelper_1.displayNode10UpdateBillingNotice(existingSpec, newSpec);
132
+ if (!(await extensionsHelper_1.confirm({
133
+ nonInteractive: options.nonInteractive,
134
+ force: options.force,
135
+ default: true,
136
+ }))) {
137
+ throw new error_1.FirebaseError("Update cancelled.");
138
+ }
110
139
  if (!enabled) {
111
- await billingMigrationHelper_1.displayNode10UpdateBillingNotice(existingSpec, newSpec, false);
112
- await checkProjectBilling_1.enableBilling(projectId, instanceId);
140
+ if (!options.nonInteractive) {
141
+ await checkProjectBilling_1.enableBilling(projectId, instanceId);
142
+ }
143
+ else {
144
+ throw new error_1.FirebaseError("The extension requires your project to be upgraded to the Blaze plan. " +
145
+ "To run this command in non-interactive mode, first upgrade your project: " +
146
+ marked(`https://console.cloud.google.com/billing/linkedaccount?project=${projectId}`));
147
+ }
113
148
  }
114
- else {
115
- await billingMigrationHelper_1.displayNode10UpdateBillingNotice(existingSpec, newSpec, true);
149
+ if (usesSecrets) {
150
+ await secretsUtils.ensureSecretManagerApiEnabled(options);
116
151
  }
117
152
  }
118
- const newParams = await paramHelper.promptForNewParams(existingSpec, newSpec, existingParams, projectId);
153
+ const oldParamValues = Object.assign({}, existingParams);
154
+ const newParams = await paramHelper.getParamsForUpdate({
155
+ spec: existingSpec,
156
+ newSpec,
157
+ currentParams: existingParams,
158
+ projectId,
159
+ paramsEnvPath: options.params,
160
+ nonInteractive: options.nonInteractive,
161
+ instanceId,
162
+ });
119
163
  spinner.start();
120
164
  const updateOptions = {
121
165
  projectId,
122
166
  instanceId,
123
167
  };
124
168
  if (newSourceName.includes("publisher")) {
125
- const { publisherId, extensionId, version } = extensionsApi.parseExtensionVersionName(newSourceName);
126
- updateOptions.extRef = `${publisherId}/${extensionId}@${version}`;
169
+ updateOptions.extRef = refs.toExtensionVersionRef(refs.parse(newSourceName));
127
170
  }
128
171
  else {
129
172
  updateOptions.source = newSource;
130
173
  }
131
- if (!_.isEqual(newParams, existingParams)) {
174
+ if (!_.isEqual(newParams, oldParamValues)) {
132
175
  updateOptions.params = newParams;
133
176
  }
134
177
  await updateHelper_1.update(updateOptions);
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path = require("path");
4
+ const clc = require("cli-color");
5
+ const requireInteractive_1 = require("../requireInteractive");
6
+ const command_1 = require("../command");
7
+ const error_1 = require("../error");
8
+ const iam_1 = require("../gcp/iam");
9
+ const logger_1 = require("../logger");
10
+ const prompt_1 = require("../prompt");
11
+ const requirePermissions_1 = require("../requirePermissions");
12
+ const utils_1 = require("../utils");
13
+ const functional_1 = require("../functional");
14
+ const configExport = require("../functions/runtimeConfigExport");
15
+ const requireConfig = require("../requireConfig");
16
+ const REQUIRED_PERMISSIONS = [
17
+ "runtimeconfig.configs.list",
18
+ "runtimeconfig.configs.get",
19
+ "runtimeconfig.variables.list",
20
+ "runtimeconfig.variables.get",
21
+ ];
22
+ const RESERVED_PROJECT_ALIAS = ["local"];
23
+ const MAX_ATTEMPTS = 3;
24
+ function checkReservedAliases(pInfos) {
25
+ for (const pInfo of pInfos) {
26
+ if (pInfo.alias && RESERVED_PROJECT_ALIAS.includes(pInfo.alias)) {
27
+ utils_1.logWarning(`Project alias (${clc.bold(pInfo.alias)}) is reserved for internal use. ` +
28
+ `Saving exported config in .env.${pInfo.projectId} instead.`);
29
+ delete pInfo.alias;
30
+ }
31
+ }
32
+ }
33
+ async function checkRequiredPermission(pInfos) {
34
+ pInfos = pInfos.filter((pInfo) => !pInfo.config);
35
+ const testPermissions = pInfos.map((pInfo) => iam_1.testIamPermissions(pInfo.projectId, REQUIRED_PERMISSIONS));
36
+ const results = await Promise.all(testPermissions);
37
+ for (const [pInfo, result] of functional_1.zip(pInfos, results)) {
38
+ if (result.passed) {
39
+ throw new error_1.FirebaseError(`Unexpectedly failed to fetch runtime config for project ${pInfo.projectId}`);
40
+ }
41
+ utils_1.logWarning("You are missing the following permissions to read functions config on project " +
42
+ `${clc.bold(pInfo.projectId)}:\n\t${result.missing.join("\n\t")}`);
43
+ const confirm = await prompt_1.promptOnce({
44
+ type: "confirm",
45
+ name: "skip",
46
+ default: true,
47
+ message: `Continue without importing configs from project ${pInfo.projectId}?`,
48
+ });
49
+ if (!confirm) {
50
+ throw new error_1.FirebaseError("Command aborted!");
51
+ }
52
+ }
53
+ }
54
+ async function promptForPrefix(errMsg) {
55
+ utils_1.logWarning("The following configs keys could not be exported as environment variables:\n");
56
+ utils_1.logWarning(errMsg);
57
+ return await prompt_1.promptOnce({
58
+ type: "input",
59
+ name: "prefix",
60
+ default: "CONFIG_",
61
+ message: "Enter a PREFIX to rename invalid environment variable keys:",
62
+ }, {});
63
+ }
64
+ function fromEntries(itr) {
65
+ const obj = {};
66
+ for (const [k, v] of itr) {
67
+ obj[k] = v;
68
+ }
69
+ return obj;
70
+ }
71
+ exports.default = new command_1.Command("functions:config:export")
72
+ .description("Export environment config as environment variables in dotenv format")
73
+ .before(requirePermissions_1.requirePermissions, [
74
+ "runtimeconfig.configs.list",
75
+ "runtimeconfig.configs.get",
76
+ "runtimeconfig.variables.list",
77
+ "runtimeconfig.variables.get",
78
+ ])
79
+ .before(requireConfig)
80
+ .before(requireInteractive_1.default)
81
+ .action(async (options) => {
82
+ let pInfos = configExport.getProjectInfos(options);
83
+ checkReservedAliases(pInfos);
84
+ utils_1.logBullet("Importing functions configs from projects [" +
85
+ pInfos.map(({ projectId }) => `${clc.bold(projectId)}`).join(", ") +
86
+ "]");
87
+ await configExport.hydrateConfigs(pInfos);
88
+ await checkRequiredPermission(pInfos);
89
+ pInfos = pInfos.filter((pInfo) => pInfo.config);
90
+ logger_1.logger.debug(`Loaded function configs: ${JSON.stringify(pInfos)}`);
91
+ utils_1.logBullet(`Importing configs from projects: [${pInfos.map((p) => p.projectId).join(", ")}]`);
92
+ let attempts = 0;
93
+ let prefix = "";
94
+ while (true) {
95
+ if (attempts >= MAX_ATTEMPTS) {
96
+ throw new error_1.FirebaseError("Exceeded max attempts to fix invalid config keys.");
97
+ }
98
+ const errMsg = configExport.hydrateEnvs(pInfos, prefix);
99
+ if (errMsg.length == 0) {
100
+ break;
101
+ }
102
+ prefix = await promptForPrefix(errMsg);
103
+ attempts += 1;
104
+ }
105
+ const header = `# Exported firebase functions:config:export command on ${new Date().toLocaleDateString()}`;
106
+ const dotEnvs = pInfos.map((pInfo) => configExport.toDotenvFormat(pInfo.envs, header));
107
+ const filenames = pInfos.map(configExport.generateDotenvFilename);
108
+ const filesToWrite = fromEntries(functional_1.zip(filenames, dotEnvs));
109
+ filesToWrite[".env.local"] = `${header}\n# .env.local file contains environment variables for the Functions Emulator.\n`;
110
+ filesToWrite[".env"] = `${header}# .env file contains environment variables that applies to all projects.\n`;
111
+ const functionsDir = options.config.get("functions.source", ".");
112
+ for (const [filename, content] of Object.entries(filesToWrite)) {
113
+ await options.config.askWriteProjectFile(path.join(functionsDir, filename), content);
114
+ }
115
+ });
@@ -1,15 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("../command");
4
3
  const clc = require("cli-color");
5
4
  const functionsConfig = require("../functionsConfig");
6
- const functionsDelete_1 = require("../functionsDelete");
5
+ const command_1 = require("../command");
6
+ const error_1 = require("../error");
7
7
  const projectUtils_1 = require("../projectUtils");
8
8
  const prompt_1 = require("../prompt");
9
- const helper = require("../deploy/functions/functionsDeployHelper");
9
+ const functional_1 = require("../functional");
10
10
  const requirePermissions_1 = require("../requirePermissions");
11
+ const helper = require("../deploy/functions/functionsDeployHelper");
11
12
  const utils = require("../utils");
12
13
  const backend = require("../deploy/functions/backend");
14
+ const planner = require("../deploy/functions/release/planner");
15
+ const fabricator = require("../deploy/functions/release/fabricator");
16
+ const executor = require("../deploy/functions/release/executor");
17
+ const reporter = require("../deploy/functions/release/reporter");
13
18
  exports.default = new command_1.Command("functions:delete [filters...]")
14
19
  .description("delete one or more Cloud Functions by name or group name.")
15
20
  .option("--region <region>", "Specify region of the function to be deleted. " +
@@ -22,35 +27,29 @@ exports.default = new command_1.Command("functions:delete [filters...]")
22
27
  }
23
28
  const context = {
24
29
  projectId: projectUtils_1.needProjectId(options),
30
+ filters: filters.map((f) => f.split(".")),
25
31
  };
26
- const filterChunks = filters.map((filter) => {
27
- return filter.split(".");
28
- });
29
32
  const [config, existingBackend] = await Promise.all([
30
33
  functionsConfig.getFirebaseConfig(options),
31
34
  backend.existingBackend(context),
32
35
  ]);
33
36
  await backend.checkAvailability(context, backend.empty());
34
37
  const appEngineLocation = functionsConfig.getAppEngineLocation(config);
35
- const functionsToDelete = existingBackend.cloudFunctions.filter((fn) => {
36
- const regionMatches = options.region ? fn.region === options.region : true;
37
- const nameMatches = helper.functionMatchesAnyGroup(fn, filterChunks);
38
- return regionMatches && nameMatches;
39
- });
40
- if (functionsToDelete.length === 0) {
41
- return utils.reject(`The specified filters do not match any existing functions in project ${clc.bold(context.projectId)}.`, { exit: 1 });
38
+ if (options.region) {
39
+ existingBackend.endpoints = { [options.region]: existingBackend.endpoints[options.region] };
42
40
  }
43
- const schedulesToDelete = existingBackend.schedules.filter((schedule) => {
44
- functionsToDelete.some(backend.sameFunctionName(schedule.targetService));
41
+ const plan = planner.createDeploymentPlan(backend.empty(), existingBackend, {
42
+ filters: context.filters,
43
+ deleteAll: true,
45
44
  });
46
- const topicsToDelete = existingBackend.topics.filter((topic) => {
47
- functionsToDelete.some(backend.sameFunctionName(topic.targetService));
48
- });
49
- const deleteList = functionsToDelete
50
- .map((func) => {
51
- return "\t" + helper.getFunctionLabel(func);
52
- })
53
- .join("\n");
45
+ const allEpToDelete = Object.values(plan)
46
+ .map((changes) => changes.endpointsToDelete)
47
+ .reduce(functional_1.reduceFlat, [])
48
+ .sort(backend.compareFunctions);
49
+ if (allEpToDelete.length === 0) {
50
+ throw new error_1.FirebaseError(`The specified filters do not match any existing functions in project ${clc.bold(context.projectId)}.`);
51
+ }
52
+ const deleteList = allEpToDelete.map((func) => `\t${helper.getFunctionLabel(func)}`).join("\n");
54
53
  const confirmDeletion = await prompt_1.promptOnce({
55
54
  type: "confirm",
56
55
  name: "force",
@@ -60,7 +59,28 @@ exports.default = new command_1.Command("functions:delete [filters...]")
60
59
  "\n Are you sure?",
61
60
  }, options);
62
61
  if (!confirmDeletion) {
63
- return utils.reject("Command aborted.", { exit: 1 });
62
+ throw new error_1.FirebaseError("Command aborted.");
63
+ }
64
+ const functionExecutor = new executor.QueueExecutor({
65
+ retries: 30,
66
+ backoff: 20000,
67
+ concurrency: 40,
68
+ maxBackoff: 40000,
69
+ });
70
+ try {
71
+ const fab = new fabricator.Fabricator({
72
+ functionExecutor,
73
+ executor: new executor.QueueExecutor({}),
74
+ appEngineLocation,
75
+ });
76
+ const summary = await fab.applyPlan(plan);
77
+ await reporter.logAndTrackDeployStats(summary);
78
+ reporter.printErrors(summary);
79
+ }
80
+ catch (err) {
81
+ throw new error_1.FirebaseError("Failed to delete functions", {
82
+ original: err,
83
+ exit: 1,
84
+ });
64
85
  }
65
- return await functionsDelete_1.deleteFunctions(functionsToDelete, schedulesToDelete, topicsToDelete, appEngineLocation);
66
86
  });
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("../command");
4
+ const error_1 = require("../error");
5
+ const projectUtils_1 = require("../projectUtils");
6
+ const requirePermissions_1 = require("../requirePermissions");
7
+ const backend = require("../deploy/functions/backend");
8
+ const previews_1 = require("../previews");
9
+ const logger_1 = require("../logger");
10
+ const Table = require("cli-table");
11
+ exports.default = new command_1.Command("functions:list")
12
+ .description("list all deployed functions in your Firebase project")
13
+ .before(requirePermissions_1.requirePermissions, ["cloudfunctions.functions.list"])
14
+ .action(async (options) => {
15
+ try {
16
+ const context = {
17
+ projectId: projectUtils_1.needProjectId(options),
18
+ };
19
+ const existing = await backend.existingBackend(context);
20
+ const endpointsList = backend.allEndpoints(existing).sort(backend.compareFunctions);
21
+ const table = previews_1.previews.functionsv2
22
+ ? new Table({
23
+ head: ["Function", "Version", "Trigger", "Location", "Memory", "Runtime"],
24
+ style: { head: ["yellow"] },
25
+ })
26
+ : new Table({
27
+ head: ["Function", "Trigger", "Location", "Memory", "Runtime"],
28
+ style: { head: ["yellow"] },
29
+ });
30
+ for (const endpoint of endpointsList) {
31
+ const trigger = backend.endpointTriggerType(endpoint);
32
+ const availableMemoryMb = endpoint.availableMemoryMb || "---";
33
+ const entry = previews_1.previews.functionsv2
34
+ ? [
35
+ endpoint.id,
36
+ endpoint.platform === "gcfv2" ? "v2" : "v1",
37
+ trigger,
38
+ endpoint.region,
39
+ availableMemoryMb,
40
+ endpoint.runtime,
41
+ ]
42
+ : [endpoint.id, trigger, endpoint.region, availableMemoryMb, endpoint.runtime];
43
+ table.push(entry);
44
+ }
45
+ logger_1.logger.info(table.toString());
46
+ return endpointsList;
47
+ }
48
+ catch (err) {
49
+ throw new error_1.FirebaseError("Failed to list functions", {
50
+ exit: 1,
51
+ original: err,
52
+ });
53
+ }
54
+ });
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const _ = require("lodash");
4
3
  const opn = require("open");
5
4
  const qs = require("querystring");
6
5
  const command_1 = require("../command");
7
6
  const error_1 = require("../error");
8
- const gcp = require("../gcp");
7
+ const cloudlogging = require("../gcp/cloudlogging");
8
+ const functionsLog = require("../functions/functionslog");
9
9
  const projectUtils_1 = require("../projectUtils");
10
- const logger_1 = require("../logger");
11
10
  const requirePermissions_1 = require("../requirePermissions");
12
11
  module.exports = new command_1.Command("functions:log")
13
12
  .description("read logs from deployed functions")
@@ -18,30 +17,14 @@ module.exports = new command_1.Command("functions:log")
18
17
  .action(async (options) => {
19
18
  try {
20
19
  const projectId = projectUtils_1.needProjectId(options);
21
- let apiFilter = `resource.type="cloud_function"`;
22
- if (options.only) {
23
- const funcNames = options.only.split(",");
24
- const apiFuncFilters = _.map(funcNames, (funcName) => {
25
- return `resource.labels.function_name="${funcName}"`;
26
- });
27
- apiFilter += `\n(${apiFuncFilters.join(" OR ")})`;
28
- }
20
+ const apiFilter = functionsLog.getApiFilter(options.only);
29
21
  if (options.open) {
30
22
  const url = `https://console.developers.google.com/logs/viewer?advancedFilter=${qs.escape(apiFilter)}&project=${projectId}`;
31
23
  opn(url);
32
24
  return;
33
25
  }
34
- const entries = await gcp.cloudlogging.listEntries(projectId, apiFilter, options.lines || 35, "desc");
35
- for (let i = _.size(entries) - 1; i >= 0; i--) {
36
- const entry = entries[i];
37
- logger_1.logger.info(entry.timestamp, _.get(entry, "severity", "?").substring(0, 1), _.get(entry, "resource.labels.function_name") + ":", entry.textPayload ||
38
- JSON.stringify(entry.jsonPayload) ||
39
- JSON.stringify(entry.protoPayload) ||
40
- "");
41
- }
42
- if (_.isEmpty(entries)) {
43
- logger_1.logger.info("No log entries found.");
44
- }
26
+ const entries = await cloudlogging.listEntries(projectId, apiFilter, options.lines || 35, "desc");
27
+ functionsLog.logEntries(entries);
45
28
  return entries;
46
29
  }
47
30
  catch (err) {
@@ -29,9 +29,6 @@ exports.default = new command_1.Command("hosting:channel:deploy [channelId]")
29
29
  if (options.open) {
30
30
  throw new error_1.FirebaseError("open is not yet implemented");
31
31
  }
32
- if (options["no-authorized-domains"]) {
33
- throw new error_1.FirebaseError("no-authorized-domains is not yet implemented");
34
- }
35
32
  let expireTTL = expireUtils_1.DEFAULT_DURATION;
36
33
  if (options.expires) {
37
34
  expireTTL = expireUtils_1.calculateChannelExpireTTL(options.expires);
@@ -95,8 +92,13 @@ exports.default = new command_1.Command("hosting:channel:deploy [channelId]")
95
92
  versionNames.push(version);
96
93
  });
97
94
  }
95
+ if (options.authorizedDomains) {
96
+ await syncAuthState(projectId, sites);
97
+ }
98
+ else {
99
+ logger_1.logger.debug(`skipping syncAuthState since authorizedDomains is ${options.authorizedDomains}`);
100
+ }
98
101
  logger_1.logger.info();
99
- await syncAuthState(projectId, sites);
100
102
  const deploys = {};
101
103
  sites.forEach((d) => {
102
104
  deploys[d.target || d.site] = d;
@@ -11,6 +11,9 @@ module.exports = function (client) {
11
11
  };
12
12
  client.appdistribution = {};
13
13
  client.appdistribution.distribute = loadCommand("appdistribution-distribute");
14
+ client.appdistribution.testers = {};
15
+ client.appdistribution.testers.add = loadCommand("appdistribution-testers-add");
16
+ client.appdistribution.testers.delete = loadCommand("appdistribution-testers-remove");
14
17
  client.apps = {};
15
18
  client.apps.create = loadCommand("apps-create");
16
19
  client.apps.list = loadCommand("apps-list");
@@ -23,6 +26,11 @@ module.exports = function (client) {
23
26
  client.auth = {};
24
27
  client.auth.export = loadCommand("auth-export");
25
28
  client.auth.upload = loadCommand("auth-import");
29
+ if (previews.crashlyticsSymbolsUpload) {
30
+ client.crashlytics = {};
31
+ client.crashlytics.symbols = {};
32
+ client.crashlytics.symbols.upload = loadCommand("crashlytics-symbols-upload");
33
+ }
26
34
  client.database = {};
27
35
  client.database.get = loadCommand("database-get");
28
36
  client.database.instances = {};
@@ -81,12 +89,16 @@ module.exports = function (client) {
81
89
  client.functions = {};
82
90
  client.functions.config = {};
83
91
  client.functions.config.clone = loadCommand("functions-config-clone");
92
+ if (previews.dotenv) {
93
+ client.functions.config.export = loadCommand("functions-config-export");
94
+ }
84
95
  client.functions.config.get = loadCommand("functions-config-get");
85
96
  client.functions.config.set = loadCommand("functions-config-set");
86
97
  client.functions.config.unset = loadCommand("functions-config-unset");
87
98
  client.functions.delete = loadCommand("functions-delete");
88
99
  client.functions.log = loadCommand("functions-log");
89
100
  client.functions.shell = loadCommand("functions-shell");
101
+ client.functions.list = loadCommand("functions-list");
90
102
  if (previews.deletegcfartifacts) {
91
103
  client.functions.deletegcfartifacts = loadCommand("functions-deletegcfartifacts");
92
104
  }