firebase-tools-with-isolate 13.2.1-0 → 13.4.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 (59) hide show
  1. package/lib/api.js +2 -1
  2. package/lib/auth.js +11 -2
  3. package/lib/commands/apphosting-backends-create.js +6 -3
  4. package/lib/commands/apphosting-backends-delete.js +6 -43
  5. package/lib/commands/apphosting-backends-get.js +4 -34
  6. package/lib/commands/apphosting-backends-list.js +15 -8
  7. package/lib/commands/apphosting-builds-create.js +4 -4
  8. package/lib/commands/apphosting-builds-get.js +2 -2
  9. package/lib/commands/apphosting-rollouts-create.js +3 -3
  10. package/lib/commands/apphosting-rollouts-list.js +2 -2
  11. package/lib/commands/firestore-backups-delete.js +44 -0
  12. package/lib/commands/firestore-backups-get.js +25 -0
  13. package/lib/commands/firestore-backups-list.js +33 -0
  14. package/lib/commands/firestore-backups-schedules-create.js +67 -0
  15. package/lib/commands/firestore-backups-schedules-delete.js +46 -0
  16. package/lib/commands/firestore-backups-schedules-list.js +27 -0
  17. package/lib/commands/firestore-backups-schedules-update.js +33 -0
  18. package/lib/commands/firestore-databases-create.js +4 -2
  19. package/lib/commands/firestore-databases-delete.js +4 -2
  20. package/lib/commands/firestore-databases-get.js +3 -1
  21. package/lib/commands/firestore-databases-list.js +3 -1
  22. package/lib/commands/firestore-databases-restore.js +42 -0
  23. package/lib/commands/firestore-databases-update.js +4 -2
  24. package/lib/commands/firestore-indexes-list.js +5 -3
  25. package/lib/commands/firestore-locations.js +3 -1
  26. package/lib/commands/index.js +11 -1
  27. package/lib/commands/init.js +3 -3
  28. package/lib/deploy/extensions/v2FunctionHelper.js +2 -1
  29. package/lib/deploy/functions/ensure.js +2 -2
  30. package/lib/deploy/functions/prepare.js +5 -9
  31. package/lib/deploy/functions/runtimes/index.js +2 -0
  32. package/lib/deploy/functions/runtimes/python/index.js +4 -1
  33. package/lib/deploy/functions/services/firestore.js +1 -1
  34. package/lib/emulator/downloadableEmulators.js +3 -3
  35. package/lib/emulator/storage/rules/runtime.js +1 -1
  36. package/lib/ensureApiEnabled.js +8 -6
  37. package/lib/experiments.js +2 -2
  38. package/lib/extensions/extensionsHelper.js +2 -2
  39. package/lib/extensions/secretsUtils.js +2 -1
  40. package/lib/firestore/api-sort.js +23 -1
  41. package/lib/firestore/api-types.js +6 -1
  42. package/lib/firestore/api.js +18 -115
  43. package/lib/firestore/backupUtils.js +30 -0
  44. package/lib/firestore/delete.js +3 -3
  45. package/lib/firestore/pretty-print.js +184 -0
  46. package/lib/functions/secrets.js +1 -1
  47. package/lib/gcp/apphosting.js +4 -5
  48. package/lib/gcp/auth.js +5 -2
  49. package/lib/gcp/cloudbuild.js +7 -2
  50. package/lib/gcp/firestore.js +89 -6
  51. package/lib/gcp/storage.js +1 -1
  52. package/lib/init/features/apphosting/index.js +144 -83
  53. package/lib/init/features/apphosting/repo.js +80 -32
  54. package/lib/init/features/database.js +2 -1
  55. package/lib/init/features/extensions/index.js +2 -1
  56. package/lib/init/features/functions/index.js +3 -2
  57. package/lib/init/features/hosting/github.js +5 -0
  58. package/lib/prompt.js +1 -0
  59. package/package.json +10 -5
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.onboardRollout = exports.createBackend = exports.onboardBackend = exports.doSetup = void 0;
3
+ exports.orchestrateRollout = exports.setDefaultTrafficPolicy = exports.createBackend = exports.doSetup = void 0;
4
4
  const clc = require("colorette");
5
5
  const repo = require("./repo");
6
6
  const poller = require("../../../operation-poller");
@@ -8,76 +8,60 @@ const apphosting = require("../../../gcp/apphosting");
8
8
  const utils_1 = require("../../../utils");
9
9
  const api_1 = require("../../../api");
10
10
  const apphosting_1 = require("../../../gcp/apphosting");
11
+ const resourceManager_1 = require("../../../gcp/resourceManager");
12
+ const iam_1 = require("../../../gcp/iam");
11
13
  const error_1 = require("../../../error");
12
14
  const prompt_1 = require("../../../prompt");
13
15
  const constants_1 = require("./constants");
14
16
  const ensureApiEnabled_1 = require("../../../ensureApiEnabled");
15
17
  const deploymentTool = require("../../../deploymentTool");
18
+ const DEFAULT_COMPUTE_SERVICE_ACCOUNT_NAME = "firebase-app-hosting-compute";
16
19
  const apphostingPollerOptions = {
17
20
  apiOrigin: api_1.apphostingOrigin,
18
21
  apiVersion: apphosting_1.API_VERSION,
19
22
  masterTimeout: 25 * 60 * 1000,
20
23
  maxBackoff: 10000,
21
24
  };
22
- async function doSetup(setup, projectId) {
25
+ async function doSetup(projectId, location, serviceAccount) {
23
26
  await Promise.all([
24
- (0, ensureApiEnabled_1.ensure)(projectId, "cloudbuild.googleapis.com", "apphosting", true),
25
- (0, ensureApiEnabled_1.ensure)(projectId, "secretmanager.googleapis.com", "apphosting", true),
26
- (0, ensureApiEnabled_1.ensure)(projectId, "run.googleapis.com", "apphosting", true),
27
- (0, ensureApiEnabled_1.ensure)(projectId, "artifactregistry.googleapis.com", "apphosting", true),
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),
28
31
  ]);
29
32
  const allowedLocations = (await apphosting.listLocations(projectId)).map((loc) => loc.locationId);
30
- if (setup.location) {
31
- if (!allowedLocations.includes(setup.location)) {
32
- throw new error_1.FirebaseError(`Invalid location ${setup.location}. Valid choices are ${allowedLocations.join(", ")}`);
33
+ if (location) {
34
+ if (!allowedLocations.includes(location)) {
35
+ throw new error_1.FirebaseError(`Invalid location ${location}. Valid choices are ${allowedLocations.join(", ")}`);
33
36
  }
34
37
  }
35
38
  (0, utils_1.logBullet)("First we need a few details to create your backend.");
36
- const location = setup.location || (await promptLocation(projectId, allowedLocations));
39
+ location =
40
+ location ||
41
+ (await (0, prompt_1.promptOnce)({
42
+ name: "region",
43
+ type: "list",
44
+ default: constants_1.DEFAULT_REGION,
45
+ message: "Please select a region " +
46
+ `(${clc.yellow("info")}: Your region determines where your backend is located):\n`,
47
+ choices: allowedLocations.map((loc) => ({ value: loc })),
48
+ }));
37
49
  (0, utils_1.logSuccess)(`Region set to ${location}.\n`);
38
- let backendId;
39
- while (true) {
40
- backendId = await (0, prompt_1.promptOnce)({
41
- name: "backendId",
42
- type: "input",
43
- default: "my-web-app",
44
- message: "Create a name for your backend [1-30 characters]",
45
- });
46
- try {
47
- await apphosting.getBackend(projectId, location, backendId);
48
- }
49
- catch (err) {
50
- if (err.status === 404) {
51
- break;
52
- }
53
- throw new error_1.FirebaseError(`Failed to check if backend with id ${backendId} already exists in ${location}`, { original: err });
54
- }
55
- (0, utils_1.logWarning)(`Backend with id ${backendId} already exists in ${location}`);
56
- }
57
- const backend = await onboardBackend(projectId, location, backendId);
50
+ const backendId = await promptNewBackendId(projectId, location, {
51
+ name: "backendId",
52
+ type: "input",
53
+ default: "my-web-app",
54
+ message: "Create a name for your backend [1-30 characters]",
55
+ });
56
+ const cloudBuildConnRepo = await repo.linkGitHubRepository(projectId, location);
57
+ const backend = await createBackend(projectId, location, backendId, cloudBuildConnRepo, serviceAccount);
58
58
  const branch = await (0, prompt_1.promptOnce)({
59
59
  name: "branch",
60
60
  type: "input",
61
61
  default: "main",
62
62
  message: "Pick a branch for continuous deployment",
63
63
  });
64
- const traffic = {
65
- rolloutPolicy: {
66
- codebaseBranch: branch,
67
- stages: [
68
- {
69
- progression: "IMMEDIATE",
70
- targetPercent: 100,
71
- },
72
- ],
73
- },
74
- };
75
- const op = await apphosting.updateTraffic(projectId, location, backendId, traffic);
76
- await poller.pollOperation({
77
- ...apphostingPollerOptions,
78
- pollerName: `updateTraffic-${projectId}-${location}-${backendId}`,
79
- operationResourceName: op.name,
80
- });
64
+ await setDefaultTrafficPolicy(projectId, location, backendId, branch);
81
65
  const confirmRollout = await (0, prompt_1.promptOnce)({
82
66
  type: "confirm",
83
67
  name: "rollout",
@@ -89,68 +73,138 @@ async function doSetup(setup, projectId) {
89
73
  (0, utils_1.logSuccess)(`Your site will be deployed at:\n\thttps://${backend.uri}`);
90
74
  return;
91
75
  }
92
- const { build } = await onboardRollout(projectId, location, backendId, {
76
+ await orchestrateRollout(projectId, location, backendId, {
93
77
  source: {
94
78
  codebase: {
95
79
  branch,
96
80
  },
97
81
  },
98
82
  });
99
- if (build.state !== "READY") {
100
- if (!build.buildLogsUri) {
101
- throw new error_1.FirebaseError("Failed to build your app, but failed to get build logs as well. " +
102
- "This is an internal error and should be reported");
103
- }
104
- throw new error_1.FirebaseError(`Failed to build your app. Please inspect the build logs at ${build.buildLogsUri}.`, { children: [build.error] });
105
- }
106
83
  (0, utils_1.logSuccess)(`Successfully created backend:\n\t${backend.name}`);
107
84
  (0, utils_1.logSuccess)(`Your site is now deployed at:\n\thttps://${backend.uri}`);
108
- (0, utils_1.logSuccess)(`View the rollout status by running:\n\tfirebase apphosting:backends:get ${backendId} --project ${projectId}`);
109
85
  }
110
86
  exports.doSetup = doSetup;
111
- async function promptLocation(projectId, locations) {
112
- return (await (0, prompt_1.promptOnce)({
113
- name: "region",
114
- type: "list",
115
- default: constants_1.DEFAULT_REGION,
116
- message: "Please select a region " +
117
- `(${clc.yellow("info")}: Your region determines where your backend is located):\n`,
118
- choices: locations.map((loc) => ({ value: loc })),
119
- }));
87
+ async function promptNewBackendId(projectId, location, prompt) {
88
+ while (true) {
89
+ const backendId = await (0, prompt_1.promptOnce)(prompt);
90
+ try {
91
+ await apphosting.getBackend(projectId, location, backendId);
92
+ }
93
+ catch (err) {
94
+ if (err.status === 404) {
95
+ return backendId;
96
+ }
97
+ throw new error_1.FirebaseError(`Failed to check if backend with id ${backendId} already exists in ${location}`, { original: err });
98
+ }
99
+ (0, utils_1.logWarning)(`Backend with id ${backendId} already exists in ${location}`);
100
+ }
120
101
  }
121
- function toBackend(cloudBuildConnRepo) {
122
- return {
102
+ function defaultComputeServiceAccountEmail(projectId) {
103
+ return `${DEFAULT_COMPUTE_SERVICE_ACCOUNT_NAME}@${projectId}.iam.gserviceaccount.com`;
104
+ }
105
+ async function createBackend(projectId, location, backendId, repository, serviceAccount) {
106
+ const defaultServiceAccount = defaultComputeServiceAccountEmail(projectId);
107
+ const backendReqBody = {
123
108
  servingLocality: "GLOBAL_ACCESS",
124
109
  codebase: {
125
- repository: `${cloudBuildConnRepo.name}`,
110
+ repository: `${repository.name}`,
126
111
  rootDirectory: "/",
127
112
  },
128
113
  labels: deploymentTool.labels(),
114
+ computeServiceAccount: serviceAccount || defaultServiceAccount,
129
115
  };
116
+ delete backendReqBody.computeServiceAccount;
117
+ async function createBackendAndPoll() {
118
+ const op = await apphosting.createBackend(projectId, location, backendReqBody, backendId);
119
+ return await poller.pollOperation({
120
+ ...apphostingPollerOptions,
121
+ pollerName: `create-${projectId}-${location}-${backendId}`,
122
+ operationResourceName: op.name,
123
+ });
124
+ }
125
+ try {
126
+ return await createBackendAndPoll();
127
+ }
128
+ catch (err) {
129
+ if (err.status === 403) {
130
+ if (err.message.includes(defaultServiceAccount)) {
131
+ await provisionDefaultComputeServiceAccount(projectId);
132
+ return await createBackendAndPoll();
133
+ }
134
+ else if (serviceAccount && err.message.includes(serviceAccount)) {
135
+ throw new error_1.FirebaseError(`Failed to create backend due to missing delegation permissions for ${serviceAccount}. Make sure you have the iam.serviceAccounts.actAs permission.`, { children: [err] });
136
+ }
137
+ }
138
+ throw err;
139
+ }
130
140
  }
131
- async function onboardBackend(projectId, location, backendId) {
132
- const cloudBuildConnRepo = await repo.linkGitHubRepository(projectId, location);
133
- const backendDetails = toBackend(cloudBuildConnRepo);
134
- return await createBackend(projectId, location, backendDetails, backendId);
141
+ exports.createBackend = createBackend;
142
+ async function provisionDefaultComputeServiceAccount(projectId) {
143
+ try {
144
+ await (0, iam_1.createServiceAccount)(projectId, DEFAULT_COMPUTE_SERVICE_ACCOUNT_NAME, "Firebase App Hosting compute service account", "Default service account used to run builds and deploys for Firebase App Hosting");
145
+ }
146
+ catch (err) {
147
+ if (err.status !== 409) {
148
+ throw err;
149
+ }
150
+ }
151
+ await (0, resourceManager_1.addServiceAccountToRoles)(projectId, defaultComputeServiceAccountEmail(projectId), [
152
+ "roles/firebaseapphosting.viewer",
153
+ "roles/artifactregistry.createOnPushWriter",
154
+ "roles/logging.logWriter",
155
+ "roles/storage.objectAdmin",
156
+ "roles/firebase.sdkAdminServiceAgent",
157
+ ], true);
135
158
  }
136
- exports.onboardBackend = onboardBackend;
137
- async function createBackend(projectId, location, backendReqBoby, backendId) {
138
- const op = await apphosting.createBackend(projectId, location, backendReqBoby, backendId);
139
- const backend = await poller.pollOperation({
159
+ async function setDefaultTrafficPolicy(projectId, location, backendId, codebaseBranch) {
160
+ const traffic = {
161
+ rolloutPolicy: {
162
+ codebaseBranch: codebaseBranch,
163
+ stages: [
164
+ {
165
+ progression: "IMMEDIATE",
166
+ targetPercent: 100,
167
+ },
168
+ ],
169
+ },
170
+ };
171
+ const op = await apphosting.updateTraffic(projectId, location, backendId, traffic);
172
+ await poller.pollOperation({
140
173
  ...apphostingPollerOptions,
141
- pollerName: `create-${projectId}-${location}-${backendId}`,
174
+ pollerName: `updateTraffic-${projectId}-${location}-${backendId}`,
142
175
  operationResourceName: op.name,
143
176
  });
144
- return backend;
145
177
  }
146
- exports.createBackend = createBackend;
147
- async function onboardRollout(projectId, location, backendId, buildInput) {
178
+ exports.setDefaultTrafficPolicy = setDefaultTrafficPolicy;
179
+ async function orchestrateRollout(projectId, location, backendId, buildInput) {
148
180
  (0, utils_1.logBullet)("Starting a new rollout... this may take a few minutes.");
149
181
  const buildId = await apphosting.getNextRolloutId(projectId, location, backendId, 1);
150
182
  const buildOp = await apphosting.createBuild(projectId, location, backendId, buildId, buildInput);
151
- const rolloutOp = await apphosting.createRollout(projectId, location, backendId, buildId, {
183
+ const rolloutBody = {
152
184
  build: `projects/${projectId}/locations/${location}/backends/${backendId}/builds/${buildId}`,
153
- });
185
+ };
186
+ let tries = 0;
187
+ let done = false;
188
+ while (!done) {
189
+ tries++;
190
+ try {
191
+ const validateOnly = true;
192
+ await apphosting.createRollout(projectId, location, backendId, buildId, rolloutBody, validateOnly);
193
+ done = true;
194
+ }
195
+ catch (err) {
196
+ if (err instanceof error_1.FirebaseError && err.status === 400) {
197
+ if (tries >= 5) {
198
+ throw err;
199
+ }
200
+ await new Promise((resolve) => setTimeout(resolve, 1000));
201
+ }
202
+ else {
203
+ throw err;
204
+ }
205
+ }
206
+ }
207
+ const rolloutOp = await apphosting.createRollout(projectId, location, backendId, buildId, rolloutBody);
154
208
  const rolloutPoll = poller.pollOperation({
155
209
  ...apphostingPollerOptions,
156
210
  pollerName: `create-${projectId}-${location}-backend-${backendId}-rollout-${buildId}`,
@@ -163,6 +217,13 @@ async function onboardRollout(projectId, location, backendId, buildInput) {
163
217
  });
164
218
  const [rollout, build] = await Promise.all([rolloutPoll, buildPoll]);
165
219
  (0, utils_1.logSuccess)("Rollout completed.");
220
+ if (build.state !== "READY") {
221
+ if (!build.buildLogsUri) {
222
+ throw new error_1.FirebaseError("Failed to build your app, but failed to get build logs as well. " +
223
+ "This is an internal error and should be reported");
224
+ }
225
+ throw new error_1.FirebaseError(`Failed to build your app. Please inspect the build logs at ${build.buildLogsUri}.`, { children: [build.error] });
226
+ }
166
227
  return { rollout, build };
167
228
  }
168
- exports.onboardRollout = onboardRollout;
229
+ exports.orchestrateRollout = orchestrateRollout;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.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");
@@ -10,11 +10,13 @@ const api_1 = require("../../../api");
10
10
  const error_1 = require("../../../error");
11
11
  const prompt_1 = require("../../../prompt");
12
12
  const getProjectNumber_1 = require("../../../getProjectNumber");
13
+ const fuzzy = require("fuzzy");
14
+ const inquirer = require("inquirer");
13
15
  const APPHOSTING_CONN_PATTERN = /.+\/apphosting-github-conn-.+$/;
14
16
  const APPHOSTING_OAUTH_CONN_NAME = "apphosting-github-oauth";
15
17
  const CONNECTION_NAME_REGEX = /^projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/connections\/(?<id>[^\/]+)$/;
16
18
  function parseConnectionName(name) {
17
- const match = name.match(CONNECTION_NAME_REGEX);
19
+ const match = CONNECTION_NAME_REGEX.exec(name);
18
20
  if (!match || typeof match.groups === undefined) {
19
21
  return;
20
22
  }
@@ -46,18 +48,21 @@ function generateConnectionId() {
46
48
  const randomHash = Math.random().toString(36).slice(6);
47
49
  return `apphosting-github-conn-${randomHash}`;
48
50
  }
51
+ const ADD_REPO_CHOICE = "@ADD_REPO";
52
+ const ADD_CONN_CHOICE = "@ADD_CONN";
53
+ const CONFIGURE_REMOTE_URI_CHOICES = [ADD_REPO_CHOICE, ADD_CONN_CHOICE];
49
54
  async function linkGitHubRepository(projectId, location) {
50
55
  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
+ }
51
60
  const existingConns = await listAppHostingConnections(projectId);
52
61
  if (existingConns.length < 1) {
53
62
  const grantSuccess = await promptSecretManagerAdminGrant(projectId);
54
63
  if (!grantSuccess) {
55
64
  throw new error_1.FirebaseError("Insufficient IAM permissions to create a new connection to GitHub");
56
65
  }
57
- let oauthConn = await getOrCreateConnection(projectId, location, APPHOSTING_OAUTH_CONN_NAME);
58
- while (oauthConn.installationState.stage === "PENDING_USER_OAUTH") {
59
- oauthConn = await promptConnectionAuth(oauthConn);
60
- }
61
66
  const connectionId = generateConnectionId();
62
67
  const conn = await createConnection(projectId, location, connectionId, {
63
68
  authorizerCredential: oauthConn.githubConfig?.authorizerCredential,
@@ -69,12 +74,25 @@ async function linkGitHubRepository(projectId, location) {
69
74
  existingConns.push(refreshedConn);
70
75
  }
71
76
  let { remoteUri, connection } = await promptRepositoryUri(projectId, existingConns);
72
- while (remoteUri === "") {
73
- await utils.openInBrowser("https://github.com/apps/google-cloud-build/installations/new");
74
- await (0, prompt_1.promptOnce)({
75
- type: "input",
76
- message: "Press ENTER once you have finished configuring your installation's access settings.",
77
- });
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);
95
+ }
78
96
  const selection = await promptRepositoryUri(projectId, existingConns);
79
97
  remoteUri = selection.remoteUri;
80
98
  connection = selection.connection;
@@ -91,28 +109,36 @@ async function linkGitHubRepository(projectId, location) {
91
109
  }
92
110
  exports.linkGitHubRepository = linkGitHubRepository;
93
111
  async function promptRepositoryUri(projectId, connections) {
94
- const remoteUriToConnection = {};
95
- for (const conn of connections) {
96
- const { location, id } = parseConnectionName(conn.name);
97
- const resp = await gcb.fetchLinkableRepositories(projectId, location, id);
98
- if (resp.repositories && resp.repositories.length > 0) {
99
- for (const repo of resp.repositories) {
100
- remoteUriToConnection[repo.remoteUri] = conn;
101
- }
102
- }
103
- }
104
- const choices = Object.keys(remoteUriToConnection).map((remoteUri) => ({
105
- name: extractRepoSlugFromUri(remoteUri) || remoteUri,
106
- value: remoteUri,
107
- }));
108
- choices.push({
109
- name: "Missing a repo? Select this option to configure your installation's access settings",
110
- value: "",
111
- });
112
+ 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
+ };
112
137
  const remoteUri = await (0, prompt_1.promptOnce)({
113
- type: "list",
138
+ type: "autocomplete",
139
+ name: "remoteUri",
114
140
  message: "Which of the following repositories would you like to deploy?",
115
- choices,
141
+ source: searchRepos(repos),
116
142
  });
117
143
  return { remoteUri, connection: remoteUriToConnection[remoteUri] };
118
144
  }
@@ -223,3 +249,25 @@ async function listAppHostingConnections(projectId) {
223
249
  !conn.disabled);
224
250
  }
225
251
  exports.listAppHostingConnections = listAppHostingConnections;
252
+ async function fetchAllRepositories(projectId, connections) {
253
+ const repos = [];
254
+ const remoteUriToConnection = {};
255
+ const getNextPage = async (conn, pageToken = "") => {
256
+ const { location, id } = parseConnectionName(conn.name);
257
+ const resp = await gcb.fetchLinkableRepositories(projectId, location, id, pageToken);
258
+ if (resp.repositories && resp.repositories.length > 0) {
259
+ for (const repo of resp.repositories) {
260
+ repos.push(repo);
261
+ remoteUriToConnection[repo.remoteUri] = conn;
262
+ }
263
+ }
264
+ if (resp.nextPageToken) {
265
+ await getNextPage(conn, resp.nextPageToken);
266
+ }
267
+ };
268
+ for (const conn of connections) {
269
+ await getNextPage(conn);
270
+ }
271
+ return { repos, remoteUriToConnection };
272
+ }
273
+ exports.fetchAllRepositories = fetchAllRepositories;
@@ -12,6 +12,7 @@ const ensureApiEnabled_1 = require("../../ensureApiEnabled");
12
12
  const getDefaultDatabaseInstance_1 = require("../../getDefaultDatabaseInstance");
13
13
  const error_1 = require("../../error");
14
14
  const apiv2_1 = require("../../apiv2");
15
+ const api_1 = require("../../api");
15
16
  const DEFAULT_RULES = JSON.stringify({ rules: { ".read": "auth != null", ".write": "auth != null" } }, null, 2);
16
17
  async function getDBRules(instanceDetails) {
17
18
  if (!instanceDetails || !instanceDetails.name) {
@@ -70,7 +71,7 @@ async function doSetup(setup, config) {
70
71
  setup.config = setup.config || {};
71
72
  let instanceDetails;
72
73
  if (setup.projectId) {
73
- await (0, ensureApiEnabled_1.ensure)(setup.projectId, "firebasedatabase.googleapis.com", "database", false);
74
+ await (0, ensureApiEnabled_1.ensure)(setup.projectId, api_1.rtdbManagementOrigin, "database", false);
74
75
  logger_1.logger.info();
75
76
  setup.instance =
76
77
  setup.instance || (await (0, getDefaultDatabaseInstance_1.getDefaultDatabaseInstance)({ project: setup.projectId }));
@@ -4,11 +4,12 @@ exports.doSetup = void 0;
4
4
  const requirePermissions_1 = require("../../../requirePermissions");
5
5
  const ensureApiEnabled_1 = require("../../../ensureApiEnabled");
6
6
  const manifest = require("../../../extensions/manifest");
7
+ const api_1 = require("../../../api");
7
8
  async function doSetup(setup, config, options) {
8
9
  const projectId = setup?.rcfile?.projects?.default;
9
10
  if (projectId) {
10
11
  await (0, requirePermissions_1.requirePermissions)({ ...options, project: projectId });
11
- await Promise.all([(0, ensureApiEnabled_1.ensure)(projectId, "firebaseextensions.googleapis.com", "unused", true)]);
12
+ await Promise.all([(0, ensureApiEnabled_1.ensure)(projectId, api_1.extensionsOrigin, "unused", true)]);
12
13
  }
13
14
  return manifest.writeEmptyManifest(config, options);
14
15
  }
@@ -8,14 +8,15 @@ const requirePermissions_1 = require("../../../requirePermissions");
8
8
  const ensureApiEnabled_1 = require("../../../ensureApiEnabled");
9
9
  const projectConfig_1 = require("../../../functions/projectConfig");
10
10
  const error_1 = require("../../../error");
11
+ const api_1 = require("../../../api");
11
12
  const MAX_ATTEMPTS = 5;
12
13
  async function doSetup(setup, config, options) {
13
14
  const projectId = setup?.rcfile?.projects?.default;
14
15
  if (projectId) {
15
16
  await (0, requirePermissions_1.requirePermissions)({ ...options, project: projectId });
16
17
  await Promise.all([
17
- (0, ensureApiEnabled_1.ensure)(projectId, "cloudfunctions.googleapis.com", "unused", true),
18
- (0, ensureApiEnabled_1.ensure)(projectId, "runtimeconfig.googleapis.com", "unused", true),
18
+ (0, ensureApiEnabled_1.ensure)(projectId, api_1.functionsOrigin, "unused", true),
19
+ (0, ensureApiEnabled_1.ensure)(projectId, api_1.runtimeconfigOrigin, "unused", true),
19
20
  ]);
20
21
  }
21
22
  setup.functions = {};
@@ -160,6 +160,11 @@ function writeChannelActionYMLFile(ymlPath, secretName, projectId, script) {
160
160
  const workflowConfig = {
161
161
  name: "Deploy to Firebase Hosting on PR",
162
162
  on: "pull_request",
163
+ permissions: {
164
+ checks: "write",
165
+ contents: "read",
166
+ "pull-requests": "write",
167
+ },
163
168
  jobs: {
164
169
  ["build_and_preview"]: {
165
170
  if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}",
package/lib/prompt.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.confirm = exports.promptOnce = exports.prompt = void 0;
4
4
  const inquirer = require("inquirer");
5
5
  const error_1 = require("./error");
6
+ inquirer.registerPrompt("autocomplete", require("inquirer-autocomplete-prompt"));
6
7
  async function prompt(options, questions) {
7
8
  const prompts = [];
8
9
  for (const question of questions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools-with-isolate",
3
- "version": "13.2.1-0",
3
+ "version": "13.4.0",
4
4
  "description": "Command-Line Interface for Firebase with monorepo support",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -27,6 +27,7 @@
27
27
  "test": "npm run lint:quiet && npm run test:compile && npm run mocha",
28
28
  "test:client-integration": "bash ./scripts/client-integration-tests/run.sh",
29
29
  "test:compile": "tsc --project tsconfig.compile.json",
30
+ "test:all-emulators": "npm run test:emulator && npm run test:extensions-emulator && npm run test:import-export && npm run test:storage-emulator-integration",
30
31
  "test:emulator": "bash ./scripts/emulator-tests/run.sh",
31
32
  "test:extensions-deploy": "bash ./scripts/extensions-deploy-tests/run.sh",
32
33
  "test:extensions-emulator": "bash ./scripts/extensions-emulator-tests/run.sh",
@@ -108,16 +109,19 @@
108
109
  "cross-env": "^5.1.3",
109
110
  "cross-spawn": "^7.0.3",
110
111
  "csv-parse": "^5.0.4",
112
+ "deep-equal-in-any-order": "^2.0.6",
111
113
  "exegesis": "^4.1.0",
112
114
  "exegesis-express": "^4.0.0",
113
115
  "express": "^4.16.4",
114
116
  "filesize": "^6.1.0",
115
117
  "form-data": "^4.0.0",
116
118
  "fs-extra": "^10.1.0",
119
+ "fuzzy": "^0.1.3",
117
120
  "glob": "^7.1.2",
118
121
  "google-auth-library": "^7.11.0",
119
- "inquirer": "^8.2.0",
120
- "isolate-package": "^1.10.0-2",
122
+ "inquirer": "^8.2.6",
123
+ "inquirer-autocomplete-prompt": "^2.0.1",
124
+ "isolate-package": "^1.10.1",
121
125
  "js-yaml": "^3.13.1",
122
126
  "jsonwebtoken": "^9.0.0",
123
127
  "leven": "^3.1.0",
@@ -167,14 +171,16 @@
167
171
  "@types/configstore": "^4.0.0",
168
172
  "@types/cors": "^2.8.10",
169
173
  "@types/cross-spawn": "^6.0.1",
174
+ "@types/deep-equal-in-any-order": "^1.0.3",
170
175
  "@types/express": "^4.17.0",
171
176
  "@types/express-serve-static-core": "^4.17.8",
172
177
  "@types/fs-extra": "^9.0.13",
173
178
  "@types/glob": "^7.1.1",
174
179
  "@types/html-escaper": "^3.0.0",
175
180
  "@types/inquirer": "^8.1.3",
181
+ "@types/inquirer-autocomplete-prompt": "^2.0.2",
176
182
  "@types/js-yaml": "^3.12.2",
177
- "@types/jsonwebtoken": "^8.3.8",
183
+ "@types/jsonwebtoken": "^9.0.5",
178
184
  "@types/libsodium-wrappers": "^0.7.9",
179
185
  "@types/lodash": "^4.14.149",
180
186
  "@types/marked": "^4.0.3",
@@ -183,7 +189,6 @@
183
189
  "@types/multer": "^1.4.3",
184
190
  "@types/node": "^14.18.18",
185
191
  "@types/node-fetch": "^2.5.12",
186
- "@types/prettier": "^2.7.2",
187
192
  "@types/progress": "^2.0.3",
188
193
  "@types/puppeteer": "^5.4.2",
189
194
  "@types/react": "^18.0.20",