@techdocs/cli
Version:
Utility CLI for managing TechDocs sites in Backstage.
3 lines (2 loc) • 5.21 kB
JavaScript
;(()=>{(self.webpackChunktechdocs_cli_embedded_app=self.webpackChunktechdocs_cli_embedded_app||[]).push([[4036],{70048:(I,m,e)=>{e.d(m,{K:()=>s});var t=e(18690);function s(P){return(0,t.g)()}},93160:(I,m,e)=>{e.d(m,{b:()=>Z,W:()=>X});var t=e(31085),s=e(14041),P=e(18690),x=e(24504),C=e(72020),D=e(88572),S=e(13976),B=e(45061),L=e(39299),K=e(82779),U=e(70048),v=e(19402),W=e(22020),F=e(82266),A=e(64947),M=e(72427),O=e(70795),T=e(57405),H=e(16261);function Y(g,c){const[E,f]=(0,s.useState)({status:"not-executed",error:void 0,result:c}),a=(0,s.useRef)(),n=(0,s.useRef)(),l=(0,H.J)({execute(...d){n.current=d;const i=g(...d);return a.current=i,f(r=>({...r,status:"loading"})),i.then(r=>{i===a.current&&f(o=>({...o,status:"success",error:void 0,result:r}))},r=>{i===a.current&&f(o=>({...o,status:"error",error:r}))}),i},reset(){f({status:"not-executed",error:void 0,result:c}),a.current=void 0,n.current=void 0}});return[E,(0,s.useMemo)(()=>({reset(){l.current.reset()},execute:(...d)=>l.current.execute(...d)}),[]),{promise:a.current,lastArgs:n.current}]}var $=e(76842),N=e(70835);const p="/.backstage/auth/v1/cookie",y=365*24*36e5;function R(g){const{pluginId:c}=g??{},E=(0,M.gf)(O.a),f=(0,M.gf)(T.I),a=(0,s.useMemo)(()=>"BroadcastChannel"in window?new BroadcastChannel(`${c}-auth-cookie-expires-at`):null,[c]),[n,l]=Y(async()=>{const o=`${await f.getBaseUrl(c)}${p}`,u=await E.fetch(`${o}`,{credentials:"include"});if(!u.ok){if(u.status===404)return{expiresAt:new Date(Date.now()+y)};throw await N.o.fromResponse(u)}const h=await u.json();if(!h.expiresAt)throw new Error("No expiration date found in response");return h});(0,$.u)(l.execute);const d=(0,s.useCallback)(()=>{l.execute()},[l]),i=(0,s.useCallback)(r=>{const o=(1+3*Math.random())*6e4,u=Date.parse(r.expiresAt)-Date.now()-o,h=setTimeout(d,u);return()=>clearTimeout(h)},[d]);return(0,s.useEffect)(()=>{if(n.status!=="success"||!n.result)return()=>{};a?.postMessage({action:"COOKIE_REFRESH_SUCCESS",payload:n.result});let r=i(n.result);const o=u=>{const{action:h,payload:b}=u.data;h==="COOKIE_REFRESH_SUCCESS"&&(r(),r=i(b))};return a?.addEventListener("message",o),()=>{r(),a?.removeEventListener("message",o)}},[n,i,a]),n.status==="not-executed"?{status:"loading"}:n.status==="loading"&&!n.result?{status:"loading"}:n.status==="loading"&&n.error?{status:"loading"}:n.status==="error"&&n.error?{status:"error",error:n.error,retry:d}:{status:"success",data:n.result}}function j(g){const{children:c,...E}=g,f=(0,F.n)(),{Progress:a}=f.getComponents(),n=R(E);return n.status==="loading"?(0,t.jsx)(a,{}):n.status==="error"?(0,t.jsx)(W.b,{error:n.error,children:(0,t.jsx)(A.A,{variant:"outlined",onClick:n.retry,children:"Retry"})}):(0,t.jsx)(t.Fragment,{children:c})}var z=e(58502),J=e(54917),G=e(98392),V=e(50868);const Z=g=>{const{withSearch:c,withHeader:E=!0}=g;return(0,t.jsxs)(x.Y,{themeId:"documentation",children:[E&&(0,t.jsx)(B.T,{}),(0,t.jsx)(L.Z,{}),(0,t.jsx)(S.p,{withSearch:c})]})},Q=(0,z.A)(x.Y)({height:"inherit",overflowY:"visible"}),X=g=>{const c=(0,J.A)(),E=(0,G.A)({...c,...g.overrideThemeOptions||{}}),{kind:f,name:a,namespace:n}=(0,U.K)(K.Oc),{children:l,entityRef:d={kind:f,name:a,namespace:n}}=g,i=(0,P.P1)();if(!l){const u=(i?s.Children.toArray(i.props.children):[]).flatMap(h=>h?.props?.children??[]).find(h=>!(0,v.E)(h,C.AF)&&!(0,v.E)(h,C.Wm));return(0,t.jsx)(V.A,{theme:E,children:(0,t.jsx)(j,{pluginId:"techdocs",children:(0,t.jsx)(D.R,{entityRef:d,children:u||(0,t.jsx)(Z,{})})})})}return(0,t.jsx)(V.A,{theme:E,children:(0,t.jsx)(j,{pluginId:"techdocs",children:(0,t.jsx)(D.R,{entityRef:d,children:({metadata:r,entityMetadata:o,onReady:u})=>(0,t.jsx)(Q,{themeId:"documentation",className:"techdocs-reader-page",children:l instanceof Function?l({entityRef:d,techdocsMetadataValue:r.value,entityMetadataValue:o.value,onReady:u}):l})})})})}},84036:(I,m,e)=>{e.r(m),e.d(m,{TechDocsReaderLayout:()=>t.b,TechDocsReaderPage:()=>t.W});var t=e(93160)},39299:(I,m,e)=>{e.d(m,{Z:()=>F});var t=e(31085),s=e(14041),P=e(58837),x=e(29365),C=e(75173),D=e(71677),S=e(37757),B=e(10394),L=e(9684),K=e(88572),U=e(72020),v=e(99730);const W=(0,P.A)(A=>({root:{gridArea:"pageSubheader",flexDirection:"column",minHeight:"auto",padding:A.spacing(3,3,0),"@media print":{display:"none"}}})),F=A=>{const M=W(),[O,T]=(0,s.useState)(null),H=(0,s.useCallback)(j=>{T(j.currentTarget)},[]),Y=(0,s.useCallback)(()=>{T(null)},[]),{entityMetadata:{value:$,loading:N}}=(0,K.V)(),p=(0,U.YR)(),y=p.renderComponentsByLocation(v.e.Subheader),R=p.renderComponentsByLocation(v.e.Settings);return!y&&!R||N===!1&&!$?null:(0,t.jsx)(C.A,{classes:M,...A.toolbarProps,children:(0,t.jsxs)(B.A,{display:"flex",justifyContent:"flex-end",width:"100%",flexWrap:"wrap",children:[y,R?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(D.Ay,{title:"Settings",children:(0,t.jsx)(x.A,{"aria-controls":"tech-docs-reader-page-settings","aria-haspopup":"true",onClick:H,children:(0,t.jsx)(L.A,{})})}),(0,t.jsx)(S.A,{id:"tech-docs-reader-page-settings",getContentAnchorEl:null,anchorEl:O,anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!O,onClose:Y,keepMounted:!0,children:(0,t.jsx)("div",{children:R})})]}):null]})})}}}]);})();
//# sourceMappingURL=4036.30d46c9e.chunk.js.map