firebase-tools-with-isolate 13.7.3 → 13.11.2

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 (113) hide show
  1. package/lib/api.js +18 -8
  2. package/lib/apiv2.js +19 -13
  3. package/lib/apphosting/app.js +40 -59
  4. package/lib/apphosting/constants.js +2 -2
  5. package/lib/apphosting/githubConnections.js +7 -9
  6. package/lib/apphosting/index.js +122 -58
  7. package/lib/apphosting/repo.js +3 -3
  8. package/lib/apphosting/secrets/index.js +7 -1
  9. package/lib/checkValidTargetFilters.js +8 -1
  10. package/lib/commands/apphosting-backends-create.js +7 -6
  11. package/lib/commands/apphosting-backends-delete.js +24 -28
  12. package/lib/commands/apphosting-backends-list.js +4 -5
  13. package/lib/commands/apphosting-secrets-access.js +1 -1
  14. package/lib/commands/apphosting-secrets-grantaccess.js +11 -7
  15. package/lib/commands/apphosting-secrets-set.js +1 -1
  16. package/lib/commands/dataconnect-sdk-generate.js +43 -0
  17. package/lib/commands/dataconnect-services-list.js +74 -0
  18. package/lib/commands/dataconnect-sql-diff.js +25 -0
  19. package/lib/commands/dataconnect-sql-migrate.js +44 -0
  20. package/lib/commands/deploy.js +27 -1
  21. package/lib/commands/index.js +11 -0
  22. package/lib/commands/init.js +10 -3
  23. package/lib/commands/setup-emulators-dataconnect.js +12 -0
  24. package/lib/config.js +1 -0
  25. package/lib/crashlytics/buildToolsJarHelper.js +2 -1
  26. package/lib/dataconnect/build.js +14 -0
  27. package/lib/dataconnect/checkIam.js +30 -0
  28. package/lib/dataconnect/client.js +104 -0
  29. package/lib/dataconnect/dataplaneClient.js +16 -0
  30. package/lib/dataconnect/ensureApis.js +12 -0
  31. package/lib/dataconnect/errors.js +37 -0
  32. package/lib/dataconnect/fileUtils.js +92 -0
  33. package/lib/dataconnect/filters.js +45 -0
  34. package/lib/dataconnect/freeTrial.js +22 -0
  35. package/lib/dataconnect/graphqlError.js +15 -0
  36. package/lib/dataconnect/load.js +40 -0
  37. package/lib/dataconnect/names.js +66 -0
  38. package/lib/dataconnect/prompts.js +20 -0
  39. package/lib/dataconnect/provisionCloudSql.js +91 -0
  40. package/lib/dataconnect/schemaMigration.js +278 -0
  41. package/lib/dataconnect/types.js +22 -0
  42. package/lib/deploy/dataconnect/deploy.js +76 -0
  43. package/lib/deploy/dataconnect/index.js +9 -0
  44. package/lib/deploy/dataconnect/prepare.js +33 -0
  45. package/lib/deploy/dataconnect/release.js +64 -0
  46. package/lib/deploy/functions/checkIam.js +4 -34
  47. package/lib/deploy/functions/prepare.js +1 -1
  48. package/lib/deploy/functions/release/fabricator.js +7 -2
  49. package/lib/deploy/functions/runtimes/discovery/index.js +2 -1
  50. package/lib/deploy/functions/runtimes/supported/types.js +6 -0
  51. package/lib/deploy/index.js +2 -0
  52. package/lib/downloadUtils.js +2 -2
  53. package/lib/emulator/constants.js +3 -0
  54. package/lib/emulator/controller.js +40 -12
  55. package/lib/emulator/dataconnectEmulator.js +137 -0
  56. package/lib/emulator/download.js +5 -1
  57. package/lib/emulator/downloadableEmulators.js +92 -16
  58. package/lib/emulator/portUtils.js +13 -4
  59. package/lib/emulator/registry.js +6 -1
  60. package/lib/emulator/storage/rules/runtime.js +1 -1
  61. package/lib/emulator/types.js +3 -0
  62. package/lib/experiments.js +19 -6
  63. package/lib/extensions/emulator/specHelper.js +5 -39
  64. package/lib/frameworks/angular/utils.js +8 -3
  65. package/lib/frameworks/next/index.js +6 -4
  66. package/lib/frameworks/next/utils.js +1 -1
  67. package/lib/functions/python.js +4 -3
  68. package/lib/gcp/apphosting.js +11 -1
  69. package/lib/gcp/cloudsql/cloudsqladmin.js +187 -0
  70. package/lib/gcp/cloudsql/connect.js +144 -0
  71. package/lib/gcp/cloudsql/fbToolsAuthClient.js +44 -0
  72. package/lib/gcp/devConnect.js +1 -1
  73. package/lib/gcp/firedata.js +27 -0
  74. package/lib/gcp/iam.js +33 -1
  75. package/lib/gcp/secretManager.js +1 -1
  76. package/lib/hosting/interactive.js +4 -0
  77. package/lib/init/features/dataconnect/index.js +228 -0
  78. package/lib/init/features/emulators.js +13 -1
  79. package/lib/init/features/functions/index.js +19 -3
  80. package/lib/init/features/functions/npm-dependencies.js +12 -23
  81. package/lib/init/features/genkit.js +53 -0
  82. package/lib/init/features/index.js +5 -1
  83. package/lib/init/index.js +2 -0
  84. package/lib/init/spawn.js +23 -0
  85. package/lib/logger.js +22 -2
  86. package/lib/operation-poller.js +8 -2
  87. package/lib/rc.js +7 -1
  88. package/lib/requireAuth.js +4 -8
  89. package/lib/requireTosAcceptance.js +22 -0
  90. package/lib/track.js +29 -2
  91. package/lib/utils.js +55 -4
  92. package/package.json +10 -4
  93. package/schema/connector-yaml.json +54 -0
  94. package/schema/dataconnect-yaml.json +72 -0
  95. package/schema/firebase-config.json +105 -0
  96. package/templates/extensions/javascript/package.lint.json +2 -2
  97. package/templates/extensions/javascript/package.nolint.json +2 -2
  98. package/templates/extensions/typescript/package.lint.json +2 -2
  99. package/templates/extensions/typescript/package.nolint.json +2 -2
  100. package/templates/init/dataconnect/connector.yaml +2 -0
  101. package/templates/init/dataconnect/dataconnect.yaml +10 -0
  102. package/templates/init/dataconnect/mutations.gql +30 -0
  103. package/templates/init/dataconnect/queries.gql +51 -0
  104. package/templates/init/dataconnect/schema.gql +28 -0
  105. package/templates/init/functions/javascript/_gitignore +2 -1
  106. package/templates/init/functions/javascript/package.lint.json +2 -2
  107. package/templates/init/functions/javascript/package.nolint.json +2 -2
  108. package/templates/init/functions/python/_gitignore +1 -0
  109. package/templates/init/functions/typescript/_gitignore +1 -0
  110. package/templates/init/functions/typescript/package.lint.json +2 -2
  111. package/templates/init/functions/typescript/package.nolint.json +2 -2
  112. package/lib/monospace/index.js +0 -82
  113. /package/lib/{monospace/interfaces.js → gcp/cloudsql/types.js} +0 -0
@@ -50,7 +50,7 @@ function generateConnectionId() {
50
50
  }
51
51
  const ADD_CONN_CHOICE = "@ADD_CONN";
52
52
  async function linkGitHubRepository(projectId, location) {
53
- utils.logBullet(clc.bold(`${clc.yellow("===")} Set up a GitHub connection`));
53
+ utils.logBullet(clc.bold(`${clc.yellow("===")} Import a GitHub repository`));
54
54
  const oauthConn = await getOrCreateOauthConnection(projectId, location);
55
55
  const existingConns = await listAppHostingConnections(projectId);
56
56
  if (existingConns.length === 0) {
@@ -83,7 +83,7 @@ async function createFullyInstalledConnection(projectId, location, connectionId,
83
83
  });
84
84
  while (conn.installationState.stage !== "COMPLETE") {
85
85
  utils.logBullet("Install the Cloud Build GitHub app to enable access to GitHub repositories");
86
- const targetUri = conn.installationState.actionUri.replace("install_v2", "direct_install_v2");
86
+ const targetUri = conn.installationState.actionUri;
87
87
  utils.logBullet(targetUri);
88
88
  await utils.openInBrowser(targetUri);
89
89
  await (0, prompt_1.promptOnce)({
@@ -129,7 +129,7 @@ async function promptRepositoryUri(projectId, connections) {
129
129
  const remoteUri = await (0, prompt_1.promptOnce)({
130
130
  type: "autocomplete",
131
131
  name: "remoteUri",
132
- message: "Which repository would you like to deploy?",
132
+ message: "Which GitHub repo do you want to deploy?",
133
133
  source: (_, input = "") => {
134
134
  return new Promise((resolve) => resolve([
135
135
  new inquirer.Separator(),
@@ -5,6 +5,7 @@ const error_1 = require("../../error");
5
5
  const gcsm = require("../../gcp/secretManager");
6
6
  const gcb = require("../../gcp/cloudbuild");
7
7
  const gce = require("../../gcp/computeEngine");
8
+ const apphosting = require("../../gcp/apphosting");
8
9
  const secretManager_1 = require("../../gcp/secretManager");
9
10
  const secretManager_2 = require("../../gcp/secretManager");
10
11
  const utils = require("../../utils");
@@ -33,7 +34,8 @@ function serviceAccountsForBackend(projectNumber, backend) {
33
34
  };
34
35
  }
35
36
  exports.serviceAccountsForBackend = serviceAccountsForBackend;
36
- async function grantSecretAccess(projectId, secretName, accounts) {
37
+ async function grantSecretAccess(projectId, projectNumber, secretName, accounts) {
38
+ const p4saEmail = apphosting.serviceAgentEmail(projectNumber);
37
39
  const newBindings = [
38
40
  {
39
41
  role: "roles/secretmanager.secretAccessor",
@@ -43,6 +45,10 @@ async function grantSecretAccess(projectId, secretName, accounts) {
43
45
  role: "roles/secretmanager.viewer",
44
46
  members: accounts.buildServiceAccounts.map((sa) => `serviceAccount:${sa}`),
45
47
  },
48
+ {
49
+ role: "roles/secretmanager.secretVersionManager",
50
+ members: [`serviceAccount:${p4saEmail}`],
51
+ },
46
52
  ];
47
53
  let existingBindings;
48
54
  try {
@@ -19,7 +19,14 @@ function targetsHaveFilters(...targets) {
19
19
  function targetsHaveNoFilters(...targets) {
20
20
  return targets.some((t) => !t.includes(":"));
21
21
  }
22
- const FILTERABLE_TARGETS = new Set(["hosting", "functions", "firestore", "storage", "database"]);
22
+ const FILTERABLE_TARGETS = new Set([
23
+ "hosting",
24
+ "functions",
25
+ "firestore",
26
+ "storage",
27
+ "database",
28
+ "dataconnect",
29
+ ]);
23
30
  async function checkValidTargetFilters(options) {
24
31
  const only = !options.only ? [] : options.only.split(",");
25
32
  return new Promise((resolve, reject) => {
@@ -6,19 +6,20 @@ const projectUtils_1 = require("../projectUtils");
6
6
  const requireInteractive_1 = require("../requireInteractive");
7
7
  const apphosting_1 = require("../apphosting");
8
8
  const apphosting_2 = require("../gcp/apphosting");
9
+ const firedata_1 = require("../gcp/firedata");
10
+ const requireTosAcceptance_1 = require("../requireTosAcceptance");
9
11
  exports.command = new command_1.Command("apphosting:backends:create")
10
12
  .description("create a Firebase App Hosting backend")
11
- .option("-a, --app <webApp>", "specify an existing Firebase web app to associate your App Hosting backend with")
12
- .option("-l, --location <location>", "specify the region of the backend", "")
13
+ .option("-a, --app <webAppId>", "specify an existing Firebase web app's ID to associate your App Hosting backend with")
14
+ .option("-l, --location <location>", "specify the location of the backend", "")
13
15
  .option("-s, --service-account <serviceAccount>", "specify the service account used to run the server", "")
14
- .option("-w, --with-dev-connect", "use the Developer Connect flow insetad of Cloud Build Repositories (testing)", false)
15
16
  .before(apphosting_2.ensureApiEnabled)
16
17
  .before(requireInteractive_1.default)
18
+ .before((0, requireTosAcceptance_1.requireTosAcceptance)(firedata_1.APPHOSTING_TOS_ID))
17
19
  .action(async (options) => {
18
20
  const projectId = (0, projectUtils_1.needProjectId)(options);
19
- const webApp = options.app;
21
+ const webAppId = options.app;
20
22
  const location = options.location;
21
23
  const serviceAccount = options.serviceAccount;
22
- const withDevConnect = options.withDevConnect;
23
- await (0, apphosting_1.doSetup)(projectId, webApp, location, serviceAccount, withDevConnect);
24
+ await (0, apphosting_1.doSetup)(projectId, webAppId, location, serviceAccount);
24
25
  });
@@ -5,44 +5,29 @@ const command_1 = require("../command");
5
5
  const projectUtils_1 = require("../projectUtils");
6
6
  const error_1 = require("../error");
7
7
  const prompt_1 = require("../prompt");
8
- const constants_1 = require("../apphosting/constants");
9
8
  const utils = require("../utils");
10
9
  const apphosting = require("../gcp/apphosting");
11
10
  const apphosting_backends_list_1 = require("./apphosting-backends-list");
12
11
  const apphosting_1 = require("../apphosting");
12
+ const ora = require("ora");
13
13
  exports.command = new command_1.Command("apphosting:backends:delete <backend>")
14
14
  .description("delete a Firebase App Hosting backend")
15
- .option("-l, --location <location>", "specify the region of the backend", "")
15
+ .option("-l, --location <location>", "specify the location of the backend", "-")
16
16
  .withForce()
17
17
  .before(apphosting.ensureApiEnabled)
18
18
  .action(async (backendId, options) => {
19
19
  const projectId = (0, projectUtils_1.needProjectId)(options);
20
20
  let location = options.location;
21
- if (!backendId) {
22
- throw new error_1.FirebaseError("Backend id can't be empty.");
23
- }
24
- if (!location) {
25
- const allowedLocations = (await apphosting.listLocations(projectId)).map((loc) => loc.locationId);
26
- location = await (0, prompt_1.promptOnce)({
27
- name: "region",
28
- type: "list",
29
- default: constants_1.DEFAULT_REGION,
30
- message: "Please select the region of the backend you'd like to delete:",
31
- choices: allowedLocations,
32
- });
33
- }
34
21
  let backend;
35
- try {
36
- backend = await apphosting.getBackend(projectId, location, backendId);
22
+ if (location === "-" || location === "") {
23
+ backend = await (0, apphosting_1.getBackendForAmbiguousLocation)(projectId, backendId, "Please select the location of the backend you'd like to delete:");
24
+ location = apphosting.parseBackendName(backend.name).location;
37
25
  }
38
- catch (err) {
39
- throw new error_1.FirebaseError(`No backends found with given parameters. Command aborted.`, {
40
- original: err,
41
- });
26
+ else {
27
+ backend = await getBackendForLocation(projectId, location, backendId);
42
28
  }
43
- utils.logWarning("You are about to permanently delete the backend:");
44
- const backends = [backend];
45
- (0, apphosting_backends_list_1.printBackendsTable)(backends);
29
+ utils.logWarning("You are about to permanently delete this backend:");
30
+ (0, apphosting_backends_list_1.printBackendsTable)([backend]);
46
31
  const confirmDeletion = await (0, prompt_1.promptOnce)({
47
32
  type: "confirm",
48
33
  name: "force",
@@ -50,14 +35,25 @@ exports.command = new command_1.Command("apphosting:backends:delete <backend>")
50
35
  message: "Are you sure?",
51
36
  }, options);
52
37
  if (!confirmDeletion) {
53
- throw new error_1.FirebaseError("Deletion Aborted");
38
+ return;
54
39
  }
40
+ const spinner = ora("Deleting backend...").start();
55
41
  try {
56
42
  await (0, apphosting_1.deleteBackendAndPoll)(projectId, location, backendId);
57
- utils.logSuccess(`Successfully deleted the backend: ${backendId}`);
43
+ spinner.succeed(`Successfully deleted the backend: ${backendId}`);
58
44
  }
59
45
  catch (err) {
60
- throw new error_1.FirebaseError(`Failed to delete backend: ${backendId}. Please check the parameters you have provided.`, { original: err });
46
+ spinner.stop();
47
+ throw new error_1.FirebaseError(`Failed to delete backend: ${backendId}.`, { original: err });
61
48
  }
62
- return backend;
63
49
  });
50
+ async function getBackendForLocation(projectId, location, backendId) {
51
+ try {
52
+ return await apphosting.getBackend(projectId, location, backendId);
53
+ }
54
+ catch (err) {
55
+ throw new error_1.FirebaseError(`No backend named "${backendId}" found in ${location}.`, {
56
+ original: err,
57
+ });
58
+ }
59
+ }
@@ -8,7 +8,7 @@ const logger_1 = require("../logger");
8
8
  const projectUtils_1 = require("../projectUtils");
9
9
  const apphosting = require("../gcp/apphosting");
10
10
  const Table = require("cli-table");
11
- const TABLE_HEAD = ["Backend ID", "Repository", "Location", "URL", "Created Date", "Updated Date"];
11
+ const TABLE_HEAD = ["Backend", "Repository", "URL", "Location", "Updated Date"];
12
12
  exports.command = new command_1.Command("apphosting:backends:list")
13
13
  .description("list Firebase App Hosting backends")
14
14
  .option("-l, --location <location>", "list backends in the specified location", "-")
@@ -33,13 +33,12 @@ function printBackendsTable(backends) {
33
33
  style: { head: ["green"] },
34
34
  });
35
35
  for (const backend of backends) {
36
- const [backendLocation, , backendId] = backend.name.split("/").slice(3, 6);
36
+ const { location, id } = apphosting.parseBackendName(backend.name);
37
37
  table.push([
38
- backendId,
38
+ id,
39
39
  backend.codebase?.repository?.split("/").pop() ?? "",
40
- backendLocation,
41
40
  backend.uri.startsWith("https:") ? backend.uri : "https://" + backend.uri,
42
- (0, utils_1.datetimeString)(new Date(backend.createTime)),
41
+ location,
43
42
  (0, utils_1.datetimeString)(new Date(backend.updateTime)),
44
43
  ]);
45
44
  }
@@ -8,7 +8,7 @@ const secretManager_1 = require("../gcp/secretManager");
8
8
  const requireAuth_1 = require("../requireAuth");
9
9
  const secretManager = require("../gcp/secretManager");
10
10
  const requirePermissions_1 = require("../requirePermissions");
11
- exports.command = new command_1.Command("apphosting:secrets:access <secretName>[@version]")
11
+ exports.command = new command_1.Command("apphosting:secrets:access <secretName[@version]>")
12
12
  .description("Access secret value given secret and its version. Defaults to accessing the latest version.")
13
13
  .before(requireAuth_1.requireAuth)
14
14
  .before(secretManager.ensureApi)
@@ -9,9 +9,10 @@ const secretManager = require("../gcp/secretManager");
9
9
  const requirePermissions_1 = require("../requirePermissions");
10
10
  const apphosting = require("../gcp/apphosting");
11
11
  const secrets = require("../apphosting/secrets");
12
+ const apphosting_1 = require("../apphosting");
12
13
  exports.command = new command_1.Command("apphosting:secrets:grantaccess <secretName>")
13
14
  .description("grant service accounts permissions to the provided secret")
14
- .option("-l, --location <location>", "backend location")
15
+ .option("-l, --location <location>", "backend location", "-")
15
16
  .option("-b, --backend <backend>", "backend name")
16
17
  .before(requireAuth_1.requireAuth)
17
18
  .before(secretManager.ensureApi)
@@ -27,10 +28,6 @@ exports.command = new command_1.Command("apphosting:secrets:grantaccess <secretN
27
28
  .action(async (secretName, options) => {
28
29
  const projectId = (0, projectUtils_1.needProjectId)(options);
29
30
  const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
30
- if (!options.location) {
31
- throw new error_1.FirebaseError("Missing required flag --location. See firebase apphosting:secrets:grantaccess --help for more info");
32
- }
33
- const location = options.location;
34
31
  if (!options.backend) {
35
32
  throw new error_1.FirebaseError("Missing required flag --backend. See firebase apphosting:secrets:grantaccess --help for more info");
36
33
  }
@@ -39,7 +36,14 @@ exports.command = new command_1.Command("apphosting:secrets:grantaccess <secretN
39
36
  throw new error_1.FirebaseError(`Cannot find secret ${secretName}`);
40
37
  }
41
38
  const backendId = options.backend;
42
- const backend = await apphosting.getBackend(projectId, location, backendId);
39
+ const location = options.location;
40
+ let backend;
41
+ if (location === "" || location === "-") {
42
+ backend = await (0, apphosting_1.getBackendForAmbiguousLocation)(projectId, backendId, "Please select the location of your backend:");
43
+ }
44
+ else {
45
+ backend = await apphosting.getBackend(projectId, location, backendId);
46
+ }
43
47
  const accounts = secrets.toMulti(secrets.serviceAccountsForBackend(projectNumber, backend));
44
- await secrets.grantSecretAccess(projectId, secretName, accounts);
48
+ await secrets.grantSecretAccess(projectId, projectNumber, secretName, accounts);
45
49
  });
@@ -50,7 +50,7 @@ exports.command = new command_1.Command("apphosting:secrets:set <secretName>")
50
50
  utils.logWarning(`To use this secret in your backend, you must grant access. You can do so in the future with ${clc.bold("firebase apphosting:secrets:grantaccess")}`);
51
51
  }
52
52
  else {
53
- await secrets.grantSecretAccess(projectId, secretName, accounts);
53
+ await secrets.grantSecretAccess(projectId, projectNumber, secretName, accounts);
54
54
  }
55
55
  await config.maybeAddSecretToYaml(secretName);
56
56
  });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const path = require("path");
5
+ const command_1 = require("../command");
6
+ const dataconnectEmulator_1 = require("../emulator/dataconnectEmulator");
7
+ const projectUtils_1 = require("../projectUtils");
8
+ const load_1 = require("../dataconnect/load");
9
+ const fileUtils_1 = require("../dataconnect/fileUtils");
10
+ const logger_1 = require("../logger");
11
+ exports.command = new command_1.Command("dataconnect:sdk:generate")
12
+ .description("generates typed SDKs for your Data Connect connectors")
13
+ .action(async (options) => {
14
+ const projectId = (0, projectUtils_1.needProjectId)(options);
15
+ const services = (0, fileUtils_1.readFirebaseJson)(options.config);
16
+ for (const service of services) {
17
+ let configDir = service.source;
18
+ if (!path.isAbsolute(configDir)) {
19
+ const cwd = options.cwd || process.cwd();
20
+ configDir = path.resolve(path.join(cwd), configDir);
21
+ }
22
+ const serviceInfo = await (0, load_1.load)(projectId, service.location, configDir);
23
+ const hasGeneratables = serviceInfo.connectorInfo.some((c) => {
24
+ return (c.connectorYaml.generate?.javascriptSdk ||
25
+ c.connectorYaml.generate?.kotlinSdk ||
26
+ c.connectorYaml.generate?.swiftSdk);
27
+ });
28
+ if (!hasGeneratables) {
29
+ logger_1.logger.warn("No generated SDKs have been declared in connector.yaml files.");
30
+ logger_1.logger.warn("See https://firebase.google.com/docs/data-connect/quickstart#configure-sdk-outputs for examples of how to configure generated SDKs.");
31
+ return;
32
+ }
33
+ for (const conn of serviceInfo.connectorInfo) {
34
+ const output = await dataconnectEmulator_1.DataConnectEmulator.generate({
35
+ configDir,
36
+ locationId: service.location,
37
+ connectorId: conn.connectorYaml.connectorId,
38
+ });
39
+ logger_1.logger.info(output);
40
+ logger_1.logger.info(`Generated SDKs for ${conn.connectorYaml.connectorId}`);
41
+ }
42
+ }
43
+ });
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const projectUtils_1 = require("../projectUtils");
6
+ const names = require("../dataconnect/names");
7
+ const client = require("../dataconnect/client");
8
+ const logger_1 = require("../logger");
9
+ const requirePermissions_1 = require("../requirePermissions");
10
+ const ensureApis_1 = require("../dataconnect/ensureApis");
11
+ const Table = require("cli-table");
12
+ exports.command = new command_1.Command("dataconnect:services:list")
13
+ .description("list all deployed services in your Firebase project")
14
+ .before(requirePermissions_1.requirePermissions, [
15
+ "dataconnect.services.list",
16
+ "dataconnect.schemas.list",
17
+ "dataconnect.connectors.list",
18
+ ])
19
+ .action(async (options) => {
20
+ const projectId = (0, projectUtils_1.needProjectId)(options);
21
+ await (0, ensureApis_1.ensureApis)(projectId);
22
+ const services = await client.listAllServices(projectId);
23
+ const table = new Table({
24
+ head: [
25
+ "Service ID",
26
+ "Location",
27
+ "Data Source",
28
+ "Schema Last Updated",
29
+ "Connector ID",
30
+ "Connector Last Updated",
31
+ ],
32
+ style: { head: ["yellow"] },
33
+ });
34
+ const jsonOutput = { services: [] };
35
+ for (const service of services) {
36
+ const schema = (await client.getSchema(service.name)) ?? {
37
+ name: "",
38
+ primaryDatasource: {},
39
+ source: { files: [] },
40
+ };
41
+ const connectors = await client.listConnectors(service.name);
42
+ const serviceName = names.parseServiceName(service.name);
43
+ const instanceName = schema?.primaryDatasource.postgresql?.cloudSql.instance ?? "";
44
+ const instanceId = instanceName.split("/").pop();
45
+ const dbId = schema?.primaryDatasource.postgresql?.database ?? "";
46
+ const dbName = `CloudSQL Instance: ${instanceId}\nDatabase:${dbId}`;
47
+ table.push([
48
+ serviceName.serviceId,
49
+ serviceName.location,
50
+ dbName,
51
+ schema?.updateTime ?? "",
52
+ "",
53
+ "",
54
+ ]);
55
+ const serviceJson = {
56
+ serviceId: serviceName.serviceId,
57
+ location: serviceName.location,
58
+ datasource: dbName,
59
+ schemaUpdateTime: schema?.updateTime,
60
+ connectors: [],
61
+ };
62
+ for (const conn of connectors) {
63
+ const connectorName = names.parseConnectorName(conn.name);
64
+ table.push(["", "", "", "", connectorName.connectorId, conn.updateTime]);
65
+ serviceJson.connectors.push({
66
+ connectorId: connectorName.connectorId,
67
+ connectorLastUpdated: conn.updateTime ?? "",
68
+ });
69
+ }
70
+ jsonOutput.services.push(serviceJson);
71
+ }
72
+ logger_1.logger.info(table.toString());
73
+ return jsonOutput;
74
+ });
@@ -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 projectUtils_1 = require("../projectUtils");
6
+ const ensureApis_1 = require("../dataconnect/ensureApis");
7
+ const requirePermissions_1 = require("../requirePermissions");
8
+ const fileUtils_1 = require("../dataconnect/fileUtils");
9
+ const schemaMigration_1 = require("../dataconnect/schemaMigration");
10
+ const requireAuth_1 = require("../requireAuth");
11
+ exports.command = new command_1.Command("dataconnect:sql:diff [serviceId]")
12
+ .description("displays the differences between a local DataConnect schema and your CloudSQL database's current schema")
13
+ .before(requirePermissions_1.requirePermissions, [
14
+ "firebasedataconnect.services.list",
15
+ "firebasedataconnect.schemas.list",
16
+ "firebasedataconnect.schemas.update",
17
+ ])
18
+ .before(requireAuth_1.requireAuth)
19
+ .action(async (serviceId, options) => {
20
+ const projectId = (0, projectUtils_1.needProjectId)(options);
21
+ await (0, ensureApis_1.ensureApis)(projectId);
22
+ const serviceInfo = await (0, fileUtils_1.pickService)(projectId, options.config, serviceId);
23
+ const diffs = await (0, schemaMigration_1.diffSchema)(serviceInfo.schema);
24
+ return { projectId, serviceId, diffs };
25
+ });
@@ -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 projectUtils_1 = require("../projectUtils");
6
+ const fileUtils_1 = require("../dataconnect/fileUtils");
7
+ const error_1 = require("../error");
8
+ const schemaMigration_1 = require("../dataconnect/schemaMigration");
9
+ const requireAuth_1 = require("../requireAuth");
10
+ const requirePermissions_1 = require("../requirePermissions");
11
+ const ensureApis_1 = require("../dataconnect/ensureApis");
12
+ const utils_1 = require("../utils");
13
+ exports.command = new command_1.Command("dataconnect:sql:migrate [serviceId]")
14
+ .description("migrates your CloudSQL database's schema to match your local DataConnect schema")
15
+ .before(requirePermissions_1.requirePermissions, [
16
+ "firebasedataconnect.services.list",
17
+ "firebasedataconnect.schemas.list",
18
+ "firebasedataconnect.schemas.update",
19
+ "cloudsql.instances.connect",
20
+ "cloudsql.users.create",
21
+ ])
22
+ .before(requireAuth_1.requireAuth)
23
+ .withForce("Execute any required database changes without prompting")
24
+ .action(async (serviceId, options) => {
25
+ const projectId = (0, projectUtils_1.needProjectId)(options);
26
+ await (0, ensureApis_1.ensureApis)(projectId);
27
+ const serviceInfo = await (0, fileUtils_1.pickService)(projectId, options.config, serviceId);
28
+ const instanceId = serviceInfo.dataConnectYaml.schema.datasource.postgresql?.cloudSql.instanceId;
29
+ if (!instanceId) {
30
+ throw new error_1.FirebaseError("dataconnect.yaml is missing field schema.datasource.postgresql.cloudsql.instanceId");
31
+ }
32
+ const diffs = await (0, schemaMigration_1.migrateSchema)({
33
+ options,
34
+ schema: serviceInfo.schema,
35
+ validateOnly: true,
36
+ });
37
+ if (diffs.length) {
38
+ (0, utils_1.logLabeledSuccess)("dataconnect", `Database schema sucessfully migrated! Run 'firebase deploy' to deploy your new schema to your Data Connect service.`);
39
+ }
40
+ else {
41
+ (0, utils_1.logLabeledSuccess)("dataconnect", "Database schema is already up to date!");
42
+ }
43
+ return { projectId, serviceId, diffs };
44
+ });
@@ -23,6 +23,7 @@ exports.VALID_DEPLOY_TARGETS = [
23
23
  "hosting",
24
24
  "remoteconfig",
25
25
  "extensions",
26
+ "dataconnect",
26
27
  ];
27
28
  exports.TARGET_PERMISSIONS = {
28
29
  database: ["firebasedatabase.instances.update"],
@@ -47,6 +48,29 @@ exports.TARGET_PERMISSIONS = {
47
48
  "firebaserules.releases.update",
48
49
  ],
49
50
  remoteconfig: ["cloudconfig.configs.get", "cloudconfig.configs.update"],
51
+ dataconnect: [
52
+ "cloudsql.databases.create",
53
+ "cloudsql.databases.update",
54
+ "cloudsql.instances.connect",
55
+ "cloudsql.instances.create",
56
+ "cloudsql.instances.get",
57
+ "cloudsql.instances.list",
58
+ "cloudsql.instances.update",
59
+ "cloudsql.users.create",
60
+ "firebasedataconnect.connectors.create",
61
+ "firebasedataconnect.connectors.delete",
62
+ "firebasedataconnect.connectors.list",
63
+ "firebasedataconnect.connectors.update",
64
+ "firebasedataconnect.operations.get",
65
+ "firebasedataconnect.services.create",
66
+ "firebasedataconnect.services.delete",
67
+ "firebasedataconnect.services.update",
68
+ "firebasedataconnect.services.list",
69
+ "firebasedataconnect.schemas.create",
70
+ "firebasedataconnect.schemas.delete",
71
+ "firebasedataconnect.schemas.list",
72
+ "firebasedataconnect.schemas.update",
73
+ ],
50
74
  };
51
75
  exports.command = new command_1.Command("deploy")
52
76
  .description("deploy code and assets to your Firebase project")
@@ -56,7 +80,9 @@ exports.command = new command_1.Command("deploy")
56
80
  .option("--only <targets>", 'only deploy to specified, comma-separated targets (e.g. "hosting,storage"). For functions, ' +
57
81
  'can specify filters with colons to scope function deploys to only those functions (e.g. "--only functions:func1,functions:func2"). ' +
58
82
  "When filtering based on export groups (the exported module object keys), use dots to specify group names " +
59
- '(e.g. "--only functions:group1.subgroup1,functions:group2)"')
83
+ '(e.g. "--only functions:group1.subgroup1,functions:group2)"' +
84
+ "For data connect, can specify filters with colons to deploy only a service, connector, or schema" +
85
+ '(e.g. "--only dataconnect:serviceId,dataconnect:serviceId:connectorId,dataconnect:serviceId:schema"). ')
60
86
  .option("--except <targets>", 'deploy to all targets except specified (e.g. "database")')
61
87
  .before(requireConfig_1.requireConfig)
62
88
  .before((options) => {
@@ -200,6 +200,17 @@ function load(client) {
200
200
  client.setup.emulators.pubsub = loadCommand("setup-emulators-pubsub");
201
201
  client.setup.emulators.storage = loadCommand("setup-emulators-storage");
202
202
  client.setup.emulators.ui = loadCommand("setup-emulators-ui");
203
+ if (experiments.isEnabled("dataconnect")) {
204
+ client.dataconnect = {};
205
+ client.setup.emulators.dataconnect = loadCommand("setup-emulators-dataconnect");
206
+ client.dataconnect.services = {};
207
+ client.dataconnect.services.list = loadCommand("dataconnect-services-list");
208
+ client.dataconnect.sql = {};
209
+ client.dataconnect.sql.diff = loadCommand("dataconnect-sql-diff");
210
+ client.dataconnect.sql.migrate = loadCommand("dataconnect-sql-migrate");
211
+ client.dataconnect.sdk = {};
212
+ client.dataconnect.sdk.generate = loadCommand("dataconnect-sdk-generate");
213
+ }
203
214
  client.target = loadCommand("target");
204
215
  client.target.apply = loadCommand("target-apply");
205
216
  client.target.clear = loadCommand("target-clear");
@@ -69,10 +69,17 @@ const choices = [
69
69
  checked: false,
70
70
  },
71
71
  ];
72
- if ((0, experiments_1.isEnabled)("apphosting")) {
72
+ if ((0, experiments_1.isEnabled)("genkit")) {
73
73
  choices.push({
74
- value: "apphosting",
75
- name: "App Hosting: Get started with App Hosting projects.",
74
+ value: "genkit",
75
+ name: "Genkit: Setup a new Genkit project with Firebase",
76
+ checked: false,
77
+ });
78
+ }
79
+ if ((0, experiments_1.isEnabled)("dataconnect")) {
80
+ choices.push({
81
+ value: "dataconnect",
82
+ name: "Data Connect: Set up a Firebase Data Connect service.",
76
83
  checked: false,
77
84
  });
78
85
  }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const command_1 = require("../command");
5
+ const download_1 = require("../emulator/download");
6
+ const types_1 = require("../emulator/types");
7
+ const NAME = types_1.Emulators.DATACONNECT;
8
+ exports.command = new command_1.Command(`setup:emulators:${NAME}`)
9
+ .description(`downloads the ${NAME} emulator`)
10
+ .action(() => {
11
+ return (0, download_1.downloadEmulator)(NAME);
12
+ });
package/lib/config.js CHANGED
@@ -225,4 +225,5 @@ Config.MATERIALIZE_TARGETS = [
225
225
  "hosting",
226
226
  "storage",
227
227
  "remoteconfig",
228
+ "dataconnect",
228
229
  ];
@@ -12,10 +12,11 @@ const rimraf = require("rimraf");
12
12
  const utils = require("../utils");
13
13
  const JAR_CACHE_DIR = process.env.FIREBASE_CRASHLYTICS_BUILDTOOLS_PATH ||
14
14
  path.join(os.homedir(), ".cache", "firebase", "crashlytics", "buildtools");
15
- const JAR_VERSION = "2.9.2";
15
+ const JAR_VERSION = "3.0.0";
16
16
  const JAR_URL = `https://dl.google.com/android/maven2/com/google/firebase/firebase-crashlytics-buildtools/${JAR_VERSION}/firebase-crashlytics-buildtools-${JAR_VERSION}.jar`;
17
17
  async function fetchBuildtoolsJar() {
18
18
  if (process.env.CRASHLYTICS_LOCAL_JAR) {
19
+ logger_1.logger.debug(`Using local Crashlytics Jar override at ${process.env.CRASHLYTICS_LOCAL_JAR}`);
19
20
  return process.env.CRASHLYTICS_LOCAL_JAR;
20
21
  }
21
22
  const jarPath = path.join(JAR_CACHE_DIR, `crashlytics-buildtools-${JAR_VERSION}.jar`);
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.build = void 0;
4
+ const dataconnectEmulator_1 = require("../emulator/dataconnectEmulator");
5
+ const error_1 = require("../error");
6
+ const graphqlError_1 = require("./graphqlError");
7
+ async function build(options, configDir) {
8
+ const buildResult = await dataconnectEmulator_1.DataConnectEmulator.build({ configDir });
9
+ if (buildResult?.errors?.length) {
10
+ throw new error_1.FirebaseError(`There are errors in your schema and connector files:\n${buildResult.errors.map(graphqlError_1.prettify).join("\n")}`);
11
+ }
12
+ return buildResult?.metadata ?? {};
13
+ }
14
+ exports.build = build;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.grantRolesToCloudSqlServiceAccount = void 0;
4
+ const iam = require("../gcp/iam");
5
+ const resourceManager_1 = require("../gcp/resourceManager");
6
+ const cloudSqlAdmin = require("../gcp/cloudsql/cloudsqladmin");
7
+ const error_1 = require("../error");
8
+ async function grantRolesToCloudSqlServiceAccount(projectId, instanceId, roles) {
9
+ const instance = await cloudSqlAdmin.getInstance(projectId, instanceId);
10
+ const saEmail = instance.serviceAccountEmailAddress;
11
+ const policy = await (0, resourceManager_1.getIamPolicy)(projectId);
12
+ const requiredBindings = roles.map((r) => {
13
+ const binding = {
14
+ role: r,
15
+ members: [`serviceAccount:${saEmail}`],
16
+ };
17
+ return binding;
18
+ });
19
+ const updated = iam.mergeBindings(policy, requiredBindings);
20
+ if (updated) {
21
+ try {
22
+ await (0, resourceManager_1.setIamPolicy)(projectId, policy, "bindings");
23
+ }
24
+ catch (err) {
25
+ iam.printManualIamConfig(requiredBindings, projectId, "dataconnect");
26
+ throw new error_1.FirebaseError("Unable to make required IAM policy changes.");
27
+ }
28
+ }
29
+ }
30
+ exports.grantRolesToCloudSqlServiceAccount = grantRolesToCloudSqlServiceAccount;