11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst {
41cb0ef41Sopenharmony_ci  getCLIOptions,
51cb0ef41Sopenharmony_ci  getEmbedderOptions: getEmbedderOptionsFromBinding,
61cb0ef41Sopenharmony_ci} = internalBinding('options');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cilet warnOnAllowUnauthorized = true;
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cilet optionsMap;
111cb0ef41Sopenharmony_cilet aliasesMap;
121cb0ef41Sopenharmony_cilet embedderOptions;
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci// getCLIOptions() would serialize the option values from C++ land.
151cb0ef41Sopenharmony_ci// It would error if the values are queried before bootstrap is
161cb0ef41Sopenharmony_ci// complete so that we don't accidentally include runtime-dependent
171cb0ef41Sopenharmony_ci// states into a runtime-independent snapshot.
181cb0ef41Sopenharmony_cifunction getCLIOptionsFromBinding() {
191cb0ef41Sopenharmony_ci  if (!optionsMap) {
201cb0ef41Sopenharmony_ci    ({ options: optionsMap } = getCLIOptions());
211cb0ef41Sopenharmony_ci  }
221cb0ef41Sopenharmony_ci  return optionsMap;
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cifunction getAliasesFromBinding() {
261cb0ef41Sopenharmony_ci  if (!aliasesMap) {
271cb0ef41Sopenharmony_ci    ({ aliases: aliasesMap } = getCLIOptions());
281cb0ef41Sopenharmony_ci  }
291cb0ef41Sopenharmony_ci  return aliasesMap;
301cb0ef41Sopenharmony_ci}
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_cifunction getEmbedderOptions() {
331cb0ef41Sopenharmony_ci  if (!embedderOptions) {
341cb0ef41Sopenharmony_ci    embedderOptions = getEmbedderOptionsFromBinding();
351cb0ef41Sopenharmony_ci  }
361cb0ef41Sopenharmony_ci  return embedderOptions;
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_cifunction refreshOptions() {
401cb0ef41Sopenharmony_ci  optionsMap = undefined;
411cb0ef41Sopenharmony_ci  aliasesMap = undefined;
421cb0ef41Sopenharmony_ci}
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_cifunction getOptionValue(optionName) {
451cb0ef41Sopenharmony_ci  const options = getCLIOptionsFromBinding();
461cb0ef41Sopenharmony_ci  if (optionName.startsWith('--no-')) {
471cb0ef41Sopenharmony_ci    const option = options.get('--' + optionName.slice(5));
481cb0ef41Sopenharmony_ci    return option && !option.value;
491cb0ef41Sopenharmony_ci  }
501cb0ef41Sopenharmony_ci  return options.get(optionName)?.value;
511cb0ef41Sopenharmony_ci}
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_cifunction getAllowUnauthorized() {
541cb0ef41Sopenharmony_ci  const allowUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0';
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci  if (allowUnauthorized && warnOnAllowUnauthorized) {
571cb0ef41Sopenharmony_ci    warnOnAllowUnauthorized = false;
581cb0ef41Sopenharmony_ci    process.emitWarning(
591cb0ef41Sopenharmony_ci      'Setting the NODE_TLS_REJECT_UNAUTHORIZED ' +
601cb0ef41Sopenharmony_ci      'environment variable to \'0\' makes TLS connections ' +
611cb0ef41Sopenharmony_ci      'and HTTPS requests insecure by disabling ' +
621cb0ef41Sopenharmony_ci      'certificate verification.');
631cb0ef41Sopenharmony_ci  }
641cb0ef41Sopenharmony_ci  return allowUnauthorized;
651cb0ef41Sopenharmony_ci}
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_cimodule.exports = {
681cb0ef41Sopenharmony_ci  get options() {
691cb0ef41Sopenharmony_ci    return getCLIOptionsFromBinding();
701cb0ef41Sopenharmony_ci  },
711cb0ef41Sopenharmony_ci  get aliases() {
721cb0ef41Sopenharmony_ci    return getAliasesFromBinding();
731cb0ef41Sopenharmony_ci  },
741cb0ef41Sopenharmony_ci  getOptionValue,
751cb0ef41Sopenharmony_ci  getAllowUnauthorized,
761cb0ef41Sopenharmony_ci  getEmbedderOptions,
771cb0ef41Sopenharmony_ci  refreshOptions,
781cb0ef41Sopenharmony_ci};
79