firebase-tools-with-isolate 13.6.4 → 13.9.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 (157) hide show
  1. package/README.md +4 -6
  2. package/lib/api.js +18 -8
  3. package/lib/apiv2.js +19 -13
  4. package/lib/apphosting/app.js +69 -0
  5. package/lib/apphosting/config.js +97 -0
  6. package/lib/{init/features/apphosting → apphosting}/constants.js +2 -2
  7. package/lib/apphosting/githubConnections.js +263 -0
  8. package/lib/apphosting/index.js +319 -0
  9. package/lib/{init/features/apphosting → apphosting}/repo.js +12 -12
  10. package/lib/apphosting/secrets/dialogs.js +170 -0
  11. package/lib/apphosting/secrets/index.js +103 -0
  12. package/lib/checkValidTargetFilters.js +8 -1
  13. package/lib/commands/apphosting-backends-create.js +9 -4
  14. package/lib/commands/apphosting-backends-delete.js +27 -30
  15. package/lib/commands/apphosting-backends-get.js +8 -8
  16. package/lib/commands/apphosting-backends-list.js +6 -7
  17. package/lib/commands/apphosting-secrets-access.js +24 -0
  18. package/lib/commands/apphosting-secrets-describe.js +29 -0
  19. package/lib/commands/apphosting-secrets-grantaccess.js +49 -0
  20. package/lib/commands/apphosting-secrets-set.js +56 -0
  21. package/lib/commands/dataconnect-sdk-generate.js +37 -0
  22. package/lib/commands/dataconnect-services-list.js +80 -0
  23. package/lib/commands/dataconnect-sql-diff.js +25 -0
  24. package/lib/commands/dataconnect-sql-migrate.js +45 -0
  25. package/lib/commands/deploy.js +27 -1
  26. package/lib/commands/firestore-databases-create.js +1 -0
  27. package/lib/commands/firestore-databases-restore.js +1 -0
  28. package/lib/commands/functions-secrets-access.js +2 -2
  29. package/lib/commands/functions-secrets-describe.js +14 -0
  30. package/lib/commands/functions-secrets-destroy.js +2 -2
  31. package/lib/commands/functions-secrets-get.js +3 -17
  32. package/lib/commands/functions-secrets-prune.js +2 -1
  33. package/lib/commands/functions-secrets-set.js +3 -19
  34. package/lib/commands/index.js +25 -6
  35. package/lib/commands/init.js +10 -3
  36. package/lib/commands/setup-emulators-dataconnect.js +12 -0
  37. package/lib/config.js +1 -0
  38. package/lib/dataconnect/build.js +22 -0
  39. package/lib/dataconnect/checkIam.js +30 -0
  40. package/lib/dataconnect/client.js +112 -0
  41. package/lib/dataconnect/dataplaneClient.js +16 -0
  42. package/lib/dataconnect/ensureApis.js +12 -0
  43. package/lib/dataconnect/errors.js +29 -0
  44. package/lib/dataconnect/fileUtils.js +92 -0
  45. package/lib/dataconnect/filters.js +45 -0
  46. package/lib/dataconnect/freeTrial.js +22 -0
  47. package/lib/dataconnect/graphqlError.js +12 -0
  48. package/lib/dataconnect/load.js +40 -0
  49. package/lib/dataconnect/names.js +46 -0
  50. package/lib/dataconnect/prompts.js +20 -0
  51. package/lib/dataconnect/provisionCloudSql.js +74 -0
  52. package/lib/dataconnect/schemaMigration.js +246 -0
  53. package/lib/dataconnect/types.js +22 -0
  54. package/lib/deploy/dataconnect/deploy.js +75 -0
  55. package/lib/deploy/dataconnect/index.js +9 -0
  56. package/lib/deploy/dataconnect/prepare.js +33 -0
  57. package/lib/deploy/dataconnect/release.js +65 -0
  58. package/lib/deploy/firestore/prepare.js +4 -2
  59. package/lib/deploy/functions/checkIam.js +6 -39
  60. package/lib/deploy/functions/containerCleaner.js +1 -15
  61. package/lib/deploy/functions/deploy.js +2 -2
  62. package/lib/deploy/functions/params.js +2 -2
  63. package/lib/deploy/functions/prepare.js +13 -3
  64. package/lib/deploy/functions/pricing.js +2 -2
  65. package/lib/deploy/functions/prompts.js +39 -7
  66. package/lib/deploy/functions/release/fabricator.js +12 -7
  67. package/lib/deploy/functions/release/index.js +17 -2
  68. package/lib/deploy/functions/release/planner.js +11 -3
  69. package/lib/deploy/functions/runtimes/discovery/index.js +3 -3
  70. package/lib/deploy/functions/runtimes/index.js +6 -43
  71. package/lib/deploy/functions/runtimes/node/index.js +3 -2
  72. package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +15 -34
  73. package/lib/deploy/functions/runtimes/python/index.js +10 -7
  74. package/lib/deploy/functions/runtimes/supported/index.js +80 -0
  75. package/lib/deploy/functions/runtimes/supported/types.js +74 -0
  76. package/lib/deploy/functions/services/index.js +4 -0
  77. package/lib/deploy/index.js +2 -0
  78. package/lib/downloadUtils.js +3 -2
  79. package/lib/emulator/constants.js +3 -0
  80. package/lib/emulator/controller.js +44 -13
  81. package/lib/emulator/dataconnectEmulator.js +95 -0
  82. package/lib/emulator/download.js +1 -1
  83. package/lib/emulator/downloadableEmulators.js +57 -8
  84. package/lib/emulator/functionsEmulator.js +2 -2
  85. package/lib/emulator/hub.js +5 -0
  86. package/lib/emulator/portUtils.js +3 -3
  87. package/lib/emulator/registry.js +6 -1
  88. package/lib/emulator/types.js +3 -0
  89. package/lib/experiments.js +31 -6
  90. package/lib/extensions/emulator/specHelper.js +9 -42
  91. package/lib/extensions/extensionsApi.js +2 -2
  92. package/lib/extensions/localHelper.js +3 -3
  93. package/lib/firestore/pretty-print.js +5 -0
  94. package/lib/frameworks/astro/index.js +1 -1
  95. package/lib/frameworks/flutter/index.js +2 -2
  96. package/lib/frameworks/next/constants.js +2 -1
  97. package/lib/frameworks/next/index.js +27 -15
  98. package/lib/frameworks/next/utils.js +33 -3
  99. package/lib/functional.js +2 -2
  100. package/lib/functions/events/v2.js +7 -1
  101. package/lib/functions/python.js +4 -3
  102. package/lib/functions/secrets.js +40 -22
  103. package/lib/gcp/apphosting.js +25 -3
  104. package/lib/gcp/cloudbuild.js +7 -3
  105. package/lib/gcp/cloudfunctions.js +5 -5
  106. package/lib/gcp/cloudfunctionsv2.js +3 -3
  107. package/lib/gcp/cloudscheduler.js +2 -2
  108. package/lib/gcp/cloudsql/cloudsqladmin.js +174 -0
  109. package/lib/gcp/cloudsql/connect.js +144 -0
  110. package/lib/gcp/cloudsql/fbToolsAuthClient.js +44 -0
  111. package/lib/gcp/computeEngine.js +7 -0
  112. package/lib/gcp/devConnect.js +25 -12
  113. package/lib/gcp/firedata.js +27 -0
  114. package/lib/gcp/iam.js +41 -1
  115. package/lib/gcp/secretManager.js +55 -7
  116. package/lib/gcp/serviceusage.js +24 -5
  117. package/lib/hosting/interactive.js +4 -0
  118. package/lib/init/features/dataconnect/index.js +166 -0
  119. package/lib/init/features/emulators.js +13 -1
  120. package/lib/init/features/functions/index.js +19 -3
  121. package/lib/init/features/functions/npm-dependencies.js +12 -23
  122. package/lib/init/features/functions/python.js +4 -3
  123. package/lib/init/features/genkit.js +53 -0
  124. package/lib/init/features/hosting/github.js +4 -5
  125. package/lib/init/features/index.js +6 -2
  126. package/lib/init/index.js +2 -0
  127. package/lib/init/spawn.js +23 -0
  128. package/lib/logger.js +22 -2
  129. package/lib/operation-poller.js +8 -2
  130. package/lib/rc.js +9 -1
  131. package/lib/requireAuth.js +1 -8
  132. package/lib/requireTosAcceptance.js +22 -0
  133. package/lib/utils.js +76 -8
  134. package/package.json +11 -5
  135. package/schema/connector-yaml.json +54 -0
  136. package/schema/dataconnect-yaml.json +72 -0
  137. package/schema/firebase-config.json +115 -2
  138. package/templates/extensions/javascript/package.lint.json +2 -2
  139. package/templates/extensions/javascript/package.nolint.json +2 -2
  140. package/templates/extensions/typescript/package.lint.json +2 -2
  141. package/templates/extensions/typescript/package.nolint.json +2 -2
  142. package/templates/init/dataconnect/connector.yaml +2 -0
  143. package/templates/init/dataconnect/dataconnect.yaml +10 -0
  144. package/templates/init/dataconnect/mutations.gql +30 -0
  145. package/templates/init/dataconnect/queries.gql +51 -0
  146. package/templates/init/dataconnect/schema.gql +28 -0
  147. package/templates/init/functions/javascript/_gitignore +2 -1
  148. package/templates/init/functions/javascript/package.lint.json +2 -2
  149. package/templates/init/functions/javascript/package.nolint.json +2 -2
  150. package/templates/init/functions/python/_gitignore +1 -0
  151. package/templates/init/functions/typescript/_eslintrc +1 -0
  152. package/templates/init/functions/typescript/_gitignore +1 -0
  153. package/templates/init/functions/typescript/package.lint.json +2 -2
  154. package/templates/init/functions/typescript/package.nolint.json +2 -2
  155. package/lib/init/features/apphosting/index.js +0 -229
  156. package/lib/monospace/index.js +0 -82
  157. /package/lib/{monospace/interfaces.js → gcp/cloudsql/types.js} +0 -0
@@ -4,17 +4,22 @@ exports.command = void 0;
4
4
  const command_1 = require("../command");
5
5
  const projectUtils_1 = require("../projectUtils");
6
6
  const requireInteractive_1 = require("../requireInteractive");
7
- const apphosting_1 = require("../init/features/apphosting");
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
- .description("create a backend in a Firebase project")
11
- .option("-l, --location <location>", "specify the region of the backend", "")
12
+ .description("create a Firebase App Hosting 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", "")
12
15
  .option("-s, --service-account <serviceAccount>", "specify the service account used to run the server", "")
13
16
  .before(apphosting_2.ensureApiEnabled)
14
17
  .before(requireInteractive_1.default)
18
+ .before((0, requireTosAcceptance_1.requireTosAcceptance)(firedata_1.APPHOSTING_TOS_ID))
15
19
  .action(async (options) => {
16
20
  const projectId = (0, projectUtils_1.needProjectId)(options);
21
+ const webAppId = options.app;
17
22
  const location = options.location;
18
23
  const serviceAccount = options.serviceAccount;
19
- await (0, apphosting_1.doSetup)(projectId, location, serviceAccount);
24
+ await (0, apphosting_1.doSetup)(projectId, webAppId, location, serviceAccount);
20
25
  });
@@ -5,43 +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("../init/features/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");
11
+ const apphosting_1 = require("../apphosting");
12
+ const ora = require("ora");
12
13
  exports.command = new command_1.Command("apphosting:backends:delete <backend>")
13
- .description("delete a backend from a Firebase project")
14
- .option("-l, --location <location>", "App Backend location", "")
14
+ .description("delete a Firebase App Hosting backend")
15
+ .option("-l, --location <location>", "specify the location of the backend", "-")
15
16
  .withForce()
16
17
  .before(apphosting.ensureApiEnabled)
17
18
  .action(async (backendId, options) => {
18
19
  const projectId = (0, projectUtils_1.needProjectId)(options);
19
20
  let location = options.location;
20
- if (!backendId) {
21
- throw new error_1.FirebaseError("Backend id can't be empty.");
22
- }
23
- if (!location) {
24
- const allowedLocations = (await apphosting.listLocations(projectId)).map((loc) => loc.locationId);
25
- location = await (0, prompt_1.promptOnce)({
26
- name: "region",
27
- type: "list",
28
- default: constants_1.DEFAULT_REGION,
29
- message: "Please select the region of the backend you'd like to delete:",
30
- choices: allowedLocations,
31
- });
32
- }
33
21
  let backend;
34
- try {
35
- 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;
36
25
  }
37
- catch (err) {
38
- throw new error_1.FirebaseError(`No backends found with given parameters. Command aborted.`, {
39
- original: err,
40
- });
26
+ else {
27
+ backend = await getBackendForLocation(projectId, location, backendId);
41
28
  }
42
- utils.logWarning("You are about to permanently delete the backend:");
43
- const backends = [backend];
44
- (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]);
45
31
  const confirmDeletion = await (0, prompt_1.promptOnce)({
46
32
  type: "confirm",
47
33
  name: "force",
@@ -49,14 +35,25 @@ exports.command = new command_1.Command("apphosting:backends:delete <backend>")
49
35
  message: "Are you sure?",
50
36
  }, options);
51
37
  if (!confirmDeletion) {
52
- throw new error_1.FirebaseError("Deletion Aborted");
38
+ return;
53
39
  }
40
+ const spinner = ora("Deleting backend...").start();
54
41
  try {
55
- await apphosting.deleteBackend(projectId, location, backendId);
56
- utils.logSuccess(`Successfully deleted the backend: ${backendId}`);
42
+ await (0, apphosting_1.deleteBackendAndPoll)(projectId, location, backendId);
43
+ spinner.succeed(`Successfully deleted the backend: ${backendId}`);
57
44
  }
58
45
  catch (err) {
59
- 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 });
60
48
  }
61
- return backend;
62
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
+ }
@@ -7,30 +7,30 @@ const error_1 = require("../error");
7
7
  const utils_1 = require("../utils");
8
8
  const apphosting = require("../gcp/apphosting");
9
9
  const apphosting_backends_list_1 = require("./apphosting-backends-list");
10
- exports.command = new command_1.Command("apphosting:backends:get <backendId>")
11
- .description("get backend details of a Firebase project")
12
- .option("-l, --location <location>", "app backend location", "-")
10
+ exports.command = new command_1.Command("apphosting:backends:get <backend>")
11
+ .description("print info about a Firebase App Hosting backend")
12
+ .option("-l, --location <location>", "backend location", "-")
13
13
  .before(apphosting.ensureApiEnabled)
14
- .action(async (backendId, options) => {
14
+ .action(async (backend, options) => {
15
15
  const projectId = (0, projectUtils_1.needProjectId)(options);
16
16
  const location = options.location;
17
17
  let backendsList = [];
18
18
  try {
19
19
  if (location !== "-") {
20
- const backendInRegion = await apphosting.getBackend(projectId, location, backendId);
20
+ const backendInRegion = await apphosting.getBackend(projectId, location, backend);
21
21
  backendsList.push(backendInRegion);
22
22
  }
23
23
  else {
24
24
  const resp = await apphosting.listBackends(projectId, "-");
25
25
  const allBackends = resp.backends || [];
26
- backendsList = allBackends.filter((bkd) => bkd.name.split("/").pop() === backendId);
26
+ backendsList = allBackends.filter((bkd) => bkd.name.split("/").pop() === backend);
27
27
  }
28
28
  }
29
29
  catch (err) {
30
- throw new error_1.FirebaseError(`Failed to get backend: ${backendId}. Please check the parameters you have provided.`, { original: err });
30
+ throw new error_1.FirebaseError(`Failed to get backend: ${backend}. Please check the parameters you have provided.`, { original: err });
31
31
  }
32
32
  if (backendsList.length === 0) {
33
- (0, utils_1.logWarning)(`Found no backend with id: ${backendId}`);
33
+ (0, utils_1.logWarning)(`Backend "${backend}" not found`);
34
34
  return;
35
35
  }
36
36
  (0, apphosting_backends_list_1.printBackendsTable)(backendsList);
@@ -8,10 +8,10 @@ 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
- .description("list backends of a Firebase project")
14
- .option("-l, --location <location>", "app Backend location", "-")
13
+ .description("list Firebase App Hosting backends")
14
+ .option("-l, --location <location>", "list backends in the specified location", "-")
15
15
  .before(apphosting.ensureApiEnabled)
16
16
  .action(async (options) => {
17
17
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -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
  }
@@ -0,0 +1,24 @@
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 projectUtils_1 = require("../projectUtils");
7
+ const secretManager_1 = require("../gcp/secretManager");
8
+ const requireAuth_1 = require("../requireAuth");
9
+ const secretManager = require("../gcp/secretManager");
10
+ const requirePermissions_1 = require("../requirePermissions");
11
+ exports.command = new command_1.Command("apphosting:secrets:access <secretName[@version]>")
12
+ .description("Access secret value given secret and its version. Defaults to accessing the latest version.")
13
+ .before(requireAuth_1.requireAuth)
14
+ .before(secretManager.ensureApi)
15
+ .before(requirePermissions_1.requirePermissions, ["secretmanager.versions.access"])
16
+ .action(async (key, options) => {
17
+ const projectId = (0, projectUtils_1.needProjectId)(options);
18
+ let [name, version] = key.split("@");
19
+ if (!version) {
20
+ version = "latest";
21
+ }
22
+ const value = await (0, secretManager_1.accessSecretVersion)(projectId, name, version);
23
+ logger_1.logger.info(value);
24
+ });
@@ -0,0 +1,29 @@
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 logger_1 = require("../logger");
7
+ const requireAuth_1 = require("../requireAuth");
8
+ const secretManager_1 = require("../gcp/secretManager");
9
+ const secretManager = require("../gcp/secretManager");
10
+ const requirePermissions_1 = require("../requirePermissions");
11
+ const Table = require("cli-table");
12
+ exports.command = new command_1.Command("apphosting:secrets:describe <secretName>")
13
+ .description("Get metadata for secret and its versions.")
14
+ .before(requireAuth_1.requireAuth)
15
+ .before(secretManager.ensureApi)
16
+ .before(requirePermissions_1.requirePermissions, ["secretmanager.secrets.get"])
17
+ .action(async (secretName, options) => {
18
+ const projectId = (0, projectUtils_1.needProjectId)(options);
19
+ const versions = await (0, secretManager_1.listSecretVersions)(projectId, secretName);
20
+ const table = new Table({
21
+ head: ["Name", "Version", "Status", "Create Time"],
22
+ style: { head: ["yellow"] },
23
+ });
24
+ for (const version of versions) {
25
+ table.push([secretName, version.versionId, version.state, version.createTime]);
26
+ }
27
+ logger_1.logger.info(table.toString());
28
+ return { secrets: versions };
29
+ });
@@ -0,0 +1,49 @@
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 error_1 = require("../error");
7
+ const requireAuth_1 = require("../requireAuth");
8
+ const secretManager = require("../gcp/secretManager");
9
+ const requirePermissions_1 = require("../requirePermissions");
10
+ const apphosting = require("../gcp/apphosting");
11
+ const secrets = require("../apphosting/secrets");
12
+ const apphosting_1 = require("../apphosting");
13
+ exports.command = new command_1.Command("apphosting:secrets:grantaccess <secretName>")
14
+ .description("grant service accounts permissions to the provided secret")
15
+ .option("-l, --location <location>", "backend location", "-")
16
+ .option("-b, --backend <backend>", "backend name")
17
+ .before(requireAuth_1.requireAuth)
18
+ .before(secretManager.ensureApi)
19
+ .before(apphosting.ensureApiEnabled)
20
+ .before(requirePermissions_1.requirePermissions, [
21
+ "secretmanager.secrets.create",
22
+ "secretmanager.secrets.get",
23
+ "secretmanager.secrets.update",
24
+ "secretmanager.versions.add",
25
+ "secretmanager.secrets.getIamPolicy",
26
+ "secretmanager.secrets.setIamPolicy",
27
+ ])
28
+ .action(async (secretName, options) => {
29
+ const projectId = (0, projectUtils_1.needProjectId)(options);
30
+ const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
31
+ if (!options.backend) {
32
+ throw new error_1.FirebaseError("Missing required flag --backend. See firebase apphosting:secrets:grantaccess --help for more info");
33
+ }
34
+ const exists = await secretManager.secretExists(projectId, secretName);
35
+ if (!exists) {
36
+ throw new error_1.FirebaseError(`Cannot find secret ${secretName}`);
37
+ }
38
+ const backendId = options.backend;
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
+ }
47
+ const accounts = secrets.toMulti(secrets.serviceAccountsForBackend(projectNumber, backend));
48
+ await secrets.grantSecretAccess(projectId, projectNumber, secretName, accounts);
49
+ });
@@ -0,0 +1,56 @@
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 projectUtils_1 = require("../projectUtils");
7
+ const requireAuth_1 = require("../requireAuth");
8
+ const gcsm = require("../gcp/secretManager");
9
+ const apphosting = require("../gcp/apphosting");
10
+ const requirePermissions_1 = require("../requirePermissions");
11
+ const secrets = require("../apphosting/secrets");
12
+ const dialogs = require("../apphosting/secrets/dialogs");
13
+ const config = require("../apphosting/config");
14
+ const utils = require("../utils");
15
+ exports.command = new command_1.Command("apphosting:secrets:set <secretName>")
16
+ .description("create or update a secret for use in Firebase App Hosting")
17
+ .option("-l, --location <location>", "optional location to retrict secret replication")
18
+ .withForce("Automatically create a secret, grant permissions, and add to YAML.")
19
+ .before(requireAuth_1.requireAuth)
20
+ .before(gcsm.ensureApi)
21
+ .before(apphosting.ensureApiEnabled)
22
+ .before(requirePermissions_1.requirePermissions, [
23
+ "secretmanager.secrets.create",
24
+ "secretmanager.secrets.get",
25
+ "secretmanager.secrets.update",
26
+ "secretmanager.versions.add",
27
+ "secretmanager.secrets.getIamPolicy",
28
+ "secretmanager.secrets.setIamPolicy",
29
+ ])
30
+ .option("--data-file <dataFile>", 'File path from which to read secret data. Set to "-" to read the secret data from stdin.')
31
+ .action(async (secretName, options) => {
32
+ const projectId = (0, projectUtils_1.needProjectId)(options);
33
+ const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
34
+ const created = await secrets.upsertSecret(projectId, secretName, options.location);
35
+ if (created === null) {
36
+ return;
37
+ }
38
+ else if (created) {
39
+ utils.logSuccess(`Created new secret projects/${projectId}/secrets/${secretName}`);
40
+ }
41
+ const secretValue = await utils.readSecretValue(`Enter a value for ${secretName}`, options.dataFile);
42
+ const version = await gcsm.addVersion(projectId, secretName, secretValue);
43
+ utils.logSuccess(`Created new secret version ${gcsm.toSecretVersionResourceName(version)}`);
44
+ utils.logBullet(`You can access the contents of the secret's latest value with ${clc.bold(`firebase apphosting:secrets:access ${secretName}\n`)}`);
45
+ if (!created) {
46
+ return;
47
+ }
48
+ const accounts = await dialogs.selectBackendServiceAccounts(projectNumber, projectId, options);
49
+ if (!accounts.buildServiceAccounts.length && !accounts.runServiceAccounts.length) {
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
+ }
52
+ else {
53
+ await secrets.grantSecretAccess(projectId, projectNumber, secretName, accounts);
54
+ }
55
+ await config.maybeAddSecretToYaml(secretName);
56
+ });
@@ -0,0 +1,37 @@
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 args = {
24
+ projectId,
25
+ configDir,
26
+ auto_download: true,
27
+ rc: options.rc,
28
+ locationId: service.location,
29
+ };
30
+ const dataconnectEmulator = new dataconnectEmulator_1.DataConnectEmulator(args);
31
+ for (const conn of serviceInfo.connectorInfo) {
32
+ const output = await dataconnectEmulator.generate(conn.connectorYaml.connectorId);
33
+ logger_1.logger.info(output);
34
+ logger_1.logger.info(`Generated SDKs for ${conn.connectorYaml.connectorId}`);
35
+ }
36
+ }
37
+ });
@@ -0,0 +1,80 @@
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
+ let schema = {
37
+ name: "",
38
+ primaryDatasource: {},
39
+ source: { files: [] },
40
+ };
41
+ try {
42
+ schema = await client.getSchema(service.name);
43
+ }
44
+ catch (err) {
45
+ logger_1.logger.debug(`Error fetching schema: ${err}`);
46
+ }
47
+ const connectors = await client.listConnectors(service.name);
48
+ const serviceName = names.parseServiceName(service.name);
49
+ const instanceName = schema?.primaryDatasource.postgresql?.cloudSql.instance ?? "";
50
+ const instanceId = instanceName.split("/").pop();
51
+ const dbId = schema?.primaryDatasource.postgresql?.database ?? "";
52
+ const dbName = `CloudSQL Instance: ${instanceId}\nDatabase:${dbId}`;
53
+ table.push([
54
+ serviceName.serviceId,
55
+ serviceName.location,
56
+ dbName,
57
+ schema?.updateTime ?? "",
58
+ "",
59
+ "",
60
+ ]);
61
+ const serviceJson = {
62
+ serviceId: serviceName.serviceId,
63
+ location: serviceName.location,
64
+ datasource: dbName,
65
+ schemaUpdateTime: schema?.updateTime,
66
+ connectors: [],
67
+ };
68
+ for (const conn of connectors) {
69
+ const connectorName = names.parseConnectorName(conn.name);
70
+ table.push(["", "", "", "", connectorName.connectorId, conn.updateTime]);
71
+ serviceJson.connectors.push({
72
+ connectorId: connectorName.connectorId,
73
+ connectorLastUpdated: conn.updateTime ?? "",
74
+ });
75
+ }
76
+ jsonOutput.services.push(serviceJson);
77
+ }
78
+ logger_1.logger.info(table.toString());
79
+ return jsonOutput;
80
+ });
@@ -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,45 @@
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
+ allowNonInteractiveMigration: true,
36
+ validateOnly: true,
37
+ });
38
+ if (diffs.length) {
39
+ (0, utils_1.logLabeledSuccess)("dataconnect", `Database schema sucessfully migrated! Run 'firebase deploy' to deploy your new schema to your Data Connect service.`);
40
+ }
41
+ else {
42
+ (0, utils_1.logLabeledSuccess)("dataconnect", "Database schema is already up to date!");
43
+ }
44
+ return { projectId, serviceId, diffs };
45
+ });
@@ -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) => {
@@ -52,6 +52,7 @@ exports.command = new command_1.Command("firestore:databases:create <database>")
52
52
  logger_1.logger.info("Please be sure to configure Firebase rules in your Firebase config file for\n" +
53
53
  "the new database. By default, created databases will have closed rules that\n" +
54
54
  "block any incoming third-party traffic.");
55
+ logger_1.logger.info(`Your database may be viewed at ${printer.firebaseConsoleDatabaseUrl(options.project, database)}`);
55
56
  }
56
57
  return databaseResp;
57
58
  });
@@ -37,6 +37,7 @@ exports.command = new command_1.Command("firestore:databases:restore")
37
37
  logger_1.logger.info("Please be sure to configure Firebase rules in your Firebase config file for\n" +
38
38
  "the new database. By default, created databases will have closed rules that\n" +
39
39
  "block any incoming third-party traffic.");
40
+ logger_1.logger.info(`Once the restore is complete, your database may be viewed at ${printer.firebaseConsoleDatabaseUrl(options.project, databaseId)}`);
40
41
  }
41
42
  return databaseResp;
42
43
  });
@@ -6,11 +6,11 @@ const logger_1 = require("../logger");
6
6
  const projectUtils_1 = require("../projectUtils");
7
7
  const secretManager_1 = require("../gcp/secretManager");
8
8
  const requireAuth_1 = require("../requireAuth");
9
- const secrets = require("../functions/secrets");
9
+ const secretManager = require("../gcp/secretManager");
10
10
  exports.command = new command_1.Command("functions:secrets:access <KEY>[@version]")
11
11
  .description("Access secret value given secret and its version. Defaults to accessing the latest version.")
12
12
  .before(requireAuth_1.requireAuth)
13
- .before(secrets.ensureApi)
13
+ .before(secretManager.ensureApi)
14
14
  .action(async (key, options) => {
15
15
  const projectId = (0, projectUtils_1.needProjectId)(options);
16
16
  let [name, version] = key.split("@");
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const requireAuth_1 = require("../requireAuth");
5
+ const command_1 = require("../command");
6
+ const requirePermissions_1 = require("../requirePermissions");
7
+ const secretManager = require("../gcp/secretManager");
8
+ const secrets = require("../functions/secrets");
9
+ exports.command = new command_1.Command("functions:secrets:describe <KEY>")
10
+ .description("Get metadata for secret and its versions. Alias for functions:secrets:get to align with gcloud")
11
+ .before(requireAuth_1.requireAuth)
12
+ .before(secretManager.ensureApi)
13
+ .before(requirePermissions_1.requirePermissions, ["secretmanager.secrets.get"])
14
+ .action(secrets.describeSecret);