firebase-tools 15.34.1 → 15.34.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "15.34.1",
3
+ "version": "15.34.2",
4
4
  "description": "Command-Line Interface for Firebase",
5
5
  "main": "./lib/index.js",
6
6
  "mcpName": "io.github.firebase/firebase-mcp",
@@ -74,8 +74,8 @@
74
74
  "ajv-formats": "3.0.1",
75
75
  "archiver": "^7.0.0",
76
76
  "async-lock": "1.4.1",
77
- "body-parser": "^1.19.0",
78
- "chokidar": "^3.6.0",
77
+ "body-parser": "^1.20.9",
78
+ "chokidar": "^4.0.3",
79
79
  "cjson": "^0.3.1",
80
80
  "cli-table3": "0.6.5",
81
81
  "colorette": "^2.0.19",
@@ -132,9 +132,14 @@
132
132
  "zod": "^4.0.0"
133
133
  },
134
134
  "overrides": {
135
+ "body-parser": "^1.20.9",
136
+ "@modelcontextprotocol/sdk": {
137
+ "body-parser": "^2.4.0"
138
+ },
135
139
  "@angular-devkit/core": {
136
140
  "ajv-formats": "3.0.1",
137
- "ajv": "^8.17.1"
141
+ "ajv": "^8.17.1",
142
+ "chokidar": "$chokidar"
138
143
  },
139
144
  "hono": "^4.13.5",
140
145
  "@tootallnate/once": "^3.0.1",
@@ -149,7 +154,6 @@
149
154
  "qs": "^6.16.0",
150
155
  "tar": "^7.5.21",
151
156
  "@opentelemetry/core": "^2.8.0",
152
- "basic-ftp": "^6.2.1",
153
157
  "re2": "1.24.0",
154
158
  "@babel/traverse": "^7.23.2",
155
159
  "gaxios": {
@@ -1,243 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseConnectionName = parseConnectionName;
4
- exports.linkGitHubRepository = linkGitHubRepository;
5
- exports.getOrCreateOauthConnection = getOrCreateOauthConnection;
6
- exports.createConnection = createConnection;
7
- exports.getOrCreateConnection = getOrCreateConnection;
8
- exports.getOrCreateRepository = getOrCreateRepository;
9
- exports.listAppHostingConnections = listAppHostingConnections;
10
- exports.fetchAllRepositories = fetchAllRepositories;
11
- const clc = require("colorette");
12
- const gcb = require("../gcp/cloudbuild");
13
- const rm = require("../gcp/resourceManager");
14
- const poller = require("../operation-poller");
15
- const utils = require("../utils");
16
- const api_1 = require("../api");
17
- const error_1 = require("../error");
18
- const prompt_1 = require("../prompt");
19
- const getProjectNumber_1 = require("../getProjectNumber");
20
- const fuzzy = require("fuzzy");
21
- const APPHOSTING_CONN_PATTERN = /.+\/apphosting-github-conn-.+$/;
22
- const APPHOSTING_OAUTH_CONN_NAME = "apphosting-github-oauth";
23
- const CONNECTION_NAME_REGEX = /^projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/connections\/(?<id>[^\/]+)$/;
24
- function parseConnectionName(name) {
25
- const match = CONNECTION_NAME_REGEX.exec(name);
26
- if (!match || typeof match.groups === "undefined") {
27
- return;
28
- }
29
- const { projectId, location, id } = match.groups;
30
- return {
31
- projectId,
32
- location,
33
- id,
34
- };
35
- }
36
- const gcbPollerOptions = {
37
- apiOrigin: (0, api_1.cloudbuildOrigin)(),
38
- apiVersion: "v2",
39
- masterTimeout: 60 * 60 * 1000,
40
- maxBackoff: 10000,
41
- };
42
- function extractRepoSlugFromUri(remoteUri) {
43
- const match = /github.com\/(.+).git/.exec(remoteUri);
44
- if (!match) {
45
- return undefined;
46
- }
47
- return match[1];
48
- }
49
- function generateRepositoryId(remoteUri) {
50
- return extractRepoSlugFromUri(remoteUri)?.replaceAll("/", "-");
51
- }
52
- function generateConnectionId() {
53
- const randomHash = Math.random().toString(36).slice(6);
54
- return `apphosting-github-conn-${randomHash}`;
55
- }
56
- const ADD_CONN_CHOICE = "@ADD_CONN";
57
- async function linkGitHubRepository(projectId, location) {
58
- utils.logBullet(clc.bold(`${clc.yellow("===")} Import a GitHub repository`));
59
- const oauthConn = await getOrCreateOauthConnection(projectId, location);
60
- const existingConns = await listAppHostingConnections(projectId);
61
- if (existingConns.length === 0) {
62
- existingConns.push(await createFullyInstalledConnection(projectId, location, generateConnectionId(), oauthConn));
63
- }
64
- let repoRemoteUri;
65
- let connection;
66
- do {
67
- if (repoRemoteUri === ADD_CONN_CHOICE) {
68
- existingConns.push(await createFullyInstalledConnection(projectId, location, generateConnectionId(), oauthConn));
69
- }
70
- const selection = await promptRepositoryUri(projectId, existingConns);
71
- repoRemoteUri = selection.remoteUri;
72
- connection = selection.connection;
73
- } while (repoRemoteUri === ADD_CONN_CHOICE);
74
- const { id: connectionId } = parseConnectionName(connection.name);
75
- await getOrCreateConnection(projectId, location, connectionId, {
76
- authorizerCredential: connection.githubConfig?.authorizerCredential,
77
- appInstallationId: connection.githubConfig?.appInstallationId,
78
- });
79
- const repo = await getOrCreateRepository(projectId, location, connectionId, repoRemoteUri);
80
- utils.logSuccess(`Successfully linked GitHub repository at remote URI`);
81
- utils.logSuccess(`\t${repoRemoteUri}`);
82
- return repo;
83
- }
84
- async function createFullyInstalledConnection(projectId, location, connectionId, oauthConn) {
85
- let conn = await createConnection(projectId, location, connectionId, {
86
- authorizerCredential: oauthConn.githubConfig?.authorizerCredential,
87
- });
88
- while (conn.installationState.stage !== "COMPLETE") {
89
- utils.logBullet("Install the Cloud Build GitHub app to enable access to GitHub repositories");
90
- const targetUri = conn.installationState.actionUri;
91
- utils.logBullet(targetUri);
92
- await utils.openInBrowser(targetUri);
93
- await (0, prompt_1.input)("Press Enter once you have installed or configured the Cloud Build GitHub app to access your GitHub repo.");
94
- conn = await gcb.getConnection(projectId, location, connectionId);
95
- }
96
- return conn;
97
- }
98
- async function getOrCreateOauthConnection(projectId, location) {
99
- let conn;
100
- try {
101
- conn = await gcb.getConnection(projectId, location, APPHOSTING_OAUTH_CONN_NAME);
102
- }
103
- catch (err) {
104
- if (err.status === 404) {
105
- await ensureSecretManagerAdminGrant(projectId);
106
- conn = await createConnection(projectId, location, APPHOSTING_OAUTH_CONN_NAME);
107
- }
108
- else {
109
- throw err;
110
- }
111
- }
112
- while (conn.installationState.stage === "PENDING_USER_OAUTH") {
113
- utils.logBullet("You must authorize the Cloud Build GitHub app.");
114
- utils.logBullet("Sign in to GitHub and authorize Cloud Build GitHub app:");
115
- const { url, cleanup } = await utils.openInBrowserPopup(conn.installationState.actionUri, "Authorize the GitHub app");
116
- utils.logBullet(`\t${url}`);
117
- await (0, prompt_1.input)("Press Enter once you have authorized the app");
118
- cleanup();
119
- const { projectId, location, id } = parseConnectionName(conn.name);
120
- conn = await gcb.getConnection(projectId, location, id);
121
- }
122
- return conn;
123
- }
124
- async function promptRepositoryUri(projectId, connections) {
125
- const { repos, remoteUriToConnection } = await fetchAllRepositories(projectId, connections);
126
- const remoteUri = await (0, prompt_1.search)({
127
- message: "Which GitHub repo do you want to deploy?",
128
- source: (input) => [
129
- new prompt_1.Separator(),
130
- {
131
- name: "Missing a repo? Select this option to configure your GitHub connection settings",
132
- value: ADD_CONN_CHOICE,
133
- },
134
- new prompt_1.Separator(),
135
- ...fuzzy
136
- .filter(input ?? "", repos, {
137
- extract: (repo) => extractRepoSlugFromUri(repo.remoteUri) || "",
138
- })
139
- .map((result) => {
140
- return {
141
- name: extractRepoSlugFromUri(result.original.remoteUri) || "",
142
- value: result.original.remoteUri,
143
- };
144
- }),
145
- ],
146
- });
147
- return { remoteUri, connection: remoteUriToConnection[remoteUri] };
148
- }
149
- async function ensureSecretManagerAdminGrant(projectId) {
150
- const projectNumber = await (0, getProjectNumber_1.getProjectNumber)({ projectId });
151
- const cbsaEmail = gcb.getDefaultServiceAgent(projectNumber);
152
- const alreadyGranted = await rm.serviceAccountHasRoles(projectId, cbsaEmail, ["roles/secretmanager.admin"], true);
153
- if (alreadyGranted) {
154
- return;
155
- }
156
- utils.logBullet("To create a new GitHub connection, Secret Manager Admin role (roles/secretmanager.admin) is required on the Cloud Build Service Agent.");
157
- const grant = await (0, prompt_1.confirm)("Grant the required role to the Cloud Build Service Agent?");
158
- if (!grant) {
159
- utils.logBullet("You, or your project administrator, should run the following command to grant the required role:\n\n" +
160
- "You, or your project adminstrator, can run the following command to grant the required role manually:\n\n" +
161
- `\tgcloud projects add-iam-policy-binding ${projectId} \\\n` +
162
- `\t --member="serviceAccount:${cbsaEmail} \\\n` +
163
- `\t --role="roles/secretmanager.admin\n`);
164
- throw new error_1.FirebaseError("Insufficient IAM permissions to create a new connection to GitHub");
165
- }
166
- await rm.addServiceAccountToRoles(projectId, cbsaEmail, ["roles/secretmanager.admin"], true);
167
- utils.logSuccess("Successfully granted the required role to the Cloud Build Service Agent!");
168
- }
169
- async function createConnection(projectId, location, connectionId, githubConfig) {
170
- const op = await gcb.createConnection(projectId, location, connectionId, githubConfig);
171
- const conn = await poller.pollOperation({
172
- ...gcbPollerOptions,
173
- pollerName: `create-${location}-${connectionId}`,
174
- operationResourceName: op.name,
175
- });
176
- return conn;
177
- }
178
- async function getOrCreateConnection(projectId, location, connectionId, githubConfig) {
179
- let conn;
180
- try {
181
- conn = await gcb.getConnection(projectId, location, connectionId);
182
- }
183
- catch (err) {
184
- if (err.status === 404) {
185
- conn = await createConnection(projectId, location, connectionId, githubConfig);
186
- }
187
- else {
188
- throw err;
189
- }
190
- }
191
- return conn;
192
- }
193
- async function getOrCreateRepository(projectId, location, connectionId, remoteUri) {
194
- const repositoryId = generateRepositoryId(remoteUri);
195
- if (!repositoryId) {
196
- throw new error_1.FirebaseError(`Failed to generate repositoryId for URI "${remoteUri}".`);
197
- }
198
- let repo;
199
- try {
200
- repo = await gcb.getRepository(projectId, location, connectionId, repositoryId);
201
- }
202
- catch (err) {
203
- if (err.status === 404) {
204
- const op = await gcb.createRepository(projectId, location, connectionId, repositoryId, remoteUri);
205
- repo = await poller.pollOperation({
206
- ...gcbPollerOptions,
207
- pollerName: `create-${location}-${connectionId}-${repositoryId}`,
208
- operationResourceName: op.name,
209
- });
210
- }
211
- else {
212
- throw err;
213
- }
214
- }
215
- return repo;
216
- }
217
- async function listAppHostingConnections(projectId) {
218
- const conns = await gcb.listConnections(projectId, "-");
219
- return conns.filter((conn) => APPHOSTING_CONN_PATTERN.test(conn.name) &&
220
- conn.installationState.stage === "COMPLETE" &&
221
- !conn.disabled);
222
- }
223
- async function fetchAllRepositories(projectId, connections) {
224
- const repos = [];
225
- const remoteUriToConnection = {};
226
- const getNextPage = async (conn, pageToken = "") => {
227
- const { location, id } = parseConnectionName(conn.name);
228
- const resp = await gcb.fetchLinkableRepositories(projectId, location, id, pageToken);
229
- if (resp.repositories && resp.repositories.length > 0) {
230
- for (const repo of resp.repositories) {
231
- repos.push(repo);
232
- remoteUriToConnection[repo.remoteUri] = conn;
233
- }
234
- }
235
- if (resp.nextPageToken) {
236
- await getNextPage(conn, resp.nextPageToken);
237
- }
238
- };
239
- for (const conn of connections) {
240
- await getNextPage(conn);
241
- }
242
- return { repos, remoteUriToConnection };
243
- }