firebase-tools 10.1.1 → 10.1.5

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 (87) hide show
  1. package/lib/accountExporter.js +9 -8
  2. package/lib/accountImporter.js +10 -8
  3. package/lib/apiv2.js +92 -48
  4. package/lib/archiveDirectory.js +63 -73
  5. package/lib/bin/firebase.js +1 -1
  6. package/lib/commands/auth-export.js +26 -25
  7. package/lib/commands/auth-import.js +88 -78
  8. package/lib/commands/ext-configure.js +1 -1
  9. package/lib/commands/ext-dev-init.js +1 -1
  10. package/lib/commands/ext-dev-publish.js +1 -1
  11. package/lib/commands/ext-dev-register.js +1 -1
  12. package/lib/commands/ext-dev-usage.js +3 -8
  13. package/lib/commands/ext-info.js +1 -1
  14. package/lib/commands/ext-install.js +1 -1
  15. package/lib/commands/ext-uninstall.js +1 -1
  16. package/lib/commands/ext-update.js +1 -1
  17. package/lib/commands/functions-config-clone.js +22 -23
  18. package/lib/commands/functions-config-get.js +22 -22
  19. package/lib/commands/functions-config-set.js +24 -22
  20. package/lib/commands/functions-config-unset.js +20 -22
  21. package/lib/commands/help.js +12 -12
  22. package/lib/commands/hosting-channel-create.js +1 -1
  23. package/lib/commands/hosting-channel-delete.js +2 -2
  24. package/lib/commands/hosting-channel-deploy.js +1 -1
  25. package/lib/commands/hosting-clone.js +1 -1
  26. package/lib/commands/login-ci.js +10 -10
  27. package/lib/commands/remoteconfig-versions-list.js +6 -1
  28. package/lib/commands/setup-emulators-database.js +8 -7
  29. package/lib/commands/setup-emulators-firestore.js +8 -7
  30. package/lib/commands/setup-emulators-pubsub.js +5 -4
  31. package/lib/commands/setup-emulators-storage.js +3 -2
  32. package/lib/commands/setup-emulators-ui.js +8 -7
  33. package/lib/commands/target-apply.js +17 -16
  34. package/lib/commands/target-clear.js +11 -10
  35. package/lib/commands/target-remove.js +10 -9
  36. package/lib/commands/target.js +20 -20
  37. package/lib/database/metadata.js +16 -24
  38. package/lib/defaultCredentials.js +3 -3
  39. package/lib/deploy/functions/backend.js +3 -1
  40. package/lib/deploy/functions/prepare.js +2 -2
  41. package/lib/deploy/functions/release/fabricator.js +4 -1
  42. package/lib/deploy/functions/runtimes/golang/index.js +2 -1
  43. package/lib/deploy/functions/validate.js +28 -1
  44. package/lib/deploy/hosting/convertConfig.js +45 -24
  45. package/lib/deploy/hosting/prepare.js +1 -1
  46. package/lib/emulator/downloadableEmulators.js +3 -2
  47. package/lib/emulator/functionsEmulator.js +9 -1
  48. package/lib/emulator/functionsEmulatorRuntime.js +4 -4
  49. package/lib/emulator/storage/apis/gcloud.js +2 -2
  50. package/lib/emulator/storage/files.js +8 -3
  51. package/lib/emulator/storage/rules/runtime.js +5 -4
  52. package/lib/extensions/askUserForConsent.js +1 -1
  53. package/lib/extensions/askUserForParam.js +1 -1
  54. package/lib/extensions/billingMigrationHelper.js +1 -1
  55. package/lib/extensions/changelog.js +1 -1
  56. package/lib/extensions/displayExtensionInfo.js +1 -1
  57. package/lib/extensions/extensionsApi.js +57 -112
  58. package/lib/extensions/extensionsHelper.js +20 -32
  59. package/lib/extensions/provisioningHelper.js +7 -10
  60. package/lib/extensions/resolveSource.js +5 -57
  61. package/lib/extensions/updateHelper.js +1 -15
  62. package/lib/extensions/utils.js +4 -2
  63. package/lib/extensions/warnings.js +1 -1
  64. package/lib/functionsConfig.js +4 -5
  65. package/lib/gcp/cloudbilling.js +8 -19
  66. package/lib/gcp/cloudfunctions.js +22 -46
  67. package/lib/gcp/cloudlogging.js +8 -11
  68. package/lib/gcp/cloudmonitoring.js +8 -5
  69. package/lib/gcp/cloudscheduler.js +7 -18
  70. package/lib/gcp/firedata.js +5 -4
  71. package/lib/gcp/firestore.js +5 -5
  72. package/lib/gcp/iam.js +18 -33
  73. package/lib/gcp/resourceManager.js +8 -13
  74. package/lib/gcp/rules.js +18 -41
  75. package/lib/gcp/runtimeconfig.js +31 -53
  76. package/lib/gcp/secretManager.js +21 -43
  77. package/lib/gcp/storage.js +25 -29
  78. package/lib/projectUtils.js +1 -1
  79. package/lib/remoteconfig/get.js +14 -8
  80. package/lib/remoteconfig/rollback.js +13 -6
  81. package/lib/remoteconfig/versionslist.js +13 -7
  82. package/npm-shrinkwrap.json +1706 -2525
  83. package/package.json +16 -11
  84. package/schema/firebase-config.json +387 -12
  85. package/templates/init/hosting/index.html +1 -1
  86. package/lib/commands/functions-config-legacy.js +0 -45
  87. package/lib/prepareFirebaseRules.js +0 -58
@@ -1,11 +1,24 @@
1
1
  "use strict";
2
- const _ = require("lodash");
3
- const { FirebaseError } = require("../../error");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertConfig = void 0;
4
+ const error_1 = require("../../error");
5
+ function has(obj, k) {
6
+ return obj[k] !== undefined;
7
+ }
4
8
  function extractPattern(type, spec) {
5
- const glob = spec.source || spec.glob;
6
- const regex = spec.regex;
9
+ let glob = "";
10
+ let regex = "";
11
+ if ("source" in spec) {
12
+ glob = spec.source;
13
+ }
14
+ if ("glob" in spec) {
15
+ glob = spec.glob;
16
+ }
17
+ if ("regex" in spec) {
18
+ regex = spec.regex;
19
+ }
7
20
  if (glob && regex) {
8
- throw new FirebaseError("Cannot specify a " + type + " pattern with both a glob and regex.");
21
+ throw new error_1.FirebaseError(`Cannot specify a ${type} pattern with both a glob and regex.`);
9
22
  }
10
23
  else if (glob) {
11
24
  return { glob: glob };
@@ -13,33 +26,38 @@ function extractPattern(type, spec) {
13
26
  else if (regex) {
14
27
  return { regex: regex };
15
28
  }
16
- throw new FirebaseError("Cannot specify a " + type + " with no pattern (either a glob or regex required).");
29
+ throw new error_1.FirebaseError(`Cannot specify a ${type} with no pattern (either a glob or regex required).`);
17
30
  }
18
- module.exports = function (config) {
31
+ function convertConfig(config) {
32
+ if (Array.isArray(config)) {
33
+ throw new error_1.FirebaseError(`convertConfig should be given a single configuration, not an array.`, {
34
+ exit: 2,
35
+ });
36
+ }
19
37
  const out = {};
20
38
  if (!config) {
21
39
  return out;
22
40
  }
23
- if (_.isArray(config.rewrites)) {
24
- out.rewrites = config.rewrites.map(function (rewrite) {
41
+ if (Array.isArray(config.rewrites)) {
42
+ out.rewrites = config.rewrites.map((rewrite) => {
25
43
  const vRewrite = extractPattern("rewrite", rewrite);
26
- if (rewrite.destination) {
44
+ if ("destination" in rewrite) {
27
45
  vRewrite.path = rewrite.destination;
28
46
  }
29
- else if (rewrite.function) {
47
+ else if ("function" in rewrite) {
30
48
  vRewrite.function = rewrite.function;
31
49
  }
32
- else if (rewrite.dynamicLinks) {
50
+ else if ("dynamicLinks" in rewrite) {
33
51
  vRewrite.dynamicLinks = rewrite.dynamicLinks;
34
52
  }
35
- else if (rewrite.run) {
53
+ else if ("run" in rewrite) {
36
54
  vRewrite.run = Object.assign({ region: "us-central1" }, rewrite.run);
37
55
  }
38
56
  return vRewrite;
39
57
  });
40
58
  }
41
- if (_.isArray(config.redirects)) {
42
- out.redirects = config.redirects.map(function (redirect) {
59
+ if (Array.isArray(config.redirects)) {
60
+ out.redirects = config.redirects.map((redirect) => {
43
61
  const vRedirect = extractPattern("redirect", redirect);
44
62
  vRedirect.location = redirect.destination;
45
63
  if (redirect.type) {
@@ -48,17 +66,19 @@ module.exports = function (config) {
48
66
  return vRedirect;
49
67
  });
50
68
  }
51
- if (_.isArray(config.headers)) {
52
- out.headers = config.headers.map(function (header) {
69
+ if (Array.isArray(config.headers)) {
70
+ out.headers = config.headers.map((header) => {
53
71
  const vHeader = extractPattern("header", header);
54
72
  vHeader.headers = {};
55
- (header.headers || []).forEach(function (h) {
56
- vHeader.headers[h.key] = h.value;
57
- });
73
+ if (Array.isArray(header.headers) && header.headers.length) {
74
+ header.headers.forEach((h) => {
75
+ vHeader.headers[h.key] = h.value;
76
+ });
77
+ }
58
78
  return vHeader;
59
79
  });
60
80
  }
61
- if (_.has(config, "cleanUrls")) {
81
+ if (has(config, "cleanUrls")) {
62
82
  out.cleanUrls = config.cleanUrls;
63
83
  }
64
84
  if (config.trailingSlash === true) {
@@ -67,11 +87,12 @@ module.exports = function (config) {
67
87
  else if (config.trailingSlash === false) {
68
88
  out.trailingSlashBehavior = "REMOVE";
69
89
  }
70
- if (_.has(config, "appAssociation")) {
90
+ if (has(config, "appAssociation")) {
71
91
  out.appAssociation = config.appAssociation;
72
92
  }
73
- if (_.has(config, "i18n")) {
93
+ if (has(config, "i18n")) {
74
94
  out.i18n = config.i18n;
75
95
  }
76
96
  return out;
77
- };
97
+ }
98
+ exports.convertConfig = convertConfig;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  const _ = require("lodash");
3
3
  const api = require("../../api");
4
- const convertConfig = require("./convertConfig");
4
+ const { convertConfig } = require("./convertConfig");
5
5
  const deploymentTool = require("../../deploymentTool");
6
6
  const { FirebaseError } = require("../../error");
7
7
  const { normalizedHostingConfigs } = require("../../hosting/normalizedHostingConfigs");
@@ -221,6 +221,7 @@ async function handleEmulatorProcessError(emulator, err) {
221
221
  exports.handleEmulatorProcessError = handleEmulatorProcessError;
222
222
  async function _runBinary(emulator, command, extraEnv) {
223
223
  return new Promise((resolve) => {
224
+ var _a, _b;
224
225
  const logger = emulatorLogger_1.EmulatorLogger.forEmulator(emulator.name);
225
226
  emulator.stdout = fs.createWriteStream(getLogFileName(emulator.name));
226
227
  try {
@@ -242,11 +243,11 @@ async function _runBinary(emulator, command, extraEnv) {
242
243
  return;
243
244
  }
244
245
  logger.logLabeled("BULLET", emulator.name, `${description} logging to ${clc.bold(getLogFileName(emulator.name))}`);
245
- emulator.instance.stdout.on("data", (data) => {
246
+ (_a = emulator.instance.stdout) === null || _a === void 0 ? void 0 : _a.on("data", (data) => {
246
247
  logger.log("DEBUG", data.toString());
247
248
  emulator.stdout.write(data);
248
249
  });
249
- emulator.instance.stderr.on("data", (data) => {
250
+ (_b = emulator.instance.stderr) === null || _b === void 0 ? void 0 : _b.on("data", (data) => {
250
251
  logger.log("DEBUG", data.toString());
251
252
  emulator.stdout.write(data);
252
253
  if (data.toString().includes("java.lang.UnsupportedClassVersionError")) {
@@ -525,7 +525,9 @@ class FunctionsEmulator {
525
525
  if (requestedMajorVersion === hostMajorVersion) {
526
526
  this.logger.logLabeled("SUCCESS", "functions", `Using node@${requestedMajorVersion} from host.`);
527
527
  }
528
- this.logger.log("WARN", `Your requested "node" version "${requestedMajorVersion}" doesn't match your global version "${hostMajorVersion}"`);
528
+ else {
529
+ this.logger.log("WARN", `Your requested "node" version "${requestedMajorVersion}" doesn't match your global version "${hostMajorVersion}". Using node@${hostMajorVersion} from host.`);
530
+ }
529
531
  return process.execPath;
530
532
  }
531
533
  getUserEnvs(backend) {
@@ -638,6 +640,12 @@ class FunctionsEmulator {
638
640
  cwd: frb.cwd,
639
641
  stdio: ["pipe", "pipe", "pipe", "ipc"],
640
642
  });
643
+ if (!childProcess.stderr) {
644
+ throw new error_1.FirebaseError(`childProcess.stderr is undefined.`);
645
+ }
646
+ if (!childProcess.stdout) {
647
+ throw new error_1.FirebaseError(`childProcess.stdout is undefined.`);
648
+ }
641
649
  const buffers = {
642
650
  stderr: { pipe: childProcess.stderr, value: "" },
643
651
  stdout: { pipe: childProcess.stdout, value: "" },
@@ -389,10 +389,10 @@ async function initializeFirebaseAdminStubs(frb) {
389
389
  return Proxied.getOriginal(target, "auth");
390
390
  })
391
391
  .finalize();
392
- require.cache[adminResolution.resolution] = {
392
+ require.cache[adminResolution.resolution] = Object.assign(require.cache[adminResolution.resolution], {
393
393
  exports: proxiedAdminModule,
394
394
  path: path.dirname(adminResolution.resolution),
395
- };
395
+ });
396
396
  logDebug("firebase-admin has been stubbed.", {
397
397
  adminResolution,
398
398
  });
@@ -456,10 +456,10 @@ async function initializeFunctionsConfigHelper(frb) {
456
456
  return proxiedConfig;
457
457
  })
458
458
  .finalize();
459
- require.cache[functionsResolution.resolution] = {
459
+ require.cache[functionsResolution.resolution] = Object.assign(require.cache[functionsResolution.resolution], {
460
460
  exports: proxiedFunctionsModule,
461
461
  path: path.dirname(functionsResolution.resolution),
462
- };
462
+ });
463
463
  logDebug("firebase-functions has been stubbed.", {
464
464
  functionsResolution,
465
465
  });
@@ -14,10 +14,10 @@ function createCloudEndpoints(emulator) {
14
14
  storageLayer.createBucket(req.params[0]);
15
15
  next();
16
16
  });
17
- gcloudStorageAPI.get("/b", (req, res) => {
17
+ gcloudStorageAPI.get("/b", async (req, res) => {
18
18
  res.json({
19
19
  kind: "storage#buckets",
20
- items: storageLayer.listBuckets(),
20
+ items: await storageLayer.listBuckets(),
21
21
  });
22
22
  });
23
23
  gcloudStorageAPI.get(["/b/:bucketId/o/:objectId", "/download/storage/v1/b/:bucketId/o/:objectId"], (req, res) => {
@@ -19,6 +19,7 @@ const fse = require("fs-extra");
19
19
  const rimraf = require("rimraf");
20
20
  const cloudFunctions_1 = require("./cloudFunctions");
21
21
  const logger_1 = require("../../logger");
22
+ const adminSdkConfig_1 = require("../adminSdkConfig");
22
23
  class StoredFile {
23
24
  constructor(metadata, path) {
24
25
  this.metadata = metadata;
@@ -108,9 +109,13 @@ class StorageLayer {
108
109
  this._buckets.set(id, new metadata_1.CloudStorageBucketMetadata(id));
109
110
  }
110
111
  }
111
- listBuckets() {
112
+ async listBuckets() {
112
113
  if (this._buckets.size == 0) {
113
- this.createBucket("default-bucket");
114
+ let adminSdkConfig = await (0, adminSdkConfig_1.getProjectAdminSdkConfigOrCached)(this._projectId);
115
+ if (!adminSdkConfig) {
116
+ adminSdkConfig = (0, adminSdkConfig_1.constructDefaultAdminSdkConfig)(this._projectId);
117
+ }
118
+ this.createBucket(adminSdkConfig.storageBucket);
114
119
  }
115
120
  return [...this._buckets.values()];
116
121
  }
@@ -355,7 +360,7 @@ class StorageLayer {
355
360
  const bucketsList = {
356
361
  buckets: [],
357
362
  };
358
- for (const b of this.listBuckets()) {
363
+ for (const b of await this.listBuckets()) {
359
364
  bucketsList.buckets.push({ id: b.id });
360
365
  }
361
366
  const bucketsFilePath = path.join(storageExportPath, "buckets.json");
@@ -62,6 +62,7 @@ class StorageRulesRuntime {
62
62
  return this._alive;
63
63
  }
64
64
  async start(auto_download = true) {
65
+ var _a, _b;
65
66
  const downloadDetails = downloadableEmulators_1.DownloadDetails[types_2.Emulators.STORAGE];
66
67
  const hasEmulator = fs.existsSync(downloadDetails.downloadPath);
67
68
  if (!hasEmulator) {
@@ -99,7 +100,7 @@ class StorageRulesRuntime {
99
100
  this._childprocess.on("error", (err) => {
100
101
  (0, downloadableEmulators_1.handleEmulatorProcessError)(types_2.Emulators.STORAGE, err);
101
102
  });
102
- this._childprocess.stderr.on("data", (buf) => {
103
+ (_a = this._childprocess.stderr) === null || _a === void 0 ? void 0 : _a.on("data", (buf) => {
103
104
  const error = buf.toString();
104
105
  if (error.includes("jarfile")) {
105
106
  throw new error_1.FirebaseError("There was an issue starting the rules emulator, please run 'firebase setup:emulators:storage` again");
@@ -108,7 +109,7 @@ class StorageRulesRuntime {
108
109
  emulatorLogger_1.EmulatorLogger.forEmulator(types_2.Emulators.STORAGE).log("WARN", `Unexpected rules runtime error: ${buf.toString()}`);
109
110
  }
110
111
  });
111
- this._childprocess.stdout.on("data", (buf) => {
112
+ (_b = this._childprocess.stdout) === null || _b === void 0 ? void 0 : _b.on("data", (buf) => {
112
113
  const serializedRuntimeActionResponse = buf.toString("UTF8").trim();
113
114
  if (serializedRuntimeActionResponse != "") {
114
115
  let rap;
@@ -148,13 +149,13 @@ class StorageRulesRuntime {
148
149
  throw new error_1.FirebaseError("Attempted to send Cloud Storage rules request with stale id");
149
150
  }
150
151
  return new Promise((resolve) => {
151
- var _a;
152
+ var _a, _b;
152
153
  this._requests[runtimeActionRequest.id] = {
153
154
  request: runtimeActionRequest,
154
155
  handler: resolve,
155
156
  };
156
157
  const serializedRequest = JSON.stringify(runtimeActionRequest);
157
- (_a = this._childprocess) === null || _a === void 0 ? void 0 : _a.stdin.write(serializedRequest + "\n");
158
+ (_b = (_a = this._childprocess) === null || _a === void 0 ? void 0 : _a.stdin) === null || _b === void 0 ? void 0 : _b.write(serializedRequest + "\n");
158
159
  });
159
160
  }
160
161
  async loadRuleset(source) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.promptForPublisherTOS = exports.displayApis = exports.displayRoles = exports.retrieveRoleInfo = exports.formatDescription = void 0;
4
4
  const _ = require("lodash");
5
5
  const clc = require("cli-color");
6
- const marked = require("marked");
6
+ const { marked } = require("marked");
7
7
  const TerminalRenderer = require("marked-terminal");
8
8
  const error_1 = require("../error");
9
9
  const extensionsHelper_1 = require("../extensions/extensionsHelper");
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ask = exports.getInquirerDefault = exports.promptCreateSecret = exports.askForParam = exports.checkResponse = void 0;
4
4
  const _ = require("lodash");
5
5
  const clc = require("cli-color");
6
- const marked = require("marked");
6
+ const { marked } = require("marked");
7
7
  const extensionsApi_1 = require("./extensionsApi");
8
8
  const secretManagerApi = require("../gcp/secretManager");
9
9
  const secretsUtils = require("./secretsUtils");
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.displayNode10CreateBillingNotice = exports.displayNode10UpdateBillingNotice = void 0;
4
- const marked = require("marked");
4
+ const { marked } = require("marked");
5
5
  const TerminalRenderer = require("marked-terminal");
6
6
  const error_1 = require("../error");
7
7
  const extensionsHelper_1 = require("./extensionsHelper");
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseChangelog = exports.getLocalChangelog = exports.breakingChangesInUpdate = exports.displayReleaseNotes = exports.getReleaseNotesForUpdate = void 0;
4
4
  const clc = require("cli-color");
5
- const marked = require("marked");
5
+ const { marked } = require("marked");
6
6
  const path = require("path");
7
7
  const semver = require("semver");
8
8
  const TerminalRenderer = require("marked-terminal");
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printSourceDownloadLink = exports.displayUpdateChangesRequiringConfirmation = exports.displayUpdateChangesNoInput = exports.displayExtInfo = void 0;
4
4
  const _ = require("lodash");
5
5
  const clc = require("cli-color");
6
- const marked = require("marked");
6
+ const { marked } = require("marked");
7
7
  const TerminalRenderer = require("marked-terminal");
8
8
  const utils = require("../utils");
9
9
  const extensionsHelper_1 = require("./extensionsHelper");