import{a as g}from"./chunk-ZCWB3HFB.js";import{b as d,f as u}from"./chunk-WI7DO2VU.js";import{b as a}from"./chunk-TX7AAHER.js";function h(r){let o={};if(r=r.replace(/^\?/,""),r)for(let n of r.split("&")){let[e,t=null]=n.split("=");e=decodeURIComponent(e),t&&(t=decodeURIComponent(t)),e in o?Array.isArray(o[e])?o[e].push(t):o[e]=[o[e],t]:o[e]=t}return o}var F=r=>{if(typeof r=="string")return F(new URL(r));let{hostname:o,pathname:n,port:e,protocol:t,search:i}=r,f;return i&&(f=h(i)),{hostname:o,port:e?parseInt(e):void 0,protocol:t,path:n,query:f}};var y=r=>()=>Promise.resolve(r);var w=(r,o,n)=>{let e,t,i,f=!1,s=async()=>{t||(t=r());try{e=await t,i=!0,f=!1}finally{t=void 0}return e};return o===void 0?async c=>((!i||c?.forceRefresh)&&(e=await s()),e):async c=>((!i||c?.forceRefresh)&&(e=await s()),f?e:n&&!n(e)?(f=!0,e):(o(e)&&await s(),e))};function m(r){try{let o=new Set(Array.from(r.match(/([A-Z_]){3,}/g)??[]));return o.delete("CONFIG"),o.delete("CONFIG_PREFIX_SEPARATOR"),o.delete("ENV"),[...o].join(", ")}catch{return r}}var C=(r,o)=>async()=>{try{let n=r(process.env,o);if(n===void 0)throw new Error;return n}catch(n){throw new a(n.message||`Not found in ENV: ${m(r.toString())}`,{logger:o?.logger})}};var S=(r,{preferredFile:o="config",...n}={})=>async()=>{let e=d(n),{configFile:t,credentialsFile:i}=await u(n),f=i[e]||{},s=t[e]||{},c=o==="config"?{...f,...s}:{...s,...f};try{let p=r(c,o==="config"?t:i);if(p===void 0)throw new Error;return p}catch(l){throw new a(l.message||`Not found in config files w/ profile [${e}]: ${m(r.toString())}`,{logger:n.logger})}};var N=r=>typeof r=="function",v=r=>N(r)?async()=>await r():y(r);var b=({environmentVariableSelector:r,configFileSelector:o,default:n},e={})=>{let{signingName:t,logger:i}=e;return w(g(C(r,{signingName:t,logger:i}),S(o,e),v(n)))};export{F as a,w as b,b as c};
