firebase-tools 13.13.0 → 13.13.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchAllRepositories = exports.listAppHostingConnections = exports.getOrCreateRepository = exports.getOrCreateConnection = exports.createConnection = exports.ensureSecretManagerAdminGrant = exports.getOrCreateOauthConnection = exports.linkGitHubRepository = exports.generateRepositoryId = exports.extractRepoSlugFromUri = exports.parseConnectionName = void 0;
3
+ exports.fetchAllRepositories = exports.listAppHostingConnections = exports.getOrCreateRepository = exports.getOrCreateConnection = exports.createConnection = exports.ensureSecretManagerAdminGrant = exports.promptGitHubBranch = exports.getOrCreateOauthConnection = exports.linkGitHubRepository = exports.generateRepositoryId = exports.extractRepoSlugFromUri = exports.parseConnectionName = void 0;
4
4
  const clc = require("colorette");
5
5
  const devConnect = require("../gcp/devConnect");
6
6
  const rm = require("../gcp/resourceManager");
@@ -56,7 +56,7 @@ async function linkGitHubRepository(projectId, location) {
56
56
  var _a, _b;
57
57
  utils.logBullet(clc.bold(`${clc.yellow("===")} Import a GitHub repository`));
58
58
  const oauthConn = await getOrCreateOauthConnection(projectId, location);
59
- const existingConns = await listAppHostingConnections(projectId);
59
+ const existingConns = await listAppHostingConnections(projectId, location);
60
60
  if (existingConns.length === 0) {
61
61
  existingConns.push(await createFullyInstalledConnection(projectId, location, generateConnectionId(), oauthConn));
62
62
  }
@@ -157,6 +157,22 @@ async function promptCloneUri(projectId, connections) {
157
157
  });
158
158
  return { cloneUri, connection: cloneUriToConnection[cloneUri] };
159
159
  }
160
+ async function promptGitHubBranch(repoLink) {
161
+ const branches = await devConnect.listAllBranches(repoLink.name);
162
+ while (true) {
163
+ const branch = await (0, prompt_1.promptOnce)({
164
+ name: "branch",
165
+ type: "input",
166
+ default: "main",
167
+ message: "Pick a branch for continuous deployment",
168
+ });
169
+ if (branches.has(branch)) {
170
+ return branch;
171
+ }
172
+ utils.logWarning(`The branch "${branch}" does not exist on "${extractRepoSlugFromUri(repoLink.cloneUri)}". Please enter a valid branch for this repo.`);
173
+ }
174
+ }
175
+ exports.promptGitHubBranch = promptGitHubBranch;
160
176
  async function ensureSecretManagerAdminGrant(projectId) {
161
177
  const projectNumber = await (0, getProjectNumber_1.getProjectNumber)({ projectId });
162
178
  const dcsaEmail = devConnect.serviceAgentEmail(projectNumber);
@@ -237,8 +253,8 @@ async function getOrCreateRepository(projectId, location, connectionId, cloneUri
237
253
  return repo;
238
254
  }
239
255
  exports.getOrCreateRepository = getOrCreateRepository;
240
- async function listAppHostingConnections(projectId) {
241
- const conns = await devConnect.listAllConnections(projectId, "-");
256
+ async function listAppHostingConnections(projectId, location) {
257
+ const conns = await devConnect.listAllConnections(projectId, location);
242
258
  return conns.filter((conn) => APPHOSTING_CONN_PATTERN.test(conn.name) &&
243
259
  conn.installationState.stage === "COMPLETE" &&
244
260
  !conn.disabled);
@@ -66,19 +66,14 @@ async function doSetup(projectId, webAppName, location, serviceAccount) {
66
66
  }
67
67
  location =
68
68
  location || (await promptLocation(projectId, "Select a location to host your backend:\n"));
69
- const gitRepositoryConnection = await githubConnections.linkGitHubRepository(projectId, location);
69
+ const gitRepositoryLink = await githubConnections.linkGitHubRepository(projectId, location);
70
70
  const rootDir = await (0, prompt_1.promptOnce)({
71
71
  name: "rootDir",
72
72
  type: "input",
73
73
  default: "/",
74
74
  message: "Specify your app's root directory relative to your repository",
75
75
  });
76
- const branch = await (0, prompt_1.promptOnce)({
77
- name: "branch",
78
- type: "input",
79
- default: "main",
80
- message: "Pick a branch for continuous deployment",
81
- });
76
+ const branch = await githubConnections.promptGitHubBranch(gitRepositoryLink);
82
77
  (0, utils_1.logSuccess)(`Repo linked successfully!\n`);
83
78
  (0, utils_1.logBullet)(`${clc.yellow("===")} Set up your backend`);
84
79
  const backendId = await promptNewBackendId(projectId, location, {
@@ -93,7 +88,7 @@ async function doSetup(projectId, webAppName, location, serviceAccount) {
93
88
  (0, utils_1.logWarning)(`Firebase web app not set`);
94
89
  }
95
90
  const createBackendSpinner = ora("Creating your new backend...").start();
96
- const backend = await createBackend(projectId, location, backendId, gitRepositoryConnection, serviceAccount, webApp === null || webApp === void 0 ? void 0 : webApp.id, rootDir);
91
+ const backend = await createBackend(projectId, location, backendId, gitRepositoryLink, serviceAccount, webApp === null || webApp === void 0 ? void 0 : webApp.id, rootDir);
97
92
  createBackendSpinner.succeed(`Successfully created backend!\n\t${backend.name}\n`);
98
93
  await setDefaultTrafficPolicy(projectId, location, backendId, branch);
99
94
  const confirmRollout = await (0, prompt_1.promptOnce)({
package/lib/auth.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addAdditionalAccount = exports.logout = exports.getAccessToken = exports.findAccountByEmail = exports.loginGithub = exports.loginGoogle = exports.setGlobalDefaultAccount = exports.setProjectAccount = exports.loginAdditionalAccount = exports.selectAccount = exports.setRefreshToken = exports.setActiveAccount = exports.getAllAccounts = exports.getAdditionalAccounts = exports.getProjectDefaultAccount = exports.getGlobalDefaultAccount = void 0;
3
+ exports.addAdditionalAccount = exports.logout = exports.getAccessToken = exports.findAccountByEmail = exports.loginGithub = exports.loginGoogle = exports.setGlobalDefaultAccount = exports.setProjectAccount = exports.loginAdditionalAccount = exports.selectAccount = exports.setAccessToken = exports.setRefreshToken = exports.setActiveAccount = exports.getAllAccounts = exports.getAdditionalAccounts = exports.getProjectDefaultAccount = exports.getGlobalDefaultAccount = void 0;
4
4
  const clc = require("colorette");
5
5
  const FormData = require("form-data");
6
6
  const http = require("http");
@@ -61,9 +61,10 @@ function getAllAccounts() {
61
61
  return res;
62
62
  }
63
63
  exports.getAllAccounts = getAllAccounts;
64
- function setActiveAccount(options, account) {
64
+ async function setActiveAccount(options, account) {
65
65
  if (account.tokens.refresh_token) {
66
66
  setRefreshToken(account.tokens.refresh_token);
67
+ setAccessToken(await apiv2.getAccessToken());
67
68
  }
68
69
  options.user = account.user;
69
70
  options.tokens = account.tokens;
@@ -73,6 +74,10 @@ function setRefreshToken(token) {
73
74
  apiv2.setRefreshToken(token);
74
75
  }
75
76
  exports.setRefreshToken = setRefreshToken;
77
+ function setAccessToken(token) {
78
+ apiv2.setAccessToken(token);
79
+ }
80
+ exports.setAccessToken = setAccessToken;
76
81
  function selectAccount(account, projectRoot) {
77
82
  const defaultUser = getProjectDefaultAccount(projectRoot);
78
83
  if (!account) {
package/lib/command.js CHANGED
@@ -173,7 +173,7 @@ class Command {
173
173
  const projectRoot = options.projectRoot;
174
174
  const activeAccount = (0, auth_1.selectAccount)(account, projectRoot);
175
175
  if (activeAccount) {
176
- (0, auth_1.setActiveAccount)(options, activeAccount);
176
+ await (0, auth_1.setActiveAccount)(options, activeAccount);
177
177
  }
178
178
  this.applyRC(options);
179
179
  if (options.project) {
@@ -44,7 +44,7 @@ exports.command = new command_1.Command("dataconnect:services:list")
44
44
  const instanceName = (_c = (_b = schema === null || schema === void 0 ? void 0 : schema.primaryDatasource.postgresql) === null || _b === void 0 ? void 0 : _b.cloudSql.instance) !== null && _c !== void 0 ? _c : "";
45
45
  const instanceId = instanceName.split("/").pop();
46
46
  const dbId = (_e = (_d = schema === null || schema === void 0 ? void 0 : schema.primaryDatasource.postgresql) === null || _d === void 0 ? void 0 : _d.database) !== null && _e !== void 0 ? _e : "";
47
- const dbName = `CloudSQL Instance: ${instanceId}\nDatabase:${dbId}`;
47
+ const dbName = `CloudSQL Instance: ${instanceId}\nDatabase: ${dbId}`;
48
48
  table.push([
49
49
  serviceName.serviceId,
50
50
  serviceName.location,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBackend = exports.resolveBackend = exports.AllIngressSettings = exports.AllVpcEgressSettings = exports.AllFunctionsPlatforms = exports.isBlockingTriggered = exports.isTaskQueueTriggered = exports.isScheduleTriggered = exports.isEventTriggered = exports.isCallableTriggered = exports.isHttpsTriggered = exports.of = exports.empty = void 0;
3
+ exports.toBackend = exports.envWithTypes = exports.resolveBackend = exports.AllIngressSettings = exports.AllVpcEgressSettings = exports.AllFunctionsPlatforms = exports.isBlockingTriggered = exports.isTaskQueueTriggered = exports.isScheduleTriggered = exports.isEventTriggered = exports.isCallableTriggered = exports.isHttpsTriggered = exports.of = exports.empty = void 0;
4
4
  const backend = require("./backend");
5
5
  const proto = require("../../gcp/proto");
6
6
  const api = require("../../.../../api");
@@ -114,12 +114,21 @@ function envWithTypes(definedParams, rawEnvs) {
114
114
  list: true,
115
115
  };
116
116
  }
117
+ else if (param.type === "secret") {
118
+ providedType = {
119
+ string: true,
120
+ boolean: false,
121
+ number: false,
122
+ list: false,
123
+ };
124
+ }
117
125
  }
118
126
  }
119
127
  out[envName] = new params.ParamValue(value, false, providedType);
120
128
  }
121
129
  return out;
122
130
  }
131
+ exports.envWithTypes = envWithTypes;
123
132
  class Resolver {
124
133
  constructor(paramValues) {
125
134
  this.paramValues = paramValues;
@@ -322,6 +322,7 @@ async function startAll(options, showUI = true, runningTestScript = false) {
322
322
  env: Object.assign({}, options.extDevEnv),
323
323
  secretEnv: [],
324
324
  predefinedTriggers: options.extDevTriggers,
325
+ ignore: cfg.ignore,
325
326
  });
326
327
  }
327
328
  }
@@ -46,20 +46,20 @@ const EMULATOR_UPDATE_DETAILS = {
46
46
  },
47
47
  dataconnect: process.platform === "darwin"
48
48
  ? {
49
- version: "1.2.3",
50
- expectedSize: 24056640,
51
- expectedChecksum: "3ed315b230965d5a6471de08e59c226a",
49
+ version: "1.2.4",
50
+ expectedSize: 24097600,
51
+ expectedChecksum: "e0a344620b71d64b79d99b2c358e7646",
52
52
  }
53
53
  : process.platform === "win32"
54
54
  ? {
55
- version: "1.2.3",
56
- expectedSize: 24466432,
57
- expectedChecksum: "a371516844fea7ea6aad3c82baf0149c",
55
+ version: "1.2.4",
56
+ expectedSize: 24509440,
57
+ expectedChecksum: "44ebc07e481a85bd735fe8007fab3efe",
58
58
  }
59
59
  : {
60
- version: "1.2.3",
61
- expectedSize: 23965848,
62
- expectedChecksum: "c5c342d76b0c118e74a5f6ecdcaa58b8",
60
+ version: "1.2.4",
61
+ expectedSize: 24010904,
62
+ expectedChecksum: "bf10e866f4c4e132bf8115460508e6e2",
63
63
  },
64
64
  };
65
65
  exports.DownloadDetails = {
@@ -248,6 +248,7 @@ class FunctionsEmulator {
248
248
  return Promise.resolve();
249
249
  }
250
250
  async connect() {
251
+ var _a, _b;
251
252
  for (const backend of this.args.emulatableBackends) {
252
253
  this.logger.logLabeled("BULLET", "functions", `Watching "${backend.functionsDir}" for Cloud Functions...`);
253
254
  const watcher = chokidar.watch(backend.functionsDir, {
@@ -256,6 +257,7 @@ class FunctionsEmulator {
256
257
  /(^|[\/\\])\../,
257
258
  /.+\.log/,
258
259
  /.+?[\\\/]venv[\\\/].+?/,
260
+ ...((_b = (_a = backend.ignore) === null || _a === void 0 ? void 0 : _a.map((i) => `**/${i}`)) !== null && _b !== void 0 ? _b : []),
259
261
  ],
260
262
  persistent: true,
261
263
  });
@@ -26,7 +26,7 @@ exports.ALL_EXPERIMENTS = experiments({
26
26
  "of deploys. This has been made an experiment due to backend bugs that are " +
27
27
  "temporarily causing failures in some regions with this optimization enabled",
28
28
  public: true,
29
- default: false,
29
+ default: true,
30
30
  },
31
31
  deletegcfartifacts: {
32
32
  shortDescription: `Add the ${(0, colorette_1.bold)("functions:deletegcfartifacts")} command to purge docker build images`,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listUsers = exports.deleteUser = exports.getUser = exports.createUser = exports.createDatabase = exports.getDatabase = exports.listDatabases = exports.updateInstanceForDataConnect = exports.createInstance = exports.instanceConsoleLink = exports.getInstance = exports.listInstances = void 0;
3
+ exports.listUsers = exports.deleteUser = exports.getUser = exports.createUser = exports.deleteDatabase = exports.createDatabase = exports.getDatabase = exports.listDatabases = exports.updateInstanceForDataConnect = exports.createInstance = exports.instanceConsoleLink = exports.getInstance = exports.listInstances = void 0;
4
4
  const apiv2_1 = require("../../apiv2");
5
5
  const api_1 = require("../../api");
6
6
  const operationPoller = require("../../operation-poller");
@@ -125,6 +125,11 @@ async function createDatabase(projectId, instanceId, databaseId) {
125
125
  return pollRes;
126
126
  }
127
127
  exports.createDatabase = createDatabase;
128
+ async function deleteDatabase(projectId, instanceId, databaseId) {
129
+ const res = await client.delete(`projects/${projectId}/instances/${instanceId}/databases/${databaseId}`);
130
+ return res.body;
131
+ }
132
+ exports.deleteDatabase = deleteDatabase;
128
133
  async function createUser(projectId, instanceId, type, username, password) {
129
134
  const maxRetries = 3;
130
135
  let retries = 0;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateP4SA = exports.serviceAgentEmail = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.listAllLinkableGitRepositories = exports.listAllConnections = exports.getConnection = exports.deleteConnection = exports.createConnection = exports.client = void 0;
3
+ exports.generateP4SA = exports.serviceAgentEmail = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.listAllBranches = exports.listAllLinkableGitRepositories = exports.listAllConnections = exports.getConnection = exports.deleteConnection = exports.createConnection = exports.client = void 0;
4
4
  const apiv2_1 = require("../apiv2");
5
5
  const api_1 = require("../api");
6
6
  const serviceusage_1 = require("./serviceusage");
@@ -72,6 +72,29 @@ async function listAllLinkableGitRepositories(projectId, location, connectionId)
72
72
  return repos;
73
73
  }
74
74
  exports.listAllLinkableGitRepositories = listAllLinkableGitRepositories;
75
+ async function listAllBranches(repoLinkName) {
76
+ const branches = new Set();
77
+ const getNextPage = async (pageToken = "") => {
78
+ const res = await exports.client.get(`${repoLinkName}:fetchGitRefs`, {
79
+ queryParams: {
80
+ refType: "BRANCH",
81
+ pageSize: PAGE_SIZE_MAX,
82
+ pageToken,
83
+ },
84
+ });
85
+ if (Array.isArray(res.body.refNames)) {
86
+ res.body.refNames.forEach((branch) => {
87
+ branches.add(branch);
88
+ });
89
+ }
90
+ if (res.body.nextPageToken) {
91
+ await getNextPage(res.body.nextPageToken);
92
+ }
93
+ };
94
+ await getNextPage();
95
+ return branches;
96
+ }
97
+ exports.listAllBranches = listAllBranches;
75
98
  async function createGitRepositoryLink(projectId, location, connectionId, gitRepositoryLinkId, cloneUri) {
76
99
  const res = await exports.client.post(`projects/${projectId}/locations/${LOCATION_OVERRIDE !== null && LOCATION_OVERRIDE !== void 0 ? LOCATION_OVERRIDE : location}/connections/${connectionId}/gitRepositoryLinks`, { cloneUri }, { queryParams: { gitRepositoryLinkId } });
77
100
  return res.body;
@@ -52,7 +52,7 @@ async function doSetup(setup, config, options) {
52
52
  if (!account) {
53
53
  throw new error_1.FirebaseError(`No account selected, have you run "firebase login"?`, { exit: 1 });
54
54
  }
55
- (0, auth_1.setActiveAccount)(options, account);
55
+ await (0, auth_1.setActiveAccount)(options, account);
56
56
  if (config.projectDir) {
57
57
  (0, auth_1.setProjectAccount)(config.projectDir, account.user.email);
58
58
  }
@@ -20,9 +20,6 @@ function getAuthClient(config) {
20
20
  return authClient;
21
21
  }
22
22
  async function autoAuth(options, authScopes) {
23
- if (process.env.MONOSPACE_ENV) {
24
- throw new error_1.FirebaseError("autoAuth not yet implemented for IDX. Please run 'firebase login'");
25
- }
26
23
  const client = getAuthClient({ scopes: authScopes, projectId: options.project });
27
24
  const token = await client.getAccessToken();
28
25
  token !== null ? apiv2.setAccessToken(token) : false;
@@ -34,6 +31,14 @@ async function autoAuth(options, authScopes) {
34
31
  catch (e) {
35
32
  logger_1.logger.debug(`Error getting account credentials.`);
36
33
  }
34
+ if (process.env.MONOSPACE_ENV && token && clientEmail) {
35
+ await (0, auth_1.setActiveAccount)(options, {
36
+ user: { email: clientEmail },
37
+ tokens: { access_token: token },
38
+ });
39
+ (0, auth_1.setGlobalDefaultAccount)({ user: { email: clientEmail }, tokens: { access_token: token } });
40
+ options.projectId = await client.getProjectId();
41
+ }
37
42
  return clientEmail;
38
43
  }
39
44
  async function requireAuth(options) {
@@ -71,7 +76,7 @@ async function requireAuth(options) {
71
76
  if (!user || !tokens) {
72
77
  throw new error_1.FirebaseError(AUTH_ERROR_MESSAGE);
73
78
  }
74
- (0, auth_1.setActiveAccount)(options, { user, tokens });
79
+ await (0, auth_1.setActiveAccount)(options, { user, tokens });
75
80
  return user.email;
76
81
  }
77
82
  exports.requireAuth = requireAuth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "13.13.0",
3
+ "version": "13.13.2",
4
4
  "description": "Command-Line Interface for Firebase",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {