firebase-tools-with-isolate 13.9.0 → 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 (125) 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 +17 -15
  7. package/lib/commands/dataconnect-services-list.js +2 -8
  8. package/lib/commands/dataconnect-sql-migrate.js +0 -1
  9. package/lib/commands/deploy.js +7 -1
  10. package/lib/commands/ext-configure.js +1 -6
  11. package/lib/commands/ext-dev-init.js +27 -30
  12. package/lib/commands/ext-dev-upload.js +4 -6
  13. package/lib/commands/ext-info.js +3 -5
  14. package/lib/commands/ext-install.js +0 -5
  15. package/lib/commands/ext-uninstall.js +0 -5
  16. package/lib/commands/ext-update.js +0 -5
  17. package/lib/commands/firestore-backups-schedules-create.js +11 -14
  18. package/lib/commands/firestore-backups-schedules-list.js +1 -1
  19. package/lib/commands/firestore-backups-schedules-update.js +4 -3
  20. package/lib/commands/firestore-databases-create.js +24 -7
  21. package/lib/commands/firestore-databases-restore.js +4 -4
  22. package/lib/commands/firestore-databases-update.js +5 -6
  23. package/lib/commands/functions-secrets-set.js +9 -6
  24. package/lib/commands/help.js +2 -0
  25. package/lib/commands/hosting-channel-create.js +1 -1
  26. package/lib/commands/hosting-channel-delete.js +1 -1
  27. package/lib/commands/hosting-channel-deploy.js +1 -1
  28. package/lib/commands/hosting-clone.js +1 -2
  29. package/lib/commands/index.js +9 -11
  30. package/lib/commands/init.js +16 -12
  31. package/lib/commands/login.js +1 -2
  32. package/lib/commands/setup-emulators-dataconnect.js +22 -3
  33. package/lib/config.js +5 -0
  34. package/lib/crashlytics/buildToolsJarHelper.js +2 -1
  35. package/lib/dataconnect/build.js +1 -9
  36. package/lib/dataconnect/client.js +67 -28
  37. package/lib/dataconnect/errors.js +17 -9
  38. package/lib/dataconnect/fileUtils.js +30 -7
  39. package/lib/dataconnect/filters.js +12 -1
  40. package/lib/dataconnect/graphqlError.js +6 -3
  41. package/lib/dataconnect/load.js +9 -7
  42. package/lib/dataconnect/names.js +21 -1
  43. package/lib/dataconnect/provisionCloudSql.js +37 -20
  44. package/lib/dataconnect/schemaMigration.js +119 -66
  45. package/lib/dataconnect/types.js +8 -1
  46. package/lib/deploy/dataconnect/deploy.js +1 -0
  47. package/lib/deploy/dataconnect/prepare.js +16 -2
  48. package/lib/deploy/dataconnect/release.js +0 -1
  49. package/lib/deploy/functions/build.js +10 -1
  50. package/lib/deploy/functions/prepare.js +1 -1
  51. package/lib/deploy/functions/runtimes/discovery/index.js +2 -1
  52. package/lib/deploy/functions/runtimes/supported/types.js +6 -0
  53. package/lib/emulator/adminSdkConfig.test.js +16 -0
  54. package/lib/emulator/constants.js +1 -0
  55. package/lib/emulator/controller.js +4 -9
  56. package/lib/emulator/dataconnectEmulator.js +181 -35
  57. package/lib/emulator/download.js +4 -0
  58. package/lib/emulator/downloadableEmulators.js +54 -28
  59. package/lib/emulator/eventarcEmulator.js +68 -18
  60. package/lib/emulator/functionsEmulator.js +89 -0
  61. package/lib/emulator/functionsEmulatorShared.js +4 -0
  62. package/lib/emulator/hub.js +1 -1
  63. package/lib/emulator/portUtils.js +20 -2
  64. package/lib/emulator/pubsubEmulator.js +1 -1
  65. package/lib/emulator/registry.js +1 -1
  66. package/lib/emulator/storage/apis/shared.js +2 -1
  67. package/lib/emulator/storage/persistence.js +5 -13
  68. package/lib/emulator/storage/rfc.js +9 -0
  69. package/lib/emulator/storage/rules/config.js +4 -2
  70. package/lib/emulator/storage/rules/runtime.js +1 -1
  71. package/lib/experiments.js +8 -3
  72. package/lib/extensions/askUserForParam.js +1 -1
  73. package/lib/extensions/change-log.js +2 -4
  74. package/lib/extensions/displayExtensionInfo.js +0 -5
  75. package/lib/extensions/extensionsHelper.js +5 -7
  76. package/lib/extensions/provisioningHelper.js +1 -1
  77. package/lib/extensions/updateHelper.js +1 -2
  78. package/lib/extensions/warnings.js +2 -7
  79. package/lib/firestore/api-sort.test.js +74 -0
  80. package/lib/firestore/api.js +8 -7
  81. package/lib/firestore/backupUtils.test.js +18 -0
  82. package/lib/firestore/pretty-print.js +21 -1
  83. package/lib/firestore/pretty-print.test.js +61 -0
  84. package/lib/firestore/util.test.js +42 -0
  85. package/lib/frameworks/angular/utils.js +21 -8
  86. package/lib/frameworks/compose/discover/mockFileSystem.js +36 -0
  87. package/lib/frameworks/index.js +2 -6
  88. package/lib/frameworks/next/utils.js +2 -9
  89. package/lib/frameworks/nuxt/index.js +3 -3
  90. package/lib/functions/events/v2.js +2 -1
  91. package/lib/gcp/cloudsql/cloudsqladmin.js +20 -2
  92. package/lib/gcp/cloudsql/connect.js +6 -6
  93. package/lib/gcp/devConnect.js +36 -1
  94. package/lib/hosting/implicitInit.js +2 -2
  95. package/lib/init/features/dataconnect/index.js +252 -124
  96. package/lib/init/features/dataconnect/sdk.js +131 -0
  97. package/lib/init/features/firestore/indexes.js +2 -2
  98. package/lib/init/features/firestore/rules.js +2 -2
  99. package/lib/init/features/functions/javascript.js +6 -8
  100. package/lib/init/features/functions/python.js +4 -6
  101. package/lib/init/features/functions/typescript.js +8 -10
  102. package/lib/init/features/hosting/github.js +43 -21
  103. package/lib/init/features/hosting/index.js +3 -3
  104. package/lib/init/features/index.js +3 -1
  105. package/lib/init/features/storage.js +2 -2
  106. package/lib/init/index.js +1 -0
  107. package/lib/listFiles.js +1 -1
  108. package/lib/management/apps.js +2 -2
  109. package/lib/rc.js +2 -3
  110. package/lib/requireAuth.js +8 -0
  111. package/lib/rulesDeploy.js +14 -12
  112. package/lib/templates.js +23 -0
  113. package/lib/track.js +29 -2
  114. package/lib/utils.js +2 -2
  115. package/package.json +25 -24
  116. package/schema/connector-yaml.json +36 -4
  117. package/schema/dataconnect-yaml.json +4 -0
  118. package/schema/firebase-config.json +2 -8
  119. package/templates/_gitignore +3 -0
  120. package/templates/init/dataconnect/connector.yaml +11 -0
  121. package/templates/init/dataconnect/dataconnect.yaml +2 -1
  122. package/templates/init/dataconnect/mutations.gql +18 -13
  123. package/templates/init/dataconnect/queries.gql +34 -29
  124. package/templates/init/dataconnect/schema.gql +1 -1
  125. package/lib/extensions/billingMigrationHelper.js +0 -61
@@ -259,6 +259,7 @@ class FunctionsEmulator {
259
259
  /(^|[\/\\])\../,
260
260
  /.+\.log/,
261
261
  /.+?[\\\/]venv[\\\/].+?/,
262
+ ...(backend.ignore?.map((i) => `**/${i}`) ?? []),
262
263
  ],
263
264
  persistent: true,
264
265
  });
@@ -349,6 +350,15 @@ class FunctionsEmulator {
349
350
  else {
350
351
  this.workerPools[emulatableBackend.codebase].refresh();
351
352
  }
353
+ const toRemove = Object.keys(this.triggers).filter((recordKey) => {
354
+ const record = this.getTriggerRecordByKey(recordKey);
355
+ if (force) {
356
+ return true;
357
+ }
358
+ return !triggerDefinitions.some((def) => record.def.entryPoint === def.entryPoint &&
359
+ JSON.stringify(record.def.eventTrigger) === JSON.stringify(def.eventTrigger));
360
+ });
361
+ await this.removeTriggers(toRemove);
352
362
  const toSetup = triggerDefinitions.filter((definition) => {
353
363
  if (force) {
354
364
  return true;
@@ -399,6 +409,9 @@ class FunctionsEmulator {
399
409
  case constants_1.Constants.SERVICE_STORAGE:
400
410
  added = this.addStorageTrigger(this.args.projectId, key, definition.eventTrigger);
401
411
  break;
412
+ case constants_1.Constants.SERVICE_FIREALERTS:
413
+ added = await this.addFirealertsTrigger(this.args.projectId, key, definition.eventTrigger);
414
+ break;
402
415
  default:
403
416
  this.logger.log("DEBUG", `Unsupported trigger: ${JSON.stringify(definition)}`);
404
417
  break;
@@ -447,6 +460,25 @@ class FunctionsEmulator {
447
460
  }
448
461
  }
449
462
  }
463
+ async removeTriggers(toRemove) {
464
+ for (const triggerKey of toRemove) {
465
+ const definition = this.triggers[triggerKey].def;
466
+ const service = (0, functionsEmulatorShared_1.getFunctionService)(definition);
467
+ const key = this.getTriggerKey(definition);
468
+ switch (service) {
469
+ case constants_1.Constants.SERVICE_EVENTARC:
470
+ await this.removeEventarcTrigger(this.args.projectId, key, definition.eventTrigger);
471
+ delete this.triggers[key];
472
+ break;
473
+ case constants_1.Constants.SERVICE_FIREALERTS:
474
+ await this.removeFirealertsTrigger(this.args.projectId, key, definition.eventTrigger);
475
+ delete this.triggers[key];
476
+ break;
477
+ default:
478
+ break;
479
+ }
480
+ }
481
+ }
450
482
  addEventarcTrigger(projectId, key, eventTrigger) {
451
483
  if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
452
484
  return Promise.resolve(false);
@@ -466,6 +498,63 @@ class FunctionsEmulator {
466
498
  return false;
467
499
  });
468
500
  }
501
+ removeEventarcTrigger(projectId, key, eventTrigger) {
502
+ if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
503
+ return Promise.resolve(false);
504
+ }
505
+ const bundle = {
506
+ eventTrigger: {
507
+ ...eventTrigger,
508
+ service: "eventarc.googleapis.com",
509
+ },
510
+ };
511
+ logger_1.logger.debug(`removeEventarcTrigger`, JSON.stringify(bundle));
512
+ return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
513
+ .post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle)
514
+ .then(() => true)
515
+ .catch((err) => {
516
+ this.logger.log("WARN", "Error removing Eventarc function: " + err);
517
+ return false;
518
+ });
519
+ }
520
+ addFirealertsTrigger(projectId, key, eventTrigger) {
521
+ if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
522
+ return Promise.resolve(false);
523
+ }
524
+ const bundle = {
525
+ eventTrigger: {
526
+ ...eventTrigger,
527
+ service: "firebasealerts.googleapis.com",
528
+ },
529
+ };
530
+ logger_1.logger.debug(`addFirealertsTrigger`, JSON.stringify(bundle));
531
+ return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
532
+ .post(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle)
533
+ .then(() => true)
534
+ .catch((err) => {
535
+ this.logger.log("WARN", "Error adding FireAlerts function: " + err);
536
+ return false;
537
+ });
538
+ }
539
+ removeFirealertsTrigger(projectId, key, eventTrigger) {
540
+ if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.EVENTARC)) {
541
+ return Promise.resolve(false);
542
+ }
543
+ const bundle = {
544
+ eventTrigger: {
545
+ ...eventTrigger,
546
+ service: "firebasealerts.googleapis.com",
547
+ },
548
+ };
549
+ logger_1.logger.debug(`removeFirealertsTrigger`, JSON.stringify(bundle));
550
+ return registry_1.EmulatorRegistry.client(types_1.Emulators.EVENTARC)
551
+ .post(`/emulator/v1/remove/projects/${projectId}/triggers/${key}`, bundle)
552
+ .then(() => true)
553
+ .catch((err) => {
554
+ this.logger.log("WARN", "Error removing FireAlerts function: " + err);
555
+ return false;
556
+ });
557
+ }
469
558
  async performPostLoadOperations() {
470
559
  if (!this.blockingFunctionsConfig.triggers &&
471
560
  !this.blockingFunctionsConfig.forwardInboundCredentials) {
@@ -17,6 +17,7 @@ const events = require("../functions/events");
17
17
  const utils_1 = require("../utils");
18
18
  const V2_EVENTS = [
19
19
  events.v2.PUBSUB_PUBLISH_EVENT,
20
+ events.v2.FIREALERTS_EVENT,
20
21
  ...events.v2.STORAGE_EVENTS,
21
22
  ...events.v2.DATABASE_EVENTS,
22
23
  ...events.v2.FIRESTORE_EVENTS,
@@ -203,6 +204,9 @@ function getServiceFromEventType(eventType) {
203
204
  if (eventType.includes("storage")) {
204
205
  return constants_1.Constants.SERVICE_STORAGE;
205
206
  }
207
+ if (eventType.includes("firebasealerts")) {
208
+ return constants_1.Constants.SERVICE_FIREALERTS;
209
+ }
206
210
  if (eventType.includes("analytics")) {
207
211
  return constants_1.Constants.SERVICE_ANALYTICS;
208
212
  }
@@ -156,7 +156,7 @@ class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
156
156
  const locatorPath = EmulatorHub.getLocatorFilePath(this.args.projectId);
157
157
  return new Promise((resolve, reject) => {
158
158
  fs.unlink(locatorPath, (e) => {
159
- if (e) {
159
+ if (e && e.code !== "ENOENT") {
160
160
  reject(e);
161
161
  }
162
162
  else {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveHostAndAssignPorts = exports.waitForPortUsed = exports.checkListenable = void 0;
3
+ exports.listenSpecsToString = exports.resolveHostAndAssignPorts = exports.waitForPortUsed = exports.checkListenable = void 0;
4
4
  const clc = require("colorette");
5
5
  const tcpport = require("tcp-port-used");
6
6
  const node_net_1 = require("node:net");
@@ -11,6 +11,7 @@ const types_1 = require("./types");
11
11
  const constants_1 = require("./constants");
12
12
  const emulatorLogger_1 = require("./emulatorLogger");
13
13
  const node_child_process_1 = require("node:child_process");
14
+ const dataconnectEmulator_1 = require("./dataconnectEmulator");
14
15
  const RESTRICTED_PORTS = new Set([
15
16
  1,
16
17
  7,
@@ -146,7 +147,7 @@ const EMULATOR_CAN_LISTEN_ON_PRIMARY_ONLY = {
146
147
  firestore: true,
147
148
  "firestore.websocket": true,
148
149
  pubsub: true,
149
- dataconnect: true,
150
+ dataconnect: false,
150
151
  hub: false,
151
152
  ui: false,
152
153
  auth: true,
@@ -219,6 +220,14 @@ async function resolveHostAndAssignPorts(listenConfig) {
219
220
  available.push(listen);
220
221
  }
221
222
  else {
223
+ if (/^dataconnect/i.exec(name)) {
224
+ const alreadyRunning = await (0, dataconnectEmulator_1.checkIfDataConnectEmulatorRunningOnAddress)(listen);
225
+ if (alreadyRunning) {
226
+ emuLogger.logLabeled("DEBUG", "dataconnect", `Detected already running emulator on ${listen.address}:${listen.port}. Will attempt to reuse it.`);
227
+ }
228
+ available.push(listen);
229
+ continue;
230
+ }
222
231
  if (!portFixed) {
223
232
  if (i > 0) {
224
233
  emuLogger.logLabeled("DEBUG", name, `Port ${p} taken on secondary address ${addr.address}, will keep searching to find a better port.`);
@@ -321,3 +330,12 @@ function listenSpec(lookup, port) {
321
330
  port: port,
322
331
  };
323
332
  }
333
+ function listenSpecsToString(specs) {
334
+ return specs
335
+ .map((spec) => {
336
+ const host = spec.family === "IPv4" ? spec.address : `[${spec.address}]`;
337
+ return `${host}:${spec.port}`;
338
+ })
339
+ .join(",");
340
+ }
341
+ exports.listenSpecsToString = listenSpecsToString;
@@ -132,7 +132,7 @@ class PubsubEmulator {
132
132
  };
133
133
  }
134
134
  createCloudEventRequestBody(topic, message) {
135
- const truncatedPublishTime = new Date(message.publishTime.getMilliseconds()).toISOString();
135
+ const truncatedPublishTime = new Date(message.publishTime.getTime()).toISOString();
136
136
  const data = {
137
137
  message: {
138
138
  messageId: message.id,
@@ -111,7 +111,7 @@ class EmulatorRegistry {
111
111
  url.port = info.port.toString();
112
112
  }
113
113
  else {
114
- console.warn(`Cannot determine host and port of ${emulator}`);
114
+ throw new Error(`Cannot determine host and port of ${emulator}`);
115
115
  }
116
116
  return url;
117
117
  }
@@ -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
  }
@@ -73,7 +73,7 @@ class StorageRulesRuntime {
73
73
  if (this.alive) {
74
74
  return;
75
75
  }
76
- const downloadDetails = downloadableEmulators_1.DownloadDetails[types_2.Emulators.STORAGE];
76
+ const downloadDetails = (0, downloadableEmulators_1.getDownloadDetails)(types_2.Emulators.STORAGE);
77
77
  const hasEmulator = fs.existsSync(downloadDetails.downloadPath);
78
78
  if (!hasEmulator) {
79
79
  if (autoDownload) {
@@ -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.");