firebase-tools-with-isolate 15.11.0-3 → 15.13.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 (57) hide show
  1. package/README.md +1 -1
  2. package/lib/agentSkills.js +70 -0
  3. package/lib/api.js +3 -1
  4. package/lib/apphosting/backend.js +22 -3
  5. package/lib/apphosting/config.js +19 -2
  6. package/lib/apphosting/localbuilds.js +25 -4
  7. package/lib/apphosting/prompts.js +35 -0
  8. package/lib/bin/mcp.js +5 -1
  9. package/lib/commands/apphosting-backends-create.js +19 -2
  10. package/lib/commands/apphosting-backends-list.js +25 -5
  11. package/lib/commands/ext-info.js +5 -1
  12. package/lib/commands/functions-delete.js +1 -0
  13. package/lib/commands/functions-export.js +40 -0
  14. package/lib/commands/index.js +3 -0
  15. package/lib/commands/init.js +1 -0
  16. package/lib/deploy/apphosting/deploy.js +11 -6
  17. package/lib/deploy/apphosting/prepare.js +88 -4
  18. package/lib/deploy/apphosting/release.js +2 -5
  19. package/lib/deploy/apphosting/util.js +45 -2
  20. package/lib/deploy/functions/prepare.js +5 -1
  21. package/lib/deploy/functions/prepareFunctionsUpload.js +5 -2
  22. package/lib/deploy/functions/release/fabricator.js +4 -3
  23. package/lib/deploy/functions/release/index.js +5 -0
  24. package/lib/deploy/functions/services/ailogic.js +68 -0
  25. package/lib/deploy/functions/services/index.js +4 -0
  26. package/lib/emulator/downloadableEmulatorInfo.json +24 -24
  27. package/lib/emulator/storage/rules/manager.js +10 -3
  28. package/lib/emulator/storage/rules/runtime.js +9 -7
  29. package/lib/experiments.js +22 -0
  30. package/lib/extensions/listExtensions.js +2 -0
  31. package/lib/firebase_studio/migrate.js +30 -61
  32. package/lib/functions/iac/export.js +36 -0
  33. package/lib/functions/iac/terraform.js +146 -0
  34. package/lib/gcp/ailogic.js +108 -0
  35. package/lib/gcp/apphosting.js +6 -0
  36. package/lib/gcp/cloudfunctionsv2.js +24 -0
  37. package/lib/gcp/cloudsql/cloudsqladmin.js +1 -1
  38. package/lib/init/features/agentSkills.js +26 -0
  39. package/lib/init/features/apphosting.js +11 -2
  40. package/lib/init/features/dataconnect/sdk.js +26 -12
  41. package/lib/init/features/functions/index.js +7 -4
  42. package/lib/init/features/index.js +4 -1
  43. package/lib/init/index.js +6 -0
  44. package/lib/mcp/index.js +1 -1
  45. package/lib/mcp/tools/core/read_resources.js +1 -1
  46. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  47. package/lib/utils.js +8 -0
  48. package/package.json +7 -5
  49. package/standalone/package.json +1 -1
  50. package/templates/extensions/typescript/package.lint.json +1 -1
  51. package/templates/extensions/typescript/package.nolint.json +1 -1
  52. package/templates/extensions/typescript/tsconfig.json +1 -0
  53. package/templates/init/functions/typescript/package-ongraphrequest.lint.json +1 -1
  54. package/templates/init/functions/typescript/package-ongraphrequest.nolint.json +1 -1
  55. package/templates/init/functions/typescript/package.lint.json +1 -1
  56. package/templates/init/functions/typescript/package.nolint.json +1 -1
  57. package/templates/init/functions/typescript/tsconfig.json +1 -0
@@ -1,16 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = default_1;
4
+ exports.injectEnvVarsFromApphostingConfig = injectEnvVarsFromApphostingConfig;
5
+ exports.injectAutoInitEnvVars = injectAutoInitEnvVars;
4
6
  exports.getBackendConfigs = getBackendConfigs;
5
7
  const path = require("path");
6
8
  const backend_1 = require("../../apphosting/backend");
7
9
  const apphosting_1 = require("../../gcp/apphosting");
10
+ const yaml_1 = require("../../apphosting/yaml");
11
+ const config_1 = require("../../apphosting/config");
8
12
  const devConnect_1 = require("../../gcp/devConnect");
13
+ const resourceManager_1 = require("../../gcp/resourceManager");
9
14
  const projectUtils_1 = require("../../projectUtils");
15
+ const getProjectNumber_1 = require("../../getProjectNumber");
10
16
  const prompt_1 = require("../../prompt");
11
17
  const utils_1 = require("../../utils");
12
18
  const localbuilds_1 = require("../../apphosting/localbuilds");
13
19
  const error_1 = require("../../error");
20
+ const managementApps = require("../../management/apps");
21
+ const utils_2 = require("../../apphosting/utils");
22
+ const experiments = require("../../experiments");
23
+ const logger_1 = require("../../logger");
14
24
  async function default_1(context, options) {
15
25
  const projectId = (0, projectUtils_1.needProjectId)(options);
16
26
  await (0, apphosting_1.ensureApiEnabled)(options);
@@ -21,6 +31,10 @@ async function default_1(context, options) {
21
31
  context.backendStorageUris = {};
22
32
  context.backendLocalBuilds = {};
23
33
  const configs = getBackendConfigs(options);
34
+ if (configs.some((cfg) => cfg.localBuild) && experiments.isEnabled("apphostinglocalbuilds")) {
35
+ const projectNumber = await (0, getProjectNumber_1.getProjectNumber)(options);
36
+ await ensureAppHostingServiceAgentRoles(projectId, projectNumber);
37
+ }
24
38
  const { backends } = await (0, apphosting_1.listBackends)(projectId, "-");
25
39
  const foundBackends = [];
26
40
  const notFoundBackends = [];
@@ -108,24 +122,66 @@ async function default_1(context, options) {
108
122
  if (skippedBackends.length > 0) {
109
123
  (0, utils_1.logLabeledWarning)("apphosting", `Skipping deployment of backend(s) ${skippedBackends.map((cfg) => cfg.backendId).join(", ")}.`);
110
124
  }
125
+ const buildEnv = {};
126
+ const runtimeEnv = {};
111
127
  for (const cfg of Object.values(context.backendConfigs)) {
112
128
  if (!cfg.localBuild) {
113
129
  continue;
114
130
  }
131
+ experiments.assertEnabled("apphostinglocalbuilds", "locally build App Hosting backends");
115
132
  (0, utils_1.logLabeledBullet)("apphosting", `Starting local build for backend ${cfg.backendId}`);
133
+ await injectEnvVarsFromApphostingConfig(configs.filter((c) => c.backendId === cfg.backendId), options, buildEnv, runtimeEnv);
134
+ await injectAutoInitEnvVars(cfg, backends, buildEnv, runtimeEnv);
116
135
  try {
117
- const { outputFiles, annotations, buildConfig } = await (0, localbuilds_1.localBuild)(options.projectRoot || "./", "nextjs");
136
+ const { outputFiles, annotations, buildConfig } = await (0, localbuilds_1.localBuild)(options.projectRoot || "./", "nextjs", buildEnv[cfg.backendId] || {});
118
137
  if (outputFiles.length !== 1) {
119
138
  throw new error_1.FirebaseError(`Local build for backend ${cfg.backendId} failed: No output files found.`);
120
139
  }
121
140
  context.backendLocalBuilds[cfg.backendId] = {
122
141
  buildDir: outputFiles[0],
123
- buildConfig,
142
+ buildConfig: {
143
+ ...buildConfig,
144
+ env: mergeEnvVars(buildConfig.env || [], runtimeEnv[cfg.backendId] || {}),
145
+ },
124
146
  annotations,
125
147
  };
126
148
  }
127
149
  catch (e) {
128
- throw new error_1.FirebaseError(`Local Build for backend ${cfg.backendId} failed: ${e}`);
150
+ const errorMsg = e instanceof Error ? e.message : String(e);
151
+ throw new error_1.FirebaseError(`Local Build for backend ${cfg.backendId} failed: ${errorMsg}`);
152
+ }
153
+ }
154
+ }
155
+ async function injectEnvVarsFromApphostingConfig(configs, options, buildEnv, runtimeEnv) {
156
+ for (const cfg of configs) {
157
+ const rootDir = options.projectRoot || process.cwd();
158
+ const appDir = path.join(rootDir, cfg.rootDir || "");
159
+ let yamlConfig = yaml_1.AppHostingYamlConfig.empty();
160
+ try {
161
+ yamlConfig = await (0, config_1.getAppHostingConfiguration)(appDir);
162
+ }
163
+ catch (e) {
164
+ (0, utils_1.logLabeledWarning)("apphosting", `Failed to read apphosting.yaml, may be missing environment variables and other configs`);
165
+ }
166
+ const { build, runtime } = (0, config_1.splitEnvVars)(yamlConfig.env);
167
+ buildEnv[cfg.backendId] = { ...buildEnv[cfg.backendId], ...build };
168
+ runtimeEnv[cfg.backendId] = { ...runtimeEnv[cfg.backendId], ...runtime };
169
+ }
170
+ }
171
+ async function injectAutoInitEnvVars(cfg, backends, buildEnv, runtimeEnv) {
172
+ var _a, _b;
173
+ const backend = backends.find((b) => (0, apphosting_1.parseBackendName)(b.name).id === cfg.backendId);
174
+ if (backend?.appId) {
175
+ try {
176
+ const webappConfig = (await managementApps.getAppConfig(backend.appId, managementApps.AppPlatform.WEB));
177
+ const autoinitVars = (0, utils_2.getAutoinitEnvVars)(webappConfig);
178
+ for (const [envVarName, envVarValue] of Object.entries(autoinitVars)) {
179
+ (_a = buildEnv[cfg.backendId])[envVarName] ?? (_a[envVarName] = { value: envVarValue });
180
+ (_b = runtimeEnv[cfg.backendId])[envVarName] ?? (_b[envVarName] = { value: envVarValue });
181
+ }
182
+ }
183
+ catch (e) {
184
+ (0, utils_1.logLabeledWarning)("apphosting", `Unable to lookup details for backend ${cfg.backendId}. Firebase SDK autoinit will not be available.`);
129
185
  }
130
186
  }
131
187
  }
@@ -155,5 +211,33 @@ function getBackendConfigs(options) {
155
211
  if (backendIds.length === 0) {
156
212
  return [];
157
213
  }
158
- return backendConfigs.filter((cfg) => backendIds.includes(cfg.backendId));
214
+ const filteredConfigs = backendConfigs.filter((cfg) => backendIds.includes(cfg.backendId));
215
+ const foundIds = filteredConfigs.map((cfg) => cfg.backendId);
216
+ const missingIds = backendIds.filter((id) => !foundIds.includes(id));
217
+ if (missingIds.length > 0) {
218
+ throw new error_1.FirebaseError(`App Hosting backend IDs ${missingIds.join(",")} not detected in firebase.json`);
219
+ }
220
+ return filteredConfigs;
221
+ }
222
+ function mergeEnvVars(base, overrides) {
223
+ const merged = new Map();
224
+ for (const env of base) {
225
+ if (env.variable) {
226
+ merged.set(env.variable, env);
227
+ }
228
+ }
229
+ for (const [envVarName, envVarConfig] of Object.entries(overrides)) {
230
+ merged.set(envVarName, { ...envVarConfig, variable: envVarName });
231
+ }
232
+ return Array.from(merged.values());
233
+ }
234
+ async function ensureAppHostingServiceAgentRoles(projectId, projectNumber) {
235
+ const p4saEmail = (0, apphosting_1.serviceAgentEmail)(projectNumber);
236
+ try {
237
+ await (0, resourceManager_1.addServiceAccountToRoles)(projectId, p4saEmail, ["roles/storage.objectViewer"], true);
238
+ }
239
+ catch (err) {
240
+ logger_1.logger.debug(`Failed to grant storage.objectViewer to ${p4saEmail}: ${String(err)}`);
241
+ (0, utils_1.logLabeledWarning)("apphosting", `Unable to verify App Hosting service agent permissions for ${p4saEmail}. If you encounter a PERMISSION_DENIED error during rollout, please ensure the service agent has the "Storage Object Viewer" role.`);
242
+ }
159
243
  }
@@ -15,11 +15,6 @@ async function default_1(context, options) {
15
15
  (0, utils_1.logLabeledWarning)("apphosting", `Failed to find metadata for backend(s) ${backendIds.join(", ")}. Please contact support with the contents of your firebase-debug.log to report your issue.`);
16
16
  backendIds = backendIds.filter((id) => !missingBackends.includes(id));
17
17
  }
18
- const localBuildBackends = backendIds.filter((id) => context.backendLocalBuilds[id]);
19
- if (localBuildBackends.length > 0) {
20
- (0, utils_1.logLabeledWarning)("apphosting", `Skipping backend(s) ${localBuildBackends.join(", ")}. Local Builds are not supported yet.`);
21
- backendIds = backendIds.filter((id) => !localBuildBackends.includes(id));
22
- }
23
18
  if (backendIds.length === 0) {
24
19
  return;
25
20
  }
@@ -29,10 +24,12 @@ async function default_1(context, options) {
29
24
  backendId,
30
25
  location: context.backendLocations[backendId],
31
26
  buildInput: {
27
+ config: context.backendLocalBuilds[backendId]?.buildConfig,
32
28
  source: {
33
29
  archive: {
34
30
  userStorageUri: context.backendStorageUris[backendId],
35
31
  rootDirectory: context.backendConfigs[backendId].rootDir,
32
+ locallyBuiltSource: !!context.backendLocalBuilds[backendId],
36
33
  },
37
34
  },
38
35
  },
@@ -1,13 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createArchive = createArchive;
3
+ exports.createLocalBuildTarArchive = createLocalBuildTarArchive;
4
+ exports.createSourceDeployArchive = createSourceDeployArchive;
4
5
  const archiver = require("archiver");
5
6
  const fs = require("fs");
6
7
  const path = require("path");
8
+ const tar = require("tar");
7
9
  const tmp = require("tmp");
8
10
  const error_1 = require("../../error");
9
11
  const fsAsync = require("../../fsAsync");
10
- async function createArchive(config, rootDir, targetSubDir) {
12
+ const config_1 = require("../../apphosting/config");
13
+ async function createLocalBuildTarArchive(config, rootDir, targetSubDir) {
14
+ const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".tar.gz" }).name;
15
+ const targetDir = targetSubDir ? path.join(rootDir, targetSubDir) : rootDir;
16
+ const ignore = ["firebase-debug.log", "firebase-debug.*.log", ".git"];
17
+ const rdrFiles = await fsAsync.readdirRecursive({
18
+ path: targetDir,
19
+ ignore: ignore,
20
+ isGitIgnore: true,
21
+ });
22
+ const allFiles = rdrFiles.map((rdrf) => path.relative(rootDir, rdrf.name));
23
+ if (targetSubDir) {
24
+ const defaultFiles = fs.readdirSync(rootDir).filter((file) => {
25
+ return config_1.APPHOSTING_YAML_FILE_REGEX.test(file);
26
+ });
27
+ for (const file of defaultFiles) {
28
+ if (!allFiles.includes(file)) {
29
+ allFiles.push(file);
30
+ }
31
+ }
32
+ }
33
+ try {
34
+ fs.statSync(rootDir);
35
+ }
36
+ catch (err) {
37
+ if (err instanceof Error && "code" in err && err.code === "ENOENT") {
38
+ throw new error_1.FirebaseError(`Could not read directory "${rootDir}"`);
39
+ }
40
+ throw err;
41
+ }
42
+ if (!allFiles.length) {
43
+ throw new error_1.FirebaseError(`Cannot create a tar archive with 0 files from directory "${rootDir}"`);
44
+ }
45
+ await tar.create({
46
+ gzip: true,
47
+ file: tmpFile,
48
+ cwd: rootDir,
49
+ portable: true,
50
+ }, allFiles);
51
+ return tmpFile;
52
+ }
53
+ async function createSourceDeployArchive(config, rootDir, targetSubDir) {
11
54
  const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".zip" }).name;
12
55
  const fileStream = fs.createWriteStream(tmpFile, {
13
56
  flags: "w",
@@ -13,6 +13,7 @@ const clc = require("colorette");
13
13
  const proto = require("../../gcp/proto");
14
14
  const backend = require("./backend");
15
15
  const build = require("./build");
16
+ const experiments = require("../../experiments");
16
17
  const ensureApiEnabled = require("../../ensureApiEnabled");
17
18
  const functionsConfig = require("../../functionsConfig");
18
19
  const functionsEnv = require("../../functions/env");
@@ -320,12 +321,15 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
320
321
  throw new error_1.FirebaseError(`Functions codebase ${codebase} has invalid runtime ` +
321
322
  `${firebaseJsonRuntime} specified in firebase.json. Valid values are: \n` +
322
323
  Object.keys(supported.RUNTIMES)
324
+ .filter((runtime) => !supported.isDecommissioned(runtime))
323
325
  .map((s) => `- ${s}`)
324
326
  .join("\n"));
325
327
  }
326
328
  const runtimeDelegate = await runtimes.getRuntimeDelegate(delegateContext);
327
329
  logger_1.logger.debug(`Validating ${runtimeDelegate.language} source`);
328
- supported.guardVersionSupport(runtimeDelegate.runtime);
330
+ if (!experiments.isEnabled("bypassfunctionsdeprecationcheck")) {
331
+ supported.guardVersionSupport(runtimeDelegate.runtime);
332
+ }
329
333
  await runtimeDelegate.validate();
330
334
  logger_1.logger.debug(`Building ${runtimeDelegate.language} source`);
331
335
  await runtimeDelegate.build();
@@ -10,6 +10,7 @@ const filesize = require("filesize");
10
10
  const fs = require("fs");
11
11
  const path = require("path");
12
12
  const tmp = require("tmp");
13
+ const crypto = require("crypto");
13
14
  const dynamicImport_1 = require("../../dynamicImport");
14
15
  const error_1 = require("../../error");
15
16
  const logger_1 = require("../../logger");
@@ -56,6 +57,7 @@ async function packageSource(projectDir, sourceDir, config, additionalSources, r
56
57
  });
57
58
  const archive = exportType === "tar.gz" ? archiver("tar", { gzip: true }) : archiver("zip");
58
59
  const hashes = [];
60
+ let configHash = "";
59
61
  const ignore = config.ignore || ["node_modules", ".git"];
60
62
  ignore.push("firebase-debug.log", "firebase-debug.*.log", CONFIG_DEST_FILE);
61
63
  try {
@@ -84,7 +86,7 @@ async function packageSource(projectDir, sourceDir, config, additionalSources, r
84
86
  }
85
87
  if (typeof runtimeConfig !== "undefined") {
86
88
  const runtimeConfigHashString = JSON.stringify(convertToSortedKeyValueArray(runtimeConfig));
87
- hashes.push(runtimeConfigHashString);
89
+ configHash = crypto.createHash("sha1").update(runtimeConfigHashString).digest("hex");
88
90
  const runtimeConfigString = JSON.stringify(runtimeConfig, null, 2);
89
91
  archive.append(runtimeConfigString, {
90
92
  name: CONFIG_DEST_FILE,
@@ -111,7 +113,8 @@ async function packageSource(projectDir, sourceDir, config, additionalSources, r
111
113
  " (" +
112
114
  filesize(archive.pointer()) +
113
115
  ") for uploading");
114
- const hash = hashes.join(".");
116
+ const sourceHash = crypto.createHash("sha1").update(hashes.sort().join("")).digest("hex");
117
+ const hash = configHash ? `${sourceHash}.${configHash}` : sourceHash;
115
118
  return { pathToSource: tmpFile, hash };
116
119
  }
117
120
  async function prepareFunctionsUpload(projectDir, sourceDir, config, additionalSources, runtimeConfig, options) {
@@ -57,6 +57,7 @@ class Fabricator {
57
57
  constructor(args) {
58
58
  this.executor = args.executor;
59
59
  this.functionExecutor = args.functionExecutor;
60
+ this.runFunctionExecutor = args.runFunctionExecutor;
60
61
  this.sources = args.sources;
61
62
  this.appEngineLocation = args.appEngineLocation;
62
63
  this.projectNumber = args.projectNumber;
@@ -521,7 +522,7 @@ class Fabricator {
521
522
  generation: storageSource.generation ? String(storageSource.generation) : undefined,
522
523
  },
523
524
  };
524
- await this.executor
525
+ await this.runFunctionExecutor
525
526
  .run(async () => {
526
527
  const op = await runV2.createService(endpoint.project, endpoint.region, endpoint.id, service);
527
528
  endpoint.uri = op.uri;
@@ -546,7 +547,7 @@ class Fabricator {
546
547
  generation: storageSource.generation ? String(storageSource.generation) : undefined,
547
548
  },
548
549
  };
549
- await this.executor
550
+ await this.runFunctionExecutor
550
551
  .run(async () => {
551
552
  const op = await runV2.updateService(service);
552
553
  endpoint.uri = op.uri;
@@ -556,7 +557,7 @@ class Fabricator {
556
557
  await this.setInvoker(endpoint);
557
558
  }
558
559
  async deleteRunFunction(endpoint) {
559
- await this.executor
560
+ await this.runFunctionExecutor
560
561
  .run(async () => {
561
562
  try {
562
563
  await runV2.deleteService(endpoint.project, endpoint.region, endpoint.id);
@@ -70,9 +70,14 @@ async function release(context, options, payload) {
70
70
  concurrency: 40,
71
71
  maxBackoff: 100000,
72
72
  };
73
+ const runThrottlerOptions = {
74
+ ...throttlerOptions,
75
+ concurrency: 2,
76
+ };
73
77
  const projectNumber = options.projectNumber || (await (0, getProjectNumber_1.getProjectNumber)(context.projectId));
74
78
  const fab = new fabricator.Fabricator({
75
79
  functionExecutor: new executor.QueueExecutor(throttlerOptions),
80
+ runFunctionExecutor: new executor.QueueExecutor(runThrottlerOptions),
76
81
  executor: new executor.QueueExecutor(throttlerOptions),
77
82
  sources: context.sources,
78
83
  appEngineLocation: (0, functionsConfig_1.getAppEngineLocation)(context.firebaseConfig),
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AILogicService = exports.AI_LOGIC_EVENTS = exports.AI_LOGIC_AFTER_GENERATE_CONTENT = exports.AI_LOGIC_BEFORE_GENERATE_CONTENT = void 0;
4
+ exports.isAILogicEvent = isAILogicEvent;
5
+ const backend = require("../backend");
6
+ const error_1 = require("../../../error");
7
+ const ailogicApi = require("../../../gcp/ailogic");
8
+ exports.AI_LOGIC_BEFORE_GENERATE_CONTENT = "firebase.vertexai.v1beta.beforeGenerateContent";
9
+ exports.AI_LOGIC_AFTER_GENERATE_CONTENT = "firebase.vertexai.v1beta.afterGenerateContent";
10
+ exports.AI_LOGIC_EVENTS = [
11
+ exports.AI_LOGIC_BEFORE_GENERATE_CONTENT,
12
+ exports.AI_LOGIC_AFTER_GENERATE_CONTENT,
13
+ ];
14
+ function isAILogicEvent(endpoint) {
15
+ if (!backend.isBlockingTriggered(endpoint)) {
16
+ return false;
17
+ }
18
+ return exports.AI_LOGIC_EVENTS.includes(endpoint.blockingTrigger.eventType);
19
+ }
20
+ class AILogicService {
21
+ constructor() {
22
+ this.ensureTriggerRegion = () => Promise.resolve();
23
+ this.name = "ailogic";
24
+ this.api = "firebasevertexai.googleapis.com";
25
+ }
26
+ validateTrigger(endpoint, wantBackend) {
27
+ if (!isAILogicEvent(endpoint)) {
28
+ return;
29
+ }
30
+ const eventType = endpoint.blockingTrigger.eventType;
31
+ const regionalWebhook = !!endpoint.blockingTrigger.options?.regionalWebhook;
32
+ const conflict = backend.allEndpoints(wantBackend).some((ep) => {
33
+ if (!isAILogicEvent(ep)) {
34
+ return false;
35
+ }
36
+ if (ep.blockingTrigger.eventType !== eventType || ep.id === endpoint.id) {
37
+ return false;
38
+ }
39
+ if (regionalWebhook) {
40
+ return ep.blockingTrigger.options?.regionalWebhook && ep.region === endpoint.region;
41
+ }
42
+ else {
43
+ return !ep.blockingTrigger.options?.regionalWebhook;
44
+ }
45
+ });
46
+ if (conflict) {
47
+ if (regionalWebhook) {
48
+ throw new error_1.FirebaseError(`Can only create at most one regional AI Logic Trigger for ${eventType} in region ${endpoint.region}`);
49
+ }
50
+ else {
51
+ throw new error_1.FirebaseError(`Can only create at most one global AI Logic Trigger for ${eventType}`);
52
+ }
53
+ }
54
+ }
55
+ async registerTrigger(ep) {
56
+ if (!isAILogicEvent(ep)) {
57
+ return;
58
+ }
59
+ await ailogicApi.upsertBlockingFunction(ep);
60
+ }
61
+ async unregisterTrigger(ep) {
62
+ if (!isAILogicEvent(ep)) {
63
+ return;
64
+ }
65
+ await ailogicApi.deleteBlockingFunction(ep);
66
+ }
67
+ }
68
+ exports.AILogicService = AILogicService;
@@ -11,6 +11,7 @@ const remoteConfig_1 = require("./remoteConfig");
11
11
  const testLab_1 = require("./testLab");
12
12
  const firestore_1 = require("./firestore");
13
13
  const dataconnect_1 = require("./dataconnect");
14
+ const ailogic_1 = require("./ailogic");
14
15
  const noop = () => Promise.resolve();
15
16
  exports.noop = noop;
16
17
  const noopProjectBindings = () => Promise.resolve([]);
@@ -51,6 +52,7 @@ const firebaseAlertsService = {
51
52
  unregisterTrigger: exports.noop,
52
53
  };
53
54
  const authBlockingService = new auth_1.AuthBlockingService();
55
+ const aiLogicService = new ailogic_1.AILogicService();
54
56
  const databaseService = {
55
57
  name: "database",
56
58
  api: "firebasedatabase.googleapis.com",
@@ -122,6 +124,8 @@ const EVENT_SERVICE_MAPPING = {
122
124
  "google.cloud.firestore.document.v1.updated.withAuthContext": firestoreService,
123
125
  "google.cloud.firestore.document.v1.deleted.withAuthContext": firestoreService,
124
126
  "google.firebase.dataconnect.connector.v1.mutationExecuted": dataconnectService,
127
+ "firebase.vertexai.v1beta.beforeGenerateContent": aiLogicService,
128
+ "firebase.vertexai.v1beta.afterGenerateContent": aiLogicService,
125
129
  };
126
130
  function serviceForEndpoint(endpoint) {
127
131
  if (backend.isEventTriggered(endpoint)) {
@@ -54,36 +54,36 @@
54
54
  },
55
55
  "dataconnect": {
56
56
  "darwin": {
57
- "version": "3.3.0",
58
- "expectedSize": 32051312,
59
- "expectedChecksum": "9c9d9fb375826d90f9a57ce7a1770afc",
60
- "expectedChecksumSHA256": "ae2fe4f4b9a79b6bfd52ef227dcdb5e58c5b0e3a662a3874abc07c73d2e8f8e4",
61
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.3.0",
62
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.3.0"
57
+ "version": "3.3.1",
58
+ "expectedSize": 32105392,
59
+ "expectedChecksum": "dfe6ff725864c37889c238aac24be304",
60
+ "expectedChecksumSHA256": "1ccfebb4c0ff85f0503b907aa589658774bb6d4fac0180c3fa6bdff3a865090d",
61
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.3.1",
62
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.3.1"
63
63
  },
64
64
  "darwin_arm64": {
65
- "version": "3.3.0",
66
- "expectedSize": 30237490,
67
- "expectedChecksum": "cd6e0b50e7614edd420a44cde1a6de54",
68
- "expectedChecksumSHA256": "1524161c428f6c97ae1e4eb6371028bace2280f1090ebe89e73313afb30b7bdc",
69
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.3.0",
70
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.3.0"
65
+ "version": "3.3.1",
66
+ "expectedSize": 30287922,
67
+ "expectedChecksum": "59af3cb51c78e8114d634afea811f8cc",
68
+ "expectedChecksumSHA256": "75bde31d15c4cc14de7071ff50cdd0d8fb644491e0c9ee3c1da82fdaf8d976a9",
69
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.3.1",
70
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.3.1"
71
71
  },
72
72
  "win32": {
73
- "version": "3.3.0",
74
- "expectedSize": 32093696,
75
- "expectedChecksum": "e2b6a90994609e613aae189fb6bb732b",
76
- "expectedChecksumSHA256": "ddf44b362658a43ffb97c23e605e26d257e786adb9a71466ebd756b36c4dd212",
77
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.3.0",
78
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.3.0.exe"
73
+ "version": "3.3.1",
74
+ "expectedSize": 32148992,
75
+ "expectedChecksum": "3205dc92bbc7edb4c5821641486dc70c",
76
+ "expectedChecksumSHA256": "fa7796077728414b0682f6ccf1df0fc7b2f56bb590f1e62698dbb7c1ddaf0fb0",
77
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.3.1",
78
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.3.1.exe"
79
79
  },
80
80
  "linux": {
81
- "version": "3.3.0",
82
- "expectedSize": 31211704,
83
- "expectedChecksum": "48b40f31c1897afd39e3b256c356730a",
84
- "expectedChecksumSHA256": "e6774287f3a3ea7ee240f524644e0b0441720dd5d55d6a970a6c4db9923b517f",
85
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.3.0",
86
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.3.0"
81
+ "version": "3.3.1",
82
+ "expectedSize": 31264952,
83
+ "expectedChecksum": "85ffdef78810e0074ac94c453a200daa",
84
+ "expectedChecksumSHA256": "f232e03165c28f72bc99dfbd2dde1bcaf8298045817b60d72d407da7dae9e9f1",
85
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.3.1",
86
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.3.1"
87
87
  }
88
88
  }
89
89
  }
@@ -34,9 +34,16 @@ class DefaultStorageRulesManager {
34
34
  .watch(rulesFile, { persistent: true, ignoreInitial: true })
35
35
  .on("change", async () => {
36
36
  await new Promise((res) => setTimeout(res, 5));
37
- this._logger.logLabeled("BULLET", "storage", "Change detected, updating rules for Cloud Storage...");
38
- this._rules.content = (0, fsutils_1.readFile)(rulesFile);
39
- await this.loadRuleset();
37
+ try {
38
+ const content = (0, fsutils_1.readFile)(rulesFile);
39
+ this._rules.content = content;
40
+ this._logger.logLabeled("BULLET", "storage", "Change detected, updating rules for Cloud Storage...");
41
+ await this.loadRuleset();
42
+ }
43
+ catch (e) {
44
+ const message = e instanceof Error ? e.message : String(e);
45
+ this._logger.logLabeled("DEBUG", "storage", `A rule file change was detected, but there was an error reading it: ${message}`);
46
+ }
40
47
  });
41
48
  }
42
49
  async loadRuleset() {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageRulesRuntime = exports.StorageRulesIssues = exports.StorageRulesetInstance = void 0;
4
+ exports.createAuthExpressionValue = createAuthExpressionValue;
4
5
  const cross_spawn_1 = require("cross-spawn");
5
6
  const error_1 = require("../../../error");
6
7
  const AsyncLock = require("async-lock");
@@ -332,14 +333,15 @@ function createAuthExpressionValue(opts) {
332
333
  if (!opts.token) {
333
334
  return toExpressionValue(null);
334
335
  }
335
- else {
336
- const tokenPayload = jwt.decode(opts.token, { json: true });
337
- const jsonValue = {
338
- uid: tokenPayload.user_id,
339
- token: tokenPayload,
340
- };
341
- return toExpressionValue(jsonValue);
336
+ const tokenPayload = jwt.decode(opts.token, { json: true });
337
+ if (typeof tokenPayload !== "object" || !tokenPayload) {
338
+ return toExpressionValue(null);
342
339
  }
340
+ const jsonValue = {
341
+ uid: "user_id" in tokenPayload ? tokenPayload.user_id : undefined,
342
+ token: tokenPayload,
343
+ };
344
+ return toExpressionValue(jsonValue);
343
345
  }
344
346
  function createRequestExpressionValue(opts) {
345
347
  const fields = {
@@ -58,10 +58,22 @@ exports.ALL_EXPERIMENTS = experiments({
58
58
  shortDescription: "Functions created using the V2 API target Cloud Run Functions (not production ready)",
59
59
  public: false,
60
60
  },
61
+ functionsiac: {
62
+ shortDescription: "Exports functions IaC code",
63
+ public: false,
64
+ },
61
65
  functionsrunapionly: {
62
66
  shortDescription: "Use Cloud Run API to list v2 functions",
63
67
  public: false,
64
68
  },
69
+ bypassfunctionsdeprecationcheck: {
70
+ shortDescription: "Bypass Functions check for old runtimes",
71
+ fullDescription: "Bypasses the local check for whether a functions runtime is " +
72
+ "decommissioned. This does not, by itself, allow you to deploy a function with a " +
73
+ "decommissioned runtime, as there are server-side checks as well.",
74
+ public: false,
75
+ default: false,
76
+ },
65
77
  emulatoruisnapshot: {
66
78
  shortDescription: "Load pre-release versions of the emulator UI",
67
79
  },
@@ -109,6 +121,11 @@ exports.ALL_EXPERIMENTS = experiments({
109
121
  default: false,
110
122
  public: false,
111
123
  },
124
+ abiu: {
125
+ shortDescription: "Enable App Hosting ABIU and runtime selection",
126
+ default: false,
127
+ public: false,
128
+ },
112
129
  dataconnect: {
113
130
  shortDescription: "Deprecated. Previosuly, enabled Data Connect related features.",
114
131
  fullDescription: "Deprecated. Previously, enabled Data Connect related features.",
@@ -150,6 +167,11 @@ exports.ALL_EXPERIMENTS = experiments({
150
167
  default: true,
151
168
  public: false,
152
169
  },
170
+ fdcrealtime: {
171
+ shortDescription: "Enable Firebase Data Connect realtime feature.",
172
+ default: false,
173
+ public: false,
174
+ },
153
175
  });
154
176
  function isValidExperiment(name) {
155
177
  return Object.keys(exports.ALL_EXPERIMENTS).includes(name);
@@ -43,6 +43,8 @@ async function listExtensions(projectId) {
43
43
  state,
44
44
  version,
45
45
  updateTime,
46
+ params: instance.config.params,
47
+ systemParams: instance.config.systemParams,
46
48
  });
47
49
  });
48
50
  (0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `list of extensions installed in ${clc.bold(projectId)}:`);