firebase-tools 15.32.1 → 15.34.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 (85) hide show
  1. package/README.md +9 -0
  2. package/lib/api.js +4 -2
  3. package/lib/apphosting/backend.js +1 -1
  4. package/lib/checkValidTargetFilters.js +1 -0
  5. package/lib/command.js +30 -23
  6. package/lib/commands/apps-create.js +34 -3
  7. package/lib/commands/crashlytics-heapdumps-disable.js +26 -0
  8. package/lib/commands/crashlytics-heapdumps-enable.js +54 -0
  9. package/lib/commands/crashlytics-heapdumps-status.js +32 -0
  10. package/lib/commands/deploy.js +3 -0
  11. package/lib/commands/functions-kits-uninstall.js +43 -21
  12. package/lib/commands/functions-lifecycle-list.js +5 -6
  13. package/lib/commands/hosting-channel-deploy.js +3 -3
  14. package/lib/commands/hosting-clone.js +102 -31
  15. package/lib/commands/hosting-disable.js +5 -1
  16. package/lib/commands/index.js +9 -0
  17. package/lib/commands/init.js +7 -0
  18. package/lib/commands/run-services-update.js +16 -0
  19. package/lib/crashlytics/onboarding.js +17 -2
  20. package/lib/crashlytics/profilingManager.js +195 -0
  21. package/lib/deploy/apphosting/prepare.js +1 -0
  22. package/lib/deploy/auth/deploy.js +1 -1
  23. package/lib/deploy/auth/prepare.js +6 -7
  24. package/lib/deploy/firestore/prepare.js +5 -5
  25. package/lib/deploy/functions/build.js +3 -0
  26. package/lib/deploy/functions/cel.js +89 -58
  27. package/lib/deploy/functions/functionsDeployHelper.js +10 -0
  28. package/lib/deploy/functions/prepare.js +25 -8
  29. package/lib/deploy/functions/release/executor.js +7 -3
  30. package/lib/deploy/functions/release/fabricator.js +42 -14
  31. package/lib/deploy/functions/release/planner.js +3 -2
  32. package/lib/deploy/functions/release/sourceTokenScraper.js +1 -1
  33. package/lib/deploy/functions/validate.js +16 -0
  34. package/lib/deploy/hosting/prepare.js +1 -1
  35. package/lib/deploy/hosting/release.js +2 -2
  36. package/lib/deploy/index.js +5 -0
  37. package/lib/deploy/run/args.js +2 -0
  38. package/lib/deploy/run/buildEnv.js +72 -0
  39. package/lib/deploy/run/deploy.js +214 -0
  40. package/lib/deploy/run/index.js +23 -0
  41. package/lib/deploy/run/prepare.js +47 -0
  42. package/lib/deploy/run/prereqs.js +32 -0
  43. package/lib/deploy/run/release.js +9 -0
  44. package/lib/deploy/run/update.js +50 -0
  45. package/lib/deploy/run/util.js +73 -0
  46. package/lib/emulator/apphosting/serve.js +1 -1
  47. package/lib/emulator/auth/utils.js +1 -1
  48. package/lib/emulator/commandUtils.js +7 -3
  49. package/lib/emulator/dataconnect/pgliteServer.js +1 -1
  50. package/lib/emulator/dataconnectEmulator.js +1 -1
  51. package/lib/emulator/download.js +1 -1
  52. package/lib/emulator/downloadableEmulatorInfo.json +31 -31
  53. package/lib/emulator/downloadableEmulators.js +1 -3
  54. package/lib/emulator/eventarcEmulator.js +1 -1
  55. package/lib/emulator/functionsEmulatorShared.js +1 -41
  56. package/lib/experiments.js +12 -11
  57. package/lib/firestore/validator.js +1 -1
  58. package/lib/frameworks/next/constants.js +20 -12
  59. package/lib/frameworks/next/index.js +3 -0
  60. package/lib/functions/env.js +4 -2
  61. package/lib/functions/projectConfig.js +10 -5
  62. package/lib/gcp/artifactregistry.js +20 -0
  63. package/lib/gcp/cloudsql/permissions.js +21 -32
  64. package/lib/gcp/cloudsql/permissionsSetup.js +6 -6
  65. package/lib/gcp/cloudtasks.js +14 -0
  66. package/lib/gcp/cloudtrace.js +38 -0
  67. package/lib/gcp/run.js +5 -0
  68. package/lib/gcp/runv2.js +32 -11
  69. package/lib/gcp/storage.js +9 -5
  70. package/lib/hosting/api.js +15 -15
  71. package/lib/hosting/runTags.js +1 -1
  72. package/lib/init/features/auth.js +46 -8
  73. package/lib/init/features/index.js +4 -1
  74. package/lib/init/features/run.js +159 -0
  75. package/lib/init/index.js +6 -0
  76. package/lib/mcp/tools/firestore/converter.js +2 -2
  77. package/lib/mcp/util.js +11 -10
  78. package/lib/profileReport.js +12 -9
  79. package/lib/throttler/throttler.js +1 -0
  80. package/lib/tsconfig.compile.tsbuildinfo +1 -1
  81. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  82. package/package.json +2 -8
  83. package/schema/firebaserc.json +133 -0
  84. package/lib/mcp/resources/guides/init_data_connect.js +0 -30
  85. package/lib/mcp/resources/guides/init_rtdb.js +0 -30
@@ -9,93 +9,164 @@ const api_1 = require("../hosting/api");
9
9
  const utils = require("../utils");
10
10
  const requireAuth_1 = require("../requireAuth");
11
11
  const logger_1 = require("../logger");
12
+ const projectUtils_1 = require("../projectUtils");
12
13
  exports.command = new command_1.Command("hosting:clone <source> <targetChannel>")
13
14
  .description("clone a version from one site to another")
14
- .help(`<source> and <targetChannel> accept the following format: <siteId>:<channelId>
15
+ .help(`<source> and <targetChannel> accept the following formats:
16
+ - [<projectId>:]<siteId>:<channelId>
17
+ - [<projectId>:]<siteId>@<versionId> (source only)
15
18
 
16
- For example, to copy the content for a site \`my-site\` from a preview channel \`staging\` to a \`live\` channel, the command would look be:
19
+ Site projects are automatically discovered if omitted.
17
20
 
18
- firebase hosting:clone my-site:foo my-site:live`)
21
+ For example, to copy the content for a site \`my-site\` from a preview channel \`staging\` to a \`live\` channel:
22
+
23
+ firebase hosting:clone my-site:staging my-site:live
24
+
25
+ To clone across different Firebase projects:
26
+
27
+ firebase hosting:clone site-a:live site-b:live --project=project-b
28
+ # or explicitly:
29
+ firebase hosting:clone project-a:site-a:live project-b:site-b:live`)
19
30
  .before(requireAuth_1.requireAuth)
20
- .action(async (source = "", targetChannel = "") => {
21
- let sourceVersionName;
31
+ .action(async (source, targetChannel, options) => {
32
+ source = source || "";
33
+ targetChannel = targetChannel || "";
34
+ let sourceProjectId;
35
+ let sourceSiteId;
36
+ let sourceChannelId;
22
37
  let sourceVersion;
23
- let [sourceSiteId, sourceChannelId] = source.split(":");
24
- let [targetSiteId, targetChannelId] = targetChannel.split(":");
25
- if (!sourceSiteId || !sourceChannelId) {
26
- [sourceSiteId, sourceVersion] = source.split("@");
27
- if (!sourceSiteId || !sourceVersion) {
28
- throw new error_1.FirebaseError(`"${source}" is not a valid source. Must be in the form "<site>:<channel>" or "<site>@<version>"`);
38
+ if (source.includes("@")) {
39
+ const [sitePart, version] = source.split("@");
40
+ sourceVersion = version;
41
+ if (sitePart.includes(":")) {
42
+ [sourceProjectId, sourceSiteId] = sitePart.split(":");
43
+ }
44
+ else {
45
+ sourceSiteId = sitePart;
46
+ }
47
+ }
48
+ else {
49
+ const parts = source.split(":");
50
+ if (parts.length === 3) {
51
+ [sourceProjectId, sourceSiteId, sourceChannelId] = parts;
52
+ }
53
+ else if (parts.length === 2) {
54
+ [sourceSiteId, sourceChannelId] = parts;
29
55
  }
30
- sourceVersionName = `sites/${sourceSiteId}/versions/${sourceVersion}`;
56
+ }
57
+ let targetProjectId;
58
+ let targetSiteId;
59
+ let targetChannelId;
60
+ const targetParts = targetChannel.split(":");
61
+ if (targetParts.length === 3) {
62
+ [targetProjectId, targetSiteId, targetChannelId] = targetParts;
63
+ }
64
+ else if (targetParts.length === 2) {
65
+ [targetSiteId, targetChannelId] = targetParts;
66
+ }
67
+ if (!sourceSiteId || (!sourceChannelId && !sourceVersion)) {
68
+ throw new error_1.FirebaseError(`"${source}" is not a valid source. Must be in the form "[<project>:]<site>:<channel>" or "[<project>:]<site>@<version>"`);
31
69
  }
32
70
  if (!targetSiteId || !targetChannelId) {
33
- throw new error_1.FirebaseError(`"${targetChannel}" is not a valid target channel. Must be in the form "<site>:<channel>" (to clone to the active website, use "live" as the channel).`);
71
+ throw new error_1.FirebaseError(`"${targetChannel}" is not a valid target channel. Must be in the form "[<project>:]<site>:<channel>" (to clone to the active website, use "live" as the channel).`);
34
72
  }
73
+ [sourceProjectId, targetProjectId] = await Promise.all([
74
+ resolveProjectId(sourceSiteId, sourceProjectId, options),
75
+ resolveProjectId(targetSiteId, targetProjectId, options),
76
+ ]);
35
77
  targetChannelId = (0, api_1.normalizeName)(targetChannelId);
36
78
  if (sourceChannelId) {
37
79
  sourceChannelId = (0, api_1.normalizeName)(sourceChannelId);
38
80
  }
81
+ const equalProjectIds = sourceProjectId === targetProjectId;
39
82
  const equalSiteIds = sourceSiteId === targetSiteId;
40
83
  const equalChannelIds = sourceChannelId === targetChannelId;
41
- if (equalSiteIds && equalChannelIds) {
42
- throw new error_1.FirebaseError(`Source and destination cannot be equal. Please pick a different source or desination.`);
84
+ if (equalProjectIds && equalSiteIds && equalChannelIds) {
85
+ throw new error_1.FirebaseError(`Source and destination cannot be equal. Please pick a different source or destination.`);
43
86
  }
44
- if (!sourceVersionName) {
45
- const sChannel = await (0, api_1.getChannel)("-", sourceSiteId, sourceChannelId);
87
+ let sourceVersionName;
88
+ if (sourceVersion) {
89
+ sourceVersionName = `projects/${sourceProjectId}/sites/${sourceSiteId}/versions/${sourceVersion}`;
90
+ }
91
+ else if (sourceChannelId) {
92
+ const sChannel = await (0, api_1.getChannel)(sourceProjectId, sourceSiteId, sourceChannelId);
46
93
  if (!sChannel) {
47
- throw new error_1.FirebaseError(`Could not find the channel ${(0, colorette_1.bold)(sourceChannelId)} for site ${(0, colorette_1.bold)(sourceSiteId)}.`);
94
+ throw new error_1.FirebaseError(`Could not find the channel ${(0, colorette_1.bold)(sourceChannelId)} for site ${(0, colorette_1.bold)(sourceSiteId)} in project ${(0, colorette_1.bold)(sourceProjectId)}.`);
48
95
  }
49
96
  sourceVersionName = sChannel.release?.version?.name;
50
97
  if (!sourceVersionName) {
51
98
  throw new error_1.FirebaseError(`Could not find a version on the channel ${(0, colorette_1.bold)(sourceChannelId)} for site ${(0, colorette_1.bold)(sourceSiteId)}.`);
52
99
  }
53
100
  }
54
- let tChannel = await (0, api_1.getChannel)("-", targetSiteId, targetChannelId);
101
+ if (!sourceVersionName) {
102
+ throw new error_1.FirebaseError(`Could not find a version to clone for site ${(0, colorette_1.bold)(sourceSiteId)}.`);
103
+ }
104
+ let tChannel = await (0, api_1.getChannel)(targetProjectId, targetSiteId, targetChannelId);
55
105
  if (!tChannel) {
56
106
  utils.logBullet(`could not find channel ${(0, colorette_1.bold)(targetChannelId)} in site ${(0, colorette_1.bold)(targetSiteId)}, creating it...`);
57
107
  try {
58
- tChannel = await (0, api_1.createChannel)("-", targetSiteId, targetChannelId);
108
+ tChannel = await (0, api_1.createChannel)(targetProjectId, targetSiteId, targetChannelId);
59
109
  }
60
110
  catch (e) {
61
111
  throw new error_1.FirebaseError(`Could not create the channel ${(0, colorette_1.bold)(targetChannelId)} for site ${(0, colorette_1.bold)(targetSiteId)}.`, { original: e });
62
112
  }
63
113
  utils.logSuccess(`Created new channel ${targetChannelId}`);
64
114
  try {
65
- const tProjectId = parseProjectId(tChannel.name);
66
- await (0, api_1.addAuthDomains)(tProjectId, [tChannel.url]);
115
+ await (0, api_1.addAuthDomains)(targetProjectId, [tChannel.url]);
67
116
  }
68
117
  catch (e) {
69
- utils.logLabeledWarning("hosting:clone", `Unable to add channel domain to Firebase Auth. Visit the Firebase Console at ${utils.consoleUrl(targetSiteId, "/authentication/providers")}`);
118
+ utils.logLabeledWarning("hosting:clone", `Unable to add channel domain to Firebase Auth. Visit the Firebase Console at ${utils.consoleUrl(targetProjectId, "/authentication/providers")}`);
70
119
  logger_1.logger.debug("[hosting] unable to add auth domain", e);
71
120
  }
72
121
  }
73
122
  const currentTargetVersionName = tChannel.release?.version?.name;
74
- if (equalSiteIds && sourceVersionName === currentTargetVersionName) {
75
- utils.logSuccess(`Channels ${(0, colorette_1.bold)(sourceChannelId)} and ${(0, colorette_1.bold)(targetChannel)} are serving identical versions. No need to clone.`);
123
+ if (equalProjectIds && equalSiteIds && sourceVersionName === currentTargetVersionName) {
124
+ utils.logSuccess(`Channels ${(0, colorette_1.bold)(sourceChannelId || sourceVersion || "")} and ${(0, colorette_1.bold)(targetChannel)} are serving identical versions. No need to clone.`);
76
125
  return;
77
126
  }
78
127
  let targetVersionName = sourceVersionName;
79
128
  const spinner = ora("Cloning site content...").start();
80
129
  try {
81
- if (!equalSiteIds) {
82
- const targetVersion = await (0, api_1.cloneVersion)(targetSiteId, sourceVersionName, true);
130
+ if (!equalSiteIds || !equalProjectIds) {
131
+ const targetVersion = await (0, api_1.cloneVersion)(targetProjectId, targetSiteId, sourceVersionName, true);
83
132
  if (!targetVersion) {
84
- throw new error_1.FirebaseError(`Could not clone the version ${(0, colorette_1.bold)(sourceVersion)} for site ${(0, colorette_1.bold)(targetSiteId)}.`);
133
+ throw new error_1.FirebaseError(`Could not clone the version ${(0, colorette_1.bold)(sourceVersion || sourceVersionName)} for site ${(0, colorette_1.bold)(targetSiteId)}.`);
85
134
  }
86
135
  targetVersionName = targetVersion.name;
87
136
  }
88
- await (0, api_1.createRelease)(targetSiteId, targetChannelId, targetVersionName);
137
+ await (0, api_1.createRelease)(targetProjectId, targetSiteId, targetChannelId, targetVersionName);
89
138
  }
90
139
  catch (err) {
91
140
  spinner.fail();
92
141
  throw err;
93
142
  }
94
143
  spinner.succeed();
95
- utils.logSuccess(`Site ${(0, colorette_1.bold)(sourceSiteId)} ${sourceChannelId ? "channel" : "version"} ${(0, colorette_1.bold)(sourceChannelId || sourceVersion)} has been cloned to site ${(0, colorette_1.bold)(targetSiteId)} channel ${(0, colorette_1.bold)(targetChannelId)}.`);
144
+ utils.logSuccess(`Site ${(0, colorette_1.bold)(sourceSiteId)} ${sourceChannelId ? "channel" : "version"} ${(0, colorette_1.bold)(sourceChannelId || sourceVersion || sourceVersionName)} has been cloned to site ${(0, colorette_1.bold)(targetSiteId)} channel ${(0, colorette_1.bold)(targetChannelId)}.`);
96
145
  utils.logSuccess(`Channel URL (${targetChannelId}): ${tChannel.url}`);
97
146
  });
98
147
  function parseProjectId(name) {
99
- const matches = name.match(`^projects/([^/]+)`);
148
+ const matches = /^projects\/([^/]+)/.exec(name);
100
149
  return matches ? matches[1] || "" : "";
101
150
  }
151
+ async function resolveProjectId(siteId, explicitProjectId, options) {
152
+ if (explicitProjectId) {
153
+ return explicitProjectId;
154
+ }
155
+ try {
156
+ const site = await (0, api_1.getSite)("-", siteId);
157
+ const projectId = parseProjectId(site.name);
158
+ if (projectId) {
159
+ return projectId;
160
+ }
161
+ }
162
+ catch (e) {
163
+ if (e instanceof error_1.FirebaseError && e.status === 404) {
164
+ throw new error_1.FirebaseError(`Could not find the site ${(0, colorette_1.bold)(siteId)}.`, {
165
+ original: e,
166
+ status: 404,
167
+ });
168
+ }
169
+ logger_1.logger.debug(`[hosting] unable to resolve project for site ${siteId} via site lookup:`, e);
170
+ }
171
+ return (0, projectUtils_1.needProjectId)(options);
172
+ }
@@ -8,6 +8,7 @@ const api_1 = require("../api");
8
8
  const prompt_1 = require("../prompt");
9
9
  const requireHostingSite_1 = require("../requireHostingSite");
10
10
  const requirePermissions_1 = require("../requirePermissions");
11
+ const projectUtils_1 = require("../projectUtils");
11
12
  const utils = require("../utils");
12
13
  exports.command = new command_1.Command("hosting:disable")
13
14
  .description("stop serving web traffic to your Firebase Hosting site")
@@ -16,6 +17,7 @@ exports.command = new command_1.Command("hosting:disable")
16
17
  .before(requirePermissions_1.requirePermissions, ["firebasehosting.sites.update"])
17
18
  .before(requireHostingSite_1.requireHostingSite)
18
19
  .action(async (options) => {
20
+ const projectId = (0, projectUtils_1.needProjectId)(options);
19
21
  const siteToDisable = options.site;
20
22
  const confirmed = await (0, prompt_1.confirm)({
21
23
  message: `Are you sure you want to disable Firebase Hosting for the site ${clc.underline(siteToDisable)}\n${clc.underline("This will immediately make your site inaccessible!")}`,
@@ -26,6 +28,8 @@ exports.command = new command_1.Command("hosting:disable")
26
28
  return;
27
29
  }
28
30
  const c = new apiv2_1.Client({ urlPrefix: (0, api_1.hostingApiOrigin)(), apiVersion: "v1beta1", auth: true });
29
- await c.post(`/sites/${siteToDisable}/releases`, { type: "SITE_DISABLE" });
31
+ await c.post(`/projects/${projectId}/sites/${siteToDisable}/releases`, {
32
+ type: "SITE_DISABLE",
33
+ });
30
34
  utils.logSuccess(`Hosting has been disabled for ${clc.bold(siteToDisable)}. Deploy a new version to re-enable.`);
31
35
  });
@@ -80,6 +80,10 @@ function load(client) {
80
80
  client.crashlytics.sourcemap = {};
81
81
  client.crashlytics.sourcemap.upload = loadCommand("crashlytics-sourcemap-upload");
82
82
  }
83
+ client.crashlytics.heapdumps = {};
84
+ client.crashlytics.heapdumps.enable = loadCommand("crashlytics-heapdumps-enable");
85
+ client.crashlytics.heapdumps.disable = loadCommand("crashlytics-heapdumps-disable");
86
+ client.crashlytics.heapdumps.status = loadCommand("crashlytics-heapdumps-status");
83
87
  client.database = {};
84
88
  client.database.get = loadCommand("database-get");
85
89
  client.database.import = loadCommand("database-import");
@@ -285,6 +289,11 @@ function load(client) {
285
289
  client.remoteconfig.experiments.get = loadCommand("remoteconfig-experiments-get");
286
290
  client.remoteconfig.experiments.list = loadCommand("remoteconfig-experiments-list");
287
291
  client.remoteconfig.experiments.delete = loadCommand("remoteconfig-experiments-delete");
292
+ if (experiments.isEnabled("directcloudrun")) {
293
+ client.run = {};
294
+ client.run.services = {};
295
+ client.run.services.update = loadCommand("run-services-update");
296
+ }
288
297
  client.serve = loadCommand("serve");
289
298
  client.setup = {};
290
299
  client.setup.emulators = {};
@@ -94,6 +94,13 @@ let choices = [
94
94
  checked: false,
95
95
  },
96
96
  ];
97
+ if ((0, experiments_1.isEnabled)("directcloudrun")) {
98
+ choices.push({
99
+ value: "run",
100
+ name: "Cloud Run: Create or update a Cloud Run service and deploy your web app to it",
101
+ checked: false,
102
+ });
103
+ }
97
104
  if ((0, experiments_1.isEnabled)("fdcwebhooks")) {
98
105
  choices.push({
99
106
  value: "dataconnect:resolver",
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const deploy_1 = require("../deploy");
6
+ const update_1 = require("../deploy/run/update");
7
+ const requireConfig_1 = require("../requireConfig");
8
+ const requirePermissions_1 = require("../requirePermissions");
9
+ exports.command = new command_1.Command("run:services:update <serviceId>")
10
+ .description("update the settings of a Cloud Run service, then build and deploy it")
11
+ .option("--region <region>", "the service's region, if firebase.json lists the service ID in more than one region")
12
+ .option("--base-image <baseImage>", "set the base image (e.g. nodejs22) and enable automatic base image updates")
13
+ .option("--clear-base-image", "clear the base image and disable automatic base image updates")
14
+ .before(requireConfig_1.requireConfig)
15
+ .before(requirePermissions_1.requirePermissions, deploy_1.TARGET_PERMISSIONS.run)
16
+ .action((serviceId, options) => (0, update_1.updateService)(serviceId, options.region, options));
@@ -12,6 +12,7 @@ const firebasetelemetry_1 = require("./firebasetelemetry");
12
12
  const types_1 = require("./types");
13
13
  const utils_1 = require("../utils");
14
14
  const apikeys_1 = require("../gcp/apikeys");
15
+ const cloudtrace_1 = require("../gcp/cloudtrace");
15
16
  const apps_1 = require("../management/apps");
16
17
  const logger_1 = require("../logger");
17
18
  const prompt_1 = require("../prompt");
@@ -42,10 +43,14 @@ async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
42
43
  await (0, cloudbilling_1.enableBilling)(projectId, "Crashlytics");
43
44
  }
44
45
  (0, utils_1.logLabeledBullet)("crashlytics", "Enabling required telemetry APIs...");
45
- await Promise.all([
46
+ const requiredApis = [
46
47
  (0, ensureApiEnabled_1.ensure)(projectId, exports.CRASHLYTICS_TELEMETRY_SERVICE, "crashlytics", false),
47
48
  (0, ensureApiEnabled_1.ensure)(projectId, "firebasetelemetryadmin.googleapis.com", "crashlytics", false),
48
- ]);
49
+ ];
50
+ if (experiments.isEnabled("crashlyticsWebBreadcrumbs")) {
51
+ requiredApis.push((0, ensureApiEnabled_1.ensure)(projectId, "cloudtrace.googleapis.com", "crashlytics", false));
52
+ }
53
+ await Promise.all(requiredApis);
49
54
  (0, utils_1.logLabeledSuccess)("crashlytics", "Telemetry APIs enabled.");
50
55
  const appConfig = await (0, apps_1.getAppConfig)(appId, apps_1.AppPlatform.WEB);
51
56
  if ("apiKey" in appConfig && appConfig.apiKey) {
@@ -73,6 +78,16 @@ async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
73
78
  (0, utils_1.logLabeledBullet)("crashlytics", `Setting up Cloud Logging routing sink '${exports.CRASHLYTICS_TELEMETRY_SINK_ID}'...`);
74
79
  const sink = await (0, cloudlogging_1.createOrUpdateLogSink)(projectId, exports.CRASHLYTICS_TELEMETRY_SINK_ID, destination, filter);
75
80
  (0, utils_1.logLabeledSuccess)("crashlytics", "Cloud Logging routing sink configured.");
81
+ if (experiments.isEnabled("crashlyticsWebBreadcrumbs")) {
82
+ (0, utils_1.logLabeledBullet)("crashlytics", "Provisioning Cloud Trace storage...");
83
+ try {
84
+ await (0, cloudtrace_1.provisionTraceStorage)(projectId);
85
+ (0, utils_1.logLabeledSuccess)("crashlytics", "Cloud Trace storage provisioned.");
86
+ }
87
+ catch (err) {
88
+ (0, utils_1.logLabeledWarning)("crashlytics", (0, error_1.getErrMsg)(err));
89
+ }
90
+ }
76
91
  (0, utils_1.logLabeledBullet)("crashlytics", "Configuring Crashlytics telemetry for web app...");
77
92
  const config = await (0, firebasetelemetry_1.createOrUpdateTelemetryConfig)(projectId, appId, `projects/${projectId}/locations/global/buckets/${exports.CRASHLYTICS_TELEMETRY_BUCKET_ID}`, 1);
78
93
  (0, utils_1.logLabeledSuccess)("crashlytics", "Crashlytics telemetry configured successfully.");
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_LIFECYCLE_RULES = exports.DEFAULT_CORS_RULES = exports.DEFAULT_FILE_TTL_DAYS = exports.DEFAULT_BUCKET_LOCATION = exports.DEFAULT_CORS_ORIGINS = exports.HEAP_DUMP_BUCKET_PREFIX = exports.STORAGE_OBJECT_CREATOR_ROLE = exports.CRASHLYTICS_SERVICE_NAME = void 0;
4
+ exports.getCrashlyticsV1Client = getCrashlyticsV1Client;
5
+ exports.parseAndroidHashedId = parseAndroidHashedId;
6
+ exports.createBucketName = createBucketName;
7
+ exports.getCrashlyticsP4sa = getCrashlyticsP4sa;
8
+ exports.resolveAndroidAppId = resolveAndroidAppId;
9
+ exports.getProfilingManagerConfig = getProfilingManagerConfig;
10
+ exports.updateProfilingManagerConfig = updateProfilingManagerConfig;
11
+ exports.ensureHeapDumpStorageBucket = ensureHeapDumpStorageBucket;
12
+ exports.ensureHeapDumpP4saRole = ensureHeapDumpP4saRole;
13
+ exports.enableHeapDumpCollection = enableHeapDumpCollection;
14
+ exports.disableHeapDumpCollection = disableHeapDumpCollection;
15
+ const apiv2_1 = require("../apiv2");
16
+ const api_1 = require("../api");
17
+ const error_1 = require("../error");
18
+ const logger_1 = require("../logger");
19
+ const utils_1 = require("../utils");
20
+ const utils_2 = require("./utils");
21
+ const storage = require("../gcp/storage");
22
+ const resourceManager = require("../gcp/resourceManager");
23
+ const serviceusage = require("../gcp/serviceusage");
24
+ const apps_1 = require("../management/apps");
25
+ function getCrashlyticsV1Client() {
26
+ return new apiv2_1.Client({
27
+ urlPrefix: (0, api_1.crashlyticsApiOrigin)(),
28
+ apiVersion: "v1",
29
+ });
30
+ }
31
+ exports.CRASHLYTICS_SERVICE_NAME = "firebasecrashlytics.googleapis.com";
32
+ exports.STORAGE_OBJECT_CREATOR_ROLE = "roles/storage.objectCreator";
33
+ exports.HEAP_DUMP_BUCKET_PREFIX = "firebasecrashlytics-heap-dumps-";
34
+ exports.DEFAULT_CORS_ORIGINS = ["https://console.firebase.google.com"];
35
+ exports.DEFAULT_BUCKET_LOCATION = "us-east1";
36
+ exports.DEFAULT_FILE_TTL_DAYS = 90;
37
+ exports.DEFAULT_CORS_RULES = [
38
+ {
39
+ origin: exports.DEFAULT_CORS_ORIGINS,
40
+ method: ["GET", "HEAD", "OPTIONS"],
41
+ responseHeader: ["Content-Type", "Access-Control-Allow-Origin", "Content-Length"],
42
+ },
43
+ ];
44
+ exports.DEFAULT_LIFECYCLE_RULES = [
45
+ {
46
+ action: { type: "Delete" },
47
+ condition: { age: exports.DEFAULT_FILE_TTL_DAYS },
48
+ },
49
+ ];
50
+ const ANDROID_APP_ID_REGEX = /^\d+:(\d+):android:([a-fA-F0-9]+)$/;
51
+ function parseAndroidHashedId(appId) {
52
+ const match = ANDROID_APP_ID_REGEX.exec(appId);
53
+ if (!match) {
54
+ throw new error_1.FirebaseError(`App ID '${appId}' is not a valid Android app ID (expected format '1:<project-number>:android:<hash>'). ` +
55
+ "Heap dump collection is only supported for Android apps. " +
56
+ "Run 'firebase apps:list ANDROID' to view valid Android app IDs for your project.");
57
+ }
58
+ return match[2].toLowerCase();
59
+ }
60
+ function createBucketName(appId) {
61
+ return `${exports.HEAP_DUMP_BUCKET_PREFIX}${parseAndroidHashedId(appId)}`;
62
+ }
63
+ function getCrashlyticsP4sa(projectNumber) {
64
+ return `service-${projectNumber}@gcp-sa-crashlytics.iam.gserviceaccount.com`;
65
+ }
66
+ async function resolveAndroidAppId(projectId, options) {
67
+ if (options.app) {
68
+ parseAndroidHashedId(options.app);
69
+ return options.app;
70
+ }
71
+ const apps = await (0, apps_1.listFirebaseApps)(projectId, apps_1.AppPlatform.ANDROID);
72
+ if (apps.length === 0) {
73
+ throw new error_1.FirebaseError(`No Android apps found in project '${projectId}'. Heap dump collection is only supported for Android apps.\n` +
74
+ "You can register an Android app using 'firebase apps:create ANDROID <package-name>'");
75
+ }
76
+ if (apps.length === 1) {
77
+ return apps[0].appId;
78
+ }
79
+ if (options.nonInteractive) {
80
+ throw new error_1.FirebaseError(`Project '${projectId}' has multiple Android apps. Please specify an app ID with '--app <appID>'.`);
81
+ }
82
+ const selectedApp = await (0, apps_1.selectAppInteractively)(apps, apps_1.AppPlatform.ANDROID, {
83
+ message: "Select an Android app:",
84
+ });
85
+ return selectedApp.appId;
86
+ }
87
+ async function getProfilingManagerConfig(appId) {
88
+ const projectNumber = (0, utils_2.parseProjectNumber)(appId);
89
+ logger_1.logger.debug(`[crashlytics] getProfilingManagerConfig called with appId: ${appId}`);
90
+ const response = await getCrashlyticsV1Client().request({
91
+ method: "GET",
92
+ headers: {
93
+ "Content-Type": "application/json",
94
+ },
95
+ path: `/projects/${projectNumber}/apps/${appId}/appconfig:profilingManager`,
96
+ timeout: utils_2.TIMEOUT,
97
+ });
98
+ const config = response.body?.configuration || {};
99
+ return {
100
+ gcsBucket: config.gcsBucket || "",
101
+ heapDumpCollectionEnabled: config.heapDumpCollectionEnabled ?? false,
102
+ };
103
+ }
104
+ async function updateProfilingManagerConfig(appId, config) {
105
+ const projectNumber = (0, utils_2.parseProjectNumber)(appId);
106
+ logger_1.logger.debug(`[crashlytics] updateProfilingManagerConfig called with appId: ${appId}, config: ${JSON.stringify(config)}`);
107
+ await getCrashlyticsV1Client().request({
108
+ method: "POST",
109
+ headers: {
110
+ "Content-Type": "application/json",
111
+ },
112
+ path: `/projects/${projectNumber}/apps/${appId}/appconfig:profilingManager`,
113
+ body: {
114
+ projectNumber,
115
+ gmpAppId: appId,
116
+ configuration: {
117
+ gcsBucket: config.gcsBucket ?? "",
118
+ heapDumpCollectionEnabled: config.heapDumpCollectionEnabled ?? false,
119
+ },
120
+ },
121
+ timeout: utils_2.TIMEOUT,
122
+ });
123
+ }
124
+ async function ensureHeapDumpStorageBucket(projectId, appId, location = exports.DEFAULT_BUCKET_LOCATION) {
125
+ const bucketName = createBucketName(appId);
126
+ const projectNumber = (0, utils_2.parseProjectNumber)(appId);
127
+ try {
128
+ const bucket = await storage.getBucket(bucketName);
129
+ if (bucket.projectNumber && String(bucket.projectNumber) !== projectNumber) {
130
+ throw new error_1.FirebaseError(`Cloud Storage bucket '${bucketName}' already exists and is owned by another project.`);
131
+ }
132
+ const patchPayload = {};
133
+ const hasConsoleCors = bucket.cors?.some((rule) => exports.DEFAULT_CORS_ORIGINS.every((origin) => rule.origin?.includes(origin)));
134
+ if (!hasConsoleCors) {
135
+ patchPayload.cors = [...(bucket.cors ?? []), ...exports.DEFAULT_CORS_RULES];
136
+ }
137
+ const hasDeleteLifecycle = bucket.lifecycle?.rule?.some((rule) => rule.action.type === "Delete" && rule.condition.age !== undefined);
138
+ if (!hasDeleteLifecycle) {
139
+ patchPayload.lifecycle = {
140
+ rule: [...(bucket.lifecycle?.rule ?? []), ...exports.DEFAULT_LIFECYCLE_RULES],
141
+ };
142
+ }
143
+ if (Object.keys(patchPayload).length > 0) {
144
+ logger_1.logger.debug(`[crashlytics] Bucket ${bucketName} found without full configuration. Patching ${Object.keys(patchPayload).join(", ")}.`);
145
+ await storage.patchBucket(bucketName, patchPayload);
146
+ }
147
+ return bucketName;
148
+ }
149
+ catch (err) {
150
+ const status = (0, error_1.getErrStatus)(err);
151
+ if (status !== 404) {
152
+ throw err;
153
+ }
154
+ }
155
+ logger_1.logger.debug(`[crashlytics] Creating GCS bucket ${bucketName} in ${location}...`);
156
+ await storage.createBucket(projectId, {
157
+ name: bucketName,
158
+ location,
159
+ cors: exports.DEFAULT_CORS_RULES,
160
+ lifecycle: { rule: exports.DEFAULT_LIFECYCLE_RULES },
161
+ }, true);
162
+ return bucketName;
163
+ }
164
+ async function ensureHeapDumpP4saRole(projectId, projectNumber) {
165
+ await serviceusage.generateServiceIdentityAndPoll(projectNumber, exports.CRASHLYTICS_SERVICE_NAME, "crashlytics");
166
+ const p4saEmail = getCrashlyticsP4sa(projectNumber);
167
+ const hasRole = await resourceManager.serviceAccountHasRoles(projectId, p4saEmail, [exports.STORAGE_OBJECT_CREATOR_ROLE], true);
168
+ if (!hasRole) {
169
+ logger_1.logger.debug(`[crashlytics] Adding ${exports.STORAGE_OBJECT_CREATOR_ROLE} to ${p4saEmail}...`);
170
+ await resourceManager.addServiceAccountToRoles(projectId, p4saEmail, [exports.STORAGE_OBJECT_CREATOR_ROLE], true);
171
+ }
172
+ }
173
+ async function enableHeapDumpCollection(projectId, appId, location = exports.DEFAULT_BUCKET_LOCATION) {
174
+ const projectNumber = (0, utils_2.parseProjectNumber)(appId);
175
+ (0, utils_1.logLabeledBullet)("crashlytics", "Configuring Google Cloud Storage bucket...");
176
+ const bucketName = await ensureHeapDumpStorageBucket(projectId, appId, location);
177
+ (0, utils_1.logLabeledBullet)("crashlytics", "Configuring service agent permissions...");
178
+ await ensureHeapDumpP4saRole(projectId, projectNumber);
179
+ (0, utils_1.logLabeledBullet)("crashlytics", "Enabling Crashlytics heap dump collection...");
180
+ await updateProfilingManagerConfig(appId, {
181
+ gcsBucket: bucketName,
182
+ heapDumpCollectionEnabled: true,
183
+ });
184
+ (0, utils_1.logLabeledSuccess)("crashlytics", "Successfully enabled Crashlytics heap dump collection!");
185
+ return bucketName;
186
+ }
187
+ async function disableHeapDumpCollection(appId) {
188
+ (0, utils_1.logLabeledBullet)("crashlytics", "Disabling Crashlytics heap dump collection...");
189
+ const currentConfig = await getProfilingManagerConfig(appId);
190
+ await updateProfilingManagerConfig(appId, {
191
+ gcsBucket: currentConfig.gcsBucket,
192
+ heapDumpCollectionEnabled: false,
193
+ });
194
+ (0, utils_1.logLabeledSuccess)("crashlytics", "Successfully disabled Crashlytics heap dump collection!");
195
+ }
@@ -4,6 +4,7 @@ exports.default = default_1;
4
4
  exports.injectEnvVarsFromApphostingConfig = injectEnvVarsFromApphostingConfig;
5
5
  exports.injectAutoInitEnvVars = injectAutoInitEnvVars;
6
6
  exports.getBackendConfigs = getBackendConfigs;
7
+ exports.prepareLocalBuildScratchDirectory = prepareLocalBuildScratchDirectory;
7
8
  exports.injectAngularEnvVars = injectAngularEnvVars;
8
9
  const crypto = require("crypto");
9
10
  const fs = require("fs");
@@ -52,7 +52,7 @@ async function deploy(context, options) {
52
52
  },
53
53
  },
54
54
  app: {
55
- platform: apps_1.AppPlatform.WEB,
55
+ platform: context.auth?.platform || apps_1.AppPlatform.WEB,
56
56
  appId: appId,
57
57
  },
58
58
  features: {
@@ -4,23 +4,22 @@ exports.prepare = prepare;
4
4
  const apps_1 = require("../../management/apps");
5
5
  const logger_1 = require("../../logger");
6
6
  const projectUtils_1 = require("../../projectUtils");
7
+ const DEFAULT_APP_DISPLAY_NAME = "Default Web App";
7
8
  async function prepare(context, options) {
8
9
  const projectId = (0, projectUtils_1.needProjectId)(options);
9
10
  const config = options.config.src.auth;
10
11
  if (!config) {
11
12
  return;
12
13
  }
13
- const apps = await (0, apps_1.listFirebaseApps)(projectId, apps_1.AppPlatform.WEB);
14
- let app = apps.find((a) => a.displayName === "Default Web App");
15
- if (!app && apps.length > 0) {
16
- app = apps[0];
17
- }
14
+ const apps = await (0, apps_1.listFirebaseApps)(projectId, apps_1.AppPlatform.ANY);
15
+ let app = apps.find((a) => a.displayName === DEFAULT_APP_DISPLAY_NAME) || apps[0];
18
16
  if (!app) {
19
- logger_1.logger.info("No Firebase Web App found. Creating 'Default Web App' for Auth provisioning...");
17
+ logger_1.logger.info(`No Firebase App found. Creating '${DEFAULT_APP_DISPLAY_NAME}' for Auth provisioning...`);
20
18
  app = await (0, apps_1.createWebApp)(projectId, {
21
- displayName: "Default Web App",
19
+ displayName: DEFAULT_APP_DISPLAY_NAME,
22
20
  });
23
21
  }
24
22
  context.auth = context.auth || {};
25
23
  context.auth.appId = app.appId;
24
+ context.auth.platform = app.platform;
26
25
  }
@@ -94,11 +94,11 @@ async function default_1(context, options) {
94
94
  await (0, ensureApiEnabled_1.ensure)(context.projectId, (0, api_1.firestoreOrigin)(), "firestore");
95
95
  if (options.only) {
96
96
  const targets = options.only.split(",");
97
- const excludeRules = targets.indexOf("firestore:indexes") >= 0;
98
- const excludeIndexes = targets.indexOf("firestore:rules") >= 0;
99
- const includeRules = targets.indexOf("firestore:rules") >= 0;
100
- const includeIndexes = targets.indexOf("firestore:indexes") >= 0;
101
- const onlyFirestore = targets.indexOf("firestore") >= 0;
97
+ const excludeRules = targets.includes("firestore:indexes");
98
+ const excludeIndexes = targets.includes("firestore:rules");
99
+ const includeRules = targets.includes("firestore:rules");
100
+ const includeIndexes = targets.includes("firestore:indexes");
101
+ const onlyFirestore = targets.includes("firestore");
102
102
  context.firestoreIndexes = !excludeIndexes || includeIndexes || onlyFirestore;
103
103
  context.firestoreRules = !excludeRules || includeRules || onlyFirestore;
104
104
  }
@@ -94,6 +94,9 @@ async function resolveBackend(opts) {
94
94
  nonInteractive: opts.nonInteractive,
95
95
  isEmulator: opts.isEmulator,
96
96
  });
97
+ if (opts.resolveRegions) {
98
+ await opts.resolveRegions(opts.build, paramValues);
99
+ }
97
100
  return { backend: toBackend(opts.build, paramValues), envs: paramValues, secretRefs: secretRefs };
98
101
  }
99
102
  function envWithTypes(definedParams, rawEnvs) {