firebase-tools-with-isolate 13.16.0 → 13.26.0-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 (221) hide show
  1. package/lib/api.js +3 -1
  2. package/lib/apiv2.js +10 -3
  3. package/lib/appdistribution/client.js +62 -8
  4. package/lib/appdistribution/distribution.js +1 -1
  5. package/lib/apphosting/backend.js +299 -0
  6. package/lib/apphosting/config.js +31 -8
  7. package/lib/apphosting/githubConnections.js +70 -22
  8. package/lib/apphosting/index.js +3 -312
  9. package/lib/apphosting/rollout.js +138 -0
  10. package/lib/apphosting/secrets/index.js +70 -5
  11. package/lib/apphosting/utils.js +41 -0
  12. package/lib/apphosting/yaml.js +82 -0
  13. package/lib/archiveDirectory.js +1 -1
  14. package/lib/auth.js +31 -5
  15. package/lib/bin/firebase.js +2 -2
  16. package/lib/command.js +18 -4
  17. package/lib/commands/appdistribution-distribute.js +4 -4
  18. package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
  19. package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
  20. package/lib/commands/appdistribution-groups-list.js +55 -0
  21. package/lib/commands/appdistribution-testers-list.js +52 -0
  22. package/lib/commands/appdistribution-testers-remove.js +1 -1
  23. package/lib/commands/apphosting-backends-create.js +4 -4
  24. package/lib/commands/apphosting-backends-delete.js +7 -15
  25. package/lib/commands/apphosting-backends-get.js +1 -1
  26. package/lib/commands/apphosting-config-export.js +51 -0
  27. package/lib/commands/apphosting-repos-create.js +23 -0
  28. package/lib/commands/apphosting-rollouts-create.js +14 -15
  29. package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
  30. package/lib/commands/database-import.js +4 -2
  31. package/lib/commands/database-push.js +4 -2
  32. package/lib/commands/database-set.js +4 -2
  33. package/lib/commands/database-settings-get.js +1 -1
  34. package/lib/commands/database-settings-set.js +1 -1
  35. package/lib/commands/dataconnect-sdk-generate.js +4 -1
  36. package/lib/commands/dataconnect-services-list.js +4 -3
  37. package/lib/commands/dataconnect-sql-diff.js +1 -1
  38. package/lib/commands/dataconnect-sql-grant.js +37 -0
  39. package/lib/commands/dataconnect-sql-migrate.js +1 -1
  40. package/lib/commands/dataconnect-sql-shell.js +115 -0
  41. package/lib/commands/deploy.js +2 -0
  42. package/lib/commands/emulators-start.js +4 -1
  43. package/lib/commands/ext-dev-init.js +2 -2
  44. package/lib/commands/ext-dev-list.js +1 -1
  45. package/lib/commands/ext-dev-register.js +2 -2
  46. package/lib/commands/ext-dev-upload.js +2 -2
  47. package/lib/commands/ext-dev-usage.js +2 -2
  48. package/lib/commands/ext-info.js +3 -1
  49. package/lib/commands/ext-install.js +2 -2
  50. package/lib/commands/ext-sdk-install.js +88 -0
  51. package/lib/commands/ext.js +1 -0
  52. package/lib/commands/firestore-databases-restore.js +39 -1
  53. package/lib/commands/functions-secrets-access.js +2 -4
  54. package/lib/commands/index.js +15 -2
  55. package/lib/commands/init.js +25 -15
  56. package/lib/commands/setup-emulators-dataconnect.js +0 -13
  57. package/lib/commands/use.js +1 -1
  58. package/lib/config.js +14 -4
  59. package/lib/crashlytics/buildToolsJarHelper.js +2 -2
  60. package/lib/dataconnect/client.js +1 -1
  61. package/lib/dataconnect/dataplaneClient.js +12 -9
  62. package/lib/dataconnect/ensureApis.js +6 -1
  63. package/lib/dataconnect/fileUtils.js +15 -39
  64. package/lib/dataconnect/freeTrial.js +45 -9
  65. package/lib/dataconnect/load.js +3 -1
  66. package/lib/dataconnect/provisionCloudSql.js +39 -26
  67. package/lib/dataconnect/schemaMigration.js +215 -74
  68. package/lib/dataconnect/types.js +4 -1
  69. package/lib/dataconnect/webhook.js +32 -0
  70. package/lib/deploy/dataconnect/deploy.js +18 -15
  71. package/lib/deploy/dataconnect/prepare.js +41 -0
  72. package/lib/deploy/dataconnect/release.js +16 -7
  73. package/lib/deploy/extensions/deploy.js +3 -1
  74. package/lib/deploy/extensions/deploymentSummary.js +7 -3
  75. package/lib/deploy/extensions/planner.js +44 -5
  76. package/lib/deploy/extensions/prepare.js +45 -73
  77. package/lib/deploy/extensions/release.js +11 -10
  78. package/lib/deploy/extensions/tasks.js +32 -21
  79. package/lib/deploy/firestore/prepare.js +9 -0
  80. package/lib/deploy/firestore/release.js +3 -6
  81. package/lib/deploy/functions/checkIam.js +7 -2
  82. package/lib/deploy/functions/ensure.js +11 -3
  83. package/lib/deploy/functions/prepare.js +32 -21
  84. package/lib/deploy/functions/prepareFunctionsUpload.js +15 -16
  85. package/lib/deploy/functions/release/planner.js +2 -1
  86. package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
  87. package/lib/deploy/functions/runtimes/node/index.js +5 -0
  88. package/lib/deploy/functions/services/auth.js +34 -3
  89. package/lib/deploy/functions/services/index.js +2 -0
  90. package/lib/deploy/index.js +8 -5
  91. package/lib/deploy/lifecycleHooks.js +2 -1
  92. package/lib/emulator/apphosting/config.js +27 -0
  93. package/lib/emulator/apphosting/index.js +38 -0
  94. package/lib/emulator/apphosting/serve.js +50 -0
  95. package/lib/emulator/apphosting/utils.js +18 -0
  96. package/lib/emulator/auth/handlers.js +27 -0
  97. package/lib/emulator/auth/operations.js +41 -2
  98. package/lib/emulator/auth/state.js +2 -1
  99. package/lib/emulator/commandUtils.js +8 -3
  100. package/lib/emulator/constants.js +4 -1
  101. package/lib/emulator/controller.js +48 -5
  102. package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
  103. package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
  104. package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
  105. package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
  106. package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
  107. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
  108. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
  109. package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
  110. package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
  111. package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
  112. package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
  113. package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
  114. package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
  115. package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
  116. package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
  117. package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
  118. package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
  119. package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
  120. package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
  121. package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
  122. package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
  123. package/lib/emulator/dataconnect/pgliteServer.js +95 -0
  124. package/lib/emulator/dataconnectEmulator.js +58 -75
  125. package/lib/emulator/dataconnectToolkitController.js +44 -0
  126. package/lib/emulator/downloadableEmulators.js +27 -16
  127. package/lib/emulator/emulatorLogger.js +3 -0
  128. package/lib/emulator/eventarcEmulator.js +1 -1
  129. package/lib/emulator/extensionsEmulator.js +38 -6
  130. package/lib/emulator/functionsEmulator.js +85 -41
  131. package/lib/emulator/functionsEmulatorShared.js +2 -1
  132. package/lib/emulator/functionsRuntimeWorker.js +2 -1
  133. package/lib/emulator/hub.js +13 -9
  134. package/lib/emulator/hubExport.js +10 -3
  135. package/lib/emulator/loggingEmulator.js +2 -2
  136. package/lib/emulator/portUtils.js +10 -11
  137. package/lib/emulator/registry.js +1 -0
  138. package/lib/emulator/storage/persistence.js +2 -2
  139. package/lib/emulator/storage/rules/runtime.js +1 -1
  140. package/lib/emulator/tasksEmulator.js +5 -2
  141. package/lib/emulator/types.js +3 -0
  142. package/lib/emulator/ui.js +51 -25
  143. package/lib/error.js +31 -1
  144. package/lib/experiments.js +5 -0
  145. package/lib/extensions/emulator/triggerHelper.js +1 -1
  146. package/lib/extensions/extensionsApi.js +14 -10
  147. package/lib/extensions/extensionsHelper.js +15 -6
  148. package/lib/extensions/localHelper.js +31 -0
  149. package/lib/extensions/runtimes/common.js +179 -39
  150. package/lib/extensions/runtimes/node.js +401 -0
  151. package/lib/extensions/types.js +25 -14
  152. package/lib/extensions/warnings.js +5 -2
  153. package/lib/firestore/api.js +2 -1
  154. package/lib/firestore/checkDatabaseType.js +10 -3
  155. package/lib/firestore/delete.js +11 -0
  156. package/lib/firestore/options.js +7 -0
  157. package/lib/frameworks/angular/index.js +15 -3
  158. package/lib/frameworks/constants.js +1 -1
  159. package/lib/frameworks/flutter/index.js +6 -6
  160. package/lib/frameworks/flutter/utils.js +34 -1
  161. package/lib/frameworks/next/index.js +10 -2
  162. package/lib/frameworks/next/utils.js +8 -5
  163. package/lib/frameworks/vite/index.js +2 -2
  164. package/lib/fsutils.js +13 -1
  165. package/lib/functions/constants.js +4 -0
  166. package/lib/functions/events/v1.js +9 -2
  167. package/lib/gcp/apphosting.js +1 -1
  168. package/lib/gcp/cloudmonitoring.js +3 -3
  169. package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
  170. package/lib/gcp/cloudsql/connect.js +49 -37
  171. package/lib/gcp/cloudsql/interactive.js +49 -0
  172. package/lib/gcp/cloudsql/permissions.js +165 -0
  173. package/lib/gcp/devConnect.js +38 -1
  174. package/lib/gcp/firestore.js +5 -1
  175. package/lib/gcp/secretManager.js +12 -5
  176. package/lib/getProjectNumber.js +1 -1
  177. package/lib/init/features/apphosting.js +15 -0
  178. package/lib/init/features/dataconnect/index.js +159 -120
  179. package/lib/init/features/dataconnect/sdk.js +77 -84
  180. package/lib/init/features/emulators.js +2 -15
  181. package/lib/init/features/firestore/index.js +20 -1
  182. package/lib/init/features/firestore/indexes.js +4 -4
  183. package/lib/init/features/genkit/index.js +444 -0
  184. package/lib/init/features/hosting/index.js +2 -2
  185. package/lib/init/features/index.js +1 -1
  186. package/lib/init/features/project.js +6 -6
  187. package/lib/init/features/storage.js +0 -2
  188. package/lib/init/index.js +1 -0
  189. package/lib/init/spawn.js +23 -2
  190. package/lib/logger.js +2 -2
  191. package/lib/management/projects.js +24 -4
  192. package/lib/projectUtils.js +1 -1
  193. package/lib/prompt.js +1 -1
  194. package/lib/rc.js +1 -8
  195. package/lib/requireAuth.js +19 -5
  196. package/lib/requireDatabaseInstance.js +1 -1
  197. package/lib/requirePermissions.js +1 -1
  198. package/lib/responseToError.js +5 -2
  199. package/lib/rulesDeploy.js +1 -1
  200. package/lib/templates.js +2 -2
  201. package/lib/utils.js +16 -11
  202. package/lib/vsCodeUtils.js +8 -0
  203. package/package.json +7 -6
  204. package/schema/connector-yaml.json +57 -17
  205. package/schema/firebase-config.json +24 -0
  206. package/templates/extensions/javascript/package.lint.json +2 -2
  207. package/templates/extensions/javascript/package.nolint.json +2 -2
  208. package/templates/extensions/typescript/package.lint.json +2 -2
  209. package/templates/extensions/typescript/package.nolint.json +2 -2
  210. package/templates/genkit/firebase.0.9.0.template +57 -0
  211. package/templates/init/apphosting/apphosting.yaml +23 -0
  212. package/templates/init/dataconnect/connector.yaml +0 -1
  213. package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
  214. package/templates/init/dataconnect/dataconnect.yaml +1 -1
  215. package/templates/init/dataconnect/queries.gql +1 -2
  216. package/templates/init/functions/javascript/package.lint.json +2 -2
  217. package/templates/init/functions/javascript/package.nolint.json +2 -2
  218. package/templates/init/functions/typescript/package.lint.json +2 -2
  219. package/templates/init/functions/typescript/package.nolint.json +2 -2
  220. package/lib/ensureCloudResourceLocation.js +0 -12
  221. package/lib/init/features/genkit.js +0 -53
@@ -81,10 +81,13 @@ class FunctionsEmulator {
81
81
  this.logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.FUNCTIONS);
82
82
  this.multicastTriggers = {};
83
83
  this.blockingFunctionsConfig = {};
84
+ this.staticBackends = [];
85
+ this.dynamicBackends = [];
84
86
  this.debugMode = false;
87
+ this.staticBackends = args.emulatableBackends;
85
88
  emulatorLogger_1.EmulatorLogger.setVerbosity(this.args.verbosity ? emulatorLogger_1.Verbosity[this.args.verbosity] : emulatorLogger_1.Verbosity["DEBUG"]);
86
89
  if (this.args.debugPort) {
87
- const maybeNodeCodebases = this.args.emulatableBackends.filter((b) => !b.runtime || b.runtime.startsWith("node"));
90
+ const maybeNodeCodebases = this.staticBackends.filter((b) => !b.runtime || b.runtime.startsWith("node"));
88
91
  if (maybeNodeCodebases.length > 1 && typeof this.args.debugPort === "number") {
89
92
  throw new error_1.FirebaseError("Cannot debug on a single port with multiple codebases. " +
90
93
  "Use --inspect-functions=true to assign dynamic ports to each codebase");
@@ -96,12 +99,37 @@ class FunctionsEmulator {
96
99
  this.adminSdkConfig = { ...this.args.adminSdkConfig, projectId: this.args.projectId };
97
100
  const mode = this.debugMode ? types_1.FunctionsExecutionMode.SEQUENTIAL : types_1.FunctionsExecutionMode.AUTO;
98
101
  this.workerPools = {};
99
- for (const backend of this.args.emulatableBackends) {
102
+ for (const backend of this.staticBackends) {
100
103
  const pool = new functionsRuntimeWorker_1.RuntimeWorkerPool(mode);
101
104
  this.workerPools[backend.codebase] = pool;
102
105
  }
103
106
  this.workQueue = new workQueue_1.WorkQueue(mode);
104
107
  }
108
+ async loadDynamicExtensionBackends() {
109
+ if (this.args.extensionsEmulator) {
110
+ const unfilteredBackends = this.args.extensionsEmulator.getDynamicExtensionBackends();
111
+ this.dynamicBackends =
112
+ this.args.extensionsEmulator.filterUnemulatedTriggers(unfilteredBackends);
113
+ const mode = this.debugMode ? types_1.FunctionsExecutionMode.SEQUENTIAL : types_1.FunctionsExecutionMode.AUTO;
114
+ const credentialEnv = await this.getCredentialsEnvironment();
115
+ for (const backend of this.dynamicBackends) {
116
+ backend.env = { ...credentialEnv, ...backend.env };
117
+ if (this.workerPools[backend.codebase]) {
118
+ if (this.debugMode) {
119
+ this.workerPools[backend.codebase].exit();
120
+ }
121
+ else {
122
+ this.workerPools[backend.codebase].refresh();
123
+ }
124
+ }
125
+ else {
126
+ const pool = new functionsRuntimeWorker_1.RuntimeWorkerPool(mode);
127
+ this.workerPools[backend.codebase] = pool;
128
+ }
129
+ await this.loadTriggers(backend, true);
130
+ }
131
+ }
132
+ }
105
133
  async getCredentialsEnvironment() {
106
134
  const credentialEnv = {};
107
135
  if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
@@ -231,7 +259,7 @@ class FunctionsEmulator {
231
259
  }
232
260
  async start() {
233
261
  const credentialEnv = await this.getCredentialsEnvironment();
234
- for (const e of this.args.emulatableBackends) {
262
+ for (const e of this.staticBackends) {
235
263
  e.env = { ...credentialEnv, ...e.env };
236
264
  }
237
265
  if (Object.keys(this.adminSdkConfig || {}).length <= 1) {
@@ -251,7 +279,7 @@ class FunctionsEmulator {
251
279
  return Promise.resolve();
252
280
  }
253
281
  async connect() {
254
- for (const backend of this.args.emulatableBackends) {
282
+ for (const backend of this.staticBackends) {
255
283
  this.logger.logLabeled("BULLET", "functions", `Watching "${backend.functionsDir}" for Cloud Functions...`);
256
284
  const watcher = chokidar.watch(backend.functionsDir, {
257
285
  ignored: [
@@ -322,6 +350,10 @@ class FunctionsEmulator {
322
350
  };
323
351
  const userEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
324
352
  const discoveredBuild = await runtimeDelegate.discoverBuild(runtimeConfig, environment);
353
+ if (discoveredBuild.extensions && this.args.extensionsEmulator) {
354
+ await this.args.extensionsEmulator.addDynamicExtensions(emulatableBackend.codebase, discoveredBuild);
355
+ await this.loadDynamicExtensionBackends();
356
+ }
325
357
  const resolution = await (0, build_1.resolveBackend)({
326
358
  build: discoveredBuild,
327
359
  firebaseConfig: JSON.parse(firebaseConfig),
@@ -359,6 +391,9 @@ class FunctionsEmulator {
359
391
  }
360
392
  const toRemove = Object.keys(this.triggers).filter((recordKey) => {
361
393
  const record = this.getTriggerRecordByKey(recordKey);
394
+ if (record.backend.codebase !== emulatableBackend.codebase) {
395
+ return false;
396
+ }
362
397
  if (force) {
363
398
  return true;
364
399
  }
@@ -436,17 +471,17 @@ class FunctionsEmulator {
436
471
  }
437
472
  const ignored = !added;
438
473
  this.addTriggerRecord(definition, { backend: emulatableBackend, ignored, url });
439
- const type = definition.httpsTrigger
474
+ const triggerType = definition.httpsTrigger
440
475
  ? "http"
441
476
  : constants_1.Constants.getServiceName((0, functionsEmulatorShared_1.getFunctionService)(definition));
442
477
  if (ignored) {
443
- const msg = `function ignored because the ${type} emulator does not exist or is not running.`;
478
+ const msg = `function ignored because the ${triggerType} emulator does not exist or is not running.`;
444
479
  this.logger.logLabeled("BULLET", `functions[${definition.id}]`, msg);
445
480
  }
446
481
  else {
447
482
  const msg = url
448
- ? `${clc.bold(type)} function initialized (${url}).`
449
- : `${clc.bold(type)} function initialized.`;
483
+ ? `${clc.bold(triggerType)} function initialized (${url}).`
484
+ : `${clc.bold(triggerType)} function initialized.`;
450
485
  this.logger.logLabeled("SUCCESS", `functions[${definition.id}]`, msg);
451
486
  }
452
487
  }
@@ -489,9 +524,9 @@ class FunctionsEmulator {
489
524
  }
490
525
  }
491
526
  }
492
- addEventarcTrigger(projectId, key, eventTrigger) {
527
+ async addEventarcTrigger(projectId, key, eventTrigger) {
493
528
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
494
- return Promise.resolve(false);
529
+ return false;
495
530
  }
496
531
  const bundle = {
497
532
  eventTrigger: {
@@ -500,15 +535,16 @@ class FunctionsEmulator {
500
535
  },
501
536
  };
502
537
  logger_1.logger.debug(`addEventarcTrigger`, JSON.stringify(bundle));
503
- return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
504
- .post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle)
505
- .then(() => true)
506
- .catch((err) => {
538
+ try {
539
+ await registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC).post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle);
540
+ return true;
541
+ }
542
+ catch (err) {
507
543
  this.logger.log("WARN", "Error adding Eventarc function: " + err);
508
- return false;
509
- });
544
+ }
545
+ return false;
510
546
  }
511
- removeEventarcTrigger(projectId, key, eventTrigger) {
547
+ async removeEventarcTrigger(projectId, key, eventTrigger) {
512
548
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
513
549
  return Promise.resolve(false);
514
550
  }
@@ -519,17 +555,18 @@ class FunctionsEmulator {
519
555
  },
520
556
  };
521
557
  logger_1.logger.debug(`removeEventarcTrigger`, JSON.stringify(bundle));
522
- return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
523
- .post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle)
524
- .then(() => true)
525
- .catch((err) => {
558
+ try {
559
+ await registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC).post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle);
560
+ return true;
561
+ }
562
+ catch (err) {
526
563
  this.logger.log("WARN", "Error removing Eventarc function: " + err);
527
- return false;
528
- });
564
+ }
565
+ return false;
529
566
  }
530
- addFirealertsTrigger(projectId, key, eventTrigger) {
567
+ async addFirealertsTrigger(projectId, key, eventTrigger) {
531
568
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
532
- return Promise.resolve(false);
569
+ return false;
533
570
  }
534
571
  const bundle = {
535
572
  eventTrigger: {
@@ -538,17 +575,18 @@ class FunctionsEmulator {
538
575
  },
539
576
  };
540
577
  logger_1.logger.debug(`addFirealertsTrigger`, JSON.stringify(bundle));
541
- return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
542
- .post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle)
543
- .then(() => true)
544
- .catch((err) => {
578
+ try {
579
+ await registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC).post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle);
580
+ return true;
581
+ }
582
+ catch (err) {
545
583
  this.logger.log("WARN", "Error adding FireAlerts function: " + err);
546
- return false;
547
- });
584
+ }
585
+ return false;
548
586
  }
549
- removeFirealertsTrigger(projectId, key, eventTrigger) {
587
+ async removeFirealertsTrigger(projectId, key, eventTrigger) {
550
588
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
551
- return Promise.resolve(false);
589
+ return false;
552
590
  }
553
591
  const bundle = {
554
592
  eventTrigger: {
@@ -557,13 +595,14 @@ class FunctionsEmulator {
557
595
  },
558
596
  };
559
597
  logger_1.logger.debug(`removeFirealertsTrigger`, JSON.stringify(bundle));
560
- return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
561
- .post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle)
562
- .then(() => true)
563
- .catch((err) => {
598
+ try {
599
+ await registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC).post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle);
600
+ return true;
601
+ }
602
+ catch (err) {
564
603
  this.logger.log("WARN", "Error removing FireAlerts function: " + err);
565
- return false;
566
- });
604
+ }
605
+ return false;
567
606
  }
568
607
  async performPostLoadOperations() {
569
608
  if (!this.blockingFunctionsConfig.triggers &&
@@ -837,9 +876,14 @@ class FunctionsEmulator {
837
876
  }
838
877
  getBackendInfo() {
839
878
  const cf3Triggers = this.getCF3Triggers();
840
- return this.args.emulatableBackends.map((e) => {
879
+ const backendInfo = this.staticBackends.map((e) => {
841
880
  return (0, functionsEmulatorShared_1.toBackendInfo)(e, cf3Triggers);
842
881
  });
882
+ const dynamicInfo = this.dynamicBackends.map((e) => {
883
+ return (0, functionsEmulatorShared_1.toBackendInfo)(e, cf3Triggers, { createdBy: "SDK" });
884
+ });
885
+ backendInfo.push(...dynamicInfo);
886
+ return backendInfo;
843
887
  }
844
888
  getCF3Triggers() {
845
889
  return Object.values(this.triggers)
@@ -1094,7 +1138,7 @@ class FunctionsEmulator {
1094
1138
  async reloadTriggers() {
1095
1139
  this.triggerGeneration++;
1096
1140
  this.blockingFunctionsConfig = {};
1097
- for (const backend of this.args.emulatableBackends) {
1141
+ for (const backend of this.staticBackends.concat(this.dynamicBackends)) {
1098
1142
  await this.loadTriggers(backend);
1099
1143
  }
1100
1144
  await this.performPostLoadOperations();
@@ -308,7 +308,7 @@ function getSecretLocalPath(backend, projectDir) {
308
308
  return path.join(secretDirectory, secretsFile);
309
309
  }
310
310
  exports.getSecretLocalPath = getSecretLocalPath;
311
- function toBackendInfo(e, cf3Triggers) {
311
+ function toBackendInfo(e, cf3Triggers, labels) {
312
312
  const envWithSecrets = Object.assign({}, e.env);
313
313
  for (const s of e.secretEnv) {
314
314
  envWithSecrets[s.key] = backend.secretVersionName(s);
@@ -334,6 +334,7 @@ function toBackendInfo(e, cf3Triggers) {
334
334
  extension: e.extension,
335
335
  extensionVersion: extensionVersion,
336
336
  extensionSpec: extensionSpec,
337
+ labels,
337
338
  functionTriggers: e.predefinedTriggers ?? cf3Triggers.filter((t) => t.codebase === e.codebase),
338
339
  }));
339
340
  }
@@ -7,6 +7,7 @@ const types_1 = require("./types");
7
7
  const events_1 = require("events");
8
8
  const emulatorLogger_1 = require("./emulatorLogger");
9
9
  const error_1 = require("../error");
10
+ const discovery_1 = require("../deploy/functions/runtimes/discovery");
10
11
  var RuntimeWorkerState;
11
12
  (function (RuntimeWorkerState) {
12
13
  RuntimeWorkerState["CREATED"] = "CREATED";
@@ -196,7 +197,7 @@ class RuntimeWorker {
196
197
  const timeout = new Promise((resolve, reject) => {
197
198
  setTimeout(() => {
198
199
  reject(new error_1.FirebaseError("Failed to load function."));
199
- }, 30000);
200
+ }, (0, discovery_1.getFunctionDiscoveryTimeout)() || 30000);
200
201
  });
201
202
  while (true) {
202
203
  try {
@@ -10,6 +10,7 @@ const types_1 = require("./types");
10
10
  const hubExport_1 = require("./hubExport");
11
11
  const registry_1 = require("./registry");
12
12
  const ExpressBasedEmulator_1 = require("./ExpressBasedEmulator");
13
+ const vsCodeUtils_1 = require("../vsCodeUtils");
13
14
  const pkg = require("../../package.json");
14
15
  class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
15
16
  static readLocatorFile(projectId) {
@@ -19,7 +20,7 @@ class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
19
20
  }
20
21
  const data = fs.readFileSync(locatorPath, "utf8").toString();
21
22
  const locator = JSON.parse(data);
22
- if (locator.version !== this.CLI_VERSION) {
23
+ if (!vsCodeUtils_1.isVSCodeExtension && locator.version !== this.CLI_VERSION) {
23
24
  logger_1.logger.debug(`Found locator with mismatched version, ignoring: ${JSON.stringify(locator)}`);
24
25
  return undefined;
25
26
  }
@@ -40,6 +41,16 @@ class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
40
41
  await super.start();
41
42
  await this.writeLocatorFile();
42
43
  }
44
+ getRunningEmulatorsMapping() {
45
+ const emulators = {};
46
+ for (const info of registry_1.EmulatorRegistry.listRunningWithInfo()) {
47
+ emulators[info.name] = {
48
+ listen: this.args.listenForEmulator[info.name],
49
+ ...info,
50
+ };
51
+ }
52
+ return emulators;
53
+ }
43
54
  async createExpressApp() {
44
55
  const app = await super.createExpressApp();
45
56
  app.get("/", (req, res) => {
@@ -50,14 +61,7 @@ class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
50
61
  });
51
62
  });
52
63
  app.get(EmulatorHub.PATH_EMULATORS, (req, res) => {
53
- const body = {};
54
- for (const info of registry_1.EmulatorRegistry.listRunningWithInfo()) {
55
- body[info.name] = {
56
- listen: this.args.listenForEmulator[info.name],
57
- ...info,
58
- };
59
- }
60
- res.json(body);
64
+ res.json(this.getRunningEmulatorsMapping());
61
65
  });
62
66
  app.post(EmulatorHub.PATH_EXPORT, async (req, res) => {
63
67
  if (req.headers.origin) {
@@ -11,7 +11,7 @@ const registry_1 = require("./registry");
11
11
  const error_1 = require("../error");
12
12
  const hub_1 = require("./hub");
13
13
  const downloadableEmulators_1 = require("./downloadableEmulators");
14
- const rimraf = require("rimraf");
14
+ const node_fs_1 = require("node:fs");
15
15
  const track_1 = require("../track");
16
16
  class HubExport {
17
17
  constructor(projectId, options) {
@@ -25,7 +25,14 @@ class HubExport {
25
25
  if (!fs.existsSync(metadataPath)) {
26
26
  return undefined;
27
27
  }
28
- return JSON.parse(fs.readFileSync(metadataPath, "utf8").toString());
28
+ let mdString = "";
29
+ try {
30
+ mdString = fs.readFileSync(metadataPath, "utf8").toString();
31
+ return JSON.parse(mdString);
32
+ }
33
+ catch (err) {
34
+ throw new error_1.FirebaseError(`Unable to parse metadata file ${metadataPath}: ${mdString}`);
35
+ }
29
36
  }
30
37
  async exportAll() {
31
38
  const toExport = types_1.ALL_EMULATORS.filter(shouldExport);
@@ -74,7 +81,7 @@ class HubExport {
74
81
  const metadataPath = path.join(this.tmpDir, HubExport.METADATA_FILE_NAME);
75
82
  fs.writeFileSync(metadataPath, JSON.stringify(metadata, undefined, 2));
76
83
  logger_1.logger.debug(`hubExport: swapping ${this.tmpDir} with ${this.exportPath}`);
77
- rimraf.sync(this.exportPath);
84
+ (0, node_fs_1.rmSync)(this.exportPath, { recursive: true });
78
85
  fse.moveSync(this.tmpDir, this.exportPath);
79
86
  }
80
87
  async exportFirestore(metadata) {
@@ -7,7 +7,7 @@ const triple_beam_1 = require("triple-beam");
7
7
  const WebSocket = require("ws");
8
8
  const TransportStream = require("winston-transport");
9
9
  const logger_1 = require("../logger");
10
- const stripAnsi = require("strip-ansi");
10
+ const node_util_1 = require("node:util");
11
11
  class LoggingEmulator {
12
12
  constructor(args) {
13
13
  this.args = args;
@@ -106,7 +106,7 @@ class WebSocketTransport extends TransportStream {
106
106
  if (bundle.data && bundle.data.metadata && bundle.data.metadata.message) {
107
107
  bundle.message = bundle.data.metadata.message;
108
108
  }
109
- bundle.message = stripAnsi(bundle.message);
109
+ bundle.message = (0, node_util_1.stripVTControlCharacters)(bundle.message);
110
110
  this.history.push(bundle);
111
111
  this.connections.forEach((ws) => {
112
112
  ws.send(JSON.stringify(bundle));
@@ -11,7 +11,6 @@ const types_1 = require("./types");
11
11
  const constants_1 = require("./constants");
12
12
  const emulatorLogger_1 = require("./emulatorLogger");
13
13
  const node_child_process_1 = require("node:child_process");
14
- const dataconnectEmulator_1 = require("./dataconnectEmulator");
15
14
  const RESTRICTED_PORTS = new Set([
16
15
  1,
17
16
  7,
@@ -147,6 +146,7 @@ const EMULATOR_CAN_LISTEN_ON_PRIMARY_ONLY = {
147
146
  firestore: true,
148
147
  "firestore.websocket": true,
149
148
  pubsub: true,
149
+ "dataconnect.postgres": true,
150
150
  dataconnect: false,
151
151
  hub: false,
152
152
  ui: false,
@@ -158,6 +158,7 @@ const EMULATOR_CAN_LISTEN_ON_PRIMARY_ONLY = {
158
158
  storage: true,
159
159
  tasks: true,
160
160
  hosting: true,
161
+ apphosting: true,
161
162
  };
162
163
  const MAX_PORT = 65535;
163
164
  async function resolveHostAndAssignPorts(listenConfig) {
@@ -184,7 +185,11 @@ async function resolveHostAndAssignPorts(listenConfig) {
184
185
  lookupForHost.set(host, lookup);
185
186
  }
186
187
  const findAddrs = lookup.then(async (addrs) => {
187
- const emuLogger = emulatorLogger_1.EmulatorLogger.forEmulator(name === "firestore.websocket" ? types_1.Emulators.FIRESTORE : name);
188
+ const emuLogger = emulatorLogger_1.EmulatorLogger.forEmulator(name === "firestore.websocket"
189
+ ? types_1.Emulators.FIRESTORE
190
+ : name === "dataconnect.postgres"
191
+ ? types_1.Emulators.DATACONNECT
192
+ : name);
188
193
  if (addrs.some((addr) => addr.address === dns_1.IPV6_UNSPECIFIED.address)) {
189
194
  if (!addrs.some((addr) => addr.address === dns_1.IPV4_UNSPECIFIED.address)) {
190
195
  emuLogger.logLabeled("DEBUG", name, `testing listening on IPv4 wildcard in addition to IPv6. To listen on IPv6 only, use "::0" instead.`);
@@ -221,14 +226,6 @@ async function resolveHostAndAssignPorts(listenConfig) {
221
226
  available.push(listen);
222
227
  }
223
228
  else {
224
- if (/^dataconnect/i.exec(name)) {
225
- const alreadyRunning = await (0, dataconnectEmulator_1.checkIfDataConnectEmulatorRunningOnAddress)(listen);
226
- if (alreadyRunning) {
227
- emuLogger.logLabeled("DEBUG", "dataconnect", `Detected already running emulator on ${listen.address}:${listen.port}. Will attempt to reuse it.`);
228
- }
229
- available.push(listen);
230
- continue;
231
- }
232
229
  if (!portFixed) {
233
230
  if (i > 0) {
234
231
  emuLogger.logLabeled("DEBUG", name, `Port ${p} taken on secondary address ${addr.address}, will keep searching to find a better port.`);
@@ -280,7 +277,9 @@ exports.resolveHostAndAssignPorts = resolveHostAndAssignPorts;
280
277
  function portDescription(name) {
281
278
  return name === "firestore.websocket"
282
279
  ? `websocket server for ${types_1.Emulators.FIRESTORE}`
283
- : constants_1.Constants.description(name);
280
+ : name === "dataconnect.postgres"
281
+ ? `postgres server for ${types_1.Emulators.DATACONNECT}`
282
+ : constants_1.Constants.description(name);
284
283
  }
285
284
  function warnPartiallyAvailablePort(emuLogger, port, available, unavailable) {
286
285
  emuLogger.logLabeled("WARN", `Port ${port} is available on ` +
@@ -42,6 +42,7 @@ class EmulatorRegistry {
42
42
  extensions: 1,
43
43
  functions: 1.1,
44
44
  hosting: 2,
45
+ apphosting: 2.1,
45
46
  database: 3.0,
46
47
  firestore: 3.1,
47
48
  pubsub: 3.2,
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Persistence = void 0;
4
4
  const fs_1 = require("fs");
5
- const rimraf_1 = require("rimraf");
5
+ const promises_1 = require("node:fs/promises");
6
6
  const fs = require("fs");
7
7
  const fse = require("fs-extra");
8
8
  const path = require("path");
@@ -57,7 +57,7 @@ class Persistence {
57
57
  this._diskPathMap.delete(fileName);
58
58
  }
59
59
  async deleteAll() {
60
- await (0, rimraf_1.rimraf)(this._dirPath);
60
+ await (0, promises_1.rm)(this._dirPath, { recursive: true });
61
61
  this._diskPathMap = new Map();
62
62
  return;
63
63
  }
@@ -107,7 +107,7 @@ class StorageRulesRuntime {
107
107
  };
108
108
  });
109
109
  this._childprocess.on("error", (err) => {
110
- (0, downloadableEmulators_1.handleEmulatorProcessError)(types_2.Emulators.STORAGE, err);
110
+ void (0, downloadableEmulators_1.handleEmulatorProcessError)(types_2.Emulators.STORAGE, err);
111
111
  });
112
112
  this._childprocess.stderr?.on("data", (buf) => {
113
113
  const error = buf.toString();
@@ -115,7 +115,10 @@ class TasksEmulator {
115
115
  const locationId = req.params.location_id;
116
116
  const queueName = req.params.queue_name;
117
117
  if (!this.validateQueueId(queueName)) {
118
- res.status(400).send("Invalid Queue ID");
118
+ res.status(400).json({
119
+ error: "Queue ID must start with a letter followed by up to 62 letters, numbers, " +
120
+ "hyphens, or underscores and must end with a letter or a number",
121
+ });
119
122
  return;
120
123
  }
121
124
  const key = `queue:${projectId}-${locationId}-${queueName}`;
@@ -138,7 +141,7 @@ class TasksEmulator {
138
141
  defaultUri: body.defaultUri,
139
142
  };
140
143
  if (taskQueueConfig.rateLimits.maxConcurrentDispatches > 5000) {
141
- res.status(400).send("cannot set maxConcurrentDispatches to a value over 5000");
144
+ res.status(400).json({ error: "cannot set maxConcurrentDispatches to a value over 5000" });
142
145
  return;
143
146
  }
144
147
  this.controller.createQueue(key, taskQueueConfig);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Severity = exports.EmulatorLog = exports.FunctionsExecutionMode = exports.isEmulator = exports.isDownloadableEmulator = exports.ALL_EMULATORS = exports.EMULATORS_SUPPORTED_BY_USE_EMULATOR = exports.EMULATORS_SUPPORTED_BY_UI = exports.EMULATORS_SUPPORTED_BY_FUNCTIONS = exports.ALL_SERVICE_EMULATORS = exports.IMPORT_EXPORT_EMULATORS = exports.DOWNLOADABLE_EMULATORS = exports.Emulators = void 0;
4
+ const experiments = require("../experiments");
4
5
  var Emulators;
5
6
  (function (Emulators) {
6
7
  Emulators["AUTH"] = "auth";
@@ -9,6 +10,7 @@ var Emulators;
9
10
  Emulators["FIRESTORE"] = "firestore";
10
11
  Emulators["DATABASE"] = "database";
11
12
  Emulators["HOSTING"] = "hosting";
13
+ Emulators["APPHOSTING"] = "apphosting";
12
14
  Emulators["PUBSUB"] = "pubsub";
13
15
  Emulators["UI"] = "ui";
14
16
  Emulators["LOGGING"] = "logging";
@@ -33,6 +35,7 @@ exports.IMPORT_EXPORT_EMULATORS = [
33
35
  Emulators.STORAGE,
34
36
  ];
35
37
  exports.ALL_SERVICE_EMULATORS = [
38
+ ...(experiments.isEnabled("emulatorapphosting") ? [Emulators.APPHOSTING] : []),
36
39
  Emulators.AUTH,
37
40
  Emulators.FUNCTIONS,
38
41
  Emulators.FIRESTORE,
@@ -1,52 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EmulatorUI = void 0;
4
+ const express = require("express");
5
+ const path = require("path");
4
6
  const types_1 = require("./types");
5
7
  const downloadableEmulators = require("./downloadableEmulators");
6
8
  const registry_1 = require("./registry");
7
9
  const error_1 = require("../error");
10
+ const emulatorLogger_1 = require("./emulatorLogger");
8
11
  const constants_1 = require("./constants");
9
12
  const track_1 = require("../track");
10
13
  const ExpressBasedEmulator_1 = require("./ExpressBasedEmulator");
11
14
  const experiments_1 = require("../experiments");
12
- class EmulatorUI {
15
+ class EmulatorUI extends ExpressBasedEmulator_1.ExpressBasedEmulator {
13
16
  constructor(args) {
17
+ super({
18
+ listen: args.listen,
19
+ });
14
20
  this.args = args;
15
21
  }
16
- start() {
22
+ async start() {
23
+ await super.start();
24
+ }
25
+ async createExpressApp() {
17
26
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.HUB)) {
18
27
  throw new error_1.FirebaseError(`Cannot start ${constants_1.Constants.description(types_1.Emulators.UI)} without ${constants_1.Constants.description(types_1.Emulators.HUB)}!`);
19
28
  }
20
- const { auto_download: autoDownload, projectId } = this.args;
21
- const env = {
22
- LISTEN: JSON.stringify(ExpressBasedEmulator_1.ExpressBasedEmulator.listenOptionsFromSpecs(this.args.listen)),
23
- GCLOUD_PROJECT: projectId,
24
- [constants_1.Constants.FIREBASE_EMULATOR_HUB]: registry_1.EmulatorRegistry.url(types_1.Emulators.HUB).host,
25
- };
26
- const session = (0, track_1.emulatorSession)();
27
- if (session) {
28
- env[constants_1.Constants.FIREBASE_GA_SESSION] = JSON.stringify(session);
29
- }
29
+ const hub = registry_1.EmulatorRegistry.get(types_1.Emulators.HUB);
30
+ const app = await super.createExpressApp();
31
+ const { projectId } = this.args;
30
32
  const enabledExperiments = Object.keys(experiments_1.ALL_EXPERIMENTS).filter((experimentName) => (0, experiments_1.isEnabled)(experimentName));
31
- env[constants_1.Constants.FIREBASE_ENABLED_EXPERIMENTS] = JSON.stringify(enabledExperiments);
32
- return downloadableEmulators.start(types_1.Emulators.UI, { auto_download: autoDownload }, env);
33
+ const emulatorGaSession = (0, track_1.emulatorSession)();
34
+ await downloadableEmulators.downloadIfNecessary(types_1.Emulators.UI);
35
+ const downloadDetails = downloadableEmulators.getDownloadDetails(types_1.Emulators.UI);
36
+ const webDir = path.join(downloadDetails.unzipDir, "client");
37
+ app.get("/api/config", this.jsonHandler(() => {
38
+ const json = {
39
+ projectId,
40
+ experiments: [],
41
+ ...hub.getRunningEmulatorsMapping(),
42
+ };
43
+ if (emulatorGaSession) {
44
+ json.analytics = emulatorGaSession;
45
+ }
46
+ if (enabledExperiments) {
47
+ json.experiments = enabledExperiments;
48
+ }
49
+ return Promise.resolve(json);
50
+ }));
51
+ app.use(express.static(webDir));
52
+ app.get("*", (_, res) => {
53
+ res.sendFile(path.join(webDir, "index.html"));
54
+ });
55
+ return app;
33
56
  }
34
57
  connect() {
35
58
  return Promise.resolve();
36
59
  }
37
- stop() {
38
- return downloadableEmulators.stop(types_1.Emulators.UI);
39
- }
40
- getInfo() {
41
- return {
42
- name: this.getName(),
43
- host: this.args.listen[0].address,
44
- port: this.args.listen[0].port,
45
- pid: downloadableEmulators.getPID(types_1.Emulators.UI),
46
- };
47
- }
48
60
  getName() {
49
61
  return types_1.Emulators.UI;
50
62
  }
63
+ jsonHandler(handler) {
64
+ return (req, res) => {
65
+ handler(req).then((body) => {
66
+ res.status(200).json(body);
67
+ }, (err) => {
68
+ emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.UI).log("ERROR", err);
69
+ res.status(500).json({
70
+ message: err.message,
71
+ stack: err.stack,
72
+ raw: err,
73
+ });
74
+ });
75
+ };
76
+ }
51
77
  }
52
78
  exports.EmulatorUI = EmulatorUI;