firebase-tools 15.30.0 → 15.30.2

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.
@@ -26,6 +26,7 @@ const config_1 = require("../config");
26
26
  const projectConfig_1 = require("../functions/projectConfig");
27
27
  const error_1 = require("../error");
28
28
  const experiments = require("../experiments");
29
+ const migrate_1 = require("../extensions/migrate");
29
30
  exports.command = new command_1.Command("ext:export")
30
31
  .description("export Extension instances installed on a project to a local Firebase directory")
31
32
  .option(`--mode <target>`, `experimental: controls the target system of the export (supports "extensions", "functions")`)
@@ -101,7 +102,7 @@ async function fnHandler(options) {
101
102
  return;
102
103
  }
103
104
  const projectId = (0, projectUtils_1.needProjectId)(options);
104
- const instance = await (0, extensionsApi_1.getInstance)(projectId, options.instance);
105
+ let instance = await (0, extensionsApi_1.getInstance)(projectId, options.instance);
105
106
  if (typeof instance === "undefined") {
106
107
  logger_1.logger.info(`No extension matching instance ID ${options.instance} found`);
107
108
  return;
@@ -109,6 +110,14 @@ async function fnHandler(options) {
109
110
  if (instance.state !== "ACTIVE" && !options.force) {
110
111
  throw new error_1.FirebaseError(`Extension ${options.instance} is in state ${instance.state}. To export a non-ACTIVE extension, use the --force option.`);
111
112
  }
113
+ instance = await (0, extensionsHelper_1.ensureInstanceSpec)(instance);
114
+ if (!instance.config?.source?.spec) {
115
+ throw new error_1.FirebaseError(`Could not load extension specification for ${options.instance}. Unable to export configuration.`);
116
+ }
117
+ instance = await (0, migrate_1.ensureInstanceUpToDate)(projectId, instance, {
118
+ nonInteractive: options.nonInteractive,
119
+ force: options.force,
120
+ });
112
121
  const instanceId = (0, utils_1.last)(instance.name.split("/")) ?? "";
113
122
  if (instanceId !== options.instance) {
114
123
  return;
@@ -5,6 +5,7 @@ const clc = require("colorette");
5
5
  const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
6
6
  const command_1 = require("../command");
7
7
  const projectUtils_1 = require("../projectUtils");
8
+ const experiments = require("../experiments");
8
9
  const extensionsHelper_1 = require("../extensions/extensionsHelper");
9
10
  const requirePermissions_1 = require("../requirePermissions");
10
11
  const requireConfig_1 = require("../requireConfig");
@@ -23,6 +24,11 @@ exports.command = new command_1.Command("ext:migrate")
23
24
  .option("--ext-instance <instanceId>", "extension instance ID to migrate")
24
25
  .option("-e, --extension <extensionRef>", "extension reference or name to migrate")
25
26
  .option("-f, --force", "force update and migration without prompting")
27
+ .before(() => {
28
+ experiments.assertEnabled("extMigrationFeatures", "migrate an extension instance to a function kit");
29
+ experiments.assertEnabled("kits", "migrate an extension instance to a function kit");
30
+ experiments.assertEnabled("secretEnvParams", "migrate an extension instance to a function kit");
31
+ })
26
32
  .before(requireConfig_1.requireConfig)
27
33
  .before(requirePermissions_1.requirePermissions, [
28
34
  "firebaseextensions.instances.list",
@@ -48,14 +54,14 @@ exports.command = new command_1.Command("ext:migrate")
48
54
  force: options.force,
49
55
  });
50
56
  (0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Selected instance ${clc.bold(plan.instanceId)} (${plan.kitPackage}) for migration.`);
51
- plan.instance = await (0, migrate_1.ensureInstanceUpToDate)(projectId, plan.instance, options);
52
- if (plan.instance.state !== "ACTIVE") {
53
- (0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, `Extension instance ${clc.bold(plan.instanceId)} is in state ${plan.instance.state}. Migration may not function as expected.`);
54
- }
55
57
  plan.instance = await (0, extensionsHelper_1.ensureInstanceSpec)(plan.instance);
56
58
  if (!plan.instance.config?.source?.spec) {
57
59
  throw new error_1.FirebaseError(`Could not load extension specification for ${clc.bold(plan.instanceId)}. Unable to export configuration.`);
58
60
  }
61
+ plan.instance = await (0, migrate_1.ensureInstanceUpToDate)(projectId, plan.instance, options);
62
+ if (plan.instance.state !== "ACTIVE") {
63
+ (0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, `Extension instance ${clc.bold(plan.instanceId)} is in state ${plan.instance.state}. Migration may not function as expected.`);
64
+ }
59
65
  const exportedEnvs = (0, export_1.functionsEnvFromInstance)(plan.instance);
60
66
  await (0, migrate_1.migrateSecrets)(plan.instance, { force: options.force });
61
67
  (0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Installing kit ${clc.bold(plan.kitPackage)} for instance ${clc.bold(plan.instanceId)}...`);
@@ -89,7 +95,7 @@ exports.command = new command_1.Command("ext:migrate")
89
95
  }
90
96
  const shouldUninstall = await (0, prompt_1.confirm)({
91
97
  message: `Functions kit ${kitInstanceId} successfully deployed. After checking function logs to verify that your backend is performing correctly, you should uninstall extension instance ${plan.instanceId}. Uninstall it now?`,
92
- default: true,
98
+ default: false,
93
99
  nonInteractive: options.nonInteractive,
94
100
  force: options.force,
95
101
  });
@@ -9,10 +9,14 @@ const utils_1 = require("../utils");
9
9
  const manifest = require("../extensions/manifest");
10
10
  const projectUtils_1 = require("../projectUtils");
11
11
  const migrate_1 = require("../extensions/migrate");
12
+ const extensionsApi_1 = require("../extensions/extensionsApi");
13
+ const export_1 = require("../extensions/export");
14
+ const error_1 = require("../error");
15
+ const prompt_1 = require("../prompt");
12
16
  exports.command = new command_1.Command("ext:uninstall <extensionInstanceId>")
13
17
  .description("uninstall an extension that is installed in your Firebase project by instance ID")
14
18
  .option("--local", "deprecated")
15
- .option("--immediate", "immediately destroy GCP resources instead of waiting on next deploy. Can be run outside a firebase project directory.")
19
+ .option("--immediate", "immediately destroy GCP resources instead of waiting on next deploy. Can be run outside a firebase project directory if --project is specified.")
16
20
  .withForce()
17
21
  .before(requirePermissions_1.requirePermissions, ["firebaseextensions.instances.delete"])
18
22
  .before(extensionsHelper_1.ensureExtensionsApiEnabled)
@@ -24,6 +28,41 @@ exports.command = new command_1.Command("ext:uninstall <extensionInstanceId>")
24
28
  }
25
29
  if (options.immediate) {
26
30
  const projectId = (0, projectUtils_1.needProjectId)(options);
31
+ let instance;
32
+ try {
33
+ instance = await (0, extensionsApi_1.getInstance)(projectId, instanceId);
34
+ }
35
+ catch (err) {
36
+ if (err instanceof error_1.FirebaseError && err.status === 404) {
37
+ (0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, "ext:uninstall called with --immediate, but no deployed GCP resources found for the extension.");
38
+ const config = manifest.loadConfig(options);
39
+ manifest.removeFromManifest(instanceId, config);
40
+ return;
41
+ }
42
+ throw new error_1.FirebaseError(`Failed to retrieve extension instance ${instanceId}: ${err instanceof Error ? err.message : String(err)}`, {
43
+ original: err instanceof Error ? err : undefined,
44
+ exit: 1,
45
+ });
46
+ }
47
+ if (!instance) {
48
+ throw new error_1.FirebaseError(`Failed to retrieve extension instance ${instanceId}`);
49
+ }
50
+ instance = await (0, extensionsHelper_1.ensureInstanceSpec)(instance);
51
+ const outstandingSecrets = await (0, export_1.secretsNeedingEjection)(instance);
52
+ if (outstandingSecrets.length > 0) {
53
+ const shouldContinue = await (0, prompt_1.confirm)({
54
+ message: `Extension instance ${instanceId} has secrets with the "firebase-extensions-managed" label:\n${outstandingSecrets.join(", ")}\nContinuing with extension uninstall will permanently destroy these secrets.\nYou can keep these secrets by running ext:export, or by manually removing the label in the Cloud Console.\nContinue?`,
55
+ default: false,
56
+ nonInteractive: options.nonInteractive,
57
+ force: options.force,
58
+ });
59
+ if (!shouldContinue) {
60
+ if (options.nonInteractive && !options.force) {
61
+ throw new error_1.FirebaseError(`Extension instance ${instanceId} has managed secrets that would be permanently destroyed. Re-run with --force in non-interactive mode to confirm deletion.`);
62
+ }
63
+ return;
64
+ }
65
+ }
27
66
  await (0, migrate_1.uninstallExtension)(projectId, instanceId, options, false);
28
67
  return;
29
68
  }
@@ -9,14 +9,17 @@ const requireAuth_1 = require("../requireAuth");
9
9
  const requireConfig_1 = require("../requireConfig");
10
10
  exports.command = new command_1.Command("functions:kits:install")
11
11
  .description("install a function kit into your project")
12
+ .before(() => {
13
+ experiments.assertEnabled("kits", "install a function kit");
14
+ })
12
15
  .before(requireConfig_1.requireConfig)
13
16
  .before(requireAuth_1.requireAuth)
17
+ .withForce()
14
18
  .option("--package <package>", "NPM package name or specifier to install as a function kit")
15
19
  .option("--directory <directory>", "path to a local functions codebase directory to install as a function kit")
16
20
  .option(`--template <template>`, `template to use for the kit index file (${Object.keys(install_1.TEMPLATES).join("|")})`)
17
21
  .option("--no-configure", "skip parameter prompting and configuration during installation")
18
22
  .action(async (options) => {
19
- experiments.assertEnabled("kits", "install a function kit");
20
23
  if (!options.config) {
21
24
  throw new error_1.FirebaseError("Not in a Firebase project directory (firebase.json not found).");
22
25
  }
@@ -14,11 +14,12 @@ const utils_1 = require("../utils");
14
14
  const logger_1 = require("../logger");
15
15
  const delete_1 = require("../deploy/functions/delete");
16
16
  exports.command = new command_1.Command("functions:kits:uninstall")
17
- .description("uninstall a function kit or kit instance from your project")
17
+ .description("uninstall a function kit or kit instance from your project. Deletes all running resources and the associated managed service account.")
18
18
  .before(requireConfig_1.requireConfig)
19
19
  .before(requireAuth_1.requireAuth)
20
20
  .option("--kit <kitId>", "")
21
21
  .option("--instance <instanceId>", "")
22
+ .withForce()
22
23
  .action(async (options) => {
23
24
  const firebaseConfig = options.config;
24
25
  if (options.instance && options.kit) {
@@ -13,8 +13,10 @@ exports.isBlockingTriggered = isBlockingTriggered;
13
13
  exports.resolveBackend = resolveBackend;
14
14
  exports.envWithTypes = envWithTypes;
15
15
  exports.toBackend = toBackend;
16
- exports.applyPrefix = applyPrefix;
17
- exports.applyEnvSecretBindings = applyEnvSecretBindings;
16
+ exports.applyKitSecretRefPrefix = applyKitSecretRefPrefix;
17
+ exports.applyEndpointPrefix = applyEndpointPrefix;
18
+ exports.applyEnvSecretBindingsToParams = applyEnvSecretBindingsToParams;
19
+ exports.applyEnvSecretBindingsToBuild = applyEnvSecretBindingsToBuild;
18
20
  exports.parseSecretRef = parseSecretRef;
19
21
  const backend = require("./backend");
20
22
  const proto = require("../../gcp/proto");
@@ -23,9 +25,11 @@ const logger_1 = require("../../logger");
23
25
  const error_1 = require("../../error");
24
26
  const functional_1 = require("../../functional");
25
27
  const cel_1 = require("./cel");
28
+ const projects = require("../../management/projects");
29
+ const projectConfig_1 = require("../../functions/projectConfig");
26
30
  exports.REGION_TBD = "REGION_TBD";
27
31
  exports.SECRET_REF_PREFIX = "FIREBASE_SECRET_REF_";
28
- const GCP_PROJECT_ID_PATTERN = "([a-z][-a-z0-9]{4,28}[a-z0-9])";
32
+ const GCP_PROJECT_ID_OR_NUM_PATTERN = "((?:\\d+)|(?:[a-z][-a-z0-9]{4,28}[a-z0-9]))";
29
33
  exports.GCP_SECRET_ID_PATTERN = "([a-zA-Z0-9-_]+)";
30
34
  exports.SECRET_REF_SHORT_RE = new RegExp("^" +
31
35
  exports.GCP_SECRET_ID_PATTERN +
@@ -34,7 +38,7 @@ exports.SECRET_REF_SHORT_RE = new RegExp("^" +
34
38
  ")?$");
35
39
  exports.SECRET_REF_LONG_RE = new RegExp("^" +
36
40
  "projects/" +
37
- GCP_PROJECT_ID_PATTERN +
41
+ GCP_PROJECT_ID_OR_NUM_PATTERN +
38
42
  "/secrets/" +
39
43
  exports.GCP_SECRET_ID_PATTERN +
40
44
  "(?:(?:/versions/|:|#|@)" +
@@ -82,7 +86,15 @@ exports.AllIngressSettings = [
82
86
  "ALLOW_INTERNAL_AND_GCLB",
83
87
  ];
84
88
  async function resolveBackend(opts) {
85
- const { paramValues: paramValues, secretRefs: secretRefs } = await params.resolveParams(opts.build.params, opts.firebaseConfig, envWithTypes(opts.build.params, opts.userEnvs), opts.codebase, opts.nonInteractive, opts.force, opts.isEmulator);
89
+ const { paramValues: paramValues, secretRefs: secretRefs } = await params.resolveParams({
90
+ params: opts.build.params,
91
+ firebaseConfig: opts.firebaseConfig,
92
+ userEnvs: envWithTypes(opts.build.params, opts.userEnvs),
93
+ codebase: opts.codebase,
94
+ nonInteractive: opts.nonInteractive,
95
+ force: opts.force,
96
+ isEmulator: opts.isEmulator,
97
+ });
86
98
  return { backend: toBackend(opts.build, paramValues), envs: paramValues, secretRefs: secretRefs };
87
99
  }
88
100
  function envWithTypes(definedParams, rawEnvs) {
@@ -377,7 +389,18 @@ function discoverTrigger(endpoint, region, r) {
377
389
  }
378
390
  (0, functional_1.assertExhaustive)(endpoint);
379
391
  }
380
- function applyPrefix(build, prefix) {
392
+ function applyKitSecretRefPrefix(build, instanceId) {
393
+ const kitPrefix = (0, projectConfig_1.addKitPrefix)(instanceId);
394
+ for (const secretParam of build.params.filter((p) => params.isSecretParam(p))) {
395
+ secretParam.resourceId = `${kitPrefix}-${secretParam.name}`;
396
+ }
397
+ for (const endpoint of Object.values(build.endpoints)) {
398
+ for (const envVar of endpoint.secretEnvironmentVariables ?? []) {
399
+ envVar.secret = `${kitPrefix}-${envVar.secret}`;
400
+ }
401
+ }
402
+ }
403
+ function applyEndpointPrefix(build, prefix) {
381
404
  if (!prefix) {
382
405
  return;
383
406
  }
@@ -392,12 +415,6 @@ function applyPrefix(build, prefix) {
392
415
  throw new error_1.FirebaseError(`Function id '${newId}' is invalid after applying prefix '${prefix}'. Function names must start with a letter and can contain letters, numbers, underscores, and hyphens, with a maximum length of 63 characters.`);
393
416
  }
394
417
  newEndpoints[newId] = endpoint;
395
- if (endpoint.secretEnvironmentVariables) {
396
- endpoint.secretEnvironmentVariables = endpoint.secretEnvironmentVariables.map((secret) => ({
397
- ...secret,
398
- secret: `${prefix}-${secret.secret}`,
399
- }));
400
- }
401
418
  }
402
419
  build.endpoints = newEndpoints;
403
420
  if (build.lifecycleHooks) {
@@ -423,7 +440,19 @@ function applyPrefix(build, prefix) {
423
440
  }
424
441
  }
425
442
  }
426
- function applyEnvSecretBindings(build, envSecrets) {
443
+ function applyEnvSecretBindingsToParams(params, envSecrets) {
444
+ for (const key of Object.keys(envSecrets)) {
445
+ const { secretId, version } = envSecrets[key];
446
+ for (const param of params) {
447
+ if (param.type === "secret" && param.name.toUpperCase() === key.toUpperCase()) {
448
+ param.resourceId = secretId;
449
+ param.version = version;
450
+ param.inLocalEnvironment = true;
451
+ }
452
+ }
453
+ }
454
+ }
455
+ async function applyEnvSecretBindingsToBuild(build, envSecrets) {
427
456
  if (envSecrets.empty) {
428
457
  return;
429
458
  }
@@ -431,15 +460,20 @@ function applyEnvSecretBindings(build, envSecrets) {
431
460
  for (const endpointName of Object.keys(build.endpoints)) {
432
461
  logger_1.logger.debug(`${endpointName} declared secrets: ${JSON.stringify(build.endpoints[endpointName].secretEnvironmentVariables)}`);
433
462
  }
463
+ applyEnvSecretBindingsToParams(build.params, envSecrets);
464
+ const projectNumberToId = new Map();
434
465
  for (const key of Object.keys(envSecrets)) {
435
466
  const secretRef = envSecrets[key];
436
- const { projectId, secretId, version } = secretRef;
437
- for (const param of build.params) {
438
- if (param.type === "secret" && param.name.toUpperCase() === key) {
439
- param.resourceId = secretId;
440
- param.version = version;
441
- param.inLocalEnvironment = true;
467
+ let { projectId } = secretRef;
468
+ const { secretId, version } = secretRef;
469
+ if (projectId && /^\d+$/.test(projectId)) {
470
+ let resolvedId = projectNumberToId.get(projectId);
471
+ if (!resolvedId) {
472
+ const project = await projects.getProject(projectId);
473
+ resolvedId = project.projectId;
474
+ projectNumberToId.set(projectId, resolvedId);
442
475
  }
476
+ projectId = resolvedId;
443
477
  }
444
478
  for (const endpointName of Object.keys(build.endpoints)) {
445
479
  const endpoint = build.endpoints[endpointName];
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REQUIRED_SECURITY_APIS = void 0;
3
4
  exports.defaultServiceAccount = defaultServiceAccount;
4
5
  exports.cloudBuildEnabled = cloudBuildEnabled;
5
6
  exports.secretsAccessDelta = secretsAccessDelta;
6
7
  exports.checkSecretAccess = checkSecretAccess;
7
8
  exports.grantSecretAccess = grantSecretAccess;
9
+ exports.checkDeclarativeSecurityApisEnabled = checkDeclarativeSecurityApisEnabled;
8
10
  const clc = require("colorette");
9
- const ensureApiEnabled_1 = require("../../ensureApiEnabled");
11
+ const ensureApiEnabled = require("../../ensureApiEnabled");
10
12
  const error_1 = require("../../error");
11
13
  const utils_1 = require("../../utils");
12
14
  const secretManager_1 = require("../../gcp/secretManager");
@@ -15,6 +17,7 @@ const functional_1 = require("../../functional");
15
17
  const api_1 = require("../../api");
16
18
  const backend = require("./backend");
17
19
  const computeEngine_1 = require("../../gcp/computeEngine");
20
+ const logger_1 = require("../../logger");
18
21
  const FAQ_URL = "https://firebase.google.com/support/faq#functions-runtime";
19
22
  const metadataCallCache = new Map();
20
23
  async function defaultServiceAccount(e) {
@@ -57,7 +60,7 @@ function isPermissionError(e) {
57
60
  }
58
61
  async function cloudBuildEnabled(projectId) {
59
62
  try {
60
- await (0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.cloudbuildOrigin)(), "functions");
63
+ await ensureApiEnabled.ensure(projectId, (0, api_1.cloudbuildOrigin)(), "functions");
61
64
  }
62
65
  catch (e) {
63
66
  if ((0, error_1.isBillingError)(e)) {
@@ -119,3 +122,40 @@ async function grantSecretAccess(args) {
119
122
  await (0, secretManager_1.ensureServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
120
123
  (0, utils_1.logLabeledSuccess)("functions", `ensured ${clc.bold(serviceAccounts.join(", "))} access to ${clc.bold(secret)}.`);
121
124
  }
125
+ exports.REQUIRED_SECURITY_APIS = [
126
+ "iam.googleapis.com",
127
+ "cloudresourcemanager.googleapis.com",
128
+ ];
129
+ async function checkDeclarativeSecurityApisEnabled(projectId, codebase) {
130
+ const checks = await Promise.all(exports.REQUIRED_SECURITY_APIS.map(async (api) => {
131
+ try {
132
+ return await ensureApiEnabled.check(projectId, api, "functions", true);
133
+ }
134
+ catch (err) {
135
+ const isPermissionDenied = err?.status === 403 ||
136
+ isPermissionError(err);
137
+ if (isPermissionDenied) {
138
+ logger_1.logger.debug(`Silencing permission error checking enablement for API ${api}:`, err);
139
+ return true;
140
+ }
141
+ throw err;
142
+ }
143
+ }));
144
+ const disabledApis = exports.REQUIRED_SECURITY_APIS.filter((_, idx) => !checks[idx]);
145
+ if (disabledApis.length > 0) {
146
+ const apiBulletList = disabledApis.map((api) => ` - ${clc.bold(api)}`).join("\n");
147
+ const enableCmd = clc.bold(`gcloud services enable ${disabledApis.join(" ")} --project ${projectId}`);
148
+ const consoleLinks = disabledApis
149
+ .map((api) => ` - ${api}: ${ensureApiEnabled.enableApiURI(projectId, api)}`)
150
+ .join("\n");
151
+ throw new error_1.FirebaseError(`Cannot deploy functions with declarative security in codebase "${codebase}". ` +
152
+ `The following required Google Cloud API(s) are not enabled on project ${clc.bold(projectId)}:\n` +
153
+ apiBulletList +
154
+ `\n\nDeclarative security requires these APIs to provision and configure managed service accounts and IAM roles.\n` +
155
+ `To enable them, run:\n\n` +
156
+ ` ${enableCmd}\n\n` +
157
+ `Or ask a project owner to enable them in the Google Cloud Console:\n` +
158
+ consoleLinks +
159
+ `\n`, { exit: 1 });
160
+ }
161
+ }
@@ -11,6 +11,7 @@ exports.targetCodebases = targetCodebases;
11
11
  exports.groupEndpointsByCodebase = groupEndpointsByCodebase;
12
12
  exports.isCodebaseFiltered = isCodebaseFiltered;
13
13
  exports.isEndpointFiltered = isEndpointFiltered;
14
+ exports.isCodebasePartiallyFiltered = isCodebasePartiallyFiltered;
14
15
  exports.parseDeleteFilters = parseDeleteFilters;
15
16
  exports.detectCodebaseAndIdCollisions = detectCodebaseAndIdCollisions;
16
17
  const backend = require("./backend");
@@ -140,6 +141,12 @@ function isCodebaseFiltered(codebase, filters) {
140
141
  function isEndpointFiltered(endpoint, filters) {
141
142
  return filters.some((filter) => endpointMatchesFilter(endpoint, filter));
142
143
  }
144
+ function isCodebasePartiallyFiltered(codebase, filters) {
145
+ if (!filters) {
146
+ return false;
147
+ }
148
+ return filters.some((f) => (!f.codebase || f.codebase === codebase) && !!f.idChunks && f.idChunks.length > 0);
149
+ }
143
150
  function parseDeleteFilters(filters, activeCodebases) {
144
151
  const liveCodebasesConfig = activeCodebases.map((codebase) => ({ source: "", codebase }));
145
152
  return filters.flatMap((f) => {
@@ -9,6 +9,7 @@ exports.isTextInput = isTextInput;
9
9
  exports.isSelectInput = isSelectInput;
10
10
  exports.isResourceInput = isResourceInput;
11
11
  exports.isMultiSelectInput = isMultiSelectInput;
12
+ exports.isSecretParam = isSecretParam;
12
13
  exports.resolveParams = resolveParams;
13
14
  const clc = require("colorette");
14
15
  const logger_1 = require("../../logger");
@@ -22,6 +23,7 @@ const storage_1 = require("../../gcp/storage");
22
23
  const cel_1 = require("./cel");
23
24
  const secretManager_1 = require("../../gcp/secretManager");
24
25
  const experiments = require("../../experiments");
26
+ const marked_1 = require("marked");
25
27
  function dependenciesCEL(expr) {
26
28
  const deps = [];
27
29
  const paramCapture = /{{ params\.(\w+) }}/g;
@@ -82,6 +84,9 @@ function isResourceInput(input) {
82
84
  function isMultiSelectInput(input) {
83
85
  return {}.hasOwnProperty.call(input, "multiSelect");
84
86
  }
87
+ function isSecretParam(param) {
88
+ return param.type === "secret";
89
+ }
85
90
  class ParamValue {
86
91
  constructor(rawValue, internal, types) {
87
92
  this.rawValue = rawValue;
@@ -163,7 +168,8 @@ function canSatisfyParam(param, value) {
163
168
  }
164
169
  (0, functional_1.assertExhaustive)(param);
165
170
  }
166
- async function resolveParams(params, firebaseConfig, userEnvs, codebase, nonInteractive, force, isEmulator = false) {
171
+ async function resolveParams(opts) {
172
+ const { params, firebaseConfig, userEnvs, codebase, nonInteractive = false, force = false, isEmulator = false, } = opts;
167
173
  const paramValues = populateDefaultParams(firebaseConfig);
168
174
  const secretRefs = {};
169
175
  const [resolved, outstanding] = (0, functional_1.partition)(params, (param) => {
@@ -258,7 +264,11 @@ async function ensureSecret(secretParam, projectId, nonInteractive, force) {
258
264
  }
259
265
  return ensureSecret(secretParam, projectId, nonInteractive, force);
260
266
  }
261
- const promptMessage = `The value for this secret (${secretParam.name}) will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${resourceId}. Enter ${secretParam.format === "json" ? "a JSON value" : "a value"} for ${secretParam.label || secretParam.name}:`;
267
+ const label = secretParam.label || secretParam.name;
268
+ const notice = `The value for this secret will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${resourceId}.`;
269
+ const desc = secretParam.description ? `${secretParam.description} ${notice}` : notice;
270
+ logger_1.logger.info(`\n${clc.bold(label)}: ${(await (0, marked_1.marked)(desc)).trim()}`);
271
+ const promptMessage = `Enter ${secretParam.format === "json" ? "a JSON value" : "a value"} for ${label}:`;
262
272
  const secretValue = await (0, prompt_1.password)({
263
273
  message: promptMessage,
264
274
  });
@@ -287,6 +297,13 @@ async function ensureSecret(secretParam, projectId, nonInteractive, force) {
287
297
  return secretRefString;
288
298
  }
289
299
  async function promptParam(param, projectId, resolvedDefault) {
300
+ const label = param.label || param.name;
301
+ if (param.description) {
302
+ logger_1.logger.info(`\n${clc.bold(label)}: ${(await (0, marked_1.marked)(param.description)).trim()}`);
303
+ }
304
+ else {
305
+ logger_1.logger.info("");
306
+ }
290
307
  if (param.type === "string") {
291
308
  const provided = await promptStringParam(param, projectId, resolvedDefault);
292
309
  return new ParamValue(provided.toString(), false, { string: true });
@@ -313,33 +330,21 @@ async function promptList(param, projectId, resolvedDefault) {
313
330
  const defaultToText = { text: {} };
314
331
  param.input = defaultToText;
315
332
  }
316
- let prompt;
333
+ const label = param.label || param.name;
317
334
  if (isSelectInput(param.input)) {
318
335
  throw new error_1.FirebaseError("List params cannot have non-list selector inputs");
319
336
  }
320
337
  else if (isMultiSelectInput(param.input)) {
321
- prompt = `Select a value for ${param.label || param.name}:`;
322
- if (param.description) {
323
- prompt += ` \n(${param.description})`;
324
- }
325
- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. ";
326
- return promptSelectMultiple(prompt, param.input, resolvedDefault, param.input.multiSelect.nonEmpty, (res) => res);
338
+ return promptSelectMultiple(`Select values for ${label}:`, param.input, resolvedDefault, param.input.multiSelect.nonEmpty, (res) => res);
327
339
  }
328
340
  else if (isTextInput(param.input)) {
329
- prompt = `Enter a list of strings (delimiter: ${param.delimiter ? param.delimiter : ","}) for ${param.label || param.name}:`;
330
- if (param.description) {
331
- prompt += ` \n(${param.description})`;
332
- }
333
- return promptText(prompt, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => {
334
- return res.split(param.delimiter || ",");
341
+ const delimiter = param.delimiter ? param.delimiter : ",";
342
+ return promptText(`Enter a list of strings (delimiter: ${delimiter}) for ${label}:`, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => {
343
+ return res.split(delimiter);
335
344
  });
336
345
  }
337
346
  else if (isResourceInput(param.input)) {
338
- prompt = `Select values for ${param.label || param.name}:`;
339
- if (param.description) {
340
- prompt += ` \n(${param.description})`;
341
- }
342
- return promptResourceStrings(prompt, param.input, projectId, false);
347
+ return promptResourceStrings(`Select values for ${label}:`, param.input, projectId, false);
343
348
  }
344
349
  else {
345
350
  (0, functional_1.assertExhaustive)(param.input);
@@ -351,24 +356,15 @@ async function promptBooleanParam(param, resolvedDefault) {
351
356
  param.input = defaultToText;
352
357
  }
353
358
  const isTruthyInput = (res) => ["true", "y", "yes", "1"].includes(res.toLowerCase());
354
- let prompt;
359
+ const label = param.label || param.name;
355
360
  if (isSelectInput(param.input)) {
356
- prompt = `Select a value for ${param.label || param.name}:`;
357
- if (param.description) {
358
- prompt += ` \n(${param.description})`;
359
- }
360
- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. ";
361
- return promptSelect(prompt, param.input, resolvedDefault, isTruthyInput);
361
+ return promptSelect(`Select a value for ${label}:`, param.input, resolvedDefault, isTruthyInput);
362
362
  }
363
363
  else if (isMultiSelectInput(param.input)) {
364
364
  throw new error_1.FirebaseError("Non-list params cannot have multi selector inputs");
365
365
  }
366
366
  else if (isTextInput(param.input)) {
367
- prompt = `Enter a boolean value for ${param.label || param.name}:`;
368
- if (param.description) {
369
- prompt += ` \n(${param.description})`;
370
- }
371
- return promptText(prompt, param.input, resolvedDefault, false, isTruthyInput);
367
+ return promptText(`Enter a boolean value for ${label}:`, param.input, resolvedDefault, false, isTruthyInput);
372
368
  }
373
369
  else if (isResourceInput(param.input)) {
374
370
  throw new error_1.FirebaseError("Boolean params cannot have Cloud Resource selector inputs");
@@ -382,31 +378,18 @@ async function promptStringParam(param, projectId, resolvedDefault) {
382
378
  const defaultToText = { text: {} };
383
379
  param.input = defaultToText;
384
380
  }
385
- let prompt;
381
+ const label = param.label || param.name;
386
382
  if (isResourceInput(param.input)) {
387
- prompt = `Select a value for ${param.label || param.name}:`;
388
- if (param.description) {
389
- prompt += ` \n(${param.description})`;
390
- }
391
- return promptResourceString(prompt, param.input, projectId, resolvedDefault);
383
+ return promptResourceString(`Select a value for ${label}:`, param.input, projectId, resolvedDefault);
392
384
  }
393
385
  else if (isMultiSelectInput(param.input)) {
394
386
  throw new error_1.FirebaseError("Non-list params cannot have multi selector inputs");
395
387
  }
396
388
  else if (isSelectInput(param.input)) {
397
- prompt = `Select a value for ${param.label || param.name}:`;
398
- if (param.description) {
399
- prompt += ` \n(${param.description})`;
400
- }
401
- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. ";
402
- return promptSelect(prompt, param.input, resolvedDefault, (res) => res);
389
+ return promptSelect(`Select a value for ${label}:`, param.input, resolvedDefault, (res) => res);
403
390
  }
404
391
  else if (isTextInput(param.input)) {
405
- prompt = `Enter a string value for ${param.label || param.name}:`;
406
- if (param.description) {
407
- prompt += ` \n(${param.description})`;
408
- }
409
- return promptText(prompt, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => res);
392
+ return promptText(`Enter a string value for ${label}:`, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => res);
410
393
  }
411
394
  else {
412
395
  (0, functional_1.assertExhaustive)(param.input);
@@ -417,14 +400,9 @@ async function promptIntParam(param, resolvedDefault) {
417
400
  const defaultToText = { text: {} };
418
401
  param.input = defaultToText;
419
402
  }
420
- let prompt;
403
+ const label = param.label || param.name;
421
404
  if (isSelectInput(param.input)) {
422
- prompt = `Select a value for ${param.label || param.name}:`;
423
- if (param.description) {
424
- prompt += ` \n(${param.description})`;
425
- }
426
- prompt += "\nSelect an option with the arrow keys, and use Enter to confirm your choice. ";
427
- return promptSelect(prompt, param.input, resolvedDefault, (res) => {
405
+ return promptSelect(`Select a value for ${label}:`, param.input, resolvedDefault, (res) => {
428
406
  if (isNaN(+res)) {
429
407
  return { message: `"${res}" could not be converted to a number.` };
430
408
  }
@@ -438,11 +416,7 @@ async function promptIntParam(param, resolvedDefault) {
438
416
  throw new error_1.FirebaseError("Non-list params cannot have multi selector inputs");
439
417
  }
440
418
  else if (isTextInput(param.input)) {
441
- prompt = `Enter an integer value for ${param.label || param.name}:`;
442
- if (param.description) {
443
- prompt += ` \n(${param.description})`;
444
- }
445
- return promptText(prompt, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => {
419
+ return promptText(`Enter an integer value for ${label}:`, param.input, resolvedDefault, param.input.text.nonEmpty, (res) => {
446
420
  if (isNaN(+res)) {
447
421
  return { message: `"${res}" could not be converted to a number.` };
448
422
  }
@@ -532,6 +506,7 @@ async function promptSelect(prompt, input, resolvedDefault, converter) {
532
506
  const response = await (0, prompt_1.select)({
533
507
  default: resolvedDefault,
534
508
  message: prompt,
509
+ instructions: "(Use arrow keys to navigate, and Enter to confirm your choice)",
535
510
  choices: input.select.options.map((option) => {
536
511
  return {
537
512
  checked: false,
@@ -551,6 +526,7 @@ async function promptSelectMultiple(prompt, input, resolvedDefault, enforceNonEm
551
526
  const response = await (0, prompt_1.checkbox)({
552
527
  default: resolvedDefault,
553
528
  message: prompt,
529
+ instructions: "(Press Space to select, and Enter to confirm your choices)",
554
530
  choices: input.multiSelect.options.map((option) => {
555
531
  return {
556
532
  checked: false,