'use strict';

var WDSPHVPJ_cjs = require('./WDSPHVPJ.cjs');
var U7VZULNU_cjs = require('./U7VZULNU.cjs');
var path = require('path');
var os = require('os');
var fs = require('fs');
var crypto = require('crypto');

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getProfileName.js
U7VZULNU_cjs.init_cjs_shims();
var ENV_PROFILE = "AWS_PROFILE";
var DEFAULT_PROFILE = "default";
var getProfileName = /* @__PURE__ */ U7VZULNU_cjs.__name((init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE, "getProfileName");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSsoSessionData.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigFilepath.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getHomeDir.js
U7VZULNU_cjs.init_cjs_shims();
var homeDirCache = {};
var getHomeDirCacheKey = /* @__PURE__ */ U7VZULNU_cjs.__name(() => {
  if (process && process.geteuid) {
    return `${process.geteuid()}`;
  }
  return "DEFAULT";
}, "getHomeDirCacheKey");
var getHomeDir = /* @__PURE__ */ U7VZULNU_cjs.__name(() => {
  const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${path.sep}` } = process.env;
  if (HOME) return HOME;
  if (USERPROFILE) return USERPROFILE;
  if (HOMEPATH) return `${HOMEDRIVE}${HOMEPATH}`;
  const homeDirCacheKey = getHomeDirCacheKey();
  if (!homeDirCache[homeDirCacheKey]) homeDirCache[homeDirCacheKey] = os.homedir();
  return homeDirCache[homeDirCacheKey];
}, "getHomeDir");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigFilepath.js
var ENV_CONFIG_PATH = "AWS_CONFIG_FILE";
var getConfigFilepath = /* @__PURE__ */ U7VZULNU_cjs.__name(() => process.env[ENV_CONFIG_PATH] || path.join(getHomeDir(), ".aws", "config"), "getConfigFilepath");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getSsoSessionData.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSharedConfigFiles.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigData.js
U7VZULNU_cjs.init_cjs_shims();
var getConfigData = /* @__PURE__ */ U7VZULNU_cjs.__name((data) => Object.entries(data).filter(([key]) => {
  const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
  if (indexOfSeparator === -1) {
    return false;
  }
  return Object.values(WDSPHVPJ_cjs.IniSectionType).includes(key.substring(0, indexOfSeparator));
}).reduce((acc, [key, value]) => {
  const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
  const updatedKey = key.substring(0, indexOfSeparator) === WDSPHVPJ_cjs.IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key;
  acc[updatedKey] = value;
  return acc;
}, {
  ...data.default && {
    default: data.default
  }
}), "getConfigData");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getCredentialsFilepath.js
U7VZULNU_cjs.init_cjs_shims();
var ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
var getCredentialsFilepath = /* @__PURE__ */ U7VZULNU_cjs.__name(() => process.env[ENV_CREDENTIALS_PATH] || path.join(getHomeDir(), ".aws", "credentials"), "getCredentialsFilepath");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/parseIni.js
U7VZULNU_cjs.init_cjs_shims();
var prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
var profileNameBlockList = [
  "__proto__",
  "profile __proto__"
];
var parseIni = /* @__PURE__ */ U7VZULNU_cjs.__name((iniData) => {
  const map = {};
  let currentSection;
  let currentSubSection;
  for (const iniLine of iniData.split(/\r?\n/)) {
    const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
    const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
    if (isSection) {
      currentSection = void 0;
      currentSubSection = void 0;
      const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
      const matches = prefixKeyRegex.exec(sectionName);
      if (matches) {
        const [, prefix, , name] = matches;
        if (Object.values(WDSPHVPJ_cjs.IniSectionType).includes(prefix)) {
          currentSection = [
            prefix,
            name
          ].join(CONFIG_PREFIX_SEPARATOR);
        }
      } else {
        currentSection = sectionName;
      }
      if (profileNameBlockList.includes(sectionName)) {
        throw new Error(`Found invalid profile name "${sectionName}"`);
      }
    } else if (currentSection) {
      const indexOfEqualsSign = trimmedLine.indexOf("=");
      if (![
        0,
        -1
      ].includes(indexOfEqualsSign)) {
        const [name, value] = [
          trimmedLine.substring(0, indexOfEqualsSign).trim(),
          trimmedLine.substring(indexOfEqualsSign + 1).trim()
        ];
        if (value === "") {
          currentSubSection = name;
        } else {
          if (currentSubSection && iniLine.trimStart() === iniLine) {
            currentSubSection = void 0;
          }
          map[currentSection] = map[currentSection] || {};
          const key = currentSubSection ? [
            currentSubSection,
            name
          ].join(CONFIG_PREFIX_SEPARATOR) : name;
          map[currentSection][key] = value;
        }
      }
    }
  }
  return map;
}, "parseIni");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/slurpFile.js
U7VZULNU_cjs.init_cjs_shims();
var { readFile } = fs.promises;
var filePromisesHash = {};
var slurpFile = /* @__PURE__ */ U7VZULNU_cjs.__name((path, options) => {
  if (!filePromisesHash[path] || options?.ignoreCache) {
    filePromisesHash[path] = readFile(path, "utf8");
  }
  return filePromisesHash[path];
}, "slurpFile");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSharedConfigFiles.js
var swallowError = /* @__PURE__ */ U7VZULNU_cjs.__name(() => ({}), "swallowError");
var CONFIG_PREFIX_SEPARATOR = ".";
var loadSharedConfigFiles = /* @__PURE__ */ U7VZULNU_cjs.__name(async (init = {}) => {
  const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init;
  const homeDir = getHomeDir();
  const relativeHomeDirPrefix = "~/";
  let resolvedFilepath = filepath;
  if (filepath.startsWith(relativeHomeDirPrefix)) {
    resolvedFilepath = path.join(homeDir, filepath.slice(2));
  }
  let resolvedConfigFilepath = configFilepath;
  if (configFilepath.startsWith(relativeHomeDirPrefix)) {
    resolvedConfigFilepath = path.join(homeDir, configFilepath.slice(2));
  }
  const parsedFiles = await Promise.all([
    slurpFile(resolvedConfigFilepath, {
      ignoreCache: init.ignoreCache
    }).then(parseIni).then(getConfigData).catch(swallowError),
    slurpFile(resolvedFilepath, {
      ignoreCache: init.ignoreCache
    }).then(parseIni).catch(swallowError)
  ]);
  return {
    configFile: parsedFiles[0],
    credentialsFile: parsedFiles[1]
  };
}, "loadSharedConfigFiles");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getSsoSessionData.js
var getSsoSessionData = /* @__PURE__ */ U7VZULNU_cjs.__name((data) => Object.entries(data).filter(([key]) => key.startsWith(WDSPHVPJ_cjs.IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR)).reduce((acc, [key, value]) => ({
  ...acc,
  [key.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1)]: value
}), {}), "getSsoSessionData");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSsoSessionData.js
var swallowError2 = /* @__PURE__ */ U7VZULNU_cjs.__name(() => ({}), "swallowError");
var loadSsoSessionData = /* @__PURE__ */ U7VZULNU_cjs.__name(async (init = {}) => slurpFile(init.configFilepath ?? getConfigFilepath()).then(parseIni).then(getSsoSessionData).catch(swallowError2), "loadSsoSessionData");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/parseKnownFiles.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/mergeConfigFiles.js
U7VZULNU_cjs.init_cjs_shims();
var mergeConfigFiles = /* @__PURE__ */ U7VZULNU_cjs.__name((...files) => {
  const merged = {};
  for (const file of files) {
    for (const [key, values] of Object.entries(file)) {
      if (merged[key] !== void 0) {
        Object.assign(merged[key], values);
      } else {
        merged[key] = values;
      }
    }
  }
  return merged;
}, "mergeConfigFiles");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/parseKnownFiles.js
var parseKnownFiles = /* @__PURE__ */ U7VZULNU_cjs.__name(async (init) => {
  const parsedFiles = await loadSharedConfigFiles(init);
  return mergeConfigFiles(parsedFiles.configFile, parsedFiles.credentialsFile);
}, "parseKnownFiles");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/index.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getSSOTokenFilepath.js
U7VZULNU_cjs.init_cjs_shims();
var getSSOTokenFilepath = /* @__PURE__ */ U7VZULNU_cjs.__name((id) => {
  const hasher = crypto.createHash("sha1");
  const cacheName = hasher.update(id).digest("hex");
  return path.join(getHomeDir(), ".aws", "sso", "cache", `${cacheName}.json`);
}, "getSSOTokenFilepath");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/getSSOTokenFromFile.js
U7VZULNU_cjs.init_cjs_shims();
var { readFile: readFile2 } = fs.promises;
var getSSOTokenFromFile = /* @__PURE__ */ U7VZULNU_cjs.__name(async (id) => {
  const ssoTokenFilepath = getSSOTokenFilepath(id);
  const ssoTokenText = await readFile2(ssoTokenFilepath, "utf8");
  return JSON.parse(ssoTokenText);
}, "getSSOTokenFromFile");

// ../../node_modules/.pnpm/@smithy+shared-ini-file-loader@4.0.5/node_modules/@smithy/shared-ini-file-loader/dist-es/types.js
U7VZULNU_cjs.init_cjs_shims();

exports.CONFIG_PREFIX_SEPARATOR = CONFIG_PREFIX_SEPARATOR;
exports.ENV_PROFILE = ENV_PROFILE;
exports.getProfileName = getProfileName;
exports.getSSOTokenFilepath = getSSOTokenFilepath;
exports.getSSOTokenFromFile = getSSOTokenFromFile;
exports.loadSharedConfigFiles = loadSharedConfigFiles;
exports.loadSsoSessionData = loadSsoSessionData;
exports.parseKnownFiles = parseKnownFiles;
//# sourceMappingURL=P5BPMTGP.cjs.map
//# sourceMappingURL=P5BPMTGP.cjs.map