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