firebase-tools 13.12.0 → 13.13.1

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");
@@ -13,7 +13,7 @@ const api_1 = require("../api");
13
13
  const fuzzy = require("fuzzy");
14
14
  const inquirer = require("inquirer");
15
15
  const APPHOSTING_CONN_PATTERN = /.+\/apphosting-github-conn-.+$/;
16
- const APPHOSTING_OAUTH_CONN_NAME = "apphosting-github-oauth";
16
+ const APPHOSTING_OAUTH_CONN_NAME = "firebase-app-hosting-github-oauth";
17
17
  const CONNECTION_NAME_REGEX = /^projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/connections\/(?<id>[^\/]+)$/;
18
18
  function parseConnectionName(name) {
19
19
  const match = CONNECTION_NAME_REGEX.exec(name);
@@ -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");
@@ -65,6 +65,9 @@ function setActiveAccount(options, account) {
65
65
  if (account.tokens.refresh_token) {
66
66
  setRefreshToken(account.tokens.refresh_token);
67
67
  }
68
+ if (account.tokens.access_token) {
69
+ setAccessToken(account.tokens.access_token);
70
+ }
68
71
  options.user = account.user;
69
72
  options.tokens = account.tokens;
70
73
  }
@@ -73,6 +76,10 @@ function setRefreshToken(token) {
73
76
  apiv2.setRefreshToken(token);
74
77
  }
75
78
  exports.setRefreshToken = setRefreshToken;
79
+ function setAccessToken(token) {
80
+ apiv2.setAccessToken(token);
81
+ }
82
+ exports.setAccessToken = setAccessToken;
76
83
  function selectAccount(account, projectRoot) {
77
84
  const defaultUser = getProjectDefaultAccount(projectRoot);
78
85
  if (!account) {
@@ -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.2",
50
- expectedSize: 24007488,
51
- expectedChecksum: "c1fb77895203681479ee5dd22d57249f",
49
+ version: "1.2.4",
50
+ expectedSize: 24097600,
51
+ expectedChecksum: "e0a344620b71d64b79d99b2c358e7646",
52
52
  }
53
53
  : process.platform === "win32"
54
54
  ? {
55
- version: "1.2.2",
56
- expectedSize: 24414208,
57
- expectedChecksum: "7e263c2b2bc9055ead2db8102e883534",
55
+ version: "1.2.4",
56
+ expectedSize: 24509440,
57
+ expectedChecksum: "44ebc07e481a85bd735fe8007fab3efe",
58
58
  }
59
59
  : {
60
- version: "1.2.2",
61
- expectedSize: 24023300,
62
- expectedChecksum: "12467418226ac9657fb64b4d719d0e1d",
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`,
@@ -87,9 +87,9 @@ async function getDevModeHandle(cwd) {
87
87
  return (0, utils_1.simpleProxy)(await host);
88
88
  }
89
89
  exports.getDevModeHandle = getDevModeHandle;
90
- async function getConfig(dir) {
91
- const { loadNuxtConfig } = await (0, utils_1.relativeRequire)(dir, "@nuxt/kit");
92
- return await loadNuxtConfig(dir);
90
+ async function getConfig(cwd) {
91
+ const { loadNuxtConfig } = await (0, utils_1.relativeRequire)(cwd, "@nuxt/kit");
92
+ return await loadNuxtConfig({ cwd });
93
93
  }
94
94
  exports.getConfig = getConfig;
95
95
  function init(setup, config) {
@@ -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;
@@ -50,11 +50,11 @@ async function doSetup(setup, config) {
50
50
  newConnectorYaml.generate = {};
51
51
  }
52
52
  if (platforms.includes(IOS)) {
53
- const defaultOutputDir = (_a = newConnectorYaml.generate.swiftSdk) === null || _a === void 0 ? void 0 : _a.outputDir;
54
53
  const outputDir = await (0, prompt_1.promptOnce)({
55
54
  message: `What directory do you want to write your Swift SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
56
55
  type: "input",
57
- default: defaultOutputDir,
56
+ default: ((_a = newConnectorYaml.generate.swiftSdk) === null || _a === void 0 ? void 0 : _a.outputDir) ||
57
+ `./../.dataconnect/generated/${newConnectorYaml.connectorId}/swift-sdk`,
58
58
  });
59
59
  const swiftSdk = { outputDir };
60
60
  newConnectorYaml.generate.swiftSdk = swiftSdk;
@@ -63,7 +63,8 @@ async function doSetup(setup, config) {
63
63
  const outputDir = await (0, prompt_1.promptOnce)({
64
64
  message: `What directory do you want to write your JavaScript SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
65
65
  type: "input",
66
- default: (_b = newConnectorYaml.generate.javascriptSdk) === null || _b === void 0 ? void 0 : _b.outputDir,
66
+ default: ((_b = newConnectorYaml.generate.javascriptSdk) === null || _b === void 0 ? void 0 : _b.outputDir) ||
67
+ `./../.dataconnect/generated/${newConnectorYaml.connectorId}/javascript-sdk`,
67
68
  });
68
69
  const pkg = await (0, prompt_1.promptOnce)({
69
70
  message: "What package name do you want to use for your JavaScript SDK?",
@@ -88,7 +89,8 @@ async function doSetup(setup, config) {
88
89
  const outputDir = await (0, prompt_1.promptOnce)({
89
90
  message: `What directory do you want to write your Kotlin SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
90
91
  type: "input",
91
- default: (_f = newConnectorYaml.generate.kotlinSdk) === null || _f === void 0 ? void 0 : _f.outputDir,
92
+ default: ((_f = newConnectorYaml.generate.kotlinSdk) === null || _f === void 0 ? void 0 : _f.outputDir) ||
93
+ `./../.dataconnect/generated/${newConnectorYaml.connectorId}/kotlin-sdk/src/main/kotlin/${newConnectorYaml.connectorId}`,
92
94
  });
93
95
  const pkg = await (0, prompt_1.promptOnce)({
94
96
  message: "What package name do you want to use for your Kotlin SDK?",
@@ -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,11 @@ 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
+ (0, auth_1.setActiveAccount)(options, { user: { email: clientEmail }, tokens: { access_token: token } });
36
+ (0, auth_1.setGlobalDefaultAccount)({ user: { email: clientEmail }, tokens: { access_token: token } });
37
+ options.projectId = await client.getProjectId();
38
+ }
37
39
  return clientEmail;
38
40
  }
39
41
  async function requireAuth(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "13.12.0",
3
+ "version": "13.13.1",
4
4
  "description": "Command-Line Interface for Firebase",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {