firebase-tools 15.29.0 → 15.30.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/commands/ext-export.js +18 -1
- package/lib/commands/ext-migrate.js +67 -4
- package/lib/commands/ext-uninstall.js +2 -28
- package/lib/commands/functions-kits-uninstall.js +23 -15
- package/lib/deploy/functions/delete.js +47 -22
- package/lib/deploy/functions/release/executor.js +14 -8
- package/lib/deploy/functions/release/fabricator.js +42 -20
- package/lib/deploy/functions/release/sourceTokenScraper.js +16 -2
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/tasksEmulator.js +2 -2
- package/lib/extensions/export.js +1 -1
- package/lib/extensions/extensionsHelper.js +1 -2
- package/lib/extensions/manifest.js +5 -4
- package/lib/extensions/migrate.js +55 -0
- package/lib/functions/kits/install.js +6 -4
- package/lib/gcp/resourceManager.js +31 -22
- package/lib/gcp/run.js +2 -2
- package/lib/mcp/onemcp/index.js +19 -0
- package/lib/mcp/onemcp/onemcp_server.js +12 -7
- package/lib/mcp/tools/dataconnect/execute.js +33 -19
- package/lib/mcp/tools/dataconnect/index.js +1 -1
- package/lib/throttler/throttler.js +2 -11
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +26 -0
- package/package.json +1 -1
- package/templates/init/functions/typescript/index-kit-migration.ts +1 -0
- package/templates/init/functions/typescript/index-kit.ts +1 -0
package/lib/extensions/export.js
CHANGED
|
@@ -104,7 +104,7 @@ function functionsEnvFromInstance(instance) {
|
|
|
104
104
|
if (renamed === "EXT_MIGRATED_SYSTEM_LOCATION") {
|
|
105
105
|
renamed = "FUNCTION_DEFAULT_REGION";
|
|
106
106
|
}
|
|
107
|
-
envs[renamed] = specSystemParam.default ?? "";
|
|
107
|
+
envs[renamed] = String(specSystemParam.default ?? "");
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
if (typeof instance.config.allowedEventTypes !== "undefined") {
|
|
@@ -162,8 +162,7 @@ async function substituteSecretParams(projectNumber, params) {
|
|
|
162
162
|
const newParams = {};
|
|
163
163
|
for await (const [key, value] of Object.entries(params)) {
|
|
164
164
|
if (typeof value !== "string") {
|
|
165
|
-
newParams[key] =
|
|
166
|
-
`projects/${projectNumber}/secrets/${value.name}/versions/latest`;
|
|
165
|
+
newParams[key] = `projects/${projectNumber}/secrets/${value.name}/versions/latest`;
|
|
167
166
|
}
|
|
168
167
|
else {
|
|
169
168
|
newParams[key] = value;
|
|
@@ -21,6 +21,7 @@ const prompt_1 = require("../prompt");
|
|
|
21
21
|
const paramHelper_1 = require("./paramHelper");
|
|
22
22
|
const error_1 = require("../error");
|
|
23
23
|
const extensionsHelper_1 = require("./extensionsHelper");
|
|
24
|
+
const utils_1 = require("../utils");
|
|
24
25
|
const types_1 = require("./types");
|
|
25
26
|
exports.ENV_DIRECTORY = "extensions";
|
|
26
27
|
async function writeToManifest(specs, config, options, allowOverwrite = false) {
|
|
@@ -99,16 +100,16 @@ function removeFromManifest(instanceId, config) {
|
|
|
99
100
|
extensions[instanceId] = undefined;
|
|
100
101
|
config.set("extensions", extensions);
|
|
101
102
|
config.writeProjectFile("firebase.json", config.src);
|
|
102
|
-
|
|
103
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Removed extension instance ${instanceId} from firebase.json`);
|
|
103
104
|
config.deleteProjectFile(`extensions/${instanceId}.env`);
|
|
104
|
-
|
|
105
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Removed extension instance environment config extensions/${instanceId}.env`);
|
|
105
106
|
if (config.projectFileExists(`extensions/${instanceId}.env.local`)) {
|
|
106
107
|
config.deleteProjectFile(`extensions/${instanceId}.env.local`);
|
|
107
|
-
|
|
108
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Removed extension instance local environment config extensions/${instanceId}.env.local`);
|
|
108
109
|
}
|
|
109
110
|
if (config.projectFileExists(`extensions/${instanceId}.secret.local`)) {
|
|
110
111
|
config.deleteProjectFile(`extensions/${instanceId}.secret.local`);
|
|
111
|
-
|
|
112
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Removed extension instance local secret config extensions/${instanceId}.secret.local`);
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
function loadConfig(options) {
|
|
@@ -8,6 +8,8 @@ exports.getMigratableInstances = getMigratableInstances;
|
|
|
8
8
|
exports.promptInstanceSelection = promptInstanceSelection;
|
|
9
9
|
exports.createMigrationPlan = createMigrationPlan;
|
|
10
10
|
exports.ensureInstanceUpToDate = ensureInstanceUpToDate;
|
|
11
|
+
exports.migrateSecrets = migrateSecrets;
|
|
12
|
+
exports.uninstallExtension = uninstallExtension;
|
|
11
13
|
const clc = require("colorette");
|
|
12
14
|
const Table = require("cli-table3");
|
|
13
15
|
const error_1 = require("../error");
|
|
@@ -20,6 +22,8 @@ const refs = require("./refs");
|
|
|
20
22
|
const paramHelper = require("./paramHelper");
|
|
21
23
|
const updateHelper = require("./updateHelper");
|
|
22
24
|
const replacements = require("./replacements.json");
|
|
25
|
+
const export_1 = require("./export");
|
|
26
|
+
const manifest = require("./manifest");
|
|
23
27
|
function getKitPackage(extensionRef, packageOverride) {
|
|
24
28
|
if (packageOverride) {
|
|
25
29
|
return packageOverride;
|
|
@@ -288,3 +292,54 @@ async function ensureInstanceUpToDate(projectId, instance, options) {
|
|
|
288
292
|
const updatedInstance = await extensionsApi.getInstance(projectId, instanceId);
|
|
289
293
|
return updatedInstance ?? instance;
|
|
290
294
|
}
|
|
295
|
+
async function migrateSecrets(instance, options) {
|
|
296
|
+
const secrets = await (0, export_1.secretsNeedingEjection)(instance);
|
|
297
|
+
if (secrets.length === 0) {
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
const instanceId = getInstanceId(instance);
|
|
301
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Transferring secrets for instance ${clc.bold(instanceId)} to Functions management...`);
|
|
302
|
+
const results = await (0, export_1.ejectSecretsFromInstance)(instance);
|
|
303
|
+
if (results.success.length > 0) {
|
|
304
|
+
(0, utils_1.logLabeledSuccess)(extensionsHelper_1.logPrefix, `Successfully transferred secrets to Functions management: ${results.success.join(", ")}`);
|
|
305
|
+
}
|
|
306
|
+
if (results.fail.length > 0) {
|
|
307
|
+
const resultMsg = `${results.fail.length} secrets failed to update: ${results.fail.join(", ")}.`;
|
|
308
|
+
(0, utils_1.logLabeledError)("functions", resultMsg);
|
|
309
|
+
(0, utils_1.logLabeledError)("functions", "Ensure you have Secret Manager Admin (roles/secretmanager.admin) permissions to transfer secrets.");
|
|
310
|
+
if (!options?.force) {
|
|
311
|
+
throw new error_1.FirebaseError("Secret migration failed.", { exit: 1 });
|
|
312
|
+
}
|
|
313
|
+
(0, utils_1.logLabeledWarning)("functions", "Proceeding after secret migration failure in --force mode. Manually remove the 'firebase-extensions-managed' label from the secrets before running ext:uninstall, or risk permanent data loss.");
|
|
314
|
+
}
|
|
315
|
+
return results.success;
|
|
316
|
+
}
|
|
317
|
+
async function uninstallExtension(projectId, instanceId, options, skipConfirm = false) {
|
|
318
|
+
if (!skipConfirm &&
|
|
319
|
+
!(await (0, prompt_1.confirm)({
|
|
320
|
+
message: `About to delete Extensions instance ${projectId}/${instanceId}, its associated resources, and service account. Continue?`,
|
|
321
|
+
nonInteractive: options.nonInteractive,
|
|
322
|
+
force: options.force,
|
|
323
|
+
default: true,
|
|
324
|
+
}))) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
let config;
|
|
328
|
+
try {
|
|
329
|
+
config = manifest.loadConfig(options);
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, "No firebase.json found. Proceeding to immediate extension instance teardown.");
|
|
333
|
+
}
|
|
334
|
+
if (config && manifest.instanceExists(instanceId, config)) {
|
|
335
|
+
manifest.removeFromManifest(instanceId, config);
|
|
336
|
+
}
|
|
337
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Uninstalling extension instance ${clc.bold(instanceId)}...`);
|
|
338
|
+
try {
|
|
339
|
+
await extensionsApi.deleteInstance(projectId, instanceId);
|
|
340
|
+
}
|
|
341
|
+
catch (err) {
|
|
342
|
+
throw new error_1.FirebaseError(`Error when attempting deletion: ${err instanceof Error ? err.message : String(err)}`, { original: err instanceof Error ? err : undefined });
|
|
343
|
+
}
|
|
344
|
+
(0, utils_1.logLabeledSuccess)(extensionsHelper_1.logPrefix, `Deleted Extensions instance ${projectId}/${instanceId}.`);
|
|
345
|
+
}
|
|
@@ -685,7 +685,9 @@ async function addKitInstanceOrConfigureProject(options, existingKit, existingFu
|
|
|
685
685
|
const unconfiguredInstances = getUnconfiguredInstancesForProject(options.config, existingKit, projectId, projectAlias);
|
|
686
686
|
const isConfiguredForProject = Object.keys(existingKit.instances || {}).length > 0 && unconfiguredInstances.length === 0;
|
|
687
687
|
let action;
|
|
688
|
-
if (options.instanceId &&
|
|
688
|
+
if (options.instanceId &&
|
|
689
|
+
existingKit.instances &&
|
|
690
|
+
Object.prototype.hasOwnProperty.call(existingKit.instances, options.instanceId)) {
|
|
689
691
|
if (!unconfiguredInstances.includes(options.instanceId)) {
|
|
690
692
|
throw new error_1.FirebaseError(`Instance '${options.instanceId}' is already configured for this project.`);
|
|
691
693
|
}
|
|
@@ -722,7 +724,7 @@ async function addKitInstanceOrConfigureProject(options, existingKit, existingFu
|
|
|
722
724
|
let absConfigDirPath;
|
|
723
725
|
if (action === "addInstance") {
|
|
724
726
|
resultAction = "addedInstance";
|
|
725
|
-
instanceId = await promptKitInstanceId(existingKit.kit, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
727
|
+
instanceId = await promptKitInstanceId(options.defaultInstanceId ?? existingKit.kit, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
726
728
|
const result = await addInstanceToKit({
|
|
727
729
|
config: options.config,
|
|
728
730
|
kitId: existingKit.kit,
|
|
@@ -739,7 +741,7 @@ async function addKitInstanceOrConfigureProject(options, existingKit, existingFu
|
|
|
739
741
|
existingKit,
|
|
740
742
|
unconfiguredInstanceIds: unconfiguredInstances,
|
|
741
743
|
});
|
|
742
|
-
configDirPath = existingKit.instances[instanceId];
|
|
744
|
+
configDirPath = existingKit.instances?.[instanceId];
|
|
743
745
|
if (!configDirPath) {
|
|
744
746
|
throw new error_1.FirebaseError(`Configuration directory for instance '${instanceId}' not found in kit '${existingKit.kit}'.`);
|
|
745
747
|
}
|
|
@@ -889,7 +891,7 @@ async function installKitOrInstance(options) {
|
|
|
889
891
|
? await resolveDirectorySource(options)
|
|
890
892
|
: await resolvePackageSource(options);
|
|
891
893
|
const kitId = await promptKitId(source.defaultKitName, existingFunctionsInfo.existingKitIds, options.nonInteractive, options.kitId);
|
|
892
|
-
const instanceId = await promptKitInstanceId(kitId, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
894
|
+
const instanceId = await promptKitInstanceId(options.defaultInstanceId ?? kitId, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
893
895
|
const { sourcePath, configDirPath, absSourcePath, absConfigDirPath } = await source.setup(kitId, instanceId);
|
|
894
896
|
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
895
897
|
(0, env_2.seedKitInstanceEnv)({
|
|
@@ -7,9 +7,10 @@ exports.addServiceAccountToRoles = addServiceAccountToRoles;
|
|
|
7
7
|
exports.serviceAccountHasRoles = serviceAccountHasRoles;
|
|
8
8
|
exports.removeServiceAccountRoles = removeServiceAccountRoles;
|
|
9
9
|
exports.getServiceAccountRoles = getServiceAccountRoles;
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
11
10
|
const api_1 = require("../api");
|
|
12
11
|
const apiv2_1 = require("../apiv2");
|
|
12
|
+
const error_1 = require("../error");
|
|
13
|
+
const utils = require("../utils");
|
|
13
14
|
const iam_1 = require("./iam");
|
|
14
15
|
const API_VERSION = "v1";
|
|
15
16
|
const apiClient = new apiv2_1.Client({ urlPrefix: (0, api_1.resourceManagerOrigin)(), apiVersion: API_VERSION });
|
|
@@ -32,30 +33,38 @@ async function setIamPolicy(projectIdOrNumber, newPolicy, updateMask = "") {
|
|
|
32
33
|
});
|
|
33
34
|
return response.body;
|
|
34
35
|
}
|
|
36
|
+
function isRetryableIamError(err) {
|
|
37
|
+
const status = (0, error_1.getErrStatus)(err);
|
|
38
|
+
if (status === 409) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
const msg = (0, error_1.getErrMsg)(err).toLowerCase();
|
|
42
|
+
const hasSa = msg.includes("service account") || msg.includes("serviceaccount");
|
|
43
|
+
if (status === 400 && hasSa && msg.includes("does not exist")) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
35
48
|
async function addServiceAccountToRoles(projectId, serviceAccountName, roles, skipAccountLookup = false) {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
: (0, iam_1.getServiceAccount)(projectId, serviceAccountName),
|
|
40
|
-
getIamPolicy(projectId),
|
|
41
|
-
]);
|
|
42
|
-
projectPolicy.bindings = projectPolicy.bindings || [];
|
|
49
|
+
const { name: fullServiceAccountName } = skipAccountLookup
|
|
50
|
+
? { name: serviceAccountName }
|
|
51
|
+
: await (0, iam_1.getServiceAccount)(projectId, serviceAccountName);
|
|
43
52
|
const newMemberName = `serviceAccount:${fullServiceAccountName.split("/").pop()}`;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
return await utils.retryWithBackoff(async () => {
|
|
54
|
+
const projectPolicy = await getIamPolicy(projectId);
|
|
55
|
+
projectPolicy.bindings = projectPolicy.bindings || [];
|
|
56
|
+
const requiredBindings = roles.map((role) => ({
|
|
57
|
+
role,
|
|
58
|
+
members: [newMemberName],
|
|
59
|
+
}));
|
|
60
|
+
(0, iam_1.mergeBindings)(projectPolicy, requiredBindings);
|
|
61
|
+
return await setIamPolicy(projectId, projectPolicy, "bindings");
|
|
62
|
+
}, {
|
|
63
|
+
retries: 6,
|
|
64
|
+
delay: 1000,
|
|
65
|
+
maxDelay: 5000,
|
|
66
|
+
retryPredicate: isRetryableIamError,
|
|
57
67
|
});
|
|
58
|
-
return setIamPolicy(projectId, projectPolicy, "bindings");
|
|
59
68
|
}
|
|
60
69
|
async function serviceAccountHasRoles(projectId, serviceAccountName, roles, skipAccountLookup = false) {
|
|
61
70
|
const [{ name: fullServiceAccountName }, projectPolicy] = await Promise.all([
|
package/lib/gcp/run.js
CHANGED
|
@@ -15,7 +15,7 @@ const apiv2_1 = require("../apiv2");
|
|
|
15
15
|
const error_1 = require("../error");
|
|
16
16
|
const api_1 = require("../api");
|
|
17
17
|
const proto = require("./proto");
|
|
18
|
-
const
|
|
18
|
+
const utils_1 = require("../utils");
|
|
19
19
|
const logger_1 = require("../logger");
|
|
20
20
|
const cloudlogging_1 = require("./cloudlogging");
|
|
21
21
|
const API_VERSION = "v1";
|
|
@@ -49,7 +49,7 @@ async function updateService(name, service) {
|
|
|
49
49
|
service = await exports.replaceService(name, service);
|
|
50
50
|
let retry = 0;
|
|
51
51
|
while (!exports.serviceIsResolved(service)) {
|
|
52
|
-
await (0,
|
|
52
|
+
await (0, utils_1.backoff)(retry, 2, 30);
|
|
53
53
|
retry = retry + 1;
|
|
54
54
|
service = await exports.getService(name);
|
|
55
55
|
}
|
package/lib/mcp/onemcp/index.js
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ONEMCP_SERVERS = void 0;
|
|
4
|
+
exports.dataConnectLocationHeaderInjector = dataConnectLocationHeaderInjector;
|
|
4
5
|
const api_1 = require("../../api");
|
|
5
6
|
const onemcp_server_1 = require("./onemcp_server");
|
|
7
|
+
function dataConnectLocationHeaderInjector(headers, _toolName, args) {
|
|
8
|
+
if (typeof args?.location === "string" && args.location && !headers["Mcp-Param-Region"]) {
|
|
9
|
+
return { "Mcp-Param-Region": args.location };
|
|
10
|
+
}
|
|
11
|
+
}
|
|
6
12
|
exports.ONEMCP_SERVERS = {
|
|
13
|
+
dataconnect: new onemcp_server_1.OneMcpServer("dataconnect", (0, api_1.dataconnectOrigin)(), {
|
|
14
|
+
requiresAuth: true,
|
|
15
|
+
}, {
|
|
16
|
+
allowedTools: [
|
|
17
|
+
"execute_graphql",
|
|
18
|
+
"execute_graphql_read",
|
|
19
|
+
"generate_schema",
|
|
20
|
+
"generate_query",
|
|
21
|
+
"generate_query_from_schema",
|
|
22
|
+
"list_locations",
|
|
23
|
+
],
|
|
24
|
+
headerOverride: dataConnectLocationHeaderInjector,
|
|
25
|
+
}),
|
|
7
26
|
developerknowledge: new onemcp_server_1.OneMcpServer("developerknowledge", (0, api_1.developerKnowledgeOrigin)(), {
|
|
8
27
|
requiresAuth: true,
|
|
9
28
|
}, {
|
|
@@ -88,6 +88,17 @@ class OneMcpServer {
|
|
|
88
88
|
await (0, ensureApiEnabled_1.ensure)(ctx.projectId, this.serverUrl, this.feature, true);
|
|
89
89
|
}
|
|
90
90
|
try {
|
|
91
|
+
const baseHeaders = {
|
|
92
|
+
"MCP-Protocol-Version": types_js_1.LATEST_PROTOCOL_VERSION,
|
|
93
|
+
"Mcp-Method": "tools/call",
|
|
94
|
+
"Mcp-Name": toolName,
|
|
95
|
+
...(ctx.projectId ? { "x-goog-user-project": ctx.projectId } : {}),
|
|
96
|
+
...paramHeaders,
|
|
97
|
+
};
|
|
98
|
+
const headers = {
|
|
99
|
+
...baseHeaders,
|
|
100
|
+
...(this.options.headerOverride?.(baseHeaders, toolName, args) ?? {}),
|
|
101
|
+
};
|
|
91
102
|
const res = await this.callClient.post("/mcp", {
|
|
92
103
|
method: "tools/call",
|
|
93
104
|
params: {
|
|
@@ -97,13 +108,7 @@ class OneMcpServer {
|
|
|
97
108
|
jsonrpc: "2.0",
|
|
98
109
|
id: 1,
|
|
99
110
|
}, {
|
|
100
|
-
headers
|
|
101
|
-
"MCP-Protocol-Version": types_js_1.LATEST_PROTOCOL_VERSION,
|
|
102
|
-
"Mcp-Method": "tools/call",
|
|
103
|
-
"Mcp-Name": toolName,
|
|
104
|
-
...(ctx.projectId ? { "x-goog-user-project": ctx.projectId } : {}),
|
|
105
|
-
...paramHeaders,
|
|
106
|
-
},
|
|
111
|
+
headers,
|
|
107
112
|
});
|
|
108
113
|
return types_js_1.CallToolResultSchema.parse(res.body.result);
|
|
109
114
|
}
|
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.execute_in_emulator = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const tool_1 = require("../../tool");
|
|
6
6
|
const dataplane = require("../../../dataconnect/dataplaneClient");
|
|
7
7
|
const load_1 = require("../../../dataconnect/load");
|
|
8
8
|
const converter_1 = require("../../util/dataconnect/converter");
|
|
9
9
|
const emulator_1 = require("../../util/dataconnect/emulator");
|
|
10
|
-
exports.
|
|
11
|
-
name: "
|
|
12
|
-
description:
|
|
10
|
+
exports.execute_in_emulator = (0, tool_1.tool)("dataconnect", {
|
|
11
|
+
name: "execute_in_emulator",
|
|
12
|
+
description: `Executes a GraphQL operation against a local Firebase SQL Connect Service instance emulator.
|
|
13
|
+
|
|
14
|
+
Grants access to run queries and mutations on the local emulator.
|
|
15
|
+
|
|
16
|
+
**Prerequisites:**
|
|
17
|
+
* The Firebase local emulators must be running (run \`firebase emulators:start\` in your project directory).
|
|
18
|
+
* A \`firebase.json\` file configured with a \`dataconnect\` service.
|
|
19
|
+
* A \`dataconnect.yaml\` configuration file inside the service's source directory.
|
|
20
|
+
* A defined SQL Connect schema (configured via the schema/schemas fields in \`dataconnect.yaml\`).
|
|
21
|
+
* Note: These files are ideally generated using the \`firebase_init\` MCP tool, or must follow the standard structure described in the \`firebase-data-connect-basics\` skill.
|
|
22
|
+
|
|
23
|
+
**When to use it:**
|
|
24
|
+
* Use this tool to execute local GraphQL queries or mutations for development and testing.
|
|
25
|
+
|
|
26
|
+
**How to use it:**
|
|
27
|
+
* Call \`execute_in_emulator\` with the GraphQL \`query\` string.
|
|
28
|
+
* Optionally provide \`service_id\`, \`location_id\`, \`variables_json\`, and \`auth_token_json\`.
|
|
29
|
+
|
|
30
|
+
**JSON Example:**
|
|
31
|
+
\`\`\`json
|
|
32
|
+
{
|
|
33
|
+
"query": "query GetUser($id: UUID!) { user(id: $id) { name } }",
|
|
34
|
+
"variables_json": "{\\"id\\": \\"123e4567-e89b-12d3-a456-426614174000\\"}"
|
|
35
|
+
}
|
|
36
|
+
\`\`\`
|
|
37
|
+
`,
|
|
13
38
|
humanReadableDescription: "Execute a GraphQL query or mutation against a Firebase SQL Connect service or emulator.",
|
|
14
39
|
inputSchema: zod_1.z.object({
|
|
15
40
|
query: zod_1.z.string().describe(`A Firebase SQL Connect GraphQL query or mutation to execute.
|
|
16
|
-
You can use the \`dataconnect_generate_operation\` tool to generate a query.
|
|
17
41
|
Example SQL Connect schema and example queries can be found in files ending in \`.graphql\` or \`.gql\`.
|
|
18
42
|
`),
|
|
19
43
|
service_id: zod_1.z
|
|
@@ -34,27 +58,17 @@ Example SQL Connect schema and example queries can be found in files ending in \
|
|
|
34
58
|
.describe("Firebase Auth Token JWT to use in this query. MUST be a valid stringified JSON object." +
|
|
35
59
|
'Importantly, when executing queries with `@auth(level: USER)` or `auth.uid`, a valid Firebase Auth Token JWT with "sub" field is required. ' +
|
|
36
60
|
'"auth.uid" expression in the query evaluates to the value of "sub" field in Firebase Auth token.'),
|
|
37
|
-
use_emulator: zod_1.z
|
|
38
|
-
.boolean()
|
|
39
|
-
.default(false)
|
|
40
|
-
.describe("If true, target the DataConnect emulator. Run `firebase emulators:start` to start it"),
|
|
41
61
|
}),
|
|
42
62
|
annotations: {
|
|
43
|
-
title: "Execute Firebase SQL Connect Query",
|
|
63
|
+
title: "Execute Firebase SQL Connect Query in Emulator",
|
|
44
64
|
},
|
|
45
65
|
_meta: {
|
|
46
66
|
requiresProject: true,
|
|
47
|
-
requiresAuth:
|
|
67
|
+
requiresAuth: false,
|
|
48
68
|
},
|
|
49
|
-
}, async ({ query, service_id, location_id, variables_json: unparsedVariables,
|
|
69
|
+
}, async ({ query, service_id, location_id, variables_json: unparsedVariables, auth_token_json: unparsedAuthToken, }, { projectId, config, host }) => {
|
|
50
70
|
const serviceInfo = await (0, load_1.pickOneService)(projectId, config, service_id || undefined, location_id || undefined);
|
|
51
|
-
|
|
52
|
-
if (use_emulator) {
|
|
53
|
-
apiClient = await (0, emulator_1.getDataConnectEmulatorClient)(host);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
apiClient = dataplane.dataconnectDataplaneClient();
|
|
57
|
-
}
|
|
71
|
+
const apiClient = await (0, emulator_1.getDataConnectEmulatorClient)(host);
|
|
58
72
|
let executeGraphQL = dataplane.executeGraphQL;
|
|
59
73
|
if (query.startsWith("query")) {
|
|
60
74
|
executeGraphQL = dataplane.executeGraphQLRead;
|
|
@@ -4,4 +4,4 @@ exports.dataconnectTools = void 0;
|
|
|
4
4
|
const list_services_1 = require("./list_services");
|
|
5
5
|
const compile_1 = require("./compile");
|
|
6
6
|
const execute_1 = require("./execute");
|
|
7
|
-
exports.dataconnectTools = [compile_1.compile, list_services_1.list_services, execute_1.
|
|
7
|
+
exports.dataconnectTools = [compile_1.compile, list_services_1.list_services, execute_1.execute_in_emulator];
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Throttler = void 0;
|
|
4
|
-
exports.backoff = backoff;
|
|
5
|
-
exports.timeToWait = timeToWait;
|
|
6
4
|
const logger_1 = require("../logger");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
7
6
|
const retries_exhausted_error_1 = require("./errors/retries-exhausted-error");
|
|
8
7
|
const timeout_error_1 = require("./errors/timeout-error");
|
|
9
|
-
function backoff(retryNumber, delay, maxDelay) {
|
|
10
|
-
return new Promise((resolve) => {
|
|
11
|
-
setTimeout(resolve, timeToWait(retryNumber, delay, maxDelay));
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
function timeToWait(retryNumber, delay, maxDelay) {
|
|
15
|
-
return Math.min(delay * Math.pow(2, retryNumber), maxDelay);
|
|
16
|
-
}
|
|
17
8
|
function DEFAULT_HANDLER(task) {
|
|
18
9
|
return task();
|
|
19
10
|
}
|
|
@@ -184,7 +175,7 @@ class Throttler {
|
|
|
184
175
|
if (taskData.retryCount === this.retries) {
|
|
185
176
|
throw new retries_exhausted_error_1.default(this.taskName(cursorIndex), this.retries, err);
|
|
186
177
|
}
|
|
187
|
-
await backoff(taskData.retryCount + 1, this.backoff, this.maxBackoff);
|
|
178
|
+
await (0, utils_1.backoff)(taskData.retryCount + 1, this.backoff, this.maxBackoff);
|
|
188
179
|
if (taskData.isTimedOut) {
|
|
189
180
|
throw new timeout_error_1.default(this.taskName(cursorIndex), taskData.timeoutMillis);
|
|
190
181
|
}
|