firebase-tools-with-isolate 13.4.0 → 13.6.1-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.
Files changed (93) hide show
  1. package/lib/accountExporter.js +1 -1
  2. package/lib/accountImporter.js +1 -1
  3. package/lib/api.js +112 -56
  4. package/lib/apiv2.js +10 -3
  5. package/lib/appdistribution/client.js +4 -4
  6. package/lib/auth.js +17 -17
  7. package/lib/commands/hosting-disable.js +1 -1
  8. package/lib/commands/open.js +1 -1
  9. package/lib/database/metadata.js +3 -3
  10. package/lib/defaultCredentials.js +2 -2
  11. package/lib/deploy/extensions/v2FunctionHelper.js +1 -1
  12. package/lib/deploy/functions/backend.js +5 -1
  13. package/lib/deploy/functions/build.js +10 -7
  14. package/lib/deploy/functions/containerCleaner.js +4 -4
  15. package/lib/deploy/functions/deploy.js +8 -2
  16. package/lib/deploy/functions/ensure.js +1 -1
  17. package/lib/deploy/functions/prepare.js +5 -4
  18. package/lib/deploy/functions/release/fabricator.js +9 -5
  19. package/lib/deploy/functions/runtimes/discovery/index.js +2 -2
  20. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +2 -1
  21. package/lib/deploy/functions/runtimes/node/parseTriggers.js +2 -2
  22. package/lib/deploy/hosting/uploader.js +1 -1
  23. package/lib/deploy/index.js +1 -1
  24. package/lib/deploy/remoteconfig/functions.js +1 -1
  25. package/lib/emulator/adminSdkConfig.js +1 -1
  26. package/lib/emulator/commandUtils.js +7 -4
  27. package/lib/emulator/controller.js +3 -4
  28. package/lib/emulator/downloadableEmulators.js +10 -10
  29. package/lib/emulator/functionsEmulator.js +21 -1
  30. package/lib/ensureApiEnabled.js +1 -1
  31. package/lib/extensions/extensionsApi.js +5 -5
  32. package/lib/extensions/extensionsHelper.js +4 -4
  33. package/lib/extensions/provisioningHelper.js +2 -2
  34. package/lib/extensions/publishHelpers.js +1 -1
  35. package/lib/extensions/publisherApi.js +3 -3
  36. package/lib/extensions/resolveSource.js +1 -1
  37. package/lib/extensions/secretsUtils.js +1 -1
  38. package/lib/extensions/tos.js +1 -1
  39. package/lib/fetchMOTD.js +1 -1
  40. package/lib/fetchWebSetup.js +4 -3
  41. package/lib/firestore/api-sort.js +17 -0
  42. package/lib/firestore/api.js +9 -2
  43. package/lib/firestore/checkDatabaseType.js +1 -1
  44. package/lib/firestore/delete.js +1 -1
  45. package/lib/firestore/pretty-print.js +11 -2
  46. package/lib/frameworks/index.js +6 -2
  47. package/lib/frameworks/next/constants.js +38 -1
  48. package/lib/frameworks/next/index.js +25 -3
  49. package/lib/frameworks/next/utils.js +20 -1
  50. package/lib/functions/secrets.js +3 -3
  51. package/lib/functionsConfig.js +1 -1
  52. package/lib/gcp/apphosting.js +21 -15
  53. package/lib/gcp/artifactregistry.js +1 -1
  54. package/lib/gcp/auth.js +1 -1
  55. package/lib/gcp/cloudbilling.js +1 -1
  56. package/lib/gcp/cloudbuild.js +1 -1
  57. package/lib/gcp/cloudfunctions.js +1 -1
  58. package/lib/gcp/cloudfunctionsv2.js +4 -1
  59. package/lib/gcp/cloudlogging.js +1 -1
  60. package/lib/gcp/cloudmonitoring.js +1 -1
  61. package/lib/gcp/cloudscheduler.js +2 -2
  62. package/lib/gcp/cloudtasks.js +1 -1
  63. package/lib/gcp/devConnect.js +84 -0
  64. package/lib/gcp/eventarc.js +1 -1
  65. package/lib/gcp/firestore.js +2 -2
  66. package/lib/gcp/iam.js +2 -2
  67. package/lib/gcp/identityPlatform.js +1 -1
  68. package/lib/gcp/pubsub.js +1 -1
  69. package/lib/gcp/resourceManager.js +2 -1
  70. package/lib/gcp/rules.js +1 -1
  71. package/lib/gcp/run.js +1 -1
  72. package/lib/gcp/runtimeconfig.js +1 -1
  73. package/lib/gcp/secretManager.js +1 -1
  74. package/lib/gcp/serviceusage.js +1 -1
  75. package/lib/gcp/storage.js +12 -8
  76. package/lib/hosting/api.js +14 -3
  77. package/lib/hosting/cloudRunProxy.js +1 -1
  78. package/lib/init/features/apphosting/index.js +5 -5
  79. package/lib/init/features/apphosting/repo.js +84 -99
  80. package/lib/init/features/database.js +1 -1
  81. package/lib/init/features/extensions/index.js +1 -1
  82. package/lib/init/features/functions/index.js +2 -2
  83. package/lib/init/features/hosting/github.js +4 -3
  84. package/lib/management/apps.js +4 -4
  85. package/lib/management/database.js +1 -1
  86. package/lib/management/projects.js +4 -4
  87. package/lib/remoteconfig/get.js +1 -1
  88. package/lib/remoteconfig/rollback.js +1 -1
  89. package/lib/remoteconfig/versionslist.js +1 -1
  90. package/lib/serve/functions.js +2 -0
  91. package/lib/shortenUrl.js +2 -2
  92. package/lib/utils.js +1 -1
  93. package/package.json +6 -6
@@ -9,9 +9,12 @@ const error_1 = require("../error");
9
9
  const logger_1 = require("../logger");
10
10
  const ensureApiEnabled_1 = require("../ensureApiEnabled");
11
11
  async function getDefaultBucket(projectId) {
12
- await (0, ensureApiEnabled_1.ensure)(projectId, api_1.firebaseStorageOrigin, "storage", false);
12
+ await (0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.firebaseStorageOrigin)(), "storage", false);
13
13
  try {
14
- const localAPIClient = new apiv2_1.Client({ urlPrefix: api_1.firebaseStorageOrigin, apiVersion: "v1alpha" });
14
+ const localAPIClient = new apiv2_1.Client({
15
+ urlPrefix: (0, api_1.firebaseStorageOrigin)(),
16
+ apiVersion: "v1alpha",
17
+ });
15
18
  const response = await localAPIClient.get(`/projects/${projectId}/defaultBucket`);
16
19
  if (!response.body?.bucket.name) {
17
20
  logger_1.logger.debug("Default storage bucket is undefined.");
@@ -28,7 +31,7 @@ async function getDefaultBucket(projectId) {
28
31
  }
29
32
  }
30
33
  exports.getDefaultBucket = getDefaultBucket;
31
- async function upload(source, uploadUrl, extraHeaders) {
34
+ async function upload(source, uploadUrl, extraHeaders, ignoreQuotaProject) {
32
35
  const url = new URL(uploadUrl);
33
36
  const localAPIClient = new apiv2_1.Client({ urlPrefix: url.origin, auth: false });
34
37
  const res = await localAPIClient.request({
@@ -42,6 +45,7 @@ async function upload(source, uploadUrl, extraHeaders) {
42
45
  },
43
46
  body: source.stream,
44
47
  skipLog: { resBody: true },
48
+ ignoreQuotaProject,
45
49
  });
46
50
  return {
47
51
  generation: res.response.headers.get("x-goog-generation"),
@@ -52,7 +56,7 @@ async function uploadObject(source, bucketName) {
52
56
  if (path.extname(source.file) !== ".zip") {
53
57
  throw new error_1.FirebaseError(`Expected a file name ending in .zip, got ${source.file}`);
54
58
  }
55
- const localAPIClient = new apiv2_1.Client({ urlPrefix: api_1.storageOrigin });
59
+ const localAPIClient = new apiv2_1.Client({ urlPrefix: (0, api_1.storageOrigin)() });
56
60
  const location = `/${bucketName}/${path.basename(source.file)}`;
57
61
  const res = await localAPIClient.request({
58
62
  method: "PUT",
@@ -71,13 +75,13 @@ async function uploadObject(source, bucketName) {
71
75
  }
72
76
  exports.uploadObject = uploadObject;
73
77
  function deleteObject(location) {
74
- const localAPIClient = new apiv2_1.Client({ urlPrefix: api_1.storageOrigin });
78
+ const localAPIClient = new apiv2_1.Client({ urlPrefix: (0, api_1.storageOrigin)() });
75
79
  return localAPIClient.delete(location);
76
80
  }
77
81
  exports.deleteObject = deleteObject;
78
82
  async function getBucket(bucketName) {
79
83
  try {
80
- const localAPIClient = new apiv2_1.Client({ urlPrefix: api_1.storageOrigin });
84
+ const localAPIClient = new apiv2_1.Client({ urlPrefix: (0, api_1.storageOrigin)() });
81
85
  const result = await localAPIClient.get(`/storage/v1/b/${bucketName}`);
82
86
  return result.body;
83
87
  }
@@ -91,7 +95,7 @@ async function getBucket(bucketName) {
91
95
  exports.getBucket = getBucket;
92
96
  async function listBuckets(projectId) {
93
97
  try {
94
- const localAPIClient = new apiv2_1.Client({ urlPrefix: api_1.storageOrigin });
98
+ const localAPIClient = new apiv2_1.Client({ urlPrefix: (0, api_1.storageOrigin)() });
95
99
  const result = await localAPIClient.get(`/storage/v1/b?project=${projectId}`);
96
100
  return result.body.items.map((bucket) => bucket.name);
97
101
  }
@@ -105,7 +109,7 @@ async function listBuckets(projectId) {
105
109
  exports.listBuckets = listBuckets;
106
110
  async function getServiceAccount(projectId) {
107
111
  try {
108
- const localAPIClient = new apiv2_1.Client({ urlPrefix: api_1.storageOrigin });
112
+ const localAPIClient = new apiv2_1.Client({ urlPrefix: (0, api_1.storageOrigin)() });
109
113
  const response = await localAPIClient.get(`/storage/v1/projects/${projectId}/serviceAccount`);
110
114
  return response.body;
111
115
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDeploymentDomain = exports.getAllSiteDomains = exports.getSiteDomains = exports.cleanAuthState = exports.getCleanDomains = exports.removeAuthDomain = exports.addAuthDomains = exports.deleteSite = exports.updateSite = exports.createSite = exports.getSite = exports.listSites = exports.createRelease = exports.cloneVersion = exports.listVersions = exports.updateVersion = exports.createVersion = exports.deleteChannel = exports.updateChannelTtl = exports.createChannel = exports.listChannels = exports.getChannel = exports.normalizeName = exports.SiteType = void 0;
3
+ exports.getDeploymentDomain = exports.getAllSiteDomains = exports.getSiteDomains = exports.cleanAuthState = exports.getCleanDomains = exports.removeAuthDomain = exports.addAuthDomains = exports.deleteSite = exports.updateSite = exports.createSite = exports.getSite = exports.listDemoSites = exports.listSites = exports.createRelease = exports.cloneVersion = exports.listVersions = exports.updateVersion = exports.createVersion = exports.deleteChannel = exports.updateChannelTtl = exports.createChannel = exports.listChannels = exports.getChannel = exports.normalizeName = exports.SiteType = void 0;
4
4
  const error_1 = require("../error");
5
5
  const api_1 = require("../api");
6
6
  const apiv2_1 = require("../apiv2");
@@ -28,7 +28,7 @@ function normalizeName(s) {
28
28
  }
29
29
  exports.normalizeName = normalizeName;
30
30
  const apiClient = new apiv2_1.Client({
31
- urlPrefix: api_1.hostingApiOrigin,
31
+ urlPrefix: (0, api_1.hostingApiOrigin)(),
32
32
  apiVersion: "v1beta1",
33
33
  auth: true,
34
34
  });
@@ -120,7 +120,7 @@ async function cloneVersion(site, versionName, finalize = false) {
120
120
  });
121
121
  const { name: operationName } = res.body;
122
122
  const pollRes = await operationPoller.pollOperation({
123
- apiOrigin: api_1.hostingApiOrigin,
123
+ apiOrigin: (0, api_1.hostingApiOrigin)(),
124
124
  apiVersion: "v1beta1",
125
125
  operationResourceName: operationName,
126
126
  masterTimeout: 600000,
@@ -156,6 +156,17 @@ async function listSites(project) {
156
156
  }
157
157
  }
158
158
  exports.listSites = listSites;
159
+ function listDemoSites(projectId) {
160
+ return [
161
+ {
162
+ name: `projects/${projectId}/sites/${projectId}`,
163
+ defaultUrl: `https://${projectId}.firebaseapp.com`,
164
+ appId: "fake-app-id",
165
+ labels: {},
166
+ },
167
+ ];
168
+ }
169
+ exports.listDemoSites = listDemoSites;
159
170
  async function getSite(project, site) {
160
171
  try {
161
172
  const res = await apiClient.get(`/projects/${project}/sites/${site}`);
@@ -7,7 +7,7 @@ const error_1 = require("../error");
7
7
  const logger_1 = require("../logger");
8
8
  const projectUtils_1 = require("../projectUtils");
9
9
  const cloudRunCache = {};
10
- const apiClient = new apiv2_1.Client({ urlPrefix: api_1.cloudRunApiOrigin, apiVersion: "v1" });
10
+ const apiClient = new apiv2_1.Client({ urlPrefix: (0, api_1.cloudRunApiOrigin)(), apiVersion: "v1" });
11
11
  async function getCloudRunUrl(rewrite, projectId) {
12
12
  const alreadyFetched = cloudRunCache[`${rewrite.run.region}/${rewrite.run.serviceId}`];
13
13
  if (alreadyFetched) {
@@ -17,17 +17,17 @@ const ensureApiEnabled_1 = require("../../../ensureApiEnabled");
17
17
  const deploymentTool = require("../../../deploymentTool");
18
18
  const DEFAULT_COMPUTE_SERVICE_ACCOUNT_NAME = "firebase-app-hosting-compute";
19
19
  const apphostingPollerOptions = {
20
- apiOrigin: api_1.apphostingOrigin,
20
+ apiOrigin: (0, api_1.apphostingOrigin)(),
21
21
  apiVersion: apphosting_1.API_VERSION,
22
22
  masterTimeout: 25 * 60 * 1000,
23
23
  maxBackoff: 10000,
24
24
  };
25
25
  async function doSetup(projectId, location, serviceAccount) {
26
26
  await Promise.all([
27
- (0, ensureApiEnabled_1.ensure)(projectId, api_1.cloudbuildOrigin, "apphosting", true),
28
- (0, ensureApiEnabled_1.ensure)(projectId, api_1.secretManagerOrigin, "apphosting", true),
29
- (0, ensureApiEnabled_1.ensure)(projectId, api_1.cloudRunApiOrigin, "apphosting", true),
30
- (0, ensureApiEnabled_1.ensure)(projectId, api_1.artifactRegistryDomain, "apphosting", true),
27
+ (0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.cloudbuildOrigin)(), "apphosting", true),
28
+ (0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.secretManagerOrigin)(), "apphosting", true),
29
+ (0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.cloudRunApiOrigin)(), "apphosting", true),
30
+ (0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.artifactRegistryDomain)(), "apphosting", true),
31
31
  ]);
32
32
  const allowedLocations = (await apphosting.listLocations(projectId)).map((loc) => loc.locationId);
33
33
  if (location) {
@@ -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.linkGitHubRepository = exports.parseConnectionName = void 0;
3
+ exports.fetchAllRepositories = exports.listAppHostingConnections = exports.getOrCreateRepository = exports.getOrCreateConnection = exports.createConnection = exports.getOrCreateOauthConnection = exports.linkGitHubRepository = exports.parseConnectionName = void 0;
4
4
  const clc = require("colorette");
5
5
  const gcb = require("../../../gcp/cloudbuild");
6
6
  const rm = require("../../../gcp/resourceManager");
@@ -29,7 +29,7 @@ function parseConnectionName(name) {
29
29
  }
30
30
  exports.parseConnectionName = parseConnectionName;
31
31
  const gcbPollerOptions = {
32
- apiOrigin: api_1.cloudbuildOrigin,
32
+ apiOrigin: (0, api_1.cloudbuildOrigin)(),
33
33
  apiVersion: "v2",
34
34
  masterTimeout: 25 * 60 * 1000,
35
35
  maxBackoff: 10000,
@@ -48,106 +48,117 @@ function generateConnectionId() {
48
48
  const randomHash = Math.random().toString(36).slice(6);
49
49
  return `apphosting-github-conn-${randomHash}`;
50
50
  }
51
- const ADD_REPO_CHOICE = "@ADD_REPO";
52
51
  const ADD_CONN_CHOICE = "@ADD_CONN";
53
- const CONFIGURE_REMOTE_URI_CHOICES = [ADD_REPO_CHOICE, ADD_CONN_CHOICE];
54
52
  async function linkGitHubRepository(projectId, location) {
55
53
  utils.logBullet(clc.bold(`${clc.yellow("===")} Set up a GitHub connection`));
56
- let oauthConn = await getOrCreateConnection(projectId, location, APPHOSTING_OAUTH_CONN_NAME);
57
- while (oauthConn.installationState.stage === "PENDING_USER_OAUTH") {
58
- oauthConn = await promptConnectionAuth(oauthConn);
59
- }
54
+ const oauthConn = await getOrCreateOauthConnection(projectId, location);
60
55
  const existingConns = await listAppHostingConnections(projectId);
61
- if (existingConns.length < 1) {
62
- const grantSuccess = await promptSecretManagerAdminGrant(projectId);
63
- if (!grantSuccess) {
64
- throw new error_1.FirebaseError("Insufficient IAM permissions to create a new connection to GitHub");
65
- }
66
- const connectionId = generateConnectionId();
67
- const conn = await createConnection(projectId, location, connectionId, {
68
- authorizerCredential: oauthConn.githubConfig?.authorizerCredential,
69
- });
70
- let refreshedConn = conn;
71
- while (refreshedConn.installationState.stage !== "COMPLETE") {
72
- refreshedConn = await promptAppInstall(conn);
73
- }
74
- existingConns.push(refreshedConn);
56
+ if (existingConns.length === 0) {
57
+ existingConns.push(await createFullyInstalledConnection(projectId, location, generateConnectionId(), oauthConn));
75
58
  }
76
- let { remoteUri, connection } = await promptRepositoryUri(projectId, existingConns);
77
- while (CONFIGURE_REMOTE_URI_CHOICES.includes(remoteUri)) {
78
- if (remoteUri === ADD_REPO_CHOICE) {
79
- await utils.openInBrowser("https://github.com/apps/google-cloud-build/installations/new");
80
- await (0, prompt_1.promptOnce)({
81
- type: "input",
82
- message: "Press ENTER once you have provided the GitHub app installation with access to your desired repository.",
83
- });
84
- }
85
- else if (remoteUri === ADD_CONN_CHOICE) {
86
- const connectionId = generateConnectionId();
87
- const conn = await createConnection(projectId, location, connectionId, {
88
- authorizerCredential: oauthConn.githubConfig?.authorizerCredential,
89
- });
90
- let refreshedConn = conn;
91
- while (refreshedConn.installationState.stage !== "COMPLETE") {
92
- refreshedConn = await promptAppInstall(conn);
93
- }
94
- existingConns.push(refreshedConn);
59
+ let repoRemoteUri;
60
+ let connection;
61
+ do {
62
+ if (repoRemoteUri === ADD_CONN_CHOICE) {
63
+ existingConns.push(await createFullyInstalledConnection(projectId, location, generateConnectionId(), oauthConn));
95
64
  }
96
65
  const selection = await promptRepositoryUri(projectId, existingConns);
97
- remoteUri = selection.remoteUri;
66
+ repoRemoteUri = selection.remoteUri;
98
67
  connection = selection.connection;
99
- }
68
+ } while (repoRemoteUri === ADD_CONN_CHOICE);
100
69
  const { id: connectionId } = parseConnectionName(connection.name);
101
70
  await getOrCreateConnection(projectId, location, connectionId, {
102
71
  authorizerCredential: connection.githubConfig?.authorizerCredential,
103
72
  appInstallationId: connection.githubConfig?.appInstallationId,
104
73
  });
105
- const repo = await getOrCreateRepository(projectId, location, connectionId, remoteUri);
74
+ const repo = await getOrCreateRepository(projectId, location, connectionId, repoRemoteUri);
106
75
  utils.logSuccess(`Successfully linked GitHub repository at remote URI`);
107
- utils.logSuccess(`\t${remoteUri}`);
76
+ utils.logSuccess(`\t${repoRemoteUri}`);
108
77
  return repo;
109
78
  }
110
79
  exports.linkGitHubRepository = linkGitHubRepository;
80
+ async function createFullyInstalledConnection(projectId, location, connectionId, oauthConn) {
81
+ let conn = await createConnection(projectId, location, connectionId, {
82
+ authorizerCredential: oauthConn.githubConfig?.authorizerCredential,
83
+ });
84
+ while (conn.installationState.stage !== "COMPLETE") {
85
+ utils.logBullet("Install the Cloud Build GitHub app to enable access to GitHub repositories");
86
+ const targetUri = conn.installationState.actionUri.replace("install_v2", "direct_install_v2");
87
+ utils.logBullet(targetUri);
88
+ await utils.openInBrowser(targetUri);
89
+ await (0, prompt_1.promptOnce)({
90
+ type: "input",
91
+ message: "Press Enter once you have installed or configured the Cloud Build GitHub app to access your GitHub repo.",
92
+ });
93
+ conn = await gcb.getConnection(projectId, location, connectionId);
94
+ }
95
+ return conn;
96
+ }
97
+ async function getOrCreateOauthConnection(projectId, location) {
98
+ let conn;
99
+ try {
100
+ conn = await gcb.getConnection(projectId, location, APPHOSTING_OAUTH_CONN_NAME);
101
+ }
102
+ catch (err) {
103
+ if (err.status === 404) {
104
+ await ensureSecretManagerAdminGrant(projectId);
105
+ conn = await createConnection(projectId, location, APPHOSTING_OAUTH_CONN_NAME);
106
+ }
107
+ else {
108
+ throw err;
109
+ }
110
+ }
111
+ while (conn.installationState.stage === "PENDING_USER_OAUTH") {
112
+ utils.logBullet("You must authorize the Cloud Build GitHub app.");
113
+ utils.logBullet("Sign in to GitHub and authorize Cloud Build GitHub app:");
114
+ const { url, cleanup } = await utils.openInBrowserPopup(conn.installationState.actionUri, "Authorize the GitHub app");
115
+ utils.logBullet(`\t${url}`);
116
+ await (0, prompt_1.promptOnce)({
117
+ type: "input",
118
+ message: "Press Enter once you have authorized the app",
119
+ });
120
+ cleanup();
121
+ const { projectId, location, id } = parseConnectionName(conn.name);
122
+ conn = await gcb.getConnection(projectId, location, id);
123
+ }
124
+ return conn;
125
+ }
126
+ exports.getOrCreateOauthConnection = getOrCreateOauthConnection;
111
127
  async function promptRepositoryUri(projectId, connections) {
112
128
  const { repos, remoteUriToConnection } = await fetchAllRepositories(projectId, connections);
113
- const searchRepos = (repos) => async (_, input = "") => {
114
- return [
115
- new inquirer.Separator(),
116
- {
117
- name: "Missing a repo? Select this option to configure your installation's access settings",
118
- value: ADD_REPO_CHOICE,
119
- },
120
- {
121
- name: "Missing an account or org? Select this option to create a new connection",
122
- value: ADD_CONN_CHOICE,
123
- },
124
- new inquirer.Separator(),
125
- ...fuzzy
126
- .filter(input, repos, {
127
- extract: (repo) => extractRepoSlugFromUri(repo.remoteUri) || "",
128
- })
129
- .map((result) => {
130
- return {
131
- name: extractRepoSlugFromUri(result.original.remoteUri) || "",
132
- value: result.original.remoteUri,
133
- };
134
- }),
135
- ];
136
- };
137
129
  const remoteUri = await (0, prompt_1.promptOnce)({
138
130
  type: "autocomplete",
139
131
  name: "remoteUri",
140
132
  message: "Which of the following repositories would you like to deploy?",
141
- source: searchRepos(repos),
133
+ source: (_, input = "") => {
134
+ return new Promise((resolve) => resolve([
135
+ new inquirer.Separator(),
136
+ {
137
+ name: "Missing a repo? Select this option to configure your GitHub connection settings",
138
+ value: ADD_CONN_CHOICE,
139
+ },
140
+ new inquirer.Separator(),
141
+ ...fuzzy
142
+ .filter(input, repos, {
143
+ extract: (repo) => extractRepoSlugFromUri(repo.remoteUri) || "",
144
+ })
145
+ .map((result) => {
146
+ return {
147
+ name: extractRepoSlugFromUri(result.original.remoteUri) || "",
148
+ value: result.original.remoteUri,
149
+ };
150
+ }),
151
+ ]));
152
+ },
142
153
  });
143
154
  return { remoteUri, connection: remoteUriToConnection[remoteUri] };
144
155
  }
145
- async function promptSecretManagerAdminGrant(projectId) {
156
+ async function ensureSecretManagerAdminGrant(projectId) {
146
157
  const projectNumber = await (0, getProjectNumber_1.getProjectNumber)({ projectId });
147
158
  const cbsaEmail = gcb.serviceAgentEmail(projectNumber);
148
159
  const alreadyGranted = await rm.serviceAccountHasRoles(projectId, cbsaEmail, ["roles/secretmanager.admin"], true);
149
160
  if (alreadyGranted) {
150
- return true;
161
+ return;
151
162
  }
152
163
  utils.logBullet("To create a new GitHub connection, Secret Manager Admin role (roles/secretmanager.admin) is required on the Cloud Build Service Agent.");
153
164
  const grant = await (0, prompt_1.promptOnce)({
@@ -160,36 +171,10 @@ async function promptSecretManagerAdminGrant(projectId) {
160
171
  `\tgcloud projects add-iam-policy-binding ${projectId} \\\n` +
161
172
  `\t --member="serviceAccount:${cbsaEmail} \\\n` +
162
173
  `\t --role="roles/secretmanager.admin\n`);
163
- return false;
174
+ throw new error_1.FirebaseError("Insufficient IAM permissions to create a new connection to GitHub");
164
175
  }
165
176
  await rm.addServiceAccountToRoles(projectId, cbsaEmail, ["roles/secretmanager.admin"], true);
166
177
  utils.logSuccess("Successfully granted the required role to the Cloud Build Service Agent!");
167
- return true;
168
- }
169
- async function promptConnectionAuth(conn) {
170
- utils.logBullet("You must authorize the Cloud Build GitHub app.");
171
- utils.logBullet("Sign in to GitHub and authorize Cloud Build GitHub app:");
172
- const { url, cleanup } = await utils.openInBrowserPopup(conn.installationState.actionUri, "Authorize the GitHub app");
173
- utils.logBullet(`\t${url}`);
174
- await (0, prompt_1.promptOnce)({
175
- type: "input",
176
- message: "Press Enter once you have authorized the app",
177
- });
178
- cleanup();
179
- const { projectId, location, id } = parseConnectionName(conn.name);
180
- return await gcb.getConnection(projectId, location, id);
181
- }
182
- async function promptAppInstall(conn) {
183
- utils.logBullet("Install the Cloud Build GitHub app to enable access to GitHub repositories");
184
- const targetUri = conn.installationState.actionUri.replace("install_v2", "direct_install_v2");
185
- utils.logBullet(targetUri);
186
- await utils.openInBrowser(targetUri);
187
- await (0, prompt_1.promptOnce)({
188
- type: "input",
189
- message: "Press Enter once you have installed or configured the Cloud Build GitHub app to access your GitHub repo.",
190
- });
191
- const { projectId, location, id } = parseConnectionName(conn.name);
192
- return await gcb.getConnection(projectId, location, id);
193
178
  }
194
179
  async function createConnection(projectId, location, connectionId, githubConfig) {
195
180
  const op = await gcb.createConnection(projectId, location, connectionId, githubConfig);
@@ -71,7 +71,7 @@ async function doSetup(setup, config) {
71
71
  setup.config = setup.config || {};
72
72
  let instanceDetails;
73
73
  if (setup.projectId) {
74
- await (0, ensureApiEnabled_1.ensure)(setup.projectId, api_1.rtdbManagementOrigin, "database", false);
74
+ await (0, ensureApiEnabled_1.ensure)(setup.projectId, (0, api_1.rtdbManagementOrigin)(), "database", false);
75
75
  logger_1.logger.info();
76
76
  setup.instance =
77
77
  setup.instance || (await (0, getDefaultDatabaseInstance_1.getDefaultDatabaseInstance)({ project: setup.projectId }));
@@ -9,7 +9,7 @@ async function doSetup(setup, config, options) {
9
9
  const projectId = setup?.rcfile?.projects?.default;
10
10
  if (projectId) {
11
11
  await (0, requirePermissions_1.requirePermissions)({ ...options, project: projectId });
12
- await Promise.all([(0, ensureApiEnabled_1.ensure)(projectId, api_1.extensionsOrigin, "unused", true)]);
12
+ await Promise.all([(0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.extensionsOrigin)(), "unused", true)]);
13
13
  }
14
14
  return manifest.writeEmptyManifest(config, options);
15
15
  }
@@ -15,8 +15,8 @@ async function doSetup(setup, config, options) {
15
15
  if (projectId) {
16
16
  await (0, requirePermissions_1.requirePermissions)({ ...options, project: projectId });
17
17
  await Promise.all([
18
- (0, ensureApiEnabled_1.ensure)(projectId, api_1.functionsOrigin, "unused", true),
19
- (0, ensureApiEnabled_1.ensure)(projectId, api_1.runtimeconfigOrigin, "unused", true),
18
+ (0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.functionsOrigin)(), "unused", true),
19
+ (0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.runtimeconfigOrigin)(), "unused", true),
20
20
  ]);
21
21
  }
22
22
  setup.functions = {};
@@ -28,7 +28,7 @@ const YML_MERGE_FILENAME = "firebase-hosting-merge.yml";
28
28
  const CHECKOUT_GITHUB_ACTION_NAME = "actions/checkout@v4";
29
29
  const HOSTING_GITHUB_ACTION_NAME = "FirebaseExtended/action-hosting-deploy@v0";
30
30
  const SERVICE_ACCOUNT_MAX_KEY_NUMBER = 10;
31
- const githubApiClient = new apiv2_1.Client({ urlPrefix: api_1.githubApiOrigin, auth: false });
31
+ const githubApiClient = new apiv2_1.Client({ urlPrefix: (0, api_1.githubApiOrigin)(), auth: false });
32
32
  async function initGitHub(setup) {
33
33
  if (!setup.projectId) {
34
34
  return (0, utils_1.reject)("Could not determine Project ID, can't set up GitHub workflow.", { exit: 1 });
@@ -109,7 +109,7 @@ async function initGitHub(setup) {
109
109
  }
110
110
  logger_1.logger.info();
111
111
  (0, utils_1.logLabeledBullet)("Action required", `Visit this URL to revoke authorization for the Firebase CLI GitHub OAuth App:`);
112
- logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${api_1.githubClientId}`)));
112
+ logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${(0, api_1.githubClientId)()}`)));
113
113
  (0, utils_1.logLabeledBullet)("Action required", `Push any new workflow file(s) to your repo`);
114
114
  }
115
115
  exports.initGitHub = initGitHub;
@@ -260,7 +260,7 @@ async function promptForRepo(options, ghAccessToken) {
260
260
  (0, utils_1.logWarning)("The provided authorization cannot be used with this repository. If this repository is in an organization, did you remember to grant access?", "error");
261
261
  logger_1.logger.info();
262
262
  (0, utils_1.logLabeledBullet)("Action required", `Visit this URL to ensure access has been granted to the appropriate organization(s) for the Firebase CLI GitHub OAuth App:`);
263
- logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${api_1.githubClientId}`)));
263
+ logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.underline)(`https://github.com/settings/connections/applications/${(0, api_1.githubClientId)()}`)));
264
264
  logger_1.logger.info();
265
265
  }
266
266
  return false;
@@ -378,6 +378,7 @@ async function createServiceAccountAndKey(options, repo, accountId) {
378
378
  }
379
379
  const requiredRoles = [
380
380
  resourceManager_1.firebaseRoles.authAdmin,
381
+ resourceManager_1.firebaseRoles.serviceUsageConsumer,
381
382
  resourceManager_1.firebaseRoles.apiKeysViewer,
382
383
  resourceManager_1.firebaseRoles.hostingAdmin,
383
384
  resourceManager_1.firebaseRoles.runViewer,
@@ -40,7 +40,7 @@ function getAppPlatform(platform) {
40
40
  }
41
41
  }
42
42
  exports.getAppPlatform = getAppPlatform;
43
- const apiClient = new apiv2_1.Client({ urlPrefix: api_1.firebaseApiOrigin, apiVersion: "v1beta1" });
43
+ const apiClient = new apiv2_1.Client({ urlPrefix: (0, api_1.firebaseApiOrigin)(), apiVersion: "v1beta1" });
44
44
  async function createIosApp(projectId, options) {
45
45
  try {
46
46
  const response = await apiClient.request({
@@ -51,7 +51,7 @@ async function createIosApp(projectId, options) {
51
51
  });
52
52
  const appData = await (0, operation_poller_1.pollOperation)({
53
53
  pollerName: "Create iOS app Poller",
54
- apiOrigin: api_1.firebaseApiOrigin,
54
+ apiOrigin: (0, api_1.firebaseApiOrigin)(),
55
55
  apiVersion: "v1beta1",
56
56
  operationResourceName: response.body.name,
57
57
  });
@@ -73,7 +73,7 @@ async function createAndroidApp(projectId, options) {
73
73
  });
74
74
  const appData = await (0, operation_poller_1.pollOperation)({
75
75
  pollerName: "Create Android app Poller",
76
- apiOrigin: api_1.firebaseApiOrigin,
76
+ apiOrigin: (0, api_1.firebaseApiOrigin)(),
77
77
  apiVersion: "v1beta1",
78
78
  operationResourceName: response.body.name,
79
79
  });
@@ -98,7 +98,7 @@ async function createWebApp(projectId, options) {
98
98
  });
99
99
  const appData = await (0, operation_poller_1.pollOperation)({
100
100
  pollerName: "Create Web app Poller",
101
- apiOrigin: api_1.firebaseApiOrigin,
101
+ apiOrigin: (0, api_1.firebaseApiOrigin)(),
102
102
  apiVersion: "v1beta1",
103
103
  operationResourceName: response.body.name,
104
104
  });
@@ -31,7 +31,7 @@ var DatabaseLocation;
31
31
  DatabaseLocation["ASIA_SOUTHEAST1"] = "asia-southeast1";
32
32
  DatabaseLocation["ANY"] = "-";
33
33
  })(DatabaseLocation = exports.DatabaseLocation || (exports.DatabaseLocation = {}));
34
- const apiClient = new apiv2_1.Client({ urlPrefix: api_1.rtdbManagementOrigin, apiVersion: exports.MGMT_API_VERSION });
34
+ const apiClient = new apiv2_1.Client({ urlPrefix: (0, api_1.rtdbManagementOrigin)(), apiVersion: exports.MGMT_API_VERSION });
35
35
  async function populateInstanceDetails(options) {
36
36
  options.instanceDetails = await getDatabaseInstanceDetails(options.project, options.instance);
37
37
  return Promise.resolve();
@@ -35,7 +35,7 @@ exports.PROJECTS_CREATE_QUESTIONS = [
35
35
  },
36
36
  ];
37
37
  const firebaseAPIClient = new apiv2_1.Client({
38
- urlPrefix: api.firebaseApiOrigin,
38
+ urlPrefix: api.firebaseApiOrigin(),
39
39
  auth: true,
40
40
  apiVersion: "v1beta1",
41
41
  });
@@ -171,7 +171,7 @@ async function promptAvailableProjectId() {
171
171
  exports.promptAvailableProjectId = promptAvailableProjectId;
172
172
  async function createCloudProject(projectId, options) {
173
173
  try {
174
- const client = new apiv2_1.Client({ urlPrefix: api.resourceManagerOrigin, apiVersion: "v1" });
174
+ const client = new apiv2_1.Client({ urlPrefix: api.resourceManagerOrigin(), apiVersion: "v1" });
175
175
  const data = {
176
176
  projectId,
177
177
  name: options.displayName || projectId,
@@ -185,7 +185,7 @@ async function createCloudProject(projectId, options) {
185
185
  });
186
186
  const projectInfo = await (0, operation_poller_1.pollOperation)({
187
187
  pollerName: "Project Creation Poller",
188
- apiOrigin: api.resourceManagerOrigin,
188
+ apiOrigin: api.resourceManagerOrigin(),
189
189
  apiVersion: "v1",
190
190
  operationResourceName: response.body.name,
191
191
  });
@@ -216,7 +216,7 @@ async function addFirebaseToCloudProject(projectId) {
216
216
  });
217
217
  const projectInfo = await (0, operation_poller_1.pollOperation)({
218
218
  pollerName: "Add Firebase Poller",
219
- apiOrigin: api.firebaseApiOrigin,
219
+ apiOrigin: api.firebaseApiOrigin(),
220
220
  apiVersion: "v1beta1",
221
221
  operationResourceName: response.body.name,
222
222
  });
@@ -8,7 +8,7 @@ const error_1 = require("../error");
8
8
  const TIMEOUT = 30000;
9
9
  const MAX_DISPLAY_ITEMS = 50;
10
10
  const apiClient = new apiv2_1.Client({
11
- urlPrefix: api_1.remoteConfigApiOrigin,
11
+ urlPrefix: (0, api_1.remoteConfigApiOrigin)(),
12
12
  apiVersion: "v1",
13
13
  });
14
14
  function parseTemplateForTable(templateItems) {
@@ -4,7 +4,7 @@ exports.rollbackTemplate = void 0;
4
4
  const api_1 = require("../api");
5
5
  const apiv2_1 = require("../apiv2");
6
6
  const apiClient = new apiv2_1.Client({
7
- urlPrefix: api_1.remoteConfigApiOrigin,
7
+ urlPrefix: (0, api_1.remoteConfigApiOrigin)(),
8
8
  apiVersion: "v1",
9
9
  });
10
10
  const TIMEOUT = 30000;
@@ -6,7 +6,7 @@ const apiv2_1 = require("../apiv2");
6
6
  const error_1 = require("../error");
7
7
  const logger_1 = require("../logger");
8
8
  const apiClient = new apiv2_1.Client({
9
- urlPrefix: api_1.remoteConfigApiOrigin,
9
+ urlPrefix: (0, api_1.remoteConfigApiOrigin)(),
10
10
  apiVersion: "v1",
11
11
  });
12
12
  const TIMEOUT = 30000;
@@ -8,6 +8,7 @@ const auth_1 = require("../auth");
8
8
  const projectConfig = require("../functions/projectConfig");
9
9
  const utils = require("../utils");
10
10
  const registry_1 = require("../emulator/registry");
11
+ const commandUtils_1 = require("../emulator/commandUtils");
11
12
  class FunctionsServer {
12
13
  assertServer() {
13
14
  if (!this.emulator || !this.backends) {
@@ -38,6 +39,7 @@ class FunctionsServer {
38
39
  projectAlias: options.projectAlias,
39
40
  account,
40
41
  ...partialArgs,
42
+ debugPort: (0, commandUtils_1.parseInspectionPort)(options),
41
43
  };
42
44
  if (options.host) {
43
45
  utils.assertIsStringOrUndefined(options.host);
package/lib/shortenUrl.js CHANGED
@@ -6,13 +6,13 @@ const apiv2_1 = require("./apiv2");
6
6
  const api_1 = require("./api");
7
7
  const DYNAMIC_LINKS_PREFIX = "https://firebase.tools/l";
8
8
  const apiClient = new apiv2_1.Client({
9
- urlPrefix: api_1.dynamicLinksOrigin,
9
+ urlPrefix: (0, api_1.dynamicLinksOrigin)(),
10
10
  auth: false,
11
11
  apiVersion: "v1",
12
12
  });
13
13
  async function shortenUrl(url, guessable = false) {
14
14
  try {
15
- const response = await apiClient.post(`shortLinks?key=${api_1.dynamicLinksKey}`, {
15
+ const response = await apiClient.post(`shortLinks?key=${(0, api_1.dynamicLinksKey)()}`, {
16
16
  dynamicLinkInfo: {
17
17
  link: url,
18
18
  domainUriPrefix: DYNAMIC_LINKS_PREFIX,
package/lib/utils.js CHANGED
@@ -27,7 +27,7 @@ const THIRTY_DAYS_IN_MILLISECONDS = 30 * 24 * 60 * 60 * 1000;
27
27
  exports.envOverrides = [];
28
28
  function consoleUrl(project, path) {
29
29
  const api = require("./api");
30
- return `${api.consoleOrigin}/project/${project}${path}`;
30
+ return `${api.consoleOrigin()}/project/${project}${path}`;
31
31
  }
32
32
  exports.consoleUrl = consoleUrl;
33
33
  function getInheritedOption(options, key) {