No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ext-configure.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const { marked } = require("marked");
  5. const TerminalRenderer = require("marked-terminal");
  6. const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
  7. const command_1 = require("../command");
  8. const error_1 = require("../error");
  9. const projectUtils_1 = require("../projectUtils");
  10. const extensionsApi = require("../extensions/extensionsApi");
  11. const extensionsHelper_1 = require("../extensions/extensionsHelper");
  12. const paramHelper = require("../extensions/paramHelper");
  13. const requirePermissions_1 = require("../requirePermissions");
  14. const utils = require("../utils");
  15. const logger_1 = require("../logger");
  16. const refs = require("../extensions/refs");
  17. const manifest = require("../extensions/manifest");
  18. const functional_1 = require("../functional");
  19. const paramHelper_1 = require("../extensions/paramHelper");
  20. const askUserForEventsConfig = require("../extensions/askUserForEventsConfig");
  21. marked.setOptions({
  22. renderer: new TerminalRenderer(),
  23. });
  24. exports.command = new command_1.Command("ext:configure <extensionInstanceId>")
  25. .description("configure an existing extension instance")
  26. .withForce()
  27. .option("--local", "deprecated")
  28. .before(requirePermissions_1.requirePermissions, [
  29. "firebaseextensions.instances.update",
  30. "firebaseextensions.instances.get",
  31. ])
  32. .before(checkMinRequiredVersion_1.checkMinRequiredVersion, "extMinVersion")
  33. .before(extensionsHelper_1.diagnoseAndFixProject)
  34. .action(async (instanceId, options) => {
  35. const projectId = (0, projectUtils_1.getProjectId)(options);
  36. if (options.nonInteractive) {
  37. throw new error_1.FirebaseError(`Command not supported in non-interactive mode, edit ./extensions/${instanceId}.env directly instead. ` +
  38. `See https://firebase.google.com/docs/extensions/manifest for more details.`);
  39. }
  40. if (options.local) {
  41. utils.logLabeledWarning(extensionsHelper_1.logPrefix, "As of firebase-tools@11.0.0, the `--local` flag is no longer required, as it is the default behavior.");
  42. }
  43. const config = manifest.loadConfig(options);
  44. const refOrPath = manifest.getInstanceTarget(instanceId, config);
  45. const isLocalSource = (0, extensionsHelper_1.isLocalPath)(refOrPath);
  46. let spec;
  47. if (isLocalSource) {
  48. const source = await (0, extensionsHelper_1.createSourceFromLocation)((0, projectUtils_1.needProjectId)({ projectId }), refOrPath);
  49. spec = source.spec;
  50. }
  51. else {
  52. const extensionVersion = await extensionsApi.getExtensionVersion(refOrPath);
  53. spec = extensionVersion.spec;
  54. }
  55. const oldParamValues = manifest.readInstanceParam({
  56. instanceId,
  57. projectDir: config.projectDir,
  58. });
  59. const [immutableParams, tbdParams] = (0, functional_1.partition)(spec.params, (param) => { var _a; return (_a = param.immutable) !== null && _a !== void 0 ? _a : false; });
  60. infoImmutableParams(immutableParams, oldParamValues);
  61. paramHelper.setNewDefaults(tbdParams, oldParamValues);
  62. const mutableParamsBindingOptions = await paramHelper.getParams({
  63. projectId,
  64. paramSpecs: tbdParams,
  65. nonInteractive: false,
  66. paramsEnvPath: "",
  67. instanceId,
  68. reconfiguring: true,
  69. });
  70. const eventsConfig = spec.events
  71. ? await askUserForEventsConfig.askForEventsConfig(spec.events, "${param:PROJECT_ID}", instanceId)
  72. : undefined;
  73. if (eventsConfig) {
  74. mutableParamsBindingOptions.EVENTARC_CHANNEL = { baseValue: eventsConfig.channel };
  75. mutableParamsBindingOptions.ALLOWED_EVENT_TYPES = {
  76. baseValue: eventsConfig.allowedEventTypes.join(","),
  77. };
  78. }
  79. const newParamOptions = Object.assign(Object.assign({}, (0, paramHelper_1.buildBindingOptionsWithBaseValue)(oldParamValues)), mutableParamsBindingOptions);
  80. await manifest.writeToManifest([
  81. {
  82. instanceId,
  83. ref: !isLocalSource ? refs.parse(refOrPath) : undefined,
  84. localPath: isLocalSource ? refOrPath : undefined,
  85. params: newParamOptions,
  86. extensionSpec: spec,
  87. },
  88. ], config, {
  89. nonInteractive: false,
  90. force: true,
  91. });
  92. manifest.showPostDeprecationNotice();
  93. return;
  94. });
  95. function infoImmutableParams(immutableParams, paramValues) {
  96. if (!immutableParams.length) {
  97. return;
  98. }
  99. const plural = immutableParams.length > 1;
  100. utils.logLabeledWarning(extensionsHelper_1.logPrefix, marked(`The following param${plural ? "s are" : " is"} immutable and won't be changed:`));
  101. for (const { param } of immutableParams) {
  102. logger_1.logger.info(`param: ${param}, value: ${paramValues[param]}`);
  103. }
  104. logger_1.logger.info((plural
  105. ? "To set different values for these params"
  106. : "To set a different value for this param") +
  107. ", uninstall the extension, then install a new instance of this extension.");
  108. }