firebase-tools 10.9.2 → 11.1.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 (181) hide show
  1. package/README.md +15 -9
  2. package/lib/accountImporter.js +92 -93
  3. package/lib/api.js +77 -218
  4. package/lib/apiv2.js +5 -4
  5. package/lib/appdistribution/client.js +16 -25
  6. package/lib/auth.js +69 -47
  7. package/lib/bin/firebase.js +42 -47
  8. package/lib/checkValidTargetFilters.js +13 -12
  9. package/lib/commands/appdistribution-distribute.js +2 -1
  10. package/lib/commands/appdistribution-testers-add.js +2 -1
  11. package/lib/commands/appdistribution-testers-remove.js +2 -1
  12. package/lib/commands/apps-android-sha-create.js +2 -1
  13. package/lib/commands/apps-android-sha-delete.js +2 -1
  14. package/lib/commands/apps-android-sha-list.js +2 -1
  15. package/lib/commands/apps-create.js +2 -1
  16. package/lib/commands/apps-list.js +2 -1
  17. package/lib/commands/apps-sdkconfig.js +8 -3
  18. package/lib/commands/auth-export.js +2 -1
  19. package/lib/commands/auth-import.js +7 -10
  20. package/lib/commands/crashlytics-symbols-upload.js +2 -1
  21. package/lib/commands/database-get.js +4 -3
  22. package/lib/commands/database-instances-create.js +2 -1
  23. package/lib/commands/database-instances-list.js +3 -3
  24. package/lib/commands/database-profile.js +2 -1
  25. package/lib/commands/database-push.js +2 -1
  26. package/lib/commands/database-remove.js +2 -1
  27. package/lib/commands/database-rules-canary.js +2 -1
  28. package/lib/commands/database-rules-get.js +2 -1
  29. package/lib/commands/database-rules-list.js +2 -1
  30. package/lib/commands/database-rules-release.js +2 -1
  31. package/lib/commands/database-rules-stage.js +2 -1
  32. package/lib/commands/database-set.js +2 -1
  33. package/lib/commands/database-settings-get.js +2 -1
  34. package/lib/commands/database-settings-set.js +2 -1
  35. package/lib/commands/database-update.js +2 -1
  36. package/lib/commands/deploy.js +23 -21
  37. package/lib/commands/emulators-exec.js +2 -1
  38. package/lib/commands/emulators-export.js +2 -1
  39. package/lib/commands/emulators-start.js +2 -1
  40. package/lib/commands/experimental-functions-shell.js +10 -8
  41. package/lib/commands/ext-configure.js +56 -120
  42. package/lib/commands/ext-dev-deprecate.js +2 -1
  43. package/lib/commands/ext-dev-emulators-exec.js +13 -7
  44. package/lib/commands/ext-dev-emulators-start.js +12 -27
  45. package/lib/commands/ext-dev-extension-delete.js +2 -1
  46. package/lib/commands/ext-dev-init.js +2 -1
  47. package/lib/commands/ext-dev-list.js +2 -1
  48. package/lib/commands/ext-dev-publish.js +2 -1
  49. package/lib/commands/ext-dev-register.js +2 -1
  50. package/lib/commands/ext-dev-undeprecate.js +2 -1
  51. package/lib/commands/ext-dev-unpublish.js +2 -1
  52. package/lib/commands/ext-dev-usage.js +2 -1
  53. package/lib/commands/ext-export.js +2 -1
  54. package/lib/commands/ext-info.js +2 -1
  55. package/lib/commands/ext-install.js +14 -198
  56. package/lib/commands/ext-list.js +2 -1
  57. package/lib/commands/ext-sources-create.js +2 -1
  58. package/lib/commands/ext-uninstall.js +9 -92
  59. package/lib/commands/ext-update.js +67 -225
  60. package/lib/commands/ext.js +2 -1
  61. package/lib/commands/firestore-delete.js +2 -1
  62. package/lib/commands/firestore-indexes-list.js +2 -1
  63. package/lib/commands/functions-config-clone.js +4 -3
  64. package/lib/commands/functions-config-export.js +2 -1
  65. package/lib/commands/functions-config-get.js +2 -1
  66. package/lib/commands/functions-config-set.js +2 -1
  67. package/lib/commands/functions-config-unset.js +2 -1
  68. package/lib/commands/functions-delete.js +2 -1
  69. package/lib/commands/functions-deletegcfartifacts.js +2 -1
  70. package/lib/commands/functions-list.js +2 -1
  71. package/lib/commands/functions-log.js +2 -1
  72. package/lib/commands/functions-secrets-access.js +2 -1
  73. package/lib/commands/functions-secrets-destroy.js +2 -1
  74. package/lib/commands/functions-secrets-get.js +2 -1
  75. package/lib/commands/functions-secrets-prune.js +2 -1
  76. package/lib/commands/functions-secrets-set.js +2 -1
  77. package/lib/commands/functions-shell.js +12 -10
  78. package/lib/commands/help.js +2 -1
  79. package/lib/commands/hosting-channel-create.js +2 -1
  80. package/lib/commands/hosting-channel-delete.js +2 -1
  81. package/lib/commands/hosting-channel-deploy.js +2 -1
  82. package/lib/commands/hosting-channel-list.js +2 -1
  83. package/lib/commands/hosting-channel-open.js +2 -1
  84. package/lib/commands/hosting-clone.js +2 -1
  85. package/lib/commands/hosting-disable.js +2 -1
  86. package/lib/commands/hosting-sites-create.js +2 -1
  87. package/lib/commands/hosting-sites-delete.js +2 -1
  88. package/lib/commands/hosting-sites-get.js +2 -1
  89. package/lib/commands/hosting-sites-list.js +2 -1
  90. package/lib/commands/index.js +23 -13
  91. package/lib/commands/init.js +47 -43
  92. package/lib/commands/login-add.js +2 -1
  93. package/lib/commands/login-ci.js +2 -1
  94. package/lib/commands/login-list.js +2 -1
  95. package/lib/commands/login-use.js +2 -1
  96. package/lib/commands/login.js +2 -1
  97. package/lib/commands/logout.js +2 -1
  98. package/lib/commands/open.js +2 -1
  99. package/lib/commands/projects-addfirebase.js +2 -1
  100. package/lib/commands/projects-create.js +2 -1
  101. package/lib/commands/projects-list.js +2 -1
  102. package/lib/commands/remoteconfig-get.js +2 -1
  103. package/lib/commands/remoteconfig-rollback.js +2 -1
  104. package/lib/commands/remoteconfig-versions-list.js +2 -1
  105. package/lib/commands/serve.js +29 -27
  106. package/lib/commands/setup-emulators-database.js +2 -1
  107. package/lib/commands/setup-emulators-firestore.js +2 -1
  108. package/lib/commands/setup-emulators-pubsub.js +2 -1
  109. package/lib/commands/setup-emulators-storage.js +2 -1
  110. package/lib/commands/setup-emulators-ui.js +2 -1
  111. package/lib/commands/target-apply.js +2 -1
  112. package/lib/commands/target-clear.js +2 -1
  113. package/lib/commands/target-remove.js +2 -1
  114. package/lib/commands/target.js +2 -1
  115. package/lib/commands/use.js +54 -52
  116. package/lib/config.js +3 -3
  117. package/lib/deploy/database/deploy.js +3 -2
  118. package/lib/deploy/database/index.js +8 -5
  119. package/lib/deploy/database/prepare.js +22 -19
  120. package/lib/deploy/database/release.js +12 -9
  121. package/lib/deploy/firestore/prepare.js +2 -2
  122. package/lib/deploy/functions/build.js +32 -20
  123. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +187 -54
  124. package/lib/deploy/functions/runtimes/node/parseTriggers.js +14 -2
  125. package/lib/deploy/functions/services/database.js +14 -0
  126. package/lib/deploy/functions/services/index.js +14 -0
  127. package/lib/deploy/index.js +3 -3
  128. package/lib/deploy/lifecycleHooks.js +23 -20
  129. package/lib/deploy/remoteconfig/functions.js +18 -14
  130. package/lib/deploy/remoteconfig/prepare.js +2 -2
  131. package/lib/emulator/auth/apiSpec.js +14 -46
  132. package/lib/emulator/auth/operations.js +6 -29
  133. package/lib/emulator/auth/state.js +2 -25
  134. package/lib/emulator/commandUtils.js +1 -1
  135. package/lib/emulator/controller.js +3 -3
  136. package/lib/emulator/databaseEmulator.js +9 -7
  137. package/lib/emulator/downloadableEmulators.js +6 -6
  138. package/lib/emulator/extensionsEmulator.js +7 -3
  139. package/lib/emulator/firestoreEmulator.js +10 -12
  140. package/lib/emulator/functionsEmulator.js +39 -42
  141. package/lib/emulator/hubClient.js +11 -22
  142. package/lib/emulator/hubExport.js +26 -16
  143. package/lib/emulator/portUtils.js +2 -0
  144. package/lib/emulator/storage/crc.js +3 -0
  145. package/lib/emulator/storage/rules/runtime.js +1 -1
  146. package/lib/errorOut.js +2 -2
  147. package/lib/extensions/extensionsHelper.js +4 -5
  148. package/lib/extensions/manifest.js +5 -11
  149. package/lib/firebaseConfigValidate.js +1 -1
  150. package/lib/firestore/checkDatabaseType.js +4 -5
  151. package/lib/firestore/indexes.js +17 -34
  152. package/lib/functions/events/v2.js +7 -1
  153. package/lib/functionsConfigClone.js +43 -41
  154. package/lib/gcp/cloudfunctionsv2.js +17 -2
  155. package/lib/gcp/iam.js +1 -1
  156. package/lib/gcp/index.js +10 -10
  157. package/lib/gcp/runtimeconfig.js +45 -47
  158. package/lib/gcp/storage.js +2 -4
  159. package/lib/hosting/cloudRunProxy.js +19 -15
  160. package/lib/index.js +29 -28
  161. package/lib/init/features/database.js +11 -5
  162. package/lib/init/features/functions/index.js +1 -1
  163. package/lib/init/features/functions/javascript.js +23 -20
  164. package/lib/init/features/functions/npm-dependencies.js +17 -14
  165. package/lib/init/features/functions/typescript.js +27 -24
  166. package/lib/init/features/hosting/github.js +5 -4
  167. package/lib/loadCJSON.js +9 -6
  168. package/lib/logError.js +15 -12
  169. package/lib/management/apps.js +47 -43
  170. package/lib/management/database.js +33 -31
  171. package/lib/management/projects.js +13 -7
  172. package/lib/parseBoltRules.js +15 -14
  173. package/lib/profileReport.js +503 -511
  174. package/lib/profiler.js +4 -4
  175. package/lib/requireAuth.js +0 -1
  176. package/lib/responseToError.js +8 -5
  177. package/lib/rtdb.js +31 -29
  178. package/lib/scopes.js +9 -9
  179. package/npm-shrinkwrap.json +1485 -670
  180. package/package.json +21 -22
  181. package/standalone/package.json +1 -1
@@ -11,14 +11,12 @@ const jwt = require("jsonwebtoken");
11
11
  const cors = require("cors");
12
12
  const url_1 = require("url");
13
13
  const events_1 = require("events");
14
- const api = require("../api");
15
14
  const logger_1 = require("../logger");
16
15
  const track_1 = require("../track");
17
16
  const constants_1 = require("./constants");
18
17
  const types_1 = require("./types");
19
18
  const chokidar = require("chokidar");
20
19
  const spawn = require("cross-spawn");
21
- const child_process_1 = require("child_process");
22
20
  const functionsEmulatorShared_1 = require("./functionsEmulatorShared");
23
21
  const registry_1 = require("./registry");
24
22
  const emulatorLogger_1 = require("./emulatorLogger");
@@ -35,6 +33,7 @@ const runtimes = require("../deploy/functions/runtimes");
35
33
  const backend = require("../deploy/functions/backend");
36
34
  const functionsEnv = require("../functions/env");
37
35
  const v1_1 = require("../functions/events/v1");
36
+ const apiv2_1 = require("../apiv2");
38
37
  const EVENT_INVOKE = "functions:invoke";
39
38
  const DATABASE_PATH_PATTERN = new RegExp("^projects/[^/]+/instances/([^/]+)/refs(/.*)$");
40
39
  class FunctionsEmulator {
@@ -383,15 +382,12 @@ class FunctionsEmulator {
383
382
  }
384
383
  const path = `/identitytoolkit.googleapis.com/v2/projects/${this.getProjectId()}/config?updateMask=blockingFunctions`;
385
384
  try {
386
- await api.request("PATCH", path, {
387
- origin: `http://${registry_1.EmulatorRegistry.getInfoHostString(authEmu.getInfo())}`,
388
- headers: {
389
- Authorization: "Bearer owner",
390
- },
391
- data: {
392
- blockingFunctions: this.blockingFunctionsConfig,
393
- },
394
- json: true,
385
+ const client = new apiv2_1.Client({
386
+ urlPrefix: `http://${registry_1.EmulatorRegistry.getInfoHostString(authEmu.getInfo())}`,
387
+ auth: false,
388
+ });
389
+ await client.patch(path, { blockingFunctions: this.blockingFunctionsConfig }, {
390
+ headers: { Authorization: "Bearer owner" },
395
391
  });
396
392
  }
397
393
  catch (err) {
@@ -399,15 +395,15 @@ class FunctionsEmulator {
399
395
  throw err;
400
396
  }
401
397
  }
402
- addRealtimeDatabaseTrigger(projectId, key, eventTrigger) {
398
+ async addRealtimeDatabaseTrigger(projectId, key, eventTrigger) {
403
399
  const databaseEmu = registry_1.EmulatorRegistry.get(types_1.Emulators.DATABASE);
404
400
  if (!databaseEmu) {
405
- return Promise.resolve(false);
401
+ return false;
406
402
  }
407
403
  const result = DATABASE_PATH_PATTERN.exec(eventTrigger.resource);
408
404
  if (result === null || result.length !== 3) {
409
405
  this.logger.log("WARN", `Event function "${key}" has malformed "resource" member. ` + `${eventTrigger.resource}`);
410
- return Promise.reject();
406
+ throw new error_1.FirebaseError(`Event function ${key} has malformed resource member`);
411
407
  }
412
408
  const instance = result[1];
413
409
  const bundle = JSON.stringify({
@@ -424,24 +420,20 @@ class FunctionsEmulator {
424
420
  else {
425
421
  this.logger.log("WARN", `No project in use. Registering function for sentinel namespace '${constants_1.Constants.DEFAULT_DATABASE_EMULATOR_NAMESPACE}'`);
426
422
  }
427
- return api
428
- .request("POST", setTriggersPath, {
429
- origin: `http://${registry_1.EmulatorRegistry.getInfoHostString(databaseEmu.getInfo())}`,
430
- headers: {
431
- Authorization: "Bearer owner",
432
- },
433
- data: bundle,
434
- json: false,
435
- })
436
- .then(() => {
437
- return true;
438
- })
439
- .catch((err) => {
423
+ const client = new apiv2_1.Client({
424
+ urlPrefix: `http://${registry_1.EmulatorRegistry.getInfoHostString(databaseEmu.getInfo())}`,
425
+ auth: false,
426
+ });
427
+ try {
428
+ await client.post(setTriggersPath, bundle, { headers: { Authorization: "Bearer owner" } });
429
+ }
430
+ catch (err) {
440
431
  this.logger.log("WARN", "Error adding Realtime Database function: " + err);
441
432
  throw err;
442
- });
433
+ }
434
+ return true;
443
435
  }
444
- addFirestoreTrigger(projectId, key, eventTrigger) {
436
+ async addFirestoreTrigger(projectId, key, eventTrigger) {
445
437
  const firestoreEmu = registry_1.EmulatorRegistry.get(types_1.Emulators.FIRESTORE);
446
438
  if (!firestoreEmu) {
447
439
  return Promise.resolve(false);
@@ -450,19 +442,18 @@ class FunctionsEmulator {
450
442
  eventTrigger: Object.assign(Object.assign({}, eventTrigger), { service: "firestore.googleapis.com" }),
451
443
  });
452
444
  logger_1.logger.debug(`addFirestoreTrigger`, JSON.stringify(bundle));
453
- return api
454
- .request("PUT", `/emulator/v1/projects/${projectId}/triggers/${key}`, {
455
- origin: `http://${registry_1.EmulatorRegistry.getInfoHostString(firestoreEmu.getInfo())}`,
456
- data: bundle,
457
- json: false,
458
- })
459
- .then(() => {
460
- return true;
461
- })
462
- .catch((err) => {
445
+ const client = new apiv2_1.Client({
446
+ urlPrefix: `http://${registry_1.EmulatorRegistry.getInfoHostString(firestoreEmu.getInfo())}`,
447
+ auth: false,
448
+ });
449
+ try {
450
+ await client.put(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle);
451
+ }
452
+ catch (err) {
463
453
  this.logger.log("WARN", "Error adding firestore function: " + err);
464
454
  throw err;
465
- });
455
+ }
456
+ return true;
466
457
  }
467
458
  async addPubsubTrigger(triggerName, key, eventTrigger, signatureType, schedule) {
468
459
  const pubsubEmulator = registry_1.EmulatorRegistry.get(types_1.Emulators.PUBSUB);
@@ -605,7 +596,7 @@ class FunctionsEmulator {
605
596
  let localMajorVersion = "0";
606
597
  const localNodePath = path.join(backend.functionsDir, "node_modules/.bin/node");
607
598
  try {
608
- const localNodeOutput = (0, child_process_1.spawnSync)(localNodePath, ["--version"]).stdout.toString();
599
+ const localNodeOutput = spawn.sync(localNodePath, ["--version"]).stdout.toString();
609
600
  localMajorVersion = localNodeOutput.slice(1).split(".")[0];
610
601
  }
611
602
  catch (err) {
@@ -618,7 +609,13 @@ class FunctionsEmulator {
618
609
  this.logger.logLabeled("SUCCESS", "functions", `Using node@${requestedMajorVersion} from host.`);
619
610
  }
620
611
  else {
621
- this.logger.log("WARN", `Your requested "node" version "${requestedMajorVersion}" doesn't match your global version "${hostMajorVersion}". Using node@${hostMajorVersion} from host.`);
612
+ if (process.env.FIREPIT_VERSION) {
613
+ this.logger.log("WARN", `You've requested "node" version "${requestedMajorVersion}", but the standalone Firebase CLI comes with bundled Node "${hostMajorVersion}".`);
614
+ this.logger.log("INFO", `To use a different Node.js version, consider removing the standalone Firebase CLI and switching to "firebase-tools" on npm.`);
615
+ }
616
+ else {
617
+ this.logger.log("WARN", `Your requested "node" version "${requestedMajorVersion}" doesn't match your global version "${hostMajorVersion}". Using node@${hostMajorVersion} from host.`);
618
+ }
622
619
  }
623
620
  return process.execPath;
624
621
  }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EmulatorHubClient = void 0;
4
- const api = require("../api");
5
4
  const hub_1 = require("./hub");
6
5
  const error_1 = require("../error");
6
+ const apiv2_1 = require("../apiv2");
7
7
  class EmulatorHubClient {
8
8
  constructor(projectId) {
9
9
  this.projectId = projectId;
@@ -12,29 +12,18 @@ class EmulatorHubClient {
12
12
  foundHub() {
13
13
  return this.locator !== undefined;
14
14
  }
15
- getStatus() {
16
- return api.request("GET", "/", {
17
- origin: this.origin,
18
- });
15
+ async getStatus() {
16
+ const apiClient = new apiv2_1.Client({ urlPrefix: this.origin, auth: false });
17
+ await apiClient.get("/");
19
18
  }
20
- getEmulators() {
21
- return api
22
- .request("GET", hub_1.EmulatorHub.PATH_EMULATORS, {
23
- origin: this.origin,
24
- json: true,
25
- })
26
- .then((res) => {
27
- return res.body;
28
- });
19
+ async getEmulators() {
20
+ const apiClient = new apiv2_1.Client({ urlPrefix: this.origin, auth: false });
21
+ const res = await apiClient.get(hub_1.EmulatorHub.PATH_EMULATORS);
22
+ return res.body;
29
23
  }
30
- postExport(path) {
31
- return api.request("POST", hub_1.EmulatorHub.PATH_EXPORT, {
32
- origin: this.origin,
33
- json: true,
34
- data: {
35
- path,
36
- },
37
- });
24
+ async postExport(path) {
25
+ const apiClient = new apiv2_1.Client({ urlPrefix: this.origin, auth: false });
26
+ await apiClient.post(hub_1.EmulatorHub.PATH_EXPORT, { path });
38
27
  }
39
28
  get origin() {
40
29
  const locator = this.assertLocator();
@@ -5,7 +5,6 @@ const path = require("path");
5
5
  const fs = require("fs");
6
6
  const fse = require("fs-extra");
7
7
  const http = require("http");
8
- const api = require("../api");
9
8
  const logger_1 = require("../logger");
10
9
  const types_1 = require("./types");
11
10
  const registry_1 = require("./registry");
@@ -13,6 +12,7 @@ const error_1 = require("../error");
13
12
  const hub_1 = require("./hub");
14
13
  const downloadableEmulators_1 = require("./downloadableEmulators");
15
14
  const rimraf = require("rimraf");
15
+ const apiv2_1 = require("../apiv2");
16
16
  class HubExport {
17
17
  constructor(projectId, exportPath) {
18
18
  this.projectId = projectId;
@@ -80,24 +80,27 @@ class HubExport {
80
80
  export_directory: this.tmpDir,
81
81
  export_name: metadata.firestore.path,
82
82
  };
83
- return api.request("POST", `/emulator/v1/projects/${this.projectId}:export`, {
84
- origin: firestoreHost,
85
- json: true,
86
- data: firestoreExportBody,
87
- });
83
+ const client = new apiv2_1.Client({ urlPrefix: firestoreHost, auth: false });
84
+ await client.post(`/emulator/v1/projects/${this.projectId}:export`, firestoreExportBody);
88
85
  }
89
86
  async exportDatabase(metadata) {
90
87
  const databaseEmulator = registry_1.EmulatorRegistry.get(types_1.Emulators.DATABASE);
91
88
  const databaseAddr = `http://${registry_1.EmulatorRegistry.getInfoHostString(databaseEmulator.getInfo())}`;
92
- const inspectURL = `/.inspect/databases.json?ns=${this.projectId}`;
93
- const inspectRes = await api.request("GET", inspectURL, { origin: databaseAddr, auth: true });
89
+ const client = new apiv2_1.Client({ urlPrefix: databaseAddr, auth: true });
90
+ const inspectURL = `/.inspect/databases.json`;
91
+ const inspectRes = await client.get(inspectURL, {
92
+ queryParams: { ns: this.projectId },
93
+ });
94
94
  const namespaces = inspectRes.body.map((instance) => instance.name);
95
95
  const namespacesToExport = [];
96
96
  for (const ns of namespaces) {
97
- const checkDataPath = `/.json?ns=${ns}&shallow=true&limitToFirst=1`;
98
- const checkDataRes = await api.request("GET", checkDataPath, {
99
- origin: databaseAddr,
100
- auth: true,
97
+ const checkDataPath = `/.json`;
98
+ const checkDataRes = await client.get(checkDataPath, {
99
+ queryParams: {
100
+ ns,
101
+ shallow: "true",
102
+ limitToFirst: 1,
103
+ },
101
104
  });
102
105
  if (checkDataRes.body !== null) {
103
106
  namespacesToExport.push(ns);
@@ -162,11 +165,18 @@ class HubExport {
162
165
  const storageExportBody = {
163
166
  path: storageExportPath,
164
167
  };
165
- return api.request("POST", "/internal/export", {
166
- origin: storageHost,
167
- json: true,
168
- data: storageExportBody,
168
+ const client = new apiv2_1.Client({ urlPrefix: storageHost, auth: false });
169
+ const res = await client.request({
170
+ method: "POST",
171
+ path: "/internal/export",
172
+ headers: { "Content-Type": "application/json" },
173
+ body: storageExportBody,
174
+ responseType: "stream",
175
+ resolveOnHTTPError: true,
169
176
  });
177
+ if (res.status >= 400) {
178
+ throw new error_1.FirebaseError(`Failed to export storage: ${await res.response.text()}`);
179
+ }
170
180
  }
171
181
  }
172
182
  exports.HubExport = HubExport;
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.waitForPortClosed = exports.checkPortOpen = exports.findAvailablePort = exports.suggestUnrestricted = exports.isRestricted = void 0;
4
4
  const pf = require("portfinder");
5
5
  const tcpport = require("tcp-port-used");
6
+ const dns = require("dns");
6
7
  const error_1 = require("../error");
7
8
  const logger_1 = require("../logger");
9
+ dns.setDefaultResultOrder("ipv4first");
8
10
  const RESTRICTED_PORTS = [
9
11
  1,
10
12
  7,
@@ -25,6 +25,9 @@ function crc32c(bytes) {
25
25
  }
26
26
  exports.crc32c = crc32c;
27
27
  function crc32cToString(crc32cValue) {
28
+ if (typeof crc32cValue === "string") {
29
+ crc32cValue = Number(crc32cValue);
30
+ }
28
31
  return "----" + Buffer.from([crc32cValue]).toString("base64");
29
32
  }
30
33
  exports.crc32cToString = crc32cToString;
@@ -115,7 +115,7 @@ class StorageRulesRuntime {
115
115
  }
116
116
  });
117
117
  (_b = this._childprocess.stdout) === null || _b === void 0 ? void 0 : _b.on("data", (buf) => {
118
- const serializedRuntimeActionResponse = buf.toString("UTF8").trim();
118
+ const serializedRuntimeActionResponse = buf.toString("utf-8").trim();
119
119
  if (serializedRuntimeActionResponse !== "") {
120
120
  let rap;
121
121
  try {
package/lib/errorOut.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.errorOut = void 0;
4
- const logError = require("./logError");
4
+ const logError_1 = require("./logError");
5
5
  const error_1 = require("./error");
6
6
  function errorOut(error) {
7
7
  let fbError;
@@ -14,7 +14,7 @@ function errorOut(error) {
14
14
  exit: 2,
15
15
  });
16
16
  }
17
- logError(fbError);
17
+ (0, logError_1.logError)(fbError);
18
18
  process.exitCode = fbError.exit || 2;
19
19
  setTimeout(() => {
20
20
  process.exit();
@@ -31,6 +31,7 @@ const utils_2 = require("../utils");
31
31
  const changelog_1 = require("./changelog");
32
32
  const getProjectNumber_1 = require("../getProjectNumber");
33
33
  const constants_1 = require("../emulator/constants");
34
+ const planner_1 = require("../deploy/extensions/planner");
34
35
  var SpecParamType;
35
36
  (function (SpecParamType) {
36
37
  SpecParamType["SELECT"] = "select";
@@ -529,15 +530,13 @@ async function diagnoseAndFixProject(options) {
529
530
  }
530
531
  }
531
532
  exports.diagnoseAndFixProject = diagnoseAndFixProject;
532
- function canonicalizeRefInput(extensionName) {
533
+ async function canonicalizeRefInput(extensionName) {
533
534
  if (extensionName.split("/").length < 2) {
534
535
  const [extensionID, version] = extensionName.split("@");
535
536
  extensionName = `firebase/${extensionID}@${version || "latest"}`;
536
537
  }
537
538
  const ref = refs.parse(extensionName);
538
- if (!ref.version) {
539
- extensionName = `${extensionName}@latest`;
540
- }
541
- return extensionName;
539
+ ref.version = await (0, planner_1.resolveVersion)(ref);
540
+ return refs.toExtensionVersionRef(ref);
542
541
  }
543
542
  exports.canonicalizeRefInput = canonicalizeRefInput;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.showPreviewWarning = exports.showDeprecationWarning = exports.readInstanceParam = exports.getInstanceRef = exports.getInstanceTarget = exports.instanceExists = exports.loadConfig = exports.removeFromManifest = exports.writeLocalSecrets = exports.writeToManifest = exports.ENV_DIRECTORY = void 0;
3
+ exports.showPostDeprecationNotice = exports.readInstanceParam = exports.getInstanceRef = exports.getInstanceTarget = exports.instanceExists = exports.loadConfig = exports.removeFromManifest = exports.writeLocalSecrets = exports.writeToManifest = exports.ENV_DIRECTORY = void 0;
4
4
  const clc = require("cli-color");
5
5
  const path = require("path");
6
6
  const refs = require("./refs");
@@ -181,16 +181,10 @@ function readParamsFile(projectDir, fileName) {
181
181
  const params = (0, paramHelper_1.readEnvFile)(paramPath);
182
182
  return params;
183
183
  }
184
- function showDeprecationWarning() {
185
- utils.logLabeledWarning(extensionsHelper_1.logPrefix, "The behavior of ext:install, ext:update, ext:configure, and ext:uninstall will change in firebase-tools@11.0.0. " +
184
+ function showPostDeprecationNotice() {
185
+ utils.logLabeledBullet(extensionsHelper_1.logPrefix, "The behavior of ext:install, ext:update, ext:configure, and ext:uninstall has changed in firebase-tools@11.0.0. " +
186
186
  "Instead of deploying extensions directly, " +
187
187
  "changes to extension instances will be written to firebase.json and ./extensions/*.env. " +
188
- `Then ${clc.bold("firebase deploy (--only extensions)")} will deploy the changes to your Firebase project. ` +
189
- `To access this behavior now, pass the ${clc.bold("--local")} flag.`);
188
+ `Then ${clc.bold("firebase deploy (--only extensions)")} will deploy the changes to your Firebase project. See https://firebase.google.com/docs/extensions/manifest for more details.`);
190
189
  }
191
- exports.showDeprecationWarning = showDeprecationWarning;
192
- function showPreviewWarning() {
193
- utils.logLabeledWarning(extensionsHelper_1.logPrefix, `See these changes in your Firebase Emulator by running "firebase emulators:start". ` +
194
- `Run ${clc.bold("firebase deploy (--only extensions)")} to deploy the changes to your Firebase project. `);
195
- }
196
- exports.showPreviewWarning = showPreviewWarning;
190
+ exports.showPostDeprecationNotice = showPostDeprecationNotice;
@@ -8,7 +8,7 @@ const ajv = new Ajv();
8
8
  let _VALIDATOR = undefined;
9
9
  function getValidator() {
10
10
  if (!_VALIDATOR) {
11
- const schemaStr = fs.readFileSync(path.resolve(__dirname, "../schema/firebase-config.json"), "UTF-8");
11
+ const schemaStr = fs.readFileSync(path.resolve(__dirname, "../schema/firebase-config.json"), "utf-8");
12
12
  const schema = JSON.parse(schemaStr);
13
13
  _VALIDATOR = ajv.compile(schema);
14
14
  }
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkDatabaseType = void 0;
4
- const api = require("../api");
4
+ const api_1 = require("../api");
5
+ const apiv2_1 = require("../apiv2");
5
6
  const logger_1 = require("../logger");
6
7
  async function checkDatabaseType(projectId) {
7
8
  try {
8
- const resp = await api.request("GET", "/v1/apps/" + projectId, {
9
- auth: true,
10
- origin: api.appengineOrigin,
11
- });
9
+ const client = new apiv2_1.Client({ urlPrefix: api_1.appengineOrigin, apiVersion: "v1" });
10
+ const resp = await client.get(`/apps/${projectId}`);
12
11
  return resp.body.databaseType;
13
12
  }
14
13
  catch (err) {
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FirestoreIndexes = void 0;
4
4
  const clc = require("cli-color");
5
- const api = require("../api");
6
5
  const logger_1 = require("../logger");
7
6
  const utils = require("../utils");
8
7
  const validator = require("./validator");
@@ -10,7 +9,12 @@ const API = require("./indexes-api");
10
9
  const sort = require("./indexes-sort");
11
10
  const util = require("./util");
12
11
  const prompt_1 = require("../prompt");
12
+ const api_1 = require("../api");
13
+ const apiv2_1 = require("../apiv2");
13
14
  class FirestoreIndexes {
15
+ constructor() {
16
+ this.apiClient = new apiv2_1.Client({ urlPrefix: api_1.firestoreOrigin, apiVersion: "v1" });
17
+ }
14
18
  async deploy(options, indexes, fieldOverrides) {
15
19
  const spec = this.upgradeOldSpec({
16
20
  indexes,
@@ -112,11 +116,8 @@ class FirestoreIndexes {
112
116
  }
113
117
  }
114
118
  async listIndexes(project) {
115
- const url = `projects/${project}/databases/(default)/collectionGroups/-/indexes`;
116
- const res = await api.request("GET", `/v1/${url}`, {
117
- auth: true,
118
- origin: api.firestoreOrigin,
119
- });
119
+ const url = `/projects/${project}/databases/(default)/collectionGroups/-/indexes`;
120
+ const res = await this.apiClient.get(url);
120
121
  const indexes = res.body.indexes;
121
122
  if (!indexes) {
122
123
  return [];
@@ -135,11 +136,8 @@ class FirestoreIndexes {
135
136
  }
136
137
  async listFieldOverrides(project) {
137
138
  const parent = `projects/${project}/databases/(default)/collectionGroups/-`;
138
- const url = `${parent}/fields?filter=indexConfig.usesAncestorConfig=false`;
139
- const res = await api.request("GET", `/v1/${url}`, {
140
- auth: true,
141
- origin: api.firestoreOrigin,
142
- });
139
+ const url = `/${parent}/fields?filter=indexConfig.usesAncestorConfig=false`;
140
+ const res = await this.apiClient.get(url);
143
141
  const fields = res.body.fields;
144
142
  if (!fields) {
145
143
  return [];
@@ -248,7 +246,7 @@ class FirestoreIndexes {
248
246
  });
249
247
  }
250
248
  async patchField(project, spec) {
251
- const url = `projects/${project}/databases/(default)/collectionGroups/${spec.collectionGroup}/fields/${spec.fieldPath}`;
249
+ const url = `/projects/${project}/databases/(default)/collectionGroups/${spec.collectionGroup}/fields/${spec.fieldPath}`;
252
250
  const indexes = spec.indexes.map((index) => {
253
251
  return {
254
252
  queryScope: index.queryScope,
@@ -266,38 +264,23 @@ class FirestoreIndexes {
266
264
  indexes,
267
265
  },
268
266
  };
269
- await api.request("PATCH", `/v1/${url}`, {
270
- auth: true,
271
- origin: api.firestoreOrigin,
272
- data,
273
- });
267
+ await this.apiClient.patch(url, data);
274
268
  }
275
269
  deleteField(field) {
276
270
  const url = field.name;
277
271
  const data = {};
278
- return api.request("PATCH", "/v1/" + url + "?updateMask=indexConfig", {
279
- auth: true,
280
- origin: api.firestoreOrigin,
281
- data,
282
- });
272
+ return this.apiClient.patch(`/${url}`, data, { queryParams: { updateMask: "indexConfig" } });
283
273
  }
284
274
  createIndex(project, index) {
285
- const url = `projects/${project}/databases/(default)/collectionGroups/${index.collectionGroup}/indexes`;
286
- return api.request("POST", "/v1/" + url, {
287
- auth: true,
288
- data: {
289
- fields: index.fields,
290
- queryScope: index.queryScope,
291
- },
292
- origin: api.firestoreOrigin,
275
+ const url = `/projects/${project}/databases/(default)/collectionGroups/${index.collectionGroup}/indexes`;
276
+ return this.apiClient.post(url, {
277
+ fields: index.fields,
278
+ queryScope: index.queryScope,
293
279
  });
294
280
  }
295
281
  deleteIndex(index) {
296
282
  const url = index.name;
297
- return api.request("DELETE", "/v1/" + url, {
298
- auth: true,
299
- origin: api.firestoreOrigin,
300
- });
283
+ return this.apiClient.delete(`/${url}`);
301
284
  }
302
285
  indexMatchesSpec(index, spec) {
303
286
  const collection = util.parseIndexName(index.name).collectionGroupId;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FIREBASE_ALERTS_PUBLISH_EVENT = exports.STORAGE_EVENTS = exports.PUBSUB_PUBLISH_EVENT = void 0;
3
+ exports.DATABASE_EVENTS = exports.FIREBASE_ALERTS_PUBLISH_EVENT = exports.STORAGE_EVENTS = exports.PUBSUB_PUBLISH_EVENT = void 0;
4
4
  exports.PUBSUB_PUBLISH_EVENT = "google.cloud.pubsub.topic.v1.messagePublished";
5
5
  exports.STORAGE_EVENTS = [
6
6
  "google.cloud.storage.object.v1.finalized",
@@ -9,3 +9,9 @@ exports.STORAGE_EVENTS = [
9
9
  "google.cloud.storage.object.v1.metadataUpdated",
10
10
  ];
11
11
  exports.FIREBASE_ALERTS_PUBLISH_EVENT = "google.firebase.firebasealerts.alerts.v1.published";
12
+ exports.DATABASE_EVENTS = [
13
+ "google.firebase.database.ref.v1.written",
14
+ "google.firebase.database.ref.v1.created",
15
+ "google.firebase.database.ref.v1.updated",
16
+ "google.firebase.database.ref.v1.deleted",
17
+ ];