firebase-tools-with-isolate 13.11.2 → 13.15.0-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 (110) hide show
  1. package/lib/api.js +4 -2
  2. package/lib/apphosting/githubConnections.js +125 -37
  3. package/lib/apphosting/index.js +3 -8
  4. package/lib/auth.js +14 -15
  5. package/lib/bin/firebase.js +7 -5
  6. package/lib/commands/dataconnect-sdk-generate.js +5 -9
  7. package/lib/commands/dataconnect-services-list.js +1 -1
  8. package/lib/commands/deploy.js +7 -1
  9. package/lib/commands/ext-configure.js +1 -6
  10. package/lib/commands/ext-dev-init.js +27 -30
  11. package/lib/commands/ext-dev-upload.js +4 -6
  12. package/lib/commands/ext-info.js +3 -5
  13. package/lib/commands/ext-install.js +0 -5
  14. package/lib/commands/ext-uninstall.js +0 -5
  15. package/lib/commands/ext-update.js +0 -5
  16. package/lib/commands/firestore-backups-schedules-create.js +11 -14
  17. package/lib/commands/firestore-backups-schedules-list.js +1 -1
  18. package/lib/commands/firestore-backups-schedules-update.js +4 -3
  19. package/lib/commands/firestore-databases-create.js +24 -7
  20. package/lib/commands/firestore-databases-restore.js +4 -4
  21. package/lib/commands/firestore-databases-update.js +5 -6
  22. package/lib/commands/functions-secrets-set.js +9 -6
  23. package/lib/commands/help.js +2 -0
  24. package/lib/commands/hosting-channel-create.js +1 -1
  25. package/lib/commands/hosting-channel-delete.js +1 -1
  26. package/lib/commands/hosting-channel-deploy.js +1 -1
  27. package/lib/commands/hosting-clone.js +1 -2
  28. package/lib/commands/index.js +9 -11
  29. package/lib/commands/init.js +16 -12
  30. package/lib/commands/login.js +1 -2
  31. package/lib/commands/setup-emulators-dataconnect.js +22 -3
  32. package/lib/config.js +5 -0
  33. package/lib/crashlytics/buildToolsJarHelper.js +1 -1
  34. package/lib/dataconnect/client.js +55 -8
  35. package/lib/dataconnect/fileUtils.js +30 -7
  36. package/lib/dataconnect/filters.js +12 -1
  37. package/lib/dataconnect/load.js +9 -7
  38. package/lib/dataconnect/schemaMigration.js +21 -0
  39. package/lib/dataconnect/types.js +8 -1
  40. package/lib/deploy/dataconnect/prepare.js +16 -2
  41. package/lib/deploy/functions/build.js +10 -1
  42. package/lib/emulator/adminSdkConfig.test.js +16 -0
  43. package/lib/emulator/constants.js +1 -0
  44. package/lib/emulator/controller.js +3 -9
  45. package/lib/emulator/dataconnectEmulator.js +122 -18
  46. package/lib/emulator/downloadableEmulators.js +21 -22
  47. package/lib/emulator/eventarcEmulator.js +68 -18
  48. package/lib/emulator/functionsEmulator.js +89 -0
  49. package/lib/emulator/functionsEmulatorShared.js +4 -0
  50. package/lib/emulator/hub.js +1 -1
  51. package/lib/emulator/portUtils.js +9 -0
  52. package/lib/emulator/pubsubEmulator.js +1 -1
  53. package/lib/emulator/registry.js +1 -1
  54. package/lib/emulator/storage/apis/shared.js +2 -1
  55. package/lib/emulator/storage/persistence.js +5 -13
  56. package/lib/emulator/storage/rfc.js +9 -0
  57. package/lib/emulator/storage/rules/config.js +4 -2
  58. package/lib/experiments.js +8 -3
  59. package/lib/extensions/askUserForParam.js +1 -1
  60. package/lib/extensions/change-log.js +2 -4
  61. package/lib/extensions/displayExtensionInfo.js +0 -5
  62. package/lib/extensions/extensionsHelper.js +5 -7
  63. package/lib/extensions/provisioningHelper.js +1 -1
  64. package/lib/extensions/updateHelper.js +1 -2
  65. package/lib/extensions/warnings.js +2 -7
  66. package/lib/firestore/api-sort.test.js +74 -0
  67. package/lib/firestore/api.js +8 -7
  68. package/lib/firestore/backupUtils.test.js +18 -0
  69. package/lib/firestore/pretty-print.js +21 -1
  70. package/lib/firestore/pretty-print.test.js +61 -0
  71. package/lib/firestore/util.test.js +42 -0
  72. package/lib/frameworks/angular/utils.js +13 -5
  73. package/lib/frameworks/compose/discover/mockFileSystem.js +36 -0
  74. package/lib/frameworks/index.js +2 -6
  75. package/lib/frameworks/next/utils.js +2 -8
  76. package/lib/frameworks/nuxt/index.js +3 -3
  77. package/lib/functions/events/v2.js +2 -1
  78. package/lib/gcp/cloudsql/cloudsqladmin.js +6 -1
  79. package/lib/gcp/devConnect.js +36 -1
  80. package/lib/hosting/implicitInit.js +2 -2
  81. package/lib/init/features/dataconnect/index.js +97 -31
  82. package/lib/init/features/dataconnect/sdk.js +131 -0
  83. package/lib/init/features/firestore/indexes.js +2 -2
  84. package/lib/init/features/firestore/rules.js +2 -2
  85. package/lib/init/features/functions/javascript.js +6 -8
  86. package/lib/init/features/functions/python.js +4 -6
  87. package/lib/init/features/functions/typescript.js +8 -10
  88. package/lib/init/features/hosting/github.js +43 -21
  89. package/lib/init/features/hosting/index.js +3 -3
  90. package/lib/init/features/index.js +3 -1
  91. package/lib/init/features/storage.js +2 -2
  92. package/lib/init/index.js +1 -0
  93. package/lib/listFiles.js +1 -1
  94. package/lib/management/apps.js +2 -2
  95. package/lib/rc.js +1 -0
  96. package/lib/requireAuth.js +8 -3
  97. package/lib/rulesDeploy.js +14 -12
  98. package/lib/templates.js +23 -0
  99. package/lib/utils.js +2 -2
  100. package/package.json +25 -24
  101. package/schema/connector-yaml.json +36 -4
  102. package/schema/dataconnect-yaml.json +4 -0
  103. package/schema/firebase-config.json +0 -8
  104. package/templates/_gitignore +3 -0
  105. package/templates/init/dataconnect/connector.yaml +11 -0
  106. package/templates/init/dataconnect/dataconnect.yaml +2 -1
  107. package/templates/init/dataconnect/mutations.gql +19 -14
  108. package/templates/init/dataconnect/queries.gql +28 -23
  109. package/templates/init/dataconnect/schema.gql +1 -1
  110. package/lib/extensions/billingMigrationHelper.js +0 -61
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sendFileBytes = void 0;
4
4
  const zlib_1 = require("zlib");
5
5
  const crc_1 = require("../crc");
6
+ const rfc_1 = require("../rfc");
6
7
  function sendFileBytes(md, data, req, res) {
7
8
  let didGunzip = false;
8
9
  if (md.contentEncoding === "gzip") {
@@ -16,7 +17,7 @@ function sendFileBytes(md, data, req, res) {
16
17
  res.setHeader("Accept-Ranges", "bytes");
17
18
  res.setHeader("Content-Type", md.contentType || "application/octet-stream");
18
19
  const fileName = md.name.split("/").pop();
19
- res.setHeader("Content-Disposition", `${md.contentDisposition || "attachment"}; filename=${fileName}`);
20
+ res.setHeader("Content-Disposition", `${md.contentDisposition || "attachment"}; filename*=${(0, rfc_1.encodeRFC5987)(fileName)}`);
20
21
  if (didGunzip) {
21
22
  res.setHeader("Transfer-Encoding", "chunked");
22
23
  }
@@ -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 = require("rimraf");
5
+ const rimraf_1 = require("rimraf");
6
6
  const fs = require("fs");
7
7
  const fse = require("fs-extra");
8
8
  const path = require("path");
@@ -56,18 +56,10 @@ class Persistence {
56
56
  }
57
57
  this._diskPathMap.delete(fileName);
58
58
  }
59
- deleteAll() {
60
- return new Promise((resolve, reject) => {
61
- rimraf(this._dirPath, (err) => {
62
- if (err) {
63
- reject(err);
64
- }
65
- else {
66
- this._diskPathMap = new Map();
67
- resolve();
68
- }
69
- });
70
- });
59
+ async deleteAll() {
60
+ await (0, rimraf_1.rimraf)(this._dirPath);
61
+ this._diskPathMap = new Map();
62
+ return;
71
63
  }
72
64
  renameFile(oldName, newName) {
73
65
  const oldNameId = this.getDiskFileName(oldName);
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeRFC5987 = void 0;
4
+ function encodeRFC5987(str) {
5
+ return encodeURIComponent(str)
6
+ .replace(/['()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`)
7
+ .replace(/%(7C|60|5E)/g, (str, hex) => String.fromCharCode(parseInt(hex, 16)));
8
+ }
9
+ exports.encodeRFC5987 = encodeRFC5987;
@@ -6,6 +6,7 @@ const fsutils_1 = require("../../../fsutils");
6
6
  const constants_1 = require("../../constants");
7
7
  const types_1 = require("../../types");
8
8
  const emulatorLogger_1 = require("../../emulatorLogger");
9
+ const templates_1 = require("../../../templates");
9
10
  function getSourceFile(rules, options) {
10
11
  const path = options.config.path(rules);
11
12
  return { name: path, content: (0, fsutils_1.readFile)(path) };
@@ -48,6 +49,7 @@ function getStorageRulesConfig(projectId, options) {
48
49
  }
49
50
  exports.getStorageRulesConfig = getStorageRulesConfig;
50
51
  function defaultStorageRules() {
51
- const path = __dirname + "/../../../../templates/emulators/default_storage.rules";
52
- return { name: path, content: (0, fsutils_1.readFile)(path) };
52
+ const defaultRulesPath = "emulators/default_storage.rules";
53
+ const name = (0, templates_1.absoluteTemplateFilePath)(defaultRulesPath);
54
+ return { name, content: (0, fsutils_1.readFile)(name) };
53
55
  }
@@ -26,7 +26,7 @@ exports.ALL_EXPERIMENTS = experiments({
26
26
  "of deploys. This has been made an experiment due to backend bugs that are " +
27
27
  "temporarily causing failures in some regions with this optimization enabled",
28
28
  public: true,
29
- default: false,
29
+ default: true,
30
30
  },
31
31
  deletegcfartifacts: {
32
32
  shortDescription: `Add the ${(0, colorette_1.bold)("functions:deletegcfartifacts")} command to purge docker build images`,
@@ -92,8 +92,8 @@ exports.ALL_EXPERIMENTS = experiments({
92
92
  public: false,
93
93
  },
94
94
  dataconnect: {
95
- shortDescription: "Enable Data Connect related features.",
96
- fullDescription: "Enable Data Connect related features.",
95
+ shortDescription: "Deprecated. Previosuly, enabled Data Connect related features.",
96
+ fullDescription: "Deprecated. Previously, enabled Data Connect related features.",
97
97
  public: false,
98
98
  },
99
99
  genkit: {
@@ -102,6 +102,11 @@ exports.ALL_EXPERIMENTS = experiments({
102
102
  default: true,
103
103
  public: false,
104
104
  },
105
+ fdccompatiblemode: {
106
+ shortDescription: "Enable Data Connect schema migrations in Compatible Mode",
107
+ fullDescription: "Enable Data Connect schema migrations in Compatible Mode",
108
+ public: false,
109
+ },
105
110
  });
106
111
  function isValidExperiment(name) {
107
112
  return Object.keys(exports.ALL_EXPERIMENTS).includes(name);
@@ -121,7 +121,7 @@ async function askForParam(args) {
121
121
  let secretLocations = [];
122
122
  const description = paramSpec.description || "";
123
123
  const label = paramSpec.label.trim();
124
- logger_1.logger.info(`\n${clc.bold(label)}${clc.bold(paramSpec.required ? "" : " (Optional)")}: ${(0, marked_1.marked)(description).trim()}`);
124
+ logger_1.logger.info(`\n${clc.bold(label)}${clc.bold(paramSpec.required ? "" : " (Optional)")}: ${(await (0, marked_1.marked)(description)).trim()}`);
125
125
  while (!valid) {
126
126
  switch (paramSpec.type) {
127
127
  case types_1.ParamType.SELECT:
@@ -5,16 +5,14 @@ const clc = require("colorette");
5
5
  const marked_1 = require("marked");
6
6
  const path = require("path");
7
7
  const semver = require("semver");
8
- const TerminalRenderer = require("marked-terminal");
8
+ const marked_terminal_1 = require("marked-terminal");
9
9
  const Table = require("cli-table");
10
10
  const extensionsApi_1 = require("./extensionsApi");
11
11
  const localHelper_1 = require("./localHelper");
12
12
  const logger_1 = require("../logger");
13
13
  const refs = require("./refs");
14
14
  const utils_1 = require("../utils");
15
- marked_1.marked.setOptions({
16
- renderer: new TerminalRenderer(),
17
- });
15
+ marked_1.marked.use((0, marked_terminal_1.markedTerminal)());
18
16
  const EXTENSIONS_CHANGELOG = "CHANGELOG.md";
19
17
  const VERSION_LINE_REGEX = /##.+?(\d+\.\d+\.\d+(?:-((\d+|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(\d+|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?).*/;
20
18
  async function getReleaseNotesForUpdate(args) {
@@ -2,18 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.retrieveRoleInfo = exports.displayResources = exports.displayEvents = exports.displayExternalServices = exports.displayExtensionVersionInfo = void 0;
4
4
  const clc = require("colorette");
5
- const marked_1 = require("marked");
6
5
  const semver = require("semver");
7
- const TerminalRenderer = require("marked-terminal");
8
6
  const path = require("path");
9
7
  const refs = require("../extensions/refs");
10
8
  const logger_1 = require("../logger");
11
9
  const types_1 = require("./types");
12
10
  const iam = require("../gcp/iam");
13
11
  const secretsUtils_1 = require("./secretsUtils");
14
- marked_1.marked.setOptions({
15
- renderer: new TerminalRenderer(),
16
- });
17
12
  const TASKS_ROLE = "cloudtasks.enqueuer";
18
13
  const TASKS_API = "cloudtasks.googleapis.com";
19
14
  async function displayExtensionVersionInfo(args) {
@@ -9,11 +9,9 @@ const fs = require("fs-extra");
9
9
  const node_fetch_1 = require("node-fetch");
10
10
  const path = require("path");
11
11
  const marked_1 = require("marked");
12
+ const marked_terminal_1 = require("marked-terminal");
12
13
  const unzip_1 = require("./../unzip");
13
- const TerminalRenderer = require("marked-terminal");
14
- marked_1.marked.setOptions({
15
- renderer: new TerminalRenderer(),
16
- });
14
+ marked_1.marked.use((0, marked_terminal_1.markedTerminal)());
17
15
  const api_1 = require("../api");
18
16
  const archiveDirectory_1 = require("../archiveDirectory");
19
17
  const utils_1 = require("./utils");
@@ -416,12 +414,12 @@ function validateReleaseNotes(rootDirectory, newVersion, extension) {
416
414
  catch (err) {
417
415
  throw new error_1.FirebaseError("No CHANGELOG.md file found. " +
418
416
  "Please create one and add an entry for this version. " +
419
- (0, marked_1.marked)("See https://firebase.google.com/docs/extensions/publishers/user-documentation#writing-changelog for more details."));
417
+ "See https://firebase.google.com/docs/extensions/publishers/user-documentation#writing-changelog for more details.");
420
418
  }
421
419
  if (!notes && !semver.prerelease(newVersion) && extension) {
422
420
  throw new error_1.FirebaseError(`No entry for version ${newVersion} found in CHANGELOG.md. ` +
423
421
  "Please add one so users know what has changed in this version. " +
424
- (0, marked_1.marked)("See https://firebase.google.com/docs/extensions/publishers/user-documentation#writing-changelog for more details."));
422
+ "See https://firebase.google.com/docs/extensions/publishers/user-documentation#writing-changelog for more details.");
425
423
  }
426
424
  return notes;
427
425
  }
@@ -698,7 +696,7 @@ async function uploadExtensionVersionFromLocalSource(args) {
698
696
  }
699
697
  exports.uploadExtensionVersionFromLocalSource = uploadExtensionVersionFromLocalSource;
700
698
  function getMissingPublisherError(publisherId) {
701
- return new error_1.FirebaseError((0, marked_1.marked)(`Couldn't find publisher ID '${clc.bold(publisherId)}'. Please ensure that you have registered this ID. For step-by-step instructions on getting started as a publisher, see https://firebase.google.com/docs/extensions/publishers/get-started.`));
699
+ return new error_1.FirebaseError(`Couldn't find publisher ID '${clc.bold(publisherId)}'. Please ensure that you have registered this ID. For step-by-step instructions on getting started as a publisher, see https://firebase.google.com/docs/extensions/publishers/get-started.`);
702
700
  }
703
701
  exports.getMissingPublisherError = getMissingPublisherError;
704
702
  async function createSourceFromLocation(projectId, sourceUri) {
@@ -64,7 +64,7 @@ async function checkProducts(projectId, usedProducts) {
64
64
  "without server-side code.\n";
65
65
  errorMessage += ` https://console.firebase.google.com/project/${projectId}/authentication/users`;
66
66
  }
67
- throw new error_1.FirebaseError((0, marked_1.marked)(errorMessage), { exit: 2 });
67
+ throw new error_1.FirebaseError(await (0, marked_1.marked)(errorMessage), { exit: 2 });
68
68
  }
69
69
  }
70
70
  function getUsedProducts(spec) {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.inferUpdateSource = exports.updateFromUrlSource = exports.updateFromLocalSource = exports.update = exports.warningUpdateToOtherSource = exports.getExistingSourceOrigin = void 0;
4
4
  const clc = require("colorette");
5
5
  const semver = require("semver");
6
- const marked_1 = require("marked");
7
6
  const error_1 = require("../error");
8
7
  const logger_1 = require("../logger");
9
8
  const extensionsApi = require("./extensionsApi");
@@ -47,7 +46,7 @@ function warningUpdateToOtherSource(sourceOrigin) {
47
46
  targetText = "URL";
48
47
  }
49
48
  const warning = `All the instance's resources and logic will be overwritten to use the source code and files from the ${targetText}.\n`;
50
- logger_1.logger.info((0, marked_1.marked)(warning));
49
+ logger_1.logger.info(warning);
51
50
  }
52
51
  exports.warningUpdateToOtherSource = warningUpdateToOtherSource;
53
52
  async function update(updateOptions) {
@@ -2,11 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.outOfBandChangesWarning = exports.displayWarningsForDeploy = void 0;
4
4
  const clc = require("colorette");
5
- const TerminalRenderer = require("marked-terminal");
6
- const marked_1 = require("marked");
7
- marked_1.marked.setOptions({
8
- renderer: new TerminalRenderer(),
9
- });
10
5
  const extensionsHelper_1 = require("./extensionsHelper");
11
6
  const deploymentSummary_1 = require("../deploy/extensions/deploymentSummary");
12
7
  const planner_1 = require("../deploy/extensions/planner");
@@ -28,9 +23,9 @@ async function displayWarningsForDeploy(instancesToCreate) {
28
23
  const unpublishedExtensions = uploadedExtensionInstances.filter((i) => i.extensionVersion?.listing?.state !== "APPROVED");
29
24
  if (unpublishedExtensions.length) {
30
25
  const humanReadableList = unpublishedExtensions.map(toListEntry).join("\n");
31
- utils.logLabeledBullet(extensionsHelper_1.logPrefix, (0, marked_1.marked)(`The following extension versions have not been published to the Firebase Extensions Hub:\n${humanReadableList}\n.` +
26
+ utils.logLabeledBullet(extensionsHelper_1.logPrefix, `The following extension versions have not been published to the Firebase Extensions Hub:\n${humanReadableList}\n.` +
32
27
  "Unpublished extensions have not been reviewed by " +
33
- "Firebase. Please make sure you trust the extension publisher before installing this extension.", { gfm: false }));
28
+ "Firebase. Please make sure you trust the extension publisher before installing this extension.");
34
29
  }
35
30
  return unpublishedExtensions.length > 0;
36
31
  }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const firestore_1 = require("../gcp/firestore");
5
+ const proto_1 = require("../gcp/proto");
6
+ const sort = require("./api-sort");
7
+ describe("compareApiBackup", () => {
8
+ it("should compare backups by location", () => {
9
+ const nam5Backup = {
10
+ name: "projects/example/locations/nam5/backups/backupid",
11
+ };
12
+ const usWest1Backup = {
13
+ name: "projects/example/locations/us-west1/backups/backupid",
14
+ };
15
+ (0, chai_1.expect)(sort.compareApiBackup(usWest1Backup, nam5Backup)).to.greaterThanOrEqual(1);
16
+ (0, chai_1.expect)(sort.compareApiBackup(nam5Backup, usWest1Backup)).to.lessThanOrEqual(-1);
17
+ });
18
+ it("should compare backups by snapshotTime (descending) if location is the same", () => {
19
+ const earlierBackup = {
20
+ name: "projects/example/locations/nam5/backups/backupid",
21
+ snapshotTime: "2024-01-01T00:00:00.000000Z",
22
+ };
23
+ const laterBackup = {
24
+ name: "projects/example/locations/nam5/backups/backupid",
25
+ snapshotTime: "2024-02-02T00:00:00.000000Z",
26
+ };
27
+ (0, chai_1.expect)(sort.compareApiBackup(earlierBackup, laterBackup)).to.greaterThanOrEqual(1);
28
+ (0, chai_1.expect)(sort.compareApiBackup(laterBackup, earlierBackup)).to.lessThanOrEqual(-1);
29
+ });
30
+ it("should compare backups by full name if location and snapshotTime are the same", () => {
31
+ const nam5Backup1 = {
32
+ name: "projects/example/locations/nam5/backups/earlier-backupid",
33
+ snapshotTime: "2024-01-01T00:00:00.000000Z",
34
+ };
35
+ const nam5Backup2 = {
36
+ name: "projects/example/locations/nam5/backups/later-backupid",
37
+ snapshotTime: "2024-01-01T00:00:00.000000Z",
38
+ };
39
+ (0, chai_1.expect)(sort.compareApiBackup(nam5Backup2, nam5Backup1)).to.greaterThanOrEqual(1);
40
+ (0, chai_1.expect)(sort.compareApiBackup(nam5Backup1, nam5Backup2)).to.lessThanOrEqual(-1);
41
+ });
42
+ });
43
+ describe("compareApiBackupSchedule", () => {
44
+ it("daily schedules should precede weekly ones", () => {
45
+ const dailySchedule = {
46
+ name: "projects/example/databases/mydatabase/backupSchedules/schedule",
47
+ dailyRecurrence: {},
48
+ retention: (0, proto_1.durationFromSeconds)(60 * 60 * 24),
49
+ };
50
+ const weeklySchedule = {
51
+ name: "projects/example/databases/mydatabase/backupSchedules/schedule",
52
+ weeklyRecurrence: {
53
+ day: firestore_1.DayOfWeek.FRIDAY,
54
+ },
55
+ retention: (0, proto_1.durationFromSeconds)(60 * 60 * 24 * 7),
56
+ };
57
+ (0, chai_1.expect)(sort.compareApiBackupSchedule(weeklySchedule, dailySchedule)).to.greaterThanOrEqual(1);
58
+ (0, chai_1.expect)(sort.compareApiBackup(dailySchedule, weeklySchedule)).to.lessThanOrEqual(-1);
59
+ });
60
+ it("should compare schedules with the same recurrence by name", () => {
61
+ const dailySchedule1 = {
62
+ name: "projects/example/databases/mydatabase/backupSchedules/schedule1",
63
+ dailyRecurrence: {},
64
+ retention: (0, proto_1.durationFromSeconds)(60 * 60 * 24),
65
+ };
66
+ const dailySchedule2 = {
67
+ name: "projects/example/databases/mydatabase/backupSchedules/schedule2",
68
+ dailyRecurrence: {},
69
+ retention: (0, proto_1.durationFromSeconds)(60 * 60 * 24),
70
+ };
71
+ (0, chai_1.expect)(sort.compareApiBackupSchedule(dailySchedule1, dailySchedule2)).to.lessThanOrEqual(-1);
72
+ (0, chai_1.expect)(sort.compareApiBackup(dailySchedule2, dailySchedule1)).to.greaterThanOrEqual(1);
73
+ });
74
+ });
@@ -420,15 +420,16 @@ class FirestoreApi {
420
420
  }
421
421
  return database;
422
422
  }
423
- async createDatabase(project, databaseId, locationId, type, deleteProtectionState, pointInTimeRecoveryEnablement) {
424
- const url = `/projects/${project}/databases`;
423
+ async createDatabase(req) {
424
+ const url = `/projects/${req.project}/databases`;
425
425
  const payload = {
426
- type,
427
- locationId,
428
- deleteProtectionState,
429
- pointInTimeRecoveryEnablement,
426
+ locationId: req.locationId,
427
+ type: req.type,
428
+ deleteProtectionState: req.deleteProtectionState,
429
+ pointInTimeRecoveryEnablement: req.pointInTimeRecoveryEnablement,
430
+ cmekConfig: req.cmekConfig,
430
431
  };
431
- const options = { queryParams: { databaseId: databaseId } };
432
+ const options = { queryParams: { databaseId: req.databaseId } };
432
433
  const res = await this.apiClient.post(url, payload, options);
433
434
  const database = res.body.response;
434
435
  if (!database) {
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const backupUtils_1 = require("./backupUtils");
5
+ describe("calculateRetention", () => {
6
+ it("should accept minutes", () => {
7
+ (0, chai_1.expect)((0, backupUtils_1.calculateRetention)("5m")).to.eq(300);
8
+ });
9
+ it("should accept hours", () => {
10
+ (0, chai_1.expect)((0, backupUtils_1.calculateRetention)("3h")).to.eq(10800);
11
+ });
12
+ it("should accept days", () => {
13
+ (0, chai_1.expect)((0, backupUtils_1.calculateRetention)("2d")).to.eq(172800);
14
+ });
15
+ it("should accept weeks", () => {
16
+ (0, chai_1.expect)((0, backupUtils_1.calculateRetention)("3w")).to.eq(1814400);
17
+ });
18
+ });
@@ -33,13 +33,33 @@ class PrettyPrint {
33
33
  logger_1.logger.info(table.toString());
34
34
  }
35
35
  prettyPrintDatabase(database) {
36
+ let colValueWidth = Math.max(50, 5 + database.name.length);
37
+ if (database.cmekConfig) {
38
+ colValueWidth = Math.max(140, 20 + database.cmekConfig.kmsKeyName.length);
39
+ }
36
40
  const table = new Table({
37
41
  head: ["Field", "Value"],
38
- colWidths: [25, Math.max(50, 5 + database.name.length)],
42
+ colWidths: [30, colValueWidth],
39
43
  });
40
44
  table.push(["Name", clc.yellow(database.name)], ["Create Time", clc.yellow(database.createTime)], ["Last Update Time", clc.yellow(database.updateTime)], ["Type", clc.yellow(database.type)], ["Location", clc.yellow(database.locationId)], ["Delete Protection State", clc.yellow(database.deleteProtectionState)], ["Point In Time Recovery", clc.yellow(database.pointInTimeRecoveryEnablement)], ["Earliest Version Time", clc.yellow(database.earliestVersionTime)], ["Version Retention Period", clc.yellow(database.versionRetentionPeriod)]);
45
+ if (database.cmekConfig) {
46
+ table.push(["KMS Key Name", clc.yellow(database.cmekConfig.kmsKeyName)]);
47
+ if (database.cmekConfig.activeKeyVersion) {
48
+ table.push([
49
+ "Active Key Versions",
50
+ clc.yellow(this.prettyStringArray(database.cmekConfig.activeKeyVersion)),
51
+ ]);
52
+ }
53
+ }
41
54
  logger_1.logger.info(table.toString());
42
55
  }
56
+ prettyStringArray(stringArray) {
57
+ let result = "";
58
+ stringArray.forEach((str) => {
59
+ result += `${str}\n`;
60
+ });
61
+ return result;
62
+ }
43
63
  prettyPrintBackups(backups) {
44
64
  if (backups.length === 0) {
45
65
  logger_1.logger.info("No backups found.");
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const API = require("./api-types");
5
+ const pretty_print_1 = require("./pretty-print");
6
+ const printer = new pretty_print_1.PrettyPrint();
7
+ describe("prettyIndexString", () => {
8
+ it("should correctly print an order type Index", () => {
9
+ (0, chai_1.expect)(printer.prettyIndexString({
10
+ name: "/projects/project/databases/(default)/collectionGroups/collectionB/indexes/a",
11
+ queryScope: API.QueryScope.COLLECTION,
12
+ fields: [
13
+ { fieldPath: "foo", order: API.Order.ASCENDING },
14
+ { fieldPath: "bar", order: API.Order.DESCENDING },
15
+ ],
16
+ }, false)).to.contain("(foo,ASCENDING) (bar,DESCENDING) ");
17
+ });
18
+ it("should correctly print a contains type Index", () => {
19
+ (0, chai_1.expect)(printer.prettyIndexString({
20
+ name: "/projects/project/databases/(default)/collectionGroups/collectionB/indexes/a",
21
+ queryScope: API.QueryScope.COLLECTION,
22
+ fields: [
23
+ { fieldPath: "foo", order: API.Order.ASCENDING },
24
+ { fieldPath: "baz", arrayConfig: API.ArrayConfig.CONTAINS },
25
+ ],
26
+ }, false)).to.contain("(foo,ASCENDING) (baz,CONTAINS) ");
27
+ });
28
+ it("should correctly print a vector type Index", () => {
29
+ (0, chai_1.expect)(printer.prettyIndexString({
30
+ name: "/projects/project/databases/(default)/collectionGroups/collectionB/indexes/a",
31
+ queryScope: API.QueryScope.COLLECTION,
32
+ fields: [{ fieldPath: "foo", vectorConfig: { dimension: 100, flat: {} } }],
33
+ }, false)).to.contain("(foo,VECTOR<100>) ");
34
+ });
35
+ it("should correctly print a vector type Index with other fields", () => {
36
+ (0, chai_1.expect)(printer.prettyIndexString({
37
+ name: "/projects/project/databases/(default)/collectionGroups/collectionB/indexes/a",
38
+ queryScope: API.QueryScope.COLLECTION,
39
+ fields: [
40
+ { fieldPath: "foo", order: API.Order.ASCENDING },
41
+ { fieldPath: "bar", vectorConfig: { dimension: 200, flat: {} } },
42
+ ],
43
+ }, false)).to.contain("(foo,ASCENDING) (bar,VECTOR<200>) ");
44
+ });
45
+ });
46
+ describe("firebaseConsoleDatabaseUrl", () => {
47
+ it("should provide a console link", () => {
48
+ (0, chai_1.expect)(printer.firebaseConsoleDatabaseUrl("example-project", "example-db")).to.equal("https://console.firebase.google.com/project/example-project/firestore/databases/example-db/data");
49
+ });
50
+ it("should convert (default) to -default-", () => {
51
+ (0, chai_1.expect)(printer.firebaseConsoleDatabaseUrl("example-project", "(default)")).to.equal("https://console.firebase.google.com/project/example-project/firestore/databases/-default-/data");
52
+ });
53
+ });
54
+ describe("prettyStringArray", () => {
55
+ it("should correctly print an array of strings", () => {
56
+ (0, chai_1.expect)(printer.prettyStringArray(["kms-key-1", "kms-key-2"])).to.equal("kms-key-1\nkms-key-2\n");
57
+ });
58
+ it("should print nothing if the array is empty", () => {
59
+ (0, chai_1.expect)(printer.prettyStringArray([])).to.equal("");
60
+ });
61
+ });
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const util = require("./util");
5
+ describe("IndexNameParsing", () => {
6
+ it("should parse an index name correctly", () => {
7
+ const name = "/projects/myproject/databases/(default)/collectionGroups/collection/indexes/abc123/";
8
+ (0, chai_1.expect)(util.parseIndexName(name)).to.eql({
9
+ projectId: "myproject",
10
+ databaseId: "(default)",
11
+ collectionGroupId: "collection",
12
+ indexId: "abc123",
13
+ });
14
+ });
15
+ it("should parse a field name correctly", () => {
16
+ const name = "/projects/myproject/databases/(default)/collectionGroups/collection/fields/abc123/";
17
+ (0, chai_1.expect)(util.parseFieldName(name)).to.eql({
18
+ projectId: "myproject",
19
+ databaseId: "(default)",
20
+ collectionGroupId: "collection",
21
+ fieldPath: "abc123",
22
+ });
23
+ });
24
+ it("should parse an index name from a named database correctly", () => {
25
+ const name = "/projects/myproject/databases/named-db/collectionGroups/collection/indexes/abc123/";
26
+ (0, chai_1.expect)(util.parseIndexName(name)).to.eql({
27
+ projectId: "myproject",
28
+ databaseId: "named-db",
29
+ collectionGroupId: "collection",
30
+ indexId: "abc123",
31
+ });
32
+ });
33
+ it("should parse a field name from a named database correctly", () => {
34
+ const name = "/projects/myproject/databases/named-db/collectionGroups/collection/fields/abc123/";
35
+ (0, chai_1.expect)(util.parseFieldName(name)).to.eql({
36
+ projectId: "myproject",
37
+ databaseId: "named-db",
38
+ collectionGroupId: "collection",
39
+ fieldPath: "abc123",
40
+ });
41
+ });
42
+ });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAngularVersion = exports.getBuildConfig = exports.getServerConfig = exports.getBrowserConfig = exports.getContext = exports.getAllTargets = void 0;
3
+ exports.tryToGetOptionsForTarget = exports.getAngularVersion = exports.getBuildConfig = exports.getServerConfig = exports.getBrowserConfig = exports.getContext = exports.getAllTargets = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const error_1 = require("../../error");
6
6
  const path_1 = require("path");
@@ -143,8 +143,9 @@ async function getContext(dir, targetOrConfiguration) {
143
143
  if (apps.length === 1)
144
144
  project = apps[0];
145
145
  }
146
- if (!project)
147
- throw new error_1.FirebaseError("Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable");
146
+ if (!project) {
147
+ throwCannotDetermineTarget();
148
+ }
148
149
  const workspaceProject = workspace.projects.get(project);
149
150
  if (!workspaceProject)
150
151
  throw new error_1.FirebaseError(`No project ${project} found.`);
@@ -334,14 +335,14 @@ async function getContext(dir, targetOrConfiguration) {
334
335
  if (!buildOrBrowserTarget) {
335
336
  throw new error_1.FirebaseError(`No build target on ${project}`);
336
337
  }
337
- const browserTargetOptions = await architectHost.getOptionsForTarget(buildOrBrowserTarget);
338
+ const browserTargetOptions = await tryToGetOptionsForTarget(architectHost, buildOrBrowserTarget);
338
339
  if (!browserTargetOptions) {
339
340
  const targetString = targetStringFromTarget(buildOrBrowserTarget);
340
341
  throw new error_1.FirebaseError(`Couldn't find options for ${targetString}.`);
341
342
  }
342
343
  const baseHref = browserTargetOptions.baseHref || "/";
343
344
  (0, utils_2.assertIsString)(baseHref);
344
- const buildTargetOptions = buildTarget && (await architectHost.getOptionsForTarget(buildTarget));
345
+ const buildTargetOptions = buildTarget && (await tryToGetOptionsForTarget(architectHost, buildTarget));
345
346
  const ssr = buildTarget ? !!buildTargetOptions?.ssr : !!serverTarget;
346
347
  return {
347
348
  architect,
@@ -465,3 +466,10 @@ function getAngularVersion(cwd) {
465
466
  return angularVersionSemver.toString();
466
467
  }
467
468
  exports.getAngularVersion = getAngularVersion;
469
+ async function tryToGetOptionsForTarget(architectHost, target) {
470
+ return await architectHost.getOptionsForTarget(target).catch(throwCannotDetermineTarget);
471
+ }
472
+ exports.tryToGetOptionsForTarget = tryToGetOptionsForTarget;
473
+ function throwCannotDetermineTarget(error) {
474
+ throw new error_1.FirebaseError(`Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable.`, { original: error });
475
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockFileSystem = void 0;
4
+ class MockFileSystem {
5
+ constructor(fileSys) {
6
+ this.fileSys = fileSys;
7
+ this.existsCache = {};
8
+ this.contentCache = {};
9
+ }
10
+ exists(path) {
11
+ if (!(path in this.existsCache)) {
12
+ this.existsCache[path] = path in this.fileSys;
13
+ }
14
+ return Promise.resolve(this.existsCache[path]);
15
+ }
16
+ read(path) {
17
+ if (!(path in this.contentCache)) {
18
+ if (!(path in this.fileSys)) {
19
+ const err = new Error("File path not found");
20
+ err.cause = "ENOENT";
21
+ throw err;
22
+ }
23
+ else {
24
+ this.contentCache[path] = this.fileSys[path];
25
+ }
26
+ }
27
+ return Promise.resolve(this.contentCache[path]);
28
+ }
29
+ getContentCache(path) {
30
+ return this.contentCache[path];
31
+ }
32
+ getExistsCache(path) {
33
+ return this.existsCache[path];
34
+ }
35
+ }
36
+ exports.MockFileSystem = MockFileSystem;
@@ -7,8 +7,8 @@ const child_process_1 = require("child_process");
7
7
  const cross_spawn_1 = require("cross-spawn");
8
8
  const promises_1 = require("fs/promises");
9
9
  const fs_extra_1 = require("fs-extra");
10
+ const glob_1 = require("glob");
10
11
  const process = require("node:process");
11
- const glob = require("glob");
12
12
  const projectUtils_1 = require("../projectUtils");
13
13
  const config_1 = require("../hosting/config");
14
14
  const api_1 = require("../hosting/api");
@@ -365,11 +365,7 @@ async function prepareFrameworks(purpose, targetNames, context, options, emulato
365
365
  await (0, promises_1.writeFile)((0, path_1.join)(functionsDist, ".env"), `${dotEnvContents}
366
366
  __FIREBASE_FRAMEWORKS_ENTRY__=${frameworksEntry}
367
367
  ${firebaseDefaults ? `__FIREBASE_DEFAULTS__=${JSON.stringify(firebaseDefaults)}\n` : ""}`.trimStart());
368
- const envs = await new Promise((resolve, reject) => glob(getProjectPath(".env.*"), (err, matches) => {
369
- if (err)
370
- reject(err);
371
- resolve(matches);
372
- }));
368
+ const envs = await (0, glob_1.glob)(getProjectPath(".env.*"));
373
369
  await Promise.all(envs.map((path) => (0, promises_1.copyFile)(path, (0, path_1.join)(functionsDist, (0, path_1.basename)(path)))));
374
370
  (0, child_process_1.execSync)(`npm i --omit dev --no-audit`, {
375
371
  cwd: functionsDist,