firebase-tools 15.30.1 → 15.30.2

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.
@@ -13,8 +13,10 @@ exports.isBlockingTriggered = isBlockingTriggered;
13
13
  exports.resolveBackend = resolveBackend;
14
14
  exports.envWithTypes = envWithTypes;
15
15
  exports.toBackend = toBackend;
16
- exports.applyPrefix = applyPrefix;
17
- exports.applyEnvSecretBindings = applyEnvSecretBindings;
16
+ exports.applyKitSecretRefPrefix = applyKitSecretRefPrefix;
17
+ exports.applyEndpointPrefix = applyEndpointPrefix;
18
+ exports.applyEnvSecretBindingsToParams = applyEnvSecretBindingsToParams;
19
+ exports.applyEnvSecretBindingsToBuild = applyEnvSecretBindingsToBuild;
18
20
  exports.parseSecretRef = parseSecretRef;
19
21
  const backend = require("./backend");
20
22
  const proto = require("../../gcp/proto");
@@ -23,9 +25,11 @@ const logger_1 = require("../../logger");
23
25
  const error_1 = require("../../error");
24
26
  const functional_1 = require("../../functional");
25
27
  const cel_1 = require("./cel");
28
+ const projects = require("../../management/projects");
29
+ const projectConfig_1 = require("../../functions/projectConfig");
26
30
  exports.REGION_TBD = "REGION_TBD";
27
31
  exports.SECRET_REF_PREFIX = "FIREBASE_SECRET_REF_";
28
- const GCP_PROJECT_ID_PATTERN = "([a-z][-a-z0-9]{4,28}[a-z0-9])";
32
+ const GCP_PROJECT_ID_OR_NUM_PATTERN = "((?:\\d+)|(?:[a-z][-a-z0-9]{4,28}[a-z0-9]))";
29
33
  exports.GCP_SECRET_ID_PATTERN = "([a-zA-Z0-9-_]+)";
30
34
  exports.SECRET_REF_SHORT_RE = new RegExp("^" +
31
35
  exports.GCP_SECRET_ID_PATTERN +
@@ -34,7 +38,7 @@ exports.SECRET_REF_SHORT_RE = new RegExp("^" +
34
38
  ")?$");
35
39
  exports.SECRET_REF_LONG_RE = new RegExp("^" +
36
40
  "projects/" +
37
- GCP_PROJECT_ID_PATTERN +
41
+ GCP_PROJECT_ID_OR_NUM_PATTERN +
38
42
  "/secrets/" +
39
43
  exports.GCP_SECRET_ID_PATTERN +
40
44
  "(?:(?:/versions/|:|#|@)" +
@@ -385,7 +389,18 @@ function discoverTrigger(endpoint, region, r) {
385
389
  }
386
390
  (0, functional_1.assertExhaustive)(endpoint);
387
391
  }
388
- function applyPrefix(build, prefix) {
392
+ function applyKitSecretRefPrefix(build, instanceId) {
393
+ const kitPrefix = (0, projectConfig_1.addKitPrefix)(instanceId);
394
+ for (const secretParam of build.params.filter((p) => params.isSecretParam(p))) {
395
+ secretParam.resourceId = `${kitPrefix}-${secretParam.name}`;
396
+ }
397
+ for (const endpoint of Object.values(build.endpoints)) {
398
+ for (const envVar of endpoint.secretEnvironmentVariables ?? []) {
399
+ envVar.secret = `${kitPrefix}-${envVar.secret}`;
400
+ }
401
+ }
402
+ }
403
+ function applyEndpointPrefix(build, prefix) {
389
404
  if (!prefix) {
390
405
  return;
391
406
  }
@@ -425,7 +440,19 @@ function applyPrefix(build, prefix) {
425
440
  }
426
441
  }
427
442
  }
428
- function applyEnvSecretBindings(build, envSecrets) {
443
+ function applyEnvSecretBindingsToParams(params, envSecrets) {
444
+ for (const key of Object.keys(envSecrets)) {
445
+ const { secretId, version } = envSecrets[key];
446
+ for (const param of params) {
447
+ if (param.type === "secret" && param.name.toUpperCase() === key.toUpperCase()) {
448
+ param.resourceId = secretId;
449
+ param.version = version;
450
+ param.inLocalEnvironment = true;
451
+ }
452
+ }
453
+ }
454
+ }
455
+ async function applyEnvSecretBindingsToBuild(build, envSecrets) {
429
456
  if (envSecrets.empty) {
430
457
  return;
431
458
  }
@@ -433,15 +460,20 @@ function applyEnvSecretBindings(build, envSecrets) {
433
460
  for (const endpointName of Object.keys(build.endpoints)) {
434
461
  logger_1.logger.debug(`${endpointName} declared secrets: ${JSON.stringify(build.endpoints[endpointName].secretEnvironmentVariables)}`);
435
462
  }
463
+ applyEnvSecretBindingsToParams(build.params, envSecrets);
464
+ const projectNumberToId = new Map();
436
465
  for (const key of Object.keys(envSecrets)) {
437
466
  const secretRef = envSecrets[key];
438
- const { projectId, secretId, version } = secretRef;
439
- for (const param of build.params) {
440
- if (param.type === "secret" && param.name.toUpperCase() === key) {
441
- param.resourceId = secretId;
442
- param.version = version;
443
- param.inLocalEnvironment = true;
467
+ let { projectId } = secretRef;
468
+ const { secretId, version } = secretRef;
469
+ if (projectId && /^\d+$/.test(projectId)) {
470
+ let resolvedId = projectNumberToId.get(projectId);
471
+ if (!resolvedId) {
472
+ const project = await projects.getProject(projectId);
473
+ resolvedId = project.projectId;
474
+ projectNumberToId.set(projectId, resolvedId);
444
475
  }
476
+ projectId = resolvedId;
445
477
  }
446
478
  for (const endpointName of Object.keys(build.endpoints)) {
447
479
  const endpoint = build.endpoints[endpointName];
@@ -9,6 +9,7 @@ exports.isTextInput = isTextInput;
9
9
  exports.isSelectInput = isSelectInput;
10
10
  exports.isResourceInput = isResourceInput;
11
11
  exports.isMultiSelectInput = isMultiSelectInput;
12
+ exports.isSecretParam = isSecretParam;
12
13
  exports.resolveParams = resolveParams;
13
14
  const clc = require("colorette");
14
15
  const logger_1 = require("../../logger");
@@ -22,6 +23,7 @@ const storage_1 = require("../../gcp/storage");
22
23
  const cel_1 = require("./cel");
23
24
  const secretManager_1 = require("../../gcp/secretManager");
24
25
  const experiments = require("../../experiments");
26
+ const marked_1 = require("marked");
25
27
  function dependenciesCEL(expr) {
26
28
  const deps = [];
27
29
  const paramCapture = /{{ params\.(\w+) }}/g;
@@ -82,6 +84,9 @@ function isResourceInput(input) {
82
84
  function isMultiSelectInput(input) {
83
85
  return {}.hasOwnProperty.call(input, "multiSelect");
84
86
  }
87
+ function isSecretParam(param) {
88
+ return param.type === "secret";
89
+ }
85
90
  class ParamValue {
86
91
  constructor(rawValue, internal, types) {
87
92
  this.rawValue = rawValue;
@@ -259,7 +264,11 @@ async function ensureSecret(secretParam, projectId, nonInteractive, force) {
259
264
  }
260
265
  return ensureSecret(secretParam, projectId, nonInteractive, force);
261
266
  }
262
- const promptMessage = `The value for this secret (${secretParam.name}) will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${resourceId}. Enter ${secretParam.format === "json" ? "a JSON value" : "a value"} for ${secretParam.label || secretParam.name}:`;
267
+ const label = secretParam.label || secretParam.name;
268
+ const notice = `The value for this secret will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${resourceId}.`;
269
+ const desc = secretParam.description ? `${secretParam.description} ${notice}` : notice;
270
+ logger_1.logger.info(`\n${clc.bold(label)}: ${(await (0, marked_1.marked)(desc)).trim()}`);
271
+ const promptMessage = `Enter ${secretParam.format === "json" ? "a JSON value" : "a value"} for ${label}:`;
263
272
  const secretValue = await (0, prompt_1.password)({
264
273
  message: promptMessage,
265
274
  });
@@ -288,6 +297,13 @@ async function ensureSecret(secretParam, projectId, nonInteractive, force) {
288
297
  return secretRefString;
289
298
  }
290
299
  async function promptParam(param, projectId, resolvedDefault) {
300
+ const label = param.label || param.name;
301
+ if (param.description) {
302
+ logger_1.logger.info(`\n${clc.bold(label)}: ${(await (0, marked_1.marked)(param.description)).trim()}`);
303
+ }
304
+ else {
305
+ logger_1.logger.info("");
306
+ }
291
307
  if (param.type === "string") {
292
308
  const provided = await promptStringParam(param, projectId, resolvedDefault);
293
309
  return new ParamValue(provided.toString(), false, { string: true });
@@ -314,33 +330,21 @@ async function promptList(param, projectId, resolvedDefault) {
314
330
  const defaultToText = { text: {} };
315
331
  param.input = defaultToText;
316
332
  }
317
- let prompt;
333
+ const label = param.label || param.name;
318
334
  if (isSelectInput(param.input)) {
319
335
  throw new error_1.FirebaseError("List params cannot have non-list selector inputs");
320
336
  }
321
337
  else if (isMultiSelectInput(param.input)) {
322
- prompt = `Select a value for ${param.label || param.name}:`;
323
- if (param.description) {
324
- prompt += ` \n(${param.description})`;
325
- }
326
- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. ";
327
- return promptSelectMultiple(prompt, param.input, resolvedDefault, param.input.multiSelect.nonEmpty, (res) => res);
338
+ return promptSelectMultiple(`Select values for ${label}:`, param.input, resolvedDefault, param.input.multiSelect.nonEmpty, (res) => res);
328
339
  }
329
340
  else if (isTextInput(param.input)) {
330
- prompt = `Enter a list of strings (delimiter: ${param.delimiter ? param.delimiter : ","}) for ${param.label || param.name}:`;
331
- if (param.description) {
332
- prompt += ` \n(${param.description})`;
333
- }
334
- return promptText(prompt, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => {
335
- return res.split(param.delimiter || ",");
341
+ const delimiter = param.delimiter ? param.delimiter : ",";
342
+ return promptText(`Enter a list of strings (delimiter: ${delimiter}) for ${label}:`, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => {
343
+ return res.split(delimiter);
336
344
  });
337
345
  }
338
346
  else if (isResourceInput(param.input)) {
339
- prompt = `Select values for ${param.label || param.name}:`;
340
- if (param.description) {
341
- prompt += ` \n(${param.description})`;
342
- }
343
- return promptResourceStrings(prompt, param.input, projectId, false);
347
+ return promptResourceStrings(`Select values for ${label}:`, param.input, projectId, false);
344
348
  }
345
349
  else {
346
350
  (0, functional_1.assertExhaustive)(param.input);
@@ -352,24 +356,15 @@ async function promptBooleanParam(param, resolvedDefault) {
352
356
  param.input = defaultToText;
353
357
  }
354
358
  const isTruthyInput = (res) => ["true", "y", "yes", "1"].includes(res.toLowerCase());
355
- let prompt;
359
+ const label = param.label || param.name;
356
360
  if (isSelectInput(param.input)) {
357
- prompt = `Select a value for ${param.label || param.name}:`;
358
- if (param.description) {
359
- prompt += ` \n(${param.description})`;
360
- }
361
- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. ";
362
- return promptSelect(prompt, param.input, resolvedDefault, isTruthyInput);
361
+ return promptSelect(`Select a value for ${label}:`, param.input, resolvedDefault, isTruthyInput);
363
362
  }
364
363
  else if (isMultiSelectInput(param.input)) {
365
364
  throw new error_1.FirebaseError("Non-list params cannot have multi selector inputs");
366
365
  }
367
366
  else if (isTextInput(param.input)) {
368
- prompt = `Enter a boolean value for ${param.label || param.name}:`;
369
- if (param.description) {
370
- prompt += ` \n(${param.description})`;
371
- }
372
- return promptText(prompt, param.input, resolvedDefault, false, isTruthyInput);
367
+ return promptText(`Enter a boolean value for ${label}:`, param.input, resolvedDefault, false, isTruthyInput);
373
368
  }
374
369
  else if (isResourceInput(param.input)) {
375
370
  throw new error_1.FirebaseError("Boolean params cannot have Cloud Resource selector inputs");
@@ -383,31 +378,18 @@ async function promptStringParam(param, projectId, resolvedDefault) {
383
378
  const defaultToText = { text: {} };
384
379
  param.input = defaultToText;
385
380
  }
386
- let prompt;
381
+ const label = param.label || param.name;
387
382
  if (isResourceInput(param.input)) {
388
- prompt = `Select a value for ${param.label || param.name}:`;
389
- if (param.description) {
390
- prompt += ` \n(${param.description})`;
391
- }
392
- return promptResourceString(prompt, param.input, projectId, resolvedDefault);
383
+ return promptResourceString(`Select a value for ${label}:`, param.input, projectId, resolvedDefault);
393
384
  }
394
385
  else if (isMultiSelectInput(param.input)) {
395
386
  throw new error_1.FirebaseError("Non-list params cannot have multi selector inputs");
396
387
  }
397
388
  else if (isSelectInput(param.input)) {
398
- prompt = `Select a value for ${param.label || param.name}:`;
399
- if (param.description) {
400
- prompt += ` \n(${param.description})`;
401
- }
402
- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. ";
403
- return promptSelect(prompt, param.input, resolvedDefault, (res) => res);
389
+ return promptSelect(`Select a value for ${label}:`, param.input, resolvedDefault, (res) => res);
404
390
  }
405
391
  else if (isTextInput(param.input)) {
406
- prompt = `Enter a string value for ${param.label || param.name}:`;
407
- if (param.description) {
408
- prompt += ` \n(${param.description})`;
409
- }
410
- return promptText(prompt, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => res);
392
+ return promptText(`Enter a string value for ${label}:`, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => res);
411
393
  }
412
394
  else {
413
395
  (0, functional_1.assertExhaustive)(param.input);
@@ -418,14 +400,9 @@ async function promptIntParam(param, resolvedDefault) {
418
400
  const defaultToText = { text: {} };
419
401
  param.input = defaultToText;
420
402
  }
421
- let prompt;
403
+ const label = param.label || param.name;
422
404
  if (isSelectInput(param.input)) {
423
- prompt = `Select a value for ${param.label || param.name}:`;
424
- if (param.description) {
425
- prompt += ` \n(${param.description})`;
426
- }
427
- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. ";
428
- return promptSelect(prompt, param.input, resolvedDefault, (res) => {
405
+ return promptSelect(`Select a value for ${label}:`, param.input, resolvedDefault, (res) => {
429
406
  if (isNaN(+res)) {
430
407
  return { message: `"${res}" could not be converted to a number.` };
431
408
  }
@@ -439,11 +416,7 @@ async function promptIntParam(param, resolvedDefault) {
439
416
  throw new error_1.FirebaseError("Non-list params cannot have multi selector inputs");
440
417
  }
441
418
  else if (isTextInput(param.input)) {
442
- prompt = `Enter an integer value for ${param.label || param.name}:`;
443
- if (param.description) {
444
- prompt += ` \n(${param.description})`;
445
- }
446
- return promptText(prompt, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => {
419
+ return promptText(`Enter an integer value for ${label}:`, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => {
447
420
  if (isNaN(+res)) {
448
421
  return { message: `"${res}" could not be converted to a number.` };
449
422
  }
@@ -533,6 +506,7 @@ async function promptSelect(prompt, input, resolvedDefault, converter) {
533
506
  const response = await (0, prompt_1.select)({
534
507
  default: resolvedDefault,
535
508
  message: prompt,
509
+ instructions: "(Use arrow keys to navigate, and Enter to confirm your choice)",
536
510
  choices: input.select.options.map((option) => {
537
511
  return {
538
512
  checked: false,
@@ -552,6 +526,7 @@ async function promptSelectMultiple(prompt, input, resolvedDefault, enforceNonEm
552
526
  const response = await (0, prompt_1.checkbox)({
553
527
  default: resolvedDefault,
554
528
  message: prompt,
529
+ instructions: "(Press Space to select, and Enter to confirm your choices)",
555
530
  choices: input.multiSelect.options.map((option) => {
556
531
  return {
557
532
  checked: false,
@@ -211,7 +211,7 @@ async function prepare(context, options, payload) {
211
211
  .filter((e) => e.codebase === codebase || e.codebase === undefined);
212
212
  await resolveDefaultRegionsForBuild(wantBuild, backend.of(...relevantEndpoints));
213
213
  const parsedSecretRefs = (0, functional_1.mapObject)(secretRefs, (unparsed) => build.parseSecretRef(unparsed));
214
- build.applyEnvSecretBindings(wantBuild, parsedSecretRefs);
214
+ await build.applyEnvSecretBindingsToBuild(wantBuild, parsedSecretRefs);
215
215
  const { backend: wantBackend, envs: resolvedEnvs, secretRefs: resolvedSecretRefs, } = await build.resolveBackend({
216
216
  build: wantBuild,
217
217
  firebaseConfig,
@@ -537,7 +537,10 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
537
537
  const prefix = (0, projectConfig_1.isKitConfig)(codebaseConfig)
538
538
  ? (0, projectConfig_1.addKitPrefix)(codebase)
539
539
  : codebaseConfig.prefix || "";
540
- build.applyPrefix(discoveredBuild, prefix);
540
+ build.applyEndpointPrefix(discoveredBuild, prefix);
541
+ if ((0, projectConfig_1.isKitConfig)(codebaseConfig)) {
542
+ build.applyKitSecretRefPrefix(discoveredBuild, codebase);
543
+ }
541
544
  wantBuilds[codebase] = discoveredBuild;
542
545
  }
543
546
  return wantBuilds;
@@ -5,6 +5,10 @@ const crypto_1 = require("crypto");
5
5
  const types_1 = require("../types");
6
6
  const emulatorLogger_1 = require("../emulatorLogger");
7
7
  const registry_1 = require("../registry");
8
+ const AUTH_V2_ACTION_MAP = {
9
+ create: "created",
10
+ delete: "deleted",
11
+ };
8
12
  class AuthCloudFunction {
9
13
  constructor(projectId) {
10
14
  this.projectId = projectId;
@@ -16,17 +20,32 @@ class AuthCloudFunction {
16
20
  if (!this.enabled)
17
21
  return;
18
22
  const userInfoPayload = this.createUserInfoPayload(user);
19
- const multicastEventBody = this.createEventRequestBody(action, userInfoPayload);
23
+ const legacyEventBody = this.createEventRequestBody(action, userInfoPayload);
24
+ const v2CloudEventBody = this.createCloudEventRequestBody(action, userInfoPayload);
20
25
  const c = registry_1.EmulatorRegistry.client(types_1.Emulators.FUNCTIONS);
21
- let res;
26
+ const errStatus = [];
22
27
  let err;
23
28
  try {
24
- res = await c.post(`/functions/projects/${this.projectId}/trigger_multicast`, multicastEventBody);
29
+ const legacyRes = await c.post(`/functions/projects/${this.projectId}/trigger_multicast`, legacyEventBody);
30
+ if (legacyRes.status !== 200) {
31
+ errStatus.push(legacyRes.status);
32
+ }
25
33
  }
26
34
  catch (e) {
27
- err = e;
35
+ err = e instanceof Error ? e : new Error(String(e));
28
36
  }
29
- if (err || res?.status !== 200) {
37
+ try {
38
+ const v2Res = await c.post(`/functions/projects/${this.projectId}/trigger_multicast`, v2CloudEventBody, {
39
+ headers: { "Content-Type": "application/cloudevents+json; charset=UTF-8" },
40
+ });
41
+ if (v2Res.status !== 200) {
42
+ errStatus.push(v2Res.status);
43
+ }
44
+ }
45
+ catch (e) {
46
+ err = e instanceof Error ? e : new Error(String(e));
47
+ }
48
+ if (err || errStatus.length > 0) {
30
49
  this.logger.logLabeled("WARN", "functions", `Firebase Authentication function was not triggered due to emulation error. Please file a bug.`);
31
50
  }
32
51
  }
@@ -43,6 +62,22 @@ class AuthCloudFunction {
43
62
  data: userInfoPayload,
44
63
  };
45
64
  }
65
+ createCloudEventRequestBody(action, userInfoPayload) {
66
+ const ceAction = AUTH_V2_ACTION_MAP[action];
67
+ const cloudEvent = {
68
+ specversion: "1.0",
69
+ id: (0, crypto_1.randomUUID)(),
70
+ time: new Date().toISOString(),
71
+ type: `google.firebase.auth.user.v2.${ceAction}`,
72
+ source: `//identitytoolkit.googleapis.com/projects/${this.projectId}`,
73
+ subject: `users/${userInfoPayload.uid}`,
74
+ data: action === "create" ? { value: userInfoPayload } : { oldValue: userInfoPayload },
75
+ };
76
+ if (userInfoPayload.tenantId) {
77
+ cloudEvent.tenantid = userInfoPayload.tenantId;
78
+ }
79
+ return cloudEvent;
80
+ }
46
81
  createUserInfoPayload(user) {
47
82
  return {
48
83
  uid: user.localId,
@@ -54,36 +54,36 @@
54
54
  },
55
55
  "dataconnect": {
56
56
  "darwin": {
57
- "version": "3.4.19",
58
- "expectedSize": 33412928,
59
- "expectedChecksum": "5a65cd626d5c022eab4c2036b18f0314",
60
- "expectedChecksumSHA256": "4a63243e720d26de7e2e5bd5060fc92768f09446ec42b3369fb6ddc06a9cdddf",
61
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.19",
62
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.19"
57
+ "version": "3.4.20",
58
+ "expectedSize": 33787120,
59
+ "expectedChecksum": "a8c044198a62239fc20a31ef545f8eea",
60
+ "expectedChecksumSHA256": "4cbef4430bb5ad72f8fbe2293b938463a1e912b5c17b5577c6546343fe3149a9",
61
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.20",
62
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.20"
63
63
  },
64
64
  "darwin_arm64": {
65
- "version": "3.4.19",
66
- "expectedSize": 31539602,
67
- "expectedChecksum": "cd914718f705a9e614bc3024f443bb52",
68
- "expectedChecksumSHA256": "dafb2e532c29d876cb30d5c2bf32b2e50a614386dc16ba82b0ed6a9fca2a6db3",
69
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.19",
70
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.19"
65
+ "version": "3.4.20",
66
+ "expectedSize": 31883698,
67
+ "expectedChecksum": "8c8cf2b1c8b99cb7ebd459ca383aa8ed",
68
+ "expectedChecksumSHA256": "873e9aab3aa09a946d4a729e5755d38c5d607655796f5a031f7b21c339fa5ef7",
69
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.20",
70
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.20"
71
71
  },
72
72
  "win32": {
73
- "version": "3.4.19",
74
- "expectedSize": 33444864,
75
- "expectedChecksum": "e2f84df8d6c536bea29d2ccc4cb21e79",
76
- "expectedChecksumSHA256": "756e370334ef982547e7252b3f91fd75b35f85c5d3666e8f3773a4a19a00c8f8",
77
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.19",
78
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.19.exe"
73
+ "version": "3.4.20",
74
+ "expectedSize": 33819136,
75
+ "expectedChecksum": "2bb404ba566f5e2d7224a802c860035c",
76
+ "expectedChecksumSHA256": "5e613eddc18378c8b917a94bd7380e6174918ccb29f5bed915927434078bc4a7",
77
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.20",
78
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.20.exe"
79
79
  },
80
80
  "linux": {
81
- "version": "3.4.19",
82
- "expectedSize": 32542904,
83
- "expectedChecksum": "63f099c9b9dad6e7d2adddae8af884a3",
84
- "expectedChecksumSHA256": "bc74b68cc4bafcccc57dbe659a74b4403c225f01f851b5a4a61dcea81e8b1310",
85
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.19",
86
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.19"
81
+ "version": "3.4.20",
82
+ "expectedSize": 32911544,
83
+ "expectedChecksum": "9ae887603b8085e50ff992dd7c86385c",
84
+ "expectedChecksumSHA256": "0500ecb9f22c8e26df1f650e656497b542f26b47b3b5730fde850a918643ca2f",
85
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.20",
86
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.20"
87
87
  }
88
88
  }
89
89
  }
@@ -170,12 +170,18 @@ class FunctionsEmulator {
170
170
  else {
171
171
  triggerKey = `${this.args.projectId}:${event.eventType}`;
172
172
  }
173
- if (event.data.bucket) {
173
+ if (event.data?.bucket) {
174
174
  triggerKey += `:${event.data.bucket}`;
175
175
  }
176
176
  const triggers = this.multicastTriggers[triggerKey] || [];
177
177
  const { host, port } = this.getInfo();
178
- triggers.forEach((triggerId) => {
178
+ const eventTenantId = (0, functionsEmulatorShared_1.getEventTenantId)(event);
179
+ for (const triggerId of triggers) {
180
+ const record = this.getTriggerRecordByKey(triggerId);
181
+ const filterTenantId = record?.def?.eventTrigger?.eventFilters?.tenantid;
182
+ if (filterTenantId && filterTenantId !== eventTenantId) {
183
+ continue;
184
+ }
179
185
  const work = () => {
180
186
  return new Promise((resolve, reject) => {
181
187
  const trigReq = http.request({
@@ -193,7 +199,7 @@ class FunctionsEmulator {
193
199
  };
194
200
  work.type = `${triggerId}-${new Date().toISOString()}`;
195
201
  this.workQueue.submit(work);
196
- });
202
+ }
197
203
  res.json({ status: "multicast_acknowledged" });
198
204
  };
199
205
  const listBackendsHandler = (req, res) => {
@@ -378,7 +384,10 @@ class FunctionsEmulator {
378
384
  await this.args.extensionsEmulator.addDynamicExtensions(emulatableBackend.codebase, discoveredBuild);
379
385
  await this.loadDynamicExtensionBackends();
380
386
  }
381
- build.applyPrefix(discoveredBuild, emulatableBackend.prefix || "");
387
+ build.applyEndpointPrefix(discoveredBuild, emulatableBackend.prefix || "");
388
+ if (emulatableBackend.env?.FIREBASE_KIT_INSTANCE_ID) {
389
+ build.applyKitSecretRefPrefix(discoveredBuild, emulatableBackend.env.FIREBASE_KIT_INSTANCE_ID);
390
+ }
382
391
  const resolution = await (0, build_1.resolveBackend)({
383
392
  build: discoveredBuild,
384
393
  firebaseConfig: JSON.parse(firebaseConfig),
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EmulatedTrigger = exports.EVENTARC_SOURCE_ENV = void 0;
4
+ exports.getEventTenantId = getEventTenantId;
4
5
  exports.eventServiceImplemented = eventServiceImplemented;
5
6
  exports.prepareEndpoints = prepareEndpoints;
6
7
  exports.emulatedFunctionsFromEndpoints = emulatedFunctionsFromEndpoints;
@@ -36,7 +37,17 @@ const V2_EVENTS = [
36
37
  ...events.v2.STORAGE_EVENTS,
37
38
  ...events.v2.DATABASE_EVENTS,
38
39
  ...events.v2.FIRESTORE_EVENTS,
40
+ ...events.v2.AUTH_EVENTS,
39
41
  ];
42
+ function getEventTenantId(eventPayload) {
43
+ if (!eventPayload || typeof eventPayload !== "object") {
44
+ return undefined;
45
+ }
46
+ if (typeof eventPayload.tenantid === "string") {
47
+ return eventPayload.tenantid;
48
+ }
49
+ return undefined;
50
+ }
40
51
  exports.EVENTARC_SOURCE_ENV = "EVENTARC_CLOUD_EVENT_SOURCE";
41
52
  class EmulatedTrigger {
42
53
  constructor(definition, module) {
@@ -229,12 +240,12 @@ function getServiceFromEventType(eventType) {
229
240
  if (eventType.includes("firebasealerts")) {
230
241
  return constants_1.Constants.SERVICE_FIREALERTS;
231
242
  }
232
- if (eventType.includes("analytics")) {
233
- return constants_1.Constants.SERVICE_ANALYTICS;
234
- }
235
243
  if (eventType.includes("auth")) {
236
244
  return constants_1.Constants.SERVICE_AUTH;
237
245
  }
246
+ if (eventType.includes("analytics")) {
247
+ return constants_1.Constants.SERVICE_ANALYTICS;
248
+ }
238
249
  if (eventType.includes("crashlytics")) {
239
250
  return constants_1.Constants.SERVICE_CRASHLYTICS;
240
251
  }
@@ -224,7 +224,7 @@ exports.ALL_EXPERIMENTS = experiments({
224
224
  fdcapimigration: {
225
225
  shortDescription: "Enable the FDC API schema migration path.",
226
226
  fullDescription: "API based Schema Migration behind experimental flag.",
227
- default: true,
227
+ default: false,
228
228
  public: false,
229
229
  },
230
230
  });
package/lib/fsutils.js CHANGED
@@ -5,10 +5,12 @@ exports.dirExistsSync = dirExistsSync;
5
5
  exports.readFile = readFile;
6
6
  exports.listFiles = listFiles;
7
7
  exports.moveAll = moveAll;
8
+ exports.removeDirectoryIfEmpty = removeDirectoryIfEmpty;
8
9
  const fs_1 = require("fs");
9
10
  const path = require("path");
11
+ const fs = require("fs-extra");
10
12
  const error_1 = require("./error");
11
- const fs_extra_1 = require("fs-extra");
13
+ const logger_1 = require("./logger");
12
14
  function fileExistsSync(path) {
13
15
  try {
14
16
  return (0, fs_1.statSync)(path).isFile();
@@ -56,6 +58,22 @@ function moveAll(srcDir, destDir) {
56
58
  const srcPath = path.join(srcDir, f);
57
59
  if (srcPath === destDir)
58
60
  continue;
59
- (0, fs_extra_1.moveSync)(srcPath, path.join(destDir, f));
61
+ fs.moveSync(srcPath, path.join(destDir, f));
62
+ }
63
+ }
64
+ async function removeDirectoryIfEmpty(absDirPath) {
65
+ try {
66
+ if (await fs.pathExists(absDirPath)) {
67
+ const stat = await fs.stat(absDirPath);
68
+ if (stat.isDirectory()) {
69
+ const entries = await fs.readdir(absDirPath);
70
+ if (entries.length === 0) {
71
+ await fs.remove(absDirPath);
72
+ }
73
+ }
74
+ }
75
+ }
76
+ catch (err) {
77
+ logger_1.logger.debug(`Failed to clean up directory '${absDirPath}' if empty: ${(0, error_1.getErrMsg)(err)}`);
60
78
  }
61
79
  }