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
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.doSetup = void 0;
4
+ const path_1 = require("path");
5
+ const prompt_1 = require("../../../prompt");
6
+ const fs_1 = require("fs");
7
+ const provisionCloudSql_1 = require("../../../dataconnect/provisionCloudSql");
8
+ const freeTrial_1 = require("../../../dataconnect/freeTrial");
9
+ const cloudsql = require("../../../gcp/cloudsql/cloudsqladmin");
10
+ const ensureApis_1 = require("../../../dataconnect/ensureApis");
11
+ const client_1 = require("../../../dataconnect/client");
12
+ const emulators_1 = require("../emulators");
13
+ const TEMPLATE_ROOT = (0, path_1.resolve)(__dirname, "../../../../templates/init/dataconnect/");
14
+ const DATACONNECT_YAML_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "dataconnect.yaml"), "utf8");
15
+ const CONNECTOR_YAML_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "connector.yaml"), "utf8");
16
+ const SCHEMA_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "schema.gql"), "utf8");
17
+ const QUERIES_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "queries.gql"), "utf8");
18
+ const MUTATIONS_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "mutations.gql"), "utf8");
19
+ async function doSetup(setup, config) {
20
+ if (setup.projectId) {
21
+ await (0, ensureApis_1.ensureApis)(setup.projectId);
22
+ }
23
+ const serviceId = await (0, prompt_1.promptOnce)({
24
+ message: "What ID would you like to use for this service?",
25
+ type: "input",
26
+ default: "dataconnect",
27
+ });
28
+ const connectorId = await (0, prompt_1.promptOnce)({
29
+ message: "What ID would you like to use for your connector?",
30
+ type: "input",
31
+ default: "my-connector",
32
+ });
33
+ let cloudSqlInstanceId = "";
34
+ let newInstance = false;
35
+ let locationId = "";
36
+ if (setup.projectId) {
37
+ const instances = await cloudsql.listInstances(setup.projectId);
38
+ const choices = instances.map((i) => {
39
+ return { name: i.name, value: i.name, location: i.region };
40
+ });
41
+ const freeTrialInstanceId = await (0, freeTrial_1.checkForFreeTrialInstance)(setup.projectId);
42
+ if (!freeTrialInstanceId) {
43
+ choices.push({ name: "Create a new instance", value: "", location: "" });
44
+ }
45
+ if (instances.length) {
46
+ cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
47
+ message: `Which CloudSSQL instance would you like to use?`,
48
+ type: "list",
49
+ choices,
50
+ });
51
+ }
52
+ locationId = choices.find((c) => c.value === cloudSqlInstanceId).location;
53
+ }
54
+ if (cloudSqlInstanceId === "") {
55
+ let locationOptions = [
56
+ { name: "us-central1", value: "us-central1" },
57
+ { name: "europe-north1", value: "europe-north1" },
58
+ { name: "europe-central2", value: "europe-central2" },
59
+ { name: "europe-west1", value: "europe-west1" },
60
+ { name: "southamerica-west1", value: "southamerica-west1" },
61
+ { name: "us-east4", value: "us-east4" },
62
+ { name: "us-west1", value: "us-west1" },
63
+ { name: "asia-southeast1", value: "asia-southeast1" },
64
+ ];
65
+ if (setup.projectId) {
66
+ const locations = await (0, client_1.listLocations)(setup.projectId);
67
+ locationOptions = locations.map((l) => {
68
+ return { name: l, value: l };
69
+ });
70
+ }
71
+ newInstance = true;
72
+ cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
73
+ message: `What ID would you like to use for your new CloudSQL instance?`,
74
+ type: "input",
75
+ default: `dataconnect-test`,
76
+ });
77
+ locationId = await (0, prompt_1.promptOnce)({
78
+ message: "What location would you use for this instance?",
79
+ type: "list",
80
+ choices: locationOptions,
81
+ });
82
+ }
83
+ const dir = config.get("dataconnect.source") || "dataconnect";
84
+ if (!config.has("dataconnect")) {
85
+ config.set("dataconnect.source", dir);
86
+ config.set("dataconnect.location", locationId);
87
+ }
88
+ let cloudSqlDatabase = "";
89
+ let newDB = false;
90
+ if (!newInstance && setup.projectId) {
91
+ const dbs = await cloudsql.listDatabases(setup.projectId, cloudSqlInstanceId);
92
+ const choices = dbs.map((d) => {
93
+ return { name: d.name, value: d.name };
94
+ });
95
+ choices.push({ name: "Create a new database", value: "" });
96
+ if (dbs.length) {
97
+ cloudSqlDatabase = await (0, prompt_1.promptOnce)({
98
+ message: `Which database in ${cloudSqlInstanceId} would you like to use?`,
99
+ type: "list",
100
+ choices,
101
+ });
102
+ }
103
+ }
104
+ if (cloudSqlDatabase === "") {
105
+ newDB = true;
106
+ cloudSqlDatabase = await (0, prompt_1.promptOnce)({
107
+ message: `What ID would you like to use for your new database in ${cloudSqlInstanceId}?`,
108
+ type: "input",
109
+ default: `dataconnect`,
110
+ });
111
+ }
112
+ const defaultConnectionString = setup.rcfile.dataconnectEmulatorConfig?.postgres?.localConnectionString ??
113
+ emulators_1.DEFAULT_POSTGRES_CONNECTION;
114
+ const localConnectionString = await (0, prompt_1.promptOnce)({
115
+ type: "input",
116
+ name: "localConnectionString",
117
+ message: `What is the connection string of the local Postgres instance you would like to use with the Data Connect emulator?`,
118
+ default: defaultConnectionString,
119
+ });
120
+ setup.rcfile.dataconnectEmulatorConfig = { postgres: { localConnectionString } };
121
+ const subbedDataconnectYaml = subValues(DATACONNECT_YAML_TEMPLATE, {
122
+ serviceId,
123
+ cloudSqlInstanceId,
124
+ cloudSqlDatabase,
125
+ connectorId,
126
+ });
127
+ const subbedConnectorYaml = subValues(CONNECTOR_YAML_TEMPLATE, {
128
+ serviceId,
129
+ cloudSqlInstanceId,
130
+ cloudSqlDatabase,
131
+ connectorId,
132
+ });
133
+ await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml);
134
+ await config.askWriteProjectFile((0, path_1.join)(dir, "connector", "connector.yaml"), subbedConnectorYaml);
135
+ await config.askWriteProjectFile((0, path_1.join)(dir, "schema", "schema.gql"), SCHEMA_TEMPLATE);
136
+ await config.askWriteProjectFile((0, path_1.join)(dir, "connector", "queries.gql"), QUERIES_TEMPLATE);
137
+ await config.askWriteProjectFile((0, path_1.join)(dir, "connector", "mutations.gql"), MUTATIONS_TEMPLATE);
138
+ if (setup.projectId &&
139
+ (newInstance || newDB) &&
140
+ (await (0, prompt_1.confirm)({
141
+ message: "Would you like to provision your CloudSQL instance and database now? This will take a few minutes.",
142
+ default: true,
143
+ }))) {
144
+ await (0, provisionCloudSql_1.provisionCloudSql)({
145
+ projectId: setup.projectId,
146
+ locationId,
147
+ instanceId: cloudSqlInstanceId,
148
+ databaseId: cloudSqlDatabase,
149
+ enableGoogleMlIntegration: false,
150
+ });
151
+ }
152
+ }
153
+ exports.doSetup = doSetup;
154
+ function subValues(template, replacementValues) {
155
+ const replacements = {
156
+ serviceId: "__serviceId__",
157
+ cloudSqlDatabase: "__cloudSqlDatabase__",
158
+ cloudSqlInstanceId: "__cloudSqlInstanceId__",
159
+ connectorId: "__connectorId__",
160
+ };
161
+ let replaced = template;
162
+ for (const [k, v] of Object.entries(replacementValues)) {
163
+ replaced = replaced.replace(replacements[k], v);
164
+ }
165
+ return replaced;
166
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doSetup = void 0;
3
+ exports.doSetup = exports.DEFAULT_POSTGRES_CONNECTION = void 0;
4
4
  const clc = require("colorette");
5
5
  const _ = require("lodash");
6
6
  const utils = require("../../utils");
@@ -8,6 +8,7 @@ const prompt_1 = require("../../prompt");
8
8
  const types_1 = require("../../emulator/types");
9
9
  const constants_1 = require("../../emulator/constants");
10
10
  const downloadableEmulators_1 = require("../../emulator/downloadableEmulators");
11
+ exports.DEFAULT_POSTGRES_CONNECTION = "postgresql://localhost:5432?sslmode=disable";
11
12
  async function doSetup(setup, config) {
12
13
  const choices = types_1.ALL_SERVICE_EMULATORS.map((e) => {
13
14
  return {
@@ -76,6 +77,17 @@ async function doSetup(setup, config) {
76
77
  ui.port = isNaN(portNum) ? undefined : portNum;
77
78
  }
78
79
  }
80
+ if (selections.emulators.includes(types_1.Emulators.DATACONNECT)) {
81
+ const defaultConnectionString = setup.rcfile.dataconnectEmulatorConfig?.postgres?.localConnectionString ??
82
+ exports.DEFAULT_POSTGRES_CONNECTION;
83
+ const localConnectionString = await (0, prompt_1.promptOnce)({
84
+ type: "input",
85
+ name: "localConnectionString",
86
+ message: `What is the connection string of the local Postgres instance you would like to use with the Data Connect emulator?`,
87
+ default: defaultConnectionString,
88
+ });
89
+ setup.rcfile.dataconnectEmulatorConfig = { postgres: { localConnectionString } };
90
+ }
79
91
  await (0, prompt_1.prompt)(selections, [
80
92
  {
81
93
  name: "download",
@@ -129,6 +129,9 @@ async function overwriteCodebase(setup, config) {
129
129
  return languageSetup(setup, config);
130
130
  }
131
131
  async function languageSetup(setup, config) {
132
+ if (setup.languageOverride) {
133
+ return require("./" + setup.languageOverride).setup(setup, config);
134
+ }
132
135
  const choices = [
133
136
  {
134
137
  name: "JavaScript",
@@ -152,14 +155,27 @@ async function languageSetup(setup, config) {
152
155
  const cbconfig = (0, projectConfig_1.configForCodebase)(setup.config.functions, setup.functions.codebase);
153
156
  switch (language) {
154
157
  case "javascript":
155
- cbconfig.ignore = ["node_modules", ".git", "firebase-debug.log", "firebase-debug.*.log"];
158
+ cbconfig.ignore = [
159
+ "node_modules",
160
+ ".git",
161
+ "firebase-debug.log",
162
+ "firebase-debug.*.log",
163
+ "*.local",
164
+ ];
156
165
  break;
157
166
  case "typescript":
158
- cbconfig.ignore = ["node_modules", ".git", "firebase-debug.log", "firebase-debug.*.log"];
167
+ cbconfig.ignore = [
168
+ "node_modules",
169
+ ".git",
170
+ "firebase-debug.log",
171
+ "firebase-debug.*.log",
172
+ "*.local",
173
+ ];
159
174
  break;
160
175
  case "python":
161
- cbconfig.ignore = ["venv", ".git", "firebase-debug.log", "firebase-debug.*.log"];
176
+ cbconfig.ignore = ["venv", ".git", "firebase-debug.log", "firebase-debug.*.log", "*.local"];
162
177
  break;
163
178
  }
179
+ setup.functions.languageChoice = language;
164
180
  return require("./" + language).setup(setup, config);
165
181
  }
@@ -1,37 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.askInstallDependencies = void 0;
4
- const spawn = require("cross-spawn");
5
4
  const logger_1 = require("../../../logger");
6
5
  const prompt_1 = require("../../../prompt");
7
- function askInstallDependencies(setup, config) {
8
- return (0, prompt_1.prompt)(setup, [
6
+ const spawn_1 = require("../../spawn");
7
+ async function askInstallDependencies(setup, config) {
8
+ await (0, prompt_1.prompt)(setup, [
9
9
  {
10
10
  name: "npm",
11
11
  type: "confirm",
12
12
  message: "Do you want to install dependencies with npm now?",
13
13
  default: true,
14
14
  },
15
- ]).then(() => {
16
- if (setup.npm) {
17
- return new Promise((resolve) => {
18
- const installer = spawn("npm", ["install"], {
19
- cwd: config.projectDir + `/${setup.source}`,
20
- stdio: "inherit",
21
- });
22
- installer.on("error", (err) => {
23
- logger_1.logger.debug(err.stack);
24
- });
25
- installer.on("close", (code) => {
26
- if (code === 0) {
27
- return resolve();
28
- }
29
- logger_1.logger.info();
30
- logger_1.logger.error("NPM install failed, continuing with Firebase initialization...");
31
- return resolve();
32
- });
33
- });
15
+ ]);
16
+ if (setup.npm) {
17
+ try {
18
+ await (0, spawn_1.wrapSpawn)("npm", ["install"], config.projectDir + `/${setup.source}`);
34
19
  }
35
- });
20
+ catch (e) {
21
+ logger_1.logger.info();
22
+ logger_1.logger.error("NPM install failed, continuing with Firebase initialization...");
23
+ }
24
+ }
36
25
  }
37
26
  exports.askInstallDependencies = askInstallDependencies;
@@ -7,6 +7,7 @@ const path = require("path");
7
7
  const python_1 = require("../../../deploy/functions/runtimes/python");
8
8
  const python_2 = require("../../../functions/python");
9
9
  const prompt_1 = require("../../../prompt");
10
+ const supported_1 = require("../../../deploy/functions/runtimes/supported");
10
11
  const TEMPLATE_ROOT = path.resolve(__dirname, "../../../../templates/init/functions/python");
11
12
  const MAIN_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "main.py"), "utf8");
12
13
  const REQUIREMENTS_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "requirements.txt"), "utf8");
@@ -15,9 +16,9 @@ async function setup(setup, config) {
15
16
  await config.askWriteProjectFile(`${setup.functions.source}/requirements.txt`, REQUIREMENTS_TEMPLATE);
16
17
  await config.askWriteProjectFile(`${setup.functions.source}/.gitignore`, GITIGNORE_TEMPLATE);
17
18
  await config.askWriteProjectFile(`${setup.functions.source}/main.py`, MAIN_TEMPLATE);
18
- config.set("functions.runtime", python_1.LATEST_VERSION);
19
+ config.set("functions.runtime", (0, supported_1.latest)("python"));
19
20
  config.set("functions.ignore", ["venv", "__pycache__"]);
20
- const venvProcess = spawn((0, python_1.getPythonBinary)(python_1.LATEST_VERSION), ["-m", "venv", "venv"], {
21
+ const venvProcess = spawn((0, python_1.getPythonBinary)((0, supported_1.latest)("python")), ["-m", "venv", "venv"], {
21
22
  shell: true,
22
23
  cwd: config.path(setup.functions.source),
23
24
  stdio: ["pipe", "pipe", "pipe", "pipe"],
@@ -38,7 +39,7 @@ async function setup(setup, config) {
38
39
  upgradeProcess.on("exit", resolve);
39
40
  upgradeProcess.on("error", reject);
40
41
  });
41
- const installProcess = (0, python_2.runWithVirtualEnv)([(0, python_1.getPythonBinary)(python_1.LATEST_VERSION), "-m", "pip", "install", "-r", "requirements.txt"], config.path(setup.functions.source), {}, { stdio: ["inherit", "inherit", "inherit"] });
42
+ const installProcess = (0, python_2.runWithVirtualEnv)([(0, python_1.getPythonBinary)((0, supported_1.latest)("python")), "-m", "pip", "install", "-r", "requirements.txt"], config.path(setup.functions.source), {}, { stdio: ["inherit", "inherit", "inherit"] });
42
43
  await new Promise((resolve, reject) => {
43
44
  installProcess.on("exit", resolve);
44
45
  installProcess.on("error", reject);
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.doSetup = void 0;
4
+ const logger_1 = require("../../logger");
5
+ const functions_1 = require("./functions");
6
+ const prompt_1 = require("../../prompt");
7
+ const spawn_1 = require("../spawn");
8
+ async function doSetup(setup, config, options) {
9
+ if (setup.functions?.languageChoice !== "typescript") {
10
+ const continueFunctions = await (0, prompt_1.promptOnce)({
11
+ type: "confirm",
12
+ message: "Genkit's Firebase integration uses Cloud Functions for Firebase with TypeScript. Initialize Functions to continue?",
13
+ default: true,
14
+ });
15
+ if (!continueFunctions) {
16
+ logger_1.logger.info("Stopped Genkit initialization");
17
+ return;
18
+ }
19
+ setup.languageOverride = "typescript";
20
+ await (0, functions_1.doSetup)(setup, config, options);
21
+ delete setup.languageOverride;
22
+ logger_1.logger.info();
23
+ }
24
+ const projectDir = `${config.projectDir}/${setup.functions.source}`;
25
+ const installType = await (0, prompt_1.promptOnce)({
26
+ type: "list",
27
+ message: "Install the Genkit CLI globally or locally in this project?",
28
+ choices: [
29
+ { name: "Globally", value: "globally" },
30
+ { name: "Just this project", value: "project" },
31
+ ],
32
+ });
33
+ try {
34
+ logger_1.logger.info("Installing Genkit CLI");
35
+ if (installType === "globally") {
36
+ await (0, spawn_1.wrapSpawn)("npm", ["install", "-g", "genkit"], projectDir);
37
+ await (0, spawn_1.wrapSpawn)("genkit", ["init", "-p", "firebase"], projectDir);
38
+ logger_1.logger.info("Start the Genkit developer experience by running:");
39
+ logger_1.logger.info(` cd ${setup.functions.source} && genkit start`);
40
+ }
41
+ else {
42
+ await (0, spawn_1.wrapSpawn)("npm", ["install", "genkit", "--save-dev"], projectDir);
43
+ await (0, spawn_1.wrapSpawn)("npx", ["genkit", "init", "-p", "firebase"], projectDir);
44
+ logger_1.logger.info("Start the Genkit developer experience by running:");
45
+ logger_1.logger.info(` cd ${setup.functions.source} && npx genkit start`);
46
+ }
47
+ }
48
+ catch (e) {
49
+ logger_1.logger.error("Genkit initialization failed...");
50
+ return;
51
+ }
52
+ }
53
+ exports.doSetup = doSetup;
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isRunningInGithubAction = exports.initGitHub = void 0;
4
4
  const colorette_1 = require("colorette");
5
5
  const fs = require("fs");
6
- const yaml = require("js-yaml");
7
- const js_yaml_1 = require("js-yaml");
6
+ const yaml = require("yaml");
8
7
  const ora = require("ora");
9
8
  const path = require("path");
10
9
  const libsodium = require("libsodium-wrappers");
@@ -149,7 +148,7 @@ function loadYMLDeploy() {
149
148
  }
150
149
  }
151
150
  function loadYML(ymlPath) {
152
- return (0, js_yaml_1.safeLoad)(fs.readFileSync(ymlPath, "utf8"));
151
+ return yaml.parse(fs.readFileSync(ymlPath, "utf8"));
153
152
  }
154
153
  function mkdirNotExists(dir) {
155
154
  if (!(0, fsutils_1.dirExistsSync)(dir)) {
@@ -189,7 +188,7 @@ function writeChannelActionYMLFile(ymlPath, secretName, projectId, script) {
189
188
  const ymlContents = `# This file was auto-generated by the Firebase CLI
190
189
  # https://github.com/firebase/firebase-tools
191
190
 
192
- ${yaml.safeDump(workflowConfig)}`;
191
+ ${yaml.stringify(workflowConfig)}`;
193
192
  mkdirNotExists(GITHUB_DIR);
194
193
  mkdirNotExists(WORKFLOW_DIR);
195
194
  fs.writeFileSync(ymlPath, ymlContents, "utf8");
@@ -222,7 +221,7 @@ function writeDeployToProdActionYMLFile(ymlPath, branch, secretName, projectId,
222
221
  const ymlContents = `# This file was auto-generated by the Firebase CLI
223
222
  # https://github.com/firebase/firebase-tools
224
223
 
225
- ${yaml.safeDump(workflowConfig)}`;
224
+ ${yaml.stringify(workflowConfig)}`;
226
225
  mkdirNotExists(GITHUB_DIR);
227
226
  mkdirNotExists(WORKFLOW_DIR);
228
227
  fs.writeFileSync(ymlPath, ymlContents, "utf8");
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.apphosting = exports.hostingGithub = exports.remoteconfig = exports.project = exports.extensions = exports.emulators = exports.storage = exports.hosting = exports.functions = exports.firestore = exports.database = exports.account = void 0;
3
+ exports.genkit = exports.apphosting = exports.dataconnect = exports.hostingGithub = exports.remoteconfig = exports.project = exports.extensions = exports.emulators = exports.storage = exports.hosting = exports.functions = exports.firestore = exports.database = exports.account = void 0;
4
4
  var account_1 = require("./account");
5
5
  Object.defineProperty(exports, "account", { enumerable: true, get: function () { return account_1.doSetup; } });
6
6
  var database_1 = require("./database");
@@ -23,5 +23,9 @@ var remoteconfig_1 = require("./remoteconfig");
23
23
  Object.defineProperty(exports, "remoteconfig", { enumerable: true, get: function () { return remoteconfig_1.doSetup; } });
24
24
  var github_1 = require("./hosting/github");
25
25
  Object.defineProperty(exports, "hostingGithub", { enumerable: true, get: function () { return github_1.initGitHub; } });
26
- var apphosting_1 = require("./apphosting");
26
+ var dataconnect_1 = require("./dataconnect");
27
+ Object.defineProperty(exports, "dataconnect", { enumerable: true, get: function () { return dataconnect_1.doSetup; } });
28
+ var apphosting_1 = require("../../apphosting");
27
29
  Object.defineProperty(exports, "apphosting", { enumerable: true, get: function () { return apphosting_1.doSetup; } });
30
+ var genkit_1 = require("./genkit");
31
+ Object.defineProperty(exports, "genkit", { enumerable: true, get: function () { return genkit_1.doSetup; } });
package/lib/init/index.js CHANGED
@@ -10,6 +10,7 @@ const featureFns = new Map([
10
10
  ["account", features.account],
11
11
  ["database", features.database],
12
12
  ["firestore", features.firestore],
13
+ ["dataconnect", features.dataconnect],
13
14
  ["functions", features.functions],
14
15
  ["hosting", features.hosting],
15
16
  ["storage", features.storage],
@@ -18,6 +19,7 @@ const featureFns = new Map([
18
19
  ["project", features.project],
19
20
  ["remoteconfig", features.remoteconfig],
20
21
  ["hosting:github", features.hostingGithub],
22
+ ["genkit", features.genkit],
21
23
  ]);
22
24
  async function init(setup, config, options) {
23
25
  const nextFeature = setup.features?.shift();
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapSpawn = void 0;
4
+ const spawn = require("cross-spawn");
5
+ const logger_1 = require("../logger");
6
+ function wrapSpawn(cmd, args, projectDir) {
7
+ return new Promise((resolve, reject) => {
8
+ const installer = spawn(cmd, args, {
9
+ cwd: projectDir,
10
+ stdio: "inherit",
11
+ });
12
+ installer.on("error", (err) => {
13
+ logger_1.logger.debug(err.stack);
14
+ });
15
+ installer.on("close", (code) => {
16
+ if (code === 0) {
17
+ return resolve();
18
+ }
19
+ return reject();
20
+ });
21
+ });
22
+ }
23
+ exports.wrapSpawn = wrapSpawn;
package/lib/logger.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logger = void 0;
3
+ exports.logger = exports.vsceLogEmitter = void 0;
4
4
  const winston = require("winston");
5
+ const utils_1 = require("./utils");
6
+ const events_1 = require("events");
7
+ exports.vsceLogEmitter = new events_1.EventEmitter();
5
8
  function expandErrors(logger) {
6
9
  const oldLogFunc = logger.log.bind(logger);
7
10
  const newLogFunc = function (levelOrEntry, message, ...meta) {
@@ -25,7 +28,24 @@ function annotateDebugLines(logger) {
25
28
  logger.debug = newDebug;
26
29
  return logger;
27
30
  }
31
+ function maybeUseVSCodeLogger(logger) {
32
+ if (!(0, utils_1.isVSCodeExtension)()) {
33
+ return logger;
34
+ }
35
+ const oldLogFunc = logger.log.bind(logger);
36
+ const vsceLogger = function (levelOrEntry, message, ...meta) {
37
+ if (message) {
38
+ exports.vsceLogEmitter.emit("log", { level: levelOrEntry, message });
39
+ }
40
+ else {
41
+ exports.vsceLogEmitter.emit("log", levelOrEntry);
42
+ }
43
+ return oldLogFunc(levelOrEntry, message, ...meta);
44
+ };
45
+ logger.log = vsceLogger;
46
+ return logger;
47
+ }
28
48
  const rawLogger = winston.createLogger();
29
49
  rawLogger.add(new winston.transports.Console({ silent: true }));
30
50
  rawLogger.exitOnError = false;
31
- exports.logger = annotateDebugLines(expandErrors(rawLogger));
51
+ exports.logger = maybeUseVSCodeLogger(annotateDebugLines(expandErrors(rawLogger)));
@@ -21,7 +21,7 @@ class OperationPoller {
21
21
  if (error) {
22
22
  throw error instanceof error_1.FirebaseError
23
23
  ? error
24
- : new error_1.FirebaseError(error.message, { status: error.code });
24
+ : new error_1.FirebaseError(error.message, { status: error.code, original: error });
25
25
  }
26
26
  return response;
27
27
  }
@@ -45,7 +45,13 @@ class OperationPoller {
45
45
  if (options.onPoll) {
46
46
  options.onPoll(res.body);
47
47
  }
48
- if (!res.body.done) {
48
+ if (options.doneFn) {
49
+ const done = options.doneFn(res.body);
50
+ if (!done) {
51
+ throw new Error("Polling incomplete, should trigger retry with backoff");
52
+ }
53
+ }
54
+ else if (!res.body.done) {
49
55
  throw new Error("Polling incomplete, should trigger retry with backoff");
50
56
  }
51
57
  return res.body;
package/lib/rc.js CHANGED
@@ -37,7 +37,7 @@ class RC {
37
37
  }
38
38
  constructor(rcpath, data) {
39
39
  this.path = rcpath;
40
- this.data = { projects: {}, targets: {}, etags: {}, ...data };
40
+ this.data = { projects: {}, targets: {}, etags: {}, dataconnectEmulatorConfig: {}, ...data };
41
41
  }
42
42
  set(key, value) {
43
43
  _.set(this.data, key, value);
@@ -150,6 +150,14 @@ class RC {
150
150
  this.data.etags[projectId][resourceType] = etagData;
151
151
  this.save();
152
152
  }
153
+ getDataconnect() {
154
+ return this.data.dataconnectEmulatorConfig ?? {};
155
+ }
156
+ setDataconnect(localConnectionString) {
157
+ if (!this.data.dataconnectEmulatorConfig) {
158
+ this.data.dataconnectEmulatorConfig = { postgres: { localConnectionString } };
159
+ }
160
+ }
153
161
  save() {
154
162
  if (this.path) {
155
163
  fs.writeFileSync(this.path, JSON.stringify(this.data, null, 2), {
@@ -10,7 +10,6 @@ const logger_1 = require("./logger");
10
10
  const utils = require("./utils");
11
11
  const scopes = require("./scopes");
12
12
  const auth_1 = require("./auth");
13
- const monospace_1 = require("./monospace");
14
13
  const AUTH_ERROR_MESSAGE = `Command requires authentication, please run ${clc.bold("firebase login")}`;
15
14
  let authClient;
16
15
  function getAuthClient(config) {
@@ -32,13 +31,6 @@ async function autoAuth(options, authScopes) {
32
31
  catch (e) {
33
32
  logger_1.logger.debug(`Error getting account credentials.`);
34
33
  }
35
- if (!options.isVSCE && (0, monospace_1.isMonospaceEnv)()) {
36
- await (0, monospace_1.selectProjectInMonospace)({
37
- projectRoot: options.config.projectDir,
38
- project: options.project,
39
- isVSCE: options.isVSCE,
40
- });
41
- }
42
34
  return clientEmail;
43
35
  }
44
36
  async function requireAuth(options) {
@@ -77,5 +69,6 @@ async function requireAuth(options) {
77
69
  throw new error_1.FirebaseError(AUTH_ERROR_MESSAGE);
78
70
  }
79
71
  (0, auth_1.setActiveAccount)(options, { user, tokens });
72
+ return user.email;
80
73
  }
81
74
  exports.requireAuth = requireAuth;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireTosAcceptance = void 0;
4
+ const error_1 = require("./error");
5
+ const firedata_1 = require("./gcp/firedata");
6
+ const api_1 = require("./api");
7
+ const consoleLandingPage = new Map([
8
+ [firedata_1.APPHOSTING_TOS_ID, `${(0, api_1.consoleOrigin)()}/project/_/apphosting`],
9
+ [firedata_1.DATA_CONNECT_TOS_ID, `${(0, api_1.consoleOrigin)()}/project/_/dataconnect`],
10
+ ]);
11
+ function requireTosAcceptance(tosId) {
12
+ return () => requireTos(tosId);
13
+ }
14
+ exports.requireTosAcceptance = requireTosAcceptance;
15
+ async function requireTos(tosId) {
16
+ const res = await (0, firedata_1.getTosStatus)();
17
+ if ((0, firedata_1.isProductTosAccepted)(res, tosId)) {
18
+ return;
19
+ }
20
+ const console = consoleLandingPage.get(tosId) || (0, api_1.consoleOrigin)();
21
+ throw new error_1.FirebaseError(`Your account has not accepted the required Terms of Service for this action. Please accept the Terms of Service and try again. ${console}`);
22
+ }