@duplicati/ngclient 0.0.190 → 0.0.191

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.html CHANGED
@@ -124,5 +124,5 @@
124
124
  <body>
125
125
  <app-root></app-root>
126
126
  <div class="loading">Connecting ...</div>
127
- <link rel="modulepreload" href="chunk-VEWX3KXN.js"><link rel="modulepreload" href="chunk-GUUVY3EP.js"><link rel="modulepreload" href="chunk-KRXQDBGB.js"><link rel="modulepreload" href="chunk-7GOEY6MG.js"><link rel="modulepreload" href="chunk-FOQJA6X2.js"><link rel="modulepreload" href="chunk-VHOAXFIJ.js"><link rel="modulepreload" href="chunk-7RZEW7SE.js"><link rel="modulepreload" href="chunk-6Q6SSTBK.js"><link rel="modulepreload" href="chunk-FK7JFD5B.js"><link rel="modulepreload" href="chunk-5DJAX2HH.js"><script src="polyfills-7RKI4BGK.js" type="module"></script><script src="main-JTTKXWGP.js" type="module"></script></body>
127
+ <link rel="modulepreload" href="chunk-VEWX3KXN.js"><link rel="modulepreload" href="chunk-GUUVY3EP.js"><link rel="modulepreload" href="chunk-KRXQDBGB.js"><link rel="modulepreload" href="chunk-7GOEY6MG.js"><link rel="modulepreload" href="chunk-FOQJA6X2.js"><link rel="modulepreload" href="chunk-VHOAXFIJ.js"><link rel="modulepreload" href="chunk-7RZEW7SE.js"><link rel="modulepreload" href="chunk-6Q6SSTBK.js"><link rel="modulepreload" href="chunk-FK7JFD5B.js"><link rel="modulepreload" href="chunk-5DJAX2HH.js"><script src="polyfills-7RKI4BGK.js" type="module"></script><script src="main-5NMKOVOL.js" type="module"></script></body>
128
128
  </html>
@@ -0,0 +1 @@
1
+ import{b as ke,c as Ae}from"./chunk-VEWX3KXN.js";import{a as Te}from"./chunk-GUUVY3EP.js";import{a as Ie}from"./chunk-KRXQDBGB.js";import{a as k}from"./chunk-7GOEY6MG.js";import{a as Me}from"./chunk-FOQJA6X2.js";import{b as Ee}from"./chunk-VHOAXFIJ.js";import"./chunk-7RZEW7SE.js";import{a as D}from"./chunk-6Q6SSTBK.js";import{a as Re}from"./chunk-FK7JFD5B.js";import"./chunk-5DJAX2HH.js";import"./chunk-G4VDCGMW.js";import"./chunk-BR5N53HF.js";import{a as H}from"./chunk-TELPJYLN.js";import{a as h,b as be,c as C,d as we,e as I}from"./chunk-DAODMGAD.js";import{v as ve,x as Ce}from"./chunk-HPNLQHW6.js";import{a as ye,d as Se}from"./chunk-BGTK25UG.js";import{c as me,d as de,g as ue,h as he,i as fe,j as ge}from"./chunk-A4LPGPDU.js";import{a as re}from"./chunk-PKPBSTZA.js";import{a as se,b as ie,c as ae,e as pe,f as ce,g as le}from"./chunk-QPTSKQZ2.js";import{fa as oe,ka as ne}from"./chunk-OTPG7USH.js";import"./chunk-TT3S63BX.js";import{Bb as Z,E as M,I as K,Ic as ee,Jc as te,K as T,M as _,R as v,U as q,W as s,cb as Y,da as z,ea as X,f as W,g as $,l as G,la as d,m as B,na as Q,p as w,y as P,z as J}from"./chunk-T2WO6CVD.js";import"./chunk-7CGTOI24.js";var A=class e{#e=s(h);#a=s(C);ngOnInit(){be(),this.#a.fetchConfig(),this.#e.clearAllNotCurrentVersion()}static \u0275fac=function(o){return new(o||e)};static \u0275cmp=Y({type:e,selectors:[["app-root"]],decls:1,vars:0,template:function(o,n){o&1&&Z(0,"router-outlet")},dependencies:[me],encapsulation:2})};var Ne={production:!0,baseUrl:"/api",machineServerUrl:"${WS_URL}",defaultTimeout:3e4};var f=new q("ENVIRONMENT");var N=class e{#e=s(Se);isLoaded=d(!1);webmodules=d(null);preload(t=!1){let o=this.#e.getApiV1Webmodules().pipe(_(n=>this.webmodules.set(n)),M(()=>this.isLoaded.set(!0)));if(t)return o;o.subscribe()}static \u0275fac=function(o){return new(o||e)};static \u0275prov=v({token:e,factory:e.\u0275fac,providedIn:"root"})};var Fe=()=>{let e=s(I);return e.token()?!0:e.checkProxyAuthed().pipe(T(t=>t?G(!0):e.refreshToken().pipe(w(()=>!0))))},We=()=>{let e=s(C),t=s(k),o=s(z),n=e.relayIsEnabled()?"longpoll":"websocket",a=[o.get(H).preload(!0),o.get(H).preloadFilterGroups(!0),o.get(N).preload(!0)];return e.configLoaded===null?P(a).pipe(w(()=>n)):e.configLoaded?.pipe(T(()=>P(a)))},$e=()=>!0,Oe={path:"connect/:typeParam",loadComponent:()=>import("./chunk-BCG7F5NN.js")},Ge=()=>{let e=s(h);return!e.getItem("locale")&&navigator.language&&e.setItem("locale",navigator.language),!0},xe=[{path:"",children:[{path:"login",canActivate:[],loadComponent:()=>import("./chunk-H6ABNEPW.js")},{path:"logout",loadComponent:()=>import("./chunk-XGIZ7XYY.js")},{path:"",canActivate:[Fe],children:[{path:"",canActivate:[We,$e,Ge],children:[{path:"welcome",loadComponent:()=>import("./chunk-ZXVCNNR6.js"),children:[{path:"",redirectTo:"select",pathMatch:"full"},{path:"select",loadComponent:()=>import("./chunk-NTFU5IZX.js")},Oe]},{path:"",loadComponent:()=>import("./chunk-3PH22VKZ.js"),children:[{path:"",loadComponent:()=>import("./chunk-6RFGEGIG.js")},Oe,{path:"add-backup",loadComponent:()=>import("./chunk-BHEVUGU3.js")},{path:"backup/:id/export",loadComponent:()=>import("./chunk-B3NBXWUT.js")},{path:"backup/import",loadComponent:()=>import("./chunk-A5VPMVHZ.js")},{path:"backup-draft/:id",loadComponent:()=>import("./chunk-QSKZSJ4L.js"),loadChildren:()=>import("./chunk-OMBODNTL.js")},{path:"backup/:id",loadComponent:()=>import("./chunk-QSKZSJ4L.js"),loadChildren:()=>import("./chunk-OMBODNTL.js")},{path:"backup/:id/log",loadComponent:()=>import("./chunk-PNYNIJ5Y.js")},{path:"backup/:id/database",loadComponent:()=>import("./chunk-XZNJPNEB.js")},{path:"backup/:id/commandline",loadComponent:()=>import("./chunk-TVCMMPDJ.js")},{path:"backup/:id/commandline/:runId",loadComponent:()=>import("./chunk-JZTT7U3Z.js")},{path:"backup/:id/delete",loadComponent:()=>import("./chunk-7PDZTGU4.js")},{path:"restore",children:[{path:"",loadComponent:()=>import("./chunk-P2DL7FAX.js")},{path:"from-config",loadComponent:()=>import("./chunk-FQZFKTPW.js")}]},{path:"restore-from-files",loadComponent:()=>import("./chunk-OUCD5MBM.js"),loadChildren:()=>import("./chunk-7QBYFFIL.js")},{path:"restore-draft/:id",loadComponent:()=>import("./chunk-OUCD5MBM.js"),loadChildren:()=>import("./chunk-7QBYFFIL.js")},{path:"restore/:id",loadComponent:()=>import("./chunk-OUCD5MBM.js"),loadChildren:()=>import("./chunk-7QBYFFIL.js")},{path:"settings",loadComponent:()=>import("./chunk-B3JL4YOW.js")},{path:"about",loadComponent:()=>import("./chunk-FGZZWR4V.js"),children:[{path:"",redirectTo:"general",pathMatch:"full"},{path:"general",loadComponent:()=>import("./chunk-37LMHAEV.js")},{path:"changelog",loadComponent:()=>import("./chunk-T7WSF7RL.js")},{path:"libraries",loadComponent:()=>import("./chunk-B2Y54P3R.js")},{path:"system-info",loadComponent:()=>import("./chunk-SFR3XMV4.js")},{path:"server-settings",loadComponent:()=>import("./chunk-ZETIORHQ.js")},{path:"logs",loadChildren:()=>import("./chunk-MRAKGZE6.js")},{path:"crashlogs",loadComponent:()=>import("./chunk-7XS6T6TX.js")}]}]}]}]}]}];var U=null,Le=(e,t)=>{let o=s(I),n=s(de),a=s(h),p=s(f),i=a.getItem("locale"),u=s(Ce),c=ke(i),r=ye.BASE||"",m=e.url===`${r}/api/v1/auth/login`,S=e.url===`${r}/api/v1/auth/logout`,g=e.url===`${r}/api/v1/auth/refresh`,b=e.url===`${r}/api/v1/progressstate`,E=e.url===`${r}/api/v1/remoteoperation/test`,Ue=e.url===`${r}/api/v1/filesystem/validate`,je=e.url.startsWith(`${r}/api/v2/`),L=o.token(),j=e,F=e.headers.has("custom-proxy-check")||L===we;if(L&&e.url.startsWith(r+p.baseUrl)&&!F){let l=e.headers.set("Authorization",`Bearer ${L}`);i&&i!=="en-US"&&(l=l.set("X-Ui-Language",c)),j=e.clone({headers:l})}return t(j).pipe(w(l=>{if(l.type===4&&l.status===200&&je){let y=l.body;if(y?.Success===!1)throw{status:200,message:y?.Error??"Unknown error",error:{Error:y?.Error??"Unknown error"},requestBody:y}}return l}),J(l=>{let y=l.error?.Error||`Error Code: ${l.status}, Message: ${l.message}`;if(!F){let R=!0;if((b&&l.status===404||E||Ue)&&(R=!1),g&&l.status===401&&(R=!1,o.logout(),n.navigate(["/logout"])),!m&&!g&&!S&&l.status===401)return R=!1,U??=o.refreshToken().pipe(K()),U.pipe(T(()=>t(e.clone({headers:e.headers.set("Authorization",`Bearer ${o.token()}`)}))),M(()=>U=null));R&&u.error(y)}return B(()=>({error:l,message:y}))}))};var O=class e{#e=s(X);showError(t){let o=this.#e.querySelector("body > .loading");if(!o)return;o.classList.add("has-error"),o.innerHTML="";let n=this.#e.createElement("div");n.classList.add("loading-title"),n.textContent="Unable to connect";let a=this.#e.createElement("div");a.classList.add("loading-error"),a.textContent=t||"Unknown error";let p=this.#e.createElement("button");p.type="button",p.classList.add("retry-button"),p.textContent="Retry",p.addEventListener("click",()=>{this.#e.defaultView?.location.reload()}),o.append(n,a,p)}static \u0275fac=function(o){return new(o||e)};static \u0275prov=v({token:e,factory:e.\u0275fac,providedIn:"root"})};var Be="1.0.0",Pe=`portal-proxy-client-${D()}`,Je=1,x=class e{#e=1e3;#a=s(f);#d=s(O);#o=d("disconnected");#u=d(this.#e);#p=d(!1);#n=d(!1);#c=d(null);#s=!1;isConnectedToMachineServer=this.#n.asReadonly();wsState=this.#o.asReadonly();#l=[];#r={};#t=null;#h=new TextDecoder("utf-8");#m=null;#g=Q(()=>{let t=this.#p(),o=this.#u(),n=this.#c();if(!n||!t||!o||o<this.#e){this.#m&&window.clearInterval(this.#m);return}this.#m=window.setInterval(()=>{this.connectToMachineServer(n)},o)});#i(t){this.#s||(this.#s=!0,this.#d.showError(t||"Unable to connect to the server."))}#f(){this.#s||(this.#s=!0)}utf8Atob(t){let o=Uint8Array.from(atob(t),a=>a.charCodeAt(0)),n=this.#h.decode(o);return n?JSON.parse(n):null}connectToMachineServer(t,o){let n=o?.reconnect??!1,a=this.wsState();(a==="disconnected"||a==="error"||n)&&(this.#t?.close(),this.#t=null),!this.#t&&(this.#s=!1,this.#t=new WebSocket(this.#a.machineServerUrl),this.#o.set("connecting"),this.#t.onopen=()=>{this.#o.set("connect"),this.#n.set(!0),this.#p.set(!1),this.#c.set(null)},this.#t.onclose=()=>{this.#o.set("disconnected"),this.#n.set(!1),this.#c.set(t),this.#p.set(!0)},this.#t.onerror=()=>{this.#o.set("error")},this.#t.onmessage=p=>{let i=JSON.parse(p.data);if(this.wsState()==="connect"){if(i.type!=="welcome"){this.disconnectFromMachineServer(`Unexpected message type, expected 'welcome' but got '${i.type}'`);return}let c={token:t,publicKey:"",clientVersion:Be,protocolVersion:Je},r=this.createResponse(i,"authportal",c);this.#o.set("welcome"),this.#t?.send(r)}else if(this.wsState()==="welcome"){if(i.type!=="authportal"){this.disconnectFromMachineServer(`Unexpected message type, expected 'authportal' but got '${i.type}'`);return}var u=JSON.parse(i.payload??"");if(u.accepted===!1){this.#i("Authentication failed"),this.disconnectFromMachineServer("Authentication failed");return}for(this.#o.set("authenticated"),this.#n.set(!0);this.#l.length>0;){let c=this.#l.pop();c&&this.#r[c.messageId]&&this.activateCommand(c)}}else if(this.wsState()==="authenticated"){if(i.type!=="command"){console.warn(`Unexpected message type, expected 'command' but got '${i.type}'`);return}let c=this.#r[i.messageId];if(c){if(i.errorMessage)this.#i(i.errorMessage),c.reject(i.errorMessage);else{let r=JSON.parse(i.payload??"");r.statusCode>=400?this.#i(r.body||`Initial request failed with status code ${r.statusCode}`):this.#f(),r.body=r?.body==null?null:this.utf8Atob(r.body),c.resolve(r)}delete this.#r[i.messageId],window.clearTimeout(c.timer)}}})}disconnectFromMachineServer(t=null){t&&console.error(t),this.#t?.close(),this.#t=null,this.#o.set("disconnected"),this.#n.set(!1)}createResponse(t,o,n){let a={from:Pe,to:t.from,type:o,messageId:t.messageId,payload:JSON.stringify(n)};return JSON.stringify(a)}sendCommand(t,o,n,a,p,i,u=5e3){return(this.wsState()==="disconnected"||this.wsState()==="error")&&this.connectToMachineServer(t),new Promise((c,r)=>{let m=D(),g={from:Pe,to:o,type:"command",messageId:m,payload:JSON.stringify({method:n,path:a,body:p,headers:i})},b={resolve:c,reject:r,timer:window.setTimeout(()=>{let E=this.#r[m];E&&(delete this.#r[m],this.#i("The request timed out before receiving a response."),E.reject("Timeout"))},u)};this.#r[m]=b,this.#n()?this.activateCommand(g):this.#l.push(g)})}activateCommand(t){this.#t?.send(JSON.stringify(t))}static \u0275fac=function(o){return new(o||e)};static \u0275prov=v({token:e,factory:e.\u0275fac,providedIn:"root"})};function Ke(e){if(typeof e!="string")return null;let o=new TextEncoder().encode(e);return window.btoa(String.fromCharCode(...o))}function He(e,t,o){let n=e.relayconfigState.config();if(n===null)return o(t);let a=Ke(t.body),p={};t.headers.keys().forEach(r=>{p[r]=t.headers.get(r)??""});let i=t.headers.get("timeout"),u=i!==null?parseInt(i):e.defaultTimeout;t.url.startsWith("/api/v1/serverstate")&&t.url.includes("longpoll=true")&&(u=1e3*99);let c=e.relayWebsocket.sendCommand(n.accessToken,n.clientId,t.method,t.url,a,p,u);return new W(r=>{c.then(m=>{let S=new se;p!=null&&Object.keys(p).forEach(b=>{S.set(b,p[b])});let g=new ie({body:m.body,status:m.statusCode,statusText:"OK",headers:S});r.next(g),r.complete()}).catch(m=>{r.error(new ae({error:m??"Unknown error",status:0,statusText:m??"Unknown error"}))})})}var De=(e,t)=>{let o={relayconfigState:s(C),defaultTimeout:s(f).defaultTimeout,relayWebsocket:s(x)},n=o.relayconfigState.config();if(o.relayconfigState.configLoaded!==null&&n===null){let a=new $;return o.relayconfigState.configLoaded.subscribe(p=>{p&&He(o,e,t).subscribe(a)}),a}return He(o,e,t)};var Ve={providers:[ee(),he(xe,ge(),fe(ue)),pe(le(),ce([De,Le])),h,{provide:f,useValue:Ne},{provide:te,useValue:Ae()},{provide:ve,useValue:{alertVariant:"simple"}},Te,k,Ee,ne,Re,oe,Me,Ie]};re(A,Ve);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.190",
2
+ "version": "0.0.191",
3
3
  "name": "@duplicati/ngclient",
4
4
  "license": "MIT",
5
5
  "contributors": [
package/main-JTTKXWGP.js DELETED
@@ -1 +0,0 @@
1
- import{b as Ie,c as ke}from"./chunk-VEWX3KXN.js";import{a as we}from"./chunk-GUUVY3EP.js";import{a as Me}from"./chunk-KRXQDBGB.js";import{a as I}from"./chunk-7GOEY6MG.js";import{a as Ee}from"./chunk-FOQJA6X2.js";import{b as Te}from"./chunk-VHOAXFIJ.js";import"./chunk-7RZEW7SE.js";import{a as H}from"./chunk-6Q6SSTBK.js";import{a as Se}from"./chunk-FK7JFD5B.js";import"./chunk-5DJAX2HH.js";import"./chunk-G4VDCGMW.js";import"./chunk-BR5N53HF.js";import{a as P}from"./chunk-TELPJYLN.js";import{a as h,b as ye,c as S,d as Re,e as M}from"./chunk-DAODMGAD.js";import{v as be,x as Ce}from"./chunk-HPNLQHW6.js";import{a as ge,d as ve}from"./chunk-BGTK25UG.js";import{c as le,d as me,g as de,h as ue,i as he,j as fe}from"./chunk-A4LPGPDU.js";import{a as ne}from"./chunk-PKPBSTZA.js";import{a as re,b as se,c as ie,e as ae,f as pe,g as ce}from"./chunk-QPTSKQZ2.js";import{fa as te,ka as oe}from"./chunk-OTPG7USH.js";import"./chunk-TT3S63BX.js";import{Bb as Y,E,I as J,Ic as Z,Jc as ee,K as w,M as K,R as v,U as _,W as s,cb as Q,da as q,ea as z,f as F,g as W,l as $,la as d,m as G,na as X,p as R,y as L,z as B}from"./chunk-T2WO6CVD.js";import"./chunk-7CGTOI24.js";var k=class e{#e=s(h);#a=s(S);ngOnInit(){ye(),this.#a.fetchConfig(),this.#e.clearAllNotCurrentVersion()}static \u0275fac=function(o){return new(o||e)};static \u0275cmp=Q({type:e,selectors:[["app-root"]],decls:1,vars:0,template:function(o,n){o&1&&Y(0,"router-outlet")},dependencies:[le],encapsulation:2})};var Ae={production:!0,baseUrl:"/api",machineServerUrl:"${WS_URL}",defaultTimeout:3e4};var f=new _("ENVIRONMENT");var A=class e{#e=s(ve);isLoaded=d(!1);webmodules=d(null);preload(t=!1){let o=this.#e.getApiV1Webmodules().pipe(K(n=>this.webmodules.set(n)),E(()=>this.isLoaded.set(!0)));if(t)return o;o.subscribe()}static \u0275fac=function(o){return new(o||e)};static \u0275prov=v({token:e,factory:e.\u0275fac,providedIn:"root"})};var Ue=()=>{let e=s(M);return e.token()?!0:e.checkProxyAuthed().pipe(w(t=>t?$(!0):e.refreshToken().pipe(R(()=>!0))))},je=()=>{let e=s(S),t=s(I),o=s(q),n=e.relayIsEnabled()?"longpoll":"websocket",a=[o.get(P).preload(!0),o.get(P).preloadFilterGroups(!0),o.get(A).preload(!0)];return e.configLoaded===null?L(a).pipe(R(()=>n)):e.configLoaded?.pipe(w(()=>L(a)))},Fe=()=>!0,Ne={path:"connect/:typeParam",loadComponent:()=>import("./chunk-BCG7F5NN.js")},We=()=>{let e=s(h);return!e.getItem("locale")&&navigator.language&&e.setItem("locale",navigator.language),!0},Oe=[{path:"",children:[{path:"login",canActivate:[],loadComponent:()=>import("./chunk-H6ABNEPW.js")},{path:"logout",loadComponent:()=>import("./chunk-XGIZ7XYY.js")},{path:"",canActivate:[Ue],children:[{path:"",canActivate:[je,Fe,We],children:[{path:"welcome",loadComponent:()=>import("./chunk-ZXVCNNR6.js"),children:[{path:"",redirectTo:"select",pathMatch:"full"},{path:"select",loadComponent:()=>import("./chunk-NTFU5IZX.js")},Ne]},{path:"",loadComponent:()=>import("./chunk-3PH22VKZ.js"),children:[{path:"",loadComponent:()=>import("./chunk-6RFGEGIG.js")},Ne,{path:"add-backup",loadComponent:()=>import("./chunk-BHEVUGU3.js")},{path:"backup/:id/export",loadComponent:()=>import("./chunk-B3NBXWUT.js")},{path:"backup/import",loadComponent:()=>import("./chunk-A5VPMVHZ.js")},{path:"backup-draft/:id",loadComponent:()=>import("./chunk-QSKZSJ4L.js"),loadChildren:()=>import("./chunk-OMBODNTL.js")},{path:"backup/:id",loadComponent:()=>import("./chunk-QSKZSJ4L.js"),loadChildren:()=>import("./chunk-OMBODNTL.js")},{path:"backup/:id/log",loadComponent:()=>import("./chunk-PNYNIJ5Y.js")},{path:"backup/:id/database",loadComponent:()=>import("./chunk-XZNJPNEB.js")},{path:"backup/:id/commandline",loadComponent:()=>import("./chunk-TVCMMPDJ.js")},{path:"backup/:id/commandline/:runId",loadComponent:()=>import("./chunk-JZTT7U3Z.js")},{path:"backup/:id/delete",loadComponent:()=>import("./chunk-7PDZTGU4.js")},{path:"restore",children:[{path:"",loadComponent:()=>import("./chunk-P2DL7FAX.js")},{path:"from-config",loadComponent:()=>import("./chunk-FQZFKTPW.js")}]},{path:"restore-from-files",loadComponent:()=>import("./chunk-OUCD5MBM.js"),loadChildren:()=>import("./chunk-7QBYFFIL.js")},{path:"restore-draft/:id",loadComponent:()=>import("./chunk-OUCD5MBM.js"),loadChildren:()=>import("./chunk-7QBYFFIL.js")},{path:"restore/:id",loadComponent:()=>import("./chunk-OUCD5MBM.js"),loadChildren:()=>import("./chunk-7QBYFFIL.js")},{path:"settings",loadComponent:()=>import("./chunk-B3JL4YOW.js")},{path:"about",loadComponent:()=>import("./chunk-FGZZWR4V.js"),children:[{path:"",redirectTo:"general",pathMatch:"full"},{path:"general",loadComponent:()=>import("./chunk-37LMHAEV.js")},{path:"changelog",loadComponent:()=>import("./chunk-T7WSF7RL.js")},{path:"libraries",loadComponent:()=>import("./chunk-B2Y54P3R.js")},{path:"system-info",loadComponent:()=>import("./chunk-SFR3XMV4.js")},{path:"server-settings",loadComponent:()=>import("./chunk-ZETIORHQ.js")},{path:"logs",loadChildren:()=>import("./chunk-MRAKGZE6.js")},{path:"crashlogs",loadComponent:()=>import("./chunk-7XS6T6TX.js")}]}]}]}]}]}];var V=null,xe=(e,t)=>{let o=s(M),n=s(me),a=s(h),p=s(f),i=a.getItem("locale"),u=s(Ce),c=Ie(i),r=ge.BASE||"",m=e.url===`${r}/api/v1/auth/login`,y=e.url===`${r}/api/v1/auth/refresh`,b=e.url===`${r}/api/v1/progressstate`,C=e.url===`${r}/api/v1/remoteoperation/test`,T=e.url===`${r}/api/v1/filesystem/validate`,Ve=e.url.startsWith(`${r}/api/v2/`),x=o.token(),U=e,j=e.headers.has("custom-proxy-check")||x===Re;if(x&&e.url.startsWith(r+p.baseUrl)&&!j){let l=e.headers.set("Authorization",`Bearer ${x}`);i&&i!=="en-US"&&(l=l.set("X-Ui-Language",c)),U=e.clone({headers:l})}return t(U).pipe(R(l=>{if(l.type===4&&l.status===200&&Ve){let g=l.body;if(g?.Success===!1)throw{status:200,message:g?.Error??"Unknown error",error:{Error:g?.Error??"Unknown error"},requestBody:g}}return l}),B(l=>{let g=l.error?.Error||`Error Code: ${l.status}, Message: ${l.message}`;return!j&&(b&&l.status===404||C||T||u.error(g),y&&l.status===401&&(o.logout(),n.navigate(["/logout"])),!m&&!y&&l.status===401)?(V??=o.refreshToken().pipe(J()),V.pipe(w(()=>t(e.clone({headers:e.headers.set("Authorization",`Bearer ${o.token()}`)}))),E(()=>V=null))):G(()=>({error:l,message:g}))}))};var N=class e{#e=s(z);showError(t){let o=this.#e.querySelector("body > .loading");if(!o)return;o.classList.add("has-error"),o.innerHTML="";let n=this.#e.createElement("div");n.classList.add("loading-title"),n.textContent="Unable to connect";let a=this.#e.createElement("div");a.classList.add("loading-error"),a.textContent=t||"Unknown error";let p=this.#e.createElement("button");p.type="button",p.classList.add("retry-button"),p.textContent="Retry",p.addEventListener("click",()=>{this.#e.defaultView?.location.reload()}),o.append(n,a,p)}static \u0275fac=function(o){return new(o||e)};static \u0275prov=v({token:e,factory:e.\u0275fac,providedIn:"root"})};var $e="1.0.0",Le=`portal-proxy-client-${H()}`,Ge=1,O=class e{#e=1e3;#a=s(f);#d=s(N);#o=d("disconnected");#u=d(this.#e);#p=d(!1);#n=d(!1);#c=d(null);#s=!1;isConnectedToMachineServer=this.#n.asReadonly();wsState=this.#o.asReadonly();#l=[];#r={};#t=null;#h=new TextDecoder("utf-8");#m=null;#g=X(()=>{let t=this.#p(),o=this.#u(),n=this.#c();if(!n||!t||!o||o<this.#e){this.#m&&window.clearInterval(this.#m);return}this.#m=window.setInterval(()=>{this.connectToMachineServer(n)},o)});#i(t){this.#s||(this.#s=!0,this.#d.showError(t||"Unable to connect to the server."))}#f(){this.#s||(this.#s=!0)}utf8Atob(t){let o=Uint8Array.from(atob(t),a=>a.charCodeAt(0)),n=this.#h.decode(o);return n?JSON.parse(n):null}connectToMachineServer(t,o){let n=o?.reconnect??!1,a=this.wsState();(a==="disconnected"||a==="error"||n)&&(this.#t?.close(),this.#t=null),!this.#t&&(this.#s=!1,this.#t=new WebSocket(this.#a.machineServerUrl),this.#o.set("connecting"),this.#t.onopen=()=>{this.#o.set("connect"),this.#n.set(!0),this.#p.set(!1),this.#c.set(null)},this.#t.onclose=()=>{this.#o.set("disconnected"),this.#n.set(!1),this.#c.set(t),this.#p.set(!0)},this.#t.onerror=()=>{this.#o.set("error")},this.#t.onmessage=p=>{let i=JSON.parse(p.data);if(this.wsState()==="connect"){if(i.type!=="welcome"){this.disconnectFromMachineServer(`Unexpected message type, expected 'welcome' but got '${i.type}'`);return}let c={token:t,publicKey:"",clientVersion:$e,protocolVersion:Ge},r=this.createResponse(i,"authportal",c);this.#o.set("welcome"),this.#t?.send(r)}else if(this.wsState()==="welcome"){if(i.type!=="authportal"){this.disconnectFromMachineServer(`Unexpected message type, expected 'authportal' but got '${i.type}'`);return}var u=JSON.parse(i.payload??"");if(u.accepted===!1){this.#i("Authentication failed"),this.disconnectFromMachineServer("Authentication failed");return}for(this.#o.set("authenticated"),this.#n.set(!0);this.#l.length>0;){let c=this.#l.pop();c&&this.#r[c.messageId]&&this.activateCommand(c)}}else if(this.wsState()==="authenticated"){if(i.type!=="command"){console.warn(`Unexpected message type, expected 'command' but got '${i.type}'`);return}let c=this.#r[i.messageId];if(c){if(i.errorMessage)this.#i(i.errorMessage),c.reject(i.errorMessage);else{let r=JSON.parse(i.payload??"");r.statusCode>=400?this.#i(r.body||`Initial request failed with status code ${r.statusCode}`):this.#f(),r.body=r?.body==null?null:this.utf8Atob(r.body),c.resolve(r)}delete this.#r[i.messageId],window.clearTimeout(c.timer)}}})}disconnectFromMachineServer(t=null){t&&console.error(t),this.#t?.close(),this.#t=null,this.#o.set("disconnected"),this.#n.set(!1)}createResponse(t,o,n){let a={from:Le,to:t.from,type:o,messageId:t.messageId,payload:JSON.stringify(n)};return JSON.stringify(a)}sendCommand(t,o,n,a,p,i,u=5e3){return(this.wsState()==="disconnected"||this.wsState()==="error")&&this.connectToMachineServer(t),new Promise((c,r)=>{let m=H(),b={from:Le,to:o,type:"command",messageId:m,payload:JSON.stringify({method:n,path:a,body:p,headers:i})},C={resolve:c,reject:r,timer:window.setTimeout(()=>{let T=this.#r[m];T&&(delete this.#r[m],this.#i("The request timed out before receiving a response."),T.reject("Timeout"))},u)};this.#r[m]=C,this.#n()?this.activateCommand(b):this.#l.push(b)})}activateCommand(t){this.#t?.send(JSON.stringify(t))}static \u0275fac=function(o){return new(o||e)};static \u0275prov=v({token:e,factory:e.\u0275fac,providedIn:"root"})};function Be(e){if(typeof e!="string")return null;let o=new TextEncoder().encode(e);return window.btoa(String.fromCharCode(...o))}function Pe(e,t,o){let n=e.relayconfigState.config();if(n===null)return o(t);let a=Be(t.body),p={};t.headers.keys().forEach(r=>{p[r]=t.headers.get(r)??""});let i=t.headers.get("timeout"),u=i!==null?parseInt(i):e.defaultTimeout;t.url.startsWith("/api/v1/serverstate")&&t.url.includes("longpoll=true")&&(u=1e3*99);let c=e.relayWebsocket.sendCommand(n.accessToken,n.clientId,t.method,t.url,a,p,u);return new F(r=>{c.then(m=>{let y=new re;p!=null&&Object.keys(p).forEach(C=>{y.set(C,p[C])});let b=new se({body:m.body,status:m.statusCode,statusText:"OK",headers:y});r.next(b),r.complete()}).catch(m=>{r.error(new ie({error:m??"Unknown error",status:0,statusText:m??"Unknown error"}))})})}var He=(e,t)=>{let o={relayconfigState:s(S),defaultTimeout:s(f).defaultTimeout,relayWebsocket:s(O)},n=o.relayconfigState.config();if(o.relayconfigState.configLoaded!==null&&n===null){let a=new W;return o.relayconfigState.configLoaded.subscribe(p=>{p&&Pe(o,e,t).subscribe(a)}),a}return Pe(o,e,t)};var De={providers:[Z(),ue(Oe,fe(),he(de)),ae(ce(),pe([He,xe])),h,{provide:f,useValue:Ae},{provide:ee,useValue:ke()},{provide:be,useValue:{alertVariant:"simple"}},we,I,Te,oe,Se,te,Ee,Me]};ne(k,De);