@fntio/infra-client
Version:
Self-hosted AWS access portal: credential vending, target-account trust, and grant-driven private networking as CDK stacks and constructs.
2 lines (1 loc) • 14.2 kB
JavaScript
import{a as ne,b as te,c as ie}from"./chunk-TOO3FEYQ.js";import{i as oe}from"./chunk-YMS43IBH.js";import{b as V}from"./chunk-6CP7VLN2.js";import"./chunk-XUEIITMC.js";import{v as ee}from"./chunk-Z2HQA5DO.js";import"./chunk-J7PZFXOE.js";import{a as Z}from"./chunk-KCJ5HNXP.js";import"./chunk-6GDWMGWO.js";import"./chunk-ZRDXKVPG.js";import{Da as s,Ea as r,Fa as Y,I as y,Ja as h,K as f,Ka as N,L as P,Ma as T,Na as p,Pb as X,Q as K,R as H,Ra as $,Sa as W,Va as z,Xa as a,_ as v,ga as B,k as I,qb as Q,rb as L,ta as S,ua as b,ub as J}from"./chunk-FYA6QUPZ.js";import{a as C,b as M,e as R}from"./chunk-WFIHWVQO.js";var U=["--background","--surface","--surface-foreground","--muted","--muted-foreground","--text-secondary","--placeholder","--border","--border-strong","--ring","--card-bg","--popover-bg","--state-hover","--state-selected","--gray-1","--gray-2","--gray-3","--gray-4","--gray-5","--gray-6","--gray-7","--gray-8","--gray-9","--gray-10","--gray-11","--gray-12","--accent-1","--accent-2","--accent-3","--accent-4","--accent-5","--accent-6","--accent-7","--accent-8","--accent-9","--accent-10","--accent-11","--accent-12","--brand-primary","--brand-primary-hover","--brand-foreground","--brand-text","--brand-muted-foreground","--success","--success-muted","--warning","--warning-muted","--danger","--danger-hover","--danger-muted","--radius","--radius-md","--radius-lg","--radius-xl","--font-sans","--font-mono","--ease-standard","--ease-emphasized"],he=new Set(U);function Te(e){return he.has(e)}function F(e){if(!e||typeof e!="object")return!1;let n=e;if(n.appearance!=="light"&&n.appearance!=="dark"||!n.tokens||typeof n.tokens!="object"||Array.isArray(n.tokens))return!1;for(let[i,o]of Object.entries(n.tokens))if(!Te(i)||typeof o!="string")return!1;let t=n.branding;return!(!t||typeof t!="object"||typeof t.projectName!="string"||t.logoUrl!==void 0&&typeof t.logoUrl!="string")}var q="infra-client-plugin",w=2,le=1e4;function A(e){return{token:e.token,expiresAt:e.expiresAt}}var _e=["init","sessionChanged","sessionEnded","accessChanged","themeChanged"],xe=["ready","requestSessionRefresh","requestAccessRefresh"];function D(e,n,t,i){return M(C({protocol:q,version:w,type:e,instanceId:n},i===void 0?{}:{requestId:i}),{payload:t})}var m=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),E=e=>typeof e=="string"&&e.length>0;function se(e){return m(e)&&E(e.token)&&typeof e.expiresAt=="number"&&Number.isFinite(e.expiresAt)}function ve(e){return m(e)&&typeof e.accountNumber=="string"&&te.test(e.accountNumber)&&typeof e.displayName=="string"&&(e.regions===void 0||Array.isArray(e.regions)&&e.regions.every(n=>typeof n=="string"))&&Array.isArray(e.permissions)&&e.permissions.every(n=>ne.includes(n))}function re(e){return Array.isArray(e)&&e.every(ve)}function Ee(e){return m(e)&&E(e.subject)&&(e.principalType==="user"||e.principalType==="service")&&(e.email===void 0||typeof e.email=="string")&&(e.displayName===void 0||typeof e.displayName=="string")}function Ce(e){return m(e)&&E(e.id)&&typeof e.displayName=="string"&&typeof e.version=="string"&&typeof e.revision=="string"&&typeof e.apiBaseUrl=="string"}var ae={init:e=>m(e)&&se(e.session)&&Ee(e.user)&&Ce(e.plugin)&&(e.entry==="user"||e.entry==="admin")&&re(e.accounts)&&F(e.theme),sessionChanged:se,sessionEnded:e=>m(e)&&(e.reason==="signedOut"||e.reason==="expired"||e.reason==="unloaded"),accessChanged:e=>m(e)&&re(e.accounts)&&typeof e.entryAvailable=="boolean",themeChanged:F,ready:e=>m(e)&&E(e.sdkVersion)&&e.protocolVersion===w,requestSessionRefresh:e=>m(e)&&(e.reason==="unauthorized"||e.reason==="expiring"),requestAccessRefresh:e=>m(e)&&(e.reason==="forbidden"||e.reason==="manual")};function Se(e){if(!m(e)||e.protocol!==q||e.version!==w||typeof e.type!="string"||!Object.hasOwn(ae,e.type)||!E(e.instanceId)||e.requestId!==void 0&&!E(e.requestId))return null;let n=e.type;return ae[n](e.payload)?D(n,e.instanceId,e.payload,e.requestId):null}var $e=new Set(_e),be=new Set(xe);function de(e){return be.has(e.type)}function ue(e){if(!m(e)||e.protocol!==q)return{kind:"ignored"};if(e.version!==w)return{kind:"incompatible",version:e.version};let n=Se(e);return n?{kind:"message",message:n}:{kind:"ignored"}}var ke=e=>({session:A(e.session),user:e.user,plugin:e.plugin,entry:e.entry,accounts:e.accounts,theme:e.theme});function ce(e){let n="waiting",t=null,i=null,o=null,c,d=!1,_=e.handshakeTimeoutMs??le,j=_>0?setTimeout(()=>{n==="waiting"&&e.onHandshakeTimeout?.()},_):void 0,x=(l,g,u)=>{let k=e.frame.contentWindow;n!=="connected"||!t||!k||k.postMessage(D(l,t,g,u),e.origin)},O=l=>{n!=="ended"&&(x("sessionEnded",{reason:l}),n="ended",d=!1,clearTimeout(j),e.listenOn.removeEventListener("message",G),e.onEnded?.(l))},pe=l=>{let g=t===l.instanceId,u=t!==null&&!g;u&&(d=!1),t=l.instanceId,n="connected",clearTimeout(j),x("init",ke(e.initialState())),g||e.onReady?.({instanceId:t,sdkVersion:l.payload.sdkVersion,reconnect:u})},ye=(l,g)=>{d=!0,c=g,!i&&(o=l,i=Promise.resolve().then(()=>e.refreshSession()).catch(()=>null),i.then(u=>{i=null;let k=o,fe=d,Pe=c;if(o=null,d=!1,c=void 0,!(n==="ended"||!fe||k!==t)){if(!u){O("expired");return}x("sessionChanged",A(u),Pe)}}))},G=l=>{if(n==="ended"||l.source!==e.frame.contentWindow||l.origin!==e.origin)return;let g=ue(l.data);if(g.kind==="incompatible"){e.onIncompatible?.({version:g.version});return}if(g.kind!=="message"||!de(g.message))return;let u=g.message;if(u.type==="ready"){pe(u);return}if(u.instanceId===t)switch(u.type){case"requestSessionRefresh":ye(u.instanceId,u.requestId);return;case"requestAccessRefresh":e.onRequestAccessRefresh?.(u.payload.reason);return;default:return}};return e.listenOn.addEventListener("message",G),{state:()=>n,instanceId:()=>t,sendSession:l=>x("sessionChanged",A(l)),sendAccess:l=>x("accessChanged",l),sendTheme:l=>x("themeChanged",l),end:O,dispose:()=>O("unloaded")}}function ge(e,n=document){let t=n.documentElement,i=getComputedStyle(t),o={};for(let c of U){let d=i.getPropertyValue(c).trim();d&&(o[c]=d)}return{appearance:t.getAttribute("data-theme")==="dark"?"dark":"light",tokens:o,branding:{projectName:e}}}var Me=["frame"];function we(e,n){e&1&&(s(0,"p",3),a(1,"Loading\u2026"),r())}function Ae(e,n){if(e&1){let t=h();s(0,"div",3)(1,"p"),a(2,"Your plugins could not be loaded."),r(),s(3,"p",6),a(4,"The portal could not fetch the plugin list."),r(),s(5,"button",7),T("click",function(){f(t);let o=p(2);return P(o.retry())}),a(6,"Try again"),r()()}if(e&2){let t=p(2);v(5),N("disabled",t.store.loading())}}function Oe(e,n){if(e&1){let t=h();s(0,"div",3)(1,"p"),a(2,"This plugin is not available to you."),r(),s(3,"p",6),a(4,"It may have been turned off, or your access may have been revoked."),r(),s(5,"button",8),T("click",function(){f(t);let o=p(2);return P(o.retry())}),a(6,"Check again"),r()()}}function Re(e,n){if(e&1){let t=h();s(0,"div",3)(1,"p"),a(2,"Your access to this plugin ended."),r(),s(3,"p",6),a(4,"An administrator revoked it, or the plugin was disabled."),r(),s(5,"button",8),T("click",function(){f(t);let o=p(2);return P(o.retry())}),a(6,"Check again"),r()()}}function Ie(e,n){if(e&1){let t=h();s(0,"div",3)(1,"p"),a(2,"This plugin's page is not deployed."),r(),s(3,"p",6),a(4,"Its files are missing from the portal; an administrator needs to publish the plugin again."),r(),s(5,"button",8),T("click",function(){f(t);let o=p(2);return P(o.reload())}),a(6,"Try again"),r()()}}function He(e,n){if(e&1){let t=h();s(0,"div",3)(1,"p"),a(2,"The plugin did not start."),r(),s(3,"p",6),a(4,"Its page loaded but never connected to the portal."),r(),s(5,"button",8),T("click",function(){f(t);let o=p(2);return P(o.reload())}),a(6,"Try again"),r()()}}function Ne(e,n){e&1&&(s(0,"div",3)(1,"p"),a(2,"This plugin was built for a different version of the portal."),r(),s(3,"p",6),a(4,"It needs rebuilding against the current plugin SDK before it can load."),r()())}function Le(e,n){e&1&&(s(0,"p",3),a(1,"Your session ended."),r())}function Ve(e,n){if(e&1){let t=h();s(0,"div",4)(1,"p"),a(2,"A newer version of this plugin is available."),r(),s(3,"button",8),T("click",function(){f(t);let o=p(2);return P(o.reload())}),a(4,"Reload it"),r()()}}function Ue(e,n){e&1&&(s(0,"p",5),a(1,"The last refresh of your plugin access failed; showing what was last known."),r())}function Fe(e,n){if(e&1&&(s(0,"div",1),S(1,we,2,0,"p",3)(2,Ae,7,1,"div",3)(3,Oe,7,0,"div",3)(4,Re,7,0,"div",3)(5,Ie,7,0,"div",3)(6,He,7,0,"div",3)(7,Ne,5,0,"div",3)(8,Le,2,0,"p",3),S(9,Ve,5,0,"div",4),S(10,Ue,2,0,"p",5),r()),e&2){let t,i=p();v(),b((t=i.state())==="loading"?1:t==="error"?2:t==="unavailable"?3:t==="accessLost"?4:t==="missing"?5:t==="timeout"?6:t==="incompatible"?7:t==="ended"?8:-1),v(8),b(i.newRevision()?9:-1),v(),b(i.store.stale()&&i.state()==="running"?10:-1)}}var qe=["user","admin"],De=e=>qe.find(n=>n===e)??null,me=class e{route=y(X);pluginId=V(this.route.paramMap.pipe(I(n=>n.get("pluginId")??"")),{initialValue:""});section=V(this.route.paramMap.pipe(I(n=>De(n.get("section")))),{initialValue:null});store=y(ie);auth=y(ee);config=y(Z);theme=y(oe);destroyRef=y(K);frame=J.required("frame");state=H("loading");startedRevision=null;newRevision=H(!1);entry=Q(()=>{let n=this.section();return n?this.store.entry(this.pluginId(),n):void 0});host;launchedFor=null;launchSeq=0;sentAccess=null;constructor(){L(()=>{let n=this.entry();if(!this.store.ready()){this.store.stale()&&this.state.set("error");return}if(!n){let t=this.host!==void 0&&this.launchedFor===this.routeKey();this.teardown(),this.state.set(t?"accessLost":"unavailable");return}this.launchedFor!==this.routeKey()?this.reload():this.pushAccess(n)}),L(()=>{let n=this.theme.theme();this.host&&this.state()==="running"&&this.host.sendTheme(this.currentTheme())}),this.destroyRef.onDestroy(()=>this.teardown())}retry(){this.store.refresh()}reload(){let n=this.entry();n&&(this.teardown(),this.state.set("loading"),this.launch(n))}launch(n){let t=this.section(),i=t?n.ui[t]:void 0;if(!t||!i)return;this.state.set("loading"),this.startedRevision=n.revision,this.launchedFor=this.routeKey(),this.newRevision.set(!1);let o=new URL(i.url,window.location.href),c=++this.launchSeq;this.assetDeployed(o).then(d=>{if(c===this.launchSeq){if(!d){this.state.set("missing");return}this.startFrame(n,t,i.url,o)}})}assetDeployed(n){return R(this,null,function*(){let t=new URL(n);t.hash="";try{return(yield fetch(t,{credentials:"omit",cache:"no-store"})).ok}catch{return!0}})}startFrame(n,t,i,o){let c=this.frame().nativeElement;this.host=ce({frame:c,origin:window.location.origin,listenOn:window,initialState:()=>this.initialState(this.entry()??n,t),refreshSession:()=>R(this,null,function*(){return!(yield this.auth.refreshNow())&&!this.auth.isAuthenticated()?null:this.session()}),onReady:()=>this.state.set("running"),onHandshakeTimeout:()=>this.state.set("timeout"),onRequestAccessRefresh:()=>this.store.refresh(),onIncompatible:()=>this.state.set("incompatible"),onEnded:_=>{(_==="expired"||_==="signedOut")&&this.state.set("ended")}});let d=this.loadedUrl(c);c.src=i,o.hash&&d&&d.origin===o.origin&&d.pathname===o.pathname&&d.search===o.search&&c.contentWindow?.location.reload()}loadedUrl(n){try{let t=n.contentWindow?.location.href;return t&&t!=="about:blank"?new URL(t):null}catch{return null}}pushAccess(n){let t=this.section();if(!this.host||!t)return;this.startedRevision&&n.revision!==this.startedRevision&&this.newRevision.set(!0);let i=this.accounts(n,t),o=JSON.stringify(i);o!==this.sentAccess&&(this.sentAccess=o,this.host.sendAccess({accounts:i,entryAvailable:!0}))}initialState(n,t){let i=this.accounts(n,t);return this.sentAccess=JSON.stringify(i),{session:this.session(),user:C({subject:this.auth.userSub(),principalType:"user"},this.auth.userEmail()?{email:this.auth.userEmail()}:{}),plugin:{id:n.id,displayName:n.displayName,version:n.version,revision:n.revision,apiBaseUrl:n.apiBaseUrl},entry:t,accounts:i,theme:this.currentTheme()}}accounts(n,t){return n.accounts.filter(i=>i.permissions.includes(t)).map(i=>M(C({accountNumber:i.accountNumber,displayName:i.displayName},i.regions?.length?{regions:i.regions}:{}),{permissions:i.permissions}))}session(){return{token:this.auth.idToken()??"",expiresAt:this.auth.idTokenExpiresAt()}}currentTheme(){return ge(this.config.branding().projectName||"")}routeKey(){return`${this.pluginId()}/${this.section()}`}teardown(){this.launchSeq++,this.host?.dispose(),this.host=void 0,this.launchedFor=null,this.startedRevision=null,this.sentAccess=null,this.newRevision.set(!1)}static \u0275fac=function(t){return new(t||e)};static \u0275cmp=B({type:e,selectors:[["app-plugin-page"]],viewQuery:function(t,i){t&1&&$(i.frame,Me,5),t&2&&W()},hostAttrs:[1,"flex","min-h-0","flex-1","flex-col"],decls:3,vars:4,consts:[["frame",""],[1,"notes"],["referrerpolicy","same-origin",1,"frame",3,"title"],[1,"note"],[1,"note","revision"],[1,"note","dim"],[1,"dim"],["type","button",3,"click","disabled"],["type","button",3,"click"]],template:function(t,i){if(t&1&&(S(0,Fe,11,3,"div",1),Y(1,"iframe",2,0)),t&2){let o;b(i.state()!=="running"||i.newRevision()||i.store.stale()?0:-1),v(),z("hidden",i.state()!=="running"),N("title",((o=i.entry())==null?null:o.displayName)??i.pluginId())}},styles:['.notes[_ngcontent-%COMP%]{display:flex;flex-direction:column;gap:.75rem;padding:1.5rem 2rem 0}.note[_ngcontent-%COMP%]{border:1px solid var(--border);border-radius:var(--radius-lg);background:var(--card-bg);padding:1.25rem;display:flex;flex-direction:column;align-items:flex-start;gap:.5rem;margin:0}.note[_ngcontent-%COMP%] p[_ngcontent-%COMP%]{margin:0}.dim[_ngcontent-%COMP%]{color:var(--muted-foreground);font-size:.9rem}.revision[_ngcontent-%COMP%]{flex-direction:row;align-items:center;justify-content:space-between}.frame[_ngcontent-%COMP%]{flex:1 1 auto;min-height:0;width:100%;border:0;background:transparent;color-scheme:light}[data-theme="dark"][_nghost-%COMP%] .frame[_ngcontent-%COMP%], [data-theme="dark"] [_nghost-%COMP%] .frame[_ngcontent-%COMP%]{color-scheme:dark}.frame.hidden[_ngcontent-%COMP%]{display:none}button[_ngcontent-%COMP%]{border:1px solid var(--border-strong);border-radius:var(--radius);background:var(--surface);color:inherit;padding:.35rem .75rem;cursor:pointer;font:inherit}'],changeDetection:0})};export{me as PluginPageComponent};