firebase-tools-with-isolate 13.16.0 → 13.26.0-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 (221) hide show
  1. package/lib/api.js +3 -1
  2. package/lib/apiv2.js +10 -3
  3. package/lib/appdistribution/client.js +62 -8
  4. package/lib/appdistribution/distribution.js +1 -1
  5. package/lib/apphosting/backend.js +299 -0
  6. package/lib/apphosting/config.js +31 -8
  7. package/lib/apphosting/githubConnections.js +70 -22
  8. package/lib/apphosting/index.js +3 -312
  9. package/lib/apphosting/rollout.js +138 -0
  10. package/lib/apphosting/secrets/index.js +70 -5
  11. package/lib/apphosting/utils.js +41 -0
  12. package/lib/apphosting/yaml.js +82 -0
  13. package/lib/archiveDirectory.js +1 -1
  14. package/lib/auth.js +31 -5
  15. package/lib/bin/firebase.js +2 -2
  16. package/lib/command.js +18 -4
  17. package/lib/commands/appdistribution-distribute.js +4 -4
  18. package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
  19. package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
  20. package/lib/commands/appdistribution-groups-list.js +55 -0
  21. package/lib/commands/appdistribution-testers-list.js +52 -0
  22. package/lib/commands/appdistribution-testers-remove.js +1 -1
  23. package/lib/commands/apphosting-backends-create.js +4 -4
  24. package/lib/commands/apphosting-backends-delete.js +7 -15
  25. package/lib/commands/apphosting-backends-get.js +1 -1
  26. package/lib/commands/apphosting-config-export.js +51 -0
  27. package/lib/commands/apphosting-repos-create.js +23 -0
  28. package/lib/commands/apphosting-rollouts-create.js +14 -15
  29. package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
  30. package/lib/commands/database-import.js +4 -2
  31. package/lib/commands/database-push.js +4 -2
  32. package/lib/commands/database-set.js +4 -2
  33. package/lib/commands/database-settings-get.js +1 -1
  34. package/lib/commands/database-settings-set.js +1 -1
  35. package/lib/commands/dataconnect-sdk-generate.js +4 -1
  36. package/lib/commands/dataconnect-services-list.js +4 -3
  37. package/lib/commands/dataconnect-sql-diff.js +1 -1
  38. package/lib/commands/dataconnect-sql-grant.js +37 -0
  39. package/lib/commands/dataconnect-sql-migrate.js +1 -1
  40. package/lib/commands/dataconnect-sql-shell.js +115 -0
  41. package/lib/commands/deploy.js +2 -0
  42. package/lib/commands/emulators-start.js +4 -1
  43. package/lib/commands/ext-dev-init.js +2 -2
  44. package/lib/commands/ext-dev-list.js +1 -1
  45. package/lib/commands/ext-dev-register.js +2 -2
  46. package/lib/commands/ext-dev-upload.js +2 -2
  47. package/lib/commands/ext-dev-usage.js +2 -2
  48. package/lib/commands/ext-info.js +3 -1
  49. package/lib/commands/ext-install.js +2 -2
  50. package/lib/commands/ext-sdk-install.js +88 -0
  51. package/lib/commands/ext.js +1 -0
  52. package/lib/commands/firestore-databases-restore.js +39 -1
  53. package/lib/commands/functions-secrets-access.js +2 -4
  54. package/lib/commands/index.js +15 -2
  55. package/lib/commands/init.js +25 -15
  56. package/lib/commands/setup-emulators-dataconnect.js +0 -13
  57. package/lib/commands/use.js +1 -1
  58. package/lib/config.js +14 -4
  59. package/lib/crashlytics/buildToolsJarHelper.js +2 -2
  60. package/lib/dataconnect/client.js +1 -1
  61. package/lib/dataconnect/dataplaneClient.js +12 -9
  62. package/lib/dataconnect/ensureApis.js +6 -1
  63. package/lib/dataconnect/fileUtils.js +15 -39
  64. package/lib/dataconnect/freeTrial.js +45 -9
  65. package/lib/dataconnect/load.js +3 -1
  66. package/lib/dataconnect/provisionCloudSql.js +39 -26
  67. package/lib/dataconnect/schemaMigration.js +215 -74
  68. package/lib/dataconnect/types.js +4 -1
  69. package/lib/dataconnect/webhook.js +32 -0
  70. package/lib/deploy/dataconnect/deploy.js +18 -15
  71. package/lib/deploy/dataconnect/prepare.js +41 -0
  72. package/lib/deploy/dataconnect/release.js +16 -7
  73. package/lib/deploy/extensions/deploy.js +3 -1
  74. package/lib/deploy/extensions/deploymentSummary.js +7 -3
  75. package/lib/deploy/extensions/planner.js +44 -5
  76. package/lib/deploy/extensions/prepare.js +45 -73
  77. package/lib/deploy/extensions/release.js +11 -10
  78. package/lib/deploy/extensions/tasks.js +32 -21
  79. package/lib/deploy/firestore/prepare.js +9 -0
  80. package/lib/deploy/firestore/release.js +3 -6
  81. package/lib/deploy/functions/checkIam.js +7 -2
  82. package/lib/deploy/functions/ensure.js +11 -3
  83. package/lib/deploy/functions/prepare.js +32 -21
  84. package/lib/deploy/functions/prepareFunctionsUpload.js +15 -16
  85. package/lib/deploy/functions/release/planner.js +2 -1
  86. package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
  87. package/lib/deploy/functions/runtimes/node/index.js +5 -0
  88. package/lib/deploy/functions/services/auth.js +34 -3
  89. package/lib/deploy/functions/services/index.js +2 -0
  90. package/lib/deploy/index.js +8 -5
  91. package/lib/deploy/lifecycleHooks.js +2 -1
  92. package/lib/emulator/apphosting/config.js +27 -0
  93. package/lib/emulator/apphosting/index.js +38 -0
  94. package/lib/emulator/apphosting/serve.js +50 -0
  95. package/lib/emulator/apphosting/utils.js +18 -0
  96. package/lib/emulator/auth/handlers.js +27 -0
  97. package/lib/emulator/auth/operations.js +41 -2
  98. package/lib/emulator/auth/state.js +2 -1
  99. package/lib/emulator/commandUtils.js +8 -3
  100. package/lib/emulator/constants.js +4 -1
  101. package/lib/emulator/controller.js +48 -5
  102. package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
  103. package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
  104. package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
  105. package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
  106. package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
  107. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
  108. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
  109. package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
  110. package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
  111. package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
  112. package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
  113. package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
  114. package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
  115. package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
  116. package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
  117. package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
  118. package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
  119. package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
  120. package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
  121. package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
  122. package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
  123. package/lib/emulator/dataconnect/pgliteServer.js +95 -0
  124. package/lib/emulator/dataconnectEmulator.js +58 -75
  125. package/lib/emulator/dataconnectToolkitController.js +44 -0
  126. package/lib/emulator/downloadableEmulators.js +27 -16
  127. package/lib/emulator/emulatorLogger.js +3 -0
  128. package/lib/emulator/eventarcEmulator.js +1 -1
  129. package/lib/emulator/extensionsEmulator.js +38 -6
  130. package/lib/emulator/functionsEmulator.js +85 -41
  131. package/lib/emulator/functionsEmulatorShared.js +2 -1
  132. package/lib/emulator/functionsRuntimeWorker.js +2 -1
  133. package/lib/emulator/hub.js +13 -9
  134. package/lib/emulator/hubExport.js +10 -3
  135. package/lib/emulator/loggingEmulator.js +2 -2
  136. package/lib/emulator/portUtils.js +10 -11
  137. package/lib/emulator/registry.js +1 -0
  138. package/lib/emulator/storage/persistence.js +2 -2
  139. package/lib/emulator/storage/rules/runtime.js +1 -1
  140. package/lib/emulator/tasksEmulator.js +5 -2
  141. package/lib/emulator/types.js +3 -0
  142. package/lib/emulator/ui.js +51 -25
  143. package/lib/error.js +31 -1
  144. package/lib/experiments.js +5 -0
  145. package/lib/extensions/emulator/triggerHelper.js +1 -1
  146. package/lib/extensions/extensionsApi.js +14 -10
  147. package/lib/extensions/extensionsHelper.js +15 -6
  148. package/lib/extensions/localHelper.js +31 -0
  149. package/lib/extensions/runtimes/common.js +179 -39
  150. package/lib/extensions/runtimes/node.js +401 -0
  151. package/lib/extensions/types.js +25 -14
  152. package/lib/extensions/warnings.js +5 -2
  153. package/lib/firestore/api.js +2 -1
  154. package/lib/firestore/checkDatabaseType.js +10 -3
  155. package/lib/firestore/delete.js +11 -0
  156. package/lib/firestore/options.js +7 -0
  157. package/lib/frameworks/angular/index.js +15 -3
  158. package/lib/frameworks/constants.js +1 -1
  159. package/lib/frameworks/flutter/index.js +6 -6
  160. package/lib/frameworks/flutter/utils.js +34 -1
  161. package/lib/frameworks/next/index.js +10 -2
  162. package/lib/frameworks/next/utils.js +8 -5
  163. package/lib/frameworks/vite/index.js +2 -2
  164. package/lib/fsutils.js +13 -1
  165. package/lib/functions/constants.js +4 -0
  166. package/lib/functions/events/v1.js +9 -2
  167. package/lib/gcp/apphosting.js +1 -1
  168. package/lib/gcp/cloudmonitoring.js +3 -3
  169. package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
  170. package/lib/gcp/cloudsql/connect.js +49 -37
  171. package/lib/gcp/cloudsql/interactive.js +49 -0
  172. package/lib/gcp/cloudsql/permissions.js +165 -0
  173. package/lib/gcp/devConnect.js +38 -1
  174. package/lib/gcp/firestore.js +5 -1
  175. package/lib/gcp/secretManager.js +12 -5
  176. package/lib/getProjectNumber.js +1 -1
  177. package/lib/init/features/apphosting.js +15 -0
  178. package/lib/init/features/dataconnect/index.js +159 -120
  179. package/lib/init/features/dataconnect/sdk.js +77 -84
  180. package/lib/init/features/emulators.js +2 -15
  181. package/lib/init/features/firestore/index.js +20 -1
  182. package/lib/init/features/firestore/indexes.js +4 -4
  183. package/lib/init/features/genkit/index.js +444 -0
  184. package/lib/init/features/hosting/index.js +2 -2
  185. package/lib/init/features/index.js +1 -1
  186. package/lib/init/features/project.js +6 -6
  187. package/lib/init/features/storage.js +0 -2
  188. package/lib/init/index.js +1 -0
  189. package/lib/init/spawn.js +23 -2
  190. package/lib/logger.js +2 -2
  191. package/lib/management/projects.js +24 -4
  192. package/lib/projectUtils.js +1 -1
  193. package/lib/prompt.js +1 -1
  194. package/lib/rc.js +1 -8
  195. package/lib/requireAuth.js +19 -5
  196. package/lib/requireDatabaseInstance.js +1 -1
  197. package/lib/requirePermissions.js +1 -1
  198. package/lib/responseToError.js +5 -2
  199. package/lib/rulesDeploy.js +1 -1
  200. package/lib/templates.js +2 -2
  201. package/lib/utils.js +16 -11
  202. package/lib/vsCodeUtils.js +8 -0
  203. package/package.json +7 -6
  204. package/schema/connector-yaml.json +57 -17
  205. package/schema/firebase-config.json +24 -0
  206. package/templates/extensions/javascript/package.lint.json +2 -2
  207. package/templates/extensions/javascript/package.nolint.json +2 -2
  208. package/templates/extensions/typescript/package.lint.json +2 -2
  209. package/templates/extensions/typescript/package.nolint.json +2 -2
  210. package/templates/genkit/firebase.0.9.0.template +57 -0
  211. package/templates/init/apphosting/apphosting.yaml +23 -0
  212. package/templates/init/dataconnect/connector.yaml +0 -1
  213. package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
  214. package/templates/init/dataconnect/dataconnect.yaml +1 -1
  215. package/templates/init/dataconnect/queries.gql +1 -2
  216. package/templates/init/functions/javascript/package.lint.json +2 -2
  217. package/templates/init/functions/javascript/package.nolint.json +2 -2
  218. package/templates/init/functions/typescript/package.lint.json +2 -2
  219. package/templates/init/functions/typescript/package.nolint.json +2 -2
  220. package/lib/ensureCloudResourceLocation.js +0 -12
  221. package/lib/init/features/genkit.js +0 -53
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.upsertSecret = exports.grantSecretAccess = exports.serviceAccountsForBackend = exports.toMulti = void 0;
3
+ exports.getSecretNameParts = exports.loadConfigToExport = exports.fetchSecrets = exports.upsertSecret = exports.grantSecretAccess = exports.serviceAccountsForBackend = exports.toMulti = void 0;
4
4
  const error_1 = require("../../error");
5
5
  const gcsm = require("../../gcp/secretManager");
6
6
  const gcb = require("../../gcp/cloudbuild");
@@ -10,6 +10,10 @@ const secretManager_1 = require("../../gcp/secretManager");
10
10
  const secretManager_2 = require("../../gcp/secretManager");
11
11
  const utils = require("../../utils");
12
12
  const prompt = require("../../prompt");
13
+ const path_1 = require("path");
14
+ const config_1 = require("../config");
15
+ const utils_1 = require("../utils");
16
+ const yaml_1 = require("../yaml");
13
17
  function toMulti(accounts) {
14
18
  const m = {
15
19
  buildServiceAccounts: [accounts.buildServiceAccount],
@@ -55,14 +59,14 @@ async function grantSecretAccess(projectId, projectNumber, secretName, accounts)
55
59
  existingBindings = (await gcsm.getIamPolicy({ projectId, name: secretName })).bindings || [];
56
60
  }
57
61
  catch (err) {
58
- throw new error_1.FirebaseError(`Failed to get IAM bindings on secret: ${secretName}. Ensure you have the permissions to do so and try again.`, { original: err });
62
+ throw new error_1.FirebaseError(`Failed to get IAM bindings on secret: ${secretName}. Ensure you have the permissions to do so and try again.`, { original: (0, error_1.getError)(err) });
59
63
  }
60
64
  try {
61
65
  const updatedBindings = existingBindings.concat(newBindings);
62
66
  await gcsm.setIamPolicy({ projectId, name: secretName }, updatedBindings);
63
67
  }
64
68
  catch (err) {
65
- throw new error_1.FirebaseError(`Failed to set IAM bindings ${JSON.stringify(newBindings)} on secret: ${secretName}. Ensure you have the permissions to do so and try again.`, { original: err });
69
+ throw new error_1.FirebaseError(`Failed to set IAM bindings ${JSON.stringify(newBindings)} on secret: ${secretName}. Ensure you have the permissions to do so and try again.`, { original: (0, error_1.getError)(err) });
66
70
  }
67
71
  utils.logSuccess(`Successfully set IAM bindings on secret ${secretName}.\n`);
68
72
  }
@@ -73,8 +77,8 @@ async function upsertSecret(project, secret, location) {
73
77
  existing = await gcsm.getSecret(project, secret);
74
78
  }
75
79
  catch (err) {
76
- if (err.status !== 404) {
77
- throw new error_1.FirebaseError("Unexpected error loading secret", { original: err });
80
+ if ((0, error_1.getErrStatus)(err) !== 404) {
81
+ throw new error_1.FirebaseError("Unexpected error loading secret", { original: (0, error_1.getError)(err) });
78
82
  }
79
83
  await gcsm.createSecret(project, secret, gcsm.labels("apphosting"), location);
80
84
  return true;
@@ -101,3 +105,64 @@ async function upsertSecret(project, secret, location) {
101
105
  return false;
102
106
  }
103
107
  exports.upsertSecret = upsertSecret;
108
+ async function fetchSecrets(projectId, secrets) {
109
+ let secretsKeyValuePairs;
110
+ try {
111
+ const secretPromises = secrets.map(async (secretConfig) => {
112
+ const [name, version] = getSecretNameParts(secretConfig.secret);
113
+ const value = await gcsm.accessSecretVersion(projectId, name, version);
114
+ return [secretConfig.variable, value];
115
+ });
116
+ const secretEntries = await Promise.all(secretPromises);
117
+ secretsKeyValuePairs = new Map(secretEntries);
118
+ }
119
+ catch (e) {
120
+ throw new error_1.FirebaseError(`Error exporting secrets`, {
121
+ original: e,
122
+ });
123
+ }
124
+ return secretsKeyValuePairs;
125
+ }
126
+ exports.fetchSecrets = fetchSecrets;
127
+ async function loadConfigToExport(cwd, userGivenConfigFile) {
128
+ if (userGivenConfigFile && !config_1.APPHOSTING_YAML_FILE_REGEX.test(userGivenConfigFile)) {
129
+ throw new error_1.FirebaseError("Invalid apphosting yaml config file provided. File must be in format: 'apphosting.yaml' or 'apphosting.<environment>.yaml'");
130
+ }
131
+ const allConfigs = getValidConfigs(cwd);
132
+ let userGivenConfigFilePath;
133
+ if (userGivenConfigFile) {
134
+ if (!allConfigs.has(userGivenConfigFile)) {
135
+ throw new error_1.FirebaseError(`The provided app hosting config file "${userGivenConfigFile}" does not exist`);
136
+ }
137
+ userGivenConfigFilePath = allConfigs.get(userGivenConfigFile);
138
+ }
139
+ else {
140
+ userGivenConfigFilePath = await (0, utils_1.promptForAppHostingYaml)(allConfigs, "Which environment would you like to export secrets from Secret Manager for?");
141
+ }
142
+ if (userGivenConfigFile === config_1.APPHOSTING_BASE_YAML_FILE) {
143
+ return yaml_1.AppHostingYamlConfig.loadFromFile(allConfigs.get(config_1.APPHOSTING_BASE_YAML_FILE));
144
+ }
145
+ const baseFilePath = allConfigs.get(config_1.APPHOSTING_BASE_YAML_FILE);
146
+ return await (0, config_1.loadConfigForEnvironment)(userGivenConfigFilePath, baseFilePath);
147
+ }
148
+ exports.loadConfigToExport = loadConfigToExport;
149
+ function getValidConfigs(cwd) {
150
+ const appHostingConfigPaths = (0, config_1.listAppHostingFilesInPath)(cwd).filter((path) => !path.endsWith(config_1.APPHOSTING_LOCAL_YAML_FILE));
151
+ if (appHostingConfigPaths.length === 0) {
152
+ throw new error_1.FirebaseError("No apphosting.*.yaml configs found");
153
+ }
154
+ const fileNameToPathMap = new Map();
155
+ for (const path of appHostingConfigPaths) {
156
+ const fileName = (0, path_1.basename)(path);
157
+ fileNameToPathMap.set(fileName, path);
158
+ }
159
+ return fileNameToPathMap;
160
+ }
161
+ function getSecretNameParts(secret) {
162
+ let [name, version] = secret.split("@");
163
+ if (!version) {
164
+ version = "latest";
165
+ }
166
+ return [name, version];
167
+ }
168
+ exports.getSecretNameParts = getSecretNameParts;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promptForAppHostingYaml = exports.getEnvironmentName = void 0;
4
+ const error_1 = require("../error");
5
+ const config_1 = require("./config");
6
+ const prompt = require("../prompt");
7
+ function getEnvironmentName(apphostingYamlFileName) {
8
+ const found = apphostingYamlFileName.match(config_1.APPHOSTING_YAML_FILE_REGEX);
9
+ if (!found || found.length < 2 || !found[1]) {
10
+ throw new error_1.FirebaseError("Invalid apphosting environment file");
11
+ }
12
+ return found[1].replaceAll(".", "");
13
+ }
14
+ exports.getEnvironmentName = getEnvironmentName;
15
+ async function promptForAppHostingYaml(apphostingFileNameToPathMap, promptMessage = "Please select an App Hosting config:") {
16
+ const fileNames = Array.from(apphostingFileNameToPathMap.keys());
17
+ const baseFilePath = apphostingFileNameToPathMap.get(config_1.APPHOSTING_BASE_YAML_FILE);
18
+ const listOptions = fileNames.map((fileName) => {
19
+ if (fileName === config_1.APPHOSTING_BASE_YAML_FILE) {
20
+ return {
21
+ name: `base (${config_1.APPHOSTING_BASE_YAML_FILE})`,
22
+ value: baseFilePath,
23
+ };
24
+ }
25
+ const environment = getEnvironmentName(fileName);
26
+ return {
27
+ name: baseFilePath
28
+ ? `${environment} (${config_1.APPHOSTING_BASE_YAML_FILE} + ${fileName})`
29
+ : `${environment} (${fileName})`,
30
+ value: apphostingFileNameToPathMap.get(fileName),
31
+ };
32
+ });
33
+ const fileToExportPath = await prompt.promptOnce({
34
+ name: "apphosting-yaml",
35
+ type: "list",
36
+ message: promptMessage,
37
+ choices: listOptions,
38
+ });
39
+ return fileToExportPath;
40
+ }
41
+ exports.promptForAppHostingYaml = promptForAppHostingYaml;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppHostingYamlConfig = void 0;
4
+ const path_1 = require("path");
5
+ const utils_1 = require("../utils");
6
+ const config_1 = require("./config");
7
+ const yaml = require("yaml");
8
+ const jsYaml = require("js-yaml");
9
+ const fsutils_1 = require("../fsutils");
10
+ const error_1 = require("../error");
11
+ class AppHostingYamlConfig {
12
+ static async loadFromFile(filePath) {
13
+ const config = new AppHostingYamlConfig();
14
+ if (!(0, fsutils_1.fileExistsSync)(filePath)) {
15
+ throw new error_1.FirebaseError("Cannot load AppHostingYamlConfig from given path, it doesn't exist");
16
+ }
17
+ const file = await (0, utils_1.readFileFromDirectory)((0, path_1.dirname)(filePath), (0, path_1.basename)(filePath));
18
+ const loadedAppHostingYaml = (await (0, utils_1.wrappedSafeLoad)(file.source)) ?? {};
19
+ if (loadedAppHostingYaml.env) {
20
+ const parsedEnvs = parseEnv(loadedAppHostingYaml.env);
21
+ config._environmentVariables = parsedEnvs.environmentVariables;
22
+ config._secrets = parsedEnvs.secrets;
23
+ }
24
+ return config;
25
+ }
26
+ static empty() {
27
+ return new AppHostingYamlConfig();
28
+ }
29
+ constructor() {
30
+ this._environmentVariables = new Map();
31
+ this._secrets = new Map();
32
+ }
33
+ get environmentVariables() {
34
+ return mapToArray(this._environmentVariables);
35
+ }
36
+ get secrets() {
37
+ return mapToArray(this._secrets);
38
+ }
39
+ addEnvironmentVariable(env) {
40
+ this._environmentVariables.set(env.variable, env);
41
+ }
42
+ addSecret(secret) {
43
+ this._secrets.set(secret.variable, secret);
44
+ }
45
+ merge(other) {
46
+ for (const [key, value] of other._environmentVariables) {
47
+ this._environmentVariables.set(key, value);
48
+ }
49
+ for (const [key, value] of other._secrets) {
50
+ this._secrets.set(key, value);
51
+ }
52
+ }
53
+ async upsertFile(filePath) {
54
+ let yamlConfigToWrite = {};
55
+ if ((0, fsutils_1.fileExistsSync)(filePath)) {
56
+ const file = await (0, utils_1.readFileFromDirectory)((0, path_1.dirname)(filePath), (0, path_1.basename)(filePath));
57
+ yamlConfigToWrite = await (0, utils_1.wrappedSafeLoad)(file.source);
58
+ }
59
+ yamlConfigToWrite.env = [...this.environmentVariables, ...this.secrets];
60
+ (0, config_1.store)(filePath, yaml.parseDocument(jsYaml.dump(yamlConfigToWrite)));
61
+ }
62
+ }
63
+ exports.AppHostingYamlConfig = AppHostingYamlConfig;
64
+ function parseEnv(envs) {
65
+ const environmentVariables = new Map();
66
+ const secrets = new Map();
67
+ for (const env of envs) {
68
+ if (env.value) {
69
+ environmentVariables.set(env.variable, env);
70
+ }
71
+ if (env.secret) {
72
+ secrets.set(env.variable, env);
73
+ }
74
+ }
75
+ return {
76
+ environmentVariables,
77
+ secrets,
78
+ };
79
+ }
80
+ function mapToArray(map) {
81
+ return Array.from(map.values());
82
+ }
@@ -39,7 +39,7 @@ async function archiveDirectory(sourceDirectory, options = {}) {
39
39
  if (err instanceof error_1.FirebaseError) {
40
40
  throw err;
41
41
  }
42
- throw new error_1.FirebaseError("Failed to create archive.", { original: err });
42
+ throw new error_1.FirebaseError("Failed to create archive.", { original: (0, error_1.getError)(err) });
43
43
  }
44
44
  }
45
45
  exports.archiveDirectory = archiveDirectory;
package/lib/auth.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addAdditionalAccount = exports.logout = exports.getAccessToken = exports.findAccountByEmail = exports.loginGithub = exports.loginGoogle = exports.setGlobalDefaultAccount = exports.setProjectAccount = exports.loginAdditionalAccount = exports.selectAccount = exports.setRefreshToken = exports.setActiveAccount = exports.getAllAccounts = exports.getAdditionalAccounts = exports.getProjectDefaultAccount = exports.getGlobalDefaultAccount = void 0;
3
+ exports.addAdditionalAccount = exports.logout = exports.getAccessToken = exports.haveValidTokens = exports.loggedIn = 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("colorette");
5
5
  const FormData = require("form-data");
6
6
  const http = require("http");
@@ -21,6 +21,7 @@ const crypto_1 = require("crypto");
21
21
  const track_1 = require("./track");
22
22
  const api_1 = require("./api");
23
23
  const templates_1 = require("./templates");
24
+ const requireAuth_1 = require("./requireAuth");
24
25
  portfinder.setBasePort(9005);
25
26
  function getGlobalDefaultAccount() {
26
27
  const user = configstore_1.configstore.get("user");
@@ -137,11 +138,13 @@ function open(url) {
137
138
  });
138
139
  }
139
140
  function invalidCredentialError() {
140
- return new error_1.FirebaseError("Authentication Error: Your credentials are no longer valid. Please run " +
141
+ const message = "Authentication Error: Your credentials are no longer valid. Please run " +
141
142
  clc.bold("firebase login --reauth") +
142
143
  "\n\n" +
143
144
  "For CI servers and headless environments, generate a new token with " +
144
- clc.bold("firebase login:ci"), { exit: 1 });
145
+ clc.bold("firebase login:ci");
146
+ logger_1.logger.error(message);
147
+ return new error_1.FirebaseError(message, { exit: 1 });
145
148
  }
146
149
  const FIFTEEN_MINUTES_IN_MS = 15 * 60 * 1000;
147
150
  const SCOPES = [
@@ -393,6 +396,10 @@ function findAccountByEmail(email) {
393
396
  return getAllAccounts().find((a) => a.user.email === email);
394
397
  }
395
398
  exports.findAccountByEmail = findAccountByEmail;
399
+ function loggedIn() {
400
+ return !!lastAccessToken;
401
+ }
402
+ exports.loggedIn = loggedIn;
396
403
  function haveValidTokens(refreshToken, authScopes) {
397
404
  if (!lastAccessToken?.access_token) {
398
405
  const tokens = configstore_1.configstore.get("tokens");
@@ -405,8 +412,16 @@ function haveValidTokens(refreshToken, authScopes) {
405
412
  const newScopesJSON = JSON.stringify(authScopes.sort());
406
413
  const hasSameScopes = oldScopesJSON === newScopesJSON;
407
414
  const isExpired = (lastAccessToken?.expires_at || 0) < Date.now() + FIFTEEN_MINUTES_IN_MS;
408
- return hasTokens && hasSameScopes && !isExpired;
415
+ const valid = hasTokens && hasSameScopes && !isExpired;
416
+ if (hasTokens) {
417
+ logger_1.logger.debug(`Checked if tokens are valid: ${valid}, expires at: ${lastAccessToken?.expires_at}`);
418
+ }
419
+ else {
420
+ logger_1.logger.debug("No OAuth tokens found");
421
+ }
422
+ return valid;
409
423
  }
424
+ exports.haveValidTokens = haveValidTokens;
410
425
  function deleteAccount(account) {
411
426
  const defaultAccount = getGlobalDefaultAccount();
412
427
  if (account.user.email === defaultAccount?.user.email) {
@@ -515,7 +530,18 @@ async function getAccessToken(refreshToken, authScopes) {
515
530
  if (haveValidTokens(refreshToken, authScopes) && lastAccessToken) {
516
531
  return lastAccessToken;
517
532
  }
518
- return refreshTokens(refreshToken, authScopes);
533
+ if (refreshToken) {
534
+ return refreshTokens(refreshToken, authScopes);
535
+ }
536
+ else {
537
+ try {
538
+ return (0, requireAuth_1.refreshAuth)();
539
+ }
540
+ catch (err) {
541
+ logger_1.logger.debug(`Unable to refresh token: ${(0, error_1.getErrMsg)(err)}`);
542
+ }
543
+ throw new error_1.FirebaseError("Unable to getAccessToken");
544
+ }
519
545
  }
520
546
  exports.getAccessToken = getAccessToken;
521
547
  async function logout(refreshToken) {
@@ -16,7 +16,7 @@ const marked_1 = require("marked");
16
16
  marked_1.marked.use((0, marked_terminal_1.markedTerminal)());
17
17
  const node_path_1 = require("node:path");
18
18
  const triple_beam_1 = require("triple-beam");
19
- const stripAnsi = require("strip-ansi");
19
+ const node_util_1 = require("node:util");
20
20
  const fs = require("node:fs");
21
21
  const configstore_1 = require("../configstore");
22
22
  const errorOut_1 = require("../errorOut");
@@ -58,7 +58,7 @@ logger_1.logger.add(new winston.transports.File({
58
58
  filename: logFilename,
59
59
  format: winston.format.printf((info) => {
60
60
  const segments = [info.message, ...(info[triple_beam_1.SPLAT] || [])].map(utils.tryStringify);
61
- return `[${info.level}] ${stripAnsi(segments.join(" "))}`;
61
+ return `[${info.level}] ${(0, node_util_1.stripVTControlCharacters)(segments.join(" "))}`;
62
62
  }),
63
63
  }));
64
64
  logger_1.logger.debug("-".repeat(70));
package/lib/command.js CHANGED
@@ -19,6 +19,7 @@ class Command {
19
19
  this.name = "";
20
20
  this.descriptionText = "";
21
21
  this.options = [];
22
+ this.aliases = [];
22
23
  this.actionFn = () => {
23
24
  };
24
25
  this.befores = [];
@@ -30,6 +31,10 @@ class Command {
30
31
  this.descriptionText = t;
31
32
  return this;
32
33
  }
34
+ alias(alias) {
35
+ this.aliases.push(alias);
36
+ return this;
37
+ }
33
38
  option(...args) {
34
39
  this.options.push(args);
35
40
  return this;
@@ -57,6 +62,9 @@ class Command {
57
62
  if (this.descriptionText) {
58
63
  cmd.description(this.descriptionText);
59
64
  }
65
+ if (this.aliases) {
66
+ cmd.aliases(this.aliases);
67
+ }
60
68
  this.options.forEach((args) => {
61
69
  const flags = args.shift();
62
70
  cmd.option(flags, ...args);
@@ -184,13 +192,15 @@ class Command {
184
192
  applyRC(options) {
185
193
  const rc = (0, rc_1.loadRC)(options);
186
194
  options.rc = rc;
187
- options.project =
188
- options.project || (configstore_1.configstore.get("activeProjects") || {})[options.projectRoot];
195
+ const activeProject = options.projectRoot
196
+ ? (configstore_1.configstore.get("activeProjects") ?? {})[options.projectRoot]
197
+ : undefined;
198
+ options.project = options.project ?? activeProject;
189
199
  if (options.config && !options.project) {
190
200
  options.project = options.config.defaults.project;
191
201
  }
192
202
  const aliases = rc.projects;
193
- const rcProject = (0, lodash_1.get)(aliases, options.project);
203
+ const rcProject = options.project ? aliases[options.project] : undefined;
194
204
  if (rcProject) {
195
205
  options.projectAlias = options.project;
196
206
  options.project = rcProject;
@@ -199,11 +209,15 @@ class Command {
199
209
  options.projectAlias = (0, lodash_1.head)((0, lodash_1.keys)(aliases));
200
210
  options.project = (0, lodash_1.head)((0, lodash_1.values)(aliases));
201
211
  }
212
+ else if (!options.project && aliases["default"]) {
213
+ options.projectAlias = "default";
214
+ options.project = aliases["default"];
215
+ }
202
216
  }
203
217
  async resolveProjectIdentifiers(options) {
204
218
  if (options.project?.match(/^\d+$/)) {
205
219
  await (0, requireAuth_1.requireAuth)(options);
206
- const { projectId, projectNumber } = await (0, projects_1.getFirebaseProject)(options.project);
220
+ const { projectId, projectNumber } = await (0, projects_1.getProject)(options.project);
207
221
  options.projectId = projectId;
208
222
  options.projectNumber = projectNumber;
209
223
  }
@@ -61,13 +61,13 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
61
61
  aabInfo = await requests.getAabInfo(appName);
62
62
  }
63
63
  catch (err) {
64
- if (err.status === 404) {
64
+ if ((0, error_1.getErrStatus)(err) === 404) {
65
65
  throw new error_1.FirebaseError(`App Distribution could not find your app ${options.app}. ` +
66
66
  `Make sure to onboard your app by pressing the "Get started" ` +
67
67
  "button on the App Distribution page in the Firebase console: " +
68
68
  "https://console.firebase.google.com/project/_/appdistribution", { exit: 1 });
69
69
  }
70
- throw new error_1.FirebaseError(`failed to determine AAB info. ${err.message}`, { exit: 1 });
70
+ throw new error_1.FirebaseError(`failed to determine AAB info. ${(0, error_1.getErrMsg)(err)}`, { exit: 1 });
71
71
  }
72
72
  if (aabInfo.integrationState !== types_1.IntegrationState.INTEGRATED &&
73
73
  aabInfo.integrationState !== types_1.IntegrationState.AAB_STATE_UNAVAILABLE) {
@@ -115,13 +115,13 @@ exports.command = new command_1.Command("appdistribution:distribute <release-bin
115
115
  releaseName = uploadResponse.release.name;
116
116
  }
117
117
  catch (err) {
118
- if (err.status === 404) {
118
+ if ((0, error_1.getErrStatus)(err) === 404) {
119
119
  throw new error_1.FirebaseError(`App Distribution could not find your app ${options.app}. ` +
120
120
  `Make sure to onboard your app by pressing the "Get started" ` +
121
121
  "button on the App Distribution page in the Firebase console: " +
122
122
  "https://console.firebase.google.com/project/_/appdistribution", { exit: 1 });
123
123
  }
124
- throw new error_1.FirebaseError(`Failed to upload release. ${err.message}`, { exit: 1 });
124
+ throw new error_1.FirebaseError(`Failed to upload release. ${(0, error_1.getErrMsg)(err)}`, { exit: 1 });
125
125
  }
126
126
  if (aabInfo && !aabInfo.testCertificate) {
127
127
  aabInfo = await requests.getAabInfo(appName);
@@ -6,8 +6,9 @@ const utils = require("../utils");
6
6
  const requireAuth_1 = require("../requireAuth");
7
7
  const client_1 = require("../appdistribution/client");
8
8
  const options_parser_util_1 = require("../appdistribution/options-parser-util");
9
- exports.command = new command_1.Command("appdistribution:group:create <displayName> [alias]")
9
+ exports.command = new command_1.Command("appdistribution:groups:create <displayName> [alias]")
10
10
  .description("create group in project")
11
+ .alias("appdistribution:group:create")
11
12
  .before(requireAuth_1.requireAuth)
12
13
  .action(async (displayName, alias, options) => {
13
14
  const projectName = await (0, options_parser_util_1.getProjectName)(options);
@@ -7,8 +7,9 @@ const requireAuth_1 = require("../requireAuth");
7
7
  const error_1 = require("../error");
8
8
  const client_1 = require("../appdistribution/client");
9
9
  const options_parser_util_1 = require("../appdistribution/options-parser-util");
10
- exports.command = new command_1.Command("appdistribution:group:delete <alias>")
10
+ exports.command = new command_1.Command("appdistribution:groups:delete <alias>")
11
11
  .description("delete group from a project")
12
+ .alias("appdistribution:group:delete")
12
13
  .before(requireAuth_1.requireAuth)
13
14
  .action(async (alias, options) => {
14
15
  const projectName = await (0, options_parser_util_1.getProjectName)(options);
@@ -18,7 +19,7 @@ exports.command = new command_1.Command("appdistribution:group:delete <alias>")
18
19
  await appDistroClient.deleteGroup(`${projectName}/groups/${alias}`);
19
20
  }
20
21
  catch (err) {
21
- throw new error_1.FirebaseError(`Failed to delete group ${err}`);
22
+ throw new error_1.FirebaseError(`Failed to delete group ${(0, error_1.getErrMsg)(err)}`);
22
23
  }
23
24
  utils.logSuccess(`Group ${alias} has successfully been deleted`);
24
25
  });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const ora = require("ora");
5
+ const client_1 = require("../appdistribution/client");
6
+ const options_parser_util_1 = require("../appdistribution/options-parser-util");
7
+ const command_1 = require("../command");
8
+ const error_1 = require("../error");
9
+ const logger_1 = require("../logger");
10
+ const requireAuth_1 = require("../requireAuth");
11
+ const utils = require("../utils");
12
+ const Table = require("cli-table");
13
+ exports.command = new command_1.Command("appdistribution:groups:list")
14
+ .description("list groups in project")
15
+ .alias("appdistribution:group:list")
16
+ .before(requireAuth_1.requireAuth)
17
+ .action(async (options) => {
18
+ const projectName = await (0, options_parser_util_1.getProjectName)(options);
19
+ const appDistroClient = new client_1.AppDistributionClient();
20
+ let groupsResponse;
21
+ const spinner = ora("Preparing the list of your App Distribution Groups").start();
22
+ try {
23
+ groupsResponse = await appDistroClient.listGroups(projectName);
24
+ }
25
+ catch (err) {
26
+ spinner.fail();
27
+ throw new error_1.FirebaseError("Failed to list groups.", {
28
+ exit: 1,
29
+ original: err,
30
+ });
31
+ }
32
+ spinner.succeed();
33
+ const groups = groupsResponse.groups ?? [];
34
+ printGroupsTable(groups);
35
+ utils.logSuccess(`Groups listed successfully`);
36
+ return groupsResponse;
37
+ });
38
+ function printGroupsTable(groups) {
39
+ const tableHead = ["Group", "Display Name", "Tester Count", "Release Count", "Invite Link Count"];
40
+ const table = new Table({
41
+ head: tableHead,
42
+ style: { head: ["green"] },
43
+ });
44
+ for (const group of groups) {
45
+ const name = group.name.split("/").pop();
46
+ table.push([
47
+ name,
48
+ group.displayName,
49
+ group.testerCount || 0,
50
+ group.releaseCount || 0,
51
+ group.inviteLinkCount || 0,
52
+ ]);
53
+ }
54
+ logger_1.logger.info(table.toString());
55
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const ora = require("ora");
5
+ const client_1 = require("../appdistribution/client");
6
+ const options_parser_util_1 = require("../appdistribution/options-parser-util");
7
+ const command_1 = require("../command");
8
+ const error_1 = require("../error");
9
+ const logger_1 = require("../logger");
10
+ const requireAuth_1 = require("../requireAuth");
11
+ const utils = require("../utils");
12
+ const Table = require("cli-table");
13
+ exports.command = new command_1.Command("appdistribution:testers:list [group]")
14
+ .description("list testers in project")
15
+ .before(requireAuth_1.requireAuth)
16
+ .action(async (group, options) => {
17
+ const projectName = await (0, options_parser_util_1.getProjectName)(options);
18
+ const appDistroClient = new client_1.AppDistributionClient();
19
+ let testersResponse;
20
+ const spinner = ora("Preparing the list of your App Distribution testers").start();
21
+ try {
22
+ testersResponse = await appDistroClient.listTesters(projectName, group);
23
+ }
24
+ catch (err) {
25
+ spinner.fail();
26
+ throw new error_1.FirebaseError("Failed to list testers.", {
27
+ exit: 1,
28
+ original: err,
29
+ });
30
+ }
31
+ spinner.succeed();
32
+ const testers = testersResponse.testers ?? [];
33
+ printTestersTable(testers);
34
+ utils.logSuccess(`Testers listed successfully`);
35
+ return testersResponse;
36
+ });
37
+ function printTestersTable(testers) {
38
+ const tableHead = ["Name", "Display Name", "Last Activity Time", "Groups"];
39
+ const table = new Table({
40
+ head: tableHead,
41
+ style: { head: ["green"] },
42
+ });
43
+ for (const tester of testers) {
44
+ const name = tester.name.split("/").pop();
45
+ const groups = tester.groups
46
+ .map((grp) => grp.split("/").pop())
47
+ .sort()
48
+ .join(";");
49
+ table.push([name, tester.displayName ?? "", tester.lastActivityTime, groups]);
50
+ }
51
+ logger_1.logger.info(table.toString());
52
+ }
@@ -28,7 +28,7 @@ exports.command = new command_1.Command("appdistribution:testers:remove [emails.
28
28
  deleteResponse = await appDistroClient.removeTesters(projectName, emailsArr);
29
29
  }
30
30
  catch (err) {
31
- throw new error_1.FirebaseError(`Failed to remove testers ${err}`);
31
+ throw new error_1.FirebaseError(`Failed to remove testers ${(0, error_1.getErrMsg)(err)}`);
32
32
  }
33
33
  if (!deleteResponse.emails) {
34
34
  utils.logSuccess(`Testers did not exist`);
@@ -4,8 +4,8 @@ exports.command = void 0;
4
4
  const command_1 = require("../command");
5
5
  const projectUtils_1 = require("../projectUtils");
6
6
  const requireInteractive_1 = require("../requireInteractive");
7
- const apphosting_1 = require("../apphosting");
8
- const apphosting_2 = require("../gcp/apphosting");
7
+ const backend_1 = require("../apphosting/backend");
8
+ const apphosting_1 = require("../gcp/apphosting");
9
9
  const firedata_1 = require("../gcp/firedata");
10
10
  const requireTosAcceptance_1 = require("../requireTosAcceptance");
11
11
  exports.command = new command_1.Command("apphosting:backends:create")
@@ -13,7 +13,7 @@ exports.command = new command_1.Command("apphosting:backends:create")
13
13
  .option("-a, --app <webAppId>", "specify an existing Firebase web app's ID to associate your App Hosting backend with")
14
14
  .option("-l, --location <location>", "specify the location of the backend", "")
15
15
  .option("-s, --service-account <serviceAccount>", "specify the service account used to run the server", "")
16
- .before(apphosting_2.ensureApiEnabled)
16
+ .before(apphosting_1.ensureApiEnabled)
17
17
  .before(requireInteractive_1.default)
18
18
  .before((0, requireTosAcceptance_1.requireTosAcceptance)(firedata_1.APPHOSTING_TOS_ID))
19
19
  .action(async (options) => {
@@ -21,5 +21,5 @@ exports.command = new command_1.Command("apphosting:backends:create")
21
21
  const webAppId = options.app;
22
22
  const location = options.location;
23
23
  const serviceAccount = options.serviceAccount;
24
- await (0, apphosting_1.doSetup)(projectId, webAppId, location, serviceAccount);
24
+ await (0, backend_1.doSetup)(projectId, webAppId, location, serviceAccount);
25
25
  });