firebase-tools 11.4.1 → 11.6.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 (203) hide show
  1. package/lib/accountImporter.js +1 -1
  2. package/lib/auth.js +3 -4
  3. package/lib/bin/firebase.js +4 -4
  4. package/lib/command.js +35 -10
  5. package/lib/commands/apps-android-sha-create.js +1 -1
  6. package/lib/commands/apps-android-sha-delete.js +1 -1
  7. package/lib/commands/apps-create.js +1 -1
  8. package/lib/commands/apps-list.js +1 -1
  9. package/lib/commands/auth-export.js +1 -1
  10. package/lib/commands/auth-import.js +1 -1
  11. package/lib/commands/database-instances-list.js +1 -1
  12. package/lib/commands/database-push.js +1 -1
  13. package/lib/commands/database-remove.js +1 -1
  14. package/lib/commands/database-set.js +1 -1
  15. package/lib/commands/database-update.js +1 -1
  16. package/lib/commands/emulators-exec.js +4 -1
  17. package/lib/commands/emulators-export.js +5 -2
  18. package/lib/commands/emulators-start.js +24 -18
  19. package/lib/commands/ext-dev-deprecate.js +1 -1
  20. package/lib/commands/ext-dev-emulators-exec.js +1 -1
  21. package/lib/commands/ext-dev-emulators-start.js +1 -1
  22. package/lib/commands/ext-dev-extension-delete.js +1 -1
  23. package/lib/commands/ext-dev-list.js +1 -1
  24. package/lib/commands/ext-dev-publish.js +4 -1
  25. package/lib/commands/ext-dev-register.js +1 -1
  26. package/lib/commands/ext-dev-undeprecate.js +1 -1
  27. package/lib/commands/ext-dev-unpublish.js +1 -1
  28. package/lib/commands/ext-dev-usage.js +1 -1
  29. package/lib/commands/ext-info.js +1 -1
  30. package/lib/commands/ext-install.js +2 -2
  31. package/lib/commands/ext-update.js +1 -1
  32. package/lib/commands/ext.js +1 -1
  33. package/lib/commands/firestore-delete.js +2 -2
  34. package/lib/commands/firestore-indexes-list.js +3 -3
  35. package/lib/commands/functions-config-clone.js +1 -1
  36. package/lib/commands/functions-config-export.js +1 -1
  37. package/lib/commands/functions-config-set.js +1 -1
  38. package/lib/commands/functions-config-unset.js +1 -1
  39. package/lib/commands/functions-delete.js +1 -1
  40. package/lib/commands/functions-secrets-set.js +1 -1
  41. package/lib/commands/help.js +1 -1
  42. package/lib/commands/hosting-channel-create.js +5 -5
  43. package/lib/commands/hosting-channel-delete.js +3 -3
  44. package/lib/commands/hosting-channel-deploy.js +6 -6
  45. package/lib/commands/hosting-channel-list.js +2 -2
  46. package/lib/commands/hosting-channel-open.js +2 -2
  47. package/lib/commands/hosting-clone.js +8 -8
  48. package/lib/commands/hosting-disable.js +1 -1
  49. package/lib/commands/hosting-sites-create.js +4 -4
  50. package/lib/commands/hosting-sites-delete.js +4 -4
  51. package/lib/commands/hosting-sites-list.js +2 -2
  52. package/lib/commands/init.js +5 -5
  53. package/lib/commands/login-add.js +1 -1
  54. package/lib/commands/login-ci.js +2 -2
  55. package/lib/commands/login-list.js +1 -1
  56. package/lib/commands/login-use.js +1 -1
  57. package/lib/commands/login.js +3 -3
  58. package/lib/commands/logout.js +1 -1
  59. package/lib/commands/open.js +3 -3
  60. package/lib/commands/projects-list.js +2 -2
  61. package/lib/commands/serve.js +1 -1
  62. package/lib/commands/target-apply.js +1 -1
  63. package/lib/commands/target-clear.js +1 -1
  64. package/lib/commands/target-remove.js +1 -1
  65. package/lib/commands/target.js +1 -1
  66. package/lib/commands/use.js +7 -7
  67. package/lib/config.js +1 -1
  68. package/lib/deploy/database/prepare.js +3 -3
  69. package/lib/deploy/database/release.js +3 -3
  70. package/lib/deploy/extensions/deploymentSummary.js +1 -1
  71. package/lib/deploy/extensions/errors.js +1 -1
  72. package/lib/deploy/extensions/secrets.js +1 -1
  73. package/lib/deploy/extensions/tasks.js +2 -2
  74. package/lib/deploy/firestore/deploy.js +2 -2
  75. package/lib/deploy/firestore/prepare.js +2 -2
  76. package/lib/deploy/functions/backend.js +7 -5
  77. package/lib/deploy/functions/build.js +110 -95
  78. package/lib/deploy/functions/checkIam.js +3 -3
  79. package/lib/deploy/functions/containerCleaner.js +2 -2
  80. package/lib/deploy/functions/deploy.js +2 -2
  81. package/lib/deploy/functions/ensure.js +2 -2
  82. package/lib/deploy/functions/params.js +5 -2
  83. package/lib/deploy/functions/prepare.js +4 -4
  84. package/lib/deploy/functions/prepareFunctionsUpload.js +2 -2
  85. package/lib/deploy/functions/pricing.js +3 -2
  86. package/lib/deploy/functions/prompts.js +2 -2
  87. package/lib/deploy/functions/release/fabricator.js +10 -9
  88. package/lib/deploy/functions/release/index.js +1 -1
  89. package/lib/deploy/functions/release/reporter.js +1 -1
  90. package/lib/deploy/functions/runtimes/discovery/parsing.js +19 -8
  91. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +112 -107
  92. package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +1 -1
  93. package/lib/deploy/functions/runtimes/node/parseTriggers.js +54 -26
  94. package/lib/deploy/functions/runtimes/node/versioning.js +4 -4
  95. package/lib/deploy/functions/services/storage.js +6 -0
  96. package/lib/deploy/functions/validate.js +1 -1
  97. package/lib/deploy/hosting/convertConfig.js +8 -1
  98. package/lib/deploy/hosting/deploy.js +10 -9
  99. package/lib/deploy/hosting/uploader.js +2 -2
  100. package/lib/deploy/hosting/validate.js +2 -2
  101. package/lib/deploy/index.js +7 -7
  102. package/lib/deploy/lifecycleHooks.js +5 -2
  103. package/lib/deploy/storage/prepare.js +5 -3
  104. package/lib/deploy/storage/release.js +7 -6
  105. package/lib/emulator/auth/index.js +7 -2
  106. package/lib/emulator/auth/operations.js +10 -10
  107. package/lib/emulator/commandUtils.js +33 -16
  108. package/lib/emulator/constants.js +14 -6
  109. package/lib/emulator/controller.js +55 -18
  110. package/lib/emulator/databaseEmulator.js +1 -1
  111. package/lib/emulator/downloadableEmulators.js +8 -8
  112. package/lib/emulator/emulatorLogger.js +1 -1
  113. package/lib/emulator/eventarcEmulator.js +148 -0
  114. package/lib/emulator/extensionsEmulator.js +5 -3
  115. package/lib/emulator/firestoreEmulator.js +1 -1
  116. package/lib/emulator/functionsEmulator.js +66 -14
  117. package/lib/emulator/functionsEmulatorShared.js +12 -12
  118. package/lib/emulator/hub.js +7 -3
  119. package/lib/emulator/hubClient.js +2 -2
  120. package/lib/emulator/hubExport.js +22 -2
  121. package/lib/emulator/loggingEmulator.js +2 -2
  122. package/lib/emulator/registry.js +1 -0
  123. package/lib/emulator/storage/apis/firebase.js +13 -1
  124. package/lib/emulator/storage/apis/gcloud.js +15 -8
  125. package/lib/emulator/storage/files.js +25 -4
  126. package/lib/emulator/storage/metadata.js +6 -6
  127. package/lib/emulator/storage/multipart.js +4 -3
  128. package/lib/emulator/storage/rules/runtime.js +3 -3
  129. package/lib/emulator/storage/rules/utils.js +4 -2
  130. package/lib/emulator/storage/server.js +2 -1
  131. package/lib/emulator/storage/upload.js +1 -0
  132. package/lib/emulator/types.js +4 -0
  133. package/lib/emulator/ui.js +7 -2
  134. package/lib/ensureApiEnabled.js +7 -7
  135. package/lib/extensions/askUserForConsent.js +1 -1
  136. package/lib/extensions/askUserForEventsConfig.js +1 -1
  137. package/lib/extensions/askUserForParam.js +1 -1
  138. package/lib/extensions/changelog.js +2 -2
  139. package/lib/extensions/checkProjectBilling.js +2 -2
  140. package/lib/extensions/displayExtensionInfo.js +2 -102
  141. package/lib/extensions/emulator/triggerHelper.js +2 -2
  142. package/lib/extensions/extensionsApi.js +3 -2
  143. package/lib/extensions/extensionsHelper.js +30 -2
  144. package/lib/extensions/listExtensions.js +1 -1
  145. package/lib/extensions/manifest.js +1 -1
  146. package/lib/extensions/metricsUtils.js +1 -1
  147. package/lib/extensions/paramHelper.js +1 -1
  148. package/lib/extensions/updateHelper.js +3 -9
  149. package/lib/extensions/warnings.js +2 -2
  150. package/lib/fetchMOTD.js +1 -1
  151. package/lib/firestore/delete.js +1 -1
  152. package/lib/firestore/indexes.js +2 -2
  153. package/lib/firestore/validator.js +1 -1
  154. package/lib/functional.js +16 -1
  155. package/lib/functions/env.js +3 -3
  156. package/lib/functions/runtimeConfigExport.js +1 -1
  157. package/lib/functionsConfig.js +1 -1
  158. package/lib/functionsConfigClone.js +1 -1
  159. package/lib/functionsShellCommandAction.js +1 -1
  160. package/lib/gcp/cloudfunctions.js +24 -11
  161. package/lib/gcp/cloudfunctionsv2.js +48 -24
  162. package/lib/gcp/cloudscheduler.js +58 -22
  163. package/lib/gcp/cloudtasks.js +21 -4
  164. package/lib/gcp/proto.js +18 -6
  165. package/lib/gcp/resourceManager.js +25 -3
  166. package/lib/gcp/serviceusage.js +2 -2
  167. package/lib/handlePreviewToggles.js +4 -4
  168. package/lib/hosting/implicitInit.js +1 -1
  169. package/lib/hosting/normalizedHostingConfigs.js +3 -3
  170. package/lib/index.js +2 -2
  171. package/lib/init/features/database.js +1 -1
  172. package/lib/init/features/emulators.js +1 -1
  173. package/lib/init/features/firestore/index.js +2 -2
  174. package/lib/init/features/firestore/indexes.js +1 -1
  175. package/lib/init/features/firestore/rules.js +1 -1
  176. package/lib/init/features/functions/golang.js +1 -1
  177. package/lib/init/features/functions/index.js +8 -1
  178. package/lib/init/features/hosting/github.js +9 -9
  179. package/lib/init/features/hosting/index.js +1 -1
  180. package/lib/init/features/project.js +1 -1
  181. package/lib/init/features/remoteconfig.js +1 -1
  182. package/lib/init/features/storage.js +1 -1
  183. package/lib/init/index.js +1 -1
  184. package/lib/logError.js +3 -3
  185. package/lib/management/projects.js +1 -1
  186. package/lib/parseBoltRules.js +1 -1
  187. package/lib/previews.js +1 -1
  188. package/lib/profileReport.js +2 -2
  189. package/lib/projectUtils.js +1 -1
  190. package/lib/rc.js +1 -1
  191. package/lib/requireAuth.js +1 -1
  192. package/lib/requireDatabaseInstance.js +2 -2
  193. package/lib/requirePermissions.js +2 -2
  194. package/lib/rulesDeploy.js +49 -13
  195. package/lib/serve/hosting.js +2 -1
  196. package/lib/serve/index.js +15 -0
  197. package/lib/track.js +119 -3
  198. package/lib/utils.js +24 -11
  199. package/npm-shrinkwrap.json +14 -294
  200. package/package.json +5 -4
  201. package/schema/firebase-config.json +12 -0
  202. package/templates/extensions/CHANGELOG.md +1 -7
  203. package/templates/hosting/init.js +6 -2
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initGitHub = void 0;
4
- const cli_color_1 = require("cli-color");
4
+ const colorette_1 = require("colorette");
5
5
  const fs = require("fs");
6
6
  const yaml = require("js-yaml");
7
7
  const js_yaml_1 = require("js-yaml");
@@ -32,7 +32,7 @@ async function initGitHub(setup) {
32
32
  return (0, utils_1.reject)("Could not determine Project ID, can't set up GitHub workflow.", { exit: 1 });
33
33
  }
34
34
  if (!setup.config.hosting) {
35
- return (0, utils_1.reject)(`Didn't find a Hosting config in firebase.json. Run ${(0, cli_color_1.bold)("firebase init hosting")} instead.`);
35
+ return (0, utils_1.reject)(`Didn't find a Hosting config in firebase.json. Run ${(0, colorette_1.bold)("firebase init hosting")} instead.`);
36
36
  }
37
37
  logger_1.logger.info();
38
38
  const gitRoot = getGitFolderPath();
@@ -46,7 +46,7 @@ async function initGitHub(setup) {
46
46
  const userDetails = await getGitHubUserDetails(ghAccessToken);
47
47
  const ghUserName = userDetails.login;
48
48
  logger_1.logger.info();
49
- (0, utils_1.logSuccess)(`Success! Logged into GitHub as ${(0, cli_color_1.bold)(ghUserName)}`);
49
+ (0, utils_1.logSuccess)(`Success! Logged into GitHub as ${(0, colorette_1.bold)(ghUserName)}`);
50
50
  logger_1.logger.info();
51
51
  const { repo, key, keyId } = await promptForRepo(setup, ghAccessToken);
52
52
  const { default_branch: defaultBranch, id: repoId } = await getRepoDetails(repo, ghAccessToken);
@@ -56,13 +56,13 @@ async function initGitHub(setup) {
56
56
  const serviceAccountName = `github-action-${repoId}`;
57
57
  const serviceAccountJSON = await createServiceAccountAndKeyWithRetry(setup, repo, serviceAccountName);
58
58
  logger_1.logger.info();
59
- (0, utils_1.logSuccess)(`Created service account ${(0, cli_color_1.bold)(serviceAccountName)} with Firebase Hosting admin permissions.`);
59
+ (0, utils_1.logSuccess)(`Created service account ${(0, colorette_1.bold)(serviceAccountName)} with Firebase Hosting admin permissions.`);
60
60
  const spinnerSecrets = ora(`Uploading service account secrets to repository: ${repo}`);
61
61
  spinnerSecrets.start();
62
62
  const encryptedServiceAccountJSON = encryptServiceAccountJSON(serviceAccountJSON, key);
63
63
  await uploadSecretToGitHub(repo, ghAccessToken, await encryptedServiceAccountJSON, keyId, githubSecretName);
64
64
  spinnerSecrets.stop();
65
- (0, utils_1.logSuccess)(`Uploaded service account JSON to GitHub as secret ${(0, cli_color_1.bold)(githubSecretName)}.`);
65
+ (0, utils_1.logSuccess)(`Uploaded service account JSON to GitHub as secret ${(0, colorette_1.bold)(githubSecretName)}.`);
66
66
  (0, utils_1.logBullet)(`You can manage your secrets at https://github.com/${repo}/settings/secrets.`);
67
67
  logger_1.logger.info();
68
68
  if (setup.config.hosting.predeploy) {
@@ -81,7 +81,7 @@ async function initGitHub(setup) {
81
81
  if (shouldWriteYMLHostingFile) {
82
82
  writeChannelActionYMLFile(YML_FULL_PATH_PULL_REQUEST, githubSecretName, setup.projectId, script);
83
83
  logger_1.logger.info();
84
- (0, utils_1.logSuccess)(`Created workflow file ${(0, cli_color_1.bold)(YML_FULL_PATH_PULL_REQUEST)}`);
84
+ (0, utils_1.logSuccess)(`Created workflow file ${(0, colorette_1.bold)(YML_FULL_PATH_PULL_REQUEST)}`);
85
85
  }
86
86
  const { setupDeploys, branch } = await promptToSetupDeploys(ymlDeployDoc.branch || defaultBranch);
87
87
  if (setupDeploys) {
@@ -102,12 +102,12 @@ async function initGitHub(setup) {
102
102
  if (shouldWriteYMLDeployFile) {
103
103
  writeDeployToProdActionYMLFile(YML_FULL_PATH_MERGE, branch, githubSecretName, setup.projectId, script);
104
104
  logger_1.logger.info();
105
- (0, utils_1.logSuccess)(`Created workflow file ${(0, cli_color_1.bold)(YML_FULL_PATH_MERGE)}`);
105
+ (0, utils_1.logSuccess)(`Created workflow file ${(0, colorette_1.bold)(YML_FULL_PATH_MERGE)}`);
106
106
  }
107
107
  }
108
108
  logger_1.logger.info();
109
109
  (0, utils_1.logLabeledBullet)("Action required", `Visit this URL to revoke authorization for the Firebase CLI GitHub OAuth App:`);
110
- logger_1.logger.info(cli_color_1.bold.underline(`https://github.com/settings/connections/applications/${api_1.githubClientId}`));
110
+ logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${api_1.githubClientId}`)));
111
111
  (0, utils_1.logLabeledBullet)("Action required", `Push any new workflow file(s) to your repo`);
112
112
  }
113
113
  exports.initGitHub = initGitHub;
@@ -253,7 +253,7 @@ async function promptForRepo(options, ghAccessToken) {
253
253
  (0, utils_1.logWarning)("The provided authorization cannot be used with this repository. If this repository is in an organization, did you remember to grant access?", "error");
254
254
  logger_1.logger.info();
255
255
  (0, utils_1.logLabeledBullet)("Action required", `Visit this URL to ensure access has been granted to the appropriate organization(s) for the Firebase CLI GitHub OAuth App:`);
256
- logger_1.logger.info(cli_color_1.bold.underline(`https://github.com/settings/connections/applications/${api_1.githubClientId}`));
256
+ logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${api_1.githubClientId}`)));
257
257
  logger_1.logger.info();
258
258
  }
259
259
  return false;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.doSetup = void 0;
4
- const clc = require("cli-color");
4
+ const clc = require("colorette");
5
5
  const fs = require("fs");
6
6
  const apiv2_1 = require("../../../apiv2");
7
7
  const github_1 = require("./github");
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.doSetup = void 0;
4
- const clc = require("cli-color");
4
+ const clc = require("colorette");
5
5
  const _ = require("lodash");
6
6
  const error_1 = require("../../error");
7
7
  const projects_1 = require("../../management/projects");
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.doSetup = void 0;
4
4
  const prompt_1 = require("../../prompt");
5
5
  const fsutils = require("../../fsutils");
6
- const clc = require("cli-color");
6
+ const clc = require("colorette");
7
7
  async function doSetup(setup, config) {
8
8
  setup.config.remoteconfig = {};
9
9
  const jsonFilePath = await (0, prompt_1.promptOnce)({
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.doSetup = void 0;
4
- const clc = require("cli-color");
4
+ const clc = require("colorette");
5
5
  const fs = require("fs");
6
6
  const logger_1 = require("../../logger");
7
7
  const prompt_1 = require("../../prompt");
package/lib/init/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = void 0;
4
4
  const lodash_1 = require("lodash");
5
- const clc = require("cli-color");
5
+ const clc = require("colorette");
6
6
  const error_1 = require("../error");
7
7
  const logger_1 = require("../logger");
8
8
  const features = require("./features");
package/lib/logError.js CHANGED
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logError = void 0;
4
4
  const logger_1 = require("./logger");
5
- const clc = require("cli-color");
5
+ const clc = require("colorette");
6
6
  function logError(error) {
7
7
  if (error.children && error.children.length) {
8
- logger_1.logger.error(clc.bold.red("Error:"), clc.underline(error.message) + ":");
8
+ logger_1.logger.error(clc.bold(clc.red("Error:")), clc.underline(error.message) + ":");
9
9
  error.children.forEach((child) => {
10
10
  let out = "- ";
11
11
  if (child.name) {
@@ -20,7 +20,7 @@ function logError(error) {
20
20
  logger_1.logger.debug(error.original.stack);
21
21
  }
22
22
  logger_1.logger.error();
23
- logger_1.logger.error(clc.bold.red("Error:"), error.message);
23
+ logger_1.logger.error(clc.bold(clc.red("Error:")), error.message);
24
24
  }
25
25
  if (error.context) {
26
26
  logger_1.logger.debug("Error Context:", JSON.stringify(error.context, undefined, 2));
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFirebaseProject = exports.listFirebaseProjects = exports.getAvailableCloudProjectPage = exports.getFirebaseProjectPage = exports.addFirebaseToCloudProject = exports.createCloudProject = exports.promptAvailableProjectId = exports.getOrPromptProject = exports.addFirebaseToCloudProjectAndLog = exports.createFirebaseProjectAndLog = exports.PROJECTS_CREATE_QUESTIONS = exports.ProjectParentResourceType = void 0;
4
- const clc = require("cli-color");
4
+ const clc = require("colorette");
5
5
  const ora = require("ora");
6
6
  const apiv2_1 = require("../apiv2");
7
7
  const error_1 = require("../error");
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseBoltRules = void 0;
4
4
  const fs = require("fs");
5
5
  const spawn = require("cross-spawn");
6
- const clc = require("cli-color");
6
+ const clc = require("colorette");
7
7
  const _ = require("lodash");
8
8
  const error_1 = require("./error");
9
9
  function parseBoltRules(filename) {
package/lib/previews.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.previews = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const configstore_1 = require("./configstore");
6
- exports.previews = Object.assign({ rtdbrules: false, ext: false, extdev: false, rtdbmanagement: false, golang: false, deletegcfartifacts: false, emulatoruisnapshot: false, frameworkawareness: false, functionsparams: false }, configstore_1.configstore.get("previews"));
6
+ exports.previews = Object.assign({ rtdbrules: false, ext: false, extdev: false, rtdbmanagement: false, golang: false, deletegcfartifacts: false, emulatoruisnapshot: false, frameworkawareness: false, functionsparams: false, crossservicerules: false }, configstore_1.configstore.get("previews"));
7
7
  if (process.env.FIREBASE_CLI_PREVIEWS) {
8
8
  process.env.FIREBASE_CLI_PREVIEWS.split(",").forEach((feature) => {
9
9
  if ((0, lodash_1.has)(exports.previews, feature)) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProfileReport = exports.extractReadableIndex = exports.formatBytes = exports.formatNumber = exports.pathString = exports.extractJSON = void 0;
4
- const clc = require("cli-color");
4
+ const clc = require("colorette");
5
5
  const Table = require("cli-table");
6
6
  const fs = require("fs");
7
7
  const _ = require("lodash");
@@ -515,7 +515,7 @@ class ProfileReport {
515
515
  write(title + "\n");
516
516
  }
517
517
  else {
518
- write(clc.bold.yellow(title) + "\n");
518
+ write(clc.bold(clc.yellow(title)) + "\n");
519
519
  }
520
520
  };
521
521
  const writeTable = (title, table) => {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAliases = exports.needProjectNumber = exports.needProjectId = exports.getProjectId = void 0;
4
4
  const projects_1 = require("./management/projects");
5
- const clc = require("cli-color");
5
+ const clc = require("colorette");
6
6
  const { marked } = require("marked");
7
7
  const { FirebaseError } = require("./error");
8
8
  function getProjectId({ projectId, project, }) {
package/lib/rc.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RC = exports.loadRC = void 0;
4
4
  const _ = require("lodash");
5
- const clc = require("cli-color");
5
+ const clc = require("colorette");
6
6
  const cjson = require("cjson");
7
7
  const fs = require("fs");
8
8
  const path = require("path");
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireAuth = void 0;
4
4
  const google_auth_library_1 = require("google-auth-library");
5
- const clc = require("cli-color");
5
+ const clc = require("colorette");
6
6
  const api = require("./api");
7
7
  const apiv2 = require("./apiv2");
8
8
  const error_1 = require("./error");
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireDatabaseInstance = exports.MISSING_DEFAULT_INSTANCE_ERROR_MESSAGE = void 0;
4
- const clc = require("cli-color");
4
+ const clc = require("colorette");
5
5
  const error_1 = require("./error");
6
6
  const getDefaultDatabaseInstance_1 = require("./getDefaultDatabaseInstance");
7
- exports.MISSING_DEFAULT_INSTANCE_ERROR_MESSAGE = `It looks like you haven't created a Realtime Database instance in this project before. Please run ${clc.bold.underline("firebase init database")} to create your default Realtime Database instance.`;
7
+ exports.MISSING_DEFAULT_INSTANCE_ERROR_MESSAGE = `It looks like you haven't created a Realtime Database instance in this project before. Please run ${clc.bold(clc.underline("firebase init database"))} to create your default Realtime Database instance.`;
8
8
  async function requireDatabaseInstance(options) {
9
9
  if (options.instance) {
10
10
  return;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requirePermissions = void 0;
4
- const cli_color_1 = require("cli-color");
4
+ const colorette_1 = require("colorette");
5
5
  const projectUtils_1 = require("./projectUtils");
6
6
  const requireAuth_1 = require("./requireAuth");
7
7
  const logger_1 = require("./logger");
@@ -19,7 +19,7 @@ async function requirePermissions(options, permissions = []) {
19
19
  try {
20
20
  const iamResult = await (0, iam_1.testIamPermissions)(projectId, requiredPermissions);
21
21
  if (!iamResult.passed) {
22
- throw new error_1.FirebaseError(`Authorization failed. This account is missing the following required permissions on project ${(0, cli_color_1.bold)(projectId)}:\n\n ${iamResult.missing.join("\n ")}`);
22
+ throw new error_1.FirebaseError(`Authorization failed. This account is missing the following required permissions on project ${(0, colorette_1.bold)(projectId)}:\n\n ${iamResult.missing.join("\n ")}`);
23
23
  }
24
24
  }
25
25
  catch (err) {
@@ -2,16 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RulesDeploy = exports.RulesetServiceType = void 0;
4
4
  const _ = require("lodash");
5
- const clc = require("cli-color");
5
+ const colorette_1 = require("colorette");
6
6
  const fs = require("fs-extra");
7
7
  const gcp = require("./gcp");
8
8
  const logger_1 = require("./logger");
9
9
  const error_1 = require("./error");
10
10
  const utils = require("./utils");
11
11
  const prompt_1 = require("./prompt");
12
+ const getProjectNumber_1 = require("./getProjectNumber");
13
+ const resourceManager_1 = require("./gcp/resourceManager");
14
+ const previews_1 = require("./previews");
12
15
  const QUOTA_EXCEEDED_STATUS_CODE = 429;
13
16
  const RULESET_COUNT_LIMIT = 1000;
14
17
  const RULESETS_TO_GC = 10;
18
+ const CROSS_SERVICE_FUNCTIONS = /firestore\.(get|exists)/;
19
+ const CROSS_SERVICE_RULES_ROLE = "roles/firebaserules.firestoreServiceAgent";
15
20
  var RulesetServiceType;
16
21
  (function (RulesetServiceType) {
17
22
  RulesetServiceType["CLOUD_FIRESTORE"] = "cloud.firestore";
@@ -37,7 +42,7 @@ class RulesDeploy {
37
42
  }
38
43
  catch (e) {
39
44
  logger_1.logger.debug("[rules read error]", e.stack);
40
- throw new error_1.FirebaseError("Error reading rules file " + clc.bold(path));
45
+ throw new error_1.FirebaseError(`Error reading rules file ${(0, colorette_1.bold)(path)}`);
41
46
  }
42
47
  this.rulesFiles[path] = [{ name: path, content: src }];
43
48
  }
@@ -54,18 +59,50 @@ class RulesDeploy {
54
59
  }
55
60
  return { latestName, latestContent };
56
61
  }
62
+ async checkStorageRulesIamPermissions(rulesContent) {
63
+ if ((rulesContent === null || rulesContent === void 0 ? void 0 : rulesContent.match(CROSS_SERVICE_FUNCTIONS)) === null) {
64
+ return;
65
+ }
66
+ if (this.options.nonInteractive) {
67
+ return;
68
+ }
69
+ const projectNumber = await (0, getProjectNumber_1.getProjectNumber)(this.options);
70
+ const saEmail = `service-${projectNumber}@gcp-sa-firebasestorage.iam.gserviceaccount.com`;
71
+ try {
72
+ if (await (0, resourceManager_1.serviceAccountHasRoles)(projectNumber, saEmail, [CROSS_SERVICE_RULES_ROLE], true)) {
73
+ return;
74
+ }
75
+ const addRole = await (0, prompt_1.promptOnce)({
76
+ type: "confirm",
77
+ name: "rulesRole",
78
+ message: `Cloud Storage for Firebase needs an IAM Role to use cross-service rules. Grant the new role?`,
79
+ default: true,
80
+ }, this.options);
81
+ if (addRole) {
82
+ await (0, resourceManager_1.addServiceAccountToRoles)(projectNumber, saEmail, [CROSS_SERVICE_RULES_ROLE], true);
83
+ utils.logLabeledBullet(RulesetType[this.type], "updated service account for cross-service rules...");
84
+ }
85
+ }
86
+ catch (e) {
87
+ logger_1.logger.warn("[rules] Error checking or updating Cloud Storage for Firebase service account permissions.");
88
+ logger_1.logger.warn("[rules] Cross-service Storage rules may not function properly", e.message);
89
+ }
90
+ }
57
91
  async createRulesets(service) {
92
+ var _a;
58
93
  const createdRulesetNames = [];
59
94
  const { latestName: latestRulesetName, latestContent: latestRulesetContent } = await this.getCurrentRules(service);
60
95
  const newRulesetsByFilename = new Map();
61
- for (const filename of Object.keys(this.rulesFiles)) {
62
- const files = this.rulesFiles[filename];
96
+ for (const [filename, files] of Object.entries(this.rulesFiles)) {
63
97
  if (latestRulesetName && _.isEqual(files, latestRulesetContent)) {
64
- utils.logBullet(`${clc.bold.cyan(RulesetType[this.type] + ":")} latest version of ${clc.bold(filename)} already up to date, skipping upload...`);
98
+ utils.logLabeledBullet(RulesetType[this.type], `latest version of ${(0, colorette_1.bold)(filename)} already up to date, skipping upload...`);
65
99
  this.rulesetNames[filename] = latestRulesetName;
66
100
  continue;
67
101
  }
68
- utils.logBullet(`${clc.bold.cyan(RulesetType[this.type] + ":")} uploading rules ${clc.bold(filename)}...`);
102
+ if (previews_1.previews.crossservicerules && service === RulesetServiceType.FIREBASE_STORAGE) {
103
+ await this.checkStorageRulesIamPermissions((_a = files[0]) === null || _a === void 0 ? void 0 : _a.content);
104
+ }
105
+ utils.logLabeledBullet(RulesetType[this.type], `uploading rules ${(0, colorette_1.bold)(filename)}...`);
69
106
  newRulesetsByFilename.set(filename, gcp.rules.createRuleset(this.options.project, files));
70
107
  }
71
108
  try {
@@ -79,8 +116,7 @@ class RulesDeploy {
79
116
  if (err.status !== QUOTA_EXCEEDED_STATUS_CODE) {
80
117
  throw err;
81
118
  }
82
- utils.logBullet(clc.bold.yellow(RulesetType[this.type] + ":") +
83
- " quota exceeded error while uploading rules");
119
+ utils.logLabeledBullet(RulesetType[this.type], "quota exceeded error while uploading rules");
84
120
  const history = await gcp.rules.listAllRulesets(this.options.project);
85
121
  if (history.length > RULESET_COUNT_LIMIT) {
86
122
  const confirm = await (0, prompt_1.promptOnce)({
@@ -99,7 +135,7 @@ class RulesDeploy {
99
135
  await gcp.rules.deleteRuleset(this.options.project, gcp.rules.getRulesetId(entry));
100
136
  logger_1.logger.debug(`[rules] Deleted ${entry.name}`);
101
137
  }
102
- utils.logBullet(clc.bold.yellow(RulesetType[this.type] + ":") + " retrying rules upload");
138
+ utils.logLabeledWarning(RulesetType[this.type], "retrying rules upload");
103
139
  return this.createRulesets(service);
104
140
  }
105
141
  }
@@ -113,10 +149,10 @@ class RulesDeploy {
113
149
  await gcp.rules.updateOrCreateRelease(this.options.project, this.rulesetNames[filename], resourceName === RulesetServiceType.FIREBASE_STORAGE
114
150
  ? `${resourceName}/${subResourceName}`
115
151
  : resourceName);
116
- utils.logSuccess(`${clc.bold.green(RulesetType[this.type] + ":")} released rules ${clc.bold(filename)} to ${clc.bold(resourceName)}`);
152
+ utils.logLabeledSuccess(RulesetType[this.type], `released rules ${(0, colorette_1.bold)(filename)} to ${(0, colorette_1.bold)(resourceName)}`);
117
153
  }
118
154
  async compileRuleset(filename, files) {
119
- utils.logBullet(`${clc.bold.cyan(this.type + ":")} checking ${clc.bold(filename)} for compilation errors...`);
155
+ utils.logLabeledBullet(this.type, `checking ${(0, colorette_1.bold)(filename)} for compilation errors...`);
120
156
  const response = await gcp.rules.testRuleset(this.options.project, files);
121
157
  if (_.get(response, "body.issues", []).length) {
122
158
  const warnings = [];
@@ -137,11 +173,11 @@ class RulesDeploy {
137
173
  }
138
174
  if (errors.length > 0) {
139
175
  const add = errors.length === 1 ? "" : "s";
140
- const message = `Compilation error${add} in ${clc.bold(filename)}:\n${errors.join("\n")}`;
176
+ const message = `Compilation error${add} in ${(0, colorette_1.bold)(filename)}:\n${errors.join("\n")}`;
141
177
  throw new error_1.FirebaseError(message, { exit: 1 });
142
178
  }
143
179
  }
144
- utils.logSuccess(`${clc.bold.green(this.type + ":")} rules file ${clc.bold(filename)} compiled successfully`);
180
+ utils.logLabeledSuccess(this.type, `rules file ${(0, colorette_1.bold)(filename)} compiled successfully`);
145
181
  }
146
182
  }
147
183
  exports.RulesDeploy = RulesDeploy;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.connect = exports.start = exports.stop = void 0;
4
- const clc = require("cli-color");
4
+ const clc = require("colorette");
5
5
  const superstatic = require("superstatic").server;
6
6
  const morgan = require("morgan");
7
7
  const detectProjectRoot_1 = require("../detectProjectRoot");
@@ -60,6 +60,7 @@ function startServer(options, config, port, init) {
60
60
  port: port,
61
61
  host: options.host,
62
62
  config: config,
63
+ compression: true,
63
64
  cwd: (0, detectProjectRoot_1.detectProjectRoot)(options),
64
65
  stack: "strict",
65
66
  before: {
@@ -4,6 +4,9 @@ exports.serve = void 0;
4
4
  const logger_1 = require("../logger");
5
5
  const frameworks_1 = require("../frameworks");
6
6
  const previews_1 = require("../previews");
7
+ const track_1 = require("../track");
8
+ const projectUtils_1 = require("../projectUtils");
9
+ const constants_1 = require("../emulator/constants");
7
10
  const { FunctionsServer } = require("./functions");
8
11
  const TARGETS = {
9
12
  hosting: require("./hosting"),
@@ -17,12 +20,24 @@ async function serve(options) {
17
20
  [].concat(options.config.get("hosting")).some((it) => it.source)) {
18
21
  await (0, frameworks_1.prepareFrameworks)(targetNames, options, options);
19
22
  }
23
+ const isDemoProject = constants_1.Constants.isDemoProject((0, projectUtils_1.getProjectId)(options) || "");
24
+ targetNames.forEach((targetName) => {
25
+ void (0, track_1.trackEmulator)("emulator_run", {
26
+ emulator_name: targetName,
27
+ is_demo_project: String(isDemoProject),
28
+ });
29
+ });
20
30
  await Promise.all(targetNames.map((targetName) => {
21
31
  return TARGETS[targetName].start(options);
22
32
  }));
23
33
  await Promise.all(targetNames.map((targetName) => {
24
34
  return TARGETS[targetName].connect();
25
35
  }));
36
+ void (0, track_1.trackEmulator)("emulators_started", {
37
+ count: targetNames.length,
38
+ count_all: targetNames.length,
39
+ is_demo_project: String(isDemoProject),
40
+ });
26
41
  await new Promise((resolve) => {
27
42
  process.on("SIGINT", () => {
28
43
  logger_1.logger.info("Shutting down...");
package/lib/track.js CHANGED
@@ -1,16 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.track = void 0;
3
+ exports.emulatorSession = exports.trackEmulator = exports.track = exports.usageEnabled = exports.EMULATOR_GA4_MEASUREMENT_ID = void 0;
4
+ const node_fetch_1 = require("node-fetch");
4
5
  const ua = require("universal-analytics");
5
6
  const uuid_1 = require("uuid");
7
+ const auth_1 = require("./auth");
6
8
  const configstore_1 = require("./configstore");
9
+ const logger_1 = require("./logger");
7
10
  const pkg = require("../package.json");
11
+ exports.EMULATOR_GA4_MEASUREMENT_ID = process.env.FIREBASE_EMULATOR_GA4_MEASUREMENT_ID || "G-KYP2JMPFC0";
12
+ function usageEnabled() {
13
+ return !!configstore_1.configstore.get("usage");
14
+ }
15
+ exports.usageEnabled = usageEnabled;
16
+ const FIREBASE_ANALYTICS_UA = process.env.FIREBASE_ANALYTICS_UA || "UA-29174744-3";
8
17
  let anonId = configstore_1.configstore.get("analytics-uuid");
9
18
  if (!anonId) {
10
19
  anonId = (0, uuid_1.v4)();
11
20
  configstore_1.configstore.set("analytics-uuid", anonId);
12
21
  }
13
- const visitor = ua(process.env.FIREBASE_ANALYTICS_UA || "UA-29174744-3", anonId, {
22
+ const visitor = ua(FIREBASE_ANALYTICS_UA, anonId, {
14
23
  strictCidFormat: false,
15
24
  https: true,
16
25
  });
@@ -19,7 +28,7 @@ visitor.set("cd2", process.version);
19
28
  visitor.set("cd3", process.env.FIREPIT_VERSION || "none");
20
29
  function track(action, label, duration = 0) {
21
30
  return new Promise((resolve) => {
22
- if (configstore_1.configstore.get("tokens") && configstore_1.configstore.get("usage")) {
31
+ if (configstore_1.configstore.get("tokens") && usageEnabled()) {
23
32
  visitor.event("Firebase CLI " + pkg.version, action, label, duration).send(() => {
24
33
  resolve();
25
34
  });
@@ -30,3 +39,110 @@ function track(action, label, duration = 0) {
30
39
  });
31
40
  }
32
41
  exports.track = track;
42
+ const EMULATOR_GA4_API_SECRET = process.env.FIREBASE_EMULATOR_GA4_API_SECRET || "2V_zBYc4TdeoppzDaIu0zw";
43
+ const EMULATOR_GA4_USER_PROPS = {
44
+ node_platform: {
45
+ value: process.platform,
46
+ },
47
+ node_version: {
48
+ value: process.version,
49
+ },
50
+ firepit_version: {
51
+ value: process.env.FIREPIT_VERSION || "none",
52
+ },
53
+ };
54
+ async function trackEmulator(eventName, params) {
55
+ const session = emulatorSession();
56
+ if (!session) {
57
+ return;
58
+ }
59
+ const oldTotalEngagementSeconds = session.totalEngagementSeconds;
60
+ session.totalEngagementSeconds = process.uptime();
61
+ session.commandName = (params === null || params === void 0 ? void 0 : params.command_name) || session.commandName;
62
+ const search = `?api_secret=${EMULATOR_GA4_API_SECRET}&measurement_id=${session.measurementId}`;
63
+ const validate = session.validateOnly ? "debug/" : "";
64
+ const url = `https://www.google-analytics.com/${validate}mp/collect${search}`;
65
+ const body = {
66
+ timestamp_micros: `${Date.now()}000`,
67
+ client_id: session.clientId,
68
+ user_properties: Object.assign(Object.assign({}, EMULATOR_GA4_USER_PROPS), { java_major_version: session.javaMajorVersion
69
+ ? { value: session.javaMajorVersion }
70
+ : undefined }),
71
+ validationBehavior: session.validateOnly ? "ENFORCE_RECOMMENDATIONS" : undefined,
72
+ events: [
73
+ {
74
+ name: eventName,
75
+ params: Object.assign({ session_id: session.sessionId, engagement_time_msec: (session.totalEngagementSeconds - oldTotalEngagementSeconds)
76
+ .toFixed(3)
77
+ .replace(".", "")
78
+ .replace(/^0+/, ""), debug_mode: session.debugMode ? true : undefined, command_name: session.commandName }, params),
79
+ },
80
+ ],
81
+ };
82
+ if (session.validateOnly) {
83
+ logger_1.logger.info(`Sending Analytics for event ${eventName}`, params, body);
84
+ }
85
+ try {
86
+ const response = await (0, node_fetch_1.default)(url, {
87
+ method: "POST",
88
+ headers: {
89
+ "content-type": "application/json;charset=UTF-8",
90
+ },
91
+ body: JSON.stringify(body),
92
+ });
93
+ if (session.validateOnly) {
94
+ if (!response.ok) {
95
+ logger_1.logger.warn(`Analytics validation HTTP error: ${response.status}`);
96
+ }
97
+ const respBody = await response.text();
98
+ logger_1.logger.info(`Analytics validation result: ${respBody}`);
99
+ }
100
+ }
101
+ catch (e) {
102
+ if (session.validateOnly) {
103
+ throw e;
104
+ }
105
+ return;
106
+ }
107
+ }
108
+ exports.trackEmulator = trackEmulator;
109
+ function emulatorSession() {
110
+ const validateOnly = !!process.env.FIREBASE_CLI_MP_VALIDATE;
111
+ if (!usageEnabled()) {
112
+ if (validateOnly) {
113
+ logger_1.logger.warn("Google Analytics is DISABLED. To enable, (re)login and opt in to collection.");
114
+ }
115
+ return;
116
+ }
117
+ if (!currentEmulatorSession) {
118
+ let clientId = configstore_1.configstore.get("emulator-analytics-clientId");
119
+ if (!clientId) {
120
+ clientId = (0, uuid_1.v4)();
121
+ configstore_1.configstore.set("emulator-analytics-clientId", clientId);
122
+ }
123
+ currentEmulatorSession = {
124
+ measurementId: exports.EMULATOR_GA4_MEASUREMENT_ID,
125
+ clientId,
126
+ sessionId: (Math.random() * Number.MAX_SAFE_INTEGER).toFixed(0),
127
+ totalEngagementSeconds: 0,
128
+ debugMode: isDebugMode(),
129
+ validateOnly,
130
+ };
131
+ }
132
+ return currentEmulatorSession;
133
+ }
134
+ exports.emulatorSession = emulatorSession;
135
+ let currentEmulatorSession = undefined;
136
+ function isDebugMode() {
137
+ const account = (0, auth_1.getGlobalDefaultAccount)();
138
+ if (account === null || account === void 0 ? void 0 : account.user.email.endsWith("@google.com")) {
139
+ try {
140
+ require("../tsconfig.json");
141
+ logger_1.logger.info(`Using Google Analytics in DEBUG mode. Emulators (+ UI) events will be shown in GA Debug View only.`);
142
+ return true;
143
+ }
144
+ catch (_a) {
145
+ }
146
+ }
147
+ return false;
148
+ }