firebase-tools-with-isolate 13.7.3 → 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 (106) hide show
  1. package/lib/api.js +18 -8
  2. package/lib/apiv2.js +19 -13
  3. package/lib/apphosting/app.js +40 -59
  4. package/lib/apphosting/constants.js +2 -2
  5. package/lib/apphosting/githubConnections.js +7 -9
  6. package/lib/apphosting/index.js +122 -58
  7. package/lib/apphosting/repo.js +3 -3
  8. package/lib/apphosting/secrets/index.js +7 -1
  9. package/lib/checkValidTargetFilters.js +8 -1
  10. package/lib/commands/apphosting-backends-create.js +7 -6
  11. package/lib/commands/apphosting-backends-delete.js +24 -28
  12. package/lib/commands/apphosting-backends-list.js +4 -5
  13. package/lib/commands/apphosting-secrets-access.js +1 -1
  14. package/lib/commands/apphosting-secrets-grantaccess.js +11 -7
  15. package/lib/commands/apphosting-secrets-set.js +1 -1
  16. package/lib/commands/dataconnect-sdk-generate.js +37 -0
  17. package/lib/commands/dataconnect-services-list.js +80 -0
  18. package/lib/commands/dataconnect-sql-diff.js +25 -0
  19. package/lib/commands/dataconnect-sql-migrate.js +45 -0
  20. package/lib/commands/deploy.js +27 -1
  21. package/lib/commands/index.js +11 -0
  22. package/lib/commands/init.js +10 -3
  23. package/lib/commands/setup-emulators-dataconnect.js +12 -0
  24. package/lib/config.js +1 -0
  25. package/lib/dataconnect/build.js +22 -0
  26. package/lib/dataconnect/checkIam.js +30 -0
  27. package/lib/dataconnect/client.js +112 -0
  28. package/lib/dataconnect/dataplaneClient.js +16 -0
  29. package/lib/dataconnect/ensureApis.js +12 -0
  30. package/lib/dataconnect/errors.js +29 -0
  31. package/lib/dataconnect/fileUtils.js +92 -0
  32. package/lib/dataconnect/filters.js +45 -0
  33. package/lib/dataconnect/freeTrial.js +22 -0
  34. package/lib/dataconnect/graphqlError.js +12 -0
  35. package/lib/dataconnect/load.js +40 -0
  36. package/lib/dataconnect/names.js +46 -0
  37. package/lib/dataconnect/prompts.js +20 -0
  38. package/lib/dataconnect/provisionCloudSql.js +74 -0
  39. package/lib/dataconnect/schemaMigration.js +246 -0
  40. package/lib/dataconnect/types.js +22 -0
  41. package/lib/deploy/dataconnect/deploy.js +75 -0
  42. package/lib/deploy/dataconnect/index.js +9 -0
  43. package/lib/deploy/dataconnect/prepare.js +33 -0
  44. package/lib/deploy/dataconnect/release.js +65 -0
  45. package/lib/deploy/functions/checkIam.js +4 -34
  46. package/lib/deploy/functions/release/fabricator.js +7 -2
  47. package/lib/deploy/index.js +2 -0
  48. package/lib/downloadUtils.js +2 -2
  49. package/lib/emulator/constants.js +3 -0
  50. package/lib/emulator/controller.js +39 -12
  51. package/lib/emulator/dataconnectEmulator.js +95 -0
  52. package/lib/emulator/download.js +1 -1
  53. package/lib/emulator/downloadableEmulators.js +57 -8
  54. package/lib/emulator/portUtils.js +3 -3
  55. package/lib/emulator/registry.js +6 -1
  56. package/lib/emulator/types.js +3 -0
  57. package/lib/experiments.js +19 -6
  58. package/lib/extensions/emulator/specHelper.js +5 -39
  59. package/lib/frameworks/next/index.js +6 -4
  60. package/lib/frameworks/next/utils.js +2 -1
  61. package/lib/functions/python.js +4 -3
  62. package/lib/gcp/apphosting.js +11 -1
  63. package/lib/gcp/cloudsql/cloudsqladmin.js +174 -0
  64. package/lib/gcp/cloudsql/connect.js +144 -0
  65. package/lib/gcp/cloudsql/fbToolsAuthClient.js +44 -0
  66. package/lib/gcp/devConnect.js +1 -1
  67. package/lib/gcp/firedata.js +27 -0
  68. package/lib/gcp/iam.js +33 -1
  69. package/lib/gcp/secretManager.js +1 -1
  70. package/lib/hosting/interactive.js +4 -0
  71. package/lib/init/features/dataconnect/index.js +166 -0
  72. package/lib/init/features/emulators.js +13 -1
  73. package/lib/init/features/functions/index.js +19 -3
  74. package/lib/init/features/functions/npm-dependencies.js +12 -23
  75. package/lib/init/features/genkit.js +53 -0
  76. package/lib/init/features/index.js +5 -1
  77. package/lib/init/index.js +2 -0
  78. package/lib/init/spawn.js +23 -0
  79. package/lib/logger.js +22 -2
  80. package/lib/operation-poller.js +8 -2
  81. package/lib/rc.js +9 -1
  82. package/lib/requireAuth.js +1 -8
  83. package/lib/requireTosAcceptance.js +22 -0
  84. package/lib/utils.js +55 -4
  85. package/package.json +9 -3
  86. package/schema/connector-yaml.json +54 -0
  87. package/schema/dataconnect-yaml.json +72 -0
  88. package/schema/firebase-config.json +103 -0
  89. package/templates/extensions/javascript/package.lint.json +2 -2
  90. package/templates/extensions/javascript/package.nolint.json +2 -2
  91. package/templates/extensions/typescript/package.lint.json +2 -2
  92. package/templates/extensions/typescript/package.nolint.json +2 -2
  93. package/templates/init/dataconnect/connector.yaml +2 -0
  94. package/templates/init/dataconnect/dataconnect.yaml +10 -0
  95. package/templates/init/dataconnect/mutations.gql +30 -0
  96. package/templates/init/dataconnect/queries.gql +51 -0
  97. package/templates/init/dataconnect/schema.gql +28 -0
  98. package/templates/init/functions/javascript/_gitignore +2 -1
  99. package/templates/init/functions/javascript/package.lint.json +2 -2
  100. package/templates/init/functions/javascript/package.nolint.json +2 -2
  101. package/templates/init/functions/python/_gitignore +1 -0
  102. package/templates/init/functions/typescript/_gitignore +1 -0
  103. package/templates/init/functions/typescript/package.lint.json +2 -2
  104. package/templates/init/functions/typescript/package.nolint.json +2 -2
  105. package/lib/monospace/index.js +0 -82
  106. /package/lib/{monospace/interfaces.js → gcp/cloudsql/types.js} +0 -0
@@ -0,0 +1,112 @@
1
+ "use strict";
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;
4
+ const api_1 = require("../api");
5
+ const apiv2_1 = require("../apiv2");
6
+ const operationPoller = require("../operation-poller");
7
+ const types = require("./types");
8
+ const logger_1 = require("../logger");
9
+ const DATACONNECT_API_VERSION = "v1alpha";
10
+ const dataconnectClient = () => new apiv2_1.Client({
11
+ urlPrefix: (0, api_1.dataconnectOrigin)(),
12
+ apiVersion: DATACONNECT_API_VERSION,
13
+ auth: true,
14
+ });
15
+ async function listLocations(projectId) {
16
+ const res = await dataconnectClient().get(`/projects/${projectId}/locations`);
17
+ return res.body?.locations?.map((l) => l.locationId) ?? [];
18
+ }
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;
33
+ }
34
+ exports.listAllServices = listAllServices;
35
+ async function listServices(projectId, locationId) {
36
+ const res = await dataconnectClient().get(`/projects/${projectId}/locations/${locationId}/services`);
37
+ return res.body.services ?? [];
38
+ }
39
+ exports.listServices = listServices;
40
+ async function createService(projectId, locationId, serviceId) {
41
+ const op = await dataconnectClient().post(`/projects/${projectId}/locations/${locationId}/services`, {
42
+ name: `projects/${projectId}/locations/${locationId}/services/${serviceId}`,
43
+ }, {
44
+ queryParams: {
45
+ service_id: serviceId,
46
+ },
47
+ });
48
+ const pollRes = await operationPoller.pollOperation({
49
+ apiOrigin: (0, api_1.dataconnectOrigin)(),
50
+ apiVersion: DATACONNECT_API_VERSION,
51
+ operationResourceName: op.body.name,
52
+ });
53
+ return pollRes;
54
+ }
55
+ exports.createService = createService;
56
+ async function deleteService(projectId, locationId, serviceId) {
57
+ const op = await dataconnectClient().delete(`projects/${projectId}/locations/${locationId}/services/${serviceId}?force=true`);
58
+ const pollRes = await operationPoller.pollOperation({
59
+ apiOrigin: (0, api_1.dataconnectOrigin)(),
60
+ apiVersion: DATACONNECT_API_VERSION,
61
+ operationResourceName: op.body.name,
62
+ });
63
+ return pollRes;
64
+ }
65
+ exports.deleteService = deleteService;
66
+ async function getSchema(serviceName) {
67
+ const res = await dataconnectClient().get(`${serviceName}/schemas/${types.SCHEMA_ID}`);
68
+ return res.body;
69
+ }
70
+ exports.getSchema = getSchema;
71
+ async function upsertSchema(schema, validateOnly = false) {
72
+ const op = await dataconnectClient().patch(`${schema.name}`, schema, {
73
+ queryParams: {
74
+ allowMissing: "true",
75
+ validateOnly: validateOnly ? "true" : "false",
76
+ },
77
+ });
78
+ if (validateOnly) {
79
+ return;
80
+ }
81
+ return operationPoller.pollOperation({
82
+ apiOrigin: (0, api_1.dataconnectOrigin)(),
83
+ apiVersion: DATACONNECT_API_VERSION,
84
+ operationResourceName: op.body.name,
85
+ });
86
+ }
87
+ exports.upsertSchema = upsertSchema;
88
+ async function getConnector(name) {
89
+ const res = await dataconnectClient().get(name);
90
+ return res.body;
91
+ }
92
+ exports.getConnector = getConnector;
93
+ async function deleteConnector(name) {
94
+ const res = await dataconnectClient().delete(name);
95
+ return res.body;
96
+ }
97
+ exports.deleteConnector = deleteConnector;
98
+ async function listConnectors(serviceName) {
99
+ const res = await dataconnectClient().get(`${serviceName}/connectors`);
100
+ return res.body?.connectors || [];
101
+ }
102
+ exports.listConnectors = listConnectors;
103
+ async function upsertConnector(connector) {
104
+ const op = await dataconnectClient().patch(`${connector.name}?allow_missing=true`, connector);
105
+ const pollRes = await operationPoller.pollOperation({
106
+ apiOrigin: (0, api_1.dataconnectOrigin)(),
107
+ apiVersion: DATACONNECT_API_VERSION,
108
+ operationResourceName: op.body.name,
109
+ });
110
+ return pollRes;
111
+ }
112
+ exports.upsertConnector = upsertConnector;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeGraphQL = void 0;
4
+ const api_1 = require("../api");
5
+ const apiv2_1 = require("../apiv2");
6
+ const DATACONNECT_API_VERSION = "v1alpha";
7
+ const dataconnectDataplaneClient = () => new apiv2_1.Client({
8
+ urlPrefix: (0, api_1.dataconnectOrigin)(),
9
+ apiVersion: DATACONNECT_API_VERSION,
10
+ auth: true,
11
+ });
12
+ async function executeGraphQL(servicePath, body) {
13
+ const res = await dataconnectDataplaneClient().post(`${servicePath}:executeGraphql`, body, { resolveOnHTTPError: true });
14
+ return res;
15
+ }
16
+ exports.executeGraphQL = executeGraphQL;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureApis = void 0;
4
+ const api = require("../api");
5
+ const ensureApiEnabled_1 = require("../ensureApiEnabled");
6
+ async function ensureApis(projectId) {
7
+ const prefix = "dataconnect";
8
+ await (0, ensureApiEnabled_1.ensure)(projectId, api.dataconnectOrigin(), prefix);
9
+ await (0, ensureApiEnabled_1.ensure)(projectId, api.cloudSQLAdminOrigin(), prefix);
10
+ await (0, ensureApiEnabled_1.ensure)(projectId, api.computeOrigin(), prefix);
11
+ }
12
+ exports.ensureApis = ensureApis;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInvalidConnectors = exports.getIncompatibleSchemaError = void 0;
4
+ const INCOMPATIBLE_SCHEMA_ERROR_TYPESTRING = "IncompatibleSqlSchemaError";
5
+ const PRECONDITION_ERROR_TYPESTRING = "type.googleapis.com/google.rpc.PreconditionFailure";
6
+ const INCOMPATIBLE_CONNECTOR_TYPE = "INCOMPATIBLE_CONNECTOR";
7
+ function getIncompatibleSchemaError(err) {
8
+ const original = err.context?.body?.error || err.orignal;
9
+ if (!original) {
10
+ throw err;
11
+ }
12
+ const details = original.details;
13
+ const incompatibles = details.filter((d) => d["@type"]?.includes(INCOMPATIBLE_SCHEMA_ERROR_TYPESTRING));
14
+ return incompatibles[0];
15
+ }
16
+ exports.getIncompatibleSchemaError = getIncompatibleSchemaError;
17
+ function getInvalidConnectors(err) {
18
+ 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
+ for (const preconditionErr of preconditionErrs) {
23
+ const incompatibleConnViolation = preconditionErr?.violations?.filter((v) => v.type === INCOMPATIBLE_CONNECTOR_TYPE);
24
+ const newConns = incompatibleConnViolation?.map((i) => i.subject) ?? [];
25
+ invalidConns.push(...newConns);
26
+ }
27
+ return invalidConns;
28
+ }
29
+ exports.getInvalidConnectors = getInvalidConnectors;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pickService = exports.readGQLFiles = exports.readConnectorYaml = exports.readDataConnectYaml = exports.readFirebaseJson = void 0;
4
+ const fs = require("fs-extra");
5
+ const path = require("path");
6
+ const error_1 = require("../error");
7
+ const utils_1 = require("../utils");
8
+ const load_1 = require("./load");
9
+ function readFirebaseJson(config) {
10
+ if (!config.has("dataconnect")) {
11
+ return [];
12
+ }
13
+ const validator = (cfg) => {
14
+ if (!cfg["source"] && !cfg["location"]) {
15
+ throw new error_1.FirebaseError("Invalid firebase.json: DataConnect requires `source` and `location`");
16
+ }
17
+ return {
18
+ source: cfg["source"],
19
+ location: cfg["location"],
20
+ };
21
+ };
22
+ const configs = config.get("dataconnect");
23
+ if (typeof configs === "object" && !Array.isArray(configs)) {
24
+ return [validator(configs)];
25
+ }
26
+ else if (Array.isArray(configs)) {
27
+ return configs.map(validator);
28
+ }
29
+ else {
30
+ throw new error_1.FirebaseError("Invalid firebase.json: dataconnect should be of the form { source: string, location: string }");
31
+ }
32
+ }
33
+ exports.readFirebaseJson = readFirebaseJson;
34
+ async function readDataConnectYaml(sourceDirectory) {
35
+ const file = await (0, utils_1.readFileFromDirectory)(sourceDirectory, "dataconnect.yaml");
36
+ const dataconnectYaml = await (0, utils_1.wrappedSafeLoad)(file.source);
37
+ return validateDataConnectYaml(dataconnectYaml);
38
+ }
39
+ exports.readDataConnectYaml = readDataConnectYaml;
40
+ function validateDataConnectYaml(unvalidated) {
41
+ return unvalidated;
42
+ }
43
+ async function readConnectorYaml(sourceDirectory) {
44
+ const file = await (0, utils_1.readFileFromDirectory)(sourceDirectory, "connector.yaml");
45
+ const connectorYaml = await (0, utils_1.wrappedSafeLoad)(file.source);
46
+ return validateConnectorYaml(connectorYaml);
47
+ }
48
+ exports.readConnectorYaml = readConnectorYaml;
49
+ function validateConnectorYaml(unvalidated) {
50
+ return unvalidated;
51
+ }
52
+ async function readGQLFiles(sourceDir) {
53
+ const files = await fs.readdir(sourceDir);
54
+ return files
55
+ .filter((f) => f.endsWith(".gql") || f.endsWith(".graphql"))
56
+ .map((f) => toFile(sourceDir, f));
57
+ }
58
+ exports.readGQLFiles = readGQLFiles;
59
+ function toFile(sourceDir, relPath) {
60
+ const fullPath = path.join(sourceDir, relPath);
61
+ if (!fs.existsSync(fullPath)) {
62
+ throw new error_1.FirebaseError(`file ${fullPath} not found`);
63
+ }
64
+ const content = fs.readFileSync(fullPath).toString();
65
+ return {
66
+ path: relPath,
67
+ content,
68
+ };
69
+ }
70
+ async function pickService(projectId, config, serviceId) {
71
+ const serviceCfgs = readFirebaseJson(config);
72
+ let serviceInfo;
73
+ if (serviceCfgs.length === 0) {
74
+ throw new error_1.FirebaseError("No Data Connect services found in firebase.json.");
75
+ }
76
+ else if (serviceCfgs.length === 1) {
77
+ serviceInfo = await (0, load_1.load)(projectId, serviceCfgs[0].location, serviceCfgs[0].source);
78
+ }
79
+ else {
80
+ if (!serviceId) {
81
+ throw new error_1.FirebaseError("Multiple Data Connect services found in firebase.json. Please specify a service ID to use.");
82
+ }
83
+ const infos = await Promise.all(serviceCfgs.map((c) => (0, load_1.load)(projectId, c.location, c.source)));
84
+ const maybe = infos.find((i) => i.dataConnectYaml.serviceId === serviceId);
85
+ if (!maybe) {
86
+ throw new error_1.FirebaseError(`No service named ${serviceId} declared in firebase.json.`);
87
+ }
88
+ serviceInfo = maybe;
89
+ }
90
+ return serviceInfo;
91
+ }
92
+ exports.pickService = pickService;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResourceFilters = void 0;
4
+ const error_1 = require("../error");
5
+ function getResourceFilters(options) {
6
+ if (!options.only) {
7
+ return undefined;
8
+ }
9
+ const selectors = options.only.split(",");
10
+ const filters = [];
11
+ for (let selector of selectors) {
12
+ if (selector.startsWith("dataconnect:")) {
13
+ selector = selector.replace("dataconnect:", "");
14
+ if (selector.length > 0) {
15
+ filters.push(parseSelector(selector));
16
+ }
17
+ }
18
+ }
19
+ if (filters.length === 0) {
20
+ return undefined;
21
+ }
22
+ return filters;
23
+ }
24
+ exports.getResourceFilters = getResourceFilters;
25
+ function parseSelector(selector) {
26
+ const parts = selector.split(":");
27
+ const filter = {
28
+ serviceId: parts[0],
29
+ };
30
+ if (parts.length === 2) {
31
+ if (parts[1] === "schema") {
32
+ filter.schemaOnly = true;
33
+ }
34
+ else {
35
+ filter.connectorId = parts[1];
36
+ }
37
+ }
38
+ else if (parts.length === 1) {
39
+ filter.fullService = true;
40
+ }
41
+ else {
42
+ throw new error_1.FirebaseError(`Invalid '--only' filter dataconnect:${selector}`);
43
+ }
44
+ return filter;
45
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printFreeTrialUnavailable = exports.checkForFreeTrialInstance = exports.freeTrialTermsLink = void 0;
4
+ const cloudsqladmin_1 = require("../gcp/cloudsql/cloudsqladmin");
5
+ const utils = require("../utils");
6
+ function freeTrialTermsLink() {
7
+ return "https://firebase.google.com/pricing";
8
+ }
9
+ exports.freeTrialTermsLink = freeTrialTermsLink;
10
+ async function checkForFreeTrialInstance(projectId) {
11
+ const instances = await (0, cloudsqladmin_1.listInstances)(projectId);
12
+ return instances.find((i) => i.settings.userLabels?.["firebase-data-connect"] === "ft")?.name;
13
+ }
14
+ exports.checkForFreeTrialInstance = checkForFreeTrialInstance;
15
+ function printFreeTrialUnavailable(projectId, instanceId) {
16
+ const message = `Project '${projectId}' already has a CloudSQL instance '${instanceId}' on the Firebase Data Connect free trial. ` +
17
+ "The free trial only includes one CloudSQL instance. " +
18
+ `Consider using a separate database on ${instanceId}, or creating a new CloudSQL instance at ` +
19
+ "https://console.cloud.google.com/sql/instances";
20
+ utils.logLabeledError("dataconnect", message);
21
+ }
22
+ exports.printFreeTrialUnavailable = printFreeTrialUnavailable;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prettify = void 0;
4
+ function prettify(err) {
5
+ const message = err.message;
6
+ let header = err.extensions.file ?? "";
7
+ if (err.locations) {
8
+ header += `:${err.locations[0].line}`;
9
+ }
10
+ return header.length ? `${header}: ${message}` : message;
11
+ }
12
+ exports.prettify = prettify;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.load = void 0;
4
+ const path = require("path");
5
+ const fileUtils = require("./fileUtils");
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);
11
+ const schemaGQLs = await fileUtils.readGQLFiles(schemaDir);
12
+ const connectorInfo = await Promise.all(dataConnectYaml.connectorDirs.map(async (dir) => {
13
+ const connectorDir = path.join(sourceDirectory, dir);
14
+ const connectorYaml = await fileUtils.readConnectorYaml(connectorDir);
15
+ const connectorGqls = await fileUtils.readGQLFiles(connectorDir);
16
+ return {
17
+ connectorYaml,
18
+ connector: {
19
+ name: `${serviceName}/connectors/${connectorYaml.connectorId}`,
20
+ source: {
21
+ files: connectorGqls,
22
+ },
23
+ },
24
+ };
25
+ }));
26
+ return {
27
+ serviceName,
28
+ sourceDirectory,
29
+ schema: {
30
+ name: `${serviceName}/schemas/${types_1.SCHEMA_ID}`,
31
+ primaryDatasource: (0, types_1.toDatasource)(projectId, locationId, dataConnectYaml.schema.datasource),
32
+ source: {
33
+ files: schemaGQLs,
34
+ },
35
+ },
36
+ dataConnectYaml,
37
+ connectorInfo,
38
+ };
39
+ }
40
+ exports.load = load;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseConnectorName = exports.parseServiceName = void 0;
4
+ const error_1 = require("../error");
5
+ const serviceNameRegex = /projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/services\/(?<serviceId>[^\/]+)/;
6
+ function parseServiceName(serviceName) {
7
+ const res = serviceNameRegex.exec(serviceName);
8
+ const projectId = res?.groups?.projectId;
9
+ const location = res?.groups?.location;
10
+ const serviceId = res?.groups?.serviceId;
11
+ if (!projectId || !location || !serviceId) {
12
+ throw new error_1.FirebaseError(`${serviceName} is not a valid service name`);
13
+ }
14
+ const toString = () => {
15
+ return `projects/${projectId}/locations/${location}/services/${serviceId}`;
16
+ };
17
+ return {
18
+ projectId,
19
+ location,
20
+ serviceId,
21
+ toString,
22
+ };
23
+ }
24
+ exports.parseServiceName = parseServiceName;
25
+ const connectorNameRegex = /projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/services\/(?<serviceId>[^\/]+)\/connectors\/(?<connectorId>[^\/]+)/;
26
+ function parseConnectorName(connectorName) {
27
+ const res = connectorNameRegex.exec(connectorName);
28
+ const projectId = res?.groups?.projectId;
29
+ const location = res?.groups?.location;
30
+ const serviceId = res?.groups?.serviceId;
31
+ const connectorId = res?.groups?.connectorId;
32
+ if (!projectId || !location || !serviceId || !connectorId) {
33
+ throw new error_1.FirebaseError(`${connectorName} is not a valid connector name`);
34
+ }
35
+ const toString = () => {
36
+ return `projects/${projectId}/locations/${location}/services/${serviceId}/connectors/${connectorId}`;
37
+ };
38
+ return {
39
+ projectId,
40
+ location,
41
+ serviceId,
42
+ connectorId,
43
+ toString,
44
+ };
45
+ }
46
+ exports.parseConnectorName = parseConnectorName;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promptDeleteConnector = void 0;
4
+ const prompt_1 = require("../prompt");
5
+ const utils = require("../utils");
6
+ const client_1 = require("./client");
7
+ async function promptDeleteConnector(options, connectorName) {
8
+ utils.logLabeledWarning("dataconnect", `Connector ${connectorName} exists but is not listed in dataconnect.yaml.`);
9
+ const confirmDeletion = await (0, prompt_1.confirm)({
10
+ default: false,
11
+ message: `Do you want to delete ${connectorName}?`,
12
+ force: options.force,
13
+ nonInteractive: options.nonInteractive,
14
+ });
15
+ if (confirmDeletion) {
16
+ await (0, client_1.deleteConnector)(connectorName);
17
+ utils.logLabeledSuccess("dataconnect", `Connector ${connectorName} deleted`);
18
+ }
19
+ }
20
+ exports.promptDeleteConnector = promptDeleteConnector;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkInstanceConfig = exports.provisionCloudSql = void 0;
4
+ const cloudSqlAdminClient = require("../gcp/cloudsql/cloudsqladmin");
5
+ const utils = require("../utils");
6
+ const checkIam_1 = require("./checkIam");
7
+ const utils_1 = require("../utils");
8
+ const GOOGLE_ML_INTEGRATION_ROLE = "roles/aiplatform.user";
9
+ const freeTrial_1 = require("./freeTrial");
10
+ const error_1 = require("../error");
11
+ async function provisionCloudSql(args) {
12
+ let connectionName;
13
+ const { projectId, locationId, instanceId, databaseId, enableGoogleMlIntegration, silent } = args;
14
+ try {
15
+ const existingInstance = await cloudSqlAdminClient.getInstance(projectId, instanceId);
16
+ silent || utils.logLabeledBullet("dataconnect", `Found existing instance ${instanceId}.`);
17
+ connectionName = existingInstance?.connectionName || "";
18
+ if (!checkInstanceConfig(existingInstance, enableGoogleMlIntegration)) {
19
+ silent ||
20
+ 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
+ await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.updateInstanceForDataConnect(existingInstance, enableGoogleMlIntegration), "Updating your instance...");
23
+ silent || utils.logLabeledBullet("dataconnect", "Instance updated");
24
+ }
25
+ }
26
+ catch (err) {
27
+ if (err.status !== 404) {
28
+ throw err;
29
+ }
30
+ const freeTrialInstanceId = await (0, freeTrial_1.checkForFreeTrialInstance)(projectId);
31
+ if (freeTrialInstanceId) {
32
+ (0, freeTrial_1.printFreeTrialUnavailable)(projectId, freeTrialInstanceId);
33
+ throw new error_1.FirebaseError("Free trial unavailable.");
34
+ }
35
+ 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 || "";
41
+ }
42
+ try {
43
+ await cloudSqlAdminClient.getDatabase(projectId, instanceId, databaseId);
44
+ silent || utils.logLabeledBullet("dataconnect", `Found existing database ${databaseId}.`);
45
+ }
46
+ 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.`);
51
+ }
52
+ if (enableGoogleMlIntegration) {
53
+ await (0, checkIam_1.grantRolesToCloudSqlServiceAccount)(projectId, instanceId, [GOOGLE_ML_INTEGRATION_ROLE]);
54
+ }
55
+ return connectionName;
56
+ }
57
+ exports.provisionCloudSql = provisionCloudSql;
58
+ function checkInstanceConfig(instance, requireGoogleMlIntegration) {
59
+ const settings = instance.settings;
60
+ if (!settings.ipConfiguration?.ipv4Enabled) {
61
+ return false;
62
+ }
63
+ if (requireGoogleMlIntegration) {
64
+ if (!settings.enableGoogleMlIntegration) {
65
+ return false;
66
+ }
67
+ if (!settings.databaseFlags?.some((f) => f.name === "cloudsql.enable_google_ml_integration" && f.value === "on")) {
68
+ return false;
69
+ }
70
+ }
71
+ const isIamEnabled = settings.databaseFlags?.some((f) => f.name === "cloudsql.iam_authentication" && f.value === "on") ?? false;
72
+ return isIamEnabled;
73
+ }
74
+ exports.checkInstanceConfig = checkInstanceConfig;