firebase-tools 15.24.0 → 15.25.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.
Files changed (58) 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/functionsDeployHelper.js +18 -12
  19. package/lib/deploy/functions/params.js +45 -11
  20. package/lib/deploy/functions/prepare.js +38 -5
  21. package/lib/deploy/functions/release/executor.js +51 -8
  22. package/lib/deploy/functions/release/fabricator.js +34 -5
  23. package/lib/deploy/functions/runtimes/node/index.js +8 -7
  24. package/lib/deploy/functions/runtimes/node/versioning.js +8 -3
  25. package/lib/deploy/functions/validate.js +5 -2
  26. package/lib/deploy/hosting/uploader.js +2 -1
  27. package/lib/emulator/controller.js +34 -15
  28. package/lib/emulator/dataconnect/pgliteServer.js +2 -1
  29. package/lib/emulator/downloadableEmulatorInfo.json +6 -6
  30. package/lib/emulator/downloadableEmulators.js +1 -0
  31. package/lib/emulator/hubExport.js +2 -1
  32. package/lib/emulator/storage/apis/firebase.js +24 -5
  33. package/lib/emulator/storage/apis/gcloud.js +16 -6
  34. package/lib/emulator/storage/rules/runtime.js +45 -33
  35. package/lib/emulator/storage/server.js +2 -5
  36. package/lib/emulator/storage/upload.js +1 -0
  37. package/lib/ensureApiEnabled.js +8 -0
  38. package/lib/experiments.js +22 -0
  39. package/lib/extensions/warnings.js +64 -0
  40. package/lib/functions/env.js +22 -2
  41. package/lib/functions/projectConfig.js +98 -12
  42. package/lib/functions/secrets.js +4 -1
  43. package/lib/gcp/ailogic.js +165 -1
  44. package/lib/gcp/cloudfunctionsv2.js +7 -0
  45. package/lib/gcp/firedata.js +5 -1
  46. package/lib/gcp/serviceusage.js +26 -0
  47. package/lib/init/features/ailogic/index.js +3 -29
  48. package/lib/init/features/database.js +1 -1
  49. package/lib/management/apps.js +16 -5
  50. package/lib/mcp/onemcp/onemcp_server.js +28 -9
  51. package/lib/mcp/tools/core/get_security_rules.js +2 -1
  52. package/lib/profiler.js +1 -1
  53. package/lib/serve/functions.js +25 -7
  54. package/lib/streamUtils.js +3 -0
  55. package/lib/tsconfig.compile.tsbuildinfo +1 -1
  56. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  57. package/package.json +2 -2
  58. package/schema/firebase-config.json +93 -0
@@ -2,10 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.displayWarningsForDeploy = displayWarningsForDeploy;
4
4
  exports.outOfBandChangesWarning = outOfBandChangesWarning;
5
+ exports.isSilenced = isSilenced;
6
+ exports.showDeprecationWarningBefore = showDeprecationWarningBefore;
7
+ exports.showDeprecationWarningAfter = showDeprecationWarningAfter;
5
8
  const clc = require("colorette");
6
9
  const extensionsHelper_1 = require("./extensionsHelper");
7
10
  const deploymentSummary_1 = require("../deploy/extensions/deploymentSummary");
8
11
  const planner_1 = require("../deploy/extensions/planner");
12
+ const error_1 = require("../error");
9
13
  const logger_1 = require("../logger");
10
14
  const utils = require("../utils");
11
15
  const toListEntry = (i) => {
@@ -38,3 +42,63 @@ function outOfBandChangesWarning(instanceIds, isDynamic) {
38
42
  clc.bold(instanceIds.join("\n\t")) +
39
43
  `\nIf you proceed with this deployment, those changes will be overwritten.${extra}`);
40
44
  }
45
+ const FAQ_URL = "https://firebase.google.com/docs/extensions/faq-and-troubleshooting";
46
+ const WARN_BEFORE_COMMANDS = new Set([
47
+ "ext:install",
48
+ "ext:configure",
49
+ "ext:update",
50
+ "ext:sdk:install",
51
+ ]);
52
+ const WARN_STRONGLY_BEFORE_COMMANDS = new Set([
53
+ "ext:dev:init",
54
+ "ext:dev:upload",
55
+ "ext:dev:list",
56
+ "ext:dev:usage",
57
+ "ext:dev:undeprecate",
58
+ ]);
59
+ const WARN_AFTER_COMMANDS = new Set(["ext:list", "ext:info"]);
60
+ function isSilenced(options) {
61
+ const opts = options;
62
+ if (opts?.json ||
63
+ utils.getInheritedOption(options, "json") ||
64
+ opts?.nonInteractive ||
65
+ utils.getInheritedOption(options, "nonInteractive") ||
66
+ !process.stdout?.isTTY ||
67
+ opts?.quiet ||
68
+ utils.getInheritedOption(options, "quiet")) {
69
+ return true;
70
+ }
71
+ if (utils.isRunningInGithubAction() ||
72
+ (!!process.env.CI && process.env.CI !== "false") ||
73
+ !!process.env.BUILD_ID ||
74
+ !!process.env.TF_BUILD ||
75
+ !!process.env.GITHUB_ACTIONS) {
76
+ return true;
77
+ }
78
+ return false;
79
+ }
80
+ function showDeprecationWarningBefore(commandName, options) {
81
+ if (commandName === "ext:dev:register") {
82
+ throw new error_1.FirebaseError(`ext:dev:register is disabled. Registering new publisher profile IDs is no longer supported.\n` +
83
+ `The Firebase Extensions service will shut down on March 31, 2027.\n` +
84
+ `Learn more: ${FAQ_URL}`, { exit: 1 });
85
+ }
86
+ if (isSilenced(options)) {
87
+ return;
88
+ }
89
+ if (WARN_BEFORE_COMMANDS.has(commandName)) {
90
+ logger_1.logger.warn(clc.yellow(`⚠ Firebase Extensions will shut down on March 31, 2027. You will not be able to install or edit extensions after this date. Learn more: ${FAQ_URL}`));
91
+ }
92
+ else if (WARN_STRONGLY_BEFORE_COMMANDS.has(commandName)) {
93
+ logger_1.logger.warn(clc.yellow(`================================================================================\n` +
94
+ `⚠ Notice for Publishers: Firebase Extensions will shut down on March 31, 2027.\n` +
95
+ `Learn more: ${FAQ_URL}\n` +
96
+ `================================================================================`));
97
+ }
98
+ }
99
+ function showDeprecationWarningAfter(commandName, options) {
100
+ if (isSilenced(options) || !WARN_AFTER_COMMANDS.has(commandName)) {
101
+ return;
102
+ }
103
+ logger_1.logger.warn(clc.yellow(`⚠ Notice: Firebase Extensions will shut down on March 31, 2027. Learn more: ${FAQ_URL}`));
104
+ }
@@ -10,6 +10,7 @@ exports.checkForDuplicateKeys = checkForDuplicateKeys;
10
10
  exports.loadUserEnvs = loadUserEnvs;
11
11
  exports.loadFirebaseEnvs = loadFirebaseEnvs;
12
12
  exports.writeResolvedParams = writeResolvedParams;
13
+ exports.writeResolvedSecretRefs = writeResolvedSecretRefs;
13
14
  const clc = require("colorette");
14
15
  const fs = require("fs");
15
16
  const path = require("path");
@@ -17,7 +18,8 @@ const error_1 = require("../error");
17
18
  const logger_1 = require("../logger");
18
19
  const utils_1 = require("../utils");
19
20
  const FUNCTIONS_EMULATOR_DOTENV = ".env.local";
20
- const RESERVED_PREFIXES = ["X_GOOGLE_", "FIREBASE_", "EXT_"];
21
+ const RESERVED_PREFIXES = ["X_GOOGLE_", "FIREBASE_", "EXT_", "KIT_"];
22
+ const RESERVED_PREFIX_ALLOWLIST = ["FIREBASE_SECRET_REF_"];
21
23
  const RESERVED_KEYS = [
22
24
  "FIREBASE_CONFIG",
23
25
  "CLOUD_RUNTIME_CONFIG",
@@ -117,9 +119,15 @@ function validateKey(key) {
117
119
  throw new KeyValidationError(key, `Key ${key} must start with an uppercase ASCII letter or underscore` +
118
120
  ", and then consist of uppercase ASCII letters, digits, and underscores.");
119
121
  }
120
- if (RESERVED_PREFIXES.some((prefix) => key.startsWith(prefix))) {
122
+ if (keyConflictsWithReservedPrefixes(key)) {
121
123
  throw new KeyValidationError(key, `Key ${key} starts with a reserved prefix (${RESERVED_PREFIXES.join(" ")})`);
122
124
  }
125
+ if (RESERVED_PREFIX_ALLOWLIST.some((prefix) => key === prefix)) {
126
+ throw new KeyValidationError(key, `Key ${key} is a known prefix with an empty suffix`);
127
+ }
128
+ }
129
+ function keyConflictsWithReservedPrefixes(key) {
130
+ return RESERVED_PREFIXES.some((prefix) => key.startsWith(prefix) && !RESERVED_PREFIX_ALLOWLIST.some((known) => key.startsWith(known)));
123
131
  }
124
132
  function parseStrict(data) {
125
133
  const { envs, errors } = parse(data);
@@ -260,3 +268,15 @@ function writeResolvedParams(resolvedEnvs, userEnvs, userEnvOpt) {
260
268
  }
261
269
  writeUserEnvs(toWrite, userEnvOpt);
262
270
  }
271
+ function writeResolvedSecretRefs(resolvedSecretRefs, haveSecretRefs, userEnvOpt) {
272
+ const toWrite = {};
273
+ for (const secretName of Object.keys(resolvedSecretRefs)) {
274
+ const uppercaseName = secretName.toUpperCase();
275
+ const resolvedRef = resolvedSecretRefs[uppercaseName];
276
+ if (!Object.prototype.hasOwnProperty.call(haveSecretRefs, uppercaseName)) {
277
+ const reservedKey = "FIREBASE_SECRET_REF_" + uppercaseName;
278
+ toWrite[reservedKey] = resolvedRef;
279
+ }
280
+ }
281
+ writeUserEnvs(toWrite, userEnvOpt);
282
+ }
@@ -1,19 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_CODEBASE = void 0;
3
+ exports.KIT_PREFIX = exports.DEFAULT_CODEBASE = void 0;
4
4
  exports.normalize = normalize;
5
5
  exports.validateCodebase = validateCodebase;
6
+ exports.validateKit = validateKit;
6
7
  exports.validatePrefix = validatePrefix;
7
8
  exports.assertUnique = assertUnique;
9
+ exports.validateKitInstances = validateKitInstances;
8
10
  exports.validate = validate;
9
11
  exports.normalizeAndValidate = normalizeAndValidate;
10
12
  exports.configForCodebase = configForCodebase;
11
13
  exports.isLocalConfig = isLocalConfig;
12
14
  exports.isRemoteConfig = isRemoteConfig;
15
+ exports.isKitConfig = isKitConfig;
16
+ exports.addKitPrefix = addKitPrefix;
13
17
  exports.requireLocal = requireLocal;
14
18
  exports.resolveConfigDir = resolveConfigDir;
15
19
  exports.shouldUseRuntimeConfig = shouldUseRuntimeConfig;
16
20
  const error_1 = require("../error");
21
+ const experiments = require("../experiments");
17
22
  exports.DEFAULT_CODEBASE = "default";
18
23
  function normalize(config) {
19
24
  if (!config) {
@@ -33,6 +38,12 @@ function validateCodebase(codebase) {
33
38
  "can contain only lowercase letters, numeric characters, underscores, and dashes.");
34
39
  }
35
40
  }
41
+ function validateKit(kit) {
42
+ if (kit.length === 0 || kit.length > 40 || !/^[a-z0-9_-]+$/.test(kit)) {
43
+ throw new error_1.FirebaseError("Invalid kit name. Kit name must be 40 characters or less and " +
44
+ "can contain only lowercase letters, numeric characters, underscores, and dashes.");
45
+ }
46
+ }
36
47
  function validatePrefix(prefix) {
37
48
  if (prefix.length > 30) {
38
49
  throw new error_1.FirebaseError("Invalid prefix. Prefix must be 30 characters or less.");
@@ -42,6 +53,31 @@ function validatePrefix(prefix) {
42
53
  }
43
54
  }
44
55
  function validateSingle(config) {
56
+ if ("kit" in config) {
57
+ experiments.assertEnabled("kits", "use functions kits");
58
+ if (!config.kit) {
59
+ throw new error_1.FirebaseError("Must specify 'kit' name in a functions kit config.");
60
+ }
61
+ validateKit(config.kit);
62
+ if (config.codebase) {
63
+ throw new error_1.FirebaseError("Cannot specify both 'kit' and 'codebase' in a single functions config.");
64
+ }
65
+ if (config.remoteSource) {
66
+ throw new error_1.FirebaseError("Cannot specify both 'kit' and 'remoteSource' in a single functions config.");
67
+ }
68
+ if (config.prefix) {
69
+ throw new error_1.FirebaseError("Cannot specify 'prefix' in a functions kit config.");
70
+ }
71
+ if (!config.source) {
72
+ throw new error_1.FirebaseError("Must specify 'source' in a functions kit config.");
73
+ }
74
+ if (!config.instances ||
75
+ typeof config.instances !== "object" ||
76
+ Array.isArray(config.instances)) {
77
+ throw new error_1.FirebaseError("Must specify 'instances' as an object mapping instance IDs to configuration paths in a functions kit config.");
78
+ }
79
+ return config;
80
+ }
45
81
  const { source, remoteSource, runtime, codebase: providedCodebase, ...rest } = config;
46
82
  if (source && remoteSource) {
47
83
  throw new error_1.FirebaseError("Cannot specify both 'source' and 'remoteSource' in a single functions config. Please choose one.");
@@ -84,10 +120,12 @@ function assertUnique(config, property, propval) {
84
120
  }
85
121
  for (const single of config) {
86
122
  const value = single[property];
87
- if (values.has(value)) {
88
- throw new error_1.FirebaseError(`functions.${property} must be unique but '${value}' was used more than once.`);
123
+ if (value !== undefined) {
124
+ if (values.has(value)) {
125
+ throw new error_1.FirebaseError(`functions.${String(property)} must be unique but '${String(value)}' was used more than once.`);
126
+ }
127
+ values.add(value);
89
128
  }
90
- values.add(value);
91
129
  }
92
130
  }
93
131
  function assertUniqueSourcePrefixPair(config) {
@@ -113,38 +151,86 @@ function assertUniqueSourcePrefixPair(config) {
113
151
  sourcePrefixPairs.add(key);
114
152
  }
115
153
  }
154
+ function validateKitInstances(instances, allProjectInstanceIds) {
155
+ for (const instanceId of Object.keys(instances)) {
156
+ if (instanceId.length === 0 ||
157
+ instanceId.length > 40 ||
158
+ !/^[a-z0-9_](?:[a-z0-9_-]*[a-z0-9_])?$/.test(instanceId)) {
159
+ throw new error_1.FirebaseError(`Invalid kit instance ID '${instanceId}'. Instance ID must be 40 characters or less, ` +
160
+ "can contain only lowercase letters, numeric characters, underscores, and dashes, and cannot start or end with a dash.");
161
+ }
162
+ if (allProjectInstanceIds.has(instanceId)) {
163
+ throw new error_1.FirebaseError(`functions kit instance ID must be unique across all kits, but '${instanceId}' was used more than once.`);
164
+ }
165
+ allProjectInstanceIds.add(instanceId);
166
+ }
167
+ }
168
+ function assertUniqueKitInstancesAndCodebases(config) {
169
+ const codebases = new Set();
170
+ const instanceIds = new Set();
171
+ for (const c of config) {
172
+ if ("codebase" in c && c.codebase) {
173
+ codebases.add(c.codebase);
174
+ }
175
+ if ("instances" in c && c.instances) {
176
+ validateKitInstances(c.instances, instanceIds);
177
+ }
178
+ }
179
+ for (const instanceId of instanceIds) {
180
+ if (codebases.has(instanceId)) {
181
+ throw new error_1.FirebaseError(`functions codebase name and kit instance ID must be mutually exclusive, but '${instanceId}' was used as both a codebase name and a kit instance ID.`);
182
+ }
183
+ }
184
+ }
116
185
  function validate(config) {
117
186
  const validated = config.map((cfg) => validateSingle(cfg));
118
187
  assertUnique(validated, "codebase");
188
+ assertUnique(validated, "kit");
119
189
  assertUniqueSourcePrefixPair(validated);
190
+ assertUniqueKitInstancesAndCodebases(validated);
120
191
  return validated;
121
192
  }
122
193
  function normalizeAndValidate(config) {
123
194
  return validate(normalize(config));
124
195
  }
125
- function configForCodebase(config, codebase) {
126
- const codebaseCfg = config.find((c) => c.codebase === codebase);
196
+ function configForCodebase(config, codebaseOrInstance) {
197
+ const codebaseCfg = config.find((c) => {
198
+ if (isKitConfig(c)) {
199
+ return c.instances && codebaseOrInstance in c.instances;
200
+ }
201
+ return c.codebase === codebaseOrInstance;
202
+ });
127
203
  if (!codebaseCfg) {
128
- throw new error_1.FirebaseError(`No functions config found for codebase ${codebase}`);
204
+ throw new error_1.FirebaseError(`No functions config found for codebase or kit instance ${codebaseOrInstance}`);
129
205
  }
130
206
  return codebaseCfg;
131
207
  }
132
208
  function isLocalConfig(c) {
133
- return c.source !== undefined;
209
+ return "source" in c && !("kit" in c);
134
210
  }
135
211
  function isRemoteConfig(c) {
136
- return c.remoteSource !== undefined;
212
+ return "remoteSource" in c;
213
+ }
214
+ function isKitConfig(c) {
215
+ return "kit" in c;
216
+ }
217
+ exports.KIT_PREFIX = "kit-";
218
+ function addKitPrefix(instanceId) {
219
+ return `${exports.KIT_PREFIX}${instanceId}`;
137
220
  }
138
221
  function requireLocal(c, purpose) {
139
- if (!isLocalConfig(c)) {
222
+ if (isRemoteConfig(c)) {
140
223
  const msg = purpose ??
141
224
  "This operation requires a local functions source directory, but the codebase is configured with a remote source.";
142
225
  throw new error_1.FirebaseError(msg);
143
226
  }
144
227
  return c;
145
228
  }
146
- function resolveConfigDir(c) {
147
- return c.configDir || c.source;
229
+ function resolveConfigDir(c, instanceId) {
230
+ if (isKitConfig(c)) {
231
+ return instanceId ? c.instances[instanceId] : undefined;
232
+ }
233
+ return c.configDir || (isLocalConfig(c) ? c.source : undefined);
148
234
  }
149
235
  function shouldUseRuntimeConfig(cfg) {
150
236
  return isLocalConfig(cfg) && cfg.disallowLegacyRuntimeConfig !== true;
@@ -175,7 +175,10 @@ async function pruneSecrets(projectInfo, endpoints) {
175
175
  }
176
176
  if (secret.projectId === projectId || secret.projectId === projectNumber) {
177
177
  if (secret.version) {
178
- secrets.push({ ...secret, version: secret.version });
178
+ secrets.push({
179
+ ...secret,
180
+ version: secret.version,
181
+ });
179
182
  }
180
183
  }
181
184
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.client = exports.AI_LOGIC_TRIGGERS_TO_EVENTS = exports.AI_LOGIC_EVENTS_TO_TRIGGER = exports.AI_LOGIC_AFTER_GENERATE_CONTENT = exports.AI_LOGIC_BEFORE_GENERATE_CONTENT = exports.API_VERSION = void 0;
3
+ exports.PROVIDER_TYPES = exports.WRITABLE_CONFIG_PATHS = exports.client = exports.AI_LOGIC_TRIGGERS_TO_EVENTS = exports.AI_LOGIC_EVENTS_TO_TRIGGER = exports.AI_LOGIC_AFTER_GENERATE_CONTENT = exports.AI_LOGIC_BEFORE_GENERATE_CONTENT = exports.GLOBAL_LOCATION = exports.AILOGIC_LOGGING_PREFIX = exports.API_VERSION = void 0;
4
4
  exports.createTrigger = createTrigger;
5
5
  exports.getTrigger = getTrigger;
6
6
  exports.updateTrigger = updateTrigger;
@@ -8,10 +8,29 @@ exports.deleteTrigger = deleteTrigger;
8
8
  exports.listTriggers = listTriggers;
9
9
  exports.upsertBlockingFunction = upsertBlockingFunction;
10
10
  exports.deleteBlockingFunction = deleteBlockingFunction;
11
+ exports.assertKnownConfigPath = assertKnownConfigPath;
12
+ exports.isProviderType = isProviderType;
13
+ exports.parseProviderType = parseProviderType;
14
+ exports.getConfig = getConfig;
15
+ exports.updateConfig = updateConfig;
16
+ exports.enableProvider = enableProvider;
17
+ exports.disableProvider = disableProvider;
18
+ exports.listProviders = listProviders;
19
+ exports.isAILogicApiEnabled = isAILogicApiEnabled;
20
+ exports.ensureAILogicApiEnabled = ensureAILogicApiEnabled;
11
21
  const apiv2_1 = require("../apiv2");
12
22
  const api_1 = require("../api");
13
23
  const error_1 = require("../error");
24
+ const ensureApiEnabled = require("../ensureApiEnabled");
25
+ const serviceUsage = require("./serviceusage");
26
+ const colorette_1 = require("colorette");
27
+ const cloudbilling = require("./cloudbilling");
28
+ const iam = require("./iam");
29
+ const logger_1 = require("../logger");
30
+ const prompt_1 = require("../prompt");
14
31
  exports.API_VERSION = "v1beta";
32
+ exports.AILOGIC_LOGGING_PREFIX = "ailogic";
33
+ exports.GLOBAL_LOCATION = "global";
15
34
  exports.AI_LOGIC_BEFORE_GENERATE_CONTENT = "google.firebase.ailogic.v1.beforeGenerate";
16
35
  exports.AI_LOGIC_AFTER_GENERATE_CONTENT = "google.firebase.ailogic.v1.afterGenerate";
17
36
  exports.AI_LOGIC_EVENTS_TO_TRIGGER = {
@@ -110,3 +129,148 @@ async function deleteBlockingFunction(endpoint) {
110
129
  const location = endpoint.blockingTrigger.options?.regionalWebhook ? endpoint.region : "global";
111
130
  await deleteTrigger(endpoint.project, location, triggerId, true);
112
131
  }
132
+ exports.WRITABLE_CONFIG_PATHS = [
133
+ "security.auth-only",
134
+ "security.template-only",
135
+ "monitoring.state",
136
+ "monitoring.sample-rate-percentage",
137
+ ];
138
+ function assertKnownConfigPath(path, validPaths) {
139
+ if (!validPaths.includes(path)) {
140
+ throw new error_1.FirebaseError(`Unknown configuration path: ${path}\n\nValid paths:\n\n` +
141
+ validPaths.map((p) => ` ${p}`).join("\n"));
142
+ }
143
+ }
144
+ exports.PROVIDER_TYPES = ["gemini-developer-api", "gemini-agent-platform-api"];
145
+ function isProviderType(value) {
146
+ return exports.PROVIDER_TYPES.some((p) => p === value);
147
+ }
148
+ function parseProviderType(value) {
149
+ if (!isProviderType(value)) {
150
+ throw new error_1.FirebaseError(`Invalid provider type: ${(0, colorette_1.bold)(value)}. Must be one of: ${exports.PROVIDER_TYPES.map((p) => `'${p}'`).join(", ")}.`);
151
+ }
152
+ return value;
153
+ }
154
+ async function getConfig(projectId) {
155
+ const name = `projects/${projectId}/locations/${exports.GLOBAL_LOCATION}/config`;
156
+ const res = await exports.client.get(name);
157
+ return res.body;
158
+ }
159
+ async function updateConfig(projectId, config, updateMask) {
160
+ const name = `projects/${projectId}/locations/${exports.GLOBAL_LOCATION}/config`;
161
+ const queryParams = {};
162
+ if (updateMask && updateMask.length > 0) {
163
+ queryParams.updateMask = updateMask.join(",");
164
+ }
165
+ const res = await exports.client.patch(name, config, { queryParams });
166
+ return res.body;
167
+ }
168
+ async function enableProvider(projectId, providerType) {
169
+ if (providerType === "gemini-agent-platform-api") {
170
+ const billingEnabled = await cloudbilling.checkBillingEnabled(projectId);
171
+ if (!billingEnabled) {
172
+ throw new error_1.FirebaseError(`Your project ${(0, colorette_1.bold)(projectId)} must be on the Blaze (pay-as-you-go) plan to enable the Agent Platform. To upgrade, visit the following URL:\n\nhttps://console.firebase.google.com/project/${projectId}/usage/details`);
173
+ }
174
+ }
175
+ await ensureApiEnabled.ensure(projectId, "firebasevertexai.googleapis.com", exports.AILOGIC_LOGGING_PREFIX);
176
+ const providerApi = providerType === "gemini-developer-api"
177
+ ? "generativelanguage.googleapis.com"
178
+ : "aiplatform.googleapis.com";
179
+ await ensureApiEnabled.ensure(projectId, providerApi, exports.AILOGIC_LOGGING_PREFIX);
180
+ }
181
+ async function disableProvider(projectId, providerType) {
182
+ if (providerType === "gemini-developer-api") {
183
+ await serviceUsage.disableServiceAndPoll(projectId, "generativelanguage.googleapis.com", exports.AILOGIC_LOGGING_PREFIX);
184
+ const isVertexEnabled = await ensureApiEnabled.check(projectId, "aiplatform.googleapis.com", exports.AILOGIC_LOGGING_PREFIX, true);
185
+ if (!isVertexEnabled) {
186
+ await serviceUsage.disableServiceAndPoll(projectId, "firebasevertexai.googleapis.com", exports.AILOGIC_LOGGING_PREFIX);
187
+ }
188
+ }
189
+ else if (providerType === "gemini-agent-platform-api") {
190
+ await serviceUsage.disableServiceAndPoll(projectId, "aiplatform.googleapis.com", exports.AILOGIC_LOGGING_PREFIX);
191
+ const isDeveloperEnabled = await ensureApiEnabled.check(projectId, "generativelanguage.googleapis.com", exports.AILOGIC_LOGGING_PREFIX, true);
192
+ if (!isDeveloperEnabled) {
193
+ await serviceUsage.disableServiceAndPoll(projectId, "firebasevertexai.googleapis.com", exports.AILOGIC_LOGGING_PREFIX);
194
+ }
195
+ }
196
+ }
197
+ async function listProviders(projectId) {
198
+ const [isAILogicEnabled, isDeveloperEnabled, isVertexEnabled] = await Promise.all([
199
+ isAILogicApiEnabled(projectId),
200
+ ensureApiEnabled.check(projectId, "generativelanguage.googleapis.com", exports.AILOGIC_LOGGING_PREFIX, true),
201
+ ensureApiEnabled.check(projectId, "aiplatform.googleapis.com", exports.AILOGIC_LOGGING_PREFIX, true),
202
+ ]);
203
+ if (!isAILogicEnabled) {
204
+ return [];
205
+ }
206
+ const enabled = [];
207
+ if (isDeveloperEnabled) {
208
+ enabled.push("gemini-developer-api");
209
+ }
210
+ if (isVertexEnabled) {
211
+ enabled.push("gemini-agent-platform-api");
212
+ }
213
+ return enabled;
214
+ }
215
+ async function isAILogicApiEnabled(projectId) {
216
+ return ensureApiEnabled.check(projectId, "firebasevertexai.googleapis.com", exports.AILOGIC_LOGGING_PREFIX, true);
217
+ }
218
+ async function ensureAILogicApiEnabled(projectId, options) {
219
+ if (await isAILogicApiEnabled(projectId)) {
220
+ return;
221
+ }
222
+ if (options.nonInteractive) {
223
+ throw new error_1.FirebaseError(`The Firebase AI Logic API (firebasevertexai.googleapis.com) is not enabled on project ${projectId}.\n\n` +
224
+ `Enable Firebase AI Logic with one of the Gemini API providers by running:\n\n` +
225
+ ` firebase ailogic:providers:enable gemini-developer-api\n` +
226
+ ` firebase ailogic:providers:enable gemini-agent-platform-api\n\n` +
227
+ `Then run this command again.`);
228
+ }
229
+ const { missing } = await iam.testIamPermissions(projectId, ["serviceusage.services.enable"]);
230
+ if (missing.length > 0) {
231
+ throw new error_1.FirebaseError(`You do not have permission to enable the Firebase AI Logic API on project ${projectId}.\n\n` +
232
+ `Missing permission: ${missing.join(", ")}\n\n` +
233
+ `This permission is included in the Owner and Editor roles. Ask a project ` +
234
+ `administrator to enable the API or grant you the permission, then run this command again.`);
235
+ }
236
+ logger_1.logger.info(`The Firebase AI Logic API (firebasevertexai.googleapis.com) is not enabled on project ${projectId}.`);
237
+ const proceed = await (0, prompt_1.confirm)({
238
+ message: "Would you like to enable it now?",
239
+ default: true,
240
+ force: options.force,
241
+ });
242
+ if (!proceed) {
243
+ throw new error_1.FirebaseError("Command aborted.", { exit: 1 });
244
+ }
245
+ for (;;) {
246
+ const provider = await (0, prompt_1.select)({
247
+ message: "Which Gemini API provider do you want to enable?",
248
+ choices: [
249
+ { name: "gemini-developer-api", value: "gemini-developer-api" },
250
+ {
251
+ name: "gemini-agent-platform-api (requires the Blaze plan)",
252
+ value: "gemini-agent-platform-api",
253
+ },
254
+ { name: "cancel", value: "cancel" },
255
+ ],
256
+ });
257
+ if (provider === "cancel") {
258
+ throw new error_1.FirebaseError("Command aborted.", { exit: 1 });
259
+ }
260
+ if (provider === "gemini-agent-platform-api") {
261
+ const billingEnabled = await cloudbilling.checkBillingEnabled(projectId);
262
+ if (!billingEnabled) {
263
+ logger_1.logger.info(`\n${(0, colorette_1.bold)("Error:")} The gemini-agent-platform-api provider requires the pay-as-you-go (Blaze) plan.\n` +
264
+ `Project ${projectId} is on the Spark plan.\n\n` +
265
+ `Upgrade your plan at:\n\n` +
266
+ ` https://console.firebase.google.com/project/${projectId}/usage/details\n`);
267
+ continue;
268
+ }
269
+ }
270
+ logger_1.logger.info(`Enabling firebasevertexai.googleapis.com...`);
271
+ logger_1.logger.info(`Enabling provider ${provider}...`);
272
+ await enableProvider(projectId, provider);
273
+ logger_1.logger.info((0, colorette_1.bold)(`Successfully enabled Firebase AI Logic with provider: ${provider}`));
274
+ break;
275
+ }
276
+ }
@@ -188,6 +188,13 @@ function functionFromEndpoint(endpoint) {
188
188
  proto.convertIfPresent(gcfFunction.serviceConfig, endpoint, "availableCpu", "cpu", (cpu) => {
189
189
  return String(cpu);
190
190
  });
191
+ if (!gcfFunction.serviceConfig.environmentVariables) {
192
+ gcfFunction.serviceConfig.environmentVariables = {};
193
+ }
194
+ if (!endpoint.region) {
195
+ throw new error_1.FirebaseError(`Function ${endpoint.id} is missing the function region at deploy time. This should never happen`, { exit: 1 });
196
+ }
197
+ gcfFunction.serviceConfig.environmentVariables["FUNCTION_REGION"] = endpoint.region;
191
198
  if (endpoint.vpc) {
192
199
  if (endpoint.vpc.connector) {
193
200
  gcfFunction.serviceConfig.vpcConnector = endpoint.vpc.connector;
@@ -12,7 +12,11 @@ exports.APPHOSTING_TOS_ID = "APP_HOSTING_TOS";
12
12
  exports.APP_CHECK_TOS_ID = "APP_CHECK";
13
13
  exports.DATA_CONNECT_TOS_ID = "FIREBASE_DATA_CONNECT";
14
14
  async function getTosStatus() {
15
- const res = await client.get("accessmanagement/tos:getStatus");
15
+ const res = await client.request({
16
+ method: "GET",
17
+ path: "accessmanagement/tos:getStatus",
18
+ ignoreQuotaProject: true,
19
+ });
16
20
  return res.body;
17
21
  }
18
22
  function getAcceptanceStatus(response, tosId) {
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.apiClient = void 0;
4
4
  exports.generateServiceIdentity = generateServiceIdentity;
5
5
  exports.generateServiceIdentityAndPoll = generateServiceIdentityAndPoll;
6
+ exports.disableService = disableService;
7
+ exports.disableServiceAndPoll = disableServiceAndPoll;
6
8
  const colorette_1 = require("colorette");
7
9
  const api_1 = require("../api");
8
10
  const apiv2_1 = require("../apiv2");
9
11
  const error_1 = require("../error");
10
12
  const utils = require("../utils");
11
13
  const poller = require("../operation-poller");
14
+ const ensureApiEnabled = require("../ensureApiEnabled");
12
15
  const API_VERSION = "v1beta1";
13
16
  const SERVICE_USAGE_ORIGIN = (0, api_1.serviceUsageOrigin)();
14
17
  exports.apiClient = new apiv2_1.Client({
@@ -42,3 +45,26 @@ async function generateServiceIdentityAndPoll(projectNumber, service, prefix) {
42
45
  headers: { "x-goog-user-project": `${projectNumber}` },
43
46
  });
44
47
  }
48
+ async function disableService(projectId, service) {
49
+ try {
50
+ const res = await exports.apiClient.post(`projects/${projectId}/services/${service}:disable`, {}, { headers: { "x-goog-user-project": `${projectId}` } });
51
+ return res.body;
52
+ }
53
+ catch (err) {
54
+ throw new error_1.FirebaseError(`Error disabling service ${service}.`, {
55
+ original: err,
56
+ });
57
+ }
58
+ }
59
+ async function disableServiceAndPoll(projectId, service, loggingPrefix) {
60
+ utils.logLabeledBullet(loggingPrefix, `disabling service ${(0, colorette_1.bold)(service)}...`);
61
+ const op = await disableService(projectId, service);
62
+ if (!op.done) {
63
+ await poller.pollOperation({
64
+ ...serviceUsagePollerOptions,
65
+ operationResourceName: op.name,
66
+ headers: { "x-goog-user-project": `${projectId}` },
67
+ });
68
+ }
69
+ ensureApiEnabled.uncacheEnabledAPI(projectId, service);
70
+ }
@@ -2,44 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.askQuestions = askQuestions;
4
4
  exports.actuate = actuate;
5
- const prompt_1 = require("../../../prompt");
6
5
  const error_1 = require("../../../error");
7
6
  const utils_1 = require("./utils");
8
7
  const apps_1 = require("../../../management/apps");
9
8
  const provision_1 = require("../../../management/provisioning/provision");
10
- function checkForApps(apps) {
11
- if (!apps.length) {
12
- throw new error_1.FirebaseError("No Firebase apps found in this project. Please create an app first using the Firebase Console or 'firebase apps:create'.", { exit: 1 });
13
- }
14
- }
15
- async function selectAppInteractively(apps) {
16
- checkForApps(apps);
17
- const choices = apps.map((app) => {
18
- let displayText = app.displayName || app.appId;
19
- if (!app.displayName) {
20
- if (app.platform === apps_1.AppPlatform.IOS && "bundleId" in app) {
21
- displayText = app.bundleId;
22
- }
23
- else if (app.platform === apps_1.AppPlatform.ANDROID && "packageName" in app) {
24
- displayText = app.packageName;
25
- }
26
- }
27
- return {
28
- name: `${displayText} - ${app.appId} (${app.platform})`,
29
- value: app,
30
- };
31
- });
32
- return await (0, prompt_1.select)({
33
- message: "Select the Firebase app to enable AI Logic for:",
34
- choices,
35
- });
36
- }
37
9
  async function askQuestions(setup) {
38
10
  if (!setup.projectId) {
39
11
  throw new error_1.FirebaseError("No project ID found. Please ensure you are in a Firebase project directory or specify a project.", { exit: 1 });
40
12
  }
41
13
  const apps = await (0, apps_1.listFirebaseApps)(setup.projectId, apps_1.AppPlatform.ANY);
42
- const selectedApp = await selectAppInteractively(apps);
14
+ const selectedApp = await (0, apps_1.selectAppInteractively)(apps, apps_1.AppPlatform.ANY, {
15
+ message: "Select the Firebase app to enable AI Logic for:",
16
+ });
43
17
  if (!setup.featureInfo) {
44
18
  setup.featureInfo = {};
45
19
  }
@@ -30,7 +30,7 @@ async function getDBRules(instanceDetails) {
30
30
  if (response.status !== 200) {
31
31
  throw new error_1.FirebaseError(`Failed to fetch current rules. Code: ${response.status}`);
32
32
  }
33
- return await response.response.text();
33
+ return await utils.streamToString(response.body);
34
34
  }
35
35
  function writeDBRules(rules, filename, config) {
36
36
  config.writeProjectFile(filename, rules);