firebase-tools-with-isolate 13.9.0 → 13.15.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 (125) hide show
  1. package/lib/api.js +4 -2
  2. package/lib/apphosting/githubConnections.js +125 -37
  3. package/lib/apphosting/index.js +3 -8
  4. package/lib/auth.js +14 -15
  5. package/lib/bin/firebase.js +7 -5
  6. package/lib/commands/dataconnect-sdk-generate.js +17 -15
  7. package/lib/commands/dataconnect-services-list.js +2 -8
  8. package/lib/commands/dataconnect-sql-migrate.js +0 -1
  9. package/lib/commands/deploy.js +7 -1
  10. package/lib/commands/ext-configure.js +1 -6
  11. package/lib/commands/ext-dev-init.js +27 -30
  12. package/lib/commands/ext-dev-upload.js +4 -6
  13. package/lib/commands/ext-info.js +3 -5
  14. package/lib/commands/ext-install.js +0 -5
  15. package/lib/commands/ext-uninstall.js +0 -5
  16. package/lib/commands/ext-update.js +0 -5
  17. package/lib/commands/firestore-backups-schedules-create.js +11 -14
  18. package/lib/commands/firestore-backups-schedules-list.js +1 -1
  19. package/lib/commands/firestore-backups-schedules-update.js +4 -3
  20. package/lib/commands/firestore-databases-create.js +24 -7
  21. package/lib/commands/firestore-databases-restore.js +4 -4
  22. package/lib/commands/firestore-databases-update.js +5 -6
  23. package/lib/commands/functions-secrets-set.js +9 -6
  24. package/lib/commands/help.js +2 -0
  25. package/lib/commands/hosting-channel-create.js +1 -1
  26. package/lib/commands/hosting-channel-delete.js +1 -1
  27. package/lib/commands/hosting-channel-deploy.js +1 -1
  28. package/lib/commands/hosting-clone.js +1 -2
  29. package/lib/commands/index.js +9 -11
  30. package/lib/commands/init.js +16 -12
  31. package/lib/commands/login.js +1 -2
  32. package/lib/commands/setup-emulators-dataconnect.js +22 -3
  33. package/lib/config.js +5 -0
  34. package/lib/crashlytics/buildToolsJarHelper.js +2 -1
  35. package/lib/dataconnect/build.js +1 -9
  36. package/lib/dataconnect/client.js +67 -28
  37. package/lib/dataconnect/errors.js +17 -9
  38. package/lib/dataconnect/fileUtils.js +30 -7
  39. package/lib/dataconnect/filters.js +12 -1
  40. package/lib/dataconnect/graphqlError.js +6 -3
  41. package/lib/dataconnect/load.js +9 -7
  42. package/lib/dataconnect/names.js +21 -1
  43. package/lib/dataconnect/provisionCloudSql.js +37 -20
  44. package/lib/dataconnect/schemaMigration.js +119 -66
  45. package/lib/dataconnect/types.js +8 -1
  46. package/lib/deploy/dataconnect/deploy.js +1 -0
  47. package/lib/deploy/dataconnect/prepare.js +16 -2
  48. package/lib/deploy/dataconnect/release.js +0 -1
  49. package/lib/deploy/functions/build.js +10 -1
  50. package/lib/deploy/functions/prepare.js +1 -1
  51. package/lib/deploy/functions/runtimes/discovery/index.js +2 -1
  52. package/lib/deploy/functions/runtimes/supported/types.js +6 -0
  53. package/lib/emulator/adminSdkConfig.test.js +16 -0
  54. package/lib/emulator/constants.js +1 -0
  55. package/lib/emulator/controller.js +4 -9
  56. package/lib/emulator/dataconnectEmulator.js +181 -35
  57. package/lib/emulator/download.js +4 -0
  58. package/lib/emulator/downloadableEmulators.js +54 -28
  59. package/lib/emulator/eventarcEmulator.js +68 -18
  60. package/lib/emulator/functionsEmulator.js +89 -0
  61. package/lib/emulator/functionsEmulatorShared.js +4 -0
  62. package/lib/emulator/hub.js +1 -1
  63. package/lib/emulator/portUtils.js +20 -2
  64. package/lib/emulator/pubsubEmulator.js +1 -1
  65. package/lib/emulator/registry.js +1 -1
  66. package/lib/emulator/storage/apis/shared.js +2 -1
  67. package/lib/emulator/storage/persistence.js +5 -13
  68. package/lib/emulator/storage/rfc.js +9 -0
  69. package/lib/emulator/storage/rules/config.js +4 -2
  70. package/lib/emulator/storage/rules/runtime.js +1 -1
  71. package/lib/experiments.js +8 -3
  72. package/lib/extensions/askUserForParam.js +1 -1
  73. package/lib/extensions/change-log.js +2 -4
  74. package/lib/extensions/displayExtensionInfo.js +0 -5
  75. package/lib/extensions/extensionsHelper.js +5 -7
  76. package/lib/extensions/provisioningHelper.js +1 -1
  77. package/lib/extensions/updateHelper.js +1 -2
  78. package/lib/extensions/warnings.js +2 -7
  79. package/lib/firestore/api-sort.test.js +74 -0
  80. package/lib/firestore/api.js +8 -7
  81. package/lib/firestore/backupUtils.test.js +18 -0
  82. package/lib/firestore/pretty-print.js +21 -1
  83. package/lib/firestore/pretty-print.test.js +61 -0
  84. package/lib/firestore/util.test.js +42 -0
  85. package/lib/frameworks/angular/utils.js +21 -8
  86. package/lib/frameworks/compose/discover/mockFileSystem.js +36 -0
  87. package/lib/frameworks/index.js +2 -6
  88. package/lib/frameworks/next/utils.js +2 -9
  89. package/lib/frameworks/nuxt/index.js +3 -3
  90. package/lib/functions/events/v2.js +2 -1
  91. package/lib/gcp/cloudsql/cloudsqladmin.js +20 -2
  92. package/lib/gcp/cloudsql/connect.js +6 -6
  93. package/lib/gcp/devConnect.js +36 -1
  94. package/lib/hosting/implicitInit.js +2 -2
  95. package/lib/init/features/dataconnect/index.js +252 -124
  96. package/lib/init/features/dataconnect/sdk.js +131 -0
  97. package/lib/init/features/firestore/indexes.js +2 -2
  98. package/lib/init/features/firestore/rules.js +2 -2
  99. package/lib/init/features/functions/javascript.js +6 -8
  100. package/lib/init/features/functions/python.js +4 -6
  101. package/lib/init/features/functions/typescript.js +8 -10
  102. package/lib/init/features/hosting/github.js +43 -21
  103. package/lib/init/features/hosting/index.js +3 -3
  104. package/lib/init/features/index.js +3 -1
  105. package/lib/init/features/storage.js +2 -2
  106. package/lib/init/index.js +1 -0
  107. package/lib/listFiles.js +1 -1
  108. package/lib/management/apps.js +2 -2
  109. package/lib/rc.js +2 -3
  110. package/lib/requireAuth.js +8 -0
  111. package/lib/rulesDeploy.js +14 -12
  112. package/lib/templates.js +23 -0
  113. package/lib/track.js +29 -2
  114. package/lib/utils.js +2 -2
  115. package/package.json +25 -24
  116. package/schema/connector-yaml.json +36 -4
  117. package/schema/dataconnect-yaml.json +4 -0
  118. package/schema/firebase-config.json +2 -8
  119. package/templates/_gitignore +3 -0
  120. package/templates/init/dataconnect/connector.yaml +11 -0
  121. package/templates/init/dataconnect/dataconnect.yaml +2 -1
  122. package/templates/init/dataconnect/mutations.gql +18 -13
  123. package/templates/init/dataconnect/queries.gql +34 -29
  124. package/templates/init/dataconnect/schema.gql +1 -1
  125. package/lib/extensions/billingMigrationHelper.js +0 -61
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initAction = exports.command = void 0;
4
4
  const clc = require("colorette");
5
- const fs = require("fs");
6
5
  const os = require("os");
7
6
  const path = require("path");
8
7
  const command_1 = require("../command");
@@ -15,10 +14,10 @@ const requireAuth_1 = require("../requireAuth");
15
14
  const fsutils = require("../fsutils");
16
15
  const utils = require("../utils");
17
16
  const experiments_1 = require("../experiments");
17
+ const templates_1 = require("../templates");
18
18
  const homeDir = os.homedir();
19
- const TEMPLATE_ROOT = path.resolve(__dirname, "../../templates/");
20
- const BANNER_TEXT = fs.readFileSync(path.join(TEMPLATE_ROOT, "banner.txt"), "utf8");
21
- const GITIGNORE_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_gitignore"), "utf8");
19
+ const BANNER_TEXT = (0, templates_1.readTemplateSync)("banner.txt");
20
+ const GITIGNORE_TEMPLATE = (0, templates_1.readTemplateSync)("_gitignore");
22
21
  function isOutside(from, to) {
23
22
  return !!/^\.\./.exec(path.relative(from, to));
24
23
  }
@@ -47,6 +46,7 @@ const choices = [
47
46
  value: "hosting:github",
48
47
  name: "Hosting: Set up GitHub Action deploys",
49
48
  checked: false,
49
+ hidden: true,
50
50
  },
51
51
  {
52
52
  value: "storage",
@@ -68,6 +68,17 @@ const choices = [
68
68
  name: "Extensions: Set up an empty Extensions manifest",
69
69
  checked: false,
70
70
  },
71
+ {
72
+ value: "dataconnect",
73
+ name: "Data Connect: Set up a Firebase Data Connect service",
74
+ checked: false,
75
+ },
76
+ {
77
+ value: "dataconnect:sdk",
78
+ name: "Data Connect: Set up a generated SDK for your Firebase Data Connect service",
79
+ checked: false,
80
+ hidden: true,
81
+ },
71
82
  ];
72
83
  if ((0, experiments_1.isEnabled)("genkit")) {
73
84
  choices.push({
@@ -76,13 +87,6 @@ if ((0, experiments_1.isEnabled)("genkit")) {
76
87
  checked: false,
77
88
  });
78
89
  }
79
- if ((0, experiments_1.isEnabled)("dataconnect")) {
80
- choices.push({
81
- value: "dataconnect",
82
- name: "Data Connect: Set up a Firebase Data Connect service.",
83
- checked: false,
84
- });
85
- }
86
90
  const featureNames = choices.map((choice) => choice.value);
87
91
  const DESCRIPTION = `Interactively configure the current directory as a Firebase project or initialize new features in an already configured Firebase project directory.
88
92
 
@@ -163,7 +167,7 @@ function initAction(feature, options) {
163
167
  name: "features",
164
168
  message: "Which Firebase features do you want to set up for this directory? " +
165
169
  "Press Space to select features, then Enter to confirm your choices.",
166
- choices: choices,
170
+ choices: choices.filter((c) => !c.hidden),
167
171
  },
168
172
  ]);
169
173
  })
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.command = void 0;
4
- const _ = require("lodash");
5
4
  const clc = require("colorette");
6
5
  const command_1 = require("../command");
7
6
  const logger_1 = require("../logger");
@@ -40,7 +39,7 @@ exports.command = new command_1.Command("login")
40
39
  }
41
40
  }
42
41
  const useLocalhost = (0, utils_1.isCloudEnvironment)() ? false : options.localhost;
43
- const result = await auth.loginGoogle(useLocalhost, _.get(user, "email"));
42
+ const result = await auth.loginGoogle(useLocalhost, user?.email);
44
43
  configstore_1.configstore.set("user", result.user);
45
44
  configstore_1.configstore.set("tokens", result.tokens);
46
45
  configstore_1.configstore.set("loginScopes", result.scopes);
@@ -2,11 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.command = void 0;
4
4
  const command_1 = require("../command");
5
- const download_1 = require("../emulator/download");
6
5
  const types_1 = require("../emulator/types");
6
+ const emulators_1 = require("../init/features/emulators");
7
+ const prompt_1 = require("../prompt");
8
+ const logger_1 = require("../logger");
9
+ const downloadableEmulators_1 = require("../emulator/downloadableEmulators");
7
10
  const NAME = types_1.Emulators.DATACONNECT;
8
11
  exports.command = new command_1.Command(`setup:emulators:${NAME}`)
9
12
  .description(`downloads the ${NAME} emulator`)
10
- .action(() => {
11
- return (0, download_1.downloadEmulator)(NAME);
13
+ .action(async (options) => {
14
+ await (0, downloadableEmulators_1.downloadIfNecessary)(NAME);
15
+ if (!options.config) {
16
+ logger_1.logger.info("Not currently in a Firebase project directory. Run this command from a project directory to configure the Data Connect emulator.");
17
+ return;
18
+ }
19
+ if (!options.nonInteractive) {
20
+ const dataconnectEmulatorConfig = options.rc.getDataconnect();
21
+ const defaultConnectionString = dataconnectEmulatorConfig?.postgres?.localConnectionString ?? emulators_1.DEFAULT_POSTGRES_CONNECTION;
22
+ const localConnectionString = await (0, prompt_1.promptOnce)({
23
+ type: "input",
24
+ name: "localConnectionString",
25
+ message: `What is the connection string of the local Postgres instance you would like to use with the Data Connect emulator?`,
26
+ default: defaultConnectionString,
27
+ });
28
+ options.rc.setDataconnect(localConnectionString);
29
+ }
30
+ logger_1.logger.info("Setup complete!");
12
31
  });
package/lib/config.js CHANGED
@@ -53,6 +53,11 @@ class Config {
53
53
  }
54
54
  }
55
55
  }
56
+ if (this._src.dataconnect?.location ||
57
+ (Array.isArray(this._src.dataconnect) && this._src.dataconnect.some((c) => c?.location))) {
58
+ utils.logLabeledWarning("dataconnect", "'location' has been moved from 'firebase.json' to 'dataconnect.yaml'. " +
59
+ "Please remove 'dataconnect.location' from 'firebase.json' and add it as top level field to 'dataconnect.yaml' instead ");
60
+ }
56
61
  }
57
62
  materialize(target) {
58
63
  const val = _.get(this._src, target);
@@ -12,10 +12,11 @@ const rimraf = require("rimraf");
12
12
  const utils = require("../utils");
13
13
  const JAR_CACHE_DIR = process.env.FIREBASE_CRASHLYTICS_BUILDTOOLS_PATH ||
14
14
  path.join(os.homedir(), ".cache", "firebase", "crashlytics", "buildtools");
15
- const JAR_VERSION = "2.9.2";
15
+ const JAR_VERSION = "3.0.2";
16
16
  const JAR_URL = `https://dl.google.com/android/maven2/com/google/firebase/firebase-crashlytics-buildtools/${JAR_VERSION}/firebase-crashlytics-buildtools-${JAR_VERSION}.jar`;
17
17
  async function fetchBuildtoolsJar() {
18
18
  if (process.env.CRASHLYTICS_LOCAL_JAR) {
19
+ logger_1.logger.debug(`Using local Crashlytics Jar override at ${process.env.CRASHLYTICS_LOCAL_JAR}`);
19
20
  return process.env.CRASHLYTICS_LOCAL_JAR;
20
21
  }
21
22
  const jarPath = path.join(JAR_CACHE_DIR, `crashlytics-buildtools-${JAR_VERSION}.jar`);
@@ -5,15 +5,7 @@ const dataconnectEmulator_1 = require("../emulator/dataconnectEmulator");
5
5
  const error_1 = require("../error");
6
6
  const graphqlError_1 = require("./graphqlError");
7
7
  async function build(options, configDir) {
8
- const projectId = options.project ?? "demo-test";
9
- const args = {
10
- projectId,
11
- configDir,
12
- auto_download: true,
13
- rc: options.rc,
14
- };
15
- const dataconnectEmulator = new dataconnectEmulator_1.DataConnectEmulator(args);
16
- const buildResult = await dataconnectEmulator.build();
8
+ const buildResult = await dataconnectEmulator_1.DataConnectEmulator.build({ configDir });
17
9
  if (buildResult?.errors?.length) {
18
10
  throw new error_1.FirebaseError(`There are errors in your schema and connector files:\n${buildResult.errors.map(graphqlError_1.prettify).join("\n")}`);
19
11
  }
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.upsertConnector = exports.listConnectors = exports.deleteConnector = exports.getConnector = exports.upsertSchema = exports.getSchema = exports.deleteService = exports.createService = exports.listServices = exports.listAllServices = exports.listLocations = void 0;
3
+ exports.upsertConnector = exports.listConnectors = exports.deleteConnector = exports.getConnector = exports.deleteSchema = exports.upsertSchema = exports.getSchema = exports.deleteServiceAndChildResources = exports.createService = exports.listAllServices = exports.getService = exports.listLocations = void 0;
4
4
  const api_1 = require("../api");
5
5
  const apiv2_1 = require("../apiv2");
6
6
  const operationPoller = require("../operation-poller");
7
7
  const types = require("./types");
8
- const logger_1 = require("../logger");
9
8
  const DATACONNECT_API_VERSION = "v1alpha";
9
+ const PAGE_SIZE_MAX = 100;
10
10
  const dataconnectClient = () => new apiv2_1.Client({
11
11
  urlPrefix: (0, api_1.dataconnectOrigin)(),
12
12
  apiVersion: DATACONNECT_API_VERSION,
@@ -17,26 +17,16 @@ async function listLocations(projectId) {
17
17
  return res.body?.locations?.map((l) => l.locationId) ?? [];
18
18
  }
19
19
  exports.listLocations = listLocations;
20
- async function listAllServices(projectId) {
21
- const locations = await listLocations(projectId);
22
- let services = [];
23
- await Promise.all(locations.map(async (l) => {
24
- try {
25
- const locationServices = await listServices(projectId, l);
26
- services = services.concat(locationServices);
27
- }
28
- catch (err) {
29
- logger_1.logger.debug(`Unable to listServices in ${l}: ${err}`);
30
- }
31
- }));
32
- return services;
20
+ async function getService(serviceName) {
21
+ const res = await dataconnectClient().get(serviceName);
22
+ return res.body;
33
23
  }
34
- exports.listAllServices = listAllServices;
35
- async function listServices(projectId, locationId) {
36
- const res = await dataconnectClient().get(`/projects/${projectId}/locations/${locationId}/services`);
24
+ exports.getService = getService;
25
+ async function listAllServices(projectId) {
26
+ const res = await dataconnectClient().get(`/projects/${projectId}/locations/-/services`);
37
27
  return res.body.services ?? [];
38
28
  }
39
- exports.listServices = listServices;
29
+ exports.listAllServices = listAllServices;
40
30
  async function createService(projectId, locationId, serviceId) {
41
31
  const op = await dataconnectClient().post(`/projects/${projectId}/locations/${locationId}/services`, {
42
32
  name: `projects/${projectId}/locations/${locationId}/services/${serviceId}`,
@@ -53,8 +43,8 @@ async function createService(projectId, locationId, serviceId) {
53
43
  return pollRes;
54
44
  }
55
45
  exports.createService = createService;
56
- async function deleteService(projectId, locationId, serviceId) {
57
- const op = await dataconnectClient().delete(`projects/${projectId}/locations/${locationId}/services/${serviceId}?force=true`);
46
+ async function deleteService(serviceName) {
47
+ const op = await dataconnectClient().delete(serviceName);
58
48
  const pollRes = await operationPoller.pollOperation({
59
49
  apiOrigin: (0, api_1.dataconnectOrigin)(),
60
50
  apiVersion: DATACONNECT_API_VERSION,
@@ -62,10 +52,31 @@ async function deleteService(projectId, locationId, serviceId) {
62
52
  });
63
53
  return pollRes;
64
54
  }
65
- exports.deleteService = deleteService;
55
+ async function deleteServiceAndChildResources(serviceName) {
56
+ const connectors = await listConnectors(serviceName);
57
+ await Promise.all(connectors.map(async (c) => deleteConnector(c.name)));
58
+ try {
59
+ await deleteSchema(serviceName);
60
+ }
61
+ catch (err) {
62
+ if (err.status !== 404) {
63
+ throw err;
64
+ }
65
+ }
66
+ await deleteService(serviceName);
67
+ }
68
+ exports.deleteServiceAndChildResources = deleteServiceAndChildResources;
66
69
  async function getSchema(serviceName) {
67
- const res = await dataconnectClient().get(`${serviceName}/schemas/${types.SCHEMA_ID}`);
68
- return res.body;
70
+ try {
71
+ const res = await dataconnectClient().get(`${serviceName}/schemas/${types.SCHEMA_ID}`);
72
+ return res.body;
73
+ }
74
+ catch (err) {
75
+ if (err.status !== 404) {
76
+ throw err;
77
+ }
78
+ return undefined;
79
+ }
69
80
  }
70
81
  exports.getSchema = getSchema;
71
82
  async function upsertSchema(schema, validateOnly = false) {
@@ -85,19 +96,47 @@ async function upsertSchema(schema, validateOnly = false) {
85
96
  });
86
97
  }
87
98
  exports.upsertSchema = upsertSchema;
99
+ async function deleteSchema(serviceName) {
100
+ const op = await dataconnectClient().delete(`${serviceName}/schemas/${types.SCHEMA_ID}`);
101
+ await operationPoller.pollOperation({
102
+ apiOrigin: (0, api_1.dataconnectOrigin)(),
103
+ apiVersion: DATACONNECT_API_VERSION,
104
+ operationResourceName: op.body.name,
105
+ });
106
+ return;
107
+ }
108
+ exports.deleteSchema = deleteSchema;
88
109
  async function getConnector(name) {
89
110
  const res = await dataconnectClient().get(name);
90
111
  return res.body;
91
112
  }
92
113
  exports.getConnector = getConnector;
93
114
  async function deleteConnector(name) {
94
- const res = await dataconnectClient().delete(name);
95
- return res.body;
115
+ const op = await dataconnectClient().delete(name);
116
+ await operationPoller.pollOperation({
117
+ apiOrigin: (0, api_1.dataconnectOrigin)(),
118
+ apiVersion: DATACONNECT_API_VERSION,
119
+ operationResourceName: op.body.name,
120
+ });
121
+ return;
96
122
  }
97
123
  exports.deleteConnector = deleteConnector;
98
124
  async function listConnectors(serviceName) {
99
- const res = await dataconnectClient().get(`${serviceName}/connectors`);
100
- return res.body?.connectors || [];
125
+ const connectors = [];
126
+ const getNextPage = async (pageToken = "") => {
127
+ const res = await dataconnectClient().get(`${serviceName}/connectors`, {
128
+ queryParams: {
129
+ pageSize: PAGE_SIZE_MAX,
130
+ pageToken,
131
+ },
132
+ });
133
+ connectors.push(...(res.body.connectors || []));
134
+ if (res.body.nextPageToken) {
135
+ await getNextPage(res.body.nextPageToken);
136
+ }
137
+ };
138
+ await getNextPage();
139
+ return connectors;
101
140
  }
102
141
  exports.listConnectors = listConnectors;
103
142
  async function upsertConnector(connector) {
@@ -5,20 +5,23 @@ const INCOMPATIBLE_SCHEMA_ERROR_TYPESTRING = "IncompatibleSqlSchemaError";
5
5
  const PRECONDITION_ERROR_TYPESTRING = "type.googleapis.com/google.rpc.PreconditionFailure";
6
6
  const INCOMPATIBLE_CONNECTOR_TYPE = "INCOMPATIBLE_CONNECTOR";
7
7
  function getIncompatibleSchemaError(err) {
8
- const original = err.context?.body?.error || err.orignal;
9
- if (!original) {
10
- throw err;
8
+ const incompatibles = errorDetails(err, INCOMPATIBLE_SCHEMA_ERROR_TYPESTRING);
9
+ if (incompatibles.length === 0) {
10
+ return undefined;
11
11
  }
12
- const details = original.details;
13
- const incompatibles = details.filter((d) => d["@type"]?.includes(INCOMPATIBLE_SCHEMA_ERROR_TYPESTRING));
14
- return incompatibles[0];
12
+ const incompatible = incompatibles[0];
13
+ const preconditionErrs = errorDetails(err, PRECONDITION_ERROR_TYPESTRING);
14
+ const violationTypes = (incompatible.violationType = preconditionErrs
15
+ .flatMap((preCondErr) => preCondErr.violations)
16
+ .flatMap((viol) => viol.type)
17
+ .filter((type) => type === "INACCESSIBLE_SCHEMA" || type === "INCOMPATIBLE_SCHEMA"));
18
+ incompatible.violationType = violationTypes[0];
19
+ return incompatible;
15
20
  }
16
21
  exports.getIncompatibleSchemaError = getIncompatibleSchemaError;
17
22
  function getInvalidConnectors(err) {
23
+ const preconditionErrs = errorDetails(err, PRECONDITION_ERROR_TYPESTRING);
18
24
  const invalidConns = [];
19
- const original = err.context?.body?.error || err?.orignal;
20
- const details = original?.details;
21
- const preconditionErrs = details?.filter((d) => d["@type"]?.includes(PRECONDITION_ERROR_TYPESTRING));
22
25
  for (const preconditionErr of preconditionErrs) {
23
26
  const incompatibleConnViolation = preconditionErr?.violations?.filter((v) => v.type === INCOMPATIBLE_CONNECTOR_TYPE);
24
27
  const newConns = incompatibleConnViolation?.map((i) => i.subject) ?? [];
@@ -27,3 +30,8 @@ function getInvalidConnectors(err) {
27
30
  return invalidConns;
28
31
  }
29
32
  exports.getInvalidConnectors = getInvalidConnectors;
33
+ function errorDetails(err, ofType) {
34
+ const original = err.context?.body?.error || err?.original;
35
+ const details = original?.details;
36
+ return details?.filter((d) => d["@type"]?.includes(ofType)) || [];
37
+ }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pickService = exports.readGQLFiles = exports.readConnectorYaml = exports.readDataConnectYaml = exports.readFirebaseJson = void 0;
3
+ exports.getPlatformFromFolder = exports.pickService = exports.readGQLFiles = exports.readConnectorYaml = exports.readDataConnectYaml = exports.readFirebaseJson = void 0;
4
4
  const fs = require("fs-extra");
5
5
  const path = require("path");
6
6
  const error_1 = require("../error");
7
+ const types_1 = require("./types");
7
8
  const utils_1 = require("../utils");
8
9
  const load_1 = require("./load");
9
10
  function readFirebaseJson(config) {
@@ -11,12 +12,11 @@ function readFirebaseJson(config) {
11
12
  return [];
12
13
  }
13
14
  const validator = (cfg) => {
14
- if (!cfg["source"] && !cfg["location"]) {
15
- throw new error_1.FirebaseError("Invalid firebase.json: DataConnect requires `source` and `location`");
15
+ if (!cfg["source"]) {
16
+ throw new error_1.FirebaseError("Invalid firebase.json: DataConnect requires `source`");
16
17
  }
17
18
  return {
18
19
  source: cfg["source"],
19
- location: cfg["location"],
20
20
  };
21
21
  };
22
22
  const configs = config.get("dataconnect");
@@ -27,7 +27,7 @@ function readFirebaseJson(config) {
27
27
  return configs.map(validator);
28
28
  }
29
29
  else {
30
- throw new error_1.FirebaseError("Invalid firebase.json: dataconnect should be of the form { source: string, location: string }");
30
+ throw new error_1.FirebaseError("Invalid firebase.json: dataconnect should be of the form { source: string }");
31
31
  }
32
32
  }
33
33
  exports.readFirebaseJson = readFirebaseJson;
@@ -38,6 +38,9 @@ async function readDataConnectYaml(sourceDirectory) {
38
38
  }
39
39
  exports.readDataConnectYaml = readDataConnectYaml;
40
40
  function validateDataConnectYaml(unvalidated) {
41
+ if (!unvalidated["location"]) {
42
+ throw new error_1.FirebaseError("Missing required field 'location' in dataconnect.yaml");
43
+ }
41
44
  return unvalidated;
42
45
  }
43
46
  async function readConnectorYaml(sourceDirectory) {
@@ -74,13 +77,13 @@ async function pickService(projectId, config, serviceId) {
74
77
  throw new error_1.FirebaseError("No Data Connect services found in firebase.json.");
75
78
  }
76
79
  else if (serviceCfgs.length === 1) {
77
- serviceInfo = await (0, load_1.load)(projectId, serviceCfgs[0].location, serviceCfgs[0].source);
80
+ serviceInfo = await (0, load_1.load)(projectId, config, serviceCfgs[0].source);
78
81
  }
79
82
  else {
80
83
  if (!serviceId) {
81
84
  throw new error_1.FirebaseError("Multiple Data Connect services found in firebase.json. Please specify a service ID to use.");
82
85
  }
83
- const infos = await Promise.all(serviceCfgs.map((c) => (0, load_1.load)(projectId, c.location, c.source)));
86
+ const infos = await Promise.all(serviceCfgs.map((c) => (0, load_1.load)(projectId, config, c.source)));
84
87
  const maybe = infos.find((i) => i.dataConnectYaml.serviceId === serviceId);
85
88
  if (!maybe) {
86
89
  throw new error_1.FirebaseError(`No service named ${serviceId} declared in firebase.json.`);
@@ -90,3 +93,23 @@ async function pickService(projectId, config, serviceId) {
90
93
  return serviceInfo;
91
94
  }
92
95
  exports.pickService = pickService;
96
+ const WEB_INDICATORS = ["package.json", "package-lock.json", "node_modules"];
97
+ const IOS_INDICATORS = ["info.plist", "podfile", "package.swift"];
98
+ const ANDROID_INDICATORS = ["androidmanifest.xml", "build.gradle"];
99
+ const IOS_INDICATORS_2 = [".xcworkspace", ".xcodeproj"];
100
+ async function getPlatformFromFolder(dirPath) {
101
+ const fileNames = await fs.readdir(dirPath);
102
+ for (const fileName of fileNames) {
103
+ const cleanedFileName = fileName.toLowerCase();
104
+ if (WEB_INDICATORS.some((indicator) => indicator === cleanedFileName))
105
+ return types_1.Platform.WEB;
106
+ if (ANDROID_INDICATORS.some((indicator) => indicator === cleanedFileName))
107
+ return types_1.Platform.ANDROID;
108
+ if (IOS_INDICATORS.some((indicator) => indicator === cleanedFileName))
109
+ return types_1.Platform.IOS;
110
+ if (IOS_INDICATORS_2.some((indicator) => cleanedFileName.endsWith(indicator)))
111
+ return types_1.Platform.IOS;
112
+ }
113
+ return types_1.Platform.UNDETERMINED;
114
+ }
115
+ exports.getPlatformFromFolder = getPlatformFromFolder;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getResourceFilters = void 0;
3
+ exports.toString = exports.getResourceFilters = void 0;
4
4
  const error_1 = require("../error");
5
5
  function getResourceFilters(options) {
6
6
  if (!options.only) {
@@ -43,3 +43,14 @@ function parseSelector(selector) {
43
43
  }
44
44
  return filter;
45
45
  }
46
+ function toString(rf) {
47
+ const base = `dataconnect:${rf.serviceId}`;
48
+ if (rf.connectorId) {
49
+ return `${base}:${rf.connectorId}`;
50
+ }
51
+ if (rf.schemaOnly) {
52
+ return `${base}:schema`;
53
+ }
54
+ return base;
55
+ }
56
+ exports.toString = toString;
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prettify = void 0;
4
4
  function prettify(err) {
5
5
  const message = err.message;
6
- let header = err.extensions.file ?? "";
7
- if (err.locations) {
8
- header += `:${err.locations[0].line}`;
6
+ let header = err.extensions?.file ?? "";
7
+ if (err.locations && err.locations.length) {
8
+ const line = err.locations[0]?.line ?? "";
9
+ if (line) {
10
+ header += `:${line}`;
11
+ }
9
12
  }
10
13
  return header.length ? `${header}: ${message}` : message;
11
14
  }
@@ -4,16 +4,18 @@ exports.load = void 0;
4
4
  const path = require("path");
5
5
  const fileUtils = require("./fileUtils");
6
6
  const types_1 = require("./types");
7
- async function load(projectId, locationId, sourceDirectory) {
8
- const dataConnectYaml = await fileUtils.readDataConnectYaml(sourceDirectory);
9
- const serviceName = `projects/${projectId}/locations/${locationId}/services/${dataConnectYaml.serviceId}`;
10
- const schemaDir = path.join(sourceDirectory, dataConnectYaml.schema.source);
7
+ async function load(projectId, config, sourceDirectory) {
8
+ const resolvedDir = config.path(sourceDirectory);
9
+ const dataConnectYaml = await fileUtils.readDataConnectYaml(resolvedDir);
10
+ const serviceName = `projects/${projectId}/locations/${dataConnectYaml.location}/services/${dataConnectYaml.serviceId}`;
11
+ const schemaDir = path.join(resolvedDir, dataConnectYaml.schema.source);
11
12
  const schemaGQLs = await fileUtils.readGQLFiles(schemaDir);
12
13
  const connectorInfo = await Promise.all(dataConnectYaml.connectorDirs.map(async (dir) => {
13
- const connectorDir = path.join(sourceDirectory, dir);
14
+ const connectorDir = path.join(resolvedDir, dir);
14
15
  const connectorYaml = await fileUtils.readConnectorYaml(connectorDir);
15
16
  const connectorGqls = await fileUtils.readGQLFiles(connectorDir);
16
17
  return {
18
+ directory: connectorDir,
17
19
  connectorYaml,
18
20
  connector: {
19
21
  name: `${serviceName}/connectors/${connectorYaml.connectorId}`,
@@ -25,10 +27,10 @@ async function load(projectId, locationId, sourceDirectory) {
25
27
  }));
26
28
  return {
27
29
  serviceName,
28
- sourceDirectory,
30
+ sourceDirectory: resolvedDir,
29
31
  schema: {
30
32
  name: `${serviceName}/schemas/${types_1.SCHEMA_ID}`,
31
- primaryDatasource: (0, types_1.toDatasource)(projectId, locationId, dataConnectYaml.schema.datasource),
33
+ primaryDatasource: (0, types_1.toDatasource)(projectId, dataConnectYaml.location, dataConnectYaml.schema.datasource),
32
34
  source: {
33
35
  files: schemaGQLs,
34
36
  },
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseConnectorName = exports.parseServiceName = void 0;
3
+ exports.parseCloudSQLInstanceName = exports.parseConnectorName = exports.parseServiceName = void 0;
4
4
  const error_1 = require("../error");
5
5
  const serviceNameRegex = /projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/services\/(?<serviceId>[^\/]+)/;
6
6
  function parseServiceName(serviceName) {
@@ -44,3 +44,23 @@ function parseConnectorName(connectorName) {
44
44
  };
45
45
  }
46
46
  exports.parseConnectorName = parseConnectorName;
47
+ const cloudSQLInstanceNameRegex = /projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/instances\/(?<instanceId>[^\/]+)/;
48
+ function parseCloudSQLInstanceName(cloudSQLInstanceName) {
49
+ const res = cloudSQLInstanceNameRegex.exec(cloudSQLInstanceName);
50
+ const projectId = res?.groups?.projectId;
51
+ const location = res?.groups?.location;
52
+ const instanceId = res?.groups?.instanceId;
53
+ if (!projectId || !location || !instanceId) {
54
+ throw new error_1.FirebaseError(`${cloudSQLInstanceName} is not a valid cloudSQL instance name`);
55
+ }
56
+ const toString = () => {
57
+ return `projects/${projectId}/locations/${location}/services/${instanceId}`;
58
+ };
59
+ return {
60
+ projectId,
61
+ location,
62
+ instanceId,
63
+ toString,
64
+ };
65
+ }
66
+ exports.parseCloudSQLInstanceName = parseCloudSQLInstanceName;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkInstanceConfig = exports.provisionCloudSql = void 0;
3
+ exports.getUpdateReason = exports.provisionCloudSql = void 0;
4
4
  const cloudSqlAdminClient = require("../gcp/cloudsql/cloudsqladmin");
5
5
  const utils = require("../utils");
6
6
  const checkIam_1 = require("./checkIam");
@@ -9,16 +9,18 @@ const GOOGLE_ML_INTEGRATION_ROLE = "roles/aiplatform.user";
9
9
  const freeTrial_1 = require("./freeTrial");
10
10
  const error_1 = require("../error");
11
11
  async function provisionCloudSql(args) {
12
- let connectionName;
13
- const { projectId, locationId, instanceId, databaseId, enableGoogleMlIntegration, silent } = args;
12
+ let connectionName = "";
13
+ const { projectId, locationId, instanceId, databaseId, enableGoogleMlIntegration, waitForCreation, silent, } = args;
14
14
  try {
15
15
  const existingInstance = await cloudSqlAdminClient.getInstance(projectId, instanceId);
16
16
  silent || utils.logLabeledBullet("dataconnect", `Found existing instance ${instanceId}.`);
17
17
  connectionName = existingInstance?.connectionName || "";
18
- if (!checkInstanceConfig(existingInstance, enableGoogleMlIntegration)) {
18
+ const why = getUpdateReason(existingInstance, enableGoogleMlIntegration);
19
+ if (why) {
19
20
  silent ||
20
21
  utils.logLabeledBullet("dataconnect", `Instance ${instanceId} settings not compatible with Firebase Data Connect. ` +
21
- `Updating instance to enable Cloud IAM authentication and public IP. This may take a few minutes...`);
22
+ `Updating instance. This may take a few minutes...` +
23
+ why);
22
24
  await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.updateInstanceForDataConnect(existingInstance, enableGoogleMlIntegration), "Updating your instance...");
23
25
  silent || utils.logLabeledBullet("dataconnect", "Instance updated");
24
26
  }
@@ -33,21 +35,32 @@ async function provisionCloudSql(args) {
33
35
  throw new error_1.FirebaseError("Free trial unavailable.");
34
36
  }
35
37
  silent ||
36
- utils.logLabeledBullet("dataconnect", `CloudSQL instance '${instanceId}' not found, creating it. This instance is provided under the terms of the Data Connect free trial ${(0, freeTrial_1.freeTrialTermsLink)()}`);
37
- silent || utils.logLabeledBullet("dataconnect", `This may take while...`);
38
- const newInstance = await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.createInstance(projectId, locationId, instanceId, enableGoogleMlIntegration), "Creating your instance...");
39
- silent || utils.logLabeledBullet("dataconnect", "Instance created");
40
- connectionName = newInstance?.connectionName || "";
38
+ utils.logLabeledBullet("dataconnect", `CloudSQL instance '${instanceId}' not found, creating it.` +
39
+ `\nThis instance is provided under the terms of the Data Connect free trial ${(0, freeTrial_1.freeTrialTermsLink)()}` +
40
+ `\nMonitor the progress at ${cloudSqlAdminClient.instanceConsoleLink(projectId, instanceId)}`);
41
+ const newInstance = await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.createInstance(projectId, locationId, instanceId, enableGoogleMlIntegration, waitForCreation), "Creating your instance...");
42
+ if (newInstance) {
43
+ silent || utils.logLabeledBullet("dataconnect", "Instance created");
44
+ connectionName = newInstance?.connectionName || "";
45
+ }
46
+ else {
47
+ silent || utils.logLabeledBullet("dataconnect", "Instance creation process started");
48
+ }
41
49
  }
42
50
  try {
43
51
  await cloudSqlAdminClient.getDatabase(projectId, instanceId, databaseId);
44
52
  silent || utils.logLabeledBullet("dataconnect", `Found existing database ${databaseId}.`);
45
53
  }
46
54
  catch (err) {
47
- silent ||
48
- utils.logLabeledBullet("dataconnect", `Database ${databaseId} not found, creating it now...`);
49
- await cloudSqlAdminClient.createDatabase(projectId, instanceId, databaseId);
50
- silent || utils.logLabeledBullet("dataconnect", `Database ${databaseId} created.`);
55
+ if (err.status === 404) {
56
+ silent ||
57
+ utils.logLabeledBullet("dataconnect", `Database ${databaseId} not found, creating it now...`);
58
+ await cloudSqlAdminClient.createDatabase(projectId, instanceId, databaseId);
59
+ silent || utils.logLabeledBullet("dataconnect", `Database ${databaseId} created.`);
60
+ }
61
+ else {
62
+ silent || utils.logLabeledWarning("dataconnect", `Database ${databaseId} is not accessible.`);
63
+ }
51
64
  }
52
65
  if (enableGoogleMlIntegration) {
53
66
  await (0, checkIam_1.grantRolesToCloudSqlServiceAccount)(projectId, instanceId, [GOOGLE_ML_INTEGRATION_ROLE]);
@@ -55,20 +68,24 @@ async function provisionCloudSql(args) {
55
68
  return connectionName;
56
69
  }
57
70
  exports.provisionCloudSql = provisionCloudSql;
58
- function checkInstanceConfig(instance, requireGoogleMlIntegration) {
71
+ function getUpdateReason(instance, requireGoogleMlIntegration) {
72
+ let reason = "";
59
73
  const settings = instance.settings;
60
74
  if (!settings.ipConfiguration?.ipv4Enabled) {
61
- return false;
75
+ reason += "\n - to enable public IP.";
62
76
  }
63
77
  if (requireGoogleMlIntegration) {
64
78
  if (!settings.enableGoogleMlIntegration) {
65
- return false;
79
+ reason += "\n - to enable Google ML integration.";
66
80
  }
67
81
  if (!settings.databaseFlags?.some((f) => f.name === "cloudsql.enable_google_ml_integration" && f.value === "on")) {
68
- return false;
82
+ reason += "\n - to enable Google ML integration database flag.";
69
83
  }
70
84
  }
71
85
  const isIamEnabled = settings.databaseFlags?.some((f) => f.name === "cloudsql.iam_authentication" && f.value === "on") ?? false;
72
- return isIamEnabled;
86
+ if (!isIamEnabled) {
87
+ reason += "\n - to enable IAM authentication database flag.";
88
+ }
89
+ return reason;
73
90
  }
74
- exports.checkInstanceConfig = checkInstanceConfig;
91
+ exports.getUpdateReason = getUpdateReason;