UNPKG

@kya-os/mcp-i

Version:

The TypeScript MCP framework with identity features built-in

1 lines 7.41 kB
"use strict";exports.id=533,exports.ids=[533],exports.modules={28226:(e,s,o)=>{o.d(s,{C:()=>r});var n=o(76982),t=o(16928),i=o(14581);const r=e=>{const s=(0,n.createHash)("sha1").update(e).digest("hex");return(0,t.join)((0,i.R)(),".aws","sso","cache",`${s}.json`)}},32914:(e,s,o)=>{o.d(s,{fromSSO:()=>N});var n=o(43281),t=o(98229),i=o(32410),r=o(40768),a=o(90814),c=o(46086);const l=e=>Object.entries(e).filter(([e])=>e.startsWith(a.I.SSO_SESSION+c.Q)).reduce((e,[s,o])=>({...e,[s.substring(s.indexOf(c.Q)+1)]:o}),{});var g=o(41844),f=o(35789);const p=()=>({}),d=async(e={})=>(0,f.TA)(e.configFilepath??(0,r.g)()).then(g.A).then(l).catch(p);var h=o(53347),w=o(68413);class u extends w.m{name="TokenProviderError";constructor(e,s=!0){super(e,s),Object.setPrototypeOf(this,u.prototype)}}var C=o(78405);const S="To refresh this SSO session run 'aws sso login' with the corresponding profile.",_=e=>{if(e.expiration&&e.expiration.getTime()<Date.now())throw new u(`Token is expired. ${S}`,!1)},k=(e,s,o=!1)=>{if(void 0===s)throw new u(`Value not present for '${e}' in SSO Token${o?". Cannot refresh":""}. ${S}`,!1)};var m=o(28226),y=o(79896);const{writeFile:T}=y.promises,x=new Date(0),O=(e={})=>async({callerClientConfig:s}={})=>{e.logger?.debug("@aws-sdk/token-providers - fromSso");const n=await(0,i.Y)(e),r=(0,t.Bz)({profile:e.profile??s?.profile}),a=n[r];if(!a)throw new u(`Profile '${r}' could not be found in shared credentials file.`,!1);if(!a.sso_session)throw new u(`Profile '${r}' is missing required property 'sso_session'.`);const c=a.sso_session,l=(await d(e))[c];if(!l)throw new u(`Sso session '${c}' could not be found in shared credentials file.`,!1);for(const e of["sso_start_url","sso_region"])if(!l[e])throw new u(`Sso session '${c}' is missing required property '${e}'.`,!1);l.sso_start_url;const g=l.sso_region;let f;try{f=await(0,C.v)(c)}catch(e){throw new u(`The SSO session token associated with profile=${r} was not found or is invalid. ${S}`,!1)}k("accessToken",f.accessToken),k("expiresAt",f.expiresAt);const{accessToken:p,expiresAt:h}=f,w={token:p,expiration:new Date(h)};if(w.expiration.getTime()-Date.now()>3e5)return w;if(Date.now()-x.getTime()<3e4)return _(w),w;k("clientId",f.clientId,!0),k("clientSecret",f.clientSecret,!0),k("refreshToken",f.refreshToken,!0);try{x.setTime(Date.now());const n=await(async(e,s,n={},t)=>{const{CreateTokenCommand:i}=await Promise.all([o.e(452),o.e(227)]).then(o.bind(o,76608)),r=await(async(e,s={},n)=>{const{SSOOIDCClient:t}=await Promise.all([o.e(452),o.e(227)]).then(o.bind(o,76608)),i=e=>s.clientConfig?.[e]??s.parentClientConfig?.[e]??n?.[e];return new t(Object.assign({},s.clientConfig??{},{region:e??s.clientConfig?.region,logger:i("logger"),userAgentAppId:i("userAgentAppId")}))})(s,n,t);return r.send(new i({clientId:e.clientId,clientSecret:e.clientSecret,refreshToken:e.refreshToken,grantType:"refresh_token"}))})(f,g,e,s);k("accessToken",n.accessToken),k("expiresIn",n.expiresIn);const t=new Date(Date.now()+1e3*n.expiresIn);try{await((e,s)=>{const o=(0,m.C)(e),n=JSON.stringify(s,null,2);return T(o,n)})(c,{...f,accessToken:n.accessToken,expiresAt:t.toISOString(),refreshToken:n.refreshToken})}catch(e){}return{token:n.accessToken,expiration:t}}catch(e){return _(w),w}},I=!1,A=async({ssoStartUrl:e,ssoSession:s,ssoAccountId:t,ssoRegion:i,ssoRoleName:r,ssoClient:a,clientConfig:c,parentClientConfig:l,callerClientConfig:g,profile:f,filepath:p,configFilepath:d,ignoreCache:w,logger:u})=>{let S;const _="To refresh this SSO session run aws sso login with the corresponding profile.";if(s)try{const e=await O({profile:f,filepath:p,configFilepath:d,ignoreCache:w})();S={accessToken:e.token,expiresAt:new Date(e.expiration).toISOString()}}catch(e){throw new n.C(e.message,{tryNextLink:I,logger:u})}else try{S=await(0,C.v)(e)}catch(e){throw new n.C(`The SSO session associated with this profile is invalid. ${_}`,{tryNextLink:I,logger:u})}if(new Date(S.expiresAt).getTime()-Date.now()<=0)throw new n.C(`The SSO session associated with this profile has expired. ${_}`,{tryNextLink:I,logger:u});const{accessToken:k}=S,{SSOClient:m,GetRoleCredentialsCommand:y}=await Promise.all([o.e(452),o.e(65)]).then(o.bind(o,38065)),T=a||new m(Object.assign({},c??{},{logger:c?.logger??g?.logger??l?.logger,region:c?.region??i,userAgentAppId:c?.userAgentAppId??g?.userAgentAppId??l?.userAgentAppId}));let x;try{x=await T.send(new y({accountId:t,roleName:r,accessToken:k}))}catch(e){throw new n.C(e,{tryNextLink:I,logger:u})}const{roleCredentials:{accessKeyId:A,secretAccessKey:N,sessionToken:v,expiration:$,credentialScope:R,accountId:D}={}}=x;if(!(A&&N&&v&&$))throw new n.C("SSO returns an invalid temporary credential.",{tryNextLink:I,logger:u});const b={accessKeyId:A,secretAccessKey:N,sessionToken:v,expiration:new Date($),...R&&{credentialScope:R},...D&&{accountId:D}};return s?(0,h.g)(b,"CREDENTIALS_SSO","s"):(0,h.g)(b,"CREDENTIALS_SSO_LEGACY","u"),b},N=(e={})=>async({callerClientConfig:s}={})=>{e.logger?.debug("@aws-sdk/credential-provider-sso - fromSSO");const{ssoStartUrl:o,ssoAccountId:r,ssoRegion:a,ssoRoleName:c,ssoSession:l}=e,{ssoClient:g}=e,f=(0,t.Bz)({profile:e.profile??s?.profile});if(o||r||a||c||l){if(o&&r&&a&&c)return A({ssoStartUrl:o,ssoSession:l,ssoAccountId:r,ssoRegion:a,ssoRoleName:c,ssoClient:g,clientConfig:e.clientConfig,parentClientConfig:e.parentClientConfig,callerClientConfig:e.callerClientConfig,profile:f,filepath:e.filepath,configFilepath:e.configFilepath,ignoreCache:e.ignoreCache,logger:e.logger});throw new n.C('Incomplete configuration. The fromSSO() argument hash must include "ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"',{tryNextLink:!1,logger:e.logger})}{const s=(await(0,i.Y)(e))[f];if(!s)throw new n.C(`Profile ${f} was not found.`,{logger:e.logger});if(!(p=s)||"string"!=typeof p.sso_start_url&&"string"!=typeof p.sso_account_id&&"string"!=typeof p.sso_session&&"string"!=typeof p.sso_region&&"string"!=typeof p.sso_role_name)throw new n.C(`Profile ${f} is not configured with SSO credentials.`,{logger:e.logger});if(s?.sso_session){const t=(await d(e))[s.sso_session],i=` configurations in profile ${f} and sso-session ${s.sso_session}`;if(a&&a!==t.sso_region)throw new n.C("Conflicting SSO region"+i,{tryNextLink:!1,logger:e.logger});if(o&&o!==t.sso_start_url)throw new n.C("Conflicting SSO start_url"+i,{tryNextLink:!1,logger:e.logger});s.sso_region=t.sso_region,s.sso_start_url=t.sso_start_url}const{sso_start_url:t,sso_account_id:r,sso_region:c,sso_role_name:l,sso_session:h}=((e,s)=>{const{sso_start_url:o,sso_account_id:t,sso_region:i,sso_role_name:r}=e;if(!(o&&t&&i&&r))throw new n.C(`Profile is configured with invalid SSO credentials. Required parameters "sso_account_id", "sso_region", "sso_role_name", "sso_start_url". Got ${Object.keys(e).join(", ")}\nReference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html`,{tryNextLink:!1,logger:s});return e})(s,e.logger);return A({ssoStartUrl:t,ssoSession:h,ssoAccountId:r,ssoRegion:c,ssoRoleName:l,ssoClient:g,clientConfig:e.clientConfig,parentClientConfig:e.parentClientConfig,callerClientConfig:e.callerClientConfig,profile:f,filepath:e.filepath,configFilepath:e.configFilepath,ignoreCache:e.ignoreCache,logger:e.logger})}var p}},78405:(e,s,o)=>{o.d(s,{a:()=>i,v:()=>r});var n=o(91943),t=o(28226);const i={},r=async e=>{if(i[e])return i[e];const s=(0,t.C)(e),o=await(0,n.readFile)(s,"utf8");return JSON.parse(o)}}};