firebase-tools 15.33.0 → 15.34.1
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/README.md +9 -0
- package/lib/apphosting/backend.js +1 -1
- package/lib/auth.js +10 -5
- package/lib/checkValidTargetFilters.js +1 -0
- package/lib/command.js +30 -23
- 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 +7 -0
- package/lib/commands/hosting-channel-create.js +3 -0
- package/lib/commands/hosting-channel-delete.js +3 -0
- package/lib/commands/hosting-channel-deploy.js +3 -0
- package/lib/commands/hosting-channel-list.js +3 -0
- package/lib/commands/hosting-channel-open.js +3 -0
- package/lib/commands/hosting-clone.js +63 -9
- package/lib/commands/hosting-disable.js +2 -0
- package/lib/commands/hosting-sites-create.js +3 -0
- package/lib/commands/hosting-sites-delete.js +3 -0
- package/lib/commands/hosting-sites-get.js +3 -0
- package/lib/commands/hosting-sites-list.js +3 -0
- package/lib/commands/index.js +9 -0
- package/lib/commands/init.js +7 -0
- package/lib/commands/run-services-update.js +18 -0
- package/lib/crashlytics/alerts.js +1 -11
- package/lib/crashlytics/onboarding.js +10 -5
- package/lib/crashlytics/profilingManager.js +195 -0
- 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/params.js +1 -0
- package/lib/deploy/functions/release/executor.js +7 -3
- package/lib/deploy/functions/release/fabricator.js +41 -9
- package/lib/deploy/functions/release/sourceTokenScraper.js +1 -1
- package/lib/deploy/hosting/prepare.js +3 -0
- 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 +242 -0
- package/lib/deploy/run/index.js +23 -0
- package/lib/deploy/run/prepare.js +99 -0
- package/lib/deploy/run/prereqs.js +32 -0
- package/lib/deploy/run/release.js +9 -0
- package/lib/deploy/run/update.js +51 -0
- package/lib/deploy/run/util.js +75 -0
- package/lib/emulator/apphosting/serve.js +1 -1
- package/lib/emulator/auth/cloudFunctions.js +47 -18
- package/lib/emulator/auth/utils.js +1 -1
- package/lib/emulator/commandUtils.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/eventarcEmulator.js +1 -1
- package/lib/emulator/functionsEmulatorShared.js +1 -41
- package/lib/experiments.js +1 -17
- package/lib/firestore/validator.js +1 -1
- package/lib/functions/projectConfig.js +10 -5
- package/lib/gcp/cloudsql/permissions.js +21 -32
- package/lib/gcp/cloudsql/permissionsSetup.js +6 -6
- package/lib/gcp/storage.js +9 -5
- package/lib/init/features/index.js +4 -1
- package/lib/init/features/run.js +198 -0
- package/lib/init/index.js +6 -0
- package/lib/mcp/index.js +19 -3
- package/lib/profileReport.js +8 -5
- package/lib/throttler/throttler.js +1 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +8 -8
- 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
|
@@ -103,20 +103,10 @@ async function enableAlerts(projectId, appId, alertTypes, userEmail) {
|
|
|
103
103
|
exit: 1,
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
return await Promise.all(alertTypes.map(async (alertType) => {
|
|
107
107
|
const { policy } = await enableAlert(projectId, appId, alertType, {
|
|
108
108
|
channelName,
|
|
109
109
|
});
|
|
110
110
|
return policy;
|
|
111
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
112
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CRASHLYTICS_TELEMETRY_SERVICE = exports.CRASHLYTICS_TELEMETRY_RESOURCE_TYPE = exports.CRASHLYTICS_TELEMETRY_SINK_ID = exports.CRASHLYTICS_TELEMETRY_BUCKET_ID = void 0;
|
|
3
|
+
exports.CLIENT_TELEMETRY_SERVICE = exports.CRASHLYTICS_SERVICE = exports.CRASHLYTICS_TELEMETRY_ADMIN_SERVICE = exports.CRASHLYTICS_TELEMETRY_SERVICE = exports.CRASHLYTICS_TELEMETRY_RESOURCE_TYPE = exports.CRASHLYTICS_TELEMETRY_SINK_ID = exports.CRASHLYTICS_TELEMETRY_BUCKET_ID = void 0;
|
|
4
4
|
exports.onboardCrashlyticsWeb = onboardCrashlyticsWeb;
|
|
5
5
|
const ensureApiEnabled_1 = require("../ensureApiEnabled");
|
|
6
6
|
const error_1 = require("../error");
|
|
@@ -21,6 +21,9 @@ exports.CRASHLYTICS_TELEMETRY_BUCKET_ID = "firebase-telemetry";
|
|
|
21
21
|
exports.CRASHLYTICS_TELEMETRY_SINK_ID = "firebase-telemetry-routing";
|
|
22
22
|
exports.CRASHLYTICS_TELEMETRY_RESOURCE_TYPE = "firebasetelemetry.googleapis.com/App";
|
|
23
23
|
exports.CRASHLYTICS_TELEMETRY_SERVICE = "firebasetelemetry.googleapis.com";
|
|
24
|
+
exports.CRASHLYTICS_TELEMETRY_ADMIN_SERVICE = "firebasetelemetryadmin.googleapis.com";
|
|
25
|
+
exports.CRASHLYTICS_SERVICE = "firebasecrashlytics.googleapis.com";
|
|
26
|
+
exports.CLIENT_TELEMETRY_SERVICE = "clienttelemetry.googleapis.com";
|
|
24
27
|
async function resolveAuthenticatedUserEmail(options) {
|
|
25
28
|
if (options.user?.email) {
|
|
26
29
|
return options.user.email;
|
|
@@ -45,9 +48,11 @@ async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
|
|
|
45
48
|
(0, utils_1.logLabeledBullet)("crashlytics", "Enabling required telemetry APIs...");
|
|
46
49
|
const requiredApis = [
|
|
47
50
|
(0, ensureApiEnabled_1.ensure)(projectId, exports.CRASHLYTICS_TELEMETRY_SERVICE, "crashlytics", false),
|
|
48
|
-
(0, ensureApiEnabled_1.ensure)(projectId,
|
|
51
|
+
(0, ensureApiEnabled_1.ensure)(projectId, exports.CRASHLYTICS_TELEMETRY_ADMIN_SERVICE, "crashlytics", false),
|
|
52
|
+
(0, ensureApiEnabled_1.ensure)(projectId, exports.CRASHLYTICS_SERVICE, "crashlytics", false),
|
|
53
|
+
(0, ensureApiEnabled_1.ensure)(projectId, exports.CLIENT_TELEMETRY_SERVICE, "crashlytics", false),
|
|
49
54
|
];
|
|
50
|
-
if (experiments.isEnabled("
|
|
55
|
+
if (experiments.isEnabled("crashlyticsWebBreadcrumbs")) {
|
|
51
56
|
requiredApis.push((0, ensureApiEnabled_1.ensure)(projectId, "cloudtrace.googleapis.com", "crashlytics", false));
|
|
52
57
|
}
|
|
53
58
|
await Promise.all(requiredApis);
|
|
@@ -78,7 +83,7 @@ async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
|
|
|
78
83
|
(0, utils_1.logLabeledBullet)("crashlytics", `Setting up Cloud Logging routing sink '${exports.CRASHLYTICS_TELEMETRY_SINK_ID}'...`);
|
|
79
84
|
const sink = await (0, cloudlogging_1.createOrUpdateLogSink)(projectId, exports.CRASHLYTICS_TELEMETRY_SINK_ID, destination, filter);
|
|
80
85
|
(0, utils_1.logLabeledSuccess)("crashlytics", "Cloud Logging routing sink configured.");
|
|
81
|
-
if (experiments.isEnabled("
|
|
86
|
+
if (experiments.isEnabled("crashlyticsWebBreadcrumbs")) {
|
|
82
87
|
(0, utils_1.logLabeledBullet)("crashlytics", "Provisioning Cloud Trace storage...");
|
|
83
88
|
try {
|
|
84
89
|
await (0, cloudtrace_1.provisionTraceStorage)(projectId);
|
|
@@ -91,7 +96,7 @@ async function onboardCrashlyticsWeb(projectId, appId, options = {}) {
|
|
|
91
96
|
(0, utils_1.logLabeledBullet)("crashlytics", "Configuring Crashlytics telemetry for web app...");
|
|
92
97
|
const config = await (0, firebasetelemetry_1.createOrUpdateTelemetryConfig)(projectId, appId, `projects/${projectId}/locations/global/buckets/${exports.CRASHLYTICS_TELEMETRY_BUCKET_ID}`, 1);
|
|
93
98
|
(0, utils_1.logLabeledSuccess)("crashlytics", "Crashlytics telemetry configured successfully.");
|
|
94
|
-
if (
|
|
99
|
+
if (options.nonInteractive) {
|
|
95
100
|
return { bucket, sink, config };
|
|
96
101
|
}
|
|
97
102
|
const userEmail = await resolveAuthenticatedUserEmail(options);
|
|
@@ -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");
|
|
@@ -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.
|
|
14
|
-
let app = apps.find((a) => a.displayName ===
|
|
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(
|
|
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:
|
|
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.
|
|
98
|
-
const excludeIndexes = targets.
|
|
99
|
-
const includeRules = targets.
|
|
100
|
-
const includeIndexes = targets.
|
|
101
|
-
const onlyFirestore = targets.
|
|
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
|
}
|
|
@@ -251,6 +251,7 @@ async function ensureSecret(secretParam, projectId, nonInteractive) {
|
|
|
251
251
|
const promptMessage = `Enter ${secretParam.format === "json" ? "a JSON value" : "a value"} for ${label}:`;
|
|
252
252
|
const secretValue = await (0, prompt_1.password)({
|
|
253
253
|
message: promptMessage,
|
|
254
|
+
validate: (val) => (val !== "" ? true : "Secrets cannot have an empty value."),
|
|
254
255
|
});
|
|
255
256
|
if (secretParam.format === "json") {
|
|
256
257
|
(0, secrets_1.validateJsonSecret)(secretParam.name, secretValue);
|
|
@@ -22,9 +22,10 @@ const isServiceUnavailable = (err) => parseErrorCode(err) === 503;
|
|
|
22
22
|
exports.isServiceUnavailable = isServiceUnavailable;
|
|
23
23
|
const isTransientError = (err) => (0, exports.isQuotaExhaustion)(err) || (0, exports.isConflict)(err) || (0, exports.isServiceUnavailable)(err);
|
|
24
24
|
exports.isTransientError = isTransientError;
|
|
25
|
+
const MANAGED_SERVICE_ACCOUNT_REGEX = /\bfirebase-fn-[0-9]+@/i;
|
|
25
26
|
const isServiceAccountPropagationError = (err) => {
|
|
26
27
|
const code = parseErrorCode(err);
|
|
27
|
-
if (code !== 404 && code !== 400) {
|
|
28
|
+
if (code !== 404 && code !== 400 && code !== 403) {
|
|
28
29
|
return false;
|
|
29
30
|
}
|
|
30
31
|
let message = "";
|
|
@@ -44,13 +45,16 @@ const isServiceAccountPropagationError = (err) => {
|
|
|
44
45
|
message = String(err).toLowerCase();
|
|
45
46
|
}
|
|
46
47
|
const hasSa = message.includes("serviceaccount") || message.includes("service account");
|
|
47
|
-
if (!hasSa) {
|
|
48
|
+
if (!hasSa || !MANAGED_SERVICE_ACCOUNT_REGEX.test(message)) {
|
|
48
49
|
return false;
|
|
49
50
|
}
|
|
50
51
|
if (code === 404) {
|
|
51
52
|
return true;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
if (code === 400) {
|
|
55
|
+
return message.includes("invalid service account");
|
|
56
|
+
}
|
|
57
|
+
return message.includes("or it may not exist");
|
|
54
58
|
};
|
|
55
59
|
exports.isServiceAccountPropagationError = isServiceAccountPropagationError;
|
|
56
60
|
const isCloudRunResourceExhausted = (err) => parseErrorCode(err) === 8;
|
|
@@ -173,14 +173,26 @@ class Fabricator {
|
|
|
173
173
|
return this.applyUpserts(changes, scraperV1, scraperV2);
|
|
174
174
|
});
|
|
175
175
|
const createAndUpdateResultsArray = await Promise.allSettled(createAndUpdatePromises);
|
|
176
|
+
const upsertErrors = [];
|
|
176
177
|
summary.results = createAndUpdateResultsArray.reduce((acc, r) => {
|
|
177
178
|
if (r.status === "fulfilled") {
|
|
178
179
|
return [...acc, ...r.value];
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
+
upsertErrors.push((0, error_1.getError)(r.reason));
|
|
182
|
+
logger_1.logger.debug("Fabricator.applyUpserts returned an unhandled exception.", (0, error_1.getErrStack)(r.reason));
|
|
181
183
|
return acc;
|
|
182
184
|
}, []);
|
|
183
185
|
await this.cleanupUnusedServiceAccounts(plan, summary.results);
|
|
186
|
+
if (upsertErrors.length) {
|
|
187
|
+
const opts = upsertErrors.length === 1 ? { original: upsertErrors[0] } : { children: upsertErrors };
|
|
188
|
+
const msg = upsertErrors.length === 1
|
|
189
|
+
? `Fabricator.applyUpserts encountered an unhandled exception: ${upsertErrors[0].message}`
|
|
190
|
+
: "Fabricator.applyUpserts encountered unhandled exceptions";
|
|
191
|
+
throw new error_1.FirebaseError(msg, {
|
|
192
|
+
...opts,
|
|
193
|
+
exit: 2,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
184
196
|
const hasFailures = summary.results.some((r) => r.error);
|
|
185
197
|
if (hasFailures) {
|
|
186
198
|
utils.logLabeledWarning("functions", "Deploys failed. Skipping deletes.");
|
|
@@ -196,14 +208,26 @@ class Fabricator {
|
|
|
196
208
|
return summary;
|
|
197
209
|
}
|
|
198
210
|
const deleteResultsArray = await Promise.allSettled(allChangesets.map((changes) => this.applyDeletes(changes)));
|
|
211
|
+
const deleteErrors = [];
|
|
199
212
|
const deleteResults = deleteResultsArray.reduce((acc, r) => {
|
|
200
213
|
if (r.status === "fulfilled") {
|
|
201
214
|
return [...acc, ...r.value];
|
|
202
215
|
}
|
|
203
|
-
|
|
216
|
+
deleteErrors.push((0, error_1.getError)(r.reason));
|
|
217
|
+
logger_1.logger.debug("Fabricator.applyDeletes returned an unhandled exception. This should never happen", (0, error_1.getErrStack)(r.reason));
|
|
204
218
|
return acc;
|
|
205
219
|
}, []);
|
|
206
220
|
summary.results.push(...deleteResults);
|
|
221
|
+
if (deleteErrors.length) {
|
|
222
|
+
const opts = deleteErrors.length === 1 ? { original: deleteErrors[0] } : { children: deleteErrors };
|
|
223
|
+
const msg = deleteErrors.length === 1
|
|
224
|
+
? `Fabricator.applyDeletes encountered an unhandled exception: ${deleteErrors[0].message}`
|
|
225
|
+
: "Fabricator.applyDeletes encountered unhandled exceptions";
|
|
226
|
+
throw new error_1.FirebaseError(msg, {
|
|
227
|
+
...opts,
|
|
228
|
+
exit: 2,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
207
231
|
for (const [codebase, codebasePlan] of Object.entries(plan)) {
|
|
208
232
|
await this.removeOldRoles(codebasePlan, codebase);
|
|
209
233
|
}
|
|
@@ -231,23 +255,29 @@ class Fabricator {
|
|
|
231
255
|
async applyUpserts(changes, scraperV1, scraperV2) {
|
|
232
256
|
const ops = [];
|
|
233
257
|
for (const endpoint of changes.endpointsToCreate) {
|
|
234
|
-
this.
|
|
235
|
-
|
|
258
|
+
ops.push(this.wrapOperation("create", endpoint, () => {
|
|
259
|
+
this.logOpStart("creating", endpoint);
|
|
260
|
+
return this.createEndpoint(endpoint, scraperV1, scraperV2);
|
|
261
|
+
}));
|
|
236
262
|
}
|
|
237
263
|
for (const endpoint of changes.endpointsToSkip) {
|
|
238
264
|
utils.logSuccess(this.getLogSuccessMessage("skip", endpoint));
|
|
239
265
|
}
|
|
240
266
|
for (const update of changes.endpointsToUpdate) {
|
|
241
|
-
this.
|
|
242
|
-
|
|
267
|
+
ops.push(this.wrapOperation("update", update.endpoint, () => {
|
|
268
|
+
this.logOpStart("updating", update.endpoint);
|
|
269
|
+
return this.updateEndpoint(update, scraperV1, scraperV2);
|
|
270
|
+
}));
|
|
243
271
|
}
|
|
244
272
|
return Promise.all(ops);
|
|
245
273
|
}
|
|
246
274
|
async applyDeletes(changes) {
|
|
247
275
|
const ops = [];
|
|
248
276
|
for (const endpoint of changes.endpointsToDelete) {
|
|
249
|
-
this.
|
|
250
|
-
|
|
277
|
+
ops.push(this.wrapOperation("delete", endpoint, () => {
|
|
278
|
+
this.logOpStart("deleting", endpoint);
|
|
279
|
+
return this.deleteEndpoint(endpoint);
|
|
280
|
+
}));
|
|
251
281
|
}
|
|
252
282
|
return Promise.all(ops);
|
|
253
283
|
}
|
|
@@ -881,7 +911,9 @@ class Fabricator {
|
|
|
881
911
|
.catch(rethrowAs(endpoint, "unregister blocking trigger"));
|
|
882
912
|
}
|
|
883
913
|
logOpStart(op, endpoint) {
|
|
884
|
-
const runtime = endpoint.runtime
|
|
914
|
+
const runtime = endpoint.runtime
|
|
915
|
+
? supported_1.RUNTIMES[endpoint.runtime]?.friendly ?? endpoint.runtime
|
|
916
|
+
: "unknown";
|
|
885
917
|
const platform = (0, functionsDeployHelper_1.getHumanFriendlyPlatformName)(endpoint.platform);
|
|
886
918
|
const label = helper.getFunctionLabel(endpoint);
|
|
887
919
|
utils.logLabeledBullet("functions", `${op} ${runtime} (${platform}) function ${clc.bold(label)}...`);
|
|
@@ -41,12 +41,12 @@ class SourceTokenScraper {
|
|
|
41
41
|
return tokenResult.token;
|
|
42
42
|
}
|
|
43
43
|
else if (this.fetchState === "VALID") {
|
|
44
|
-
const tokenResult = await this.promise;
|
|
45
44
|
if (this.isTokenExpired()) {
|
|
46
45
|
this.fetchState = "FETCHING";
|
|
47
46
|
this.promise = new Promise((resolve) => (this.resolve = resolve));
|
|
48
47
|
return undefined;
|
|
49
48
|
}
|
|
49
|
+
const tokenResult = await this.promise;
|
|
50
50
|
return tokenResult.token;
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
@@ -15,6 +15,8 @@ const utils = require("../../utils");
|
|
|
15
15
|
const backend = require("../functions/backend");
|
|
16
16
|
const ensureTargeted_1 = require("../../functions/ensureTargeted");
|
|
17
17
|
const frameworks_1 = require("../../frameworks");
|
|
18
|
+
const ensureApiEnabled_1 = require("../../ensureApiEnabled");
|
|
19
|
+
const api_1 = require("../../api");
|
|
18
20
|
function handlePublicDirectoryFlag(options) {
|
|
19
21
|
if (options.public) {
|
|
20
22
|
if (Array.isArray(options.config.get("hosting"))) {
|
|
@@ -73,6 +75,7 @@ async function prepare(context, options) {
|
|
|
73
75
|
if (configs.length === 0) {
|
|
74
76
|
return Promise.resolve();
|
|
75
77
|
}
|
|
78
|
+
await (0, ensureApiEnabled_1.ensure)(context.projectId, (0, api_1.hostingApiOrigin)(), "hosting", true);
|
|
76
79
|
const versions = await Promise.all(configs.map(async (config) => {
|
|
77
80
|
await api.getSite(context.projectId, config.site);
|
|
78
81
|
const labels = {
|
package/lib/deploy/index.js
CHANGED
|
@@ -23,6 +23,8 @@ const DataConnectTarget = require("./dataconnect");
|
|
|
23
23
|
const AppHostingTarget = require("./apphosting");
|
|
24
24
|
const AuthTarget = require("./auth");
|
|
25
25
|
const AiLogicTarget = require("./ailogic");
|
|
26
|
+
const RunTarget = require("./run");
|
|
27
|
+
const prereqs_1 = require("./run/prereqs");
|
|
26
28
|
const frameworks_1 = require("../frameworks");
|
|
27
29
|
const prepare_1 = require("./hosting/prepare");
|
|
28
30
|
const requirePermissions_1 = require("../requirePermissions");
|
|
@@ -39,6 +41,7 @@ exports.VALID_DEPLOY_TARGETS = [
|
|
|
39
41
|
"apphosting",
|
|
40
42
|
"auth",
|
|
41
43
|
"ailogic",
|
|
44
|
+
"run",
|
|
42
45
|
];
|
|
43
46
|
exports.TARGET_PERMISSIONS = {
|
|
44
47
|
database: ["firebasedatabase.instances.update"],
|
|
@@ -95,6 +98,7 @@ exports.TARGET_PERMISSIONS = {
|
|
|
95
98
|
"firebasevertexai.templates.delete",
|
|
96
99
|
"serviceusage.services.get",
|
|
97
100
|
],
|
|
101
|
+
run: prereqs_1.RUN_PERMISSIONS,
|
|
98
102
|
};
|
|
99
103
|
exports.TARGETS = {
|
|
100
104
|
hosting: HostingTarget,
|
|
@@ -108,6 +112,7 @@ exports.TARGETS = {
|
|
|
108
112
|
apphosting: AppHostingTarget,
|
|
109
113
|
auth: AuthTarget,
|
|
110
114
|
ailogic: AiLogicTarget,
|
|
115
|
+
run: RunTarget,
|
|
111
116
|
};
|
|
112
117
|
const chain = async function (fns, context, options, payload) {
|
|
113
118
|
for (const latest of fns) {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BUILD_ENV_ANNOTATION = void 0;
|
|
4
|
+
exports.getBuildEnv = getBuildEnv;
|
|
5
|
+
exports.secretNames = secretNames;
|
|
6
|
+
exports.nonSecretValues = nonSecretValues;
|
|
7
|
+
exports.toLocalBuildEnv = toLocalBuildEnv;
|
|
8
|
+
const error_1 = require("../../error");
|
|
9
|
+
exports.BUILD_ENV_ANNOTATION = "firebase.google.com/buildConfig.environmentVariablesAndSecrets";
|
|
10
|
+
function getBuildEnv(service) {
|
|
11
|
+
const raw = service?.annotations?.[exports.BUILD_ENV_ANNOTATION];
|
|
12
|
+
if (!service || !raw) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
const invalid = (reason) => new error_1.FirebaseError(`Invalid ${exports.BUILD_ENV_ANNOTATION} annotation on ${service.name}: ${reason}`);
|
|
16
|
+
let parsed;
|
|
17
|
+
try {
|
|
18
|
+
parsed = JSON.parse(raw);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw invalid("it isn't valid JSON.");
|
|
22
|
+
}
|
|
23
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
24
|
+
throw invalid("it must be a JSON object.");
|
|
25
|
+
}
|
|
26
|
+
const env = {};
|
|
27
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
28
|
+
if (typeof value === "string" || isSecretRef(value)) {
|
|
29
|
+
env[name] = value;
|
|
30
|
+
}
|
|
31
|
+
else if (typeof value === "number" || typeof value === "boolean") {
|
|
32
|
+
env[name] = String(value);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw invalid(`${name} must be a string, number, boolean, or {"secret": "<secret name>"}.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return env;
|
|
39
|
+
}
|
|
40
|
+
function isSecretRef(value) {
|
|
41
|
+
const ref = value;
|
|
42
|
+
return (typeof ref === "object" &&
|
|
43
|
+
ref !== null &&
|
|
44
|
+
Object.keys(ref).length === 1 &&
|
|
45
|
+
typeof ref.secret === "string");
|
|
46
|
+
}
|
|
47
|
+
function secretNames(env) {
|
|
48
|
+
return Object.entries(env)
|
|
49
|
+
.filter(([, value]) => isSecretRef(value))
|
|
50
|
+
.map(([name]) => name);
|
|
51
|
+
}
|
|
52
|
+
function nonSecretValues(env) {
|
|
53
|
+
const values = {};
|
|
54
|
+
for (const [name, value] of Object.entries(env)) {
|
|
55
|
+
if (!isSecretRef(value)) {
|
|
56
|
+
values[name] = value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return values;
|
|
60
|
+
}
|
|
61
|
+
function toLocalBuildEnv(env) {
|
|
62
|
+
const result = {};
|
|
63
|
+
for (const [name, value] of Object.entries(env)) {
|
|
64
|
+
if (isSecretRef(value)) {
|
|
65
|
+
result[name] = { secret: value.secret, availability: ["BUILD"] };
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
result[name] = { value, availability: ["BUILD"] };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|