firebase-tools-with-isolate 14.10.1 → 14.16.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 (236) hide show
  1. package/lib/api.js +5 -1
  2. package/lib/apphosting/backend.js +40 -15
  3. package/lib/apptesting/ensureProjectConfigured.js +56 -0
  4. package/lib/apptesting/invokeTests.js +40 -0
  5. package/lib/apptesting/parseTestFiles.js +75 -0
  6. package/lib/apptesting/types.js +18 -0
  7. package/lib/auth.js +37 -2
  8. package/lib/command.js +24 -5
  9. package/lib/commands/apphosting-backends-create.js +8 -5
  10. package/lib/commands/apptesting-execute.js +101 -0
  11. package/lib/commands/dataconnect-sdk-generate.js +28 -26
  12. package/lib/commands/dataconnect-services-list.js +1 -1
  13. package/lib/commands/dataconnect-sql-diff.js +2 -2
  14. package/lib/commands/dataconnect-sql-grant.js +7 -2
  15. package/lib/commands/dataconnect-sql-migrate.js +2 -2
  16. package/lib/commands/dataconnect-sql-setup.js +3 -5
  17. package/lib/commands/dataconnect-sql-shell.js +2 -2
  18. package/lib/commands/ext-export.js +1 -1
  19. package/lib/commands/firestore-bulkdelete.js +73 -0
  20. package/lib/commands/firestore-databases-create.js +11 -0
  21. package/lib/commands/firestore-operations-cancel.js +44 -0
  22. package/lib/commands/firestore-operations-describe.js +29 -0
  23. package/lib/commands/firestore-operations-list.js +29 -0
  24. package/lib/commands/firestore-utils.js +15 -0
  25. package/lib/commands/functions-config-clone.js +2 -0
  26. package/lib/commands/functions-config-export.js +5 -2
  27. package/lib/commands/functions-config-get.js +2 -0
  28. package/lib/commands/functions-config-set.js +2 -0
  29. package/lib/commands/functions-config-unset.js +2 -0
  30. package/lib/commands/index.js +9 -0
  31. package/lib/commands/init.js +24 -4
  32. package/lib/commands/internaltesting-functions-discover.js +20 -5
  33. package/lib/commands/login.js +13 -9
  34. package/lib/commands/use.js +5 -0
  35. package/lib/config.js +16 -4
  36. package/lib/crashlytics/addNote.js +27 -0
  37. package/lib/crashlytics/buildToolsJarHelper.js +1 -2
  38. package/lib/crashlytics/deleteNote.js +23 -0
  39. package/lib/crashlytics/getIssueDetails.js +26 -0
  40. package/lib/crashlytics/getSampleCrash.js +34 -0
  41. package/lib/crashlytics/listNotes.js +29 -0
  42. package/lib/crashlytics/listTopDevices.js +33 -0
  43. package/lib/crashlytics/listTopIssues.js +8 -23
  44. package/lib/crashlytics/listTopOperatingSystems.js +32 -0
  45. package/lib/crashlytics/listTopVersions.js +32 -0
  46. package/lib/crashlytics/updateIssue.js +35 -0
  47. package/lib/crashlytics/utils.js +38 -0
  48. package/lib/dataconnect/appFinder.js +102 -0
  49. package/lib/dataconnect/client.js +23 -15
  50. package/lib/dataconnect/ensureApis.js +6 -9
  51. package/lib/dataconnect/errors.js +7 -1
  52. package/lib/dataconnect/freeTrial.js +16 -38
  53. package/lib/dataconnect/load.js +105 -6
  54. package/lib/dataconnect/provisionCloudSql.js +67 -70
  55. package/lib/dataconnect/schemaMigration.js +219 -169
  56. package/lib/deploy/dataconnect/deploy.js +7 -9
  57. package/lib/deploy/dataconnect/prepare.js +7 -12
  58. package/lib/deploy/dataconnect/release.js +43 -31
  59. package/lib/deploy/firestore/deploy.js +10 -0
  60. package/lib/deploy/functions/backend.js +7 -1
  61. package/lib/deploy/functions/build.js +28 -14
  62. package/lib/deploy/functions/deploy.js +3 -2
  63. package/lib/deploy/functions/ensure.js +1 -1
  64. package/lib/deploy/functions/functionsDeployHelper.js +8 -1
  65. package/lib/deploy/functions/params.js +4 -0
  66. package/lib/deploy/functions/prepare.js +25 -13
  67. package/lib/deploy/functions/pricing.js +12 -5
  68. package/lib/deploy/functions/release/fabricator.js +25 -3
  69. package/lib/deploy/functions/release/reporter.js +1 -0
  70. package/lib/deploy/functions/runtimes/discovery/index.js +52 -5
  71. package/lib/deploy/functions/runtimes/node/index.js +83 -51
  72. package/lib/emulator/auth/operations.js +10 -1
  73. package/lib/emulator/commandUtils.js +7 -1
  74. package/lib/emulator/controller.js +22 -34
  75. package/lib/emulator/dataconnectEmulator.js +27 -24
  76. package/lib/emulator/downloadableEmulatorInfo.json +18 -18
  77. package/lib/emulator/env.js +2 -1
  78. package/lib/emulator/functionsEmulator.js +12 -2
  79. package/lib/emulator/hub.js +11 -8
  80. package/lib/emulator/tasksEmulator.js +1 -1
  81. package/lib/emulator/ui.js +3 -1
  82. package/lib/env.js +18 -0
  83. package/lib/experiments.js +20 -0
  84. package/lib/extensions/extensionsHelper.js +4 -15
  85. package/lib/extensions/runtimes/common.js +3 -2
  86. package/lib/extensions/utils.js +1 -12
  87. package/lib/firestore/api-sort.js +96 -3
  88. package/lib/firestore/api-types.js +20 -1
  89. package/lib/firestore/api.js +144 -15
  90. package/lib/firestore/pretty-print.js +35 -1
  91. package/lib/firestore/validator.js +1 -1
  92. package/lib/functional.js +7 -1
  93. package/lib/functions/deprecationWarnings.js +21 -0
  94. package/lib/functions/env.js +31 -16
  95. package/lib/functions/projectConfig.js +87 -8
  96. package/lib/functions/secrets.js +3 -0
  97. package/lib/gcp/cloudfunctions.js +1 -6
  98. package/lib/gcp/cloudfunctionsv2.js +3 -39
  99. package/lib/gcp/cloudscheduler.js +1 -1
  100. package/lib/gcp/cloudsql/cloudsqladmin.js +4 -16
  101. package/lib/gcp/cloudsql/connect.js +4 -3
  102. package/lib/gcp/cloudsql/permissionsSetup.js +23 -16
  103. package/lib/gcp/k8s.js +32 -0
  104. package/lib/gcp/runv2.js +181 -0
  105. package/lib/gemini/fdcExperience.js +5 -3
  106. package/lib/init/features/aitools/claude.js +43 -0
  107. package/lib/init/features/aitools/cursor.js +61 -0
  108. package/lib/init/features/aitools/gemini.js +58 -0
  109. package/lib/init/features/aitools/index.js +28 -0
  110. package/lib/init/features/aitools/promptUpdater.js +111 -0
  111. package/lib/init/features/aitools/studio.js +17 -0
  112. package/lib/init/features/aitools/types.js +2 -0
  113. package/lib/init/features/aitools.js +83 -0
  114. package/lib/init/features/apptesting/index.js +34 -0
  115. package/lib/init/features/dataconnect/create_app.js +53 -0
  116. package/lib/init/features/dataconnect/index.js +280 -186
  117. package/lib/init/features/dataconnect/sdk.js +232 -144
  118. package/lib/init/features/index.js +8 -3
  119. package/lib/init/features/project.js +4 -0
  120. package/lib/init/index.js +18 -2
  121. package/lib/management/apps.js +3 -3
  122. package/lib/management/studio.js +120 -0
  123. package/lib/mcp/errors.js +5 -7
  124. package/lib/mcp/index.js +179 -61
  125. package/lib/mcp/logging-transport.js +23 -0
  126. package/lib/mcp/prompt.js +10 -0
  127. package/lib/mcp/prompts/core/deploy.js +101 -0
  128. package/lib/mcp/prompts/core/index.js +5 -0
  129. package/lib/mcp/prompts/crashlytics/connect.js +114 -0
  130. package/lib/mcp/prompts/crashlytics/index.js +5 -0
  131. package/lib/mcp/prompts/dataconnect/index.js +9 -0
  132. package/lib/mcp/prompts/dataconnect/schema.js +67 -0
  133. package/lib/mcp/prompts/index.js +47 -0
  134. package/lib/mcp/tools/apphosting/fetch_logs.js +22 -22
  135. package/lib/mcp/tools/apphosting/list_backends.js +10 -10
  136. package/lib/mcp/tools/auth/disable_user.js +7 -7
  137. package/lib/mcp/tools/auth/get_user.js +13 -6
  138. package/lib/mcp/tools/auth/index.js +10 -10
  139. package/lib/mcp/tools/auth/list_users.js +6 -6
  140. package/lib/mcp/tools/auth/set_claims.js +7 -7
  141. package/lib/mcp/tools/auth/set_sms_region_policy.js +6 -6
  142. package/lib/mcp/tools/core/consult_assistant.js +13 -8
  143. package/lib/mcp/tools/core/create_android_sha.js +9 -9
  144. package/lib/mcp/tools/core/create_app.js +7 -7
  145. package/lib/mcp/tools/core/create_project.js +13 -13
  146. package/lib/mcp/tools/core/get_admin_sdk_config.js +7 -7
  147. package/lib/mcp/tools/core/get_environment.js +8 -8
  148. package/lib/mcp/tools/core/get_project.js +5 -5
  149. package/lib/mcp/tools/core/get_sdk_config.js +19 -9
  150. package/lib/mcp/tools/core/index.js +28 -24
  151. package/lib/mcp/tools/core/init.js +39 -16
  152. package/lib/mcp/tools/core/list_apps.js +6 -6
  153. package/lib/mcp/tools/core/list_projects.js +6 -6
  154. package/lib/mcp/tools/core/login.js +46 -0
  155. package/lib/mcp/tools/core/logout.js +62 -0
  156. package/lib/mcp/tools/core/update_environment.js +10 -10
  157. package/lib/mcp/tools/crashlytics/add_note.js +32 -0
  158. package/lib/mcp/tools/crashlytics/constants.js +11 -0
  159. package/lib/mcp/tools/crashlytics/delete_note.js +35 -0
  160. package/lib/mcp/tools/crashlytics/get_issue_details.js +31 -0
  161. package/lib/mcp/tools/crashlytics/get_sample_crash.js +43 -0
  162. package/lib/mcp/tools/crashlytics/index.js +22 -2
  163. package/lib/mcp/tools/crashlytics/list_notes.js +37 -0
  164. package/lib/mcp/tools/crashlytics/list_top_devices.js +33 -0
  165. package/lib/mcp/tools/crashlytics/list_top_issues.js +12 -13
  166. package/lib/mcp/tools/crashlytics/list_top_operating_systems.js +33 -0
  167. package/lib/mcp/tools/crashlytics/list_top_versions.js +33 -0
  168. package/lib/mcp/tools/crashlytics/update_issue.js +37 -0
  169. package/lib/mcp/tools/database/get_data.js +49 -0
  170. package/lib/mcp/tools/database/get_rules.js +39 -0
  171. package/lib/mcp/tools/database/index.js +8 -0
  172. package/lib/mcp/tools/database/set_data.js +57 -0
  173. package/lib/mcp/tools/database/validate_rules.js +41 -0
  174. package/lib/mcp/tools/dataconnect/compile.js +43 -0
  175. package/lib/mcp/tools/dataconnect/execute.js +71 -0
  176. package/lib/mcp/tools/dataconnect/generate_operation.js +8 -8
  177. package/lib/mcp/tools/dataconnect/generate_schema.js +6 -6
  178. package/lib/mcp/tools/dataconnect/index.js +10 -18
  179. package/lib/mcp/tools/dataconnect/list_services.js +107 -11
  180. package/lib/mcp/tools/firestore/delete_document.js +13 -13
  181. package/lib/mcp/tools/firestore/get_documents.js +13 -13
  182. package/lib/mcp/tools/firestore/list_collections.js +7 -10
  183. package/lib/mcp/tools/firestore/query_collection.js +13 -13
  184. package/lib/mcp/tools/index.js +24 -18
  185. package/lib/mcp/tools/messaging/index.js +2 -2
  186. package/lib/mcp/tools/messaging/send_message.js +7 -7
  187. package/lib/mcp/tools/remoteconfig/get_template.js +5 -5
  188. package/lib/mcp/tools/remoteconfig/index.js +4 -4
  189. package/lib/mcp/tools/remoteconfig/publish_template.js +7 -7
  190. package/lib/mcp/tools/remoteconfig/rollback_template.js +6 -6
  191. package/lib/mcp/tools/rules/get_rules.js +8 -8
  192. package/lib/mcp/tools/rules/validate_rules.js +10 -10
  193. package/lib/mcp/tools/storage/get_download_url.js +8 -8
  194. package/lib/mcp/tools/storage/get_rules.js +8 -8
  195. package/lib/mcp/types.js +2 -0
  196. package/lib/mcp/util/dataconnect/compile.js +20 -0
  197. package/lib/mcp/util/dataconnect/content.js +655 -0
  198. package/lib/mcp/util/dataconnect/emulator.js +16 -0
  199. package/lib/mcp/util.js +5 -18
  200. package/lib/requireAuth.js +14 -4
  201. package/lib/rtdb.js +10 -6
  202. package/lib/scopes.js +2 -1
  203. package/lib/serve/functions.js +4 -3
  204. package/lib/timeout.js +21 -0
  205. package/lib/track.js +18 -1
  206. package/lib/unzip.js +13 -0
  207. package/lib/utils.js +76 -2
  208. package/package.json +6 -4
  209. package/prompts/FIREBASE.md +121 -0
  210. package/prompts/FIREBASE_FUNCTIONS.md +221 -0
  211. package/schema/apptesting-yaml.json +64 -0
  212. package/schema/firebase-config.json +163 -53
  213. package/templates/init/aitools/cursor-rules-header.txt +8 -0
  214. package/templates/init/aitools/gemini-extension.json +11 -0
  215. package/templates/init/apptesting/smoke_test.yaml +6 -0
  216. package/templates/init/dataconnect/connector.yaml +0 -16
  217. package/templates/init/dataconnect/dataconnect.yaml +2 -1
  218. package/templates/init/dataconnect/mutations.gql +29 -29
  219. package/templates/init/dataconnect/queries.gql +73 -73
  220. package/templates/init/dataconnect/schema.gql +48 -48
  221. package/templates/init/firestore/firestore.indexes.json +26 -1
  222. package/lib/dataconnect/fileUtils.js +0 -168
  223. package/lib/emulator/adminSdkConfig.test.js +0 -16
  224. package/lib/extensions/resolveSource.js +0 -23
  225. package/lib/firestore/api-sort.test.js +0 -74
  226. package/lib/firestore/backupUtils.test.js +0 -18
  227. package/lib/firestore/pretty-print.test.js +0 -61
  228. package/lib/firestore/util.test.js +0 -42
  229. package/lib/mcp/tools/dataconnect/emulator.js +0 -16
  230. package/lib/mcp/tools/dataconnect/execute_graphql.js +0 -48
  231. package/lib/mcp/tools/dataconnect/execute_graphql_read.js +0 -48
  232. package/lib/mcp/tools/dataconnect/execute_mutation.js +0 -62
  233. package/lib/mcp/tools/dataconnect/execute_query.js +0 -62
  234. package/lib/mcp/tools/dataconnect/get_connector.js +0 -31
  235. package/lib/mcp/tools/dataconnect/get_schema.js +0 -31
  236. /package/lib/mcp/{tools → util}/dataconnect/converter.js +0 -0
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.upgradeInstructions = exports.printFreeTrialUnavailable = exports.isFreeTrialError = exports.getFreeTrialInstanceId = exports.checkFreeTrialInstanceUsed = exports.freeTrialTermsLink = void 0;
3
+ exports.upgradeInstructions = exports.checkFreeTrialInstanceUsed = exports.freeTrialTermsLink = void 0;
4
4
  const clc = require("colorette");
5
5
  const cloudmonitoring_1 = require("../gcp/cloudmonitoring");
6
- const cloudsqladmin_1 = require("../gcp/cloudsql/cloudsqladmin");
7
6
  const utils = require("../utils");
8
7
  function freeTrialTermsLink() {
9
8
  return "https://firebase.google.com/pricing";
@@ -11,7 +10,6 @@ function freeTrialTermsLink() {
11
10
  exports.freeTrialTermsLink = freeTrialTermsLink;
12
11
  const FREE_TRIAL_METRIC = "sqladmin.googleapis.com/fdc_lifetime_free_trial_per_project";
13
12
  async function checkFreeTrialInstanceUsed(projectId) {
14
- utils.logLabeledBullet("dataconnect", "Checking Cloud SQL no cost trial eligibility...");
15
13
  const past7d = new Date();
16
14
  past7d.setDate(past7d.getDate() - 7);
17
15
  const query = {
@@ -19,52 +17,32 @@ async function checkFreeTrialInstanceUsed(projectId) {
19
17
  "interval.endTime": new Date().toJSON(),
20
18
  "interval.startTime": past7d.toJSON(),
21
19
  };
20
+ let used = true;
22
21
  try {
23
22
  const ts = await (0, cloudmonitoring_1.queryTimeSeries)(query, projectId);
24
- let used = true;
25
23
  if (ts.length) {
26
24
  used = ts[0].points.some((p) => p.value.int64Value);
27
25
  }
28
- if (used) {
29
- utils.logLabeledWarning("dataconnect", "CloudSQL no cost trial has already been used on this project.");
30
- }
31
- return used;
32
26
  }
33
27
  catch (err) {
28
+ used = false;
29
+ }
30
+ if (used) {
31
+ utils.logLabeledWarning("dataconnect", "CloudSQL no cost trial has already been used on this project.");
32
+ }
33
+ else {
34
34
  utils.logLabeledSuccess("dataconnect", "CloudSQL no cost trial available!");
35
- return false;
36
35
  }
36
+ return used;
37
37
  }
38
38
  exports.checkFreeTrialInstanceUsed = checkFreeTrialInstanceUsed;
39
- async function getFreeTrialInstanceId(projectId) {
40
- const instances = await (0, cloudsqladmin_1.listInstances)(projectId);
41
- return instances.find((i) => i.settings.userLabels?.["firebase-data-connect"] === "ft")?.name;
42
- }
43
- exports.getFreeTrialInstanceId = getFreeTrialInstanceId;
44
- async function isFreeTrialError(err, projectId) {
45
- return err.message.includes("Quota Exhausted") && (await checkFreeTrialInstanceUsed(projectId))
46
- ? true
47
- : false;
48
- }
49
- exports.isFreeTrialError = isFreeTrialError;
50
- function printFreeTrialUnavailable(projectId, configYamlPath, instanceId) {
51
- if (!instanceId) {
52
- utils.logLabeledError("dataconnect", "The CloudSQL free trial has already been used on this project.");
53
- utils.logLabeledError("dataconnect", `You may create or use a paid CloudSQL instance by visiting https://console.cloud.google.com/sql/instances`);
54
- return;
55
- }
56
- utils.logLabeledError("dataconnect", `Project '${projectId} already has a CloudSQL instance '${instanceId}' on the Firebase Data Connect no-cost trial.`);
57
- const reuseHint = `To use a different database in the same instance, ${clc.bold(`change the ${clc.blue("instanceId")} to "${instanceId}"`)} and update ${clc.blue("location")} in ` +
58
- `${clc.green(configYamlPath)}.`;
59
- utils.logLabeledError("dataconnect", reuseHint);
60
- utils.logLabeledError("dataconnect", `Alternatively, you may create a new (paid) CloudSQL instance at https://console.cloud.google.com/sql/instances`);
61
- }
62
- exports.printFreeTrialUnavailable = printFreeTrialUnavailable;
63
39
  function upgradeInstructions(projectId) {
64
- return `If you'd like to provision a CloudSQL Postgres instance on the Firebase Data Connect no-cost trial:
65
- 1. Please upgrade to the pay-as-you-go (Blaze) billing plan. Visit the following page:
66
- https://console.firebase.google.com/project/${projectId}/usage/details
67
- 2. Run ${clc.bold("firebase init dataconnect")} again to configure the Cloud SQL instance.
68
- 3. Run ${clc.bold("firebase deploy --only dataconnect")} to deploy your Data Connect service.`;
40
+ return `To provision a CloudSQL Postgres instance on the Firebase Data Connect no-cost trial:
41
+
42
+ 1. Please upgrade to the pay-as-you-go (Blaze) billing plan. Visit the following page:
43
+
44
+ https://console.firebase.google.com/project/${projectId}/usage/details
45
+
46
+ 2. Run ${clc.bold("firebase deploy --only dataconnect")} to deploy your Data Connect service.`;
69
47
  }
70
48
  exports.upgradeInstructions = upgradeInstructions;
@@ -1,19 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.load = void 0;
3
+ exports.readConnectorYaml = exports.readDataConnectYaml = exports.readFirebaseJson = exports.load = exports.loadAll = exports.pickService = void 0;
4
4
  const path = require("path");
5
- const fileUtils = require("./fileUtils");
5
+ const fs = require("fs-extra");
6
+ const clc = require("colorette");
7
+ const glob_1 = require("glob");
8
+ const error_1 = require("../error");
6
9
  const types_1 = require("./types");
10
+ const utils_1 = require("../utils");
11
+ async function pickService(projectId, config, serviceId) {
12
+ const serviceInfos = await loadAll(projectId, config);
13
+ if (serviceInfos.length === 0) {
14
+ throw new error_1.FirebaseError("No Data Connect services found in firebase.json." +
15
+ `\nYou can run ${clc.bold("firebase init dataconnect")} to add a Data Connect service.`);
16
+ }
17
+ else if (serviceInfos.length === 1) {
18
+ if (serviceId && serviceId !== serviceInfos[0].dataConnectYaml.serviceId) {
19
+ throw new error_1.FirebaseError(`No service named ${serviceId} declared in firebase.json. Found ${serviceInfos[0].dataConnectYaml.serviceId}.` +
20
+ `\nYou can run ${clc.bold("firebase init dataconnect")} to add this Data Connect service.`);
21
+ }
22
+ return serviceInfos[0];
23
+ }
24
+ else {
25
+ if (!serviceId) {
26
+ throw new error_1.FirebaseError("Multiple Data Connect services found in firebase.json. Please specify a service ID to use.");
27
+ }
28
+ const maybe = serviceInfos.find((i) => i.dataConnectYaml.serviceId === serviceId);
29
+ if (!maybe) {
30
+ const serviceIds = serviceInfos.map((i) => i.dataConnectYaml.serviceId);
31
+ throw new error_1.FirebaseError(`No service named ${serviceId} declared in firebase.json. Found ${serviceIds.join(", ")}.` +
32
+ `\nYou can run ${clc.bold("firebase init dataconnect")} to add this Data Connect service.`);
33
+ }
34
+ return maybe;
35
+ }
36
+ }
37
+ exports.pickService = pickService;
38
+ async function loadAll(projectId, config) {
39
+ const serviceCfgs = readFirebaseJson(config);
40
+ return await Promise.all(serviceCfgs.map((c) => load(projectId, config, c.source)));
41
+ }
42
+ exports.loadAll = loadAll;
7
43
  async function load(projectId, config, sourceDirectory) {
8
44
  const resolvedDir = config.path(sourceDirectory);
9
- const dataConnectYaml = await fileUtils.readDataConnectYaml(resolvedDir);
45
+ const dataConnectYaml = await readDataConnectYaml(resolvedDir);
10
46
  const serviceName = `projects/${projectId}/locations/${dataConnectYaml.location}/services/${dataConnectYaml.serviceId}`;
11
47
  const schemaDir = path.join(resolvedDir, dataConnectYaml.schema.source);
12
- const schemaGQLs = await fileUtils.readGQLFiles(schemaDir);
48
+ const schemaGQLs = await readGQLFiles(schemaDir);
13
49
  const connectorInfo = await Promise.all(dataConnectYaml.connectorDirs.map(async (dir) => {
14
50
  const connectorDir = path.join(resolvedDir, dir);
15
- const connectorYaml = await fileUtils.readConnectorYaml(connectorDir);
16
- const connectorGqls = await fileUtils.readGQLFiles(connectorDir);
51
+ const connectorYaml = await readConnectorYaml(connectorDir);
52
+ const connectorGqls = await readGQLFiles(connectorDir);
17
53
  return {
18
54
  directory: connectorDir,
19
55
  connectorYaml,
@@ -42,3 +78,66 @@ async function load(projectId, config, sourceDirectory) {
42
78
  };
43
79
  }
44
80
  exports.load = load;
81
+ function readFirebaseJson(config) {
82
+ if (!config?.has("dataconnect")) {
83
+ return [];
84
+ }
85
+ const validator = (cfg) => {
86
+ if (!cfg["source"]) {
87
+ throw new error_1.FirebaseError("Invalid firebase.json: DataConnect requires `source`");
88
+ }
89
+ return {
90
+ source: cfg["source"],
91
+ };
92
+ };
93
+ const configs = config.get("dataconnect");
94
+ if (typeof configs === "object" && !Array.isArray(configs)) {
95
+ return [validator(configs)];
96
+ }
97
+ else if (Array.isArray(configs)) {
98
+ return configs.map(validator);
99
+ }
100
+ else {
101
+ throw new error_1.FirebaseError("Invalid firebase.json: dataconnect should be of the form { source: string }");
102
+ }
103
+ }
104
+ exports.readFirebaseJson = readFirebaseJson;
105
+ async function readDataConnectYaml(sourceDirectory) {
106
+ const file = await (0, utils_1.readFileFromDirectory)(sourceDirectory, "dataconnect.yaml");
107
+ const dataconnectYaml = await (0, utils_1.wrappedSafeLoad)(file.source);
108
+ return validateDataConnectYaml(dataconnectYaml);
109
+ }
110
+ exports.readDataConnectYaml = readDataConnectYaml;
111
+ function validateDataConnectYaml(unvalidated) {
112
+ if (!unvalidated["location"]) {
113
+ throw new error_1.FirebaseError("Missing required field 'location' in dataconnect.yaml");
114
+ }
115
+ return unvalidated;
116
+ }
117
+ async function readConnectorYaml(sourceDirectory) {
118
+ const file = await (0, utils_1.readFileFromDirectory)(sourceDirectory, "connector.yaml");
119
+ const connectorYaml = await (0, utils_1.wrappedSafeLoad)(file.source);
120
+ return validateConnectorYaml(connectorYaml);
121
+ }
122
+ exports.readConnectorYaml = readConnectorYaml;
123
+ function validateConnectorYaml(unvalidated) {
124
+ return unvalidated;
125
+ }
126
+ async function readGQLFiles(sourceDir) {
127
+ if (!fs.existsSync(sourceDir)) {
128
+ return [];
129
+ }
130
+ const files = await (0, glob_1.glob)("**/*.{gql,graphql}", { cwd: sourceDir, absolute: true, nodir: true });
131
+ return files.map((f) => toFile(sourceDir, f));
132
+ }
133
+ function toFile(sourceDir, fullPath) {
134
+ const relPath = path.relative(sourceDir, fullPath);
135
+ if (!fs.existsSync(fullPath)) {
136
+ throw new error_1.FirebaseError(`file ${fullPath} not found`);
137
+ }
138
+ const content = fs.readFileSync(fullPath).toString();
139
+ return {
140
+ path: relPath,
141
+ content,
142
+ };
143
+ }
@@ -1,95 +1,98 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUpdateReason = exports.provisionCloudSql = void 0;
3
+ exports.getUpdateReason = exports.cloudSQLBeingCreated = exports.setupCloudSql = void 0;
4
4
  const cloudSqlAdminClient = require("../gcp/cloudsql/cloudsqladmin");
5
5
  const utils = require("../utils");
6
6
  const checkIam_1 = require("./checkIam");
7
7
  const utils_1 = require("../utils");
8
8
  const logger_1 = require("../logger");
9
- const GOOGLE_ML_INTEGRATION_ROLE = "roles/aiplatform.user";
10
9
  const freeTrial_1 = require("./freeTrial");
11
- async function provisionCloudSql(args) {
12
- let connectionName = "";
13
- const { projectId, location, instanceId, databaseId, enableGoogleMlIntegration, waitForCreation, silent, dryRun, } = args;
10
+ const GOOGLE_ML_INTEGRATION_ROLE = "roles/aiplatform.user";
11
+ async function setupCloudSql(args) {
12
+ await upsertInstance({ ...args });
13
+ const { projectId, instanceId, requireGoogleMlIntegration, dryRun } = args;
14
+ if (requireGoogleMlIntegration && !dryRun) {
15
+ await (0, checkIam_1.grantRolesToCloudSqlServiceAccount)(projectId, instanceId, [GOOGLE_ML_INTEGRATION_ROLE]);
16
+ }
17
+ }
18
+ exports.setupCloudSql = setupCloudSql;
19
+ async function upsertInstance(args) {
20
+ const { projectId, instanceId, requireGoogleMlIntegration, dryRun } = args;
14
21
  try {
15
22
  const existingInstance = await cloudSqlAdminClient.getInstance(projectId, instanceId);
16
- silent || utils.logLabeledBullet("dataconnect", `Found existing instance ${instanceId}.`);
17
- connectionName = existingInstance?.connectionName || "";
18
- const why = getUpdateReason(existingInstance, enableGoogleMlIntegration);
23
+ utils.logLabeledBullet("dataconnect", `Found existing Cloud SQL instance ${instanceId}.`);
24
+ const why = getUpdateReason(existingInstance, requireGoogleMlIntegration);
19
25
  if (why) {
20
- const cta = dryRun
21
- ? `It will be updated on your next deploy.`
22
- : `Updating instance. This may take a few minutes...`;
23
- silent ||
24
- utils.logLabeledBullet("dataconnect", `Instance ${instanceId} settings not compatible with Firebase Data Connect. ` + cta + why);
25
- if (!dryRun) {
26
- await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.updateInstanceForDataConnect(existingInstance, enableGoogleMlIntegration), "Updating your instance...");
27
- silent || utils.logLabeledBullet("dataconnect", "Instance updated");
26
+ if (dryRun) {
27
+ utils.logLabeledBullet("dataconnect", `Cloud SQL instance ${instanceId} settings not compatible with Firebase Data Connect. ` +
28
+ `It will be updated on your next deploy.` +
29
+ why);
30
+ }
31
+ else {
32
+ utils.logLabeledBullet("dataconnect", `Cloud SQL instance ${instanceId} settings not compatible with Firebase Data Connect. ` +
33
+ why);
34
+ await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.updateInstanceForDataConnect(existingInstance, requireGoogleMlIntegration), "Updating your Cloud SQL instance...");
28
35
  }
29
36
  }
37
+ await upsertDatabase({ ...args });
30
38
  }
31
39
  catch (err) {
32
40
  if (err.status !== 404) {
33
41
  throw err;
34
42
  }
35
- cmekWarning();
36
- const cta = dryRun ? "It will be created on your next deploy" : "Creating it now.";
37
- const freeTrialUsed = await (0, freeTrial_1.checkFreeTrialInstanceUsed)(projectId);
38
- silent ||
39
- utils.logLabeledBullet("dataconnect", `CloudSQL instance '${instanceId}' not found.` + cta + freeTrialUsed
40
- ? ""
41
- : `\nThis instance is provided under the terms of the Data Connect no-cost trial ${(0, freeTrial_1.freeTrialTermsLink)()}` +
42
- dryRun
43
- ? `\nMonitor the progress at ${cloudSqlAdminClient.instanceConsoleLink(projectId, instanceId)}`
44
- : "");
45
- if (!dryRun) {
46
- const newInstance = await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.createInstance({
47
- projectId,
48
- location,
49
- instanceId,
50
- enableGoogleMlIntegration,
51
- waitForCreation,
52
- freeTrial: !freeTrialUsed,
53
- }), "Creating your instance...");
54
- if (newInstance) {
55
- silent || utils.logLabeledBullet("dataconnect", "Instance created");
56
- connectionName = newInstance?.connectionName || "";
57
- }
58
- else {
59
- silent ||
60
- utils.logLabeledBullet("dataconnect", "Cloud SQL instance creation started - it should be ready shortly. Database and users will be created on your next deploy.");
61
- return connectionName;
62
- }
63
- }
43
+ await createInstance({ ...args });
44
+ }
45
+ }
46
+ async function createInstance(args) {
47
+ const { projectId, location, instanceId, requireGoogleMlIntegration, dryRun } = args;
48
+ const freeTrialUsed = await (0, freeTrial_1.checkFreeTrialInstanceUsed)(projectId);
49
+ if (dryRun) {
50
+ utils.logLabeledBullet("dataconnect", `Cloud SQL Instance ${instanceId} not found. It will be created on your next deploy.`);
51
+ }
52
+ else {
53
+ await cloudSqlAdminClient.createInstance({
54
+ projectId,
55
+ location,
56
+ instanceId,
57
+ enableGoogleMlIntegration: requireGoogleMlIntegration,
58
+ freeTrial: !freeTrialUsed,
59
+ });
60
+ utils.logLabeledBullet("dataconnect", cloudSQLBeingCreated(projectId, instanceId, !freeTrialUsed));
64
61
  }
62
+ }
63
+ function cloudSQLBeingCreated(projectId, instanceId, includeFreeTrialToS) {
64
+ return (`Cloud SQL Instance ${instanceId} is being created.` +
65
+ (includeFreeTrialToS
66
+ ? `\nThis instance is provided under the terms of the Data Connect no-cost trial ${(0, freeTrial_1.freeTrialTermsLink)()}`
67
+ : "") +
68
+ `
69
+ Meanwhile, your data are saved in a temporary database and will be migrated once complete. Monitor its progress at
70
+
71
+ ${cloudSqlAdminClient.instanceConsoleLink(projectId, instanceId)}
72
+ `);
73
+ }
74
+ exports.cloudSQLBeingCreated = cloudSQLBeingCreated;
75
+ async function upsertDatabase(args) {
76
+ const { projectId, instanceId, databaseId, dryRun } = args;
65
77
  try {
66
78
  await cloudSqlAdminClient.getDatabase(projectId, instanceId, databaseId);
67
- silent || utils.logLabeledBullet("dataconnect", `Found existing database ${databaseId}.`);
79
+ utils.logLabeledBullet("dataconnect", `Found existing Postgres Database ${databaseId}.`);
68
80
  }
69
81
  catch (err) {
70
- if (err.status === 404) {
71
- if (dryRun) {
72
- silent ||
73
- utils.logLabeledBullet("dataconnect", `Database ${databaseId} not found. It will be created on your next deploy.`);
74
- }
75
- else {
76
- silent ||
77
- utils.logLabeledBullet("dataconnect", `Database ${databaseId} not found, creating it now...`);
78
- await cloudSqlAdminClient.createDatabase(projectId, instanceId, databaseId);
79
- silent || utils.logLabeledBullet("dataconnect", `Database ${databaseId} created.`);
80
- }
82
+ if (err.status !== 404) {
83
+ logger_1.logger.debug(`Unexpected error from Cloud SQL: ${err}`);
84
+ utils.logLabeledWarning("dataconnect", `Postgres Database ${databaseId} is not accessible.`);
85
+ return;
86
+ }
87
+ if (dryRun) {
88
+ utils.logLabeledBullet("dataconnect", `Postgres Database ${databaseId} not found. It will be created on your next deploy.`);
81
89
  }
82
90
  else {
83
- logger_1.logger.debug(`Unexpected error from CloudSQL: ${err}`);
84
- silent || utils.logLabeledWarning("dataconnect", `Database ${databaseId} is not accessible.`);
91
+ await cloudSqlAdminClient.createDatabase(projectId, instanceId, databaseId);
92
+ utils.logLabeledBullet("dataconnect", `Postgres Database ${databaseId} created.`);
85
93
  }
86
94
  }
87
- if (enableGoogleMlIntegration && !dryRun) {
88
- await (0, checkIam_1.grantRolesToCloudSqlServiceAccount)(projectId, instanceId, [GOOGLE_ML_INTEGRATION_ROLE]);
89
- }
90
- return connectionName;
91
95
  }
92
- exports.provisionCloudSql = provisionCloudSql;
93
96
  function getUpdateReason(instance, requireGoogleMlIntegration) {
94
97
  let reason = "";
95
98
  const settings = instance.settings;
@@ -111,9 +114,3 @@ function getUpdateReason(instance, requireGoogleMlIntegration) {
111
114
  return reason;
112
115
  }
113
116
  exports.getUpdateReason = getUpdateReason;
114
- function cmekWarning() {
115
- const message = "Cloud SQL instances created via the Firebase CLI do not support customer managed encryption keys.\n" +
116
- "If you'd like to use a CMEK to encrypt your data, first create a CMEK encrypted instance (https://cloud.google.com/sql/docs/postgres/configure-cmek#createcmekinstance).\n" +
117
- "Then, edit your `dataconnect.yaml` file to use the encrypted instance and redeploy.";
118
- utils.logLabeledWarning("dataconnect", message);
119
- }