diff --git a/dist/main.js b/dist/main.js index 0d9bba03d0..07dc9c14f8 100644 --- a/dist/main.js +++ b/dist/main.js @@ -1136,7 +1136,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho `;var hc="primaryEnvironmentName",tm="environmentsURL",fc="ditto-ui-env",Tr,Ye,Ke,Kn,ae={environmentSelector:null,tbodyEnvironments:null,tableValidationEnvironments:null,crudEnvironmentFields:null,crudEnvironmentJson:null,inputApiUri:null,inputSearchNamespaces:null,selectDittoVersion:null,inputTabPolicies:null,inputTabConnections:null,inputTabOperations:null},pc=[];document.getElementById("environmentsHTML").innerHTML=ac;function ks(t){Object.assign(this,t),Object.defineProperties(this,{bearer:{enumerable:!1,writable:!0},bearerDevOps:{enumerable:!1,writable:!0},usernamePassword:{value:this.defaultUsernamePassword,enumerable:!1,writable:!0},usernamePasswordDevOps:{value:this.defaultUsernamePasswordDevOps,enumerable:!1,writable:!0},dittoPreAuthenticatedUsername:{value:this.defaultDittoPreAuthenticatedUsername,enumerable:!1,writable:!0}})}function V(){return Ye[ae.environmentSelector.value]}function xt(t){pc.push(t)}function gc(t=null){oc(),pc.forEach(e=>e.call(null,t))}async function mc(){ce(ae),Gt(ae.tbodyEnvironments,ae.tableValidationEnvironments),Tr=new URLSearchParams(window.location.search),Ye=await rm(),Kn=$e("settingsEditor","ace/mode/json",!0),ae.tbodyEnvironments.addEventListener("click",im),ae.crudEnvironmentJson.addEventListener("onCreateClick",cc),ae.crudEnvironmentJson.addEventListener("onUpdateClick",uc),ae.crudEnvironmentJson.addEventListener("onDeleteClick",lc),ae.crudEnvironmentJson.addEventListener("onEditToggle",dc),ae.crudEnvironmentFields.addEventListener("onCreateClick",cc),ae.crudEnvironmentFields.addEventListener("onUpdateClick",uc),ae.crudEnvironmentFields.addEventListener("onDeleteClick",lc),ae.crudEnvironmentFields.addEventListener("onEditToggle",dc),ae.environmentSelector.onchange=nm,document.querySelector('a[data-bs-target="#tabEnvJson"]').addEventListener("shown.bs.tab",()=>{Kn.renderer.updateFull()}),rt()}function nm(){Tr.set(hc,ae.environmentSelector.value),window.history.replaceState({},"",`${window.location.pathname}?${Tr}`),gc()}function lc(){ie(Ke,"No environment selected",ae.tableValidationEnvironments),ie(Object.keys(Ye).length>=2,"At least one environment is required",ae.tableValidationEnvironments),delete Ye[Ke],Ke=null,rt()}function cc(t){var e,c;ie(t.target.idValue,"Environment name must not be empty",t.target.validationElement),ie(!Ye[t.target.idValue],"Environment name already used",t.target.validationElement),t.target===ae.crudEnvironmentFields?Ye[t.target.idValue]=new ks({api_uri:(e=ae.inputApiUri.value)!=null?e:"",searchNamespaces:(c=ae.inputSearchNamespaces.value)!=null?c:"",ditto_version:ae.selectDittoVersion.value?ae.selectDittoVersion.value:"3"}):Ye[t.target.idValue]=new ks(JSON.parse(Kn.getValue())),Ke=t.target.idValue,t.target.toggleEdit(),rt()}function im(t){t.target&&t.target.tagName==="TD"&&(Ke&&Ke===t.target.parentNode.id?Ke=null:Ke=t.target.parentNode.id,Is())}function uc(t){Ke!==t.target.idValue&&e(),t.target===ae.crudEnvironmentFields?(Ye[Ke].api_uri=ae.inputApiUri.value,Ye[Ke].searchNamespaces=ae.inputSearchNamespaces.value,Ye[Ke].ditto_version=ae.selectDittoVersion.value,Ye[Ke].disablePolicies=!ae.inputTabPolicies.checked,Ye[Ke].disableConnections=!ae.inputTabConnections.checked,Ye[Ke].disableOperations=!ae.inputTabOperations.checked):Ye[Ke]=JSON.parse(Kn.getValue()),t.target.toggleEdit(),rt();function e(){Ye[t.target.idValue]=Ye[Ke],delete Ye[Ke],Ke=t.target.idValue}}function rt(t=null){Ye&&localStorage.setItem(fc,JSON.stringify(Ye)),e(),Is(),c(),gc(t);function e(){let d=ae.environmentSelector.value;d||(d=Tr.get(hc)),(!d||!Ye[d])&&(d=Object.keys(Ye)[0]),$t(ae.environmentSelector,Object.keys(Ye)),ae.environmentSelector.value=d}function c(){ae.tbodyEnvironments.innerHTML="",Object.keys(Ye).forEach(d=>{De(ae.tbodyEnvironments,d,d===Ke)})}}function Is(){var t;if(Ke){let e=Ye[Ke];ae.crudEnvironmentFields.idValue=Ke,ae.crudEnvironmentJson.idValue=Ke,Kn.setValue(be(e),-1),ae.inputApiUri.value=e.api_uri,ae.inputSearchNamespaces.value=(t=e.searchNamespaces)!=null?t:"",ae.selectDittoVersion.value=e.ditto_version?e.ditto_version:"3",ae.inputTabPolicies.checked=!e.disablePolicies,ae.inputTabConnections.checked=!e.disableConnections,ae.inputTabOperations.checked=!e.disableOperations}else ae.crudEnvironmentFields.idValue=null,ae.crudEnvironmentJson.idValue=null,Kn.setValue(""),ae.inputApiUri.value=null,ae.inputSearchNamespaces.value=null,ae.selectDittoVersion.value=3,ae.inputTabPolicies.checked=!0,ae.inputTabConnections.checked=!0,ae.inputTabOperations.checked=!0}async function rm(){let t,e,c=Tr.get(tm);if(c)try{let u=await fetch(c);if(!u.ok)throw new Error(`URL ${c} can not be loaded`);t=await u.json(),g(t)}catch(u){t=null,qt(u.message,"Error loading environments from URL")}let d=localStorage.getItem(fc);d&&(e=JSON.parse(d));let p;return t?e?p=a(t,e):p=t:e?p=e:p=sc,Object.keys(p).forEach(u=>{p[u]=new ks(p[u])}),p;function g(u){Object.keys(u).forEach(o=>{if(!u[o].hasOwnProperty("api_uri"))throw new SyntaxError("Environments json invalid")})}function a(u,o){let r={};return Object.keys(u).forEach(n=>{r[n]={...o[n],...u[n]}}),{...o,...r}}}function dc(t){ae.inputApiUri.disabled=!t.detail.isEditing,ae.inputSearchNamespaces.disabled=!t.detail.isEditing,ae.selectDittoVersion.disabled=!t.detail.isEditing,ae.inputTabPolicies.disabled=!t.detail.isEditing,ae.inputTabConnections.disabled=!t.detail.isEditing,ae.inputTabOperations.disabled=!t.detail.isEditing,Kn.setReadOnly(!t.detail.isEditing),Kn.renderer.setShowGutter(t.detail.isEditing),t.detail.isEditing||Is()}var om={things:{listConnections:{path:"/api/2/solutions/{{solutionId}}/connections",method:"GET",body:null,unwrapJsonPath:null},retrieveConnection:{path:"/api/2/solutions/{{solutionId}}/connections/{{connectionId}}",method:"GET",body:null,unwrapJsonPath:null},createConnection:{path:"/api/2/solutions/{{solutionId}}/connections",method:"POST",body:null,unwrapJsonPath:null},modifyConnection:{path:"/api/2/solutions/{{solutionId}}/connections/{{connectionId}}",method:"PUT",body:null,unwrapJsonPath:null},deleteConnection:{path:"/api/2/solutions/{{solutionId}}/connections/{{connectionId}}",method:"DELETE",body:null,unwrapJsonPath:null},retrieveStatus:{path:"/api/2/solutions/{{solutionId}}/connections/{{connectionId}}/status",method:"GET",body:null,unwrapJsonPath:null},retrieveConnectionLogs:{path:"/api/2/solutions/{{solutionId}}/connections/{{connectionId}}/logs",method:"GET",body:null,unwrapJsonPath:null},retrieveConnectionMetrics:{path:"/api/2/solutions/{{solutionId}}/connections/{{connectionId}}/metrics",method:"GET",body:null,unwrapJsonPath:null},connectionCommand:{path:"/api/2/solutions/{{solutionId}}/connections/{{connectionId}}/command",method:"POST",body:null,unwrapJsonPath:null}},ditto_3:{listConnections:{path:"/api/2/connections",method:"GET",body:null,unwrapJsonPath:null},retrieveConnection:{path:"/api/2/connections/{{connectionId}}",method:"GET",body:null,unwrapJsonPath:null},createConnection:{path:"/api/2/connections",method:"POST",body:null,unwrapJsonPath:null},modifyConnection:{path:"/api/2/connections/{{connectionId}}",method:"PUT",body:null,unwrapJsonPath:null},deleteConnection:{path:"/api/2/connections/{{connectionId}}",method:"DELETE",body:null,unwrapJsonPath:null},retrieveStatus:{path:"/api/2/connections/{{connectionId}}/status",method:"GET",body:null,unwrapJsonPath:null},retrieveConnectionLogs:{path:"/api/2/connections/{{connectionId}}/logs",method:"GET",body:null,unwrapJsonPath:null},retrieveConnectionMetrics:{path:"/api/2/connections/{{connectionId}}/metrics",method:"GET",body:null,unwrapJsonPath:null},connectionCommand:{path:"/api/2/connections/{{connectionId}}/command",method:"POST",body:null,unwrapJsonPath:null}},ditto_2:{listConnections:{path:"/devops/piggyback/connectivity",method:"POST",body:{targetActorSelection:"/user/connectivityRoot/connectionIdsRetrieval/singleton",headers:{aggregate:!1},piggybackCommand:{type:"connectivity.commands:retrieveAllConnectionIds"}},unwrapJsonPath:"?.?.connectionIds"},retrieveConnection:{path:"/devops/piggyback/connectivity",method:"POST",body:{targetActorSelection:"/system/sharding/connection",headers:{aggregate:!1},piggybackCommand:{type:"connectivity.commands:retrieveConnection",connectionId:"{{connectionId}}"}},unwrapJsonPath:"?.?.connection"},createConnection:{path:"/devops/piggyback/connectivity",method:"POST",body:{targetActorSelection:"/system/sharding/connection",headers:{aggregate:!1},piggybackCommand:{type:"connectivity.commands:createConnection",connection:"{{connectionJson}}"}},unwrapJsonPath:"?.?.connection"},modifyConnection:{path:"/devops/piggyback/connectivity",method:"POST",body:{targetActorSelection:"/system/sharding/connection",headers:{aggregate:!1},piggybackCommand:{type:"connectivity.commands:modifyConnection",connection:"{{connectionJson}}"}},unwrapJsonPath:null},deleteConnection:{path:"/devops/piggyback/connectivity",method:"POST",body:{targetActorSelection:"/system/sharding/connection",headers:{aggregate:!1},piggybackCommand:{type:"connectivity.commands:deleteConnection",connectionId:"{{connectionId}}"}},unwrapJsonPath:null},retrieveStatus:{path:"/devops/piggyback/connectivity",method:"POST",body:{targetActorSelection:"/system/sharding/connection",headers:{aggregate:!1},piggybackCommand:{type:"connectivity.commands:retrieveConnectionStatus",connectionId:"{{connectionId}}"}},unwrapJsonPath:"?.?"},retrieveConnectionLogs:{path:"/devops/piggyback/connectivity",method:"POST",body:{targetActorSelection:"/system/sharding/connection",headers:{aggregate:!1,"is-group-topic":!0},piggybackCommand:{type:"connectivity.commands:retrieveConnectionLogs",connectionId:"{{connectionId}}"}},unwrapJsonPath:"?.?"},retrieveConnectionMetrics:{path:"/devops/piggyback/connectivity",method:"POST",body:{targetActorSelection:"/system/sharding/connection",headers:{aggregate:!1,"is-group-topic":!0},piggybackCommand:{type:"connectivity.commands:retrieveConnectionMetrics",connectionId:"{{connectionId}}"}},unwrapJsonPath:"?.?"},connectionCommand:{path:"/devops/piggyback/connectivity",method:"POST",body:{targetActorSelection:"/system/sharding/connection",headers:{aggregate:!1,"is-group-topic":!0},piggybackCommand:{type:"{{command}}",connectionId:"{{connectionId}}"}},unwrapJsonPath:null}}},fn,pn;function Ms(t){t?V().devopsAuth==="basic"?(fn="Authorization",pn="Basic "+window.btoa(V().usernamePasswordDevOps)):V().devopsAuth==="bearer"?(fn="Authorization",pn="Bearer "+V().bearerDevOps):(fn="Basic",pn=""):V().mainAuth==="basic"?(fn="Authorization",pn="Basic "+window.btoa(V().usernamePassword)):V().mainAuth==="pre"?(fn="x-ditto-pre-authenticated",pn=V().dittoPreAuthenticatedUsername):V().mainAuth==="bearer"?(fn="Authorization",pn="Bearer "+V().bearer):(fn="Basic",pn="")}function sm(t){return t.status===400&&t.error==="jwt:invalid"||t.status===401}function fo(t,e){t.status&&t.message?(qt(t.description+` -(${t.error})`,t.message,t.status),sm(t)&&document.getElementById("authorize").click()):qt(JSON.stringify(t),"Error",e.status)}async function fe(t,e,c=null,d=null,p=!1,g=!1,a=!1){let u,o=t==="PATCH"?"application/merge-patch+json":"application/json";try{u=await fetch(V().api_uri+(g?"":"/api/2")+e,{method:t,headers:{"Content-Type":o,[fn]:pn,...d},...t!=="GET"&&t!=="DELETE"&&c!==void 0&&{body:JSON.stringify(c)}})}catch(r){throw qt(r),r}if(!u.ok){if(a)return p?u:u.json().then(r=>(fo(r,u),r));throw u.json().then(r=>{fo(r,u)}).catch(r=>{qt("No error details from Ditto",u.statusText,u.status)}),new Error("An error occurred: "+u.status)}return u.status!==204&&u.status!==202?p?u:u.json():null}function Rs(t,e){return new vc.EventSourcePolyfill(`${V().api_uri}/api/2/things?ids=${t}${e?"&"+e:""}`,{headers:{[fn]:pn}})}async function bt(t,e,c="",d=null,p=null){ie(gi()!=="things"||V().solutionId,"No solutionId configured in environment");let g=om[gi()][t],a,u;g.body?u=JSON.stringify(g.body).replace("{{connectionId}}",c).replace('"{{connectionJson}}"',JSON.stringify(d)).replace("{{command}}",p):d?u=JSON.stringify(d):u=p;try{a=await fetch(V().api_uri+g.path.replace("{{solutionId}}",V().solutionId).replace("{{connectionId}}",c),{method:g.method,headers:{"Content-Type":t==="connectionCommand"?"text/plain":"application/json",[fn]:pn},...u&&{body:u}})}catch(o){throw qt(o),o}if(!a.ok)throw a.json().then(o=>{fo(o,a)}).catch(o=>{qt("No error details from Ditto",a.statusText,a.status)}),new Error("An error occured: "+a.status);t!=="connectionCommand"&&a.status!==204?(document.body.style.cursor="progress",a.json().then(o=>{if(o&&o["?"]&&o["?"]["?"].status>=400){let r=o["?"]["?"].payload;fo(r,a)}else g.unwrapJsonPath&&g.unwrapJsonPath.split(".").forEach(function(r){r==="?"&&(r=Object.keys(o)[0]),o=o[r]}),e(o)}).catch(o=>{throw qt("Error calling connections API",o),o}).finally(()=>{document.body.style.cursor="default"})):e&&e()}function gi(){return V().api_uri.startsWith("https://things")?"things":V().ditto_version==="2"?"ditto_2":"ditto_3"}function gn(t,e,c,d=null){let p=t,g=e,a=c,u=d,o=!1;return p.addEventListener("click",r),xt(n),{set viewDirty(i){o=i}};function r(){ic(p.dataset.auth==="devOps"),o&&(a.call(null,!1),o=!1)}function n(i){var s;p.toggleAttribute("hidden",(s=V()[u])!=null?s:!1),["pinnedThings","filterList","messageTemplates","recentPolicyIds"].includes(i)||(g.classList.contains("show")?a.call(null,!0):o=!0)}}var bc=`