firebase-tools 15.32.0 → 15.33.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/secrets/index.js +7 -2
- package/lib/command.js +1 -1
- package/lib/commands/apps-create.js +34 -3
- 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 +60 -29
- package/lib/commands/hosting-disable.js +5 -1
- package/lib/config.js +1 -0
- package/lib/crashlytics/alerts.js +122 -0
- package/lib/crashlytics/onboarding.js +71 -3
- package/lib/crashlytics/sourcemap.js +46 -11
- package/lib/crashlytics/types.js +6 -1
- 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/fabricator.js +1 -5
- package/lib/deploy/functions/release/planner.js +3 -2
- 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/emulator/auth/operations.js +8 -4
- package/lib/emulator/databaseEmulator.js +7 -3
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/emulatorLogger.js +2 -1
- package/lib/emulator/functionsEmulatorRuntime.js +2 -1
- package/lib/experiments.js +17 -0
- package/lib/extensions/warnings.js +48 -7
- 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/gcp/artifactregistry.js +20 -0
- package/lib/gcp/cloudmonitoring.js +80 -3
- 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/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/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 +4 -4
- package/lib/scopes.js +1 -3
- package/lib/streamJson.js +1 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +0 -15
- package/package.json +10 -9
- package/schema/firebase-config.json +41 -0
package/lib/accountImporter.js
CHANGED
|
@@ -191,13 +191,14 @@ function validateRequiredParameters(options) {
|
|
|
191
191
|
case "MD5":
|
|
192
192
|
case "SHA1":
|
|
193
193
|
case "SHA256":
|
|
194
|
-
case "SHA512":
|
|
194
|
+
case "SHA512": {
|
|
195
195
|
roundsNum = parseInt(options.rounds, 10);
|
|
196
196
|
const minRounds = hashAlgo === "MD5" ? 0 : 1;
|
|
197
197
|
if (isNaN(roundsNum) || roundsNum < minRounds || roundsNum > 8192) {
|
|
198
198
|
throw new error_1.FirebaseError(`Must provide valid rounds(${minRounds}..8192) for hash algorithm ${options.hashAlgo}`);
|
|
199
199
|
}
|
|
200
200
|
return { hashAlgo: hashAlgo, rounds: options.rounds, valid: true };
|
|
201
|
+
}
|
|
201
202
|
case "PBKDF_SHA1":
|
|
202
203
|
case "PBKDF2_SHA256":
|
|
203
204
|
roundsNum = parseInt(options.rounds, 10);
|
|
@@ -205,7 +206,7 @@ function validateRequiredParameters(options) {
|
|
|
205
206
|
throw new error_1.FirebaseError("Must provide valid rounds(0..120000) for hash algorithm " + options.hashAlgo);
|
|
206
207
|
}
|
|
207
208
|
return { hashAlgo: hashAlgo, rounds: options.rounds, valid: true };
|
|
208
|
-
case "SCRYPT":
|
|
209
|
+
case "SCRYPT": {
|
|
209
210
|
if (!options.hashKey || options.hashKey === "") {
|
|
210
211
|
throw new error_1.FirebaseError("Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo);
|
|
211
212
|
}
|
|
@@ -229,9 +230,10 @@ function validateRequiredParameters(options) {
|
|
|
229
230
|
memCost: options.memCost,
|
|
230
231
|
valid: true,
|
|
231
232
|
};
|
|
233
|
+
}
|
|
232
234
|
case "BCRYPT":
|
|
233
235
|
return { hashAlgo: hashAlgo, valid: true };
|
|
234
|
-
case "STANDARD_SCRYPT":
|
|
236
|
+
case "STANDARD_SCRYPT": {
|
|
235
237
|
const cpuMemCost = parseInt(options.memCost, 10);
|
|
236
238
|
const parallelization = parseInt(options.parallelization, 10);
|
|
237
239
|
const blockSize = parseInt(options.blockSize, 10);
|
|
@@ -244,6 +246,7 @@ function validateRequiredParameters(options) {
|
|
|
244
246
|
blockSize: blockSize,
|
|
245
247
|
dkLen: dkLen,
|
|
246
248
|
};
|
|
249
|
+
}
|
|
247
250
|
default:
|
|
248
251
|
throw new error_1.FirebaseError("Unsupported hash algorithm " + clc.bold(options.hashAlgo));
|
|
249
252
|
}
|
package/lib/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rulesOrigin = exports.resourceManagerOrigin = exports.firebaseTelemetryAdminOrigin = exports.
|
|
3
|
+
exports.rulesOrigin = exports.resourceManagerOrigin = exports.firebaseTelemetryAdminOrigin = exports.crashlyticsApiOrigin = exports.messagingApiOrigin = exports.remoteConfigApiOrigin = exports.rtdbMetadataOrigin = exports.rtdbManagementOrigin = exports.realtimeOrigin = exports.extensionsTOSOrigin = exports.extensionsPublisherOrigin = exports.extensionsOrigin = exports.iamOrigin = exports.identityOrigin = exports.hostingOrigin = exports.googleOrigin = exports.pubsubOrigin = exports.cloudTasksOrigin = exports.cloudschedulerOrigin = exports.cloudbuildOrigin = exports.functionsDefaultRegion = exports.runOrigin = exports.functionsV2Origin = exports.functionsOrigin = exports.firestoreOrigin = exports.firestoreOriginOrEmulator = exports.firedataOrigin = exports.firebaseExtensionsRegistryOrigin = exports.firebaseApiOrigin = exports.eventarcOrigin = exports.consoleOrigin = exports.authManagementOrigin = exports.authOrigin = exports.apphostingGitHubAppInstallationURL = exports.apphostingP4SADomain = exports.apphostingOrigin = exports.appDistributionOrigin = exports.appCheckOrigin = exports.apiKeysOrigin = exports.artifactRegistryDomain = exports.developerConnectP4SADomain = exports.developerConnectOrigin = exports.containerRegistryDomain = exports.cloudTraceOrigin = exports.cloudMonitoringOrigin = exports.cloudloggingOrigin = exports.cloudbillingOrigin = exports.clientSecret = exports.clientId = exports.authProxyOrigin = void 0;
|
|
4
4
|
exports.developerKnowledgeOrigin = exports.cloudTestingOrigin = exports.appTestingOrigin = exports.aiLogicProxyOrigin = exports.vertexAIOrigin = exports.cloudSQLAdminOrigin = exports.dataConnectLocalConnString = exports.dataconnectP4SADomain = exports.dataconnectOrigin = exports.githubClientSecret = exports.githubClientId = exports.computeOrigin = exports.secretManagerOrigin = exports.githubApiOrigin = exports.githubOrigin = exports.studioApiOrigin = exports.serviceUsageOrigin = exports.cloudRunApiOrigin = exports.hostingApiOrigin = exports.firebaseStorageOrigin = exports.storageOrigin = exports.runtimeconfigOrigin = void 0;
|
|
5
5
|
exports.getScopes = getScopes;
|
|
6
6
|
exports.setScopes = setScopes;
|
|
@@ -21,6 +21,8 @@ const cloudloggingOrigin = () => utils.envOverride("FIREBASE_CLOUDLOGGING_URL",
|
|
|
21
21
|
exports.cloudloggingOrigin = cloudloggingOrigin;
|
|
22
22
|
const cloudMonitoringOrigin = () => utils.envOverride("CLOUD_MONITORING_URL", "https://monitoring.googleapis.com");
|
|
23
23
|
exports.cloudMonitoringOrigin = cloudMonitoringOrigin;
|
|
24
|
+
const cloudTraceOrigin = () => utils.envOverride("CLOUD_TRACE_URL", "https://cloudtrace.googleapis.com");
|
|
25
|
+
exports.cloudTraceOrigin = cloudTraceOrigin;
|
|
24
26
|
const containerRegistryDomain = () => utils.envOverride("CONTAINER_REGISTRY_DOMAIN", "gcr.io");
|
|
25
27
|
exports.containerRegistryDomain = containerRegistryDomain;
|
|
26
28
|
const developerConnectOrigin = () => utils.envOverride("DEVELOPERCONNECT_URL", "https://developerconnect.googleapis.com");
|
|
@@ -106,8 +108,6 @@ const messagingApiOrigin = () => utils.envOverride("FIREBASE_MESSAGING_CONFIG_UR
|
|
|
106
108
|
exports.messagingApiOrigin = messagingApiOrigin;
|
|
107
109
|
const crashlyticsApiOrigin = () => utils.envOverride("FIREBASE_CRASHLYTICS_URL", "https://firebasecrashlytics.googleapis.com");
|
|
108
110
|
exports.crashlyticsApiOrigin = crashlyticsApiOrigin;
|
|
109
|
-
const firebaseTelemetryOrigin = () => utils.envOverride("FIREBASE_TELEMETRY_URL", "https://firebasetelemetry.googleapis.com");
|
|
110
|
-
exports.firebaseTelemetryOrigin = firebaseTelemetryOrigin;
|
|
111
111
|
const firebaseTelemetryAdminOrigin = () => utils.envOverride("FIREBASE_TELEMETRY_ADMIN_URL", "https://firebasetelemetryadmin.googleapis.com");
|
|
112
112
|
exports.firebaseTelemetryAdminOrigin = firebaseTelemetryAdminOrigin;
|
|
113
113
|
const resourceManagerOrigin = () => utils.envOverride("FIREBASE_RESOURCEMANAGER_URL", "https://cloudresourcemanager.googleapis.com");
|
|
@@ -200,8 +200,13 @@ async function upsertSecret(project, secret, location) {
|
|
|
200
200
|
existing = await gcsm.getSecret(project, secret);
|
|
201
201
|
}
|
|
202
202
|
catch (err) {
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
const status = (0, error_1.getErrStatus)(err);
|
|
204
|
+
if (status !== 404) {
|
|
205
|
+
const original = (0, error_1.getError)(err);
|
|
206
|
+
throw new error_1.FirebaseError(`Unexpected error loading secret: ${original.message}`, {
|
|
207
|
+
original,
|
|
208
|
+
status,
|
|
209
|
+
});
|
|
205
210
|
}
|
|
206
211
|
await gcsm.createSecret(project, secret, gcsm.labels("apphosting"), location);
|
|
207
212
|
return true;
|
package/lib/command.js
CHANGED
|
@@ -272,7 +272,7 @@ class Command {
|
|
|
272
272
|
const options = (0, lodash_1.last)(args);
|
|
273
273
|
await this.prepare(options);
|
|
274
274
|
if (this.name.startsWith("ext:") && experiments.isEnabled("extdeprecationwarnings")) {
|
|
275
|
-
(0, warnings_1.showDeprecationWarningBefore)(this.name, options);
|
|
275
|
+
await (0, warnings_1.showDeprecationWarningBefore)(this.name, options, args);
|
|
276
276
|
}
|
|
277
277
|
for (const before of this.befores) {
|
|
278
278
|
await before.fn(options, ...before.args);
|
|
@@ -9,6 +9,10 @@ const apps_1 = require("../management/apps");
|
|
|
9
9
|
const requireAuth_1 = require("../requireAuth");
|
|
10
10
|
const logger_1 = require("../logger");
|
|
11
11
|
const prompt_1 = require("../prompt");
|
|
12
|
+
const getDefaultHostingSite_1 = require("../getDefaultHostingSite");
|
|
13
|
+
const interactive_1 = require("../hosting/interactive");
|
|
14
|
+
const api_1 = require("../hosting/api");
|
|
15
|
+
const utils_1 = require("../utils");
|
|
12
16
|
function logPostAppCreationInformation(appMetadata, appPlatform) {
|
|
13
17
|
logger_1.logger.info("");
|
|
14
18
|
logger_1.logger.info(`🎉🎉🎉 Your Firebase ${appPlatform} App is ready! 🎉🎉🎉`);
|
|
@@ -40,8 +44,9 @@ exports.command = new command_1.Command("apps:create [platform] [displayName]")
|
|
|
40
44
|
.before(requireAuth_1.requireAuth)
|
|
41
45
|
.action(async (platform = "", displayName, options) => {
|
|
42
46
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
let chosenPlatform = typeof platform === "string" ? platform : "";
|
|
48
|
+
if (!options.nonInteractive && !chosenPlatform) {
|
|
49
|
+
chosenPlatform = await (0, prompt_1.select)({
|
|
45
50
|
message: "Please choose the platform of the app:",
|
|
46
51
|
choices: [
|
|
47
52
|
{ name: "iOS", value: apps_1.AppPlatform.IOS },
|
|
@@ -50,13 +55,39 @@ exports.command = new command_1.Command("apps:create [platform] [displayName]")
|
|
|
50
55
|
],
|
|
51
56
|
});
|
|
52
57
|
}
|
|
53
|
-
const appPlatform = (0, apps_1.getAppPlatform)(
|
|
58
|
+
const appPlatform = (0, apps_1.getAppPlatform)(chosenPlatform);
|
|
54
59
|
if (appPlatform === apps_1.AppPlatform.ANY) {
|
|
55
60
|
throw new error_1.FirebaseError("App platform must be provided");
|
|
56
61
|
}
|
|
57
62
|
logger_1.logger.info(`Create your ${appPlatform} app in project ${clc.bold(projectId)}:`);
|
|
63
|
+
let newSiteId;
|
|
64
|
+
if (appPlatform === apps_1.AppPlatform.WEB) {
|
|
65
|
+
const existingSite = await (0, getDefaultHostingSite_1.getDefaultHostingSite)({ projectId }).catch((err) => {
|
|
66
|
+
if (err !== getDefaultHostingSite_1.errNoDefaultSite) {
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (existingSite) {
|
|
71
|
+
logger_1.logger.info(`Firebase Hosting site is present: ${clc.bold(existingSite)}.`);
|
|
72
|
+
}
|
|
73
|
+
else if (await (0, prompt_1.confirm)({
|
|
74
|
+
message: "A Firebase Hosting site is recommended for Web apps. Would you like to create a default site now?",
|
|
75
|
+
default: true,
|
|
76
|
+
nonInteractive: options.nonInteractive,
|
|
77
|
+
})) {
|
|
78
|
+
newSiteId = await (0, interactive_1.pickHostingSiteName)("", {
|
|
79
|
+
projectId,
|
|
80
|
+
nonInteractive: options.nonInteractive,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
58
84
|
options.displayName = displayName;
|
|
59
85
|
const appData = await (0, apps_1.sdkInit)(appPlatform, options);
|
|
86
|
+
if (newSiteId) {
|
|
87
|
+
await (0, api_1.createSite)(projectId, newSiteId, appData.appId);
|
|
88
|
+
logger_1.logger.info("");
|
|
89
|
+
(0, utils_1.logSuccess)(`Firebase Hosting site ${newSiteId} created!`);
|
|
90
|
+
}
|
|
60
91
|
logPostAppCreationInformation(appData, appPlatform);
|
|
61
92
|
return appData;
|
|
62
93
|
});
|
|
@@ -13,6 +13,7 @@ const projectUtils_1 = require("../projectUtils");
|
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
14
|
const logger_1 = require("../logger");
|
|
15
15
|
const delete_1 = require("../deploy/functions/delete");
|
|
16
|
+
const ENV_FILE_PREFIX = ".env.";
|
|
16
17
|
exports.command = new command_1.Command("functions:kits:uninstall")
|
|
17
18
|
.description("uninstall a function kit or kit instance from your project. Deletes all running resources and the associated managed service account.")
|
|
18
19
|
.before(requireConfig_1.requireConfig)
|
|
@@ -73,10 +74,7 @@ async function handleInstance(options, config) {
|
|
|
73
74
|
const instanceConfigDirPath = kitForInstance.instances[instanceId];
|
|
74
75
|
const conservativeDeletion = nonstandardKitLayout(kitForInstance);
|
|
75
76
|
logger_1.logger.debug(`Kit ${kitForInstance.kit} uninstall mode: conservativeDeletion=${conservativeDeletion}`);
|
|
76
|
-
const
|
|
77
|
-
const envFileNames = configDirContents
|
|
78
|
-
.filter((f) => f.isFile() && f.name.startsWith(".env."))
|
|
79
|
-
.map((f) => f.name.slice(".env.".length));
|
|
77
|
+
const envFileNames = getInstanceEnvNames(config, instanceConfigDirPath);
|
|
80
78
|
const projectNamesInEnvs = envFileNames.map((envName) => options.rc ? options.rc.resolveAlias(envName) : envName);
|
|
81
79
|
if (projectNamesInEnvs.length > 0 && !projectNamesInEnvs.includes(projectId)) {
|
|
82
80
|
throw new error_1.FirebaseError(`Instance at ${instanceConfigDirPath} contains no .env file for current project`);
|
|
@@ -101,7 +99,7 @@ async function handleInstance(options, config) {
|
|
|
101
99
|
let filesystemNameForProject = projectId;
|
|
102
100
|
const envFilesWhichAliasToProject = envFileNames.filter((name) => (options.rc?.resolveAlias(name) || name) === projectId);
|
|
103
101
|
if (envFilesWhichAliasToProject.length > 1) {
|
|
104
|
-
throw new error_1.FirebaseError(`Instance ${instanceId} contains multiple .env files which ambiguously resolve to the current project ${envFilesWhichAliasToProject.map((s) =>
|
|
102
|
+
throw new error_1.FirebaseError(`Instance ${instanceId} contains multiple .env files which ambiguously resolve to the current project ${envFilesWhichAliasToProject.map((s) => ENV_FILE_PREFIX + s).join(", ")}`);
|
|
105
103
|
}
|
|
106
104
|
if (envFilesWhichAliasToProject.length === 1) {
|
|
107
105
|
filesystemNameForProject = envFilesWhichAliasToProject[0];
|
|
@@ -109,18 +107,8 @@ async function handleInstance(options, config) {
|
|
|
109
107
|
await uninstallProjectInstance(options, config, filesystemNameForProject, instanceId, instanceConfigDirPath);
|
|
110
108
|
}
|
|
111
109
|
async function uninstallInstance(options, config, instanceId, instanceConfigDirPath, onlyDeleteEmpty) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
for (const fileName of fileNames) {
|
|
115
|
-
if (!fileName.startsWith(".env.")) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const projectIdOrAlias = fileName.slice(".env.".length);
|
|
119
|
-
await uninstallProjectInstance(options, config, projectIdOrAlias, instanceId, instanceConfigDirPath);
|
|
120
|
-
}
|
|
121
|
-
if (!onlyDeleteEmpty || configDirEmpty(config, instanceConfigDirPath)) {
|
|
122
|
-
config.deleteProjectDir(instanceConfigDirPath);
|
|
123
|
-
}
|
|
110
|
+
await deleteInstancesFunctions(options, config, { [instanceId]: instanceConfigDirPath });
|
|
111
|
+
deleteInstanceConfigFiles(config, instanceConfigDirPath, onlyDeleteEmpty);
|
|
124
112
|
let functionsConfig = config.src.functions ?? [];
|
|
125
113
|
if (!Array.isArray(functionsConfig)) {
|
|
126
114
|
functionsConfig = [functionsConfig];
|
|
@@ -141,7 +129,7 @@ async function uninstallInstance(options, config, instanceId, instanceConfigDirP
|
|
|
141
129
|
}
|
|
142
130
|
async function uninstallProjectInstance(options, config, envName, instanceId, kitInstancePath) {
|
|
143
131
|
const projectId = options.rc?.resolveAlias(envName) || envName;
|
|
144
|
-
const envFilePath = (0, path_1.join)(kitInstancePath,
|
|
132
|
+
const envFilePath = (0, path_1.join)(kitInstancePath, `${ENV_FILE_PREFIX}${envName}`);
|
|
145
133
|
if (!config.projectFileExists(envFilePath)) {
|
|
146
134
|
throw new error_1.FirebaseError(`Expected to clean up project kit instance .env file at ${envFilePath}, but it doesn't exist.`);
|
|
147
135
|
}
|
|
@@ -155,10 +143,11 @@ async function uninstallProjectInstance(options, config, envName, instanceId, ki
|
|
|
155
143
|
}
|
|
156
144
|
async function uninstallKit(options, config, kit) {
|
|
157
145
|
const conservativeDeletion = nonstandardKitLayout(kit);
|
|
158
|
-
|
|
159
|
-
await uninstallInstance(options, config, instanceId, instanceConfigDir, conservativeDeletion);
|
|
160
|
-
}
|
|
146
|
+
await deleteInstancesFunctions(options, config, kit.instances);
|
|
161
147
|
if (conservativeDeletion) {
|
|
148
|
+
for (const instanceConfigDir of Object.values(kit.instances)) {
|
|
149
|
+
deleteInstanceConfigFiles(config, instanceConfigDir);
|
|
150
|
+
}
|
|
162
151
|
const instanceConfigDirParents = Object.values(kit.instances).map((p) => (0, posix_1.dirname)(p));
|
|
163
152
|
if (instanceConfigDirParents.length > 0 &&
|
|
164
153
|
instanceConfigDirParents.every((p) => p === instanceConfigDirParents[0]) &&
|
|
@@ -184,6 +173,33 @@ async function uninstallKit(options, config, kit) {
|
|
|
184
173
|
config.set("functions", functionsConfig);
|
|
185
174
|
config.writeProjectFile("firebase.json", config.src);
|
|
186
175
|
}
|
|
176
|
+
async function deleteInstancesFunctions(options, config, instances) {
|
|
177
|
+
const instancesByProject = new Map();
|
|
178
|
+
for (const [instanceId, instanceConfigDir] of Object.entries(instances)) {
|
|
179
|
+
for (const projectIdOrAlias of getInstanceEnvNames(config, instanceConfigDir)) {
|
|
180
|
+
const projectId = options.rc ? options.rc.resolveAlias(projectIdOrAlias) : projectIdOrAlias;
|
|
181
|
+
const list = instancesByProject.get(projectId) ?? [];
|
|
182
|
+
list.push(instanceId);
|
|
183
|
+
instancesByProject.set(projectId, list);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const [projectId, instanceIds] of instancesByProject.entries()) {
|
|
187
|
+
const epFilters = instanceIds.map((id) => ({ codebase: id }));
|
|
188
|
+
const deployContext = { projectId, filters: epFilters };
|
|
189
|
+
const deletionCount = await (0, delete_1.deleteFunctionsByEndpointFilters)(deployContext, options);
|
|
190
|
+
if (deletionCount === 0) {
|
|
191
|
+
logger_1.logger.info(`No deployed functions found for instances: ${instanceIds.join(", ")}. This is normal if firebase deploy was never run.`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function deleteInstanceConfigFiles(config, instanceConfigDirPath, onlyDeleteEmpty = true) {
|
|
196
|
+
for (const projectIdOrAlias of getInstanceEnvNames(config, instanceConfigDirPath)) {
|
|
197
|
+
config.deleteProjectFile((0, path_1.join)(instanceConfigDirPath, `${ENV_FILE_PREFIX}${projectIdOrAlias}`));
|
|
198
|
+
}
|
|
199
|
+
if (!onlyDeleteEmpty || configDirEmpty(config, instanceConfigDirPath)) {
|
|
200
|
+
config.deleteProjectDir(instanceConfigDirPath);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
187
203
|
function nonstandardKitLayout(kitConfig) {
|
|
188
204
|
if (kitConfig.sourcePackage) {
|
|
189
205
|
if (kitConfig.source !== `function-kits/${kitConfig.kit}/source`) {
|
|
@@ -209,3 +225,9 @@ function configDirEmpty(config, projectRelativePath) {
|
|
|
209
225
|
}
|
|
210
226
|
return true;
|
|
211
227
|
}
|
|
228
|
+
function getInstanceEnvNames(config, instanceConfigDirPath) {
|
|
229
|
+
return config
|
|
230
|
+
.lsProjectDir(instanceConfigDirPath)
|
|
231
|
+
.filter((f) => f.isFile() && f.name.startsWith(ENV_FILE_PREFIX))
|
|
232
|
+
.map((f) => f.name.slice(ENV_FILE_PREFIX.length));
|
|
233
|
+
}
|
|
@@ -19,16 +19,13 @@ async function loadCodebaseBuild(codebase, options) {
|
|
|
19
19
|
throw new error_1.FirebaseError("Not in a Firebase project directory (firebase.json not found).");
|
|
20
20
|
}
|
|
21
21
|
const fnConfig = (0, projectConfig_1.normalizeAndValidate)(options.config.src.functions);
|
|
22
|
-
const
|
|
23
|
-
if (!hasCodebase) {
|
|
24
|
-
throw new error_1.FirebaseError(`Codebase "${codebase}" is not defined in firebase.json.`);
|
|
25
|
-
}
|
|
22
|
+
const codebaseConfig = (0, projectConfig_1.configForCodebase)(fnConfig, codebase);
|
|
26
23
|
const firebaseConfig = await (0, adminSdkConfig_1.getProjectAdminSdkConfigOrCached)(projectId);
|
|
27
24
|
if (!firebaseConfig) {
|
|
28
25
|
throw new error_1.FirebaseError("Admin SDK config unexpectedly undefined - have you run firebase init?");
|
|
29
26
|
}
|
|
30
27
|
let runtimeConfig = { firebase: firebaseConfig };
|
|
31
|
-
if (
|
|
28
|
+
if ((0, projectConfig_1.shouldUseRuntimeConfig)(codebaseConfig)) {
|
|
32
29
|
try {
|
|
33
30
|
const runtimeConfigApiEnabled = await ensureApiEnabled.check(projectId, (0, api_1.runtimeconfigOrigin)(), "runtimeconfig", true);
|
|
34
31
|
if (runtimeConfigApiEnabled) {
|
|
@@ -39,7 +36,9 @@ async function loadCodebaseBuild(codebase, options) {
|
|
|
39
36
|
logger_1.logger.debug("Could not check Runtime Config API status, assuming disabled:", err);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
|
-
const wantBuilds = await (0, prepare_1.loadCodebases)(fnConfig, options, firebaseConfig, runtimeConfig,
|
|
39
|
+
const wantBuilds = await (0, prepare_1.loadCodebases)(fnConfig, options, firebaseConfig, runtimeConfig, [
|
|
40
|
+
{ codebase },
|
|
41
|
+
]);
|
|
43
42
|
const codebaseBuild = wantBuilds[codebase];
|
|
44
43
|
if (!codebaseBuild) {
|
|
45
44
|
throw new error_1.FirebaseError(`Failed to load build for codebase "${codebase}".`);
|
|
@@ -112,13 +112,13 @@ async function hostingChannelDeployAction(channelId, options) {
|
|
|
112
112
|
if (d.expireTime) {
|
|
113
113
|
expires = `[expires ${(0, colorette_1.bold)((0, utils_1.datetimeString)(new Date(d.expireTime)))}]`;
|
|
114
114
|
}
|
|
115
|
-
const versionPrefix = `sites/${d.site}/versions/`;
|
|
115
|
+
const versionPrefix = `projects/${projectId}/sites/${d.site}/versions/`;
|
|
116
116
|
const versionName = versionNames.find((v) => {
|
|
117
|
-
return v.startsWith(versionPrefix);
|
|
117
|
+
return v.startsWith(versionPrefix) || v.startsWith(`sites/${d.site}/versions/`);
|
|
118
118
|
});
|
|
119
119
|
let version = "";
|
|
120
120
|
if (versionName) {
|
|
121
|
-
d.version = versionName.
|
|
121
|
+
d.version = (0, utils_1.last)(versionName.split("/")) || "";
|
|
122
122
|
version = ` [version ${(0, colorette_1.bold)(d.version)}]`;
|
|
123
123
|
}
|
|
124
124
|
(0, utils_1.logLabeledSuccess)(LOG_TAG, `Channel URL (${(0, colorette_1.bold)(d.site || d.target || "")}): ${d.url} ${expires}${version}`);
|
|
@@ -9,6 +9,7 @@ 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
15
|
.help(`<source> and <targetChannel> accept the following format: <siteId>:<channelId>
|
|
@@ -17,32 +18,64 @@ For example, to copy the content for a site \`my-site\` from a preview channel \
|
|
|
17
18
|
|
|
18
19
|
firebase hosting:clone my-site:foo my-site:live`)
|
|
19
20
|
.before(requireAuth_1.requireAuth)
|
|
20
|
-
.action(async (source = "", targetChannel = "") => {
|
|
21
|
-
let
|
|
21
|
+
.action(async (source = "", targetChannel = "", options) => {
|
|
22
|
+
let sourceProjectId;
|
|
23
|
+
let sourceSiteId;
|
|
24
|
+
let sourceChannelId;
|
|
22
25
|
let sourceVersion;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (source.includes("@")) {
|
|
27
|
+
const [sitePart, version] = source.split("@");
|
|
28
|
+
sourceVersion = version;
|
|
29
|
+
if (sitePart.includes(":")) {
|
|
30
|
+
[sourceProjectId, sourceSiteId] = sitePart.split(":");
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
sourceSiteId = sitePart;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const parts = source.split(":");
|
|
38
|
+
if (parts.length === 3) {
|
|
39
|
+
[sourceProjectId, sourceSiteId, sourceChannelId] = parts;
|
|
29
40
|
}
|
|
30
|
-
|
|
41
|
+
else if (parts.length === 2) {
|
|
42
|
+
[sourceSiteId, sourceChannelId] = parts;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
let targetProjectId;
|
|
46
|
+
let targetSiteId;
|
|
47
|
+
let targetChannelId;
|
|
48
|
+
const targetParts = targetChannel.split(":");
|
|
49
|
+
if (targetParts.length === 3) {
|
|
50
|
+
[targetProjectId, targetSiteId, targetChannelId] = targetParts;
|
|
51
|
+
}
|
|
52
|
+
else if (targetParts.length === 2) {
|
|
53
|
+
[targetSiteId, targetChannelId] = targetParts;
|
|
54
|
+
}
|
|
55
|
+
if (!sourceSiteId || (!sourceChannelId && !sourceVersion)) {
|
|
56
|
+
throw new error_1.FirebaseError(`"${source}" is not a valid source. Must be in the form "<site>:<channel>" or "<site>@<version>"`);
|
|
31
57
|
}
|
|
32
58
|
if (!targetSiteId || !targetChannelId) {
|
|
33
59
|
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).`);
|
|
34
60
|
}
|
|
61
|
+
sourceProjectId = sourceProjectId || (0, projectUtils_1.needProjectId)(options);
|
|
62
|
+
targetProjectId = targetProjectId || (0, projectUtils_1.needProjectId)(options);
|
|
35
63
|
targetChannelId = (0, api_1.normalizeName)(targetChannelId);
|
|
36
64
|
if (sourceChannelId) {
|
|
37
65
|
sourceChannelId = (0, api_1.normalizeName)(sourceChannelId);
|
|
38
66
|
}
|
|
67
|
+
const equalProjectIds = sourceProjectId === targetProjectId;
|
|
39
68
|
const equalSiteIds = sourceSiteId === targetSiteId;
|
|
40
69
|
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
|
|
70
|
+
if (equalProjectIds && equalSiteIds && equalChannelIds) {
|
|
71
|
+
throw new error_1.FirebaseError(`Source and destination cannot be equal. Please pick a different source or destination.`);
|
|
43
72
|
}
|
|
44
|
-
|
|
45
|
-
|
|
73
|
+
let sourceVersionName;
|
|
74
|
+
if (sourceVersion) {
|
|
75
|
+
sourceVersionName = `projects/${sourceProjectId}/sites/${sourceSiteId}/versions/${sourceVersion}`;
|
|
76
|
+
}
|
|
77
|
+
else if (sourceChannelId) {
|
|
78
|
+
const sChannel = await (0, api_1.getChannel)(sourceProjectId, sourceSiteId, sourceChannelId);
|
|
46
79
|
if (!sChannel) {
|
|
47
80
|
throw new error_1.FirebaseError(`Could not find the channel ${(0, colorette_1.bold)(sourceChannelId)} for site ${(0, colorette_1.bold)(sourceSiteId)}.`);
|
|
48
81
|
}
|
|
@@ -51,51 +84,49 @@ For example, to copy the content for a site \`my-site\` from a preview channel \
|
|
|
51
84
|
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
85
|
}
|
|
53
86
|
}
|
|
54
|
-
|
|
87
|
+
if (!sourceVersionName) {
|
|
88
|
+
throw new error_1.FirebaseError(`Could not find a version to clone for site ${(0, colorette_1.bold)(sourceSiteId)}.`);
|
|
89
|
+
}
|
|
90
|
+
let tChannel = await (0, api_1.getChannel)(targetProjectId, targetSiteId, targetChannelId);
|
|
55
91
|
if (!tChannel) {
|
|
56
92
|
utils.logBullet(`could not find channel ${(0, colorette_1.bold)(targetChannelId)} in site ${(0, colorette_1.bold)(targetSiteId)}, creating it...`);
|
|
57
93
|
try {
|
|
58
|
-
tChannel = await (0, api_1.createChannel)(
|
|
94
|
+
tChannel = await (0, api_1.createChannel)(targetProjectId, targetSiteId, targetChannelId);
|
|
59
95
|
}
|
|
60
96
|
catch (e) {
|
|
61
97
|
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
98
|
}
|
|
63
99
|
utils.logSuccess(`Created new channel ${targetChannelId}`);
|
|
64
100
|
try {
|
|
65
|
-
|
|
66
|
-
await (0, api_1.addAuthDomains)(tProjectId, [tChannel.url]);
|
|
101
|
+
await (0, api_1.addAuthDomains)(targetProjectId, [tChannel.url]);
|
|
67
102
|
}
|
|
68
103
|
catch (e) {
|
|
69
|
-
utils.logLabeledWarning("hosting:clone", `Unable to add channel domain to Firebase Auth. Visit the Firebase Console at ${utils.consoleUrl(
|
|
104
|
+
utils.logLabeledWarning("hosting:clone", `Unable to add channel domain to Firebase Auth. Visit the Firebase Console at ${utils.consoleUrl(targetProjectId, "/authentication/providers")}`);
|
|
70
105
|
logger_1.logger.debug("[hosting] unable to add auth domain", e);
|
|
71
106
|
}
|
|
72
107
|
}
|
|
73
108
|
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.`);
|
|
109
|
+
if (equalProjectIds && equalSiteIds && sourceVersionName === currentTargetVersionName) {
|
|
110
|
+
utils.logSuccess(`Channels ${(0, colorette_1.bold)(sourceChannelId || sourceVersion || "")} and ${(0, colorette_1.bold)(targetChannel)} are serving identical versions. No need to clone.`);
|
|
76
111
|
return;
|
|
77
112
|
}
|
|
78
113
|
let targetVersionName = sourceVersionName;
|
|
79
114
|
const spinner = ora("Cloning site content...").start();
|
|
80
115
|
try {
|
|
81
|
-
if (!equalSiteIds) {
|
|
82
|
-
const targetVersion = await (0, api_1.cloneVersion)(targetSiteId, sourceVersionName, true);
|
|
116
|
+
if (!equalSiteIds || !equalProjectIds) {
|
|
117
|
+
const targetVersion = await (0, api_1.cloneVersion)(targetProjectId, targetSiteId, sourceVersionName, true);
|
|
83
118
|
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)}.`);
|
|
119
|
+
throw new error_1.FirebaseError(`Could not clone the version ${(0, colorette_1.bold)(sourceVersion || sourceVersionName)} for site ${(0, colorette_1.bold)(targetSiteId)}.`);
|
|
85
120
|
}
|
|
86
121
|
targetVersionName = targetVersion.name;
|
|
87
122
|
}
|
|
88
|
-
await (0, api_1.createRelease)(targetSiteId, targetChannelId, targetVersionName);
|
|
123
|
+
await (0, api_1.createRelease)(targetProjectId, targetSiteId, targetChannelId, targetVersionName);
|
|
89
124
|
}
|
|
90
125
|
catch (err) {
|
|
91
126
|
spinner.fail();
|
|
92
127
|
throw err;
|
|
93
128
|
}
|
|
94
129
|
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)}.`);
|
|
130
|
+
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
131
|
utils.logSuccess(`Channel URL (${targetChannelId}): ${tChannel.url}`);
|
|
97
132
|
});
|
|
98
|
-
function parseProjectId(name) {
|
|
99
|
-
const matches = name.match(`^projects/([^/]+)`);
|
|
100
|
-
return matches ? matches[1] || "" : "";
|
|
101
|
-
}
|
|
@@ -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/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
|
+
}
|