firebase-tools 15.35.0 → 15.36.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/appcheck/debugTokens.js +293 -0
- package/lib/appcheck/localConfig.js +191 -0
- package/lib/appdistribution/options-parser-util.js +1 -1
- package/lib/apphosting/githubConnections.js +1 -1
- package/lib/auth.js +8 -2
- package/lib/commands/appcheck-debugtokens-create.js +60 -35
- package/lib/commands/appcheck-debugtokens-delete.js +21 -7
- package/lib/commands/appcheck-debugtokens-list.js +37 -8
- package/lib/commands/appcheck-debugtokens-prune.js +59 -0
- package/lib/commands/crashlytics-heapdumps-status.js +1 -1
- package/lib/commands/deploy.js +1 -3
- package/lib/commands/hosting-channel-create.js +1 -3
- package/lib/commands/hosting-channel-delete.js +1 -3
- package/lib/commands/hosting-channel-deploy.js +1 -3
- package/lib/commands/hosting-channel-list.js +1 -3
- package/lib/commands/hosting-channel-open.js +1 -3
- package/lib/commands/hosting-clone.js +3 -5
- package/lib/commands/hosting-disable.js +2 -2
- package/lib/commands/hosting-sites-create.js +1 -3
- package/lib/commands/hosting-sites-delete.js +1 -3
- package/lib/commands/hosting-sites-get.js +1 -3
- package/lib/commands/hosting-sites-list.js +1 -3
- package/lib/commands/index.js +1 -0
- package/lib/crashlytics/events.js +122 -1
- package/lib/crashlytics/filters.js +12 -6
- package/lib/crashlytics/profilingManager.js +14 -34
- package/lib/crashlytics/utils.js +14 -0
- package/lib/database/import.js +5 -4
- package/lib/dataconnect/names.js +3 -3
- package/lib/dataconnect/schemaMigration.js +1 -1
- package/lib/deploy/functions/backend.js +0 -10
- package/lib/deploy/functions/cel.js +1 -1
- package/lib/deploy/functions/release/reporter.js +0 -26
- package/lib/deploy/functions/runtimes/discovery/index.js +4 -1
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +1 -1
- package/lib/deploy/functions/services/index.js +13 -11
- package/lib/deploy/hosting/prepare.js +1 -3
- package/lib/deploy/lifecycleHooks.js +1 -1
- package/lib/emulator/auth/operations.js +2 -2
- package/lib/emulator/auth/server.js +4 -2
- package/lib/emulator/auth/widget_ui.js +1 -1
- package/lib/emulator/commandUtils.js +4 -1
- package/lib/emulator/databaseEmulator.js +16 -11
- package/lib/emulator/dataconnect/pgliteServer.js +30 -24
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/downloadableEmulators.js +2 -2
- package/lib/emulator/extensions/postinstall.js +6 -6
- package/lib/emulator/firestoreEmulator.js +21 -15
- package/lib/emulator/functionsEmulator.js +11 -7
- package/lib/emulator/functionsEmulatorRuntime.js +7 -2
- package/lib/emulator/hub.js +12 -8
- package/lib/emulator/shared/express.js +30 -0
- package/lib/emulator/storage/apis/firebase.js +11 -10
- package/lib/emulator/storage/apis/gcloud.js +21 -20
- package/lib/emulator/storage/files.js +1 -1
- package/lib/emulator/storage/rules/manager.js +15 -12
- package/lib/emulator/storage/server.js +10 -5
- package/lib/extensions/extensionsHelper.js +2 -2
- package/lib/extensions/paramHelper.js +1 -1
- package/lib/extensions/provisioningHelper.js +1 -6
- package/lib/firestore/util.js +3 -3
- package/lib/frameworks/angular/utils.js +1 -1
- package/lib/frameworks/next/utils.js +1 -1
- package/lib/functions/kits/install.js +221 -316
- package/lib/functions/kits/sources/directory.js +32 -0
- package/lib/functions/kits/sources/npm.js +55 -5
- package/lib/functionsConfig.js +0 -4
- package/lib/functionsShellCommandAction.js +1 -1
- package/lib/gcp/cloudfunctionsv2.js +0 -6
- package/lib/gcp/devConnect.js +2 -2
- package/lib/hosting/api.js +79 -0
- package/lib/hosting/proxy.js +4 -1
- package/lib/init/features/hosting/github.js +6 -4
- package/lib/init/features/hosting/index.js +4 -0
- package/lib/mcp/apps/init/mcp-app.js +4 -1
- package/lib/mcp/index.js +8 -2
- package/lib/mcp/prompts/apptesting/run_test.js +3 -3
- package/lib/mcp/prompts/core/deploy.js +3 -3
- package/lib/mcp/resources/guides/init_ai.js +10 -10
- package/lib/mcp/tools/crashlytics/events.js +18 -93
- package/lib/mcp/tools/crashlytics/index.js +2 -0
- package/lib/mcp/tools/crashlytics/reports.js +1 -1
- package/lib/mcp/tools/crashlytics/setup.js +392 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +4 -10
- package/package.json +1 -1
- package/lib/functions/kits/sources/index.js +0 -19
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateAndResolveDirectoryKit = validateAndResolveDirectoryKit;
|
|
4
4
|
exports.buildAndInstallDirectoryKit = buildAndInstallDirectoryKit;
|
|
5
|
+
exports.createDirectoryAdapter = createDirectoryAdapter;
|
|
5
6
|
const path = require("path");
|
|
6
7
|
const fs = require("fs-extra");
|
|
7
8
|
const error_1 = require("../../../error");
|
|
8
9
|
const spawn_1 = require("../../../init/spawn");
|
|
9
10
|
const utils_1 = require("../../../utils");
|
|
11
|
+
const projectConfig_1 = require("../../projectConfig");
|
|
12
|
+
const types_1 = require("./types");
|
|
10
13
|
async function validateAndResolveDirectoryKit(projectDir, rawDir) {
|
|
11
14
|
const absDirectoryPath = (0, utils_1.resolveWithin)(projectDir, rawDir, `Directory '${rawDir}' is outside of project directory. Function kit directory must be inside the project directory.`);
|
|
12
15
|
if (!(await fs.pathExists(absDirectoryPath))) {
|
|
@@ -57,3 +60,32 @@ async function buildAndInstallDirectoryKit(absSourcePath, hasBuildScript) {
|
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
}
|
|
63
|
+
function createDirectoryAdapter(config, directory) {
|
|
64
|
+
const absDir = path.isAbsolute(directory)
|
|
65
|
+
? directory
|
|
66
|
+
: path.resolve(config.projectDir, directory);
|
|
67
|
+
let validated;
|
|
68
|
+
return {
|
|
69
|
+
defaultKitId: (0, types_1.sanitizeToKitId)(path.basename(absDir)) || "kit",
|
|
70
|
+
findExistingKit(existingFunctions) {
|
|
71
|
+
return existingFunctions.find((c) => (0, projectConfig_1.isKitConfig)(c) &&
|
|
72
|
+
!c.sourcePackage &&
|
|
73
|
+
path.resolve(config.projectDir, c.source) === absDir);
|
|
74
|
+
},
|
|
75
|
+
async validateAndConfirm() {
|
|
76
|
+
validated = await validateAndResolveDirectoryKit(config.projectDir, directory);
|
|
77
|
+
},
|
|
78
|
+
async prepareSource() {
|
|
79
|
+
if (!validated) {
|
|
80
|
+
validated = await validateAndResolveDirectoryKit(config.projectDir, directory);
|
|
81
|
+
}
|
|
82
|
+
await buildAndInstallDirectoryKit(validated.absDirectoryPath, validated.hasBuildScript);
|
|
83
|
+
return {
|
|
84
|
+
sourcePath: validated.relSourcePath,
|
|
85
|
+
...(validated.hasBuildScript
|
|
86
|
+
? { predeploy: ['npm --prefix "$RESOURCE_DIR" run build'] }
|
|
87
|
+
: {}),
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -14,6 +14,7 @@ exports.scaffoldKitFiles = scaffoldKitFiles;
|
|
|
14
14
|
exports.resolveSdkSpecifierToSave = resolveSdkSpecifierToSave;
|
|
15
15
|
exports.getKitPackagesToSave = getKitPackagesToSave;
|
|
16
16
|
exports.buildAndInstallKit = buildAndInstallKit;
|
|
17
|
+
exports.createNpmPackageAdapter = createNpmPackageAdapter;
|
|
17
18
|
const path = require("path");
|
|
18
19
|
const clc = require("colorette");
|
|
19
20
|
const fs = require("fs-extra");
|
|
@@ -25,6 +26,7 @@ const prompt_1 = require("../../../prompt");
|
|
|
25
26
|
const templates_1 = require("../../../templates");
|
|
26
27
|
const utils_1 = require("../../../utils");
|
|
27
28
|
const supported = require("../../../deploy/functions/runtimes/supported");
|
|
29
|
+
const projectConfig_1 = require("../../projectConfig");
|
|
28
30
|
const types_1 = require("./types");
|
|
29
31
|
exports.TEMPLATES = {
|
|
30
32
|
installation: "init/functions/typescript/index-kit.ts",
|
|
@@ -164,18 +166,16 @@ async function writeKitIndexTs(options) {
|
|
|
164
166
|
await config.askWriteProjectFile(relIndexTsPath, indexContent);
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
|
-
async function scaffoldKitFiles(
|
|
169
|
+
async function scaffoldKitFiles(options) {
|
|
170
|
+
const { config, kitId, packageName, templateType = exports.DEFAULT_TEMPLATE } = options;
|
|
168
171
|
const sourcePath = path.join(types_1.FUNCTION_KITS_DIR, kitId, "source");
|
|
169
|
-
const configDirPath = path.join(types_1.FUNCTION_KITS_DIR, kitId, `config-${instanceId}`);
|
|
170
172
|
const absSourcePath = config.path(sourcePath);
|
|
171
|
-
const absConfigDirPath = config.path(configDirPath);
|
|
172
173
|
await fs.ensureDir(absSourcePath);
|
|
173
|
-
await fs.ensureDir(absConfigDirPath);
|
|
174
174
|
await writeKitPackageJson(config, sourcePath, kitId);
|
|
175
175
|
await config.askWriteProjectFile(path.join(sourcePath, "tsconfig.json"), (0, templates_1.readTemplateSync)("init/functions/typescript/tsconfig.json"));
|
|
176
176
|
await config.askWriteProjectFile(path.join(sourcePath, ".gitignore"), (0, templates_1.readTemplateSync)("init/functions/typescript/_gitignore"));
|
|
177
177
|
await writeKitIndexTs({ config, sourcePath, packageName, templateType });
|
|
178
|
-
return { sourcePath,
|
|
178
|
+
return { sourcePath, absSourcePath };
|
|
179
179
|
}
|
|
180
180
|
function resolveSdkSpecifierToSave(packageName, declaredVer, installedVer) {
|
|
181
181
|
const cleanVer = semver.clean(declaredVer);
|
|
@@ -272,3 +272,53 @@ async function buildAndInstallKit(absSourcePath, rawPkgName, isThirdParty) {
|
|
|
272
272
|
throw new error_1.FirebaseError(`TypeScript build failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
|
+
function createNpmPackageAdapter(options) {
|
|
276
|
+
validateNpmPackageName(options.package);
|
|
277
|
+
const { packageName } = parseNpmPackageSpecifier(options.package);
|
|
278
|
+
const templateType = options.template || exports.DEFAULT_TEMPLATE;
|
|
279
|
+
if (!(templateType in exports.TEMPLATES)) {
|
|
280
|
+
const validTemplates = Object.keys(exports.TEMPLATES)
|
|
281
|
+
.map((t) => `'${t}'`)
|
|
282
|
+
.join(" or ");
|
|
283
|
+
throw new error_1.FirebaseError(`Invalid template '${templateType}'. Template must be ${validTemplates}.`);
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
defaultKitId: sanitizePackageNameToKitName(packageName) || "kit",
|
|
287
|
+
findExistingKit(existingFunctions) {
|
|
288
|
+
return existingFunctions.find((c) => (0, projectConfig_1.isKitConfig)(c) && c.sourcePackage?.name === packageName);
|
|
289
|
+
},
|
|
290
|
+
async validateAndConfirm() {
|
|
291
|
+
await validateNpmPackageExists(options.package);
|
|
292
|
+
await promptSecurityConfirmation({
|
|
293
|
+
rawPkgName: options.package,
|
|
294
|
+
packageName,
|
|
295
|
+
nonInteractive: options.nonInteractive,
|
|
296
|
+
force: options.force,
|
|
297
|
+
});
|
|
298
|
+
},
|
|
299
|
+
async prepareSource(kitId) {
|
|
300
|
+
const absKitDir = options.config.path(path.join(types_1.FUNCTION_KITS_DIR, kitId));
|
|
301
|
+
try {
|
|
302
|
+
const { sourcePath, absSourcePath } = await scaffoldKitFiles({
|
|
303
|
+
config: options.config,
|
|
304
|
+
kitId,
|
|
305
|
+
packageName,
|
|
306
|
+
templateType,
|
|
307
|
+
});
|
|
308
|
+
await buildAndInstallKit(absSourcePath, options.package, isThirdPartyPackage(packageName));
|
|
309
|
+
return {
|
|
310
|
+
sourcePath,
|
|
311
|
+
sourcePackage: { name: packageName },
|
|
312
|
+
predeploy: ['npm --prefix "$RESOURCE_DIR" run build'],
|
|
313
|
+
createdPaths: [absKitDir],
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
await fs.remove(absKitDir).catch((cleanupErr) => {
|
|
318
|
+
logger_1.logger.debug(`Failed to clean up kit directory '${absKitDir}': ${(0, error_1.getErrMsg)(cleanupErr)}`);
|
|
319
|
+
});
|
|
320
|
+
throw err;
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
}
|
package/lib/functionsConfig.js
CHANGED
|
@@ -6,7 +6,6 @@ exports.logFunctionsConfigDeprecationWarning = logFunctionsConfigDeprecationWarn
|
|
|
6
6
|
exports.ensureLegacyRuntimeConfigCommandsEnabled = ensureLegacyRuntimeConfigCommandsEnabled;
|
|
7
7
|
exports.ensureApi = ensureApi;
|
|
8
8
|
exports.varNameToIds = varNameToIds;
|
|
9
|
-
exports.idsToVarName = idsToVarName;
|
|
10
9
|
exports.getAppEngineLocation = getAppEngineLocation;
|
|
11
10
|
exports.getFirebaseConfig = getFirebaseConfig;
|
|
12
11
|
exports.setVariablesRecursive = setVariablesRecursive;
|
|
@@ -89,9 +88,6 @@ function varNameToIds(varName) {
|
|
|
89
88
|
variable: varName.match(new RegExp("/variables/(.+)"))[1],
|
|
90
89
|
};
|
|
91
90
|
}
|
|
92
|
-
function idsToVarName(projectId, configId, varId) {
|
|
93
|
-
return ["projects", projectId, "configs", configId, "variables", varId].join("/");
|
|
94
|
-
}
|
|
95
91
|
function getAppEngineLocation(config) {
|
|
96
92
|
let appEngineLocation = config.locationId;
|
|
97
93
|
if (appEngineLocation && appEngineLocation.match(/[^\d]$/)) {
|
|
@@ -103,7 +103,7 @@ const actionFunction = async (options) => {
|
|
|
103
103
|
replServer.on("reset", initializeContext);
|
|
104
104
|
return new Promise((resolve) => {
|
|
105
105
|
replServer.on("exit", () => {
|
|
106
|
-
|
|
106
|
+
serveFunctions.stop().then(resolve).catch(resolve);
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
});
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.API_VERSION = void 0;
|
|
4
4
|
exports.generateUploadUrl = generateUploadUrl;
|
|
5
5
|
exports.createFunction = createFunction;
|
|
6
|
-
exports.getFunction = getFunction;
|
|
7
6
|
exports.listAllFunctions = listAllFunctions;
|
|
8
7
|
exports.updateFunction = updateFunction;
|
|
9
8
|
exports.deleteFunction = deleteFunction;
|
|
@@ -92,11 +91,6 @@ async function createFunction(cloudFunction) {
|
|
|
92
91
|
throw functionsOpLogReject(cloudFunction, "create", err);
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
|
-
async function getFunction(projectId, location, functionId) {
|
|
96
|
-
const name = `projects/${projectId}/locations/${location}/functions/${functionId}`;
|
|
97
|
-
const res = await client.get(name);
|
|
98
|
-
return res.body;
|
|
99
|
-
}
|
|
100
94
|
async function listAllFunctions(projectId) {
|
|
101
95
|
return await listFunctionsInternal(projectId, "-");
|
|
102
96
|
}
|
package/lib/gcp/devConnect.js
CHANGED
|
@@ -146,8 +146,8 @@ async function generateP4SA(projectNumber) {
|
|
|
146
146
|
await (0, serviceusage_1.generateServiceIdentityAndPoll)(projectNumber, new URL(devConnectOrigin).hostname, "apphosting");
|
|
147
147
|
}
|
|
148
148
|
function extractGitRepositoryLinkComponents(path) {
|
|
149
|
-
const connectionMatch = /connections\/([
|
|
150
|
-
const repositoryMatch = /gitRepositoryLinks\/([
|
|
149
|
+
const connectionMatch = /connections\/([^/]+)/.exec(path);
|
|
150
|
+
const repositoryMatch = /gitRepositoryLinks\/([^/]+)/.exec(path);
|
|
151
151
|
const connection = connectionMatch ? connectionMatch[1] : null;
|
|
152
152
|
const gitRepoLink = repositoryMatch ? repositoryMatch[1] : null;
|
|
153
153
|
return { connection, gitRepoLink };
|
package/lib/hosting/api.js
CHANGED
|
@@ -25,13 +25,19 @@ exports.cleanAuthState = cleanAuthState;
|
|
|
25
25
|
exports.getSiteDomains = getSiteDomains;
|
|
26
26
|
exports.getAllSiteDomains = getAllSiteDomains;
|
|
27
27
|
exports.getDeploymentDomain = getDeploymentDomain;
|
|
28
|
+
exports.resetEnsureApiEnabledCacheForTests = resetEnsureApiEnabledCacheForTests;
|
|
29
|
+
exports.ensureApiEnabled = ensureApiEnabled;
|
|
30
|
+
const clc = require("colorette");
|
|
28
31
|
const error_1 = require("../error");
|
|
29
32
|
const api_1 = require("../api");
|
|
30
33
|
const apiv2_1 = require("../apiv2");
|
|
34
|
+
const ensureApiEnabledModule = require("../ensureApiEnabled");
|
|
35
|
+
const logger_1 = require("../logger");
|
|
31
36
|
const operationPoller = require("../operation-poller");
|
|
32
37
|
const expireUtils_1 = require("../hosting/expireUtils");
|
|
33
38
|
const auth_1 = require("../gcp/auth");
|
|
34
39
|
const proto = require("../gcp/proto");
|
|
40
|
+
const utils = require("../utils");
|
|
35
41
|
const utils_1 = require("../utils");
|
|
36
42
|
const constants_1 = require("../emulator/constants");
|
|
37
43
|
const ONE_WEEK_MS = 604800000;
|
|
@@ -313,3 +319,76 @@ async function getDeploymentDomain(projectId, siteId, hostingChannel) {
|
|
|
313
319
|
});
|
|
314
320
|
return site && (0, utils_1.getHostnameFromUrl)(site?.defaultUrl);
|
|
315
321
|
}
|
|
322
|
+
const FAILED_API_CHECK_TTL_MS = 5 * 60 * 1000;
|
|
323
|
+
const failedApiChecks = new Map();
|
|
324
|
+
const inFlightApiChecks = new Map();
|
|
325
|
+
function resetEnsureApiEnabledCacheForTests() {
|
|
326
|
+
failedApiChecks.clear();
|
|
327
|
+
inFlightApiChecks.clear();
|
|
328
|
+
}
|
|
329
|
+
function isServiceUsagePermissionError(err) {
|
|
330
|
+
if ((0, error_1.getErrStatus)(err) === 403) {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
if (!(0, error_1.isObject)(err)) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
const context = (0, error_1.isObject)(err.context) ? err.context : undefined;
|
|
337
|
+
const body = context && (0, error_1.isObject)(context.body) ? context.body : undefined;
|
|
338
|
+
const errorBody = body && (0, error_1.isObject)(body.error) ? body.error : undefined;
|
|
339
|
+
return errorBody?.status === "PERMISSION_DENIED" || errorBody?.code === 403;
|
|
340
|
+
}
|
|
341
|
+
function isServiceUsageEnableError(err, errMsg) {
|
|
342
|
+
if (errMsg.startsWith("Permissions denied enabling") || errMsg.includes(":enable")) {
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
if (!(0, error_1.isObject)(err) || !(0, error_1.isObject)(err.context) || !(0, error_1.isObject)(err.context.response)) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
const responseUrl = err.context.response.url;
|
|
349
|
+
return typeof responseUrl === "string" && responseUrl.includes(":enable");
|
|
350
|
+
}
|
|
351
|
+
async function ensureApiEnabled(projectId) {
|
|
352
|
+
const apiUri = (0, api_1.hostingApiOrigin)();
|
|
353
|
+
const apiName = (0, utils_1.getHostnameFromUrl)(apiUri) || apiUri;
|
|
354
|
+
const cacheKey = `${projectId}:${apiName}`;
|
|
355
|
+
const failedUntil = failedApiChecks.get(cacheKey);
|
|
356
|
+
if (failedUntil !== undefined) {
|
|
357
|
+
if (Date.now() < failedUntil) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
failedApiChecks.delete(cacheKey);
|
|
361
|
+
}
|
|
362
|
+
const inFlight = inFlightApiChecks.get(cacheKey);
|
|
363
|
+
if (inFlight) {
|
|
364
|
+
return inFlight;
|
|
365
|
+
}
|
|
366
|
+
const checkPromise = (async () => {
|
|
367
|
+
try {
|
|
368
|
+
await ensureApiEnabledModule.ensure(projectId, apiUri, "hosting", true);
|
|
369
|
+
failedApiChecks.delete(cacheKey);
|
|
370
|
+
}
|
|
371
|
+
catch (err) {
|
|
372
|
+
const errMsg = (0, error_1.getErrMsg)(err);
|
|
373
|
+
logger_1.logger.debug(`[hosting] failed to ensure Hosting API is enabled: ${errMsg}`);
|
|
374
|
+
const enableUrl = ensureApiEnabledModule.enableApiURI(projectId, apiName);
|
|
375
|
+
if (isServiceUsagePermissionError(err)) {
|
|
376
|
+
failedApiChecks.set(cacheKey, Date.now() + FAILED_API_CHECK_TTL_MS);
|
|
377
|
+
if (isServiceUsageEnableError(err, errMsg)) {
|
|
378
|
+
utils.logLabeledWarning("hosting", clc.bold(`Unable to enable ${apiName} on project ${projectId}. Enable the API by visiting ${enableUrl}, or grant the caller the roles/serviceusage.serviceUsageAdmin role.`));
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
utils.logLabeledWarning("hosting", clc.bold(`Unable to check whether ${apiName} is enabled on project ${projectId}. Grant the caller the roles/serviceusage.serviceUsageConsumer role to check API enablement, or ensure the API is enabled at ${enableUrl} if subsequent requests fail.`));
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
utils.logLabeledWarning("hosting", clc.bold(`Unable to ensure that ${apiName} is enabled on project ${projectId}. Ensure it is enabled at ${enableUrl} if subsequent requests fail.`));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
finally {
|
|
389
|
+
inFlightApiChecks.delete(cacheKey);
|
|
390
|
+
}
|
|
391
|
+
})();
|
|
392
|
+
inFlightApiChecks.set(cacheKey, checkPromise);
|
|
393
|
+
return checkPromise;
|
|
394
|
+
}
|
package/lib/hosting/proxy.js
CHANGED
|
@@ -27,7 +27,7 @@ function makeVary(vary = "") {
|
|
|
27
27
|
return varies.join(", ");
|
|
28
28
|
}
|
|
29
29
|
function proxyRequestHandler(url, rewriteIdentifier, options = {}) {
|
|
30
|
-
|
|
30
|
+
const handle = async (req, res, next) => {
|
|
31
31
|
logger_1.logger.info(`[hosting] Rewriting ${req.url} to ${url} for ${rewriteIdentifier}`);
|
|
32
32
|
const cookie = req.headers.cookie || "";
|
|
33
33
|
const sessionCookie = cookie.split(/; ?/).find((c) => {
|
|
@@ -164,6 +164,9 @@ function proxyRequestHandler(url, rewriteIdentifier, options = {}) {
|
|
|
164
164
|
res.statusCode = proxyRes.status;
|
|
165
165
|
proxyRes.body.pipe(res);
|
|
166
166
|
};
|
|
167
|
+
return (req, res, next) => {
|
|
168
|
+
void handle(req, res, next).catch(next);
|
|
169
|
+
};
|
|
167
170
|
}
|
|
168
171
|
function errorRequestHandler(error) {
|
|
169
172
|
return (req, res) => {
|
|
@@ -11,10 +11,11 @@ const auth_1 = require("../../../auth");
|
|
|
11
11
|
const fsutils_1 = require("../../../fsutils");
|
|
12
12
|
const iam_1 = require("../../../gcp/iam");
|
|
13
13
|
const resourceManager_1 = require("../../../gcp/resourceManager");
|
|
14
|
+
const api_1 = require("../../../hosting/api");
|
|
14
15
|
const logger_1 = require("../../../logger");
|
|
15
16
|
const prompt_1 = require("../../../prompt");
|
|
16
17
|
const utils_1 = require("../../../utils");
|
|
17
|
-
const
|
|
18
|
+
const api_2 = require("../../../api");
|
|
18
19
|
const apiv2_1 = require("../../../apiv2");
|
|
19
20
|
const error_1 = require("../../../error");
|
|
20
21
|
let GIT_DIR;
|
|
@@ -27,7 +28,7 @@ const YML_MERGE_FILENAME = "firebase-hosting-merge.yml";
|
|
|
27
28
|
const CHECKOUT_GITHUB_ACTION_NAME = "actions/checkout@v4";
|
|
28
29
|
const HOSTING_GITHUB_ACTION_NAME = "FirebaseExtended/action-hosting-deploy@v0";
|
|
29
30
|
const SERVICE_ACCOUNT_MAX_KEY_NUMBER = 10;
|
|
30
|
-
const githubApiClient = new apiv2_1.Client({ urlPrefix: (0,
|
|
31
|
+
const githubApiClient = new apiv2_1.Client({ urlPrefix: (0, api_2.githubApiOrigin)(), auth: false });
|
|
31
32
|
async function initGitHub(setup) {
|
|
32
33
|
if (!setup.projectId) {
|
|
33
34
|
return (0, utils_1.reject)("Could not determine Project ID, can't set up GitHub workflow.", { exit: 1 });
|
|
@@ -35,6 +36,7 @@ async function initGitHub(setup) {
|
|
|
35
36
|
if (!setup.config.hosting && !setup.featureInfo?.hosting) {
|
|
36
37
|
return (0, utils_1.reject)(`Didn't find a Hosting config in firebase.json. Run ${(0, colorette_1.bold)("firebase init hosting")} instead.`);
|
|
37
38
|
}
|
|
39
|
+
await (0, api_1.ensureApiEnabled)(setup.projectId);
|
|
38
40
|
logger_1.logger.info();
|
|
39
41
|
const gitRoot = getGitFolderPath();
|
|
40
42
|
GIT_DIR = path.join(gitRoot, ".git");
|
|
@@ -107,7 +109,7 @@ async function initGitHub(setup) {
|
|
|
107
109
|
}
|
|
108
110
|
logger_1.logger.info();
|
|
109
111
|
(0, utils_1.logLabeledBullet)("Action required", `Visit this URL to revoke authorization for the Firebase CLI GitHub OAuth App:`);
|
|
110
|
-
logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${(0,
|
|
112
|
+
logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${(0, api_2.githubClientId)()}`)));
|
|
111
113
|
(0, utils_1.logLabeledBullet)("Action required", `Push any new workflow file(s) to your repo`);
|
|
112
114
|
}
|
|
113
115
|
function getGitFolderPath() {
|
|
@@ -277,7 +279,7 @@ async function promptForRepo(options, ghAccessToken) {
|
|
|
277
279
|
(0, utils_1.logWarning)("The provided authorization cannot be used with this repository. If this repository is in an organization, did you remember to grant access?", "error");
|
|
278
280
|
logger_1.logger.info();
|
|
279
281
|
(0, utils_1.logLabeledBullet)("Action required", `Visit this URL to ensure access has been granted to the appropriate organization(s) for the Firebase CLI GitHub OAuth App:`);
|
|
280
|
-
logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${(0,
|
|
282
|
+
logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${(0, api_2.githubClientId)()}`)));
|
|
281
283
|
logger_1.logger.info();
|
|
282
284
|
}
|
|
283
285
|
return false;
|
|
@@ -69,6 +69,7 @@ async function askQuestions(setup, config, options) {
|
|
|
69
69
|
setup.featureInfo = setup.featureInfo || {};
|
|
70
70
|
setup.featureInfo.hosting = {};
|
|
71
71
|
if (setup.projectId) {
|
|
72
|
+
await (0, api_1.ensureApiEnabled)(setup.projectId);
|
|
72
73
|
let hasHostingSite = true;
|
|
73
74
|
try {
|
|
74
75
|
await (0, getDefaultHostingSite_1.getDefaultHostingSite)({ projectId: setup.projectId });
|
|
@@ -113,6 +114,9 @@ async function actuate(setup, config, options) {
|
|
|
113
114
|
if (hostingInfo.redirectToAppHosting) {
|
|
114
115
|
return;
|
|
115
116
|
}
|
|
117
|
+
if (setup.projectId) {
|
|
118
|
+
await (0, api_1.ensureApiEnabled)(setup.projectId);
|
|
119
|
+
}
|
|
116
120
|
if (hostingInfo.newSiteId && setup.projectId) {
|
|
117
121
|
await (0, api_1.createSite)(setup.projectId, hostingInfo.newSiteId);
|
|
118
122
|
logger_1.logger.info();
|
|
@@ -87,7 +87,7 @@ googleCheckbox.addEventListener("change", (e) => {
|
|
|
87
87
|
googleFields.classList.remove("active");
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
-
|
|
90
|
+
async function onInitClick() {
|
|
91
91
|
const selectedProduct = Array.from(productRadios).find((r) => r.checked)?.value;
|
|
92
92
|
if (!selectedProjectId) {
|
|
93
93
|
setStatus("Please select a project first.", "error");
|
|
@@ -158,6 +158,9 @@ initBtn.addEventListener("click", async () => {
|
|
|
158
158
|
initBtn.disabled = false;
|
|
159
159
|
initBtn.textContent = "Initialize";
|
|
160
160
|
}
|
|
161
|
+
}
|
|
162
|
+
initBtn.addEventListener("click", () => {
|
|
163
|
+
void onInitClick();
|
|
161
164
|
});
|
|
162
165
|
app.onhostcontextchanged = (ctx) => {
|
|
163
166
|
if (ctx.theme)
|
package/lib/mcp/index.js
CHANGED
|
@@ -409,7 +409,7 @@ class FirebaseMcpServer {
|
|
|
409
409
|
app.use(cors());
|
|
410
410
|
const port = options.port || 3000;
|
|
411
411
|
const transports = {};
|
|
412
|
-
|
|
412
|
+
const handleSse = async (req, res) => {
|
|
413
413
|
this.logger.debug(`[SSE] GET /sse connection attempt from ${req.ip}`);
|
|
414
414
|
try {
|
|
415
415
|
const transport = new sse_js_1.SSEServerTransport("/message", res);
|
|
@@ -429,8 +429,11 @@ class FirebaseMcpServer {
|
|
|
429
429
|
catch (err) {
|
|
430
430
|
this.logger.error(`[SSE] Connection error: ${err}`);
|
|
431
431
|
}
|
|
432
|
+
};
|
|
433
|
+
app.get("/sse", (req, res) => {
|
|
434
|
+
void handleSse(req, res);
|
|
432
435
|
});
|
|
433
|
-
|
|
436
|
+
const handleMessage = async (req, res) => {
|
|
434
437
|
const sessionId = req.query.sessionId;
|
|
435
438
|
this.logger.debug(`[SSE] POST /message attempt for session ${sessionId}`);
|
|
436
439
|
const transport = transports[sessionId];
|
|
@@ -447,6 +450,9 @@ class FirebaseMcpServer {
|
|
|
447
450
|
this.logger.error(`[SSE] Rejecting message: No active transport found for session ${sessionId}`);
|
|
448
451
|
res.status(400).send("No active SSE transport connection found for this session");
|
|
449
452
|
}
|
|
453
|
+
};
|
|
454
|
+
app.post("/message", (req, res) => {
|
|
455
|
+
void handleMessage(req, res);
|
|
450
456
|
});
|
|
451
457
|
app.listen(port, "127.0.0.1", () => {
|
|
452
458
|
this.logger.info(`MCP Server running on HTTP/SSE mode at http://127.0.0.1:${port}`);
|
|
@@ -112,14 +112,14 @@ Here are a list of prerequisite steps that must be completed before running a te
|
|
|
112
112
|
devices.
|
|
113
113
|
|
|
114
114
|
Once the test has started, provide the developer a link to see the results of the test in the Firebase Console.
|
|
115
|
-
You should already know the value of \`appId
|
|
115
|
+
You should already know the value of \`appId\` and \`projectId\` from earlier (if you only know \`projectNumber\`,
|
|
116
116
|
use the \`firebase_get_project\` tool to get \`projectId\`). \`packageName\` is the package name of the app we tested.
|
|
117
117
|
The \`apptesting_run_test\` tool returns a response with field \`name\` in the form
|
|
118
|
-
projects/{projectNumber}/apps/{appId}/releases/{releaseId}/tests/{releaseTestId}. Extract the values for
|
|
118
|
+
projects/{projectNumber}/apps/{appId}/releases/{releaseId}/tests/{releaseTestId}. Extract the values for \`releaseId\`
|
|
119
119
|
and \`releaseTestId\` and use provide a link to the results in the Firebase Console in the format:
|
|
120
120
|
\`https://console.firebase.google.com/u/0/project/{projectId}/apptesting/app/android:{packageName}/releases/{releaseId}/tests/{releaseTestId}\`.
|
|
121
121
|
|
|
122
|
-
You can check the status of the test using the \`apptesting_check_status\` tool with \`release_test_name
|
|
122
|
+
You can check the status of the test using the \`apptesting_check_status\` tool with \`release_test_name\` set to
|
|
123
123
|
the name of the release test returned by the \`run_test\` tool.
|
|
124
124
|
`.trim(),
|
|
125
125
|
},
|
|
@@ -79,12 +79,12 @@ Follow the steps below taking note of any user instructions provided above.
|
|
|
79
79
|
Example (No): "No, there are no dependencies or file structures that indicate the use of a server-side rendering framework."
|
|
80
80
|
4. If there is no \`firebase.json\` file, manually create one based on whether the app requires SSR:
|
|
81
81
|
4a. If the app requires SSR, configure Firebase App Hosting:
|
|
82
|
-
Create \`firebase.json
|
|
82
|
+
Create \`firebase.json\` with an "apphosting" configuration, setting backendId to the app's name in package.json: \`{"apphosting": {"backendId": "<backendId>"}}\`
|
|
83
83
|
4b. If the app does NOT require SSR, configure Firebase Hosting:
|
|
84
|
-
Create \`firebase.json
|
|
84
|
+
Create \`firebase.json\` with a "hosting" configuration. Add a \`{"hosting": {"predeploy": "<build_script>"}}\` config to build before deploying.
|
|
85
85
|
5. Check if there is an active Firebase project for this environment (the \`firebase_get_environment\` tool may be helpful). If there is, provide the active project ID to the user and ask them if they want to proceed using that project. If there is not an active project, give the user two options: Provide an existing project ID or create a new project. Only use the list_projects tool on user request. Wait for their response before proceeding.
|
|
86
86
|
5a. If the user chooses to use an existing Firebase project, the \`firebase_list_projects\` tool may be helpful. Set the selected project as the active project (the \`firebase_update_environment\` tool may be helpful).
|
|
87
|
-
5b. If the user chooses to create a new project, use the \`firebase_create_project
|
|
87
|
+
5b. If the user chooses to create a new project, use the \`firebase_create_project\` tool. Then set the new project as the active project (the \`firebase_update_environment\` tool may be helpful).
|
|
88
88
|
6. If firebase.json contains an "apphosting" configuration, check if a backend exists matching the provided backendId (the \`apphosting_list_backends\` tool may be helpful).
|
|
89
89
|
If it doesn't exist, create one by running the \`${firebaseCliCommand} apphosting:backends:create --backend <backendId> --primary-region us-central1 --root-dir .\` shell.
|
|
90
90
|
7. Only after making sure Firebase has been initialized, run the \`${firebaseCliCommand} deploy\` shell command to perform the deploy. This may take a few minutes.
|
|
@@ -36,7 +36,7 @@ Before starting, ensure you have **Node.js 16+** and npm installed. Install them
|
|
|
36
36
|
|
|
37
37
|
## Firebase Setup Instructions
|
|
38
38
|
|
|
39
|
-
### 1
|
|
39
|
+
### 1. Understand the Application Setup
|
|
40
40
|
|
|
41
41
|
Scan the application files to identify what type of application the user is building. Ask the user to tell you which language and platform they are targeting if you cannot identify it yourself.
|
|
42
42
|
|
|
@@ -49,12 +49,12 @@ The following mobile and web applications are supported. Let the user know their
|
|
|
49
49
|
|
|
50
50
|
Take the following actions depending on the language and platform or framework that is identified:
|
|
51
51
|
|
|
52
|
-
- Android Platform
|
|
53
|
-
- Web Platform
|
|
54
|
-
- Flutter Platform
|
|
55
|
-
- Unsupported Platform
|
|
52
|
+
- Android Platform -> Set up Firebase AI Logic
|
|
53
|
+
- Web Platform -> Set up Firebase AI Logic
|
|
54
|
+
- Flutter Platform -> Set up Firebase AI Logic. Always do the subsequent firebase_init call using the web app
|
|
55
|
+
- Unsupported Platform -> Direct the user to Firebase Docs to learn how to set up AI Logic for their application (share this link with the user https://firebase.google.com/docs/ai-logic/get-started?api=dev)
|
|
56
56
|
|
|
57
|
-
### 2
|
|
57
|
+
### 2. Set up Firebase AI Logic
|
|
58
58
|
|
|
59
59
|
#### Set up the Firebase AI Logic Backend
|
|
60
60
|
|
|
@@ -64,11 +64,11 @@ Take the following actions depending on the language and platform or framework t
|
|
|
64
64
|
- 1. In your project-level \`/build.gradle.kts\` file, add the plugin to the plugins block: id("com.google.gms.google-services") version "4.4.2" apply false
|
|
65
65
|
- 2. In your **app-level** \`/app/build.gradle.kts\` file, apply the plugin: id("com.google.gms.google-services")
|
|
66
66
|
|
|
67
|
-
### 3
|
|
67
|
+
### 3. Implement AI Features
|
|
68
68
|
|
|
69
69
|
#### Gather Building Blocks for Code Generation
|
|
70
70
|
- Identify the correct initialization code snippet from the "Initialization Code References" section based on the language, platform, or framework used in the developer's app.
|
|
71
|
-
- Use the reference loaded from the step above to generate the initialization snippet. PLEASE USE THE EXACT SNIPPET AS A STARTING POINT
|
|
71
|
+
- Use the reference loaded from the step above to generate the initialization snippet. PLEASE USE THE EXACT SNIPPET AS A STARTING POINT!
|
|
72
72
|
- For Android apps, always include the following imports. do not forget or modify them
|
|
73
73
|
- import com.google.firebase.Firebase
|
|
74
74
|
- import com.google.firebase.ai.ai
|
|
@@ -102,7 +102,7 @@ Take the following actions depending on the language and platform or framework t
|
|
|
102
102
|
- Now implement the feature according to the plan you put together. Do not stray away from the instructions provided to you. Always re-read them fully and consult them if you run into any issues.
|
|
103
103
|
- ***DO NOT EXECUTE THE CODE YET. PERFORM THE VALIDATIONS IN STEP 4 BEFORE HANDING THE SESSION BACK OVER TO THE USER***
|
|
104
104
|
|
|
105
|
-
### 4
|
|
105
|
+
### 4. Validate Implementation
|
|
106
106
|
|
|
107
107
|
#### Perform the following checks before handing the session back to the user.
|
|
108
108
|
- Walk through the validation steps one-by-one. Analyze your instructions and the code you generated. Confirm you did not make any mistakes. If you made a mistake, FIX IT.
|
|
@@ -116,7 +116,7 @@ Take the following actions depending on the language and platform or framework t
|
|
|
116
116
|
- Confirmation that the backend is correctly configured to use the Google AI backend.
|
|
117
117
|
- Confirmation that the gemini model is correctly set based on the feature the user is implementing
|
|
118
118
|
|
|
119
|
-
### 5
|
|
119
|
+
### 5. Code Snippet References
|
|
120
120
|
|
|
121
121
|
#### Initialization Code References
|
|
122
122
|
|