firebase-tools-with-isolate 13.15.0-0 → 13.26.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 (235) hide show
  1. package/lib/api.js +3 -1
  2. package/lib/apiv2.js +10 -3
  3. package/lib/appdistribution/client.js +62 -8
  4. package/lib/appdistribution/distribution.js +1 -1
  5. package/lib/apphosting/backend.js +299 -0
  6. package/lib/apphosting/config.js +31 -8
  7. package/lib/apphosting/githubConnections.js +70 -22
  8. package/lib/apphosting/index.js +3 -312
  9. package/lib/apphosting/rollout.js +138 -0
  10. package/lib/apphosting/secrets/index.js +70 -5
  11. package/lib/apphosting/utils.js +41 -0
  12. package/lib/apphosting/yaml.js +82 -0
  13. package/lib/archiveDirectory.js +1 -1
  14. package/lib/auth.js +31 -5
  15. package/lib/bin/firebase.js +2 -2
  16. package/lib/command.js +18 -4
  17. package/lib/commands/appdistribution-distribute.js +4 -4
  18. package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
  19. package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
  20. package/lib/commands/appdistribution-groups-list.js +55 -0
  21. package/lib/commands/appdistribution-testers-list.js +52 -0
  22. package/lib/commands/appdistribution-testers-remove.js +1 -1
  23. package/lib/commands/apphosting-backends-create.js +4 -4
  24. package/lib/commands/apphosting-backends-delete.js +7 -15
  25. package/lib/commands/apphosting-backends-get.js +1 -1
  26. package/lib/commands/apphosting-config-export.js +51 -0
  27. package/lib/commands/apphosting-repos-create.js +23 -0
  28. package/lib/commands/apphosting-rollouts-create.js +14 -15
  29. package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
  30. package/lib/commands/database-import.js +4 -2
  31. package/lib/commands/database-push.js +4 -2
  32. package/lib/commands/database-set.js +4 -2
  33. package/lib/commands/database-settings-get.js +1 -1
  34. package/lib/commands/database-settings-set.js +1 -1
  35. package/lib/commands/dataconnect-sdk-generate.js +4 -1
  36. package/lib/commands/dataconnect-services-list.js +4 -3
  37. package/lib/commands/dataconnect-sql-diff.js +1 -1
  38. package/lib/commands/dataconnect-sql-grant.js +37 -0
  39. package/lib/commands/dataconnect-sql-migrate.js +1 -1
  40. package/lib/commands/dataconnect-sql-shell.js +115 -0
  41. package/lib/commands/deploy.js +5 -1
  42. package/lib/commands/emulators-start.js +4 -1
  43. package/lib/commands/ext-dev-init.js +2 -2
  44. package/lib/commands/ext-dev-list.js +1 -1
  45. package/lib/commands/ext-dev-register.js +2 -2
  46. package/lib/commands/ext-dev-upload.js +2 -2
  47. package/lib/commands/ext-dev-usage.js +2 -2
  48. package/lib/commands/ext-info.js +3 -1
  49. package/lib/commands/ext-install.js +2 -2
  50. package/lib/commands/ext-sdk-install.js +88 -0
  51. package/lib/commands/ext.js +1 -0
  52. package/lib/commands/firestore-databases-restore.js +39 -1
  53. package/lib/commands/functions-secrets-access.js +2 -4
  54. package/lib/commands/index.js +15 -2
  55. package/lib/commands/init.js +25 -15
  56. package/lib/commands/setup-emulators-dataconnect.js +0 -13
  57. package/lib/commands/use.js +1 -1
  58. package/lib/config.js +14 -4
  59. package/lib/crashlytics/buildToolsJarHelper.js +2 -2
  60. package/lib/dataconnect/client.js +3 -2
  61. package/lib/dataconnect/dataplaneClient.js +12 -9
  62. package/lib/dataconnect/ensureApis.js +6 -1
  63. package/lib/dataconnect/fileUtils.js +29 -12
  64. package/lib/dataconnect/freeTrial.js +45 -9
  65. package/lib/dataconnect/load.js +3 -1
  66. package/lib/dataconnect/provisionCloudSql.js +41 -24
  67. package/lib/dataconnect/schemaMigration.js +215 -74
  68. package/lib/dataconnect/types.js +4 -1
  69. package/lib/dataconnect/webhook.js +32 -0
  70. package/lib/deploy/dataconnect/deploy.js +18 -15
  71. package/lib/deploy/dataconnect/prepare.js +41 -0
  72. package/lib/deploy/dataconnect/release.js +16 -7
  73. package/lib/deploy/extensions/deploy.js +3 -1
  74. package/lib/deploy/extensions/deploymentSummary.js +7 -3
  75. package/lib/deploy/extensions/planner.js +95 -5
  76. package/lib/deploy/extensions/prepare.js +89 -42
  77. package/lib/deploy/extensions/release.js +17 -10
  78. package/lib/deploy/extensions/tasks.js +32 -21
  79. package/lib/deploy/firestore/prepare.js +9 -0
  80. package/lib/deploy/firestore/release.js +3 -6
  81. package/lib/deploy/functions/build.js +5 -5
  82. package/lib/deploy/functions/checkIam.js +7 -2
  83. package/lib/deploy/functions/deploy.js +12 -12
  84. package/lib/deploy/functions/ensure.js +11 -3
  85. package/lib/deploy/functions/params.js +5 -3
  86. package/lib/deploy/functions/prepare.js +18 -3
  87. package/lib/deploy/functions/release/index.js +4 -0
  88. package/lib/deploy/functions/release/planner.js +2 -1
  89. package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
  90. package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
  91. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +46 -0
  92. package/lib/deploy/functions/runtimes/node/index.js +5 -0
  93. package/lib/deploy/functions/services/auth.js +34 -3
  94. package/lib/deploy/functions/services/index.js +2 -0
  95. package/lib/deploy/index.js +8 -5
  96. package/lib/deploy/lifecycleHooks.js +2 -1
  97. package/lib/emulator/apphosting/config.js +27 -0
  98. package/lib/emulator/apphosting/index.js +38 -0
  99. package/lib/emulator/apphosting/serve.js +50 -0
  100. package/lib/emulator/apphosting/utils.js +18 -0
  101. package/lib/emulator/auth/handlers.js +27 -0
  102. package/lib/emulator/auth/operations.js +41 -2
  103. package/lib/emulator/auth/state.js +2 -1
  104. package/lib/emulator/commandUtils.js +8 -3
  105. package/lib/emulator/constants.js +11 -1
  106. package/lib/emulator/controller.js +59 -6
  107. package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
  108. package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
  109. package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
  110. package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
  111. package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
  112. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
  113. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
  114. package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
  115. package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
  116. package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
  117. package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
  118. package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
  119. package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
  120. package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
  121. package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
  122. package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
  123. package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
  124. package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
  125. package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
  126. package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
  127. package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
  128. package/lib/emulator/dataconnect/pgliteServer.js +95 -0
  129. package/lib/emulator/dataconnectEmulator.js +58 -75
  130. package/lib/emulator/dataconnectToolkitController.js +44 -0
  131. package/lib/emulator/downloadableEmulators.js +30 -19
  132. package/lib/emulator/emulatorLogger.js +3 -0
  133. package/lib/emulator/env.js +3 -0
  134. package/lib/emulator/eventarcEmulator.js +1 -1
  135. package/lib/emulator/extensionsEmulator.js +38 -6
  136. package/lib/emulator/functionsEmulator.js +115 -42
  137. package/lib/emulator/functionsEmulatorShared.js +18 -1
  138. package/lib/emulator/functionsRuntimeWorker.js +2 -1
  139. package/lib/emulator/hub.js +13 -9
  140. package/lib/emulator/hubExport.js +10 -3
  141. package/lib/emulator/loggingEmulator.js +2 -2
  142. package/lib/emulator/portUtils.js +11 -11
  143. package/lib/emulator/registry.js +2 -0
  144. package/lib/emulator/storage/persistence.js +2 -2
  145. package/lib/emulator/storage/rules/runtime.js +1 -1
  146. package/lib/emulator/taskQueue.js +348 -0
  147. package/lib/emulator/tasksEmulator.js +240 -0
  148. package/lib/emulator/types.js +6 -0
  149. package/lib/emulator/ui.js +51 -25
  150. package/lib/error.js +31 -1
  151. package/lib/experiments.js +5 -0
  152. package/lib/extensions/askUserForEventsConfig.js +18 -8
  153. package/lib/extensions/askUserForParam.js +2 -1
  154. package/lib/extensions/displayExtensionInfo.js +5 -5
  155. package/lib/extensions/emulator/triggerHelper.js +1 -1
  156. package/lib/extensions/extensionsApi.js +15 -11
  157. package/lib/extensions/extensionsHelper.js +39 -8
  158. package/lib/extensions/localHelper.js +32 -1
  159. package/lib/extensions/refs.js +26 -11
  160. package/lib/extensions/runtimes/common.js +215 -0
  161. package/lib/extensions/runtimes/node.js +401 -0
  162. package/lib/extensions/types.js +67 -1
  163. package/lib/extensions/warnings.js +5 -2
  164. package/lib/firestore/api.js +2 -1
  165. package/lib/firestore/checkDatabaseType.js +10 -3
  166. package/lib/firestore/delete.js +11 -0
  167. package/lib/firestore/options.js +7 -0
  168. package/lib/frameworks/angular/index.js +15 -3
  169. package/lib/frameworks/constants.js +2 -2
  170. package/lib/frameworks/flutter/index.js +6 -6
  171. package/lib/frameworks/flutter/utils.js +34 -1
  172. package/lib/frameworks/next/constants.js +1 -1
  173. package/lib/frameworks/next/index.js +45 -17
  174. package/lib/frameworks/next/utils.js +57 -4
  175. package/lib/frameworks/vite/index.js +2 -2
  176. package/lib/fsutils.js +13 -1
  177. package/lib/functions/constants.js +4 -0
  178. package/lib/functions/events/v1.js +9 -2
  179. package/lib/gcp/apphosting.js +1 -1
  180. package/lib/gcp/cloudmonitoring.js +3 -3
  181. package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
  182. package/lib/gcp/cloudsql/connect.js +49 -37
  183. package/lib/gcp/cloudsql/interactive.js +49 -0
  184. package/lib/gcp/cloudsql/permissions.js +165 -0
  185. package/lib/gcp/devConnect.js +38 -1
  186. package/lib/gcp/firestore.js +5 -1
  187. package/lib/gcp/secretManager.js +12 -5
  188. package/lib/getProjectNumber.js +1 -1
  189. package/lib/init/features/apphosting.js +15 -0
  190. package/lib/init/features/dataconnect/index.js +166 -121
  191. package/lib/init/features/dataconnect/sdk.js +90 -81
  192. package/lib/init/features/emulators.js +2 -15
  193. package/lib/init/features/firestore/index.js +20 -1
  194. package/lib/init/features/firestore/indexes.js +4 -4
  195. package/lib/init/features/genkit/index.js +444 -0
  196. package/lib/init/features/hosting/index.js +2 -2
  197. package/lib/init/features/index.js +1 -1
  198. package/lib/init/features/project.js +6 -6
  199. package/lib/init/features/storage.js +0 -2
  200. package/lib/init/index.js +1 -0
  201. package/lib/init/spawn.js +23 -2
  202. package/lib/logger.js +2 -2
  203. package/lib/management/projects.js +24 -4
  204. package/lib/projectUtils.js +1 -1
  205. package/lib/prompt.js +22 -1
  206. package/lib/rc.js +1 -8
  207. package/lib/requireAuth.js +19 -5
  208. package/lib/requireDatabaseInstance.js +1 -1
  209. package/lib/requirePermissions.js +1 -1
  210. package/lib/responseToError.js +5 -2
  211. package/lib/rulesDeploy.js +1 -1
  212. package/lib/templates.js +2 -2
  213. package/lib/utils.js +16 -11
  214. package/lib/vsCodeUtils.js +8 -0
  215. package/package.json +8 -7
  216. package/schema/connector-yaml.json +57 -17
  217. package/schema/firebase-config.json +36 -0
  218. package/templates/extensions/javascript/package.lint.json +2 -2
  219. package/templates/extensions/javascript/package.nolint.json +2 -2
  220. package/templates/extensions/typescript/package.lint.json +2 -2
  221. package/templates/extensions/typescript/package.nolint.json +2 -2
  222. package/templates/genkit/firebase.0.9.0.template +57 -0
  223. package/templates/init/apphosting/apphosting.yaml +23 -0
  224. package/templates/init/dataconnect/connector.yaml +4 -3
  225. package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
  226. package/templates/init/dataconnect/dataconnect.yaml +6 -6
  227. package/templates/init/dataconnect/mutations.gql +44 -29
  228. package/templates/init/dataconnect/queries.gql +65 -38
  229. package/templates/init/dataconnect/schema.gql +38 -21
  230. package/templates/init/functions/javascript/package.lint.json +2 -2
  231. package/templates/init/functions/javascript/package.nolint.json +2 -2
  232. package/templates/init/functions/typescript/package.lint.json +2 -2
  233. package/templates/init/functions/typescript/package.nolint.json +2 -2
  234. package/lib/ensureCloudResourceLocation.js +0 -12
  235. package/lib/init/features/genkit.js +0 -53
@@ -8,19 +8,30 @@ const provisionCloudSql_1 = require("../../../dataconnect/provisionCloudSql");
8
8
  const freeTrial_1 = require("../../../dataconnect/freeTrial");
9
9
  const cloudsql = require("../../../gcp/cloudsql/cloudsqladmin");
10
10
  const ensureApis_1 = require("../../../dataconnect/ensureApis");
11
+ const experiments = require("../../../experiments");
11
12
  const client_1 = require("../../../dataconnect/client");
12
- const emulators_1 = require("../emulators");
13
+ const types_1 = require("../../../dataconnect/types");
13
14
  const names_1 = require("../../../dataconnect/names");
14
15
  const logger_1 = require("../../../logger");
15
16
  const templates_1 = require("../../../templates");
16
17
  const utils_1 = require("../../../utils");
18
+ const cloudbilling_1 = require("../../../gcp/cloudbilling");
19
+ const sdk = require("./sdk");
20
+ const fileUtils_1 = require("../../../dataconnect/fileUtils");
17
21
  const DATACONNECT_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/dataconnect.yaml");
22
+ const DATACONNECT_YAML_COMPAT_EXPERIMENT_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/dataconnect-fdccompatiblemode.yaml");
18
23
  const CONNECTOR_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/connector.yaml");
19
24
  const SCHEMA_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/schema.gql");
20
25
  const QUERIES_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/queries.gql");
21
26
  const MUTATIONS_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/mutations.gql");
27
+ const emptyConnector = {
28
+ id: "default",
29
+ path: "./connector",
30
+ files: [],
31
+ };
22
32
  const defaultConnector = {
23
33
  id: "default",
34
+ path: "./connector",
24
35
  files: [
25
36
  {
26
37
  path: "queries.gql",
@@ -32,14 +43,27 @@ const defaultConnector = {
32
43
  },
33
44
  ],
34
45
  };
46
+ const defaultSchema = { path: "schema.gql", content: SCHEMA_TEMPLATE };
35
47
  async function doSetup(setup, config) {
36
- const info = await askQuestions(setup, config);
48
+ const isBillingEnabled = setup.projectId ? await (0, cloudbilling_1.checkBillingEnabled)(setup.projectId) : false;
49
+ if (setup.projectId) {
50
+ isBillingEnabled ? await (0, ensureApis_1.ensureApis)(setup.projectId) : await (0, ensureApis_1.ensureSparkApis)(setup.projectId);
51
+ }
52
+ const info = await askQuestions(setup, isBillingEnabled);
37
53
  await actuate(setup, config, info);
38
- logger_1.logger.info("");
39
- (0, utils_1.logSuccess)(`If you'd like to generate an SDK for your new connector, run ${clc.bold("firebase init dataconnect:sdk")}`);
54
+ const cwdPlatformGuess = await (0, fileUtils_1.getPlatformFromFolder)(process.cwd());
55
+ if (cwdPlatformGuess !== types_1.Platform.NONE) {
56
+ await sdk.doSetup(setup, config);
57
+ }
58
+ else {
59
+ (0, utils_1.logBullet)(`If you'd like to add the generated SDK to your app your, run ${clc.bold("firebase init dataconnect:sdk")}`);
60
+ }
61
+ if (setup.projectId && !isBillingEnabled) {
62
+ (0, utils_1.logBullet)((0, freeTrial_1.upgradeInstructions)(setup.projectId));
63
+ }
40
64
  }
41
65
  exports.doSetup = doSetup;
42
- async function askQuestions(setup, config) {
66
+ async function askQuestions(setup, isBillingEnabled) {
43
67
  let info = {
44
68
  serviceId: "",
45
69
  locationId: "",
@@ -48,31 +72,37 @@ async function askQuestions(setup, config) {
48
72
  cloudSqlDatabase: "",
49
73
  isNewDatabase: false,
50
74
  connectors: [defaultConnector],
51
- schemaGql: [],
75
+ schemaGql: [defaultSchema],
52
76
  shouldProvisionCSQL: false,
53
77
  };
54
- info = await promptForService(setup, info);
55
- if (info.cloudSqlInstanceId === "") {
56
- info = await promptForCloudSQLInstance(setup, info);
78
+ info = await promptForExistingServices(setup, info, isBillingEnabled);
79
+ const requiredConfigUnset = info.serviceId === "" ||
80
+ info.cloudSqlInstanceId === "" ||
81
+ info.locationId === "" ||
82
+ info.cloudSqlDatabase === "";
83
+ const shouldConfigureBackend = isBillingEnabled && requiredConfigUnset
84
+ ? await (0, prompt_1.confirm)({
85
+ message: `Would you like to configure your backend resources now?`,
86
+ default: true,
87
+ })
88
+ : false;
89
+ if (shouldConfigureBackend) {
90
+ info = await promptForService(info);
91
+ info = await promptForCloudSQL(setup, info);
92
+ info.shouldProvisionCSQL = !!(setup.projectId &&
93
+ (info.isNewInstance || info.isNewDatabase) &&
94
+ isBillingEnabled &&
95
+ (await (0, prompt_1.confirm)({
96
+ message: `Would you like to provision your Cloud SQL instance and database now?${info.isNewInstance ? " This will take several minutes." : ""}.`,
97
+ default: true,
98
+ })));
57
99
  }
58
- if (info.cloudSqlDatabase === "") {
59
- info = await promptForDatabase(setup, config, info);
100
+ else {
101
+ info.serviceId = info.serviceId || (0, path_1.basename)(process.cwd());
102
+ info.cloudSqlInstanceId = info.cloudSqlInstanceId || `${info.serviceId || "app"}-fdc`;
103
+ info.locationId = info.locationId || `us-central1`;
104
+ info.cloudSqlDatabase = info.cloudSqlDatabase || `fdcdb`;
60
105
  }
61
- const defaultConnectionString = setup.rcfile.dataconnectEmulatorConfig?.postgres?.localConnectionString ??
62
- emulators_1.DEFAULT_POSTGRES_CONNECTION;
63
- const localConnectionString = await (0, prompt_1.promptOnce)({
64
- type: "input",
65
- name: "localConnectionString",
66
- message: `What is the connection string of the local Postgres instance you would like to use with the Data Connect emulator?`,
67
- default: defaultConnectionString,
68
- });
69
- setup.rcfile.dataconnectEmulatorConfig = { postgres: { localConnectionString } };
70
- info.shouldProvisionCSQL = !!(setup.projectId &&
71
- (info.isNewInstance || info.isNewDatabase) &&
72
- (await (0, prompt_1.confirm)({
73
- message: "Would you like to provision your CloudSQL instance and database now? This will take a few minutes.",
74
- default: true,
75
- })));
76
106
  return info;
77
107
  }
78
108
  async function actuate(setup, config, info) {
@@ -83,6 +113,7 @@ async function actuate(setup, config, info) {
83
113
  locationId: info.locationId,
84
114
  instanceId: info.cloudSqlInstanceId,
85
115
  databaseId: info.cloudSqlDatabase,
116
+ configYamlPath: (0, path_1.join)(config.get("dataconnect.source"), "dataconnect.yaml"),
86
117
  enableGoogleMlIntegration: false,
87
118
  waitForCreation: false,
88
119
  });
@@ -91,22 +122,23 @@ async function actuate(setup, config, info) {
91
122
  exports.actuate = actuate;
92
123
  async function writeFiles(config, info) {
93
124
  const dir = config.get("dataconnect.source") || "dataconnect";
94
- console.log(dir);
95
125
  const subbedDataconnectYaml = subDataconnectYamlValues({
96
126
  ...info,
97
- connectorIds: info.connectors.map((c) => `"./${c.id}"`).join(", "),
127
+ connectorDirs: info.connectors.map((c) => c.path),
98
128
  });
129
+ if (!config.get("dataconnect.source")) {
130
+ if (!info.schemaGql.length && !info.connectors.flatMap((r) => r.files).length) {
131
+ info.schemaGql = [defaultSchema];
132
+ info.connectors = [defaultConnector];
133
+ }
134
+ }
99
135
  config.set("dataconnect", { source: dir });
100
- await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml);
136
+ await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml, false, true);
101
137
  if (info.schemaGql.length) {
102
- (0, utils_1.logSuccess)("The service you chose already has GQL files deployed. We'll use those instead of the default templates.");
103
138
  for (const f of info.schemaGql) {
104
139
  await config.askWriteProjectFile((0, path_1.join)(dir, "schema", f.path), f.content);
105
140
  }
106
141
  }
107
- else {
108
- await config.askWriteProjectFile((0, path_1.join)(dir, "schema", "schema.gql"), SCHEMA_TEMPLATE);
109
- }
110
142
  for (const c of info.connectors) {
111
143
  await writeConnectorFiles(config, c);
112
144
  }
@@ -114,9 +146,9 @@ async function writeFiles(config, info) {
114
146
  async function writeConnectorFiles(config, connectorInfo) {
115
147
  const subbedConnectorYaml = subConnectorYamlValues({ connectorId: connectorInfo.id });
116
148
  const dir = config.get("dataconnect.source") || "dataconnect";
117
- await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.id, "connector.yaml"), subbedConnectorYaml);
149
+ await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, "connector.yaml"), subbedConnectorYaml);
118
150
  for (const f of connectorInfo.files) {
119
- await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.id, f.path), f.content);
151
+ await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, f.path), f.content);
120
152
  }
121
153
  }
122
154
  function subDataconnectYamlValues(replacementValues) {
@@ -124,12 +156,14 @@ function subDataconnectYamlValues(replacementValues) {
124
156
  serviceId: "__serviceId__",
125
157
  cloudSqlDatabase: "__cloudSqlDatabase__",
126
158
  cloudSqlInstanceId: "__cloudSqlInstanceId__",
127
- connectorIds: "__connectorIds__",
159
+ connectorDirs: "__connectorDirs__",
128
160
  locationId: "__location__",
129
161
  };
130
- let replaced = DATACONNECT_YAML_TEMPLATE;
162
+ let replaced = experiments.isEnabled("fdccompatiblemode")
163
+ ? DATACONNECT_YAML_COMPAT_EXPERIMENT_TEMPLATE
164
+ : DATACONNECT_YAML_TEMPLATE;
131
165
  for (const [k, v] of Object.entries(replacementValues)) {
132
- replaced = replaced.replace(replacements[k], v);
166
+ replaced = replaced.replace(replacements[k], JSON.stringify(v));
133
167
  }
134
168
  return replaced;
135
169
  }
@@ -139,80 +173,84 @@ function subConnectorYamlValues(replacementValues) {
139
173
  };
140
174
  let replaced = CONNECTOR_YAML_TEMPLATE;
141
175
  for (const [k, v] of Object.entries(replacementValues)) {
142
- replaced = replaced.replace(replacements[k], v);
176
+ replaced = replaced.replace(replacements[k], JSON.stringify(v));
143
177
  }
144
178
  return replaced;
145
179
  }
146
- async function promptForService(setup, info) {
147
- if (setup.projectId) {
148
- await (0, ensureApis_1.ensureApis)(setup.projectId);
149
- const existingServices = await (0, client_1.listAllServices)(setup.projectId);
150
- const existingServicesAndSchemas = await Promise.all(existingServices.map(async (s) => {
180
+ async function promptForExistingServices(setup, info, isBillingEnabled) {
181
+ if (!setup.projectId || !isBillingEnabled) {
182
+ return info;
183
+ }
184
+ const existingServices = await (0, client_1.listAllServices)(setup.projectId);
185
+ const existingServicesAndSchemas = await Promise.all(existingServices.map(async (s) => {
186
+ return {
187
+ service: s,
188
+ schema: await (0, client_1.getSchema)(s.name),
189
+ };
190
+ }));
191
+ if (existingServicesAndSchemas.length) {
192
+ const choices = existingServicesAndSchemas.map((s) => {
193
+ const serviceName = (0, names_1.parseServiceName)(s.service.name);
151
194
  return {
152
- service: s,
153
- schema: await (0, client_1.getSchema)(s.name),
195
+ name: `${serviceName.location}/${serviceName.serviceId}`,
196
+ value: s,
154
197
  };
155
- }));
156
- if (existingServicesAndSchemas.length) {
157
- const choices = existingServicesAndSchemas.map((s) => {
158
- const serviceName = (0, names_1.parseServiceName)(s.service.name);
159
- return {
160
- name: `${serviceName.location}/${serviceName.serviceId}`,
161
- value: s,
162
- };
163
- });
164
- choices.push({ name: "Create a new service", value: undefined });
165
- const choice = await (0, prompt_1.promptOnce)({
166
- message: "Your project already has existing services. Which would you like to set up local files for?",
167
- type: "list",
168
- choices,
169
- });
170
- if (choice) {
171
- const serviceName = (0, names_1.parseServiceName)(choice.service.name);
172
- info.serviceId = serviceName.serviceId;
173
- info.locationId = serviceName.location;
174
- if (choice.schema) {
175
- if (choice.schema.primaryDatasource.postgresql?.cloudSql.instance) {
176
- const instanceName = (0, names_1.parseCloudSQLInstanceName)(choice.schema.primaryDatasource.postgresql?.cloudSql.instance);
177
- info.cloudSqlInstanceId = instanceName.instanceId;
178
- }
179
- if (choice.schema.source.files) {
180
- info.schemaGql = choice.schema.source.files;
181
- }
182
- info.cloudSqlDatabase = choice.schema.primaryDatasource.postgresql?.database ?? "";
183
- const connectors = await (0, client_1.listConnectors)(choice.service.name);
184
- if (connectors.length) {
185
- info.connectors = connectors.map((c) => {
186
- return {
187
- id: c.name.split("/").pop(),
188
- files: c.source.files || [],
189
- };
190
- });
191
- }
198
+ });
199
+ choices.push({ name: "Create a new service", value: undefined });
200
+ const choice = await (0, prompt_1.promptOnce)({
201
+ message: "Your project already has existing services. Which would you like to set up local files for?",
202
+ type: "list",
203
+ choices,
204
+ });
205
+ if (choice) {
206
+ const serviceName = (0, names_1.parseServiceName)(choice.service.name);
207
+ info.serviceId = serviceName.serviceId;
208
+ info.locationId = serviceName.location;
209
+ info.schemaGql = [];
210
+ info.connectors = [emptyConnector];
211
+ if (choice.schema) {
212
+ const primaryDatasource = choice.schema.datasources.find((d) => d.postgresql);
213
+ if (primaryDatasource?.postgresql?.cloudSql.instance) {
214
+ const instanceName = (0, names_1.parseCloudSQLInstanceName)(primaryDatasource.postgresql.cloudSql.instance);
215
+ info.cloudSqlInstanceId = instanceName.instanceId;
216
+ }
217
+ if (choice.schema.source.files?.length) {
218
+ info.schemaGql = choice.schema.source.files;
219
+ }
220
+ info.cloudSqlDatabase = primaryDatasource?.postgresql?.database ?? "";
221
+ const connectors = await (0, client_1.listConnectors)(choice.service.name, [
222
+ "connectors.name",
223
+ "connectors.source.files",
224
+ ]);
225
+ if (connectors.length) {
226
+ info.connectors = connectors.map((c) => {
227
+ const id = c.name.split("/").pop();
228
+ return {
229
+ id,
230
+ path: connectors.length === 1 ? "./connector" : `./${id}`,
231
+ files: c.source.files || [],
232
+ };
233
+ });
192
234
  }
193
235
  }
194
236
  }
195
237
  }
196
- if (info.serviceId === "") {
197
- info.serviceId = await (0, prompt_1.promptOnce)({
198
- message: "What ID would you like to use for this service?",
199
- type: "input",
200
- default: "my-service",
201
- });
202
- }
203
238
  return info;
204
239
  }
205
- async function promptForCloudSQLInstance(setup, info) {
206
- if (setup.projectId) {
240
+ async function promptForCloudSQL(setup, info) {
241
+ if (info.cloudSqlInstanceId === "" && setup.projectId) {
207
242
  const instances = await cloudsql.listInstances(setup.projectId);
208
243
  let choices = instances.map((i) => {
209
- return { name: i.name, value: i.name, location: i.region };
244
+ let display = `${i.name} (${i.region})`;
245
+ if (i.settings.userLabels?.["firebase-data-connect"] === "ft") {
246
+ display += " (no cost trial)";
247
+ }
248
+ return { name: display, value: i.name, location: i.region };
210
249
  });
211
250
  choices = choices.filter((c) => info.locationId === "" || info.locationId === c.location);
212
251
  if (choices.length) {
213
- const freeTrialInstanceId = await (0, freeTrial_1.checkForFreeTrialInstance)(setup.projectId);
214
- if (!freeTrialInstanceId) {
215
- choices.push({ name: "Create a new instance", value: "", location: "" });
252
+ if (!(await (0, freeTrial_1.checkFreeTrialInstanceUsed)(setup.projectId))) {
253
+ choices.push({ name: "Create a new free trial instance", value: "", location: "" });
216
254
  }
217
255
  info.cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
218
256
  message: `Which CloudSQL instance would you like to use?`,
@@ -229,7 +267,7 @@ async function promptForCloudSQLInstance(setup, info) {
229
267
  info.cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
230
268
  message: `What ID would you like to use for your new CloudSQL instance?`,
231
269
  type: "input",
232
- default: `fdc-sql`,
270
+ default: `${info.serviceId || "app"}-fdc`,
233
271
  });
234
272
  }
235
273
  if (info.locationId === "") {
@@ -240,30 +278,7 @@ async function promptForCloudSQLInstance(setup, info) {
240
278
  choices,
241
279
  });
242
280
  }
243
- return info;
244
- }
245
- async function locationChoices(setup) {
246
- if (setup.projectId) {
247
- const locations = await (0, client_1.listLocations)(setup.projectId);
248
- return locations.map((l) => {
249
- return { name: l, value: l };
250
- });
251
- }
252
- else {
253
- return [
254
- { name: "us-central1", value: "us-central1" },
255
- { name: "europe-north1", value: "europe-north1" },
256
- { name: "europe-central2", value: "europe-central2" },
257
- { name: "europe-west1", value: "europe-west1" },
258
- { name: "southamerica-west1", value: "southamerica-west1" },
259
- { name: "us-east4", value: "us-east4" },
260
- { name: "us-west1", value: "us-west1" },
261
- { name: "asia-southeast1", value: "asia-southeast1" },
262
- ];
263
- }
264
- }
265
- async function promptForDatabase(setup, config, info) {
266
- if (!info.isNewInstance && setup.projectId) {
281
+ if (info.cloudSqlDatabase === "" && setup.projectId) {
267
282
  try {
268
283
  const dbs = await cloudsql.listDatabases(setup.projectId, info.cloudSqlInstanceId);
269
284
  const choices = dbs.map((d) => {
@@ -292,3 +307,33 @@ async function promptForDatabase(setup, config, info) {
292
307
  }
293
308
  return info;
294
309
  }
310
+ async function promptForService(info) {
311
+ if (info.serviceId === "") {
312
+ info.serviceId = await (0, prompt_1.promptOnce)({
313
+ message: "What ID would you like to use for this service?",
314
+ type: "input",
315
+ default: (0, path_1.basename)(process.cwd()),
316
+ });
317
+ }
318
+ return info;
319
+ }
320
+ async function locationChoices(setup) {
321
+ if (setup.projectId) {
322
+ const locations = await (0, client_1.listLocations)(setup.projectId);
323
+ return locations.map((l) => {
324
+ return { name: l, value: l };
325
+ });
326
+ }
327
+ else {
328
+ return [
329
+ { name: "us-central1", value: "us-central1" },
330
+ { name: "europe-north1", value: "europe-north1" },
331
+ { name: "europe-central2", value: "europe-central2" },
332
+ { name: "europe-west1", value: "europe-west1" },
333
+ { name: "southamerica-west1", value: "southamerica-west1" },
334
+ { name: "us-east4", value: "us-east4" },
335
+ { name: "us-west1", value: "us-west1" },
336
+ { name: "asia-southeast1", value: "asia-southeast1" },
337
+ ];
338
+ }
339
+ }
@@ -1,22 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.actuate = exports.doSetup = void 0;
3
+ exports.actuate = exports.generateSdkYaml = exports.doSetup = exports.FDC_APP_FOLDER = void 0;
4
4
  const yaml = require("yaml");
5
5
  const fs = require("fs");
6
6
  const clc = require("colorette");
7
+ const path = require("path");
8
+ const fsutils_1 = require("../../../fsutils");
7
9
  const prompt_1 = require("../../../prompt");
8
10
  const fileUtils_1 = require("../../../dataconnect/fileUtils");
9
11
  const load_1 = require("../../../dataconnect/load");
10
- const logger_1 = require("../../../logger");
12
+ const types_1 = require("../../../dataconnect/types");
11
13
  const dataconnectEmulator_1 = require("../../../emulator/dataconnectEmulator");
12
14
  const error_1 = require("../../../error");
13
15
  const lodash_1 = require("lodash");
14
- const IOS = "ios";
15
- const WEB = "web";
16
- const ANDROID = "android";
16
+ const utils_1 = require("../../../utils");
17
+ exports.FDC_APP_FOLDER = "_FDC_APP_FOLDER";
17
18
  async function doSetup(setup, config) {
18
19
  const sdkInfo = await askQuestions(setup, config);
19
- await actuate(sdkInfo, setup.projectId);
20
+ await actuate(sdkInfo);
21
+ (0, utils_1.logSuccess)(`If you'd like to add more generated SDKs to your app your later, run ${clc.bold("firebase init dataconnect:sdk")} again`);
20
22
  }
21
23
  exports.doSetup = doSetup;
22
24
  async function askQuestions(setup, config) {
@@ -33,99 +35,106 @@ async function askQuestions(setup, config) {
33
35
  })
34
36
  .flat();
35
37
  if (!connectorChoices.length) {
36
- throw new error_1.FirebaseError(`Your config has no connectors to set up SDKs for. Run ${clc.bold("firebase init dataconnect")} to set up a service and conenctors.`);
38
+ throw new error_1.FirebaseError(`Your config has no connectors to set up SDKs for. Run ${clc.bold("firebase init dataconnect")} to set up a service and connectors.`);
39
+ }
40
+ let appDir = process.env[exports.FDC_APP_FOLDER] || process.cwd();
41
+ let targetPlatform = await (0, fileUtils_1.getPlatformFromFolder)(appDir);
42
+ if (targetPlatform === types_1.Platform.NONE && !process.env[exports.FDC_APP_FOLDER]?.length) {
43
+ appDir = await (0, prompt_1.promptForDirectory)({
44
+ config,
45
+ message: "Where is your app directory? Leave blank to set up a generated SDK in your current directory.",
46
+ });
47
+ targetPlatform = await (0, fileUtils_1.getPlatformFromFolder)(appDir);
48
+ }
49
+ if (targetPlatform === types_1.Platform.NONE || targetPlatform === types_1.Platform.MULTIPLE) {
50
+ if (targetPlatform === types_1.Platform.NONE) {
51
+ (0, utils_1.logBullet)(`Couldn't automatically detect app your in directory ${appDir}.`);
52
+ }
53
+ else {
54
+ (0, utils_1.logSuccess)(`Detected multiple app platforms in directory ${appDir}`);
55
+ }
56
+ const platforms = [
57
+ { name: "iOS (Swift)", value: types_1.Platform.IOS },
58
+ { name: "Web (JavaScript)", value: types_1.Platform.WEB },
59
+ { name: "Android (Kotlin)", value: types_1.Platform.ANDROID },
60
+ { name: "Flutter (Dart)", value: types_1.Platform.FLUTTER },
61
+ ];
62
+ targetPlatform = await (0, prompt_1.promptOnce)({
63
+ message: "Which platform do you want to set up a generated SDK for?",
64
+ type: "list",
65
+ choices: platforms,
66
+ });
67
+ }
68
+ else {
69
+ (0, utils_1.logSuccess)(`Detected ${targetPlatform} app in directory ${appDir}`);
37
70
  }
38
71
  const connectorInfo = await (0, prompt_1.promptOnce)({
39
72
  message: "Which connector do you want set up a generated SDK for?",
40
73
  type: "list",
41
74
  choices: connectorChoices,
42
75
  });
43
- let platforms = [];
44
- while (!platforms.length) {
45
- platforms = await (0, prompt_1.promptOnce)({
46
- message: "Which platforms do you want to set up a generated SDK for?",
47
- type: "checkbox",
48
- choices: [
49
- { name: "iOS (Swift)", value: IOS },
50
- { name: "Web (JavaScript)", value: WEB },
51
- { name: "Androd (Kotlin)", value: ANDROID },
52
- ],
53
- });
54
- if (!platforms.length) {
55
- logger_1.logger.info("You must pick at least one platform.");
56
- }
57
- }
58
- const newConnectorYaml = JSON.parse(JSON.stringify(connectorInfo.connectorYaml));
59
- if (!newConnectorYaml.generate) {
60
- newConnectorYaml.generate = {};
76
+ const connectorYaml = JSON.parse(JSON.stringify(connectorInfo.connectorYaml));
77
+ const newConnectorYaml = generateSdkYaml(targetPlatform, connectorYaml, connectorInfo.directory, appDir);
78
+ const connectorYamlContents = yaml.stringify(newConnectorYaml);
79
+ connectorInfo.connectorYaml = newConnectorYaml;
80
+ const displayIOSWarning = targetPlatform === types_1.Platform.IOS;
81
+ return { connectorYamlContents, connectorInfo, displayIOSWarning };
82
+ }
83
+ function generateSdkYaml(targetPlatform, connectorYaml, connectorDir, appDir) {
84
+ if (!connectorYaml.generate) {
85
+ connectorYaml.generate = {};
61
86
  }
62
- if (platforms.includes(IOS)) {
63
- const outputDir = await (0, prompt_1.promptOnce)({
64
- message: `What directory do you want to write your Swift SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
65
- type: "input",
66
- default: newConnectorYaml.generate.swiftSdk?.outputDir ||
67
- `./../gensdk/${newConnectorYaml.connectorId}/swift-sdk`,
68
- });
69
- const pkg = (0, lodash_1.camelCase)(newConnectorYaml.connectorId);
70
- const swiftSdk = { outputDir, package: pkg };
71
- newConnectorYaml.generate.swiftSdk = swiftSdk;
87
+ if (targetPlatform === types_1.Platform.IOS) {
88
+ const swiftSdk = {
89
+ outputDir: path.relative(connectorDir, path.join(appDir, `dataconnect-generated/swift`)),
90
+ package: (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(connectorYaml.connectorId)) + "Connector",
91
+ };
92
+ connectorYaml.generate.swiftSdk = swiftSdk;
72
93
  }
73
- if (platforms.includes(WEB)) {
74
- const outputDir = await (0, prompt_1.promptOnce)({
75
- message: `What directory do you want to write your JavaScript SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
76
- type: "input",
77
- default: newConnectorYaml.generate.javascriptSdk?.outputDir ||
78
- `./../gensdk/${newConnectorYaml.connectorId}/javascript-sdk`,
79
- });
80
- const pkg = newConnectorYaml.generate.javascriptSdk?.package ??
81
- `@firebasegen/${connectorInfo.connectorYaml.connectorId}`;
82
- const packageJSONDir = await (0, prompt_1.promptOnce)({
83
- message: "Which directory contains the package.json that you would like to add the JavaScript SDK dependency to? (Leave blank to skip)",
84
- type: "input",
85
- default: newConnectorYaml.generate.javascriptSdk?.packageJSONDir,
86
- });
94
+ if (targetPlatform === types_1.Platform.WEB) {
95
+ const pkg = `${connectorYaml.connectorId}-connector`;
87
96
  const javascriptSdk = {
88
- outputDir,
97
+ outputDir: path.relative(connectorDir, path.join(appDir, `dataconnect-generated/js/${pkg}`)),
98
+ package: `@firebasegen/${pkg}`,
99
+ packageJsonDir: path.relative(connectorDir, appDir),
100
+ };
101
+ connectorYaml.generate.javascriptSdk = javascriptSdk;
102
+ }
103
+ if (targetPlatform === types_1.Platform.FLUTTER) {
104
+ const pkg = `${(0, lodash_1.snakeCase)(connectorYaml.connectorId)}_connector`;
105
+ const dartSdk = {
106
+ outputDir: path.relative(connectorDir, path.join(appDir, `dataconnect-generated/dart/${pkg}`)),
89
107
  package: pkg,
90
108
  };
91
- if (packageJSONDir) {
92
- javascriptSdk.packageJSONDir = packageJSONDir;
93
- }
94
- newConnectorYaml.generate.javascriptSdk = javascriptSdk;
109
+ connectorYaml.generate.dartSdk = dartSdk;
95
110
  }
96
- if (platforms.includes(ANDROID)) {
97
- const outputDir = await (0, prompt_1.promptOnce)({
98
- message: `What directory do you want to write your Kotlin SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
99
- type: "input",
100
- default: newConnectorYaml.generate.kotlinSdk?.outputDir ||
101
- `./../gensdk/${newConnectorYaml.connectorId}/kotlin-sdk`,
102
- });
103
- const pkg = newConnectorYaml.generate.kotlinSdk?.package ??
104
- `connectors.${(0, lodash_1.snakeCase)(connectorInfo.connectorYaml.connectorId)}`;
111
+ if (targetPlatform === types_1.Platform.ANDROID) {
105
112
  const kotlinSdk = {
106
- outputDir,
107
- package: pkg,
113
+ outputDir: path.relative(connectorDir, path.join(appDir, `dataconnect-generated/kotlin`)),
114
+ package: `connectors.${(0, lodash_1.snakeCase)(connectorYaml.connectorId)}`,
108
115
  };
109
- newConnectorYaml.generate.kotlinSdk = kotlinSdk;
116
+ for (const candidateSubdir of ["app/src/main/java", "app/src/main/kotlin"]) {
117
+ const candidateDir = path.join(appDir, candidateSubdir);
118
+ if ((0, fsutils_1.dirExistsSync)(candidateDir)) {
119
+ kotlinSdk.outputDir = path.relative(connectorDir, candidateDir);
120
+ }
121
+ }
122
+ connectorYaml.generate.kotlinSdk = kotlinSdk;
110
123
  }
111
- const shouldGenerate = !!(setup.projectId &&
112
- (await (0, prompt_1.confirm)({
113
- message: "Would you like to generate SDK code now?",
114
- default: true,
115
- })));
116
- const connectorYamlContents = yaml.stringify(newConnectorYaml);
117
- return { connectorYamlContents, connectorInfo, shouldGenerate };
124
+ return connectorYaml;
118
125
  }
119
- async function actuate(sdkInfo, projectId) {
126
+ exports.generateSdkYaml = generateSdkYaml;
127
+ async function actuate(sdkInfo) {
120
128
  const connectorYamlPath = `${sdkInfo.connectorInfo.directory}/connector.yaml`;
121
129
  fs.writeFileSync(connectorYamlPath, sdkInfo.connectorYamlContents, "utf8");
122
- logger_1.logger.info(`Wrote new config to ${connectorYamlPath}`);
123
- if (projectId && sdkInfo.shouldGenerate) {
124
- await dataconnectEmulator_1.DataConnectEmulator.generate({
125
- configDir: sdkInfo.connectorInfo.directory,
126
- connectorId: sdkInfo.connectorInfo.connectorYaml.connectorId,
127
- });
128
- logger_1.logger.info(`Generated SDK code for ${sdkInfo.connectorInfo.connectorYaml.connectorId}`);
130
+ (0, utils_1.logBullet)(`Wrote new config to ${connectorYamlPath}`);
131
+ await dataconnectEmulator_1.DataConnectEmulator.generate({
132
+ configDir: sdkInfo.connectorInfo.directory,
133
+ connectorId: sdkInfo.connectorInfo.connectorYaml.connectorId,
134
+ });
135
+ (0, utils_1.logBullet)(`Generated SDK code for ${sdkInfo.connectorInfo.connectorYaml.connectorId}`);
136
+ if (sdkInfo.connectorInfo.connectorYaml.generate?.swiftSdk && sdkInfo.displayIOSWarning) {
137
+ (0, utils_1.logBullet)(clc.bold("Please follow the instructions here to add your generated sdk to your XCode project:\n\thttps://firebase.google.com/docs/data-connect/gp/ios-sdk#set-client"));
129
138
  }
130
139
  }
131
140
  exports.actuate = actuate;