firebase-tools-with-isolate 15.32.0 → 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.
- package/lib/accountImporter.js +6 -3
- package/lib/api.js +3 -3
- package/lib/apphosting/backend.js +1 -1
- package/lib/apphosting/secrets/index.js +7 -2
- package/lib/checkValidTargetFilters.js +1 -0
- package/lib/command.js +31 -24
- package/lib/commands/apps-create.js +34 -3
- package/lib/commands/crashlytics-heapdumps-disable.js +26 -0
- package/lib/commands/crashlytics-heapdumps-enable.js +54 -0
- package/lib/commands/crashlytics-heapdumps-status.js +32 -0
- package/lib/commands/deploy.js +3 -0
- package/lib/commands/functions-kits-uninstall.js +43 -21
- package/lib/commands/functions-lifecycle-list.js +5 -6
- package/lib/commands/hosting-channel-deploy.js +3 -3
- package/lib/commands/hosting-clone.js +102 -31
- package/lib/commands/hosting-disable.js +5 -1
- package/lib/commands/index.js +9 -0
- package/lib/commands/init.js +7 -0
- package/lib/commands/run-services-update.js +16 -0
- package/lib/config.js +1 -0
- package/lib/crashlytics/alerts.js +122 -0
- package/lib/crashlytics/onboarding.js +71 -3
- package/lib/crashlytics/profilingManager.js +195 -0
- package/lib/crashlytics/sourcemap.js +46 -11
- package/lib/crashlytics/types.js +6 -1
- package/lib/deploy/apphosting/prepare.js +1 -0
- package/lib/deploy/auth/deploy.js +1 -1
- package/lib/deploy/auth/prepare.js +6 -7
- package/lib/deploy/firestore/prepare.js +5 -5
- package/lib/deploy/functions/build.js +3 -0
- package/lib/deploy/functions/cel.js +89 -58
- package/lib/deploy/functions/functionsDeployHelper.js +10 -0
- package/lib/deploy/functions/params.js +4 -2
- package/lib/deploy/functions/prepare.js +25 -8
- package/lib/deploy/functions/release/executor.js +7 -3
- package/lib/deploy/functions/release/fabricator.js +42 -14
- package/lib/deploy/functions/release/planner.js +3 -2
- package/lib/deploy/functions/release/sourceTokenScraper.js +1 -1
- package/lib/deploy/functions/validate.js +16 -0
- package/lib/deploy/hosting/prepare.js +1 -1
- package/lib/deploy/hosting/release.js +2 -2
- package/lib/deploy/index.js +5 -0
- package/lib/deploy/run/args.js +2 -0
- package/lib/deploy/run/buildEnv.js +72 -0
- package/lib/deploy/run/deploy.js +214 -0
- package/lib/deploy/run/index.js +23 -0
- package/lib/deploy/run/prepare.js +47 -0
- package/lib/deploy/run/prereqs.js +32 -0
- package/lib/deploy/run/release.js +9 -0
- package/lib/deploy/run/update.js +50 -0
- package/lib/deploy/run/util.js +73 -0
- package/lib/emulator/apphosting/serve.js +1 -1
- package/lib/emulator/auth/operations.js +8 -4
- package/lib/emulator/auth/utils.js +1 -1
- package/lib/emulator/commandUtils.js +7 -3
- package/lib/emulator/databaseEmulator.js +7 -3
- package/lib/emulator/dataconnect/pgliteServer.js +1 -1
- package/lib/emulator/dataconnectEmulator.js +1 -1
- package/lib/emulator/download.js +1 -1
- package/lib/emulator/downloadableEmulatorInfo.json +31 -31
- package/lib/emulator/downloadableEmulators.js +1 -3
- package/lib/emulator/emulatorLogger.js +2 -1
- package/lib/emulator/eventarcEmulator.js +1 -1
- package/lib/emulator/functionsEmulatorRuntime.js +2 -1
- package/lib/emulator/functionsEmulatorShared.js +1 -41
- package/lib/experiments.js +17 -11
- package/lib/extensions/warnings.js +48 -7
- package/lib/firestore/validator.js +1 -1
- package/lib/frameworks/next/constants.js +20 -12
- package/lib/frameworks/next/index.js +4 -23
- package/lib/frameworks/next/utils.js +28 -0
- package/lib/functions/env.js +4 -2
- package/lib/functions/projectConfig.js +10 -5
- package/lib/gcp/artifactregistry.js +20 -0
- package/lib/gcp/cloudmonitoring.js +80 -3
- package/lib/gcp/cloudsql/permissions.js +21 -32
- package/lib/gcp/cloudsql/permissionsSetup.js +6 -6
- package/lib/gcp/cloudtasks.js +15 -1
- package/lib/gcp/cloudtrace.js +38 -0
- package/lib/gcp/run.js +5 -0
- package/lib/gcp/runv2.js +32 -11
- package/lib/gcp/storage.js +9 -5
- package/lib/hosting/api.js +15 -15
- package/lib/hosting/runTags.js +1 -1
- package/lib/init/features/auth.js +46 -8
- package/lib/init/features/hosting/index.js +4 -2
- package/lib/init/features/index.js +4 -1
- package/lib/init/features/run.js +159 -0
- package/lib/init/index.js +6 -0
- package/lib/management/apps.js +4 -2
- package/lib/mcp/tools/firestore/converter.js +2 -2
- package/lib/mcp/util.js +11 -10
- package/lib/profileReport.js +12 -9
- package/lib/scopes.js +1 -3
- package/lib/streamJson.js +1 -0
- package/lib/throttler/throttler.js +1 -0
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +0 -15
- package/package.json +11 -17
- package/schema/firebase-config.json +41 -0
- package/schema/firebaserc.json +133 -0
- package/lib/mcp/resources/guides/init_data_connect.js +0 -30
- 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
|
|
15
|
+
.help(`<source> and <targetChannel> accept the following formats:
|
|
16
|
+
- [<projectId>:]<siteId>:<channelId>
|
|
17
|
+
- [<projectId>:]<siteId>@<versionId> (source only)
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
Site projects are automatically discovered if omitted.
|
|
17
20
|
|
|
18
|
-
|
|
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
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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)(
|
|
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
|
-
|
|
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(
|
|
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 =
|
|
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`, {
|
|
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
|
});
|
package/lib/commands/index.js
CHANGED
|
@@ -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 = {};
|
package/lib/commands/init.js
CHANGED
|
@@ -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));
|
package/lib/config.js
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NOTIFICATION_CHANNELS_MASK_PATH = exports.EMAIL_CHANNEL_TYPE = exports.FIREBASE_EMAIL_CHANNEL_DISPLAY_NAME_SUFFIX = exports.FIREBASE_CHANNEL_LABEL = void 0;
|
|
4
|
+
exports.generateAlertPolicy = generateAlertPolicy;
|
|
5
|
+
exports.fetchFirebaseEmailChannel = fetchFirebaseEmailChannel;
|
|
6
|
+
exports.createEmailChannel = createEmailChannel;
|
|
7
|
+
exports.resolveEmailNotificationChannel = resolveEmailNotificationChannel;
|
|
8
|
+
exports.addChannelToPolicy = addChannelToPolicy;
|
|
9
|
+
exports.enableAlert = enableAlert;
|
|
10
|
+
exports.enableAlerts = enableAlerts;
|
|
11
|
+
const error_1 = require("../error");
|
|
12
|
+
const cloudmonitoring_1 = require("../gcp/cloudmonitoring");
|
|
13
|
+
const logger_1 = require("../logger");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
exports.FIREBASE_CHANNEL_LABEL = "is_firebase_channel";
|
|
16
|
+
exports.FIREBASE_EMAIL_CHANNEL_DISPLAY_NAME_SUFFIX = " - for Firebase alerts";
|
|
17
|
+
exports.EMAIL_CHANNEL_TYPE = "email";
|
|
18
|
+
exports.NOTIFICATION_CHANNELS_MASK_PATH = "notification_channels";
|
|
19
|
+
async function generateAlertPolicy(projectId, appId, alertType) {
|
|
20
|
+
logger_1.logger.debug(`[crashlytics] generateAlertPolicy called with projectId: ${projectId}, appId: ${appId}, alertType: ${alertType}`);
|
|
21
|
+
try {
|
|
22
|
+
const response = await utils_1.CRASHLYTICS_API_CLIENT.request({
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
|
+
},
|
|
27
|
+
path: `/projects/${projectId}/apps/${appId}:generateAlertPolicy`,
|
|
28
|
+
body: { alertType },
|
|
29
|
+
timeout: utils_1.TIMEOUT,
|
|
30
|
+
});
|
|
31
|
+
return response.body.alertPolicy;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
const status = (0, error_1.getErrStatus)(err);
|
|
35
|
+
const msg = (0, error_1.getErrMsg)(err);
|
|
36
|
+
throw new error_1.FirebaseError(`Failed to generate Crashlytics alert policy for ${alertType} on app ${appId} (status ${status}): ${msg}`, { original: (0, error_1.getError)(err), status });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function fetchFirebaseEmailChannel(projectId, userEmail) {
|
|
40
|
+
const escapedEmail = userEmail.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
41
|
+
const filter = `type = "${exports.EMAIL_CHANNEL_TYPE}" AND ` +
|
|
42
|
+
`labels.email_address = "${escapedEmail}" AND ` +
|
|
43
|
+
`user_labels.${exports.FIREBASE_CHANNEL_LABEL} = "true"`;
|
|
44
|
+
const channels = await (0, cloudmonitoring_1.listNotificationChannels)(projectId, filter);
|
|
45
|
+
return channels[0];
|
|
46
|
+
}
|
|
47
|
+
async function createEmailChannel(projectId, userEmail) {
|
|
48
|
+
return await (0, cloudmonitoring_1.createNotificationChannel)(projectId, {
|
|
49
|
+
type: exports.EMAIL_CHANNEL_TYPE,
|
|
50
|
+
displayName: `${userEmail}${exports.FIREBASE_EMAIL_CHANNEL_DISPLAY_NAME_SUFFIX}`,
|
|
51
|
+
labels: {
|
|
52
|
+
email_address: userEmail,
|
|
53
|
+
},
|
|
54
|
+
userLabels: {
|
|
55
|
+
[exports.FIREBASE_CHANNEL_LABEL]: "true",
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async function resolveEmailNotificationChannel(projectId, userEmail) {
|
|
60
|
+
const existingChannel = await fetchFirebaseEmailChannel(projectId, userEmail);
|
|
61
|
+
return existingChannel ?? (await createEmailChannel(projectId, userEmail));
|
|
62
|
+
}
|
|
63
|
+
function addChannelToPolicy(policy, channelName) {
|
|
64
|
+
const currentChannels = policy.notificationChannels ?? [];
|
|
65
|
+
if (currentChannels.includes(channelName)) {
|
|
66
|
+
return policy;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...policy,
|
|
70
|
+
notificationChannels: [...currentChannels, channelName],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function enableAlert(projectId, appId, alertType, target) {
|
|
74
|
+
let channel;
|
|
75
|
+
if (!target.channelName && target.userEmail) {
|
|
76
|
+
channel = await resolveEmailNotificationChannel(projectId, target.userEmail);
|
|
77
|
+
}
|
|
78
|
+
else if (!target.channelName) {
|
|
79
|
+
throw new error_1.FirebaseError("Either channelName or userEmail must be specified to enable a Crashlytics alert.", { exit: 1 });
|
|
80
|
+
}
|
|
81
|
+
const channelName = target.channelName ?? channel?.name;
|
|
82
|
+
if (!channelName) {
|
|
83
|
+
throw new error_1.FirebaseError("Resolved notification channel is missing a resource name.", {
|
|
84
|
+
exit: 1,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const policyResourceName = await generateAlertPolicy(projectId, appId, alertType);
|
|
88
|
+
const targetPolicy = await (0, cloudmonitoring_1.getAlertPolicy)(policyResourceName);
|
|
89
|
+
const policyWithChannel = addChannelToPolicy(targetPolicy, channelName);
|
|
90
|
+
const updatedPolicy = policyWithChannel === targetPolicy
|
|
91
|
+
? targetPolicy
|
|
92
|
+
: await (0, cloudmonitoring_1.updateAlertPolicy)(policyWithChannel, exports.NOTIFICATION_CHANNELS_MASK_PATH);
|
|
93
|
+
return { channel, policy: updatedPolicy };
|
|
94
|
+
}
|
|
95
|
+
async function enableAlerts(projectId, appId, alertTypes, userEmail) {
|
|
96
|
+
if (alertTypes.length === 0) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
const channel = await resolveEmailNotificationChannel(projectId, userEmail);
|
|
100
|
+
const channelName = channel.name;
|
|
101
|
+
if (!channelName) {
|
|
102
|
+
throw new error_1.FirebaseError("Notification channel for Crashlytics alerts is missing a name.", {
|
|
103
|
+
exit: 1,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const results = await Promise.allSettled(alertTypes.map(async (alertType) => {
|
|
107
|
+
const { policy } = await enableAlert(projectId, appId, alertType, {
|
|
108
|
+
channelName,
|
|
109
|
+
});
|
|
110
|
+
return policy;
|
|
111
|
+
}));
|
|
112
|
+
const policies = [];
|
|
113
|
+
for (const res of results) {
|
|
114
|
+
if (res.status === "fulfilled") {
|
|
115
|
+
policies.push(res.value);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
logger_1.logger.debug(`[crashlytics] Failed to enable alert: ${(0, error_1.getErrMsg)(res.reason)}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return policies;
|
|
122
|
+
}
|
|
@@ -4,16 +4,35 @@ exports.CRASHLYTICS_TELEMETRY_SERVICE = exports.CRASHLYTICS_TELEMETRY_RESOURCE_T
|
|
|
4
4
|
exports.onboardCrashlyticsWeb = onboardCrashlyticsWeb;
|
|
5
5
|
const ensureApiEnabled_1 = require("../ensureApiEnabled");
|
|
6
6
|
const error_1 = require("../error");
|
|
7
|
+
const experiments = require("../experiments");
|
|
7
8
|
const cloudbilling_1 = require("../gcp/cloudbilling");
|
|
8
9
|
const cloudlogging_1 = require("../gcp/cloudlogging");
|
|
10
|
+
const alerts_1 = require("./alerts");
|
|
9
11
|
const firebasetelemetry_1 = require("./firebasetelemetry");
|
|
12
|
+
const types_1 = require("./types");
|
|
10
13
|
const utils_1 = require("../utils");
|
|
11
14
|
const apikeys_1 = require("../gcp/apikeys");
|
|
15
|
+
const cloudtrace_1 = require("../gcp/cloudtrace");
|
|
12
16
|
const apps_1 = require("../management/apps");
|
|
17
|
+
const logger_1 = require("../logger");
|
|
18
|
+
const prompt_1 = require("../prompt");
|
|
19
|
+
const requireAuth_1 = require("../requireAuth");
|
|
13
20
|
exports.CRASHLYTICS_TELEMETRY_BUCKET_ID = "firebase-telemetry";
|
|
14
21
|
exports.CRASHLYTICS_TELEMETRY_SINK_ID = "firebase-telemetry-routing";
|
|
15
22
|
exports.CRASHLYTICS_TELEMETRY_RESOURCE_TYPE = "firebasetelemetry.googleapis.com/App";
|
|
16
23
|
exports.CRASHLYTICS_TELEMETRY_SERVICE = "firebasetelemetry.googleapis.com";
|
|
24
|
+
async function resolveAuthenticatedUserEmail(options) {
|
|
25
|
+
if (options.user?.email) {
|
|
26
|
+
return options.user.email;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return (await (0, requireAuth_1.requireAuth)(options)) ?? undefined;
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
logger_1.logger.debug(`[crashlytics] Failed to resolve authenticated user email: ${(0, error_1.getErrMsg)(err)}`);
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
17
36
|
async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
|
|
18
37
|
const billingEnabled = await (0, cloudbilling_1.checkBillingEnabled)(projectId);
|
|
19
38
|
if (!billingEnabled && options.nonInteractive) {
|
|
@@ -24,10 +43,14 @@ async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
|
|
|
24
43
|
await (0, cloudbilling_1.enableBilling)(projectId, "Crashlytics");
|
|
25
44
|
}
|
|
26
45
|
(0, utils_1.logLabeledBullet)("crashlytics", "Enabling required telemetry APIs...");
|
|
27
|
-
|
|
46
|
+
const requiredApis = [
|
|
28
47
|
(0, ensureApiEnabled_1.ensure)(projectId, exports.CRASHLYTICS_TELEMETRY_SERVICE, "crashlytics", false),
|
|
29
48
|
(0, ensureApiEnabled_1.ensure)(projectId, "firebasetelemetryadmin.googleapis.com", "crashlytics", false),
|
|
30
|
-
]
|
|
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);
|
|
31
54
|
(0, utils_1.logLabeledSuccess)("crashlytics", "Telemetry APIs enabled.");
|
|
32
55
|
const appConfig = await (0, apps_1.getAppConfig)(appId, apps_1.AppPlatform.WEB);
|
|
33
56
|
if ("apiKey" in appConfig && appConfig.apiKey) {
|
|
@@ -55,8 +78,53 @@ async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
|
|
|
55
78
|
(0, utils_1.logLabeledBullet)("crashlytics", `Setting up Cloud Logging routing sink '${exports.CRASHLYTICS_TELEMETRY_SINK_ID}'...`);
|
|
56
79
|
const sink = await (0, cloudlogging_1.createOrUpdateLogSink)(projectId, exports.CRASHLYTICS_TELEMETRY_SINK_ID, destination, filter);
|
|
57
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
|
+
}
|
|
58
91
|
(0, utils_1.logLabeledBullet)("crashlytics", "Configuring Crashlytics telemetry for web app...");
|
|
59
92
|
const config = await (0, firebasetelemetry_1.createOrUpdateTelemetryConfig)(projectId, appId, `projects/${projectId}/locations/global/buckets/${exports.CRASHLYTICS_TELEMETRY_BUCKET_ID}`, 1);
|
|
60
93
|
(0, utils_1.logLabeledSuccess)("crashlytics", "Crashlytics telemetry configured successfully.");
|
|
61
|
-
|
|
94
|
+
if (!experiments.isEnabled("crashlyticsWebAlerts") || options.nonInteractive) {
|
|
95
|
+
return { bucket, sink, config };
|
|
96
|
+
}
|
|
97
|
+
const userEmail = await resolveAuthenticatedUserEmail(options);
|
|
98
|
+
if (!userEmail) {
|
|
99
|
+
(0, utils_1.logLabeledWarning)("crashlytics", "Unable to determine authenticated user email for alert setup. You can configure alerts later in the Firebase Console.");
|
|
100
|
+
return { bucket, sink, config };
|
|
101
|
+
}
|
|
102
|
+
const selectedAlerts = await (0, prompt_1.checkbox)({
|
|
103
|
+
message: "Which email alerts would you like to enable? (Optional)",
|
|
104
|
+
choices: [
|
|
105
|
+
{
|
|
106
|
+
name: "New issues (Notify when a new issue is detected)",
|
|
107
|
+
value: types_1.AlertType.ALERT_TYPE_NEW_ISSUE,
|
|
108
|
+
checked: true,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "Regressed issues (Notify when a closed issue reoccurs)",
|
|
112
|
+
value: types_1.AlertType.ALERT_TYPE_REGRESSED_ISSUE,
|
|
113
|
+
checked: true,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
if (selectedAlerts.length === 0) {
|
|
118
|
+
return { bucket, sink, config };
|
|
119
|
+
}
|
|
120
|
+
(0, utils_1.logLabeledBullet)("crashlytics", `Setting up Crashlytics email alerts for ${userEmail}...`);
|
|
121
|
+
try {
|
|
122
|
+
const alertPolicies = await (0, alerts_1.enableAlerts)(projectId, appId, selectedAlerts, userEmail);
|
|
123
|
+
(0, utils_1.logLabeledSuccess)("crashlytics", "Crashlytics email alerts configured successfully.");
|
|
124
|
+
return { bucket, sink, config, alertPolicies };
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
(0, utils_1.logLabeledWarning)("crashlytics", (0, error_1.getErrMsg)(err));
|
|
128
|
+
return { bucket, sink, config };
|
|
129
|
+
}
|
|
62
130
|
}
|