var A="AWS_PROFILE",N="default",q=e=>e.profile||process.env[A]||N;import{join as L}from"path";import{homedir as v}from"os";import{sep as w}from"path";var h={},H=()=>process&&process.geteuid?`${process.geteuid()}`:"DEFAULT",f=()=>{let{HOME:e,USERPROFILE:t,HOMEPATH:o,HOMEDRIVE:r=`C:${w}`}=process.env;if(e)return e;if(t)return t;if(o)return`${r}${o}`;let i=H();return h[i]||(h[i]=v()),h[i]};var b="AWS_CONFIG_FILE",F=()=>process.env[b]||L(f(),".aws","config");var c;(function(e){e.PROFILE="profile",e.SSO_SESSION="sso-session",e.SERVICES="services"})(c||(c={}));import{join as C}from"path";var E=e=>Object.entries(e).filter(([t])=>{let o=t.indexOf(".");return o===-1?!1:Object.values(c).includes(t.substring(0,o))}).reduce((t,[o,r])=>{let i=o.indexOf("."),n=o.substring(0,i)===c.PROFILE?o.substring(i+1):o;return t[n]=r,t},{...e.default&&{default:e.default}});import{join as j}from"path";var k="AWS_SHARED_CREDENTIALS_FILE",I=()=>process.env[k]||j(f(),".aws","credentials");var y=/^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/,$=["__proto__","profile __proto__"],g=e=>{let t={},o,r;for(let i of e.split(/\r?\n/)){let n=i.split(/(^|\s)[;#]/)[0].trim();if(n[0]==="["&&n[n.length-1]==="]"){o=void 0,r=void 0;let s=n.substring(1,n.length-1),p=y.exec(s);if(p){let[,m,,x]=p;Object.values(c).includes(m)&&(o=[m,x].join("."))}else o=s;if($.includes(s))throw new Error(`Found invalid profile name "${s}"`)}else if(o){let s=n.indexOf("=");if(![0,-1].includes(s)){let[p,m]=[n.substring(0,s).trim(),n.substring(s+1).trim()];if(m==="")r=p;else{r&&i.trimStart()===i&&(r=void 0),t[o]=t[o]||{};let x=r?[r,p].join("."):p;t[o][x]=m}}}}return t};import{readFile as G}from"fs/promises";var O={},u={},a=(e,t)=>u[e]!==void 0?u[e]:((!O[e]||t?.ignoreCache)&&(O[e]=G(e,"utf8")),O[e]);var _=()=>({}),R=async(e={})=>{let{filepath:t=I(),configFilepath:o=F()}=e,r=f(),i="~/",n=t;t.startsWith(i)&&(n=C(r,t.slice(2)));let S=o;o.startsWith(i)&&(S=C(r,o.slice(2)));let s=await Promise.all([a(S,{ignoreCache:e.ignoreCache}).then(g).then(E).catch(_),a(n,{ignoreCache:e.ignoreCache}).then(g).catch(_)]);return{configFile:s[0],credentialsFile:s[1]}};var D=e=>Object.entries(e).filter(([t])=>t.startsWith(c.SSO_SESSION+".")).reduce((t,[o,r])=>({...t,[o.substring(o.indexOf(".")+1)]:r}),{});var W=()=>({}),Re=async(e={})=>a(e.configFilepath??F()).then(g).then(D).catch(W);var P=(...e)=>{let t={};for(let o of e)for(let[r,i]of Object.entries(o))t[r]!==void 0?Object.assign(t[r],i):t[r]=i;return t};var Ne=async e=>{let t=await R(e);return P(t.configFile,t.credentialsFile)};import{readFile as X}from"fs/promises";import{createHash as K}from"crypto";import{join as V}from"path";var T=e=>{let o=K("sha1").update(e).digest("hex");return V(f(),".aws","sso","cache",`${o}.json`)};var d={},M=async e=>{if(d[e])return d[e];let t=T(e),o=await X(t,"utf8");return JSON.parse(o)};var U={getFileRecord(){return u},interceptFile(e,t){u[e]=Promise.resolve(t)},getTokenRecord(){return d},interceptToken(e,t){d[e]=t}};export{A as a,q as b,T as c,M as d,a as e,R as f,Re as g,Ne as h,U as i};
