firebase-tools-with-isolate 13.2.1-0 → 13.3.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 (46) hide show
  1. package/lib/auth.js +11 -2
  2. package/lib/commands/apphosting-backends-create.js +6 -3
  3. package/lib/commands/apphosting-backends-delete.js +3 -5
  4. package/lib/commands/apphosting-backends-get.js +2 -2
  5. package/lib/commands/apphosting-backends-list.js +3 -3
  6. package/lib/commands/apphosting-builds-create.js +4 -4
  7. package/lib/commands/apphosting-builds-get.js +2 -2
  8. package/lib/commands/apphosting-rollouts-create.js +3 -3
  9. package/lib/commands/apphosting-rollouts-list.js +2 -2
  10. package/lib/commands/firestore-backups-delete.js +44 -0
  11. package/lib/commands/firestore-backups-get.js +25 -0
  12. package/lib/commands/firestore-backups-list.js +33 -0
  13. package/lib/commands/firestore-backups-schedules-create.js +67 -0
  14. package/lib/commands/firestore-backups-schedules-delete.js +46 -0
  15. package/lib/commands/firestore-backups-schedules-list.js +27 -0
  16. package/lib/commands/firestore-backups-schedules-update.js +33 -0
  17. package/lib/commands/firestore-databases-create.js +4 -2
  18. package/lib/commands/firestore-databases-delete.js +4 -2
  19. package/lib/commands/firestore-databases-get.js +3 -1
  20. package/lib/commands/firestore-databases-list.js +3 -1
  21. package/lib/commands/firestore-databases-restore.js +42 -0
  22. package/lib/commands/firestore-databases-update.js +4 -2
  23. package/lib/commands/firestore-indexes-list.js +5 -3
  24. package/lib/commands/firestore-locations.js +3 -1
  25. package/lib/commands/index.js +11 -1
  26. package/lib/commands/init.js +3 -3
  27. package/lib/deploy/functions/runtimes/index.js +2 -0
  28. package/lib/deploy/functions/runtimes/python/index.js +4 -1
  29. package/lib/deploy/functions/services/firestore.js +1 -1
  30. package/lib/emulator/downloadableEmulators.js +3 -3
  31. package/lib/emulator/storage/rules/runtime.js +1 -1
  32. package/lib/experiments.js +2 -2
  33. package/lib/firestore/api-sort.js +23 -1
  34. package/lib/firestore/api-types.js +6 -1
  35. package/lib/firestore/api.js +18 -115
  36. package/lib/firestore/backupUtils.js +30 -0
  37. package/lib/firestore/delete.js +3 -3
  38. package/lib/firestore/pretty-print.js +184 -0
  39. package/lib/gcp/apphosting.js +2 -2
  40. package/lib/gcp/cloudbuild.js +7 -2
  41. package/lib/gcp/firestore.js +89 -6
  42. package/lib/init/features/apphosting/index.js +140 -79
  43. package/lib/init/features/apphosting/repo.js +80 -32
  44. package/lib/init/features/hosting/github.js +5 -0
  45. package/lib/prompt.js +1 -0
  46. package/package.json +10 -5
package/lib/auth.js CHANGED
@@ -306,7 +306,7 @@ async function loginRemotely() {
306
306
  const tokens = await getTokensFromAuthorizationCode(code, `${api_1.authProxyOrigin}/complete`, codeVerifier);
307
307
  void (0, track_1.trackGA4)("login", { method: "google_remote" });
308
308
  return {
309
- user: jwt.decode(tokens.id_token),
309
+ user: jwt.decode(tokens.id_token, { json: true }),
310
310
  tokens: tokens,
311
311
  scopes: SCOPES,
312
312
  };
@@ -322,7 +322,7 @@ async function loginWithLocalhostGoogle(port, userHint) {
322
322
  const tokens = await loginWithLocalhost(port, callbackUrl, authUrl, successTemplate, getTokensFromAuthorizationCode);
323
323
  void (0, track_1.trackGA4)("login", { method: "google_localhost" });
324
324
  return {
325
- user: jwt.decode(tokens.id_token),
325
+ user: jwt.decode(tokens.id_token, { json: true }),
326
326
  tokens: tokens,
327
327
  scopes: tokens.scopes,
328
328
  };
@@ -474,6 +474,15 @@ async function refreshTokens(refreshToken, authScopes) {
474
474
  skipLog: { body: true, queryParams: true, resBody: true },
475
475
  resolveOnHTTPError: true,
476
476
  });
477
+ const forceReauthErrs = [
478
+ { error: "invalid_grant", error_subtype: "invalid_rapt" },
479
+ ];
480
+ const matches = (a, b) => {
481
+ return a.error === b.error && a.error_subtype === b.error_subtype;
482
+ };
483
+ if (forceReauthErrs.some((a) => matches(a, res.body))) {
484
+ throw invalidCredentialError();
485
+ }
477
486
  if (res.status === 401 || res.status === 400) {
478
487
  return { access_token: refreshToken };
479
488
  }
@@ -7,11 +7,14 @@ const requireInteractive_1 = require("../requireInteractive");
7
7
  const apphosting_1 = require("../init/features/apphosting");
8
8
  const apphosting_2 = require("../gcp/apphosting");
9
9
  exports.command = new command_1.Command("apphosting:backends:create")
10
- .description("Create a backend in a Firebase project")
11
- .option("-l, --location <location>", "Specify the region of the backend", "")
10
+ .description("create a backend in a Firebase project")
11
+ .option("-l, --location <location>", "specify the region of the backend", "")
12
+ .option("-s, --service-account <serviceAccount>", "specify the service account used to run the server", "")
12
13
  .before(apphosting_2.ensureApiEnabled)
13
14
  .before(requireInteractive_1.default)
14
15
  .action(async (options) => {
15
16
  const projectId = (0, projectUtils_1.needProjectId)(options);
16
- await (0, apphosting_1.doSetup)(options, projectId);
17
+ const location = options.location;
18
+ const serviceAccount = options.serviceAccount;
19
+ await (0, apphosting_1.doSetup)(projectId, location, serviceAccount);
17
20
  });
@@ -19,16 +19,14 @@ const TABLE_HEAD = [
19
19
  "Created Date",
20
20
  "Updated Date",
21
21
  ];
22
- exports.command = new command_1.Command("apphosting:backends:delete")
23
- .description("Delete a backend from a Firebase project")
22
+ exports.command = new command_1.Command("apphosting:backends:delete <backend>")
23
+ .description("delete a backend from a Firebase project")
24
24
  .option("-l, --location <location>", "App Backend location", "")
25
- .option("-s, --backend <backend>", "Backend Id", "")
26
25
  .withForce()
27
26
  .before(apphosting.ensureApiEnabled)
28
- .action(async (options) => {
27
+ .action(async (backendId, options) => {
29
28
  const projectId = (0, projectUtils_1.needProjectId)(options);
30
29
  let location = options.location;
31
- const backendId = options.backend;
32
30
  if (!backendId) {
33
31
  throw new error_1.FirebaseError("Backend id can't be empty.");
34
32
  }
@@ -11,8 +11,8 @@ const Table = require("cli-table");
11
11
  const COLUMN_LENGTH = 20;
12
12
  const TABLE_HEAD = ["Backend Id", "Repository", "Location", "URL", "Created Date", "Updated Date"];
13
13
  exports.command = new command_1.Command("apphosting:backends:get <backendId>")
14
- .description("Get backend details of a Firebase project")
15
- .option("-l, --location <location>", "App Backend location", "-")
14
+ .description("get backend details of a Firebase project")
15
+ .option("-l, --location <location>", "app backend location", "-")
16
16
  .before(apphosting.ensureApiEnabled)
17
17
  .action(async (backendId, options) => {
18
18
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -10,8 +10,8 @@ const projectUtils_1 = require("../projectUtils");
10
10
  const apphosting = require("../gcp/apphosting");
11
11
  const TABLE_HEAD = ["Backend ID", "Repository", "Location", "URL", "Created Date", "Updated Date"];
12
12
  exports.command = new command_1.Command("apphosting:backends:list")
13
- .description("List backends of a Firebase project.")
14
- .option("-l, --location <location>", "App Backend location", "-")
13
+ .description("list backends of a Firebase project")
14
+ .option("-l, --location <location>", "app Backend location", "-")
15
15
  .before(apphosting.ensureApiEnabled)
16
16
  .action(async (options) => {
17
17
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -24,7 +24,7 @@ exports.command = new command_1.Command("apphosting:backends:list")
24
24
  catch (err) {
25
25
  throw new error_1.FirebaseError(`Unable to list backends present for project: ${projectId}. Please check the parameters you have provided.`, { original: err });
26
26
  }
27
- const backends = backendRes?.backends;
27
+ const backends = backendRes.backends ?? [];
28
28
  for (const backend of backends) {
29
29
  const [backendLocation, , backendId] = backend.name.split("/").slice(3, 6);
30
30
  table.push([
@@ -6,10 +6,10 @@ const logger_1 = require("../logger");
6
6
  const command_1 = require("../command");
7
7
  const projectUtils_1 = require("../projectUtils");
8
8
  exports.command = new command_1.Command("apphosting:builds:create <backendId>")
9
- .description("Create a build for an App Hosting backend")
10
- .option("-l, --location <location>", "Specify the region of the backend", "us-central1")
11
- .option("-i, --id <buildId>", "Id of the build. If not present, autogenerate a random id", "")
12
- .option("-b, --branch <branch>", "Repository branch to deploy. Defaults to 'main'", "main")
9
+ .description("create a build for an App Hosting backend")
10
+ .option("-l, --location <location>", "specify the region of the backend", "us-central1")
11
+ .option("-i, --id <buildId>", "id of the build (defaults to autogenerating a random id)", "")
12
+ .option("-b, --branch <branch>", "repository branch to deploy (defaults to 'main')", "main")
13
13
  .before(apphosting.ensureApiEnabled)
14
14
  .action(async (backendId, options) => {
15
15
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -6,8 +6,8 @@ const logger_1 = require("../logger");
6
6
  const command_1 = require("../command");
7
7
  const projectUtils_1 = require("../projectUtils");
8
8
  exports.command = new command_1.Command("apphosting:builds:get <backendId> <buildId>")
9
- .description("Create a build for an App Hosting backend")
10
- .option("-l, --location <location>", "Specify the region of the backend", "us-central1")
9
+ .description("get a build for an App Hosting backend")
10
+ .option("-l, --location <location>", "specify the region of the backend", "us-central1")
11
11
  .before(apphosting.ensureApiEnabled)
12
12
  .action(async (backendId, buildId, options) => {
13
13
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -6,9 +6,9 @@ const logger_1 = require("../logger");
6
6
  const command_1 = require("../command");
7
7
  const projectUtils_1 = require("../projectUtils");
8
8
  exports.command = new command_1.Command("apphosting:rollouts:create <backendId> <buildId>")
9
- .description("Create a build for an App Hosting backend")
10
- .option("-l, --location <location>", "Specify the region of the backend", "us-central1")
11
- .option("-i, --id <rolloutId>", "Id of the rollout. If not present, autogenerate a random id", "")
9
+ .description("create a rollout using a build for an App Hosting backend")
10
+ .option("-l, --location <location>", "specify the region of the backend", "us-central1")
11
+ .option("-i, --id <rolloutId>", "id of the rollout (defaults to autogenerating a random id)", "")
12
12
  .before(apphosting.ensureApiEnabled)
13
13
  .action(async (backendId, buildId, options) => {
14
14
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -6,8 +6,8 @@ const logger_1 = require("../logger");
6
6
  const command_1 = require("../command");
7
7
  const projectUtils_1 = require("../projectUtils");
8
8
  exports.command = new command_1.Command("apphosting:rollouts:list <backendId>")
9
- .description("List rollouts of an App Hosting backend")
10
- .option("-l, --location <location>", "Rgion of the rollouts. Defaults to listing rollouts from all regions", "-")
9
+ .description("list rollouts of an App Hosting backend")
10
+ .option("-l, --location <location>", "region of the rollouts (defaults to listing rollouts from all regions)", "-")
11
11
  .before(apphosting.ensureApiEnabled)
12
12
  .action(async (backendId, options) => {
13
13
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const firestore_1 = require("../gcp/firestore");
6
+ const prompt_1 = require("../prompt");
7
+ const clc = require("colorette");
8
+ const logger_1 = require("../logger");
9
+ const requirePermissions_1 = require("../requirePermissions");
10
+ const types_1 = require("../emulator/types");
11
+ const commandUtils_1 = require("../emulator/commandUtils");
12
+ const error_1 = require("../error");
13
+ exports.command = new command_1.Command("firestore:backups:delete <backup>")
14
+ .description("Delete a backup under your Cloud Firestore database.")
15
+ .option("--force", "Attempt to delete backup without prompting for confirmation.")
16
+ .before(requirePermissions_1.requirePermissions, ["datastore.backups.delete"])
17
+ .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
18
+ .action(async (backupName, options) => {
19
+ const backup = await (0, firestore_1.getBackup)(backupName);
20
+ if (!options.force) {
21
+ const confirmMessage = `You are about to delete ${backupName}. Do you wish to continue?`;
22
+ const consent = await (0, prompt_1.promptOnce)({
23
+ type: "confirm",
24
+ message: confirmMessage,
25
+ default: false,
26
+ });
27
+ if (!consent) {
28
+ throw new error_1.FirebaseError("Delete backup canceled.");
29
+ }
30
+ }
31
+ try {
32
+ await (0, firestore_1.deleteBackup)(backupName);
33
+ }
34
+ catch (err) {
35
+ throw new error_1.FirebaseError(`Failed to delete the backup ${backupName}`, { original: err });
36
+ }
37
+ if (options.json) {
38
+ logger_1.logger.info(JSON.stringify(backup, undefined, 2));
39
+ }
40
+ else {
41
+ logger_1.logger.info(clc.bold(`Successfully deleted ${clc.yellow(backupName)}`));
42
+ }
43
+ return backup;
44
+ });
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const logger_1 = require("../logger");
6
+ const requirePermissions_1 = require("../requirePermissions");
7
+ const types_1 = require("../emulator/types");
8
+ const commandUtils_1 = require("../emulator/commandUtils");
9
+ const firestore_1 = require("../gcp/firestore");
10
+ const pretty_print_1 = require("../firestore/pretty-print");
11
+ exports.command = new command_1.Command("firestore:backups:get <backup>")
12
+ .description("Get a Cloud Firestore database backup.")
13
+ .before(requirePermissions_1.requirePermissions, ["datastore.backups.get"])
14
+ .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
15
+ .action(async (backupName, options) => {
16
+ const backup = await (0, firestore_1.getBackup)(backupName);
17
+ const printer = new pretty_print_1.PrettyPrint();
18
+ if (options.json) {
19
+ logger_1.logger.info(JSON.stringify(backup, undefined, 2));
20
+ }
21
+ else {
22
+ printer.prettyPrintBackup(backup);
23
+ }
24
+ return backup;
25
+ });
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const logger_1 = require("../logger");
6
+ const requirePermissions_1 = require("../requirePermissions");
7
+ const types_1 = require("../emulator/types");
8
+ const commandUtils_1 = require("../emulator/commandUtils");
9
+ const firestore_1 = require("../gcp/firestore");
10
+ const utils_1 = require("../utils");
11
+ const pretty_print_1 = require("../firestore/pretty-print");
12
+ exports.command = new command_1.Command("firestore:backups:list")
13
+ .description("List all Cloud Firestore backups in a given location")
14
+ .option("-l, --location <locationId>", "Location to search for backups, for example 'nam5'. Run 'firebase firestore:locations' to get a list of eligible locations. Defaults to all locations.")
15
+ .before(requirePermissions_1.requirePermissions, ["datastore.backups.list"])
16
+ .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
17
+ .action(async (options) => {
18
+ const printer = new pretty_print_1.PrettyPrint();
19
+ const location = options.location ?? "-";
20
+ const listBackupsResponse = await (0, firestore_1.listBackups)(options.project, location);
21
+ const backups = listBackupsResponse.backups || [];
22
+ if (options.json) {
23
+ logger_1.logger.info(JSON.stringify(listBackupsResponse, undefined, 2));
24
+ }
25
+ else {
26
+ printer.prettyPrintBackups(backups);
27
+ if (listBackupsResponse.unreachable && listBackupsResponse.unreachable.length > 0) {
28
+ (0, utils_1.logWarning)("We were not able to reach the following locations: " +
29
+ listBackupsResponse.unreachable.join(", "));
30
+ }
31
+ }
32
+ return backups;
33
+ });
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const clc = require("colorette");
5
+ const command_1 = require("../command");
6
+ const backupUtils_1 = require("../firestore/backupUtils");
7
+ const firestore_1 = require("../gcp/firestore");
8
+ const types = require("../firestore/api-types");
9
+ const logger_1 = require("../logger");
10
+ const requirePermissions_1 = require("../requirePermissions");
11
+ const types_1 = require("../emulator/types");
12
+ const commandUtils_1 = require("../emulator/commandUtils");
13
+ const pretty_print_1 = require("../firestore/pretty-print");
14
+ exports.command = new command_1.Command("firestore:backups:schedules:create")
15
+ .description("Create a backup schedule under your Cloud Firestore database.")
16
+ .option("-db, --database <databaseId>", "Database under which you want to create a schedule. Defaults to the (default) database")
17
+ .option("-rt, --retention <duration>", "duration string (e.g. 12h or 30d) for backup retention")
18
+ .option("-rc, --recurrence <recurrence>", "Recurrence settings; either DAILY or WEEKLY")
19
+ .option("-dw, --day-of-week <dayOfWeek>", "On which day of the week to perform backups; one of MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, or SUNDAY")
20
+ .before(requirePermissions_1.requirePermissions, ["datastore.backupSchedules.create"])
21
+ .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
22
+ .action(async (options) => {
23
+ const printer = new pretty_print_1.PrettyPrint();
24
+ const databaseId = options.database || "(default)";
25
+ if (!options.retention) {
26
+ logger_1.logger.error("Missing required flag --retention. See firebase firestore:backups:schedules:create --help for more info");
27
+ return;
28
+ }
29
+ const retention = (0, backupUtils_1.calculateRetention)(options.retention);
30
+ if (!options.recurrence) {
31
+ logger_1.logger.error("Missing required flag --recurrence. See firebase firestore:backups:schedules:create --help for more info");
32
+ return;
33
+ }
34
+ const recurrenceType = options.recurrence;
35
+ if (recurrenceType !== types.RecurrenceType.DAILY &&
36
+ recurrenceType !== types.RecurrenceType.WEEKLY) {
37
+ logger_1.logger.error("Invalid value for flag --recurrence. See firebase firestore:backups:schedules:create --help for more info");
38
+ return;
39
+ }
40
+ let dailyRecurrence;
41
+ let weeklyRecurrence;
42
+ if (options.recurrence === types.RecurrenceType.DAILY) {
43
+ dailyRecurrence = {};
44
+ if (options.dayOfWeek) {
45
+ logger_1.logger.error("--day-of-week should not be provided if --recurrence is DAILY");
46
+ return;
47
+ }
48
+ }
49
+ else if (options.recurrence === types.RecurrenceType.WEEKLY) {
50
+ if (!options.dayOfWeek) {
51
+ logger_1.logger.error("If --recurrence is WEEKLY, --day-of-week must be provided. See firebase firestore:backups:schedules:create --help for more info");
52
+ return;
53
+ }
54
+ const day = options.dayOfWeek;
55
+ weeklyRecurrence = {
56
+ day,
57
+ };
58
+ }
59
+ const backupSchedule = await (0, firestore_1.createBackupSchedule)(options.project, databaseId, retention, dailyRecurrence, weeklyRecurrence);
60
+ if (options.json) {
61
+ logger_1.logger.info(JSON.stringify(backupSchedule, undefined, 2));
62
+ }
63
+ else {
64
+ logger_1.logger.info(clc.bold(`Successfully created ${printer.prettyBackupScheduleString(backupSchedule)}`));
65
+ }
66
+ return backupSchedule;
67
+ });
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const firestore_1 = require("../gcp/firestore");
6
+ const prompt_1 = require("../prompt");
7
+ const clc = require("colorette");
8
+ const logger_1 = require("../logger");
9
+ const requirePermissions_1 = require("../requirePermissions");
10
+ const types_1 = require("../emulator/types");
11
+ const commandUtils_1 = require("../emulator/commandUtils");
12
+ const error_1 = require("../error");
13
+ exports.command = new command_1.Command("firestore:backups:schedules:delete <backupSchedule>")
14
+ .description("Delete a backup schedule under your Cloud Firestore database.")
15
+ .option("--force", "Attempt to delete backup schedule without prompting for confirmation.")
16
+ .before(requirePermissions_1.requirePermissions, ["datastore.backupSchedules.delete"])
17
+ .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
18
+ .action(async (backupScheduleName, options) => {
19
+ const backupSchedule = await (0, firestore_1.getBackupSchedule)(backupScheduleName);
20
+ if (!options.force) {
21
+ const confirmMessage = `You are about to delete ${backupScheduleName}. Do you wish to continue?`;
22
+ const consent = await (0, prompt_1.promptOnce)({
23
+ type: "confirm",
24
+ message: confirmMessage,
25
+ default: false,
26
+ });
27
+ if (!consent) {
28
+ throw new error_1.FirebaseError("Delete backup schedule canceled.");
29
+ }
30
+ }
31
+ try {
32
+ await (0, firestore_1.deleteBackupSchedule)(backupScheduleName);
33
+ }
34
+ catch (err) {
35
+ throw new error_1.FirebaseError(`Failed to delete the backup schedule ${backupScheduleName}`, {
36
+ original: err,
37
+ });
38
+ }
39
+ if (options.json) {
40
+ logger_1.logger.info(JSON.stringify(backupSchedule, undefined, 2));
41
+ }
42
+ else {
43
+ logger_1.logger.info(clc.bold(`Successfully deleted ${clc.yellow(backupScheduleName)}`));
44
+ }
45
+ return backupSchedule;
46
+ });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const logger_1 = require("../logger");
6
+ const requirePermissions_1 = require("../requirePermissions");
7
+ const types_1 = require("../emulator/types");
8
+ const commandUtils_1 = require("../emulator/commandUtils");
9
+ const firestore_1 = require("../gcp/firestore");
10
+ const pretty_print_1 = require("../firestore/pretty-print");
11
+ exports.command = new command_1.Command("firestore:backups:schedules:list")
12
+ .description("List backup schedules under your Cloud Firestore database.")
13
+ .option("-db, --database <databaseId>", "Database whose schedules you wish to list. Defaults to the (default) database.")
14
+ .before(requirePermissions_1.requirePermissions, ["datastore.backupSchedules.list"])
15
+ .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
16
+ .action(async (options) => {
17
+ const printer = new pretty_print_1.PrettyPrint();
18
+ const databaseId = options.database ?? "(default)";
19
+ const backupSchedules = await (0, firestore_1.listBackupSchedules)(options.project, databaseId);
20
+ if (options.json) {
21
+ logger_1.logger.info(JSON.stringify(backupSchedules, undefined, 2));
22
+ }
23
+ else {
24
+ printer.prettyPrintBackupSchedules(backupSchedules, databaseId);
25
+ }
26
+ return backupSchedules;
27
+ });
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const clc = require("colorette");
5
+ const command_1 = require("../command");
6
+ const backupUtils_1 = require("../firestore/backupUtils");
7
+ const firestore_1 = require("../gcp/firestore");
8
+ const logger_1 = require("../logger");
9
+ const requirePermissions_1 = require("../requirePermissions");
10
+ const types_1 = require("../emulator/types");
11
+ const commandUtils_1 = require("../emulator/commandUtils");
12
+ const pretty_print_1 = require("../firestore/pretty-print");
13
+ exports.command = new command_1.Command("firestore:backups:schedules:update <backupSchedule>")
14
+ .description("Update a backup schedule under your Cloud Firestore database.")
15
+ .option("-rt, --retention <duration>", "duration string (e.g. 12h or 30d) for backup retention")
16
+ .before(requirePermissions_1.requirePermissions, ["datastore.backupSchedules.update"])
17
+ .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
18
+ .action(async (backupScheduleName, options) => {
19
+ const printer = new pretty_print_1.PrettyPrint();
20
+ if (!options.retention) {
21
+ logger_1.logger.error("Missing required flag --retention. See firebase firestore:backups:schedules:update --help for more info");
22
+ return;
23
+ }
24
+ const retention = (0, backupUtils_1.calculateRetention)(options.retention);
25
+ const backupSchedule = await (0, firestore_1.updateBackupSchedule)(backupScheduleName, retention);
26
+ if (options.json) {
27
+ logger_1.logger.info(JSON.stringify(backupSchedule, undefined, 2));
28
+ }
29
+ else {
30
+ logger_1.logger.info(clc.bold(`Successfully updated ${printer.prettyBackupScheduleString(backupSchedule)}`));
31
+ }
32
+ return backupSchedule;
33
+ });
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.command = void 0;
4
- const command_1 = require("../command");
5
4
  const clc = require("colorette");
5
+ const command_1 = require("../command");
6
6
  const fsi = require("../firestore/api");
7
7
  const types = require("../firestore/api-types");
8
8
  const logger_1 = require("../logger");
9
9
  const requirePermissions_1 = require("../requirePermissions");
10
10
  const types_1 = require("../emulator/types");
11
11
  const commandUtils_1 = require("../emulator/commandUtils");
12
+ const pretty_print_1 = require("../firestore/pretty-print");
12
13
  exports.command = new command_1.Command("firestore:databases:create <database>")
13
14
  .description("Create a database in your Firebase project.")
14
15
  .option("--location <locationId>", "Region to create database, for example 'nam5'. Run 'firebase firestore:locations' to get a list of eligible locations. (required)")
@@ -18,6 +19,7 @@ exports.command = new command_1.Command("firestore:databases:create <database>")
18
19
  .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
19
20
  .action(async (database, options) => {
20
21
  const api = new fsi.FirestoreApi();
22
+ const printer = new pretty_print_1.PrettyPrint();
21
23
  if (!options.location) {
22
24
  logger_1.logger.error("Missing required flag --location. See firebase firestore:databases:create --help for more info.");
23
25
  return;
@@ -46,7 +48,7 @@ exports.command = new command_1.Command("firestore:databases:create <database>")
46
48
  logger_1.logger.info(JSON.stringify(databaseResp, undefined, 2));
47
49
  }
48
50
  else {
49
- logger_1.logger.info(clc.bold(`Successfully created ${api.prettyDatabaseString(databaseResp)}`));
51
+ logger_1.logger.info(clc.bold(`Successfully created ${printer.prettyDatabaseString(databaseResp)}`));
50
52
  logger_1.logger.info("Please be sure to configure Firebase rules in your Firebase config file for\n" +
51
53
  "the new database. By default, created databases will have closed rules that\n" +
52
54
  "block any incoming third-party traffic.");
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.command = void 0;
4
- const command_1 = require("../command");
5
4
  const clc = require("colorette");
5
+ const command_1 = require("../command");
6
6
  const fsi = require("../firestore/api");
7
7
  const prompt_1 = require("../prompt");
8
8
  const logger_1 = require("../logger");
@@ -10,6 +10,7 @@ const requirePermissions_1 = require("../requirePermissions");
10
10
  const types_1 = require("../emulator/types");
11
11
  const commandUtils_1 = require("../emulator/commandUtils");
12
12
  const error_1 = require("../error");
13
+ const pretty_print_1 = require("../firestore/pretty-print");
13
14
  exports.command = new command_1.Command("firestore:databases:delete <database>")
14
15
  .description("Delete a database in your Cloud Firestore project. Database delete protection state must be disabled. To do so, use the update command: firebase firestore:databases:update <database> --delete-protection DISABLED")
15
16
  .option("--force", "Attempt to delete database without prompting for confirmation.")
@@ -17,6 +18,7 @@ exports.command = new command_1.Command("firestore:databases:delete <database>")
17
18
  .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
18
19
  .action(async (database, options) => {
19
20
  const api = new fsi.FirestoreApi();
21
+ const printer = new pretty_print_1.PrettyPrint();
20
22
  if (!options.force) {
21
23
  const confirmMessage = `You are about to delete projects/${options.project}/databases/${database}. Do you wish to continue?`;
22
24
  const consent = await (0, prompt_1.promptOnce)({
@@ -33,7 +35,7 @@ exports.command = new command_1.Command("firestore:databases:delete <database>")
33
35
  logger_1.logger.info(JSON.stringify(databaseResp, undefined, 2));
34
36
  }
35
37
  else {
36
- logger_1.logger.info(clc.bold(`Successfully deleted ${api.prettyDatabaseString(databaseResp)}`));
38
+ logger_1.logger.info(clc.bold(`Successfully deleted ${printer.prettyDatabaseString(databaseResp)}`));
37
39
  }
38
40
  return databaseResp;
39
41
  });
@@ -7,19 +7,21 @@ const logger_1 = require("../logger");
7
7
  const requirePermissions_1 = require("../requirePermissions");
8
8
  const types_1 = require("../emulator/types");
9
9
  const commandUtils_1 = require("../emulator/commandUtils");
10
+ const pretty_print_1 = require("../firestore/pretty-print");
10
11
  exports.command = new command_1.Command("firestore:databases:get [database]")
11
12
  .description("Get database in your Cloud Firestore project.")
12
13
  .before(requirePermissions_1.requirePermissions, ["datastore.databases.get"])
13
14
  .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
14
15
  .action(async (database, options) => {
15
16
  const api = new fsi.FirestoreApi();
17
+ const printer = new pretty_print_1.PrettyPrint();
16
18
  const databaseId = database || "(default)";
17
19
  const databaseResp = await api.getDatabase(options.project, databaseId);
18
20
  if (options.json) {
19
21
  logger_1.logger.info(JSON.stringify(databaseResp, undefined, 2));
20
22
  }
21
23
  else {
22
- api.prettyPrintDatabase(databaseResp);
24
+ printer.prettyPrintDatabase(databaseResp);
23
25
  }
24
26
  return databaseResp;
25
27
  });
@@ -7,18 +7,20 @@ const logger_1 = require("../logger");
7
7
  const requirePermissions_1 = require("../requirePermissions");
8
8
  const types_1 = require("../emulator/types");
9
9
  const commandUtils_1 = require("../emulator/commandUtils");
10
+ const pretty_print_1 = require("../firestore/pretty-print");
10
11
  exports.command = new command_1.Command("firestore:databases:list")
11
12
  .description("List databases in your Cloud Firestore project.")
12
13
  .before(requirePermissions_1.requirePermissions, ["datastore.databases.list"])
13
14
  .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
14
15
  .action(async (options) => {
15
16
  const api = new fsi.FirestoreApi();
17
+ const printer = new pretty_print_1.PrettyPrint();
16
18
  const databases = await api.listDatabases(options.project);
17
19
  if (options.json) {
18
20
  logger_1.logger.info(JSON.stringify(databases, undefined, 2));
19
21
  }
20
22
  else {
21
- api.prettyPrintDatabases(databases);
23
+ printer.prettyPrintDatabases(databases);
22
24
  }
23
25
  return databases;
24
26
  });
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const clc = require("colorette");
5
+ const command_1 = require("../command");
6
+ const fsi = require("../firestore/api");
7
+ const logger_1 = require("../logger");
8
+ const requirePermissions_1 = require("../requirePermissions");
9
+ const types_1 = require("../emulator/types");
10
+ const commandUtils_1 = require("../emulator/commandUtils");
11
+ const pretty_print_1 = require("../firestore/pretty-print");
12
+ exports.command = new command_1.Command("firestore:databases:restore")
13
+ .description("Restore a Firestore database in your Firebase project.")
14
+ .option("-d, --database <databaseID>", "ID of the database to restore into")
15
+ .option("-b, --backup <backup>", "Backup from which to restore")
16
+ .before(requirePermissions_1.requirePermissions, ["datastore.backups.restoreDatabase"])
17
+ .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
18
+ .action(async (options) => {
19
+ const api = new fsi.FirestoreApi();
20
+ const printer = new pretty_print_1.PrettyPrint();
21
+ if (!options.database) {
22
+ logger_1.logger.error("Missing required flag --database. See firebase firestore:databases:restore --help for more info");
23
+ return;
24
+ }
25
+ const databaseId = options.database;
26
+ if (!options.backup) {
27
+ logger_1.logger.error("Missing required flag --backup. See firebase firestore:databases:restore --help for more info");
28
+ return;
29
+ }
30
+ const backupName = options.backup;
31
+ const databaseResp = await api.restoreDatabase(options.project, databaseId, backupName);
32
+ if (options.json) {
33
+ logger_1.logger.info(JSON.stringify(databaseResp, undefined, 2));
34
+ }
35
+ else {
36
+ logger_1.logger.info(clc.bold(`Successfully initiated restore of ${printer.prettyDatabaseString(databaseResp)}`));
37
+ logger_1.logger.info("Please be sure to configure Firebase rules in your Firebase config file for\n" +
38
+ "the new database. By default, created databases will have closed rules that\n" +
39
+ "block any incoming third-party traffic.");
40
+ }
41
+ return databaseResp;
42
+ });
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.command = void 0;
4
- const command_1 = require("../command");
5
4
  const clc = require("colorette");
5
+ const command_1 = require("../command");
6
6
  const fsi = require("../firestore/api");
7
7
  const types = require("../firestore/api-types");
8
8
  const logger_1 = require("../logger");
9
9
  const requirePermissions_1 = require("../requirePermissions");
10
10
  const types_1 = require("../emulator/types");
11
11
  const commandUtils_1 = require("../emulator/commandUtils");
12
+ const pretty_print_1 = require("../firestore/pretty-print");
12
13
  exports.command = new command_1.Command("firestore:databases:update <database>")
13
14
  .description("Update a database in your Firebase project. Must specify at least one property to update.")
14
15
  .option("--json", "Prints raw json response of the create API call if specified")
@@ -18,6 +19,7 @@ exports.command = new command_1.Command("firestore:databases:update <database>")
18
19
  .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
19
20
  .action(async (database, options) => {
20
21
  const api = new fsi.FirestoreApi();
22
+ const printer = new pretty_print_1.PrettyPrint();
21
23
  if (!options.deleteProtection && !options.pointInTimeRecovery) {
22
24
  logger_1.logger.error("Missing properties to update. See firebase firestore:databases:update --help for more info.");
23
25
  return;
@@ -53,7 +55,7 @@ exports.command = new command_1.Command("firestore:databases:update <database>")
53
55
  logger_1.logger.info(JSON.stringify(databaseResp, undefined, 2));
54
56
  }
55
57
  else {
56
- logger_1.logger.info(clc.bold(`Successfully updated ${api.prettyDatabaseString(databaseResp)}`));
58
+ logger_1.logger.info(clc.bold(`Successfully updated ${printer.prettyDatabaseString(databaseResp)}`));
57
59
  }
58
60
  return databaseResp;
59
61
  });