firebase-tools-with-isolate 13.0.2 → 13.3.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.
Files changed (76) hide show
  1. package/README.md +6 -2
  2. package/lib/appdistribution/client.js +36 -28
  3. package/lib/appdistribution/options-parser-util.js +80 -1
  4. package/lib/appdistribution/types.js +31 -0
  5. package/lib/auth.js +11 -2
  6. package/lib/commands/appdistribution-distribute.js +70 -10
  7. package/lib/commands/apphosting-backends-create.js +6 -3
  8. package/lib/commands/apphosting-backends-delete.js +3 -5
  9. package/lib/commands/apphosting-backends-get.js +2 -2
  10. package/lib/commands/apphosting-backends-list.js +21 -37
  11. package/lib/commands/apphosting-builds-create.js +8 -8
  12. package/lib/commands/apphosting-builds-get.js +2 -2
  13. package/lib/commands/apphosting-rollouts-create.js +5 -5
  14. package/lib/commands/apphosting-rollouts-list.js +6 -3
  15. package/lib/commands/firestore-backups-delete.js +44 -0
  16. package/lib/commands/firestore-backups-get.js +25 -0
  17. package/lib/commands/firestore-backups-list.js +33 -0
  18. package/lib/commands/firestore-backups-schedules-create.js +67 -0
  19. package/lib/commands/firestore-backups-schedules-delete.js +46 -0
  20. package/lib/commands/firestore-backups-schedules-list.js +27 -0
  21. package/lib/commands/firestore-backups-schedules-update.js +33 -0
  22. package/lib/commands/firestore-databases-create.js +4 -2
  23. package/lib/commands/firestore-databases-delete.js +4 -2
  24. package/lib/commands/firestore-databases-get.js +3 -1
  25. package/lib/commands/firestore-databases-list.js +3 -1
  26. package/lib/commands/firestore-databases-restore.js +42 -0
  27. package/lib/commands/firestore-databases-update.js +4 -2
  28. package/lib/commands/firestore-indexes-list.js +5 -3
  29. package/lib/commands/firestore-locations.js +3 -1
  30. package/lib/commands/functions-config-export.js +4 -2
  31. package/lib/commands/index.js +11 -1
  32. package/lib/commands/init.js +3 -3
  33. package/lib/commands/use.js +4 -1
  34. package/lib/deploy/functions/runtimes/index.js +2 -0
  35. package/lib/deploy/functions/runtimes/python/index.js +4 -1
  36. package/lib/deploy/functions/services/firestore.js +1 -1
  37. package/lib/deploy/hosting/convertConfig.js +5 -0
  38. package/lib/deploy/hosting/prepare.js +2 -1
  39. package/lib/emulator/auth/handlers.js +1 -1
  40. package/lib/emulator/auth/operations.js +42 -13
  41. package/lib/emulator/auth/state.js +14 -0
  42. package/lib/emulator/downloadableEmulators.js +3 -3
  43. package/lib/emulator/storage/metadata.js +1 -1
  44. package/lib/emulator/storage/rules/runtime.js +1 -1
  45. package/lib/experiments.js +2 -2
  46. package/lib/firestore/api-sort.js +23 -1
  47. package/lib/firestore/api-types.js +6 -1
  48. package/lib/firestore/api.js +18 -115
  49. package/lib/firestore/backupUtils.js +30 -0
  50. package/lib/firestore/delete.js +3 -3
  51. package/lib/firestore/pretty-print.js +184 -0
  52. package/lib/frameworks/angular/index.js +2 -2
  53. package/lib/frameworks/angular/utils.js +14 -10
  54. package/lib/frameworks/astro/index.js +1 -2
  55. package/lib/frameworks/flutter/index.js +1 -1
  56. package/lib/frameworks/index.js +2 -3
  57. package/lib/frameworks/next/index.js +5 -3
  58. package/lib/frameworks/nuxt/index.js +2 -2
  59. package/lib/frameworks/nuxt2/index.js +1 -2
  60. package/lib/frameworks/sveltekit/index.js +2 -2
  61. package/lib/frameworks/utils.js +11 -2
  62. package/lib/frameworks/vite/index.js +8 -4
  63. package/lib/functions/env.js +2 -0
  64. package/lib/gcp/apphosting.js +103 -17
  65. package/lib/gcp/cloudbuild.js +7 -2
  66. package/lib/gcp/cloudfunctionsv2.js +2 -4
  67. package/lib/gcp/firestore.js +89 -6
  68. package/lib/hosting/api.js +3 -9
  69. package/lib/hosting/options.js +2 -1
  70. package/lib/init/features/apphosting/index.js +150 -68
  71. package/lib/init/features/apphosting/repo.js +80 -32
  72. package/lib/init/features/hosting/github.js +6 -1
  73. package/lib/metaprogramming.js +3 -0
  74. package/lib/prompt.js +1 -0
  75. package/lib/utils.js +1 -12
  76. package/package.json +15 -10
package/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # Firebase CLI with monorepo support
2
2
 
3
- This is an experimental fork of the [firebase-tools](https://github.com/firebase/firebase-tools) which integrates [isolate-package](https://github.com/0x80/isolate-package/) as part of the functions `deploy` command in order to [support monorepo setups](https://thijs-koerselman.medium.com/deploy-to-firebase-without-the-hacks-e685de39025e).
3
+ This is a fork of the [firebase-tools](https://github.com/firebase/firebase-tools) which integrates [isolate-package](https://github.com/0x80/isolate-package/) as part of the functions `deploy` command in order to [support monorepo setups](https://thijs-koerselman.medium.com/deploy-to-firebase-without-the-hacks-e685de39025e).
4
4
 
5
5
  Alternatively, you can manually configure `isolate` as part of the `predeploy` step of your configuration, but having the process integrated and only running as part of the deploy command is essential if you want to have live code updates when running the Firebase emulators locally during development with a watch task.
6
6
 
7
7
  I suspect it will take some time before the Firebase team would agree to make isolate an integral part of the toolchain and that is why I have published this fork to be available on NPM.
8
8
 
9
- In the meantime I will try to keep this fairly in-sync with updates to the original firebase-tools repository. The published versions of the fork will be kept the same as the original `firebase-tools` package, so you can easily see how up-to-date it is.
9
+ The fork is pretty much identical, and the integration with isolate-package does
10
+ not affect any existing functionality, so I do not think there is a reason to worry
11
+ about things breaking. I will sync the fork with the upstream firebase-tools on
12
+ a regular basis. The fork versions will match the firebase-tools versions for
13
+ clarity.
10
14
 
11
15
  ## Installation
12
16
 
@@ -1,37 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppDistributionClient = exports.UploadReleaseResult = exports.IntegrationState = void 0;
3
+ exports.AppDistributionClient = void 0;
4
4
  const utils = require("../utils");
5
5
  const operationPoller = require("../operation-poller");
6
6
  const error_1 = require("../error");
7
7
  const apiv2_1 = require("../apiv2");
8
8
  const api_1 = require("../api");
9
- var IntegrationState;
10
- (function (IntegrationState) {
11
- IntegrationState["AAB_INTEGRATION_STATE_UNSPECIFIED"] = "AAB_INTEGRATION_STATE_UNSPECIFIED";
12
- IntegrationState["INTEGRATED"] = "INTEGRATED";
13
- IntegrationState["PLAY_ACCOUNT_NOT_LINKED"] = "PLAY_ACCOUNT_NOT_LINKED";
14
- IntegrationState["NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT"] = "NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT";
15
- IntegrationState["APP_NOT_PUBLISHED"] = "APP_NOT_PUBLISHED";
16
- IntegrationState["AAB_STATE_UNAVAILABLE"] = "AAB_STATE_UNAVAILABLE";
17
- IntegrationState["PLAY_IAS_TERMS_NOT_ACCEPTED"] = "PLAY_IAS_TERMS_NOT_ACCEPTED";
18
- })(IntegrationState = exports.IntegrationState || (exports.IntegrationState = {}));
19
- var UploadReleaseResult;
20
- (function (UploadReleaseResult) {
21
- UploadReleaseResult["UPLOAD_RELEASE_RESULT_UNSPECIFIED"] = "UPLOAD_RELEASE_RESULT_UNSPECIFIED";
22
- UploadReleaseResult["RELEASE_CREATED"] = "RELEASE_CREATED";
23
- UploadReleaseResult["RELEASE_UPDATED"] = "RELEASE_UPDATED";
24
- UploadReleaseResult["RELEASE_UNMODIFIED"] = "RELEASE_UNMODIFIED";
25
- })(UploadReleaseResult = exports.UploadReleaseResult || (exports.UploadReleaseResult = {}));
9
+ const types_1 = require("./types");
26
10
  class AppDistributionClient {
27
11
  constructor() {
28
- this.appDistroV2Client = new apiv2_1.Client({
12
+ this.appDistroV1Client = new apiv2_1.Client({
29
13
  urlPrefix: api_1.appDistributionOrigin,
30
14
  apiVersion: "v1",
31
15
  });
16
+ this.appDistroV1AlphaClient = new apiv2_1.Client({
17
+ urlPrefix: api_1.appDistributionOrigin,
18
+ apiVersion: "v1alpha",
19
+ });
32
20
  }
33
21
  async getAabInfo(appName) {
34
- const apiResponse = await this.appDistroV2Client.get(`/${appName}/aabInfo`);
22
+ const apiResponse = await this.appDistroV1Client.get(`/${appName}/aabInfo`);
35
23
  return apiResponse.body;
36
24
  }
37
25
  async uploadRelease(appName, distribution) {
@@ -74,7 +62,7 @@ class AppDistributionClient {
74
62
  };
75
63
  const queryParams = { updateMask: "release_notes.text" };
76
64
  try {
77
- await this.appDistroV2Client.patch(`/${releaseName}`, data, { queryParams });
65
+ await this.appDistroV1Client.patch(`/${releaseName}`, data, { queryParams });
78
66
  }
79
67
  catch (err) {
80
68
  throw new error_1.FirebaseError(`failed to update release notes with ${err?.message}`);
@@ -92,7 +80,7 @@ class AppDistributionClient {
92
80
  groupAliases,
93
81
  };
94
82
  try {
95
- await this.appDistroV2Client.post(`/${releaseName}:distribute`, data);
83
+ await this.appDistroV1Client.post(`/${releaseName}:distribute`, data);
96
84
  }
97
85
  catch (err) {
98
86
  let errorMessage = err.message;
@@ -111,7 +99,7 @@ class AppDistributionClient {
111
99
  }
112
100
  async addTesters(projectName, emails) {
113
101
  try {
114
- await this.appDistroV2Client.request({
102
+ await this.appDistroV1Client.request({
115
103
  method: "POST",
116
104
  path: `${projectName}/testers:batchAdd`,
117
105
  body: { emails: emails },
@@ -125,7 +113,7 @@ class AppDistributionClient {
125
113
  async removeTesters(projectName, emails) {
126
114
  let apiResponse;
127
115
  try {
128
- apiResponse = await this.appDistroV2Client.request({
116
+ apiResponse = await this.appDistroV1Client.request({
129
117
  method: "POST",
130
118
  path: `${projectName}/testers:batchRemove`,
131
119
  body: { emails: emails },
@@ -139,7 +127,7 @@ class AppDistributionClient {
139
127
  async createGroup(projectName, displayName, alias) {
140
128
  let apiResponse;
141
129
  try {
142
- apiResponse = await this.appDistroV2Client.request({
130
+ apiResponse = await this.appDistroV1Client.request({
143
131
  method: "POST",
144
132
  path: alias === undefined ? `${projectName}/groups` : `${projectName}/groups?groupId=${alias}`,
145
133
  body: { displayName: displayName },
@@ -152,7 +140,7 @@ class AppDistributionClient {
152
140
  }
153
141
  async deleteGroup(groupName) {
154
142
  try {
155
- await this.appDistroV2Client.request({
143
+ await this.appDistroV1Client.request({
156
144
  method: "DELETE",
157
145
  path: groupName,
158
146
  });
@@ -164,7 +152,7 @@ class AppDistributionClient {
164
152
  }
165
153
  async addTestersToGroup(groupName, emails) {
166
154
  try {
167
- await this.appDistroV2Client.request({
155
+ await this.appDistroV1Client.request({
168
156
  method: "POST",
169
157
  path: `${groupName}:batchJoin`,
170
158
  body: { emails: emails },
@@ -177,7 +165,7 @@ class AppDistributionClient {
177
165
  }
178
166
  async removeTestersFromGroup(groupName, emails) {
179
167
  try {
180
- await this.appDistroV2Client.request({
168
+ await this.appDistroV1Client.request({
181
169
  method: "POST",
182
170
  path: `${groupName}:batchLeave`,
183
171
  body: { emails: emails },
@@ -188,5 +176,25 @@ class AppDistributionClient {
188
176
  }
189
177
  utils.logSuccess(`Testers removed from group successfully`);
190
178
  }
179
+ async createReleaseTest(releaseName, devices, loginCredential) {
180
+ try {
181
+ const response = await this.appDistroV1AlphaClient.request({
182
+ method: "POST",
183
+ path: `${releaseName}/tests`,
184
+ body: {
185
+ deviceExecutions: devices.map(types_1.mapDeviceToExecution),
186
+ loginCredential,
187
+ },
188
+ });
189
+ return response.body;
190
+ }
191
+ catch (err) {
192
+ throw new error_1.FirebaseError(`Failed to create release test ${err}`);
193
+ }
194
+ }
195
+ async getReleaseTest(releaseTestName) {
196
+ const response = await this.appDistroV1AlphaClient.get(releaseTestName);
197
+ return response.body;
198
+ }
191
199
  }
192
200
  exports.AppDistributionClient = AppDistributionClient;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAppName = exports.getProjectName = exports.ensureFileExists = exports.getEmails = exports.getTestersOrGroups = void 0;
3
+ exports.getLoginCredential = exports.getTestDevices = exports.getAppName = exports.getProjectName = exports.ensureFileExists = exports.getEmails = exports.getTestersOrGroups = void 0;
4
4
  const fs = require("fs-extra");
5
5
  const error_1 = require("../error");
6
6
  const projectUtils_1 = require("../projectUtils");
@@ -49,3 +49,82 @@ function getAppName(options) {
49
49
  return `projects/${appId.split(":")[1]}/apps/${appId}`;
50
50
  }
51
51
  exports.getAppName = getAppName;
52
+ function getTestDevices(value, file) {
53
+ if (!value && file) {
54
+ ensureFileExists(file);
55
+ value = fs.readFileSync(file, "utf8");
56
+ }
57
+ if (!value) {
58
+ return [];
59
+ }
60
+ return value
61
+ .split(/[;\n]/)
62
+ .map((entry) => entry.trim())
63
+ .filter((entry) => !!entry)
64
+ .map((str) => parseTestDevice(str));
65
+ }
66
+ exports.getTestDevices = getTestDevices;
67
+ function parseTestDevice(testDeviceString) {
68
+ const entries = testDeviceString.split(",");
69
+ const allowedKeys = new Set(["model", "version", "orientation", "locale"]);
70
+ let model;
71
+ let version;
72
+ let orientation;
73
+ let locale;
74
+ for (const entry of entries) {
75
+ const keyAndValue = entry.split("=");
76
+ switch (keyAndValue[0]) {
77
+ case "model":
78
+ model = keyAndValue[1];
79
+ break;
80
+ case "version":
81
+ version = keyAndValue[1];
82
+ break;
83
+ case "orientation":
84
+ orientation = keyAndValue[1];
85
+ break;
86
+ case "locale":
87
+ locale = keyAndValue[1];
88
+ break;
89
+ default:
90
+ throw new error_1.FirebaseError(`Unrecognized key in test devices. Can only contain ${Array.from(allowedKeys).join(", ")}`);
91
+ }
92
+ }
93
+ if (!model || !version || !orientation || !locale) {
94
+ throw new error_1.FirebaseError("Test devices must be in the format 'model=<model-id>,version=<os-version-id>,locale=<locale>,orientation=<orientation>'");
95
+ }
96
+ return { model, version, locale, orientation };
97
+ }
98
+ function getLoginCredential(args) {
99
+ const { username, passwordFile, usernameResourceName, passwordResourceName } = args;
100
+ let password = args.password;
101
+ if (!password && passwordFile) {
102
+ ensureFileExists(passwordFile);
103
+ password = fs.readFileSync(passwordFile, "utf8").trim();
104
+ }
105
+ if (isPresenceMismatched(usernameResourceName, passwordResourceName)) {
106
+ throw new error_1.FirebaseError("Username and password resource names for automated tests need to be specified together.");
107
+ }
108
+ let fieldHints;
109
+ if (usernameResourceName && passwordResourceName) {
110
+ fieldHints = {
111
+ usernameResourceName: usernameResourceName,
112
+ passwordResourceName: passwordResourceName,
113
+ };
114
+ }
115
+ if (isPresenceMismatched(username, password)) {
116
+ throw new error_1.FirebaseError("Username and password for automated tests need to be specified together.");
117
+ }
118
+ let loginCredential;
119
+ if (username && password) {
120
+ loginCredential = { username, password, fieldHints };
121
+ }
122
+ else if (fieldHints) {
123
+ throw new error_1.FirebaseError("Must specify username and password for automated tests if resource names are set");
124
+ }
125
+ return loginCredential;
126
+ }
127
+ exports.getLoginCredential = getLoginCredential;
128
+ function isPresenceMismatched(value1, value2) {
129
+ return (value1 && !value2) || (!value1 && value2);
130
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapDeviceToExecution = exports.UploadReleaseResult = exports.IntegrationState = void 0;
4
+ var IntegrationState;
5
+ (function (IntegrationState) {
6
+ IntegrationState["AAB_INTEGRATION_STATE_UNSPECIFIED"] = "AAB_INTEGRATION_STATE_UNSPECIFIED";
7
+ IntegrationState["INTEGRATED"] = "INTEGRATED";
8
+ IntegrationState["PLAY_ACCOUNT_NOT_LINKED"] = "PLAY_ACCOUNT_NOT_LINKED";
9
+ IntegrationState["NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT"] = "NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT";
10
+ IntegrationState["APP_NOT_PUBLISHED"] = "APP_NOT_PUBLISHED";
11
+ IntegrationState["AAB_STATE_UNAVAILABLE"] = "AAB_STATE_UNAVAILABLE";
12
+ IntegrationState["PLAY_IAS_TERMS_NOT_ACCEPTED"] = "PLAY_IAS_TERMS_NOT_ACCEPTED";
13
+ })(IntegrationState = exports.IntegrationState || (exports.IntegrationState = {}));
14
+ var UploadReleaseResult;
15
+ (function (UploadReleaseResult) {
16
+ UploadReleaseResult["UPLOAD_RELEASE_RESULT_UNSPECIFIED"] = "UPLOAD_RELEASE_RESULT_UNSPECIFIED";
17
+ UploadReleaseResult["RELEASE_CREATED"] = "RELEASE_CREATED";
18
+ UploadReleaseResult["RELEASE_UPDATED"] = "RELEASE_UPDATED";
19
+ UploadReleaseResult["RELEASE_UNMODIFIED"] = "RELEASE_UNMODIFIED";
20
+ })(UploadReleaseResult = exports.UploadReleaseResult || (exports.UploadReleaseResult = {}));
21
+ function mapDeviceToExecution(device) {
22
+ return {
23
+ device: {
24
+ model: device.model,
25
+ version: device.version,
26
+ orientation: device.orientation,
27
+ locale: device.locale,
28
+ },
29
+ };
30
+ }
31
+ exports.mapDeviceToExecution = mapDeviceToExecution;
package/lib/auth.js CHANGED
@@ -306,7 +306,7 @@ async function loginRemotely() {
306
306
  const tokens = await getTokensFromAuthorizationCode(code, `${api_1.authProxyOrigin}/complete`, codeVerifier);
307
307
  void (0, track_1.trackGA4)("login", { method: "google_remote" });
308
308
  return {
309
- user: jwt.decode(tokens.id_token),
309
+ user: jwt.decode(tokens.id_token, { json: true }),
310
310
  tokens: tokens,
311
311
  scopes: SCOPES,
312
312
  };
@@ -322,7 +322,7 @@ async function loginWithLocalhostGoogle(port, userHint) {
322
322
  const tokens = await loginWithLocalhost(port, callbackUrl, authUrl, successTemplate, getTokensFromAuthorizationCode);
323
323
  void (0, track_1.trackGA4)("login", { method: "google_localhost" });
324
324
  return {
325
- user: jwt.decode(tokens.id_token),
325
+ user: jwt.decode(tokens.id_token, { json: true }),
326
326
  tokens: tokens,
327
327
  scopes: tokens.scopes,
328
328
  };
@@ -474,6 +474,15 @@ async function refreshTokens(refreshToken, authScopes) {
474
474
  skipLog: { body: true, queryParams: true, resBody: true },
475
475
  resolveOnHTTPError: true,
476
476
  });
477
+ const forceReauthErrs = [
478
+ { error: "invalid_grant", error_subtype: "invalid_rapt" },
479
+ ];
480
+ const matches = (a, b) => {
481
+ return a.error === b.error && a.error_subtype === b.error_subtype;
482
+ };
483
+ if (forceReauthErrs.some((a) => matches(a, res.body))) {
484
+ throw invalidCredentialError();
485
+ }
477
486
  if (res.status === 401 || res.status === 400) {
478
487
  return { access_token: refreshToken };
479
488
  }
@@ -6,9 +6,12 @@ const command_1 = require("../command");
6
6
  const utils = require("../utils");
7
7
  const requireAuth_1 = require("../requireAuth");
8
8
  const client_1 = require("../appdistribution/client");
9
+ const types_1 = require("../appdistribution/types");
9
10
  const error_1 = require("../error");
10
11
  const distribution_1 = require("../appdistribution/distribution");
11
12
  const options_parser_util_1 = require("../appdistribution/options-parser-util");
13
+ const TEST_MAX_POLLING_RETRIES = 40;
14
+ const TEST_POLLING_INTERVAL_MILLIS = 30000;
12
15
  function getReleaseNotes(releaseNotes, releaseNotesFile) {
13
16
  if (releaseNotes) {
14
17
  return releaseNotes.replace(/\\n/g, "\n");
@@ -28,6 +31,14 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
28
31
  .option("--testers-file <file>", "path to file with a comma separated list of tester emails to distribute to")
29
32
  .option("--groups <string>", "a comma separated list of group aliases to distribute to")
30
33
  .option("--groups-file <file>", "path to file with a comma separated list of group aliases to distribute to")
34
+ .option("--test-devices <string>", "semicolon-separated list of devices to run automated tests on, in the format 'model=<model-id>,version=<os-version-id>,locale=<locale>,orientation=<orientation>'. Run 'gcloud firebase test android|ios models list' to see available devices. Note: This feature is in beta.")
35
+ .option("--test-devices-file <string>", "path to file containing a list of semicolon- or newline-separated devices to run automated tests on, in the format 'model=<model-id>,version=<os-version-id>,locale=<locale>,orientation=<orientation>'. Run 'gcloud firebase test android|ios models list' to see available devices. Note: This feature is in beta.")
36
+ .option("--test-username <string>", "username for automatic login")
37
+ .option("--test-password <string>", "password for automatic login. If using a real password, use --test-password-file instead to avoid putting sensitive info in history and logs.")
38
+ .option("--test-password-file <string>", "path to file containing password for automatic login")
39
+ .option("--test-username-resource <string>", "resource name for the username field for automatic login")
40
+ .option("--test-password-resource <string>", "resource name for the password field for automatic login")
41
+ .option("--test-non-blocking", "run automated tests without waiting for them to complete. Visit the Firebase console for the test results.")
31
42
  .before(requireAuth_1.requireAuth)
32
43
  .action(async (file, options) => {
33
44
  const appName = (0, options_parser_util_1.getAppName)(options);
@@ -35,6 +46,14 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
35
46
  const releaseNotes = getReleaseNotes(options.releaseNotes, options.releaseNotesFile);
36
47
  const testers = (0, options_parser_util_1.getTestersOrGroups)(options.testers, options.testersFile);
37
48
  const groups = (0, options_parser_util_1.getTestersOrGroups)(options.groups, options.groupsFile);
49
+ const testDevices = (0, options_parser_util_1.getTestDevices)(options.testDevices, options.testDevicesFile);
50
+ const loginCredential = (0, options_parser_util_1.getLoginCredential)({
51
+ username: options.testUsername,
52
+ password: options.testPassword,
53
+ passwordFile: options.testPasswordFile,
54
+ usernameResourceName: options.testUsernameResource,
55
+ passwordResourceName: options.testPasswordResource,
56
+ });
38
57
  const requests = new client_1.AppDistributionClient();
39
58
  let aabInfo;
40
59
  if (distribution.distributionFileType() === distribution_1.DistributionFileType.AAB) {
@@ -50,19 +69,19 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
50
69
  }
51
70
  throw new error_1.FirebaseError(`failed to determine AAB info. ${err.message}`, { exit: 1 });
52
71
  }
53
- if (aabInfo.integrationState !== client_1.IntegrationState.INTEGRATED &&
54
- aabInfo.integrationState !== client_1.IntegrationState.AAB_STATE_UNAVAILABLE) {
72
+ if (aabInfo.integrationState !== types_1.IntegrationState.INTEGRATED &&
73
+ aabInfo.integrationState !== types_1.IntegrationState.AAB_STATE_UNAVAILABLE) {
55
74
  switch (aabInfo.integrationState) {
56
- case client_1.IntegrationState.PLAY_ACCOUNT_NOT_LINKED: {
75
+ case types_1.IntegrationState.PLAY_ACCOUNT_NOT_LINKED: {
57
76
  throw new error_1.FirebaseError("This project is not linked to a Google Play account.");
58
77
  }
59
- case client_1.IntegrationState.APP_NOT_PUBLISHED: {
78
+ case types_1.IntegrationState.APP_NOT_PUBLISHED: {
60
79
  throw new error_1.FirebaseError('"This app is not published in the Google Play console.');
61
80
  }
62
- case client_1.IntegrationState.NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT: {
81
+ case types_1.IntegrationState.NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT: {
63
82
  throw new error_1.FirebaseError("App with matching package name does not exist in Google Play.");
64
83
  }
65
- case client_1.IntegrationState.PLAY_IAS_TERMS_NOT_ACCEPTED: {
84
+ case types_1.IntegrationState.PLAY_IAS_TERMS_NOT_ACCEPTED: {
66
85
  throw new error_1.FirebaseError("You must accept the Play Internal App Sharing (IAS) terms to upload AABs.");
67
86
  }
68
87
  default: {
@@ -78,13 +97,13 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
78
97
  const uploadResponse = await requests.pollUploadStatus(operationName);
79
98
  const release = uploadResponse.release;
80
99
  switch (uploadResponse.result) {
81
- case client_1.UploadReleaseResult.RELEASE_CREATED:
100
+ case types_1.UploadReleaseResult.RELEASE_CREATED:
82
101
  utils.logSuccess(`uploaded new release ${release.displayVersion} (${release.buildVersion}) successfully!`);
83
102
  break;
84
- case client_1.UploadReleaseResult.RELEASE_UPDATED:
103
+ case types_1.UploadReleaseResult.RELEASE_UPDATED:
85
104
  utils.logSuccess(`uploaded update to existing release ${release.displayVersion} (${release.buildVersion}) successfully!`);
86
105
  break;
87
- case client_1.UploadReleaseResult.RELEASE_UNMODIFIED:
106
+ case types_1.UploadReleaseResult.RELEASE_UNMODIFIED:
88
107
  utils.logSuccess(`re-uploaded already existing release ${release.displayVersion} (${release.buildVersion}) successfully!`);
89
108
  break;
90
109
  default:
@@ -102,7 +121,7 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
102
121
  "button on the App Distribution page in the Firebase console: " +
103
122
  "https://console.firebase.google.com/project/_/appdistribution", { exit: 1 });
104
123
  }
105
- throw new error_1.FirebaseError(`failed to upload release. ${err.message}`, { exit: 1 });
124
+ throw new error_1.FirebaseError(`Failed to upload release. ${err.message}`, { exit: 1 });
106
125
  }
107
126
  if (aabInfo && !aabInfo.testCertificate) {
108
127
  aabInfo = await requests.getAabInfo(appName);
@@ -118,4 +137,45 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
118
137
  }
119
138
  await requests.updateReleaseNotes(releaseName, releaseNotes);
120
139
  await requests.distribute(releaseName, testers, groups);
140
+ if (testDevices?.length) {
141
+ utils.logBullet("starting automated tests (note: this feature is in beta)");
142
+ const releaseTest = await requests.createReleaseTest(releaseName, testDevices, loginCredential);
143
+ utils.logSuccess(`Release test created successfully`);
144
+ if (!options.testNonBlocking) {
145
+ await awaitTestResults(releaseTest.name, requests);
146
+ }
147
+ }
121
148
  });
149
+ async function awaitTestResults(releaseTestName, requests) {
150
+ for (let i = 0; i < TEST_MAX_POLLING_RETRIES; i++) {
151
+ utils.logBullet("the automated tests results are pending");
152
+ await delay(TEST_POLLING_INTERVAL_MILLIS);
153
+ const releaseTest = await requests.getReleaseTest(releaseTestName);
154
+ if (releaseTest.deviceExecutions.every((e) => e.state === "PASSED")) {
155
+ utils.logSuccess("automated test(s) passed!");
156
+ return;
157
+ }
158
+ for (const execution of releaseTest.deviceExecutions) {
159
+ switch (execution.state) {
160
+ case "PASSED":
161
+ case "IN_PROGRESS":
162
+ continue;
163
+ case "FAILED":
164
+ throw new error_1.FirebaseError(`Automated test failed for ${deviceToString(execution.device)}: ${execution.failedReason}`, { exit: 1 });
165
+ case "INCONCLUSIVE":
166
+ throw new error_1.FirebaseError(`Automated test inconclusive for ${deviceToString(execution.device)}: ${execution.inconclusiveReason}`, { exit: 1 });
167
+ default:
168
+ throw new error_1.FirebaseError(`Unsupported automated test state for ${deviceToString(execution.device)}: ${execution.state}`, { exit: 1 });
169
+ }
170
+ }
171
+ }
172
+ throw new error_1.FirebaseError("It took longer than expected to process your test, please try again.", {
173
+ exit: 1,
174
+ });
175
+ }
176
+ function delay(ms) {
177
+ return new Promise((resolve) => setTimeout(resolve, ms));
178
+ }
179
+ function deviceToString(device) {
180
+ return `${device.model} (${device.version}/${device.orientation}/${device.locale})`;
181
+ }
@@ -7,11 +7,14 @@ const requireInteractive_1 = require("../requireInteractive");
7
7
  const apphosting_1 = require("../init/features/apphosting");
8
8
  const apphosting_2 = require("../gcp/apphosting");
9
9
  exports.command = new command_1.Command("apphosting:backends:create")
10
- .description("Create a backend in a Firebase project")
11
- .option("-l, --location <location>", "Specify the region of the backend", "")
10
+ .description("create a backend in a Firebase project")
11
+ .option("-l, --location <location>", "specify the region of the backend", "")
12
+ .option("-s, --service-account <serviceAccount>", "specify the service account used to run the server", "")
12
13
  .before(apphosting_2.ensureApiEnabled)
13
14
  .before(requireInteractive_1.default)
14
15
  .action(async (options) => {
15
16
  const projectId = (0, projectUtils_1.needProjectId)(options);
16
- await (0, apphosting_1.doSetup)(options, projectId);
17
+ const location = options.location;
18
+ const serviceAccount = options.serviceAccount;
19
+ await (0, apphosting_1.doSetup)(projectId, location, serviceAccount);
17
20
  });
@@ -19,16 +19,14 @@ const TABLE_HEAD = [
19
19
  "Created Date",
20
20
  "Updated Date",
21
21
  ];
22
- exports.command = new command_1.Command("apphosting:backends:delete")
23
- .description("Delete a backend from a Firebase project")
22
+ exports.command = new command_1.Command("apphosting:backends:delete <backend>")
23
+ .description("delete a backend from a Firebase project")
24
24
  .option("-l, --location <location>", "App Backend location", "")
25
- .option("-s, --backend <backend>", "Backend Id", "")
26
25
  .withForce()
27
26
  .before(apphosting.ensureApiEnabled)
28
- .action(async (options) => {
27
+ .action(async (backendId, options) => {
29
28
  const projectId = (0, projectUtils_1.needProjectId)(options);
30
29
  let location = options.location;
31
- const backendId = options.backend;
32
30
  if (!backendId) {
33
31
  throw new error_1.FirebaseError("Backend id can't be empty.");
34
32
  }
@@ -11,8 +11,8 @@ const Table = require("cli-table");
11
11
  const COLUMN_LENGTH = 20;
12
12
  const TABLE_HEAD = ["Backend Id", "Repository", "Location", "URL", "Created Date", "Updated Date"];
13
13
  exports.command = new command_1.Command("apphosting:backends:get <backendId>")
14
- .description("Get backend details of a Firebase project")
15
- .option("-l, --location <location>", "App Backend location", "-")
14
+ .description("get backend details of a Firebase project")
15
+ .option("-l, --location <location>", "app backend location", "-")
16
16
  .before(apphosting.ensureApiEnabled)
17
17
  .action(async (backendId, options) => {
18
18
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -1,57 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.command = void 0;
4
+ const Table = require("cli-table");
4
5
  const command_1 = require("../command");
5
- const projectUtils_1 = require("../projectUtils");
6
+ const utils_1 = require("../utils");
6
7
  const error_1 = require("../error");
7
8
  const logger_1 = require("../logger");
9
+ const projectUtils_1 = require("../projectUtils");
8
10
  const apphosting = require("../gcp/apphosting");
9
- const Table = require("cli-table");
10
- const COLUMN_LENGTH = 20;
11
- const TABLE_HEAD = ["Backend Id", "Repository", "Location", "URL", "Created Date", "Updated Date"];
11
+ const TABLE_HEAD = ["Backend ID", "Repository", "Location", "URL", "Created Date", "Updated Date"];
12
12
  exports.command = new command_1.Command("apphosting:backends:list")
13
- .description("List backends of a Firebase project.")
14
- .option("-l, --location <location>", "App Backend location", "-")
13
+ .description("list backends of a Firebase project")
14
+ .option("-l, --location <location>", "app Backend location", "-")
15
15
  .before(apphosting.ensureApiEnabled)
16
16
  .action(async (options) => {
17
17
  const projectId = (0, projectUtils_1.needProjectId)(options);
18
18
  const location = options.location;
19
- const table = new Table({
20
- head: TABLE_HEAD,
21
- style: { head: ["green"] },
22
- });
23
- table.colWidths = COLUMN_LENGTH;
24
- const backendsList = [];
19
+ const table = new Table({ head: TABLE_HEAD, style: { head: ["green"] } });
20
+ let backendRes;
25
21
  try {
26
- const backendsPerRegion = await apphosting.listBackends(projectId, location);
27
- backendsList.push(...(backendsPerRegion.backends || []));
28
- populateTable(backendsList, table);
29
- logger_1.logger.info(table.toString());
22
+ backendRes = await apphosting.listBackends(projectId, location);
30
23
  }
31
24
  catch (err) {
32
25
  throw new error_1.FirebaseError(`Unable to list backends present for project: ${projectId}. Please check the parameters you have provided.`, { original: err });
33
26
  }
34
- return backendsList;
35
- });
36
- function populateTable(backends, table) {
27
+ const backends = backendRes.backends ?? [];
37
28
  for (const backend of backends) {
38
- const [location, , backendId] = backend.name.split("/").slice(3, 6);
39
- const entry = [
29
+ const [backendLocation, , backendId] = backend.name.split("/").slice(3, 6);
30
+ table.push([
40
31
  backendId,
41
- backend.codebase.repository?.split("/").pop(),
42
- location,
43
- backend.uri,
44
- backend.createTime,
45
- backend.updateTime,
46
- ];
47
- const newRow = entry.map((name) => {
48
- const maxCellWidth = COLUMN_LENGTH - 2;
49
- const chunks = [];
50
- for (let i = 0; name && i < name.length; i += maxCellWidth) {
51
- chunks.push(name.substring(i, i + maxCellWidth));
52
- }
53
- return chunks.join("\n");
54
- });
55
- table.push(newRow);
32
+ backend.codebase?.repository?.split("/").pop() ?? "",
33
+ backendLocation,
34
+ backend.uri.startsWith("https:") ? backend.uri : "https://" + backend.uri,
35
+ (0, utils_1.datetimeString)(new Date(backend.createTime)),
36
+ (0, utils_1.datetimeString)(new Date(backend.updateTime)),
37
+ ]);
56
38
  }
57
- }
39
+ logger_1.logger.info(table.toString());
40
+ return backends;
41
+ });
@@ -4,23 +4,23 @@ exports.command = void 0;
4
4
  const apphosting = require("../gcp/apphosting");
5
5
  const logger_1 = require("../logger");
6
6
  const command_1 = require("../command");
7
- const utils_1 = require("../utils");
8
7
  const projectUtils_1 = require("../projectUtils");
9
8
  exports.command = new command_1.Command("apphosting:builds:create <backendId>")
10
- .description("Create a build for an App Hosting backend")
11
- .option("-l, --location <location>", "Specify the region of the backend", "us-central1")
12
- .option("-i, --id <buildId>", "Id of the build. If not present, autogenerate a random id", "")
13
- .option("-b, --branch <branch>", "Repository branch to deploy. Defaults to 'main'", "main")
9
+ .description("create a build for an App Hosting backend")
10
+ .option("-l, --location <location>", "specify the region of the backend", "us-central1")
11
+ .option("-i, --id <buildId>", "id of the build (defaults to autogenerating a random id)", "")
12
+ .option("-b, --branch <branch>", "repository branch to deploy (defaults to 'main')", "main")
14
13
  .before(apphosting.ensureApiEnabled)
15
14
  .action(async (backendId, options) => {
16
15
  const projectId = (0, projectUtils_1.needProjectId)(options);
17
16
  const location = options.location;
18
- const buildId = options.buildId || (0, utils_1.generateId)();
19
- const branch = options.branch;
17
+ const buildId = options.buildId ||
18
+ (await apphosting.getNextRolloutId(projectId, location, backendId));
19
+ const branch = options.branch ?? "main";
20
20
  const op = await apphosting.createBuild(projectId, location, backendId, buildId, {
21
21
  source: {
22
22
  codebase: {
23
- branch: "main",
23
+ branch,
24
24
  },
25
25
  },
26
26
  });
@@ -6,8 +6,8 @@ const logger_1 = require("../logger");
6
6
  const command_1 = require("../command");
7
7
  const projectUtils_1 = require("../projectUtils");
8
8
  exports.command = new command_1.Command("apphosting:builds:get <backendId> <buildId>")
9
- .description("Create a build for an App Hosting backend")
10
- .option("-l, --location <location>", "Specify the region of the backend", "us-central1")
9
+ .description("get a build for an App Hosting backend")
10
+ .option("-l, --location <location>", "specify the region of the backend", "us-central1")
11
11
  .before(apphosting.ensureApiEnabled)
12
12
  .action(async (backendId, buildId, options) => {
13
13
  const projectId = (0, projectUtils_1.needProjectId)(options);