firebase-tools 10.9.2 → 11.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 (181) hide show
  1. package/README.md +15 -9
  2. package/lib/accountImporter.js +92 -93
  3. package/lib/api.js +77 -218
  4. package/lib/apiv2.js +5 -4
  5. package/lib/appdistribution/client.js +16 -25
  6. package/lib/auth.js +69 -47
  7. package/lib/bin/firebase.js +42 -47
  8. package/lib/checkValidTargetFilters.js +13 -12
  9. package/lib/commands/appdistribution-distribute.js +2 -1
  10. package/lib/commands/appdistribution-testers-add.js +2 -1
  11. package/lib/commands/appdistribution-testers-remove.js +2 -1
  12. package/lib/commands/apps-android-sha-create.js +2 -1
  13. package/lib/commands/apps-android-sha-delete.js +2 -1
  14. package/lib/commands/apps-android-sha-list.js +2 -1
  15. package/lib/commands/apps-create.js +2 -1
  16. package/lib/commands/apps-list.js +2 -1
  17. package/lib/commands/apps-sdkconfig.js +8 -3
  18. package/lib/commands/auth-export.js +2 -1
  19. package/lib/commands/auth-import.js +7 -10
  20. package/lib/commands/crashlytics-symbols-upload.js +2 -1
  21. package/lib/commands/database-get.js +4 -3
  22. package/lib/commands/database-instances-create.js +2 -1
  23. package/lib/commands/database-instances-list.js +3 -3
  24. package/lib/commands/database-profile.js +2 -1
  25. package/lib/commands/database-push.js +2 -1
  26. package/lib/commands/database-remove.js +2 -1
  27. package/lib/commands/database-rules-canary.js +2 -1
  28. package/lib/commands/database-rules-get.js +2 -1
  29. package/lib/commands/database-rules-list.js +2 -1
  30. package/lib/commands/database-rules-release.js +2 -1
  31. package/lib/commands/database-rules-stage.js +2 -1
  32. package/lib/commands/database-set.js +2 -1
  33. package/lib/commands/database-settings-get.js +2 -1
  34. package/lib/commands/database-settings-set.js +2 -1
  35. package/lib/commands/database-update.js +2 -1
  36. package/lib/commands/deploy.js +23 -21
  37. package/lib/commands/emulators-exec.js +2 -1
  38. package/lib/commands/emulators-export.js +2 -1
  39. package/lib/commands/emulators-start.js +2 -1
  40. package/lib/commands/experimental-functions-shell.js +10 -8
  41. package/lib/commands/ext-configure.js +56 -120
  42. package/lib/commands/ext-dev-deprecate.js +2 -1
  43. package/lib/commands/ext-dev-emulators-exec.js +13 -7
  44. package/lib/commands/ext-dev-emulators-start.js +12 -27
  45. package/lib/commands/ext-dev-extension-delete.js +2 -1
  46. package/lib/commands/ext-dev-init.js +2 -1
  47. package/lib/commands/ext-dev-list.js +2 -1
  48. package/lib/commands/ext-dev-publish.js +2 -1
  49. package/lib/commands/ext-dev-register.js +2 -1
  50. package/lib/commands/ext-dev-undeprecate.js +2 -1
  51. package/lib/commands/ext-dev-unpublish.js +2 -1
  52. package/lib/commands/ext-dev-usage.js +2 -1
  53. package/lib/commands/ext-export.js +2 -1
  54. package/lib/commands/ext-info.js +2 -1
  55. package/lib/commands/ext-install.js +14 -198
  56. package/lib/commands/ext-list.js +2 -1
  57. package/lib/commands/ext-sources-create.js +2 -1
  58. package/lib/commands/ext-uninstall.js +9 -92
  59. package/lib/commands/ext-update.js +67 -225
  60. package/lib/commands/ext.js +2 -1
  61. package/lib/commands/firestore-delete.js +2 -1
  62. package/lib/commands/firestore-indexes-list.js +2 -1
  63. package/lib/commands/functions-config-clone.js +4 -3
  64. package/lib/commands/functions-config-export.js +2 -1
  65. package/lib/commands/functions-config-get.js +2 -1
  66. package/lib/commands/functions-config-set.js +2 -1
  67. package/lib/commands/functions-config-unset.js +2 -1
  68. package/lib/commands/functions-delete.js +2 -1
  69. package/lib/commands/functions-deletegcfartifacts.js +2 -1
  70. package/lib/commands/functions-list.js +2 -1
  71. package/lib/commands/functions-log.js +2 -1
  72. package/lib/commands/functions-secrets-access.js +2 -1
  73. package/lib/commands/functions-secrets-destroy.js +2 -1
  74. package/lib/commands/functions-secrets-get.js +2 -1
  75. package/lib/commands/functions-secrets-prune.js +2 -1
  76. package/lib/commands/functions-secrets-set.js +2 -1
  77. package/lib/commands/functions-shell.js +12 -10
  78. package/lib/commands/help.js +2 -1
  79. package/lib/commands/hosting-channel-create.js +2 -1
  80. package/lib/commands/hosting-channel-delete.js +2 -1
  81. package/lib/commands/hosting-channel-deploy.js +2 -1
  82. package/lib/commands/hosting-channel-list.js +2 -1
  83. package/lib/commands/hosting-channel-open.js +2 -1
  84. package/lib/commands/hosting-clone.js +2 -1
  85. package/lib/commands/hosting-disable.js +2 -1
  86. package/lib/commands/hosting-sites-create.js +2 -1
  87. package/lib/commands/hosting-sites-delete.js +2 -1
  88. package/lib/commands/hosting-sites-get.js +2 -1
  89. package/lib/commands/hosting-sites-list.js +2 -1
  90. package/lib/commands/index.js +23 -13
  91. package/lib/commands/init.js +47 -43
  92. package/lib/commands/login-add.js +2 -1
  93. package/lib/commands/login-ci.js +2 -1
  94. package/lib/commands/login-list.js +2 -1
  95. package/lib/commands/login-use.js +2 -1
  96. package/lib/commands/login.js +2 -1
  97. package/lib/commands/logout.js +2 -1
  98. package/lib/commands/open.js +2 -1
  99. package/lib/commands/projects-addfirebase.js +2 -1
  100. package/lib/commands/projects-create.js +2 -1
  101. package/lib/commands/projects-list.js +2 -1
  102. package/lib/commands/remoteconfig-get.js +2 -1
  103. package/lib/commands/remoteconfig-rollback.js +2 -1
  104. package/lib/commands/remoteconfig-versions-list.js +2 -1
  105. package/lib/commands/serve.js +29 -27
  106. package/lib/commands/setup-emulators-database.js +2 -1
  107. package/lib/commands/setup-emulators-firestore.js +2 -1
  108. package/lib/commands/setup-emulators-pubsub.js +2 -1
  109. package/lib/commands/setup-emulators-storage.js +2 -1
  110. package/lib/commands/setup-emulators-ui.js +2 -1
  111. package/lib/commands/target-apply.js +2 -1
  112. package/lib/commands/target-clear.js +2 -1
  113. package/lib/commands/target-remove.js +2 -1
  114. package/lib/commands/target.js +2 -1
  115. package/lib/commands/use.js +54 -52
  116. package/lib/config.js +3 -3
  117. package/lib/deploy/database/deploy.js +3 -2
  118. package/lib/deploy/database/index.js +8 -5
  119. package/lib/deploy/database/prepare.js +22 -19
  120. package/lib/deploy/database/release.js +12 -9
  121. package/lib/deploy/firestore/prepare.js +2 -2
  122. package/lib/deploy/functions/build.js +32 -20
  123. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +187 -54
  124. package/lib/deploy/functions/runtimes/node/parseTriggers.js +14 -2
  125. package/lib/deploy/functions/services/database.js +14 -0
  126. package/lib/deploy/functions/services/index.js +14 -0
  127. package/lib/deploy/index.js +3 -3
  128. package/lib/deploy/lifecycleHooks.js +23 -20
  129. package/lib/deploy/remoteconfig/functions.js +18 -14
  130. package/lib/deploy/remoteconfig/prepare.js +2 -2
  131. package/lib/emulator/auth/apiSpec.js +14 -46
  132. package/lib/emulator/auth/operations.js +6 -29
  133. package/lib/emulator/auth/state.js +2 -25
  134. package/lib/emulator/commandUtils.js +1 -1
  135. package/lib/emulator/controller.js +3 -3
  136. package/lib/emulator/databaseEmulator.js +9 -7
  137. package/lib/emulator/downloadableEmulators.js +6 -6
  138. package/lib/emulator/extensionsEmulator.js +7 -3
  139. package/lib/emulator/firestoreEmulator.js +10 -12
  140. package/lib/emulator/functionsEmulator.js +39 -42
  141. package/lib/emulator/hubClient.js +11 -22
  142. package/lib/emulator/hubExport.js +26 -16
  143. package/lib/emulator/portUtils.js +2 -0
  144. package/lib/emulator/storage/crc.js +3 -0
  145. package/lib/emulator/storage/rules/runtime.js +1 -1
  146. package/lib/errorOut.js +2 -2
  147. package/lib/extensions/extensionsHelper.js +4 -5
  148. package/lib/extensions/manifest.js +5 -11
  149. package/lib/firebaseConfigValidate.js +1 -1
  150. package/lib/firestore/checkDatabaseType.js +4 -5
  151. package/lib/firestore/indexes.js +17 -34
  152. package/lib/functions/events/v2.js +7 -1
  153. package/lib/functionsConfigClone.js +43 -41
  154. package/lib/gcp/cloudfunctionsv2.js +17 -2
  155. package/lib/gcp/iam.js +1 -1
  156. package/lib/gcp/index.js +10 -10
  157. package/lib/gcp/runtimeconfig.js +45 -47
  158. package/lib/gcp/storage.js +2 -4
  159. package/lib/hosting/cloudRunProxy.js +19 -15
  160. package/lib/index.js +29 -28
  161. package/lib/init/features/database.js +11 -5
  162. package/lib/init/features/functions/index.js +1 -1
  163. package/lib/init/features/functions/javascript.js +23 -20
  164. package/lib/init/features/functions/npm-dependencies.js +17 -14
  165. package/lib/init/features/functions/typescript.js +27 -24
  166. package/lib/init/features/hosting/github.js +5 -4
  167. package/lib/loadCJSON.js +9 -6
  168. package/lib/logError.js +15 -12
  169. package/lib/management/apps.js +47 -43
  170. package/lib/management/database.js +33 -31
  171. package/lib/management/projects.js +13 -7
  172. package/lib/parseBoltRules.js +15 -14
  173. package/lib/profileReport.js +503 -511
  174. package/lib/profiler.js +4 -4
  175. package/lib/requireAuth.js +0 -1
  176. package/lib/responseToError.js +8 -5
  177. package/lib/rtdb.js +31 -29
  178. package/lib/scopes.js +9 -9
  179. package/npm-shrinkwrap.json +1485 -670
  180. package/package.json +21 -22
  181. package/standalone/package.json +1 -1
package/lib/auth.js CHANGED
@@ -2,15 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logout = exports.getAccessToken = exports.findAccountByEmail = exports.loginGithub = exports.loginGoogle = exports.setGlobalDefaultAccount = exports.setProjectAccount = exports.loginAdditionalAccount = exports.selectAccount = exports.setRefreshToken = exports.setActiveAccount = exports.getAllAccounts = exports.getAdditionalAccounts = exports.getProjectDefaultAccount = exports.getGlobalDefaultAccount = void 0;
4
4
  const clc = require("cli-color");
5
+ const FormData = require("form-data");
5
6
  const fs = require("fs");
6
- const jwt = require("jsonwebtoken");
7
7
  const http = require("http");
8
+ const jwt = require("jsonwebtoken");
8
9
  const opn = require("open");
9
10
  const path = require("path");
10
11
  const portfinder = require("portfinder");
11
12
  const url = require("url");
12
13
  const util = require("util");
13
- const api = require("./api");
14
14
  const apiv2 = require("./apiv2");
15
15
  const configstore_1 = require("./configstore");
16
16
  const error_1 = require("./error");
@@ -23,6 +23,7 @@ const uuid_1 = require("uuid");
23
23
  const crypto_1 = require("crypto");
24
24
  const cli_color_1 = require("cli-color");
25
25
  const track_1 = require("./track");
26
+ const api_1 = require("./api");
26
27
  portfinder.basePort = 9005;
27
28
  function getGlobalDefaultAccount() {
28
29
  const user = configstore_1.configstore.get("user");
@@ -72,7 +73,6 @@ function setActiveAccount(options, account) {
72
73
  }
73
74
  exports.setActiveAccount = setActiveAccount;
74
75
  function setRefreshToken(token) {
75
- api.setRefreshToken(token);
76
76
  apiv2.setRefreshToken(token);
77
77
  }
78
78
  exports.setRefreshToken = setRefreshToken;
@@ -175,10 +175,10 @@ function queryParamString(args) {
175
175
  return tokens.join("&");
176
176
  }
177
177
  function getLoginUrl(callbackUrl, userHint) {
178
- return (api.authOrigin +
178
+ return (api_1.authOrigin +
179
179
  "/o/oauth2/auth?" +
180
180
  queryParamString({
181
- client_id: api.clientId,
181
+ client_id: api_1.clientId,
182
182
  scope: SCOPES.join(" "),
183
183
  response_type: "code",
184
184
  state: _nonce,
@@ -187,22 +187,29 @@ function getLoginUrl(callbackUrl, userHint) {
187
187
  }));
188
188
  }
189
189
  async function getTokensFromAuthorizationCode(code, callbackUrl, verifier) {
190
- var _a, _b;
191
- let res;
192
190
  const params = {
193
191
  code: code,
194
- client_id: api.clientId,
195
- client_secret: api.clientSecret,
192
+ client_id: api_1.clientId,
193
+ client_secret: api_1.clientSecret,
196
194
  redirect_uri: callbackUrl,
197
195
  grant_type: "authorization_code",
198
196
  };
199
197
  if (verifier) {
200
198
  params["code_verifier"] = verifier;
201
199
  }
200
+ let res;
202
201
  try {
203
- res = await api.request("POST", "/o/oauth2/token", {
204
- origin: api.authOrigin,
205
- form: params,
202
+ const client = new apiv2.Client({ urlPrefix: api_1.authOrigin, auth: false });
203
+ const form = new FormData();
204
+ for (const [k, v] of Object.entries(params)) {
205
+ form.append(k, v);
206
+ }
207
+ res = await client.request({
208
+ method: "POST",
209
+ path: "/o/oauth2/token",
210
+ body: form,
211
+ headers: form.getHeaders(),
212
+ skipLog: { body: true, queryParams: true, resBody: true },
206
213
  });
207
214
  }
208
215
  catch (err) {
@@ -214,8 +221,8 @@ async function getTokensFromAuthorizationCode(code, callbackUrl, verifier) {
214
221
  }
215
222
  throw invalidCredentialError();
216
223
  }
217
- if (!((_a = res === null || res === void 0 ? void 0 : res.body) === null || _a === void 0 ? void 0 : _a.access_token) && !((_b = res === null || res === void 0 ? void 0 : res.body) === null || _b === void 0 ? void 0 : _b.refresh_token)) {
218
- logger_1.logger.debug("Token Fetch Error:", res.statusCode, res.body);
224
+ if (!res.body.access_token && !res.body.refresh_token) {
225
+ logger_1.logger.debug("Token Fetch Error:", res.status, res.body);
219
226
  throw invalidCredentialError();
220
227
  }
221
228
  lastAccessToken = Object.assign({
@@ -225,25 +232,35 @@ async function getTokensFromAuthorizationCode(code, callbackUrl, verifier) {
225
232
  }
226
233
  const GITHUB_SCOPES = ["read:user", "repo", "public_repo"];
227
234
  function getGithubLoginUrl(callbackUrl) {
228
- return (api.githubOrigin +
235
+ return (api_1.githubOrigin +
229
236
  "/login/oauth/authorize?" +
230
237
  queryParamString({
231
- client_id: api.githubClientId,
238
+ client_id: api_1.githubClientId,
232
239
  state: _nonce,
233
240
  redirect_uri: callbackUrl,
234
241
  scope: GITHUB_SCOPES.join(" "),
235
242
  }));
236
243
  }
237
244
  async function getGithubTokensFromAuthorizationCode(code, callbackUrl) {
238
- const res = await api.request("POST", "/login/oauth/access_token", {
239
- origin: api.githubOrigin,
240
- form: {
241
- client_id: api.githubClientId,
242
- client_secret: api.githubClientSecret,
243
- code,
244
- redirect_uri: callbackUrl,
245
- state: _nonce,
246
- },
245
+ const client = new apiv2.Client({ urlPrefix: api_1.githubOrigin, auth: false });
246
+ const data = {
247
+ client_id: api_1.githubClientId,
248
+ client_secret: api_1.githubClientSecret,
249
+ code,
250
+ redirect_uri: callbackUrl,
251
+ state: _nonce,
252
+ };
253
+ const form = new FormData();
254
+ for (const [k, v] of Object.entries(data)) {
255
+ form.append(k, v);
256
+ }
257
+ const headers = form.getHeaders();
258
+ headers.accept = "application/json";
259
+ const res = await client.request({
260
+ method: "POST",
261
+ path: "/login/oauth/access_token",
262
+ body: form,
263
+ headers,
247
264
  });
248
265
  return res.body.access_token;
249
266
  }
@@ -262,7 +279,7 @@ function urlsafeBase64(base64string) {
262
279
  async function loginRemotely(userHint) {
263
280
  var _a;
264
281
  const authProxyClient = new apiv2.Client({
265
- urlPrefix: api.authProxyOrigin,
282
+ urlPrefix: api_1.authProxyOrigin,
266
283
  auth: false,
267
284
  });
268
285
  const sessionId = (0, uuid_1.v4)();
@@ -271,7 +288,7 @@ async function loginRemotely(userHint) {
271
288
  const attestToken = (_a = (await authProxyClient.post("/attest", {
272
289
  session_id: sessionId,
273
290
  })).body) === null || _a === void 0 ? void 0 : _a.token;
274
- const loginUrl = `${api.authProxyOrigin}/login?code_challenge=${codeChallenge}&session=${sessionId}&attest=${attestToken}`;
291
+ const loginUrl = `${api_1.authProxyOrigin}/login?code_challenge=${codeChallenge}&session=${sessionId}&attest=${attestToken}`;
275
292
  logger_1.logger.info();
276
293
  logger_1.logger.info("To sign in to the Firebase CLI:");
277
294
  logger_1.logger.info();
@@ -290,7 +307,7 @@ async function loginRemotely(userHint) {
290
307
  message: "Enter authorization code:",
291
308
  });
292
309
  try {
293
- const tokens = await getTokensFromAuthorizationCode(code, `${api.authProxyOrigin}/complete`, codeVerifier);
310
+ const tokens = await getTokensFromAuthorizationCode(code, `${api_1.authProxyOrigin}/complete`, codeVerifier);
294
311
  void (0, track_1.track)("login", "google_remote");
295
312
  return {
296
313
  user: jwt.decode(tokens.id_token),
@@ -442,24 +459,33 @@ function logoutCurrentSession(refreshToken) {
442
459
  deleteAccount(account);
443
460
  }
444
461
  async function refreshTokens(refreshToken, authScopes) {
445
- var _a, _b, _c;
462
+ var _a, _b;
446
463
  logger_1.logger.debug("> refreshing access token with scopes:", JSON.stringify(authScopes));
447
464
  try {
448
- const res = await api.request("POST", "/oauth2/v3/token", {
449
- origin: api.googleOrigin,
450
- form: {
451
- refresh_token: refreshToken,
452
- client_id: api.clientId,
453
- client_secret: api.clientSecret,
454
- grant_type: "refresh_token",
455
- scope: (authScopes || []).join(" "),
456
- },
457
- logOptions: { skipRequestBody: true, skipQueryParams: true, skipResponseBody: true },
465
+ const client = new apiv2.Client({ urlPrefix: api_1.googleOrigin, auth: false });
466
+ const data = {
467
+ refresh_token: refreshToken,
468
+ client_id: api_1.clientId,
469
+ client_secret: api_1.clientSecret,
470
+ grant_type: "refresh_token",
471
+ scope: (authScopes || []).join(" "),
472
+ };
473
+ const form = new FormData();
474
+ for (const [k, v] of Object.entries(data)) {
475
+ form.append(k, v);
476
+ }
477
+ const res = await client.request({
478
+ method: "POST",
479
+ path: "/oauth2/v3/token",
480
+ body: form,
481
+ headers: form.getHeaders(),
482
+ skipLog: { body: true, queryParams: true, resBody: true },
483
+ resolveOnHTTPError: true,
458
484
  });
459
485
  if (res.status === 401 || res.status === 400) {
460
486
  return { access_token: refreshToken };
461
487
  }
462
- if (typeof ((_a = res.body) === null || _a === void 0 ? void 0 : _a.access_token) !== "string") {
488
+ if (typeof res.body.access_token !== "string") {
463
489
  throw invalidCredentialError();
464
490
  }
465
491
  lastAccessToken = Object.assign({
@@ -475,7 +501,7 @@ async function refreshTokens(refreshToken, authScopes) {
475
501
  return lastAccessToken;
476
502
  }
477
503
  catch (err) {
478
- if (((_c = (_b = err === null || err === void 0 ? void 0 : err.context) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.error) === "invalid_scope") {
504
+ if (((_b = (_a = err === null || err === void 0 ? void 0 : err.context) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.error) === "invalid_scope") {
479
505
  throw new error_1.FirebaseError("This command requires new authorization scopes not granted to your current session. Please run " +
480
506
  clc.bold("firebase login --reauth") +
481
507
  "\n\n" +
@@ -498,12 +524,8 @@ async function logout(refreshToken) {
498
524
  }
499
525
  logoutCurrentSession(refreshToken);
500
526
  try {
501
- await api.request("GET", "/o/oauth2/revoke", {
502
- origin: api.authOrigin,
503
- data: {
504
- token: refreshToken,
505
- },
506
- });
527
+ const client = new apiv2.Client({ urlPrefix: api_1.authOrigin, auth: false });
528
+ await client.get("/o/oauth2/revoke", { queryParams: { token: refreshToken } });
507
529
  }
508
530
  catch (thrown) {
509
531
  const err = thrown instanceof Error ? thrown : new Error(thrown);
@@ -1,42 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
3
4
  const semver = require("semver");
4
5
  const pkg = require("../../package.json");
5
6
  const nodeVersion = process.version;
6
7
  if (!semver.satisfies(nodeVersion, pkg.engines.node)) {
7
- console.error("Firebase CLI v" +
8
- pkg.version +
9
- " is incompatible with Node.js " +
10
- nodeVersion +
11
- " Please upgrade Node.js to version " +
12
- pkg.engines.node);
8
+ console.error(`Firebase CLI v${pkg.version} is incompatible with Node.js ${nodeVersion} Please upgrade Node.js to version ${pkg.engines.node}`);
13
9
  process.exit(1);
14
10
  }
15
- const updateNotifier = require("update-notifier")({ pkg: pkg });
11
+ const updateNotifierPkg = require("update-notifier");
16
12
  const clc = require("cli-color");
17
13
  const TerminalRenderer = require("marked-terminal");
18
- const marked = require("marked").marked;
19
- marked.setOptions({
14
+ const updateNotifier = updateNotifierPkg({ pkg: pkg });
15
+ const marked_1 = require("marked");
16
+ marked_1.marked.setOptions({
20
17
  renderer: new TerminalRenderer(),
21
18
  });
22
19
  const updateMessage = `Update available ${clc.xterm(240)("{currentVersion}")} → ${clc.green("{latestVersion}")}\n` +
23
20
  `To update to the latest version using npm, run\n${clc.cyan("npm install -g firebase-tools")}\n` +
24
- `For other CLI management options, visit the ${marked("[CLI documentation](https://firebase.google.com/docs/cli#update-cli)")}`;
21
+ `For other CLI management options, visit the ${(0, marked_1.marked)("[CLI documentation](https://firebase.google.com/docs/cli#update-cli)")}`;
25
22
  updateNotifier.notify({ defer: true, isGlobal: true, message: updateMessage });
23
+ const node_path_1 = require("node:path");
24
+ const triple_beam_1 = require("triple-beam");
25
+ const cli_color_1 = require("cli-color");
26
+ const fs = require("node:fs");
27
+ const configstore_1 = require("../configstore");
28
+ const errorOut_1 = require("../errorOut");
29
+ const handlePreviewToggles_1 = require("../handlePreviewToggles");
30
+ const logger_1 = require("../logger");
26
31
  const client = require("..");
27
- const errorOut = require("../errorOut").errorOut;
28
- const winston = require("winston");
29
- const { SPLAT } = require("triple-beam");
30
- const { logger } = require("../logger");
31
- const fs = require("fs");
32
32
  const fsutils = require("../fsutils");
33
- const path = require("path");
34
- const ansiStrip = require("cli-color/strip");
35
- const { configstore } = require("../configstore");
36
- const _ = require("lodash");
37
- let args = process.argv.slice(2);
38
- const { handlePreviewToggles } = require("../handlePreviewToggles");
39
33
  const utils = require("../utils");
34
+ const winston = require("winston");
35
+ let args = process.argv.slice(2);
40
36
  let cmd;
41
37
  function findAvailableLogFile() {
42
38
  const candidates = ["firebase-debug.log"];
@@ -44,7 +40,7 @@ function findAvailableLogFile() {
44
40
  candidates.push(`firebase-debug.${i}.log`);
45
41
  }
46
42
  for (const c of candidates) {
47
- const logFilename = path.join(process.cwd(), c);
43
+ const logFilename = (0, node_path_1.join)(process.cwd(), c);
48
44
  try {
49
45
  const fd = fs.openSync(logFilename, "r+");
50
46
  fs.closeSync(fd);
@@ -59,43 +55,43 @@ function findAvailableLogFile() {
59
55
  throw new Error("Unable to obtain permissions for firebase-debug.log");
60
56
  }
61
57
  const logFilename = findAvailableLogFile();
62
- if (!process.env.DEBUG && _.includes(args, "--debug")) {
58
+ if (!process.env.DEBUG && args.includes("--debug")) {
63
59
  process.env.DEBUG = "true";
64
60
  }
65
61
  process.env.IS_FIREBASE_CLI = "true";
66
- logger.add(new winston.transports.File({
62
+ logger_1.logger.add(new winston.transports.File({
67
63
  level: "debug",
68
64
  filename: logFilename,
69
65
  format: winston.format.printf((info) => {
70
- const segments = [info.message, ...(info[SPLAT] || [])].map(utils.tryStringify);
71
- return `[${info.level}] ${ansiStrip(segments.join(" "))}`;
66
+ const segments = [info.message, ...(info[triple_beam_1.SPLAT] || [])].map(utils.tryStringify);
67
+ return `[${info.level}] ${(0, cli_color_1.strip)(segments.join(" "))}`;
72
68
  }),
73
69
  }));
74
- logger.debug(_.repeat("-", 70));
75
- logger.debug("Command: ", process.argv.join(" "));
76
- logger.debug("CLI Version: ", pkg.version);
77
- logger.debug("Platform: ", process.platform);
78
- logger.debug("Node Version: ", process.version);
79
- logger.debug("Time: ", new Date().toString());
70
+ logger_1.logger.debug("-".repeat(70));
71
+ logger_1.logger.debug("Command: ", process.argv.join(" "));
72
+ logger_1.logger.debug("CLI Version: ", pkg.version);
73
+ logger_1.logger.debug("Platform: ", process.platform);
74
+ logger_1.logger.debug("Node Version: ", process.version);
75
+ logger_1.logger.debug("Time: ", new Date().toString());
80
76
  if (utils.envOverrides.length) {
81
- logger.debug("Env Overrides:", utils.envOverrides.join(", "));
77
+ logger_1.logger.debug("Env Overrides:", utils.envOverrides.join(", "));
82
78
  }
83
- logger.debug(_.repeat("-", 70));
84
- logger.debug();
85
- require("../fetchMOTD").fetchMOTD();
86
- process.on("exit", function (code) {
79
+ logger_1.logger.debug("-".repeat(70));
80
+ logger_1.logger.debug();
81
+ const fetchMOTD_1 = require("../fetchMOTD");
82
+ (0, fetchMOTD_1.fetchMOTD)();
83
+ process.on("exit", (code) => {
87
84
  code = process.exitCode || code;
88
85
  if (!process.env.DEBUG && code < 2 && fsutils.fileExistsSync(logFilename)) {
89
86
  fs.unlinkSync(logFilename);
90
87
  }
91
88
  if (code > 0 && process.stdout.isTTY) {
92
- const lastError = configstore.get("lastError") || 0;
89
+ const lastError = configstore_1.configstore.get("lastError") || 0;
93
90
  const timestamp = Date.now();
94
91
  if (lastError > timestamp - 120000) {
95
92
  let help;
96
93
  if (code === 1 && cmd) {
97
- const commandName = _.get(_.last(cmd.args), "_name", "[command]");
98
- help = "Having trouble? Try " + clc.bold("firebase " + commandName + " --help");
94
+ help = "Having trouble? Try " + clc.bold("firebase [command] --help");
99
95
  }
100
96
  else {
101
97
  help = "Having trouble? Try again or contact support with contents of firebase-debug.log";
@@ -105,19 +101,18 @@ process.on("exit", function (code) {
105
101
  console.log(help);
106
102
  }
107
103
  }
108
- configstore.set("lastError", timestamp);
104
+ configstore_1.configstore.set("lastError", timestamp);
109
105
  }
110
106
  else {
111
- configstore.delete("lastError");
107
+ configstore_1.configstore.delete("lastError");
112
108
  }
113
109
  });
114
- require("exit-code");
115
- process.on("uncaughtException", function (err) {
116
- errorOut(err);
110
+ process.on("uncaughtException", (err) => {
111
+ (0, errorOut_1.errorOut)(err);
117
112
  });
118
- if (!handlePreviewToggles(args)) {
113
+ if (!(0, handlePreviewToggles_1.handlePreviewToggles)(args)) {
119
114
  cmd = client.cli.parse(process.argv);
120
- args = args.filter(function (arg) {
115
+ args = args.filter((arg) => {
121
116
  return arg.indexOf("-") < 0;
122
117
  });
123
118
  if (!args.length) {
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
- var _ = require("lodash");
3
- var { FirebaseError } = require("./error");
4
- module.exports = function (options) {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkValidTargetFilters = void 0;
4
+ const _ = require("lodash");
5
+ const error_1 = require("./error");
6
+ function checkValidTargetFilters(options) {
5
7
  function numFilters(targetTypes) {
6
- return _.filter(options.only, function (opt) {
7
- var optChunks = opt.split(":");
8
+ return _.filter(options.only, (opt) => {
9
+ const optChunks = opt.split(":");
8
10
  return _.includes(targetTypes, optChunks[0]) && optChunks.length > 1;
9
11
  }).length;
10
12
  }
@@ -14,21 +16,20 @@ module.exports = function (options) {
14
16
  function targetDoesNotContainFilter(targetTypes) {
15
17
  return numFilters(targetTypes) === 0;
16
18
  }
17
- return new Promise(function (resolve, reject) {
19
+ return new Promise((resolve, reject) => {
18
20
  if (!options.only) {
19
21
  return resolve();
20
22
  }
21
23
  if (options.except) {
22
- return reject(new FirebaseError("Cannot specify both --only and --except", {
23
- exit: 1,
24
- }));
24
+ return reject(new error_1.FirebaseError("Cannot specify both --only and --except"));
25
25
  }
26
26
  if (targetContainsFilter(["database", "storage", "hosting"])) {
27
- return reject(new FirebaseError("Filters specified with colons (e.g. --only functions:func1,functions:func2) are only supported for functions", { exit: 1 }));
27
+ return reject(new error_1.FirebaseError("Filters specified with colons (e.g. --only functions:func1,functions:func2) are only supported for functions"));
28
28
  }
29
29
  if (targetContainsFilter(["functions"]) && targetDoesNotContainFilter(["functions"])) {
30
- return reject(new FirebaseError('Cannot specify "--only functions" and "--only functions:<filter>" at the same time', { exit: 1 }));
30
+ return reject(new error_1.FirebaseError('Cannot specify "--only functions" and "--only functions:<filter>" at the same time'));
31
31
  }
32
32
  return resolve();
33
33
  });
34
- };
34
+ }
35
+ exports.checkValidTargetFilters = checkValidTargetFilters;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const fs = require("fs-extra");
4
5
  const command_1 = require("../command");
5
6
  const utils = require("../utils");
@@ -18,7 +19,7 @@ function getReleaseNotes(releaseNotes, releaseNotesFile) {
18
19
  }
19
20
  return "";
20
21
  }
21
- module.exports = new command_1.Command("appdistribution:distribute <release-binary-file>")
22
+ exports.command = new command_1.Command("appdistribution:distribute <release-binary-file>")
22
23
  .description("upload a release binary")
23
24
  .option("--app <app_id>", "the app id of your Firebase app")
24
25
  .option("--release-notes <string>", "release notes to include")
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const command_1 = require("../command");
4
5
  const utils = require("../utils");
5
6
  const requireAuth_1 = require("../requireAuth");
6
7
  const client_1 = require("../appdistribution/client");
7
8
  const options_parser_util_1 = require("../appdistribution/options-parser-util");
8
- module.exports = new command_1.Command("appdistribution:testers:add [emails...]")
9
+ exports.command = new command_1.Command("appdistribution:testers:add [emails...]")
9
10
  .description("add testers to project")
10
11
  .option("--file <file>", "a path to a file containing a list of tester emails to be added")
11
12
  .before(requireAuth_1.requireAuth)
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const command_1 = require("../command");
4
5
  const utils = require("../utils");
5
6
  const requireAuth_1 = require("../requireAuth");
@@ -7,7 +8,7 @@ const error_1 = require("../error");
7
8
  const client_1 = require("../appdistribution/client");
8
9
  const options_parser_util_1 = require("../appdistribution/options-parser-util");
9
10
  const logger_1 = require("../logger");
10
- module.exports = new command_1.Command("appdistribution:testers:remove [emails...]")
11
+ exports.command = new command_1.Command("appdistribution:testers:remove [emails...]")
11
12
  .description("remove testers from a project")
12
13
  .option("--file <file>", "a path to a file containing a list of tester emails to be removed")
13
14
  .before(requireAuth_1.requireAuth)
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const clc = require("cli-color");
4
5
  const command_1 = require("../command");
5
6
  const projectUtils_1 = require("../projectUtils");
@@ -15,7 +16,7 @@ function getCertHashType(shaHash) {
15
16
  return apps_1.ShaCertificateType.SHA_256.toString();
16
17
  return apps_1.ShaCertificateType.SHA_CERTIFICATE_TYPE_UNSPECIFIED.toString();
17
18
  }
18
- module.exports = new command_1.Command("apps:android:sha:create <appId> <shaHash>")
19
+ exports.command = new command_1.Command("apps:android:sha:create <appId> <shaHash>")
19
20
  .description("add a SHA certificate hash for a given app id.")
20
21
  .before(requireAuth_1.requireAuth)
21
22
  .action(async (appId = "", shaHash = "", options) => {
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const clc = require("cli-color");
4
5
  const command_1 = require("../command");
5
6
  const projectUtils_1 = require("../projectUtils");
6
7
  const apps_1 = require("../management/apps");
7
8
  const requireAuth_1 = require("../requireAuth");
8
9
  const utils_1 = require("../utils");
9
- module.exports = new command_1.Command("apps:android:sha:delete <appId> <shaId>")
10
+ exports.command = new command_1.Command("apps:android:sha:delete <appId> <shaId>")
10
11
  .description("delete a SHA certificate hash for a given app id.")
11
12
  .before(requireAuth_1.requireAuth)
12
13
  .action(async (appId = "", shaId = "", options) => {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const Table = require("cli-table");
4
5
  const command_1 = require("../command");
5
6
  const projectUtils_1 = require("../projectUtils");
@@ -29,7 +30,7 @@ function logCertificatesCount(count = 0) {
29
30
  logger_1.logger.info("");
30
31
  logger_1.logger.info(`${count} SHA hash(es) total.`);
31
32
  }
32
- module.exports = new command_1.Command("apps:android:sha:list <appId>")
33
+ exports.command = new command_1.Command("apps:android:sha:list <appId>")
33
34
  .description("list the SHA certificate hashes for a given app id. ")
34
35
  .before(requireAuth_1.requireAuth)
35
36
  .action(async (appId = "", options) => {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const clc = require("cli-color");
4
5
  const ora = require("ora");
5
6
  const command_1 = require("../command");
@@ -121,7 +122,7 @@ async function initiateWebAppCreation(options) {
121
122
  throw err;
122
123
  }
123
124
  }
124
- module.exports = new command_1.Command("apps:create [platform] [displayName]")
125
+ exports.command = new command_1.Command("apps:create [platform] [displayName]")
125
126
  .description("create a new Firebase app. [platform] can be IOS, ANDROID or WEB (case insensitive).")
126
127
  .option("-a, --package-name <packageName>", "required package name for the Android app")
127
128
  .option("-b, --bundle-id <bundleId>", "required bundle id for the iOS app")
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const clc = require("cli-color");
4
5
  const ora = require("ora");
5
6
  const Table = require("cli-table");
@@ -28,7 +29,7 @@ function logAppCount(count = 0) {
28
29
  logger_1.logger.info("");
29
30
  logger_1.logger.info(`${count} app(s) total.`);
30
31
  }
31
- module.exports = new command_1.Command("apps:list [platform]")
32
+ exports.command = new command_1.Command("apps:list [platform]")
32
33
  .description("list the registered apps of a Firebase project. " +
33
34
  "Optionally filter apps by [platform]: IOS, ANDROID or WEB (case insensitive)")
34
35
  .before(requireAuth_1.requireAuth)
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const ora = require("ora");
4
5
  const fs = require("fs-extra");
5
6
  const command_1 = require("../command");
@@ -10,11 +11,14 @@ const error_1 = require("../error");
10
11
  const requireAuth_1 = require("../requireAuth");
11
12
  const logger_1 = require("../logger");
12
13
  const prompt_1 = require("../prompt");
13
- async function selectAppInteractively(apps, appPlatform) {
14
- if (apps.length === 0) {
14
+ function checkForApps(apps, appPlatform) {
15
+ if (!apps.length) {
15
16
  throw new error_1.FirebaseError(`There are no ${appPlatform === apps_1.AppPlatform.ANY ? "" : appPlatform + " "}apps ` +
16
17
  "associated with this Firebase project");
17
18
  }
19
+ }
20
+ async function selectAppInteractively(apps, appPlatform) {
21
+ checkForApps(apps, appPlatform);
18
22
  const choices = apps.map((app) => {
19
23
  return {
20
24
  name: `${app.displayName || app.bundleId || app.packageName}` +
@@ -29,7 +33,7 @@ async function selectAppInteractively(apps, appPlatform) {
29
33
  choices,
30
34
  });
31
35
  }
32
- module.exports = new command_1.Command("apps:sdkconfig [platform] [appId]")
36
+ exports.command = new command_1.Command("apps:sdkconfig [platform] [appId]")
33
37
  .description("print the Google Services config of a Firebase app. " +
34
38
  "[platform] can be IOS, ANDROID or WEB (case insensitive)")
35
39
  .option("-o, --out [file]", "(optional) write config output to a file")
@@ -46,6 +50,7 @@ module.exports = new command_1.Command("apps:sdkconfig [platform] [appId]")
46
50
  projectId = result.projectId;
47
51
  }
48
52
  const apps = await (0, apps_1.listFirebaseApps)(projectId, appPlatform);
53
+ checkForApps(apps, appPlatform);
49
54
  if (apps.length === 1) {
50
55
  appId = apps[0].appId;
51
56
  appPlatform = apps[0].platform;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
3
4
  const clc = require("cli-color");
4
5
  const fs = require("fs");
5
6
  const os = require("os");
@@ -9,7 +10,7 @@ const projectUtils_1 = require("../projectUtils");
9
10
  const requirePermissions_1 = require("../requirePermissions");
10
11
  const accountExporter_1 = require("../accountExporter");
11
12
  const MAX_BATCH_SIZE = 1000;
12
- exports.default = new command_1.Command("auth:export [dataFile]")
13
+ exports.command = new command_1.Command("auth:export [dataFile]")
13
14
  .description("Export accounts from your Firebase project into a data file")
14
15
  .option("--format <format>", "Format of exported data (csv, json). Ignored if <dataFile> has format extension.")
15
16
  .before(requirePermissions_1.requirePermissions, ["firebaseauth.users.get"])