firebase-tools 15.24.0 → 15.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/lib/api.js +4 -2
  2. package/lib/appcheck/api.js +42 -0
  3. package/lib/appcheck/prompts.js +41 -0
  4. package/lib/appcheck/types.js +2 -0
  5. package/lib/command.js +11 -3
  6. package/lib/commands/ailogic-config-get.js +75 -0
  7. package/lib/commands/ailogic-config-set.js +109 -0
  8. package/lib/commands/ailogic-providers-disable.js +39 -0
  9. package/lib/commands/ailogic-providers-enable.js +28 -0
  10. package/lib/commands/ailogic-providers-list.js +29 -0
  11. package/lib/commands/appcheck-debugtokens-create.js +95 -0
  12. package/lib/commands/appcheck-debugtokens-delete.js +48 -0
  13. package/lib/commands/appcheck-debugtokens-list.js +35 -0
  14. package/lib/commands/apps-sdkconfig.js +2 -23
  15. package/lib/commands/database-get.js +1 -1
  16. package/lib/commands/index.js +15 -0
  17. package/lib/deploy/functions/build.js +93 -3
  18. package/lib/deploy/functions/params.js +45 -11
  19. package/lib/deploy/functions/prepare.js +22 -2
  20. package/lib/deploy/functions/runtimes/node/index.js +8 -7
  21. package/lib/deploy/functions/runtimes/node/versioning.js +8 -3
  22. package/lib/deploy/functions/validate.js +5 -2
  23. package/lib/deploy/hosting/uploader.js +2 -1
  24. package/lib/emulator/dataconnect/pgliteServer.js +2 -1
  25. package/lib/emulator/downloadableEmulatorInfo.json +6 -6
  26. package/lib/emulator/downloadableEmulators.js +1 -0
  27. package/lib/emulator/hubExport.js +2 -1
  28. package/lib/emulator/storage/apis/firebase.js +24 -5
  29. package/lib/emulator/storage/apis/gcloud.js +16 -6
  30. package/lib/emulator/storage/rules/runtime.js +45 -33
  31. package/lib/emulator/storage/server.js +2 -5
  32. package/lib/emulator/storage/upload.js +1 -0
  33. package/lib/ensureApiEnabled.js +8 -0
  34. package/lib/experiments.js +16 -0
  35. package/lib/extensions/warnings.js +64 -0
  36. package/lib/functions/env.js +22 -2
  37. package/lib/functions/secrets.js +4 -1
  38. package/lib/gcp/ailogic.js +165 -1
  39. package/lib/gcp/cloudfunctionsv2.js +7 -0
  40. package/lib/gcp/firedata.js +5 -1
  41. package/lib/gcp/serviceusage.js +26 -0
  42. package/lib/init/features/ailogic/index.js +3 -29
  43. package/lib/init/features/database.js +1 -1
  44. package/lib/management/apps.js +16 -5
  45. package/lib/mcp/onemcp/onemcp_server.js +28 -9
  46. package/lib/mcp/tools/core/get_security_rules.js +2 -1
  47. package/lib/profiler.js +1 -1
  48. package/lib/streamUtils.js +3 -0
  49. package/lib/tsconfig.compile.tsbuildinfo +1 -1
  50. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  51. package/package.json +2 -2
package/lib/api.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hostingApiOrigin = exports.firebaseStorageOrigin = exports.storageOrigin = exports.runtimeconfigOrigin = exports.rulesOrigin = exports.resourceManagerOrigin = 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.artifactRegistryDomain = exports.developerConnectP4SADomain = exports.developerConnectOrigin = exports.containerRegistryDomain = exports.cloudMonitoringOrigin = exports.cloudloggingOrigin = exports.cloudbillingOrigin = exports.clientSecret = exports.clientId = exports.authProxyOrigin = void 0;
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 = void 0;
3
+ exports.firebaseStorageOrigin = exports.storageOrigin = exports.runtimeconfigOrigin = exports.rulesOrigin = exports.resourceManagerOrigin = 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.artifactRegistryDomain = exports.developerConnectP4SADomain = exports.developerConnectOrigin = exports.containerRegistryDomain = exports.cloudMonitoringOrigin = exports.cloudloggingOrigin = exports.cloudbillingOrigin = exports.clientSecret = exports.clientId = exports.authProxyOrigin = void 0;
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 = void 0;
5
5
  exports.getScopes = getScopes;
6
6
  exports.setScopes = setScopes;
7
7
  const constants_1 = require("./emulator/constants");
@@ -29,6 +29,8 @@ const developerConnectP4SADomain = () => utils.envOverride("DEVELOPERCONNECT_P4S
29
29
  exports.developerConnectP4SADomain = developerConnectP4SADomain;
30
30
  const artifactRegistryDomain = () => utils.envOverride("ARTIFACT_REGISTRY_DOMAIN", "https://artifactregistry.googleapis.com");
31
31
  exports.artifactRegistryDomain = artifactRegistryDomain;
32
+ const appCheckOrigin = () => utils.envOverride("FIREBASE_APPCHECK_URL", "https://firebaseappcheck.googleapis.com");
33
+ exports.appCheckOrigin = appCheckOrigin;
32
34
  const appDistributionOrigin = () => utils.envOverride("FIREBASE_APP_DISTRIBUTION_URL", "https://firebaseappdistribution.googleapis.com");
33
35
  exports.appDistributionOrigin = appDistributionOrigin;
34
36
  const apphostingOrigin = () => utils.envOverride("FIREBASE_APPHOSTING_URL", "https://firebaseapphosting.googleapis.com");
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.client = void 0;
4
+ exports.createDebugToken = createDebugToken;
5
+ exports.listDebugTokens = listDebugTokens;
6
+ exports.deleteDebugToken = deleteDebugToken;
7
+ const api_1 = require("../api");
8
+ const apiv2_1 = require("../apiv2");
9
+ const API_VERSION = "v1";
10
+ exports.client = new apiv2_1.Client({
11
+ urlPrefix: (0, api_1.appCheckOrigin)(),
12
+ auth: true,
13
+ apiVersion: API_VERSION,
14
+ });
15
+ async function createDebugToken(projectNumber, appId, displayName, token) {
16
+ const parent = `projects/${projectNumber}/apps/${appId}`;
17
+ const res = await exports.client.post(`${parent}/debugTokens`, {
18
+ displayName,
19
+ token,
20
+ });
21
+ return res.body;
22
+ }
23
+ async function listDebugTokens(projectNumber, appId) {
24
+ const parent = `projects/${projectNumber}/apps/${appId}`;
25
+ const debugTokens = [];
26
+ let pageToken = "";
27
+ do {
28
+ const queryParams = {};
29
+ if (pageToken) {
30
+ queryParams.pageToken = pageToken;
31
+ }
32
+ const res = await exports.client.get(`${parent}/debugTokens`, { queryParams });
33
+ if (res.body?.debugTokens) {
34
+ debugTokens.push(...res.body.debugTokens);
35
+ }
36
+ pageToken = res.body?.nextPageToken || "";
37
+ } while (pageToken);
38
+ return debugTokens;
39
+ }
40
+ async function deleteDebugToken(name) {
41
+ await exports.client.delete(name);
42
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOrPromptProjectAndAppId = void 0;
4
+ exports.getOrPromptAppId = getOrPromptAppId;
5
+ const apps_1 = require("../management/apps");
6
+ const projectUtils_1 = require("../projectUtils");
7
+ const appUtils_1 = require("../appUtils");
8
+ const error_1 = require("../error");
9
+ const logger_1 = require("../logger");
10
+ const clc = require("colorette");
11
+ async function getOrPromptAppId(options) {
12
+ const projectId = (0, projectUtils_1.needProjectId)(options);
13
+ logger_1.logger.info(`Active Project: ${clc.bold(projectId)}`);
14
+ if (options.app) {
15
+ return { projectId, appId: options.app };
16
+ }
17
+ const projectDir = options.cwd || process.cwd();
18
+ let apps = await (0, apps_1.listFirebaseApps)(projectId, apps_1.AppPlatform.ANY);
19
+ if (!apps.length) {
20
+ throw new error_1.FirebaseError(`There are no apps associated with project ${projectId}.`);
21
+ }
22
+ const localApps = await (0, appUtils_1.detectApps)(projectDir);
23
+ const localAppIds = localApps.map((a) => a.appId).filter(Boolean);
24
+ if (localAppIds.length > 0) {
25
+ const filteredApps = apps.filter((app) => localAppIds.includes(app.appId));
26
+ if (filteredApps.length > 0) {
27
+ apps = filteredApps;
28
+ }
29
+ }
30
+ if (apps.length === 1) {
31
+ return { projectId, appId: apps[0].appId };
32
+ }
33
+ else if (options.nonInteractive) {
34
+ throw new error_1.FirebaseError(`Project ${projectId} has multiple apps, must specify an app id.`);
35
+ }
36
+ const selectedApp = await (0, apps_1.selectAppInteractively)(apps, apps_1.AppPlatform.ANY, {
37
+ message: "Select the app to register a debug token for:",
38
+ });
39
+ return { projectId, appId: selectedApp.appId };
40
+ }
41
+ exports.getOrPromptProjectAndAppId = getOrPromptAppId;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/command.js CHANGED
@@ -18,6 +18,8 @@ const projects_1 = require("./management/projects");
18
18
  const studio_1 = require("./management/studio");
19
19
  const requireAuth_1 = require("./requireAuth");
20
20
  const env_1 = require("./env");
21
+ const experiments = require("./experiments");
22
+ const warnings_1 = require("./extensions/warnings");
21
23
  function isCommandModule(value) {
22
24
  return typeof value === "function" && typeof value.load === "function";
23
25
  }
@@ -73,8 +75,7 @@ class Command {
73
75
  if (this.aliases) {
74
76
  cmd.aliases(this.aliases);
75
77
  }
76
- this.options.forEach((args) => {
77
- const flags = args.shift();
78
+ this.options.forEach(([flags, ...args]) => {
78
79
  cmd.option(flags, ...args);
79
80
  });
80
81
  if (this.helpText) {
@@ -267,10 +268,17 @@ class Command {
267
268
  }
268
269
  const options = (0, lodash_1.last)(args);
269
270
  await this.prepare(options);
271
+ if (this.name.startsWith("ext:") && experiments.isEnabled("extdeprecationwarnings")) {
272
+ (0, warnings_1.showDeprecationWarningBefore)(this.name, options);
273
+ }
270
274
  for (const before of this.befores) {
271
275
  await before.fn(options, ...before.args);
272
276
  }
273
- return this.actionFn(...args);
277
+ const result = await this.actionFn(...args);
278
+ if (this.name.startsWith("ext:") && experiments.isEnabled("extdeprecationwarnings")) {
279
+ (0, warnings_1.showDeprecationWarningAfter)(this.name, options);
280
+ }
281
+ return result;
274
282
  };
275
283
  }
276
284
  }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const requirePermissions_1 = require("../requirePermissions");
6
+ const projectUtils_1 = require("../projectUtils");
7
+ const ailogic = require("../gcp/ailogic");
8
+ const logger_1 = require("../logger");
9
+ const READABLE_CONFIG_PATHS = [
10
+ "providers",
11
+ ...ailogic.PROVIDER_TYPES.map((p) => `providers.${p}`),
12
+ "security",
13
+ ...ailogic.WRITABLE_CONFIG_PATHS.filter((p) => p.startsWith("security.")),
14
+ "monitoring",
15
+ ...ailogic.WRITABLE_CONFIG_PATHS.filter((p) => p.startsWith("monitoring.")),
16
+ ];
17
+ function isRecord(value) {
18
+ return typeof value === "object" && value !== null;
19
+ }
20
+ exports.command = new command_1.Command("ailogic:config:get [path]")
21
+ .description("read AI Logic configuration")
22
+ .help(`prints the full AI Logic configuration for the active project as JSON. If [path] is given, prints only that section or value.
23
+
24
+ Valid values for [path]:
25
+
26
+ ${READABLE_CONFIG_PATHS.map((p) => ` ${p}`).join("\n")}
27
+
28
+ For example, to check whether requests are restricted to authenticated users:
29
+
30
+ firebase ailogic:config:get security.auth-only`)
31
+ .before(requirePermissions_1.requirePermissions, ["firebasevertexai.config.get", "serviceusage.services.get"])
32
+ .action(async (path, options) => {
33
+ const projectId = (0, projectUtils_1.needProjectId)(options);
34
+ if (path) {
35
+ ailogic.assertKnownConfigPath(path, READABLE_CONFIG_PATHS);
36
+ }
37
+ if (!(await ailogic.isAILogicApiEnabled(projectId))) {
38
+ logger_1.logger.info("Firebase AI Logic is not enabled on this project.");
39
+ return;
40
+ }
41
+ const config = await ailogic.getConfig(projectId);
42
+ const monitoringState = config.telemetryConfig?.mode === "ALL";
43
+ const sampleRatePercent = config.telemetryConfig?.samplingRate !== undefined
44
+ ? Math.round(config.telemetryConfig.samplingRate * 100)
45
+ : 100;
46
+ const needsProviders = !path || path === "providers" || path.startsWith("providers.");
47
+ const enabledProviders = needsProviders ? await ailogic.listProviders(projectId) : [];
48
+ const configObj = {
49
+ ...(needsProviders && {
50
+ providers: Object.fromEntries(ailogic.PROVIDER_TYPES.map((p) => [p, enabledProviders.includes(p)])),
51
+ }),
52
+ security: {
53
+ "auth-only": config.trafficFilter?.firebaseAuthRequired ?? false,
54
+ "template-only": config.trafficFilter?.templateOnly ?? false,
55
+ },
56
+ monitoring: {
57
+ state: monitoringState,
58
+ "sample-rate-percentage": sampleRatePercent,
59
+ },
60
+ };
61
+ if (!path) {
62
+ logger_1.logger.info(JSON.stringify(configObj, null, 2));
63
+ return configObj;
64
+ }
65
+ let val = configObj;
66
+ for (const part of path.split(".")) {
67
+ if (!isRecord(val)) {
68
+ val = undefined;
69
+ break;
70
+ }
71
+ val = val[part];
72
+ }
73
+ logger_1.logger.info(typeof val === "object" ? JSON.stringify(val, null, 2) : String(val));
74
+ return val;
75
+ });
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const requirePermissions_1 = require("../requirePermissions");
6
+ const projectUtils_1 = require("../projectUtils");
7
+ const ailogic = require("../gcp/ailogic");
8
+ const clc = require("colorette");
9
+ const utils = require("../utils");
10
+ const error_1 = require("../error");
11
+ const prompt_1 = require("../prompt");
12
+ function parseBool(pathStr, value) {
13
+ const normalized = value.toLowerCase();
14
+ if (normalized !== "true" && normalized !== "false") {
15
+ throw new error_1.FirebaseError(`Value for ${clc.bold(pathStr)} must be 'true' or 'false'.`);
16
+ }
17
+ return normalized === "true";
18
+ }
19
+ function buildUpdate(pathStr, value) {
20
+ switch (pathStr) {
21
+ case "security.auth-only": {
22
+ const boolVal = parseBool(pathStr, value);
23
+ return {
24
+ config: { trafficFilter: { firebaseAuthRequired: boolVal } },
25
+ updateMask: "trafficFilter.firebaseAuthRequired",
26
+ normalizedValue: String(boolVal),
27
+ confirm: boolVal
28
+ ? {
29
+ message: `Enabling ${clc.bold(pathStr)} will reject requests from unauthenticated users. Continue?`,
30
+ isAlreadyEnabled: (current) => current.trafficFilter?.firebaseAuthRequired ?? false,
31
+ }
32
+ : undefined,
33
+ };
34
+ }
35
+ case "security.template-only": {
36
+ const boolVal = parseBool(pathStr, value);
37
+ return {
38
+ config: { trafficFilter: { templateOnly: boolVal } },
39
+ updateMask: "trafficFilter.templateOnly",
40
+ normalizedValue: String(boolVal),
41
+ confirm: boolVal
42
+ ? {
43
+ message: `Enabling ${clc.bold(pathStr)} will reject requests not using templates. Continue?`,
44
+ isAlreadyEnabled: (current) => current.trafficFilter?.templateOnly ?? false,
45
+ }
46
+ : undefined,
47
+ };
48
+ }
49
+ case "monitoring.state": {
50
+ const boolVal = parseBool(pathStr, value);
51
+ return {
52
+ config: { telemetryConfig: { mode: boolVal ? "ALL" : "NONE" } },
53
+ updateMask: "telemetryConfig.mode",
54
+ normalizedValue: String(boolVal),
55
+ };
56
+ }
57
+ case "monitoring.sample-rate-percentage": {
58
+ if (!/^\d+$/.test(value) || Number(value) < 1 || Number(value) > 100) {
59
+ throw new error_1.FirebaseError(`Value for ${clc.bold(pathStr)} must be an integer in the range 1-100.`);
60
+ }
61
+ return {
62
+ config: { telemetryConfig: { samplingRate: Number(value) / 100 } },
63
+ updateMask: "telemetryConfig.samplingRate",
64
+ normalizedValue: String(Number(value)),
65
+ };
66
+ }
67
+ default:
68
+ throw new error_1.FirebaseError(`Unknown configuration path: ${pathStr}`);
69
+ }
70
+ }
71
+ exports.command = new command_1.Command("ailogic:config:set <path> <value>")
72
+ .description("set one configuration value")
73
+ .help(`sets one AI Logic configuration value on the active project.
74
+
75
+ Valid values for <path>, and the <value> each accepts:
76
+
77
+ security.auth-only true|false - only allow requests from authenticated users
78
+ security.template-only true|false - only allow requests that use a server template
79
+ monitoring.state true|false - turn AI monitoring on or off
80
+ monitoring.sample-rate-percentage 1-100 - percentage of requests sampled for monitoring
81
+
82
+ For example, to only allow requests from authenticated users:
83
+
84
+ firebase ailogic:config:set security.auth-only true`)
85
+ .option("-f, --force", "bypass confirmation prompt")
86
+ .before(requirePermissions_1.requirePermissions, [
87
+ "firebasevertexai.config.update",
88
+ "firebasevertexai.config.get",
89
+ "serviceusage.services.get",
90
+ ])
91
+ .action(async (pathStr, value, options) => {
92
+ const projectId = (0, projectUtils_1.needProjectId)(options);
93
+ ailogic.assertKnownConfigPath(pathStr, ailogic.WRITABLE_CONFIG_PATHS);
94
+ const update = buildUpdate(pathStr, value);
95
+ await ailogic.ensureAILogicApiEnabled(projectId, options);
96
+ if (update.confirm && !update.confirm.isAlreadyEnabled(await ailogic.getConfig(projectId))) {
97
+ const confirmed = await (0, prompt_1.confirm)({
98
+ message: update.confirm.message,
99
+ force: options.force,
100
+ nonInteractive: options.nonInteractive,
101
+ });
102
+ if (!confirmed) {
103
+ throw new error_1.FirebaseError("Command aborted.", { exit: 1 });
104
+ }
105
+ }
106
+ await ailogic.updateConfig(projectId, update.config, [update.updateMask]);
107
+ utils.logSuccess(`Updated ${clc.bold(pathStr)} = ${update.normalizedValue}`);
108
+ return { path: pathStr, value: update.normalizedValue };
109
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const requirePermissions_1 = require("../requirePermissions");
6
+ const projectUtils_1 = require("../projectUtils");
7
+ const ailogic = require("../gcp/ailogic");
8
+ const clc = require("colorette");
9
+ const logger_1 = require("../logger");
10
+ const error_1 = require("../error");
11
+ const prompt_1 = require("../prompt");
12
+ exports.command = new command_1.Command("ailogic:providers:disable <providerType>")
13
+ .description("disable a Gemini API provider service")
14
+ .help(`disables the Google Cloud API that backs a Gemini API provider. Running apps that use the provider will no longer be able to invoke it.
15
+
16
+ Valid values for <providerType>:
17
+
18
+ gemini-developer-api the Gemini Developer API
19
+ gemini-agent-platform-api the Gemini API on the Agent Platform
20
+
21
+ For example:
22
+
23
+ firebase ailogic:providers:disable gemini-developer-api`)
24
+ .option("-f, --force", "bypass confirmation prompt")
25
+ .before(requirePermissions_1.requirePermissions, ["serviceusage.services.disable", "firebasevertexai.config.update"])
26
+ .action(async (providerType, options) => {
27
+ const projectId = (0, projectUtils_1.needProjectId)(options);
28
+ const provider = ailogic.parseProviderType(providerType);
29
+ const confirmed = await (0, prompt_1.confirm)({
30
+ message: `You are about to disable ${clc.bold(provider)}. This will stop running apps from invoking it. Are you sure?`,
31
+ force: options.force,
32
+ nonInteractive: options.nonInteractive,
33
+ });
34
+ if (!confirmed) {
35
+ throw new error_1.FirebaseError("Command aborted.", { exit: 1 });
36
+ }
37
+ await ailogic.disableProvider(projectId, provider);
38
+ logger_1.logger.info(clc.green(`Successfully disabled provider: ${clc.bold(provider)}`));
39
+ });
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const requirePermissions_1 = require("../requirePermissions");
6
+ const projectUtils_1 = require("../projectUtils");
7
+ const ailogic = require("../gcp/ailogic");
8
+ const clc = require("colorette");
9
+ const logger_1 = require("../logger");
10
+ exports.command = new command_1.Command("ailogic:providers:enable <providerType>")
11
+ .description("enable a Gemini API provider service")
12
+ .help(`enables the Google Cloud APIs that back a Gemini API provider, along with the Firebase AI Logic API.
13
+
14
+ Valid values for <providerType>:
15
+
16
+ gemini-developer-api the Gemini Developer API
17
+ gemini-agent-platform-api the Gemini API on the Agent Platform; requires the Blaze (pay-as-you-go) plan
18
+
19
+ For example:
20
+
21
+ firebase ailogic:providers:enable gemini-developer-api`)
22
+ .before(requirePermissions_1.requirePermissions, ["serviceusage.services.enable", "firebasevertexai.config.update"])
23
+ .action(async (providerType, options) => {
24
+ const projectId = (0, projectUtils_1.needProjectId)(options);
25
+ const provider = ailogic.parseProviderType(providerType);
26
+ await ailogic.enableProvider(projectId, provider);
27
+ logger_1.logger.info(clc.green(`Successfully enabled provider: ${clc.bold(provider)}`));
28
+ });
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const requirePermissions_1 = require("../requirePermissions");
6
+ const projectUtils_1 = require("../projectUtils");
7
+ const ailogic = require("../gcp/ailogic");
8
+ const clc = require("colorette");
9
+ const logger_1 = require("../logger");
10
+ const Table = require("cli-table3");
11
+ exports.command = new command_1.Command("ailogic:providers:list")
12
+ .description("list which Gemini API providers are enabled")
13
+ .before(requirePermissions_1.requirePermissions, ["serviceusage.services.get"])
14
+ .action(async (options) => {
15
+ const projectId = (0, projectUtils_1.needProjectId)(options);
16
+ const enabledProviders = await ailogic.listProviders(projectId);
17
+ if (enabledProviders.length === 0) {
18
+ logger_1.logger.info(clc.bold("No Gemini API providers are enabled."));
19
+ return enabledProviders;
20
+ }
21
+ const tableHead = ["Provider", "Status"];
22
+ const table = new Table({ head: tableHead, style: { head: ["green"] } });
23
+ for (const provider of ailogic.PROVIDER_TYPES) {
24
+ const isEnabled = enabledProviders.includes(provider);
25
+ table.push([clc.bold(provider), isEnabled ? clc.green("Enabled") : clc.red("Disabled")]);
26
+ }
27
+ logger_1.logger.info(table.toString());
28
+ return enabledProviders;
29
+ });
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const clc = require("colorette");
5
+ const node_crypto_1 = require("node:crypto");
6
+ const os = require("os");
7
+ const command_1 = require("../command");
8
+ const projectUtils_1 = require("../projectUtils");
9
+ const api_1 = require("../appcheck/api");
10
+ const prompts_1 = require("../appcheck/prompts");
11
+ const requireAuth_1 = require("../requireAuth");
12
+ const utils_1 = require("../utils");
13
+ const error_1 = require("../error");
14
+ const prompt_1 = require("../prompt");
15
+ const logger_1 = require("../logger");
16
+ exports.command = new command_1.Command("appcheck:debugtokens:create [debugToken]")
17
+ .description("generate and register an App Check debug token for an app")
18
+ .option("--app <appId>", "the app id of your Firebase app")
19
+ .option("--display-name <displayName>", "display name for the debug token")
20
+ .option("--force", "overwrite existing debug token if it has the same display name without prompting")
21
+ .before(requireAuth_1.requireAuth)
22
+ .action(async (debugToken, options) => {
23
+ const { appId } = await (0, prompts_1.getOrPromptProjectAndAppId)(options);
24
+ const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
25
+ let token = debugToken;
26
+ if (!token) {
27
+ if (!options.nonInteractive) {
28
+ const action = await (0, prompt_1.select)({
29
+ message: "Would you like to register a token generated by the SDK, or create a new one?",
30
+ choices: [
31
+ { name: "Create a new debug token", value: "generate" },
32
+ { name: "Register a token generated by the SDK", value: "sdk" },
33
+ ],
34
+ });
35
+ if (action === "sdk") {
36
+ token = await (0, prompt_1.password)({
37
+ message: "Enter the debug token generated by the SDK:",
38
+ validate: (val) => (val.trim().length > 0 ? true : "Debug token cannot be empty."),
39
+ });
40
+ }
41
+ else {
42
+ token = (0, node_crypto_1.randomUUID)();
43
+ }
44
+ }
45
+ else {
46
+ token = (0, node_crypto_1.randomUUID)();
47
+ }
48
+ }
49
+ let displayName = options.displayName;
50
+ const defaultName = `CLI Debug Token (${os.hostname() || "Unknown Host"})`;
51
+ if (!displayName) {
52
+ if (!options.nonInteractive) {
53
+ displayName = await (0, prompt_1.input)({
54
+ message: "What would you like to call this debug token?",
55
+ default: defaultName,
56
+ });
57
+ }
58
+ else {
59
+ displayName = defaultName;
60
+ }
61
+ }
62
+ const existingTokens = await (0, api_1.listDebugTokens)(projectNumber, appId);
63
+ const matchingTokens = existingTokens.filter((t) => t.displayName === displayName);
64
+ if (matchingTokens.length > 0) {
65
+ let shouldOverwrite = options.force;
66
+ if (!shouldOverwrite) {
67
+ if (options.nonInteractive) {
68
+ throw new error_1.FirebaseError(`A token with the display name "${displayName}" already exists. Must pass --force to overwrite in non-interactive mode.`, { exit: 1 });
69
+ }
70
+ shouldOverwrite = await (0, prompt_1.confirm)({
71
+ message: `A token with the display name "${displayName}" already exists. Delete the old token(s)?`,
72
+ default: true,
73
+ });
74
+ }
75
+ if (shouldOverwrite) {
76
+ for (const t of matchingTokens) {
77
+ await (0, api_1.deleteDebugToken)(t.name);
78
+ }
79
+ }
80
+ else {
81
+ throw new error_1.FirebaseError("Registration canceled.", { exit: 1 });
82
+ }
83
+ }
84
+ const result = await (0, utils_1.promiseWithSpinner)(async () => await (0, api_1.createDebugToken)(projectNumber, appId, displayName, token), `Registering App Check debug token with Firebase for app ${clc.bold(appId)}`);
85
+ (0, utils_1.logSuccess)(`Successfully registered App Check debug token:
86
+ - Display Name: ${clc.bold(result.displayName)}
87
+ - Resource Name: ${clc.cyan(result.name)}`);
88
+ if (!options.json) {
89
+ console.log(` - Token: ${clc.bold(clc.green(token))}\n`);
90
+ }
91
+ logger_1.logger.info(clc.yellow(clc.bold("Warning: ") +
92
+ "This debug token is a secret and should not be shared or uploaded to source code."));
93
+ logger_1.logger.info(clc.yellow("TODO: Remember to delete this token once your testing has finished."));
94
+ return result;
95
+ });
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const clc = require("colorette");
5
+ const command_1 = require("../command");
6
+ const projectUtils_1 = require("../projectUtils");
7
+ const api_1 = require("../appcheck/api");
8
+ const prompts_1 = require("../appcheck/prompts");
9
+ const requireAuth_1 = require("../requireAuth");
10
+ const utils_1 = require("../utils");
11
+ const prompt_1 = require("../prompt");
12
+ const error_1 = require("../error");
13
+ exports.command = new command_1.Command("appcheck:debugtokens:delete <debugTokenId>")
14
+ .description("delete a Firebase App Check debug token for an app")
15
+ .option("--app <appId>", "the app id of your Firebase app")
16
+ .option("--force", "attempt to delete debug token without prompting for confirmation")
17
+ .before(requireAuth_1.requireAuth)
18
+ .action(async (debugTokenId, options) => {
19
+ const { appId } = await (0, prompts_1.getOrPromptProjectAndAppId)(options);
20
+ const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
21
+ let debugTokenName = debugTokenId;
22
+ if (!debugTokenName.startsWith("projects/")) {
23
+ debugTokenName = `projects/${projectNumber}/apps/${appId}/debugTokens/${debugTokenId}`;
24
+ }
25
+ else {
26
+ const expectedPrefix = `projects/${projectNumber}/apps/${appId}/debugTokens/`;
27
+ if (!debugTokenName.startsWith(expectedPrefix)) {
28
+ throw new error_1.FirebaseError(`Debug token ${debugTokenId} does not belong to app ${appId} in project ${projectNumber}`, { exit: 1 });
29
+ }
30
+ }
31
+ if (!options.force) {
32
+ if (options.nonInteractive) {
33
+ throw new error_1.FirebaseError("Must pass --force to delete in non-interactive mode.", {
34
+ exit: 1,
35
+ });
36
+ }
37
+ const confirmMessage = `You are about to delete App Check debug token ${clc.bold(debugTokenName)}. Do you wish to continue?`;
38
+ const consent = await (0, prompt_1.confirm)({
39
+ message: confirmMessage,
40
+ default: false,
41
+ });
42
+ if (!consent) {
43
+ throw new error_1.FirebaseError("Delete App Check debug token canceled.");
44
+ }
45
+ }
46
+ await (0, utils_1.promiseWithSpinner)(async () => await (0, api_1.deleteDebugToken)(debugTokenName), `Deleting App Check debug token ${clc.bold(debugTokenName)}`);
47
+ (0, utils_1.logSuccess)(`Successfully deleted App Check debug token ${clc.bold(debugTokenName)}`);
48
+ });
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const clc = require("colorette");
5
+ const Table = require("cli-table3");
6
+ const command_1 = require("../command");
7
+ const projectUtils_1 = require("../projectUtils");
8
+ const api_1 = require("../appcheck/api");
9
+ const prompts_1 = require("../appcheck/prompts");
10
+ const requireAuth_1 = require("../requireAuth");
11
+ const logger_1 = require("../logger");
12
+ const utils_1 = require("../utils");
13
+ function logDebugTokensList(debugTokens) {
14
+ if (debugTokens.length === 0) {
15
+ logger_1.logger.info(clc.bold("No App Check debug tokens found."));
16
+ return;
17
+ }
18
+ const tableHead = ["Display Name", "Resource Name", "Update Time"];
19
+ const table = new Table({ head: tableHead, style: { head: ["green"] } });
20
+ debugTokens.forEach(({ displayName, name, updateTime }) => {
21
+ table.push([displayName, name, updateTime || "N/A"]);
22
+ });
23
+ logger_1.logger.info(table.toString());
24
+ }
25
+ exports.command = new command_1.Command("appcheck:debugtokens:list")
26
+ .description("list all Firebase App Check debug tokens for an app")
27
+ .option("--app <appId>", "the app id of your Firebase app")
28
+ .before(requireAuth_1.requireAuth)
29
+ .action(async (options) => {
30
+ const { appId } = await (0, prompts_1.getOrPromptProjectAndAppId)(options);
31
+ const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
32
+ const debugTokens = await (0, utils_1.promiseWithSpinner)(async () => await (0, api_1.listDebugTokens)(projectNumber, appId), `Listing App Check debug tokens for app ${clc.bold(appId)}`);
33
+ logDebugTokensList(debugTokens);
34
+ return debugTokens;
35
+ });
@@ -11,27 +11,6 @@ const error_1 = require("../error");
11
11
  const requireAuth_1 = require("../requireAuth");
12
12
  const logger_1 = require("../logger");
13
13
  const prompt_1 = require("../prompt");
14
- function checkForApps(apps, appPlatform) {
15
- if (!apps.length) {
16
- throw new error_1.FirebaseError(`There are no ${appPlatform === apps_1.AppPlatform.ANY ? "" : appPlatform + " "}apps ` +
17
- "associated with this Firebase project");
18
- }
19
- }
20
- async function selectAppInteractively(apps, appPlatform) {
21
- checkForApps(apps, appPlatform);
22
- const choices = apps.map((app) => {
23
- return {
24
- name: `${app.displayName || app.bundleId || app.packageName}` +
25
- ` - ${app.appId} (${app.platform})`,
26
- value: app,
27
- };
28
- });
29
- return await (0, prompt_1.select)({
30
- message: `Select the ${appPlatform === apps_1.AppPlatform.ANY ? "" : appPlatform + " "}` +
31
- "app to get the configuration data:",
32
- choices,
33
- });
34
- }
35
14
  exports.command = new command_1.Command("apps:sdkconfig [platform] [appId]")
36
15
  .description("print the Google Services config of a Firebase app. " +
37
16
  "[platform] can be IOS, ANDROID or WEB (case insensitive)")
@@ -49,7 +28,7 @@ exports.command = new command_1.Command("apps:sdkconfig [platform] [appId]")
49
28
  projectId = result.projectId;
50
29
  }
51
30
  const apps = await (0, apps_1.listFirebaseApps)(projectId, appPlatform);
52
- checkForApps(apps, appPlatform);
31
+ (0, apps_1.checkForApps)(apps, appPlatform);
53
32
  if (apps.length === 1) {
54
33
  appId = apps[0].appId;
55
34
  appPlatform = apps[0].platform;
@@ -58,7 +37,7 @@ exports.command = new command_1.Command("apps:sdkconfig [platform] [appId]")
58
37
  throw new error_1.FirebaseError(`Project ${projectId} has multiple apps, must specify an app id.`);
59
38
  }
60
39
  else {
61
- const appMetadata = await selectAppInteractively(apps, appPlatform);
40
+ const appMetadata = await (0, apps_1.selectAppInteractively)(apps, appPlatform);
62
41
  appId = appMetadata.appId;
63
42
  appPlatform = appMetadata.platform;
64
43
  }