harperdb
Version:
HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.
1 lines • 77.1 kB
JavaScript
"use strict";(self.webpackChunkharperdb_studio=self.webpackChunkharperdb_studio||[]).push([[302],{4298:(e,t,n)=>{n.r(t),n.d(t,{default:()=>gt});var a=n(9950),s=n(6713),r=n(135),l=n(5269),o=n(7176),i=n(6114),c=n(4084),u=n(8156),d=n(625),p=n(9435),m=n(5488),h=n(3452),f=n(9163),g=n.n(f);var x=n(127);const j=async e=>{let{auth:t,url:n}=e;return(0,x.A)({operation:{operation:"custom_functions_status"},auth:t,url:n,timeout:5e3})},v=async e=>{let{auth:t,url:n}=e;return(0,x.A)({operation:{operation:"get_custom_functions"},auth:t,url:n})};function b(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(e&&e.entries){var s,r,l;if(t===n)e.path=n,e.key=null!==(s=null===(r=(l=crypto).randomUUID)||void 0===r?void 0:r.call(l))&&void 0!==s?s:Math.random().toString().slice(2);for(const s of e.entries){var o,i,c;const e=`${t}/${s.name}`,[,r]=e.split("/");s.project=r,s.path=e,s.key=null!==(o=null===(i=(c=crypto).randomUUID)||void 0===i?void 0:i.call(c))&&void 0!==o?o:Math.random().toString().slice(2),s.readOnly=a||!!s.package,b(s,e,n,s.readOnly)}}}const y=async e=>{let{auth:t,url:n}=e;const a=await(0,x.A)({operation:{operation:"get_components"},auth:t,url:n});return b(a,a.name,a.name,!1),a},N=async e=>{let{auth:t,url:n}=e;const{is_enabled:a,port:s,directory:r,error:o,message:i}=await j({auth:t,url:n}),c=await y({auth:t,url:n}),u={is_enabled:a,port:s,endpoints:a?await v({auth:t,url:n}):{},directory:r,error:o,message:i,fileTree:c};return l.A.update((e=>{e.custom_functions=u})),{custom_functions:u}};var A=n(4414);const k=function(){const e=(0,s.O$)(l.A,(e=>e.auth)),t=(0,s.O$)(l.A,(e=>e.url)),n=(0,s.O$)(l.A,(e=>e.is_local)),r=(0,s.O$)(l.A,(e=>{var t;return null===(t=e.custom_functions)||void 0===t?void 0:t.port})),[d,p]=(0,a.useState)({}),[f,j]=(0,a.useState)({port:r||9926});return g()((async()=>{const{submitted:n}=d;if(n){const{port:n}=f;if(n)if(a=n,Number.isNaN(parseFloat(a))||!Number.isFinite(parseFloat(a)))p({error:"port must be a valid number"});else{const a=await(async e=>{let{auth:t,url:n,port:a}=e;return(0,x.A)({operation:{operation:"configure_cluster",CUSTOM_FUNCTIONS_PORT:parseInt(a,10)},auth:t,url:n})})({auth:e,url:t,port:n});a.error?p({error:a.message}):N({auth:e,url:t})}else p({error:"All fields are required"})}var a}),[d]),g()((()=>{d.submitted||p({})}),[f]),n&&!r?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("div",{className:"text-nowrap mb-3",children:"Custom Functions Port"}),(0,A.jsx)(m.A,{id:"custom_api_port",onChange:e=>j({...f,port:e.target.value}),className:"mb-3 "+(d.error&&!f.port?"error":""),type:"number",title:"custom api port",placeholder:"9926",value:f.port}),(0,A.jsx)(h.A,{color:"success",block:!0,onClick:()=>p({submitted:!0}),children:"Set Custom API Port"}),!!d.error&&(0,A.jsx)(c.A,{className:"mt-3 error",children:(0,A.jsx)(u.A,{children:d.error})})]}):(0,A.jsxs)(o.A,{children:[(0,A.jsxs)(i.A,{xs:"10",children:["Custom Functions Port ",n?r:"Set"]}),(0,A.jsx)(i.A,{xs:"2",className:"text-end",children:(0,A.jsx)("i",{className:"fa fa-check-circle fa-lg text-success"})})]})};var C=n(4834),w=n(2010),_=n(6177);const S=function(e){let{setConfiguring:t}=e;const{compute_stack_id:n}=(0,d.g)(),r=(0,s.O$)(l.A,(e=>e.auth),[n]),o=(0,s.O$)(l.A,(e=>e.url),[n]),i=(0,s.O$)(l.A,(e=>{var t;return parseFloat(null===(t=e.registration)||void 0===t?void 0:t.version)>=4?"nats":"socketcluster"}),[n]),[c,u]=(0,a.useState)({});return g()((async()=>{if(c.submitted){if("nats"===i)await(0,C.A)({auth:r,url:o,customFunctions_enabled:!0});else{const e=await(0,_.A)({auth:r,url:o});await(0,C.A)({auth:r,url:o,operation:"configure_cluster",CUSTOM_FUNCTIONS:!0,CLUSTERING:Boolean(null===e||void 0===e?void 0:e.config_cluster_user),CLUSTERING_PORT:null===e||void 0===e?void 0:e.config_cluster_port,CLUSTERING_USER:null===e||void 0===e?void 0:e.config_cluster_user,NODE_NAME:null===e||void 0===e?void 0:e.nodeName})}window._kmq&&window._kmq.push(["record","enabled custom functions"]),(0,w.A)({auth:r,url:o}),setTimeout((()=>t(!0)),0)}}),[c.submitted]),(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("hr",{className:"my-3"}),(0,A.jsx)(h.A,{color:"success",disabled:c.submitted,block:!0,onClick:()=>u({submitted:!0}),children:c.submitted?(0,A.jsx)("i",{className:"fa fa-spinner fa-spin text-white"}):"Enable Custom Functions"})]})};var F=n(6165),O=n(3150),P=n(3628);const $=function(e){let{setConfiguring:t}=e;const{compute_stack_id:n}=(0,d.g)(),a=(0,s.O$)(l.A,(e=>{var t;return null===(t=e.custom_functions)||void 0===t?void 0:t.port}),[n]);return(0,A.jsxs)(o.A,{id:"functions",children:[(0,A.jsxs)(i.A,{xl:"3",lg:"4",md:"5",xs:"12",children:[(0,A.jsx)("span",{className:"floating-card-header",children:"enable custom functions"}),(0,A.jsx)(c.A,{className:"my-3",children:(0,A.jsx)(u.A,{children:(0,A.jsxs)(p.tH,{onError:(e,t)=>(0,P.A)({error:{message:e.message,componentStack:t}}),FallbackComponent:O.A,children:[(0,A.jsx)(k,{}),!!a&&(0,A.jsx)(S,{setConfiguring:t})]})})})]}),(0,A.jsx)(i.A,{xl:"9",lg:"8",md:"7",xs:"12",children:a?(0,A.jsx)(F.A,{headline:"Enable Custom Functions",description:"Click the button at left to enable Custom Functions. NOTE: We'll restart the instance when you click this button.",icon:(0,A.jsx)("i",{className:"fa fa-thumbs-up text-success"})}):(0,A.jsx)(F.A,{headline:"Set Your Custom Functions Server Port",description:"If your instance is behind a firewall, you'll need to ensure this port is accessible by other instances if you want to access the API.",icon:(0,A.jsx)("i",{className:"fa fa-thumbs-up text-success"})})})]})};var E=n(7348),D=n(5553);const I=async e=>{let{auth:t,url:n,project:a,file:s}=e;return(0,x.A)({operation:{operation:"get_component_file",project:a,file:s},auth:t,url:n})},T=async e=>{let{auth:t,url:n,project:a,file:s,payload:r}=e;return(0,x.A)({operation:{operation:"set_component_file",project:a,file:s,payload:r},auth:t,url:n})},R=async e=>{let{auth:t,url:n,project:a,file:s}=e;return(0,x.A)({operation:{operation:"drop_component",project:a,file:s},auth:t,url:n})},z=async e=>{let{auth:t,url:n,project:a,packageUrl:s,payload:r}=e;return r?(0,x.A)({auth:t,url:n,operation:{operation:"deploy_component",project:a,payload:r}}):(0,x.A)({auth:t,url:n,operation:{operation:"deploy_component",project:a,package:s}})};var U=n(1534),L=n(4319);const W=(0,n(6997).A)("editorCache");var M=n(8738),q=n.n(M);function H(){return(0,A.jsx)(c.A,{className:"file-browser-scroll-container",children:(0,A.jsx)(u.A,{children:(0,A.jsxs)("div",{className:"p-4",children:["You have no Harper applications yet. ",(0,A.jsx)("br",{}),(0,A.jsx)("br",{}),'Click "',(0,A.jsx)("i",{className:"fas fa-plus"}),' app" above to create one!',(0,A.jsx)("br",{}),(0,A.jsx)("br",{}),"See the"," ",(0,A.jsx)("a",{className:"docs-link",href:"https://docs.harperdb.io",target:"_blank",rel:"noreferrer",children:"documentation"})," ","for more info on Harper Applications."]})})})}function G(e,t){const n=+Boolean(e.entries),a=+Boolean(t.entries);return n===a?e.name.localeCompare(t.name):a-n}function B(){return(0,A.jsx)("i",{className:q()("package-icon fas fa-cube")})}function V(e){let{name:t,url:n,onPackageSelect:s,selectedPackage:r}=e;const[l,o]=(0,a.useState)(Boolean(r)&&t===(null===r||void 0===r?void 0:r.name));return(0,a.useEffect)((()=>{o(r&&r.name===t)}),[r,t]),(0,A.jsxs)("button",{type:"button",onClick:e=>{s(l?null:{name:t,url:n,event:e}),o(!l)},className:q()("package",{"package-selected":l}),onKeyDown:()=>{},children:[(0,A.jsx)(B,{}),(0,A.jsx)("span",{className:"package-text",children:t})]})}function K(e){let{directoryEntry:t,selectedFile:n,selectedFolder:a,onFileSelect:s,onFolderSelect:r,Icon:l}=e;const o=Boolean(t.entries);const i=t.path===n,c=t.path===(null===a||void 0===a?void 0:a.path);return(0,A.jsxs)("button",{type:"button",onClick:function(e){const n=e.target.classList.contains("rename-file")||e.target.classList.contains("deploy-project");o?c&&n||r(c?null:t):s(i?null:t)},className:q()("file",{"file-selected":i,"folder-selected":c}),onKeyDown:function(){},children:[(0,A.jsx)(l,{className:"filename-icon"}),(0,A.jsx)("span",{className:"filename-text",children:t.name})]})}function Z(e){let{directoryEntry:t,userOnSelect:n,onFolderSelect:s,onDeployProject:r,onFileSelect:l,onPackageSelect:o,onFileRename:i,selectedFile:c,selectedFolder:u,selectedPackage:d}=e;const[p,m]=(0,a.useState)(!0),h=[...t.entries||[]].sort(G),f=(g=t.name)&&[...g].includes(".")?g.split(".").slice(-1)[0]:null;var g;let x;return x=2===t.path.split("/").length?()=>function(e){let{toggleClosed:t,isOpen:n}=e;return(0,A.jsx)("i",{onClick:t,onKeyDown:t,className:q()("project-icon fas fa-file-code"),tabIndex:0,"aria-expanded":n,"aria-controls":"folder","aria-label":n?"close project":"open project",role:"button"})}({isOpen:p,toggleClosed:()=>m(!p)}):t.entries?()=>function(e){let{toggleClosed:t,isOpen:n}=e;return(0,A.jsx)("i",{onClick:t,onKeyDown:t,className:q()("folder-icon fas "+(n?"fa-folder-open":"fa-folder")),tabIndex:0,"aria-expanded":n,"aria-controls":"folder","aria-label":n?"close folder":"open folder",role:"button"})}({isOpen:p,toggleClosed:()=>m(!p)}):()=>function(e){let{extension:t}=e;switch(t){case"js":return(0,A.jsx)("i",{className:q()("file-icon filetype-js fab fa-js")});case"yaml":return(0,A.jsx)("i",{className:q()("file-icon filetype-yaml fas fa-cog")});default:return(0,A.jsx)("i",{className:q()("file-icon filetype-unknown far fa-file-alt")})}}({extension:f}),(0,A.jsxs)(A.Fragment,{children:["components"!==t.name?(0,A.jsx)("li",{className:q()(`${t.entries?"folder-container":"file-container"} ${p?"folder-open":"folder-closed"}`),children:t.package?(0,A.jsx)(V,{selectedPackage:d,onPackageSelect:o,name:t.name,url:t.package}):(0,A.jsx)(K,{Icon:x,selectedFile:c,selectedFolder:u,selectedPackage:d,directoryEntry:t,onDeployProject:r,onFileRename:()=>{i(t)},onFileSelect:l,onFolderSelect:s,userOnSelect:n})},t.key):null,h.map((e=>(0,A.jsx)("li",{children:(0,A.jsx)("ul",{className:q()("folder",{"folder-contents-open":!0,"folder-contents-closed":!1}),children:(0,A.jsx)(Z,{selectedFile:c,selectedFolder:u,selectedPackage:d,directoryEntry:e,onFileSelect:l,onDeployProject:r,onFileRename:i,onFolderSelect:s,onPackageSelect:o,userOnSelect:n})})},e.key)))]})}const Y=function(e){var t;let{files:n,userOnSelect:a,onFileSelect:s,onPackageSelect:r,onDeployProject:l,onFileRename:o,onFolderSelect:i,selectedFile:d,selectedFolder:p,selectedPackage:m}=e;return null!==n&&void 0!==n&&null!==(t=n.entries)&&void 0!==t&&t.length?(0,A.jsx)(c.A,{className:"file-browser-scroll-container",children:(0,A.jsx)(u.A,{children:(0,A.jsx)("ul",{className:"file-browser",children:(0,A.jsx)(Z,{selectedFile:d,selectedFolder:p,selectedPackage:m,onFileSelect:s,onFileRename:o,onFolderSelect:i,onDeployProject:l,onPackageSelect:r,userOnSelect:a,directoryEntry:n})})})}):(0,A.jsx)(H,{})};var J=n(5023);J.wG.init().then((e=>{e.editor.defineTheme("hdb",{base:"vs-dark",inherit:!0,rules:[],colors:{"editor.background":"#111111"}})}));const Q={js:"javascript",yaml:"yaml",ts:"typescript",json:"json",md:"markdown",html:"html",css:"css",graphql:"graphql",mjs:"javascript"};const X=function(e){let{active:t,file:n,onFileChange:s}=e;const[r,l]=(0,a.useState)("javascript");return(0,a.useEffect)((()=>{const e=function(e){var t;const n=null===(t=e||"")||void 0===t?void 0:t.split(".");return n.length>1?n.slice(-1)[0]:""}(null===n||void 0===n?void 0:n.name);l(Q[e]||"plaintext")}),[n]),t?(0,A.jsx)(J.Ay,{height:"100%",language:r,value:(null===n||void 0===n?void 0:n.content)||"",theme:"hdb",onChange:s,options:{readOnly:null===n||void 0===n?void 0:n.readOnly,automaticLayout:!0,minimap:{enabled:!1}}}):null};function ee(e){let{onClick:t,disabled:n=!1,text:a="",extraClasses:s=""}=e;return(0,A.jsxs)("button",{type:"button",disabled:n,onClick:t,className:s,title:"Create a new app",children:[(0,A.jsx)("i",{className:"fas fa-plus"}),a&&(0,A.jsxs)("span",{className:"ms-1",children:[" ",a]})]})}function te(e){let{onClick:t,disabled:n=!1,text:a="",extraClasses:s=""}=e;return(0,A.jsxs)("button",{type:"button",disabled:n,onClick:t,className:s,title:"Add a folder",children:[(0,A.jsx)("i",{className:"fas fa-plus"}),a&&(0,A.jsx)("span",{className:"ms-1 d-none d-lg-inline-block",children:a})]})}function ne(e){let{onClick:t,disabled:n=!1,text:a="",extraClasses:s=""}=e;return(0,A.jsxs)("button",{type:"button",onClick:t,disabled:n,className:s,title:"Delete selected app or folder",children:[(0,A.jsx)("i",{className:"fas fa-minus"}),a&&(0,A.jsx)("span",{className:"ms-1 d-none d-lg-inline-block",children:a})]})}function ae(e){let{onClick:t,disabled:n,text:a="",extraClasses:s=""}=e;return(0,A.jsxs)("button",{type:"button",disabled:n,onClick:t,className:s,title:"Add a new file",children:[(0,A.jsx)("i",{className:"fas fa-plus"}),a&&(0,A.jsxs)("span",{className:"ms-1 d-none d-lg-inline-block",children:[" ",a]})]})}function se(e){let{onClick:t,disabled:n,text:a="",extraClasses:s=""}=e;return(0,A.jsxs)("button",{type:"button",onClick:t,disabled:n,className:s,title:"Delete selected file",children:[(0,A.jsx)("i",{className:"fas fa-minus"}),a&&(0,A.jsxs)("span",{className:"ms-1 d-none d-lg-inline-block",children:[" ",a]})]})}const re=function(e){let{children:t}=e;return(0,A.jsx)("ul",{className:"file-menu text-nowrap",children:t.map((e=>{var t,n,a;return e&&(0,A.jsx)("li",{className:"file-menu-item",children:e},null!==(t=null===(n=(a=crypto).randomUUID)||void 0===n?void 0:n.call(a))&&void 0!==t?t:Math.random().toString().slice(2))}))})};function le(e){let{onClick:t,disabled:n=!1,text:a="",extraClasses:s=""}=e;return(0,A.jsxs)("button",{type:"button",disabled:n,onClick:t,className:s,title:"Import external component or application",children:[(0,A.jsx)("i",{className:"fas fa-share-alt"}),a&&(0,A.jsx)("span",{className:"ms-2 d-none d-lg-inline-block",children:a})]})}function oe(e){let{onClick:t,savingFile:n,disabled:a=!1,text:s="",extraClasses:r=""}=e;return(0,A.jsxs)("button",{type:"button",onClick:t,disabled:a,className:r,title:"save file to instance",children:[(0,A.jsx)("i",{className:q()("fas",{"fa-save":!n,"fa-spinner":n,"fa-spin":n})}),s&&(0,A.jsx)("span",{className:"ms-2 d-none d-lg-inline-block",children:s})]})}function ie(e){let{onClick:t,restarting:n,disabled:a=!1,text:s="",extraClasses:r=""}=e;return(0,A.jsxs)("button",{type:"button",onClick:t,disabled:a,className:r,title:"Click to restart your instance",children:[(0,A.jsx)("i",{className:q()("fas",{"fa-sync":!n,"fa-spinner":n,"fa-spin":n})}),s&&(0,A.jsx)("span",{className:"ms-2 d-none d-lg-inline-block",children:s})]})}function ce(e){let{onClick:t,restartAfterSave:n,disabled:a=!1,text:s="",extraClasses:r=""}=e;return(0,A.jsxs)("button",{type:"button",onClick:t,disabled:a,className:r,title:"Toggle whether saving a file restarts the application",children:[(0,A.jsx)("i",{className:q()("fa",{"fa-toggle-on":n,"fa-toggle-off":!n})}),s&&(0,A.jsx)("span",{className:"ms-2 d-none d-lg-inline-block",children:s})]})}function ue(e){let{onClick:t,disabled:n=!1,text:a="",extraClasses:s="",loading:r}=e;return(0,A.jsxs)("button",{type:"button",disabled:n,onClick:t,className:s,title:"revert file",children:[(0,A.jsx)("i",{className:q()("revert-file fas",{disabled:n,"fa-history":!r,"fa-spinner":r,"fa-spin":r})}),a&&(0,A.jsx)("span",{className:"ms-2 d-none d-lg-inline-block",children:a})]})}function de(e){let{children:t}=e;return(0,A.jsx)("ul",{className:"editor-menu",children:t.map((e=>{var t,n,a;return e&&(0,A.jsx)("li",{className:"editor-menu-item",children:e},null!==(t=null===(n=(a=crypto).randomUUID)||void 0===n?void 0:n.call(a))&&void 0!==t?t:Math.random().toString().slice(2))}))})}function pe(e){let{active:t,AddProjectButtonClick:n,InstallPackageButtonClick:a}=e;return t?(0,A.jsxs)("div",{className:"content-window",children:[(0,A.jsx)("h4",{className:"mb-5",children:"Add A New Application"}),(0,A.jsx)(ee,{text:"Create A New Application Using The Default Template",extraClasses:"btn btn-block btn-success",onClick:n}),(0,A.jsx)(le,{text:"Import Or Deploy A Remote Application Package",extraClasses:"btn btn-block btn-outline-success mt-2",onClick:a})]}):null}function me(e){let{active:t,type:n}=e;return t?(0,A.jsxs)("div",{className:"content-window text-nowrap",children:[(0,A.jsx)("i",{className:"fa fa-exclamation-triangle mt-5 pt-5"}),"\xa0",(0,A.jsxs)("span",{children:["You have selected a ",n,". Nothing to see here!"]})]}):null}var he=n(6359);function fe(e){return/^[a-zA-Z0-9-_]+$/.test(e)}function ge(e){if(!e)return null;const t={type:null,user:null,repo:null,url:null,package:null,tag:null};if(e.url.match("://"))t.url=e.url,t.type="url";else if(e.url.match("semver:")){const[n,a,s]=e.url.split(/[/#]/);t.type="github",t.user=n,t.repo=a,t.tag=s.replace("semver:","")}else{t.type="npm";const n=e.url.split("/");if(1===n.length){const[e,a]=n[0].split("@");t.package=e,t.tag=a}else if(2===n.length){const[,e]=n,[a,s]=e.split("@");t.package=a,t.tag=s}}return t}function xe(e,t,n){var s=this,r=(0,a.useRef)(null),l=(0,a.useRef)(0),o=(0,a.useRef)(null),i=(0,a.useRef)([]),c=(0,a.useRef)(),u=(0,a.useRef)(),d=(0,a.useRef)(e),p=(0,a.useRef)(!0);d.current=e;var m="undefined"!=typeof window,h=!t&&0!==t&&m;if("function"!=typeof e)throw new TypeError("Expected a function");t=+t||0;var f=!!(n=n||{}).leading,g=!("trailing"in n)||!!n.trailing,x="maxWait"in n,j="debounceOnServer"in n&&!!n.debounceOnServer,v=x?Math.max(+n.maxWait||0,t):null;(0,a.useEffect)((function(){return p.current=!0,function(){p.current=!1}}),[]);var b=(0,a.useMemo)((function(){var e=function(e){var t=i.current,n=c.current;return i.current=c.current=null,l.current=e,u.current=d.current.apply(n,t)},n=function(e,t){h&&cancelAnimationFrame(o.current),o.current=h?requestAnimationFrame(e):setTimeout(e,t)},a=function(e){if(!p.current)return!1;var n=e-r.current;return!r.current||n>=t||n<0||x&&e-l.current>=v},b=function(t){return o.current=null,g&&i.current?e(t):(i.current=c.current=null,u.current)},y=function e(){var s=Date.now();if(a(s))return b(s);if(p.current){var o=t-(s-r.current),i=x?Math.min(o,v-(s-l.current)):o;n(e,i)}},N=function(){if(m||j){var d=Date.now(),h=a(d);if(i.current=[].slice.call(arguments),c.current=s,r.current=d,h){if(!o.current&&p.current)return l.current=r.current,n(y,t),f?e(r.current):u.current;if(x)return n(y,t),e(r.current)}return o.current||n(y,t),u.current}};return N.cancel=function(){o.current&&(h?cancelAnimationFrame(o.current):clearTimeout(o.current)),l.current=0,i.current=r.current=c.current=o.current=null},N.isPending=function(){return!!o.current},N.flush=function(){return o.current?b(Date.now()):u.current},N}),[f,x,t,v,g,h,m,j]);return b}function je(e,t){return e===t}function ve(e,t,n){var s=n&&n.equalityFn||je,r=(0,a.useRef)(e),l=(0,a.useState)({})[1],o=xe((0,a.useCallback)((function(e){r.current=e,l({})}),[l]),t,n),i=(0,a.useRef)(e);return s(i.current,e)||(o(e),i.current=e),[r.current,o]}function be(e){let{pkg:t,setPackageSpec:n}=e;const[s,r]=(0,a.useState)((null===t||void 0===t?void 0:t.user)||""),[l]=ve(s,300),[o,i]=(0,a.useState)((null===t||void 0===t?void 0:t.repo)||""),[c]=ve(o,300),[u,d]=(0,a.useState)([]),[p,h]=(0,a.useState)(!1),[f,g]=(0,a.useState)((null===t||void 0===t?void 0:t.tag)||""),[x,j]=(0,a.useState)(""),[,v]=(0,a.useState)(!1),[b,y]=(0,a.useState)(!1);return(0,a.useEffect)((()=>{r((null===t||void 0===t?void 0:t.user)||""),i((null===t||void 0===t?void 0:t.repo)||""),d(null!==t&&void 0!==t&&t.tag?[null===t||void 0===t?void 0:t.tag]:[]),g((null===t||void 0===t?void 0:t.tag)||"")}),[t]),(0,a.useEffect)((()=>{l&&c?(v(!0),async function(e,t){try{const n=await fetch(`https://api.github.com/repos/${e}/${t}`),a=await n.json();return n.status<400?a.name:null}catch(n){return null}}(s,c).then((e=>{e?(j(e),y(!0),async function(e,t){const n=await fetch(`https://api.github.com/repos/${e}/${t}/git/refs/tags`);if(n.status<400)return(await n.json()).map((e=>e.ref.split("/").slice(-1)[0]));return[]}(s,c).then((e=>{v(!1),h(!0),d(e)}))):(v(!1),y(!1),j(""),d([]))})).catch((()=>{v(!1)}))):(y(!1),v(!1),d([]),g(""))}),[l,c,s]),(0,a.useEffect)((()=>{if(s&&o&&x){n(f?`${s}/${o}#semver:${f}`:`${s}/${o}`)}else n("")}),[x,f,s,n,o]),(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(m.A,{title:"Github Organization",className:"mt-2 form-control",valid:l.length>0&&c.length>0&&b,placeholder:"Github Organization",onChange:e=>r(e.target.value),value:s}),(0,A.jsx)(m.A,{title:"Github Repo",className:"mt-2",placeholder:"Github Repo",onChange:e=>i(e.target.value),value:o}),(null===u||void 0===u?void 0:u.length)>0&&(0,A.jsx)(he.Ay,{className:"react-select-container github-tag-select mt-2",classNamePrefix:"react-select",isDisabled:!x,isSearchable:!0,placeholder:"Choose a tag",onChange:e=>g(e.value),options:u.map((e=>({label:e,value:e})))})]})}function ye(e){let{pkg:t,setPackageSpec:n}=e;const[s,r]=(0,a.useState)(""),[l]=ve(s,300),[o,i]=(0,a.useState)(""),[c,u]=(0,a.useState)(""),[d,p]=(0,a.useState)(""),[m,h]=(0,a.useState)(!1),[f,g]=(0,a.useState)(!1);return(0,a.useEffect)((()=>{r((null===t||void 0===t?void 0:t.package)||"")}),[t]),(0,a.useEffect)((function(){if(d){n(c?`${d}@${c}`:d)}else n("")}),[d,c,n]),(0,a.useEffect)((function(){l?(h(!0),async function(e){var t;const n=await fetch(`https://registry.npmjs.org/-/v1/search?text=${e}`),a=(await n.json()).objects.find((t=>t.package.name===e));return null===a||void 0===a||null===(t=a.package)||void 0===t?void 0:t.name}(l).then((e=>{h(!1),g(!!e),p(e),e&&async function(e){const t=await fetch(`https://registry.npmjs.org/${e}`);return(await t.json())["dist-tags"]}(e).then((e=>{i(e),u(null)})).catch((e=>{throw e}))})).catch((()=>{h(!1)}))):(p(null),i(null),u(null))}),[l]),(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)("div",{className:"input-group",children:[(0,A.jsx)("input",{className:"mt-2 form-control",title:"enter an npm package specifier",value:s,placeholder:"Enter the [@scope]/package",onChange:function(e){r(e.target.value)}}),(0,A.jsx)("div",{className:"input-group-append",children:(0,A.jsx)("i",{className:q()("input-group-text fa mt-2",{"fa-spinner fa-spin loading":m,"fa-check found":l.length>0&&f,"fa-times not-found":l.length>0&&!(m||f),"fa-check not-searching":0===l.length})})})]}),(0,A.jsx)(he.Ay,{className:"react-select-container mt-2",classNamePrefix:"react-select",isDisabled:!s,placeholder:"Choose a tag",disabled:!o,onChange:function(e){let{value:t}=e;u(t)},options:Object.entries(o||[]).map((e=>{let[t,n]=e;return{label:`${t} (${n})`,value:t}}))})]})}function Ne(e){return function(e){try{return Boolean(new URL(e))}catch(t){return!1}}(e)&&(-1!==e.indexOf(".tar")||-1!==e.indexOf(".tar.gz")||-1!==e.indexOf(".tgz"))}function Ae(e){let{pkg:t,setPackageSpec:n}=e;const[s,r]=(0,a.useState)((null===t||void 0===t?void 0:t.url)||""),[l,o]=(0,a.useState)(Ne(null===t||void 0===t?void 0:t.url));return(0,a.useEffect)((()=>{n(l?s:"")}),[s,l,n]),(0,A.jsx)(m.A,{type:"text",id:"tarball-url",title:"URL to gzipped tarball",className:q()("package-url-input mt-2",{invalid:!l}),value:s,onChange:e=>{o(0===e.target.value.length||Ne(e.target.value)),r(e.target.value)},placeholder:"URL to gzipped tarball"})}var ke=n(5996);function Ce(e){let{selectedPackage:t,onConfirm:n,onCancel:r,deployTargets:o,active:i}=e;const c=!1,[u,d]=(0,a.useState)(Boolean(t)),[p,f]=(0,a.useState)(ge(t)),[g,x]=(0,a.useState)((null===p||void 0===p?void 0:p.type)||c),[j,v]=(0,a.useState)((null===t||void 0===t?void 0:t.name)||""),[b,y]=(0,a.useState)(!0),[N,k]=(0,a.useState)(""),[C,w]=(0,a.useState)(!1),_=(0,s.O$)(l.A,(e=>e.auth)),S=(0,s.O$)(l.A,(e=>e.url)),[F,O]=(0,a.useState)([{isCurrentInstance:!0,auth:_,instance:{url:S,instance_name:"This Instance"}}]);function P(){v(""),y(!1),x(!1),O([]),r()}return(0,a.useEffect)((function(){const e=ge(t);v((null===t||void 0===t?void 0:t.name)||""),f(ge(t)),x((null===e||void 0===e?void 0:e.type)||c),d(Boolean(t))}),[t,c]),(0,a.useEffect)((function(){y(fe(j))}),[j]),i?(0,A.jsxs)("div",{className:"content-window",children:[(0,A.jsx)("h4",{className:"mb-5",children:"Import Remote App Package"}),(0,A.jsx)(m.A,{valid:b&&j.length>0,title:"enter a name for this package",value:j,placeholder:"Application Name",onChange:e=>{v(e.target.value),y(fe(e.target.value))}}),!ke.A.is_local_studio&&(0,A.jsx)(he.Ay,{className:"react-select-container package-install-deploy-targets-dropdown mt-2",classNamePrefix:"react-select",isSearchable:!0,isMulti:!0,placeholder:"Choose your deploy targets",onChange:e=>{const t=e.map((e=>e.value)),n=o.filter((e=>t.includes(e.instance.url)));O(n)},options:o.map((e=>({label:e.instance.instance_name,value:e.instance.url})))}),(0,A.jsx)(he.Ay,{className:"react-select-container mt-2",classNamePrefix:"react-select",placeholder:"How would you like to fetch this package?",onChange:function(e){let{value:t}=e;x(t)},options:[{label:"A Public GitHub Repo",value:"github"},{label:"Install a gzipped .tar file from a URL",value:"url"}]}),!b&&j.length>0&&(0,A.jsxs)("span",{className:"text-danger text-center mt-3",children:[(0,A.jsx)("i",{className:"fa fa-exclamation-triangle"}),(0,A.jsx)("br",{}),(0,A.jsx)("span",{className:"mt-2",children:"Project name limited to alphanumeric, dashes, & underscores."})]}),b&&F.length>0&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("div",{className:"mt-2"}),"npm"===g&&(0,A.jsx)(ye,{projectName:j,installed:u,pkg:p,setPackageSpec:k}),"github"===g&&(0,A.jsx)(be,{projectName:j,installed:u,pkg:p,setPackageSpec:k}),"url"===g&&(0,A.jsx)(Ae,{projectName:j,installed:u,pkg:p,setPackageSpec:k})]}),b&&F.length>0&&g?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(h.A,{onClick:async()=>{w(!0);try{await n(j,N,F)}catch(e){w(!1)}w(!1)},className:q()("btn btn-block btn-success mt-3",{loading:C}),disabled:!fe(j)||!N||!F.length,children:C?(0,A.jsx)("i",{className:"install-package-status-icon fa fa-spinner fa-spin"}):"Install Package"}),(0,A.jsx)(h.A,{onClick:P,className:"btn btn-block btn-outline-success mt-2",children:"Cancel"})]}):(0,A.jsx)(h.A,{onClick:P,className:"btn btn-block btn-outline-success mt-3",children:"Cancel"})]}):null}function we(e){let{className:t,onClick:n,disabled:s,children:r}=e;const[l,o]=(0,a.useState)(!1);return(0,A.jsx)("button",{disabled:s,type:"button",onClick:async()=>{o(!0);try{await n(),o(!1)}catch(e){o(!1)}},className:q()(`${t} button-with-loader`,{loading:l}),children:l?(0,A.jsx)("i",{className:"button-with-loader-icon fas fa-spinner fa-spin"}):r})}function _e(e){let{onCancel:t,onConfirm:n,onEnter:s,value:r,type:l,validate:o=()=>!0}=e;const[i,c]=(0,a.useState)(r||""),[u,d]=(0,a.useState)(!1);return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("input",{className:q()("w-100 text-center",{invalid:i.length>0&&!u}),onChange:e=>{c(e.target.value),d(o(e.target.value))},onKeyDown:function(e){"Enter"===e.key?s(e.target.value):"Esc"===e.key&&t()},value:i,placeholder:`name for your new ${l}`,title:`name for your new ${l}`}),(0,A.jsx)("i",{title:"error: name must contain only alphanumeric characters, dashes and underscores.",className:q()("text-danger fa fa-warning",{hidden:u||0===i.length})}),(0,A.jsx)(we,{disabled:!u,className:"btn btn-success btn-block mt-3",onClick:()=>n(i),children:"OK"}),(0,A.jsx)("button",{type:"button",className:"btn btn-outline-success btn-block mt-2",onClick:t,children:"Cancel"}),i.length>0&&!u&&(0,A.jsx)("div",{className:"validation-message mt-5",children:"error: name must contain only alphanumeric characters, dashes and underscores."})]})}function Se(e){let{active:t,onConfirm:n,onCancel:a}=e;return t?(0,A.jsxs)("div",{className:"content-window",children:[(0,A.jsx)("h4",{className:"mb-5",children:"Default Template Application"}),(0,A.jsx)(_e,{type:"project",validate:fe,onEnter:n,onConfirm:n,onCancel:a})]}):null}function Fe(e){let{active:t,onConfirm:n,onCancel:a,selectedFolder:s}=e;return t?(0,A.jsxs)("div",{className:"content-window",children:[(0,A.jsxs)("h4",{className:"mb-5",children:["Add Folder To ",(0,A.jsx)("span",{className:"text-success",children:s.path.replace("components","")})]}),(0,A.jsx)(_e,{type:"folder",selectedFolder:s,onEnter:n,onConfirm:n,onCancel:a})]}):null}function Oe(e){let{active:t,onConfirm:n,onCancel:a}=e;return t?(0,A.jsxs)("div",{className:"content-window",children:[(0,A.jsx)("h4",{className:"mb-5",children:"Add A New File"}),(0,A.jsx)(_e,{type:"file",onEnter:n,onConfirm:n,onCancel:a})]}):null}function Pe(e){let{active:t,selectedFile:n,onConfirm:a,onCancel:s}=e;if(!t)return null;const{path:r}=n,l=r.split("/"),o=l.pop(),i=l.slice(1);return(0,A.jsxs)("div",{className:"content-window",children:[(0,A.jsxs)("h4",{className:"mb-5",children:["Delete ",(0,A.jsx)("span",{className:"text-danger",children:o})," File"]}),(0,A.jsx)(we,{className:"btn btn-danger btn-block delete-button mt-2",onClick:a,children:"Delete"}),(0,A.jsx)("button",{type:"button",className:"btn btn-outline-danger btn-block mt-2",onClick:s,children:"Cancel"}),(0,A.jsxs)("div",{className:"mt-5",children:["Are you sure you want to delete ",(0,A.jsx)("span",{className:"text-danger",children:o})," from"," ",(0,A.jsx)("span",{className:"text-danger",children:i.join("/")}),"?"]})]})}function $e(e){let{active:t,selectedFolder:n,onConfirm:a,onCancel:s}=e;if(!t)return null;if(!n)return null;const r=n.path.split("/"),l=2===r.length,o=l?null:r.slice(-1)[0];return(0,A.jsxs)("div",{className:"content-window",children:[(0,A.jsxs)("h4",{className:"mb-5",children:["Delete ",(0,A.jsx)("span",{className:"text-danger",children:l?null===n||void 0===n?void 0:n.project:o})," ",l?"Project":"Folder"]}),(0,A.jsx)(we,{className:"btn btn-danger btn-block delete-button mt-2",onClick:a,children:"Delete"}),(0,A.jsx)("button",{type:"button",className:"btn btn-outline-danger btn-block mt-2",onClick:s,children:"Cancel"}),(0,A.jsx)("div",{className:"mt-5",children:l?(0,A.jsxs)("div",{children:["Are you sure you want to delete project ",(0,A.jsx)("span",{className:"text-danger",children:null===n||void 0===n?void 0:n.project})," ?"]}):(0,A.jsxs)("div",{children:["Are you sure you want to delete the folder ",(0,A.jsx)("span",{className:"text-danger",children:o})," from"," ",(0,A.jsx)("span",{className:"text-danger",children:null===n||void 0===n?void 0:n.project}),"?"]})})]})}function Ee(e){let{active:t,selectedPackage:n,onConfirm:a,onCancel:s}=e;if(!t)return null;const r=n.name;return(0,A.jsxs)("div",{className:"content-window",children:[(0,A.jsxs)("h4",{className:"mb-5",children:["Delete ",(0,A.jsx)("span",{className:"text-danger",children:r})," Package"]}),(0,A.jsx)(we,{className:"btn btn-danger btn-block delete-button mt-2",onClick:a,children:"Delete"}),(0,A.jsx)("button",{type:"button",className:"btn btn-outline-danger btn-block mt-2",onClick:s,children:"Cancel"}),(0,A.jsxs)("div",{className:"mt-5",children:["Are you sure you want to delete ",(0,A.jsx)("span",{className:"text-danger",children:r}),"?"]})]})}const De="DEFAULT_WINDOW",Ie="DEFAULT_FOLDER_WINDOW",Te="CODE_EDITOR_WINDOW",Re="NAME_FILE_WINDOW",ze="NAME_PROJECT_WINDOW",Ue="NAME_PROJECT_FOLDER_WINDOW",Le="INSTALL_PACKAGE_WINDOW",We="DELETE_FILE_WINDOW",Me="DELETE_FOLDER_WINDOW",qe="DELETE_PACKAGE_WINDOW";function He(e){let{children:t}=e;return(0,A.jsx)(c.A,{className:"editor-window",children:(0,A.jsx)(u.A,{children:t})})}var Ge=n(5502);const Be=function(e){var t,n,s,r;let{deployTargets:l,fileTree:c,onFileSave:u,onAddFile:d,onRevertFile:p,onAddProjectFolder:m,onAddProject:h,onFileChange:f,onDeleteFolder:g,onDeleteFile:x,onDeletePackage:j,onDeployProject:v,onFileSelect:b,onInstallPackage:y,restartInstance:N,restartingInstance:k}=e;const[C,w]=(0,a.useState)(null),[_,S]=(0,a.useState)(null),[F,O]=(0,a.useState)(null),[P,$]=(0,a.useState)(De),[E,D]=(0,a.useState)(null),[I,T]=(0,a.useState)(!0),[R,z]=(0,a.useState)(!1),[U,L]=(0,a.useState)(!1),W=(null===c||void 0===c||null===(t=c.entries)||void 0===t?void 0:t.length)>0,M=Boolean(W&&C),q=Boolean(W&&(C||F)),H=Boolean(C);function G(e,t){$(e),D(t)}function B(){O(null),w(null),S(null)}function V(){G(De,P)}return(0,A.jsxs)(o.A,{id:"webide",children:[(0,A.jsxs)(i.A,{md:"4",xl:"3",className:"file-browser-outer-container mb-3",children:[(0,A.jsx)("div",{className:"floating-card-header-row",children:(0,A.jsxs)(re,{children:[(0,A.jsx)(ee,{onClick:()=>G(De,P),text:"app"}),(H||q)&&(0,A.jsx)("span",{className:"px-1",children:"|"}),H&&(0,A.jsx)(te,{disabled:!H,onClick:()=>G(Ue,P),text:!q&&"folder"}),q&&(0,A.jsx)(ne,{disabled:!q,onClick:()=>{F?G(qe,P):C&&G(Me,P)},text:"folder"}),(M||(null===_||void 0===_?void 0:_.path))&&(0,A.jsx)("span",{className:"px-1",children:"|"}),M&&(0,A.jsx)(ae,{onClick:()=>G(Re,P),disabled:!M,text:!(null!==_&&void 0!==_&&_.path)&&"file"}),(null===_||void 0===_?void 0:_.path)&&(0,A.jsx)(se,{disabled:!(null!==_&&void 0!==_&&_.path),onClick:()=>G(We,P),text:!M&&"file"})]})}),(0,A.jsx)(Y,{files:c,root:c.path,selectedFile:null===_||void 0===_?void 0:_.path,selectedFolder:C,selectedPackage:F,onDeployProject:v,onFolderSelect:e=>{B(),w(e),G(e?Ie:De,P)},onPackageSelect:e=>{B(),O(e),G(e?Ie:De,P)},onFileSelect:async e=>{const t=!e;if(B(),t)S(null),G(De,P);else{const t=await b(e),{content:n,cached:a}=t;S({...e,content:n,cached:a}),G(Te,P)}}})]}),(0,A.jsxs)(i.A,{md:"8",xl:"9",className:"editor-window-container",children:[(0,A.jsxs)(o.A,{className:"floating-card-header-row g-0",children:[(0,A.jsx)(i.A,{className:"text-nowrap",children:_&&(0,A.jsxs)(A.Fragment,{children:[null===_||void 0===_||null===(n=_.path)||void 0===n||null===(s=n.split("/"))||void 0===s||null===(r=s.slice(1))||void 0===r?void 0:r.join(" > ")," ",(0,A.jsxs)("span",{className:"text-grey d-none d-xl-inline-block",children:["| ",(null===_||void 0===_?void 0:_.size)||"..."," bytes |"," ",null!==_&&void 0!==_&&_.mtime?new Date(_.mtime).toLocaleTimeString():"..."]})]})}),(0,A.jsx)(i.A,{className:"text-nowrap",children:(0,A.jsxs)(de,{children:[(0,A.jsx)(oe,{savingFile:U,disabled:!(null!==_&&void 0!==_&&_.cached&&P===Te),onClick:async()=>{L(!0),await u(_,I),L(!1)},text:"save"}),(0,A.jsx)(ue,{loading:R,disabled:!(null!==_&&void 0!==_&&_.cached&&P===Te),onClick:async()=>{z(!0);try{const e=await p(_),t={..._,content:e,cached:!1};S(t)}finally{z(!1)}},text:"revert"}),(0,A.jsx)("span",{className:"px-1",children:"|"}),(0,A.jsx)(ie,{restarting:k,onClick:N,text:"restart"}),(0,A.jsx)(ce,{restartAfterSave:I,onClick:()=>T(!I),text:"auto"})]})})]}),(0,A.jsxs)(He,{children:[(0,A.jsx)(pe,{fileTree:c,active:P===De,AddProjectButtonClick:()=>G(ze,P),InstallPackageButtonClick:()=>{O(null),G(Le,P)}}),(0,A.jsx)(me,{active:P===Ie,type:F?"package":C?"folder":"nothing"}),(0,A.jsx)(Se,{active:P===ze,onConfirm:e=>{!async function(e){await h(e),G(E,P)}(e),(0,Ge.Ak)()},onCancel:V}),(0,A.jsx)(Fe,{projectName:null===C||void 0===C?void 0:C.project,active:P===Ue,selectedFolder:C,onConfirm:async function(e){await m(e,C),G(E,P)},onCancel:V}),(0,A.jsx)(Oe,{active:P===Re,onConfirm:async function(e){const t=await d(e,C);S(t),G(Te,P)},onCancel:V}),(0,A.jsx)(Ce,{active:P===Le,onConfirm:async function(e,t,n){await y(e,t,n),O(null),G(De,P)},onCancel:V,deployTargets:l,selectedPackage:F}),(0,A.jsx)(Ee,{active:P===qe,selectedPackage:F,onConfirm:async()=>{await j(F),G(De,P),B()},onCancel:V}),(0,A.jsx)($e,{active:P===Me,selectedFolder:C,onConfirm:async()=>{await g(C),G(De,P),B()},onCancel:V}),(0,A.jsx)(Pe,{active:P===We,selectedFile:_,onConfirm:async()=>{await x(_),G(De,P),B()},onCancel:V}),(0,A.jsx)(X,{active:P===Te,file:_,onFileChange:async e=>{_&&(!function(e){const t={..._,content:e};S(t)}(e),await f({path:null===_||void 0===_?void 0:_.path,content:e}),S({..._,content:e,cached:!0}))}})]})]})]})},Ve=async e=>{let{auth:t,url:n,function_content:a,project:s,type:r,file:l}=e;return(0,x.A)({operation:{operation:"set_custom_function",function_content:a,project:s,type:r,file:l},auth:t,url:n})},Ke={routes:"'use strict';\n\n/* Dependencies\n- import any packages that are listed in your projects package.json\n- for example:\nimport needle from 'needle'\n*/\n\n/* Helpers\n- import any helper methods from your project's \"helpers\" directory\n- for example:\nimport filter from '../helpers/filter.js';\n*/\n\nmodule.exports = async (server, { hdbCore, logger }) => {\n // POST route\n // with hdbCore.preValidation to process basic auth\n // uses hdbCore.requese to execute the validated request\n server.route({\n url: '/path/to/my/route',\n method: 'POST',\n preValidation: hdbCore.preValidation,\n handler: hdbCore.request,\n })\n\n // GET route\n // with custom validation\n // uses hdbCore.requestWithoutAuthentication\n server.route({\n url: '/path/to/my/route/:id',\n method: 'GET',\n preValidation: async (request, reply) => {\n const token = request.headers.authorization\n const results = hdbCore.requestWithoutAuthentication({\n body: {\n operation: 'search_by_hash',\n schema: 'auth',\n table: 'tokens',\n hash_values: [token],\n get_attributes: ['id']\n }\n })\n if (!results.length) {\n const errorString = result.body.error || 'Sorry, there was an error authenticating your request';\n logger.error(errorString);\n throw new Error(errorString);\n }\n },\n handler: async (request) => {\n const id = parseInt(request.params.id)\n request.body= {\n operation: 'sql',\n sql: `SELECT * FROM dev.dogs WHERE id = ${id}`\n };\n\n /*\n * requestWithoutAuthentication bypasses the standard HarperDB authentication.\n * YOU MUST ADD YOUR OWN preValidation method above, or this method will be available to anyone.\n */\n const result = await hdbCore.requestWithoutAuthentication(request);\n\n return result\n }\n });\n};\n",helpers:"\n/* filters the results, only returning the selected keys */\nexport default (result, keys) => {\n return result.map(r => {\n const f = {}\n keys.forEach(k => f[k] = r[k])\n return f;\n })\n}\n"};var Ze=n(9561);const Ye=function(e){let{items:t,toggleDropItem:n,toggleCreate:r,baseUrl:c,restarting:u,itemType:p,project:f}=e;const g=(0,d.Zp)(),j=(0,E.MW)(),v=(0,s.O$)(l.A,(e=>e.auth)),b=(0,s.O$)(l.A,(e=>e.url)),[y,k]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[_,S]=(0,a.useState)(!1),F=async e=>{e.preventDefault();let n,a=!1;if(y&&!t.includes(y)||(w(!0),a=!0),y&&!(0,Ze.A)(y)&&(w(!0),a=!0,j.error(("projects"===p?"Project":"File")+" names may only contain letters, numbers, hyphens, or underscores.")),a)return!1;if(S(!0),"projects"===p)n=await(async e=>{let{auth:t,url:n,project:a}=e;return(0,x.A)({operation:{operation:"add_custom_function_project",project:a},auth:t,url:n})})({auth:v,url:b,project:y});else{const e=(e=>Ke[e]||null)(p);n=await Ve({auth:v,url:b,project:f,type:p,file:y,function_content:e})}return n.error?(S(!1),r(!1),j.error(n.message)):setTimeout((async()=>(await(0,U.A)({auth:v,url:b,service:"custom_functions"}),await N({auth:v,url:b}),g(`${c}/${y}`))),500)};return(0,a.useEffect)((()=>{n()}),[n]),(0,a.useEffect)((()=>{y&&t.find((e=>e===y))&&g(`${c}/${y}`)}),[t]),(0,A.jsxs)(o.A,{className:"item-row form",children:[(0,A.jsx)(i.A,{className:"input-holder",children:(0,A.jsx)(m.A,{id:"name",invalid:C,onChange:e=>{w(!1),k(e.target.value)},value:y||"",disabled:_,type:"text",name:"name",placeholder:"projects"===p?"ex: api, api-v1, dogs":"routes"===p?"ex: v1, post, public":"ex: filter, auth, queries"})}),(0,A.jsx)(i.A,{className:"item-action",children:_?(0,A.jsx)(h.A,{color:"success",className:"round me-1",children:(0,A.jsx)("i",{className:"fa fa-spinner fa-spin text-white"})}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(h.A,{id:"createItem",color:"success",className:"round me-1",disabled:u,onClick:F,onKeyDown:e=>13!==e.keyCode||F(e),children:(0,A.jsx)("i",{className:"fa fa-check text-white"})}),(0,A.jsx)(h.A,{id:"toggleCreate",color:"black",className:"round",onClick:()=>r(!1),children:(0,A.jsx)("i",{className:"fa fa-times text-white"})})]})})]})},Je=async e=>{let{auth:t,url:n,project:a}=e;return(0,x.A)({operation:{operation:"drop_custom_function_project",project:a},auth:t,url:n})};const Qe=function(e){let{item:t,baseUrl:n,isActive:r,toggleDropItem:c,isDropping:u,itemType:p,restarting:m}=e;const{project:f}=(0,d.g)(),g=(0,d.Zp)(),j=(0,E.MW)(),[v,b]=(0,a.useState)(!1),[y,k]=(0,a.useState)(!1),C=(0,s.O$)(l.A,(e=>e.auth)),w=(0,s.O$)(l.A,(e=>e.url)),_=async()=>{if(!v)return!1;let e;return e="projects"===p?await Je({auth:C,url:w,project:t}):await(async e=>{let{auth:t,url:n,project:a,type:s,file:r}=e;return(0,x.A)({operation:{operation:"drop_custom_function",project:a,type:s,file:r},auth:t,url:n})})({auth:C,url:w,project:f,type:p,file:t}),e.error?(b(!1),k(!1),j.error(e.message)):(j.success(e.message),(0,U.A)({auth:C,url:w,service:"custom_functions"}),await N({auth:C,url:w}),g(n))};return(0,A.jsxs)(o.A,{title:`View${r?"ing":""} ${t}`,className:"item-row "+(r?"active":""),onClick:m?null:()=>!(r||u||v)&&g(`${n}/${t}`),tabIndex:"0",children:[(0,A.jsx)(i.A,{className:"item-label "+(v?"text-danger text-nowrap":""),children:v?`drop ${t}?`:"projects"===p?`/${t}`:t}),(0,A.jsx)(i.A,{className:"item-action",children:y?(0,A.jsx)(h.A,{tabIndex:"-1",disabled:!0,color:"purple",className:"round",children:(0,A.jsx)("i",{className:"fa fa-spinner fa-spin"})}):v?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(h.A,{id:"confirmDropItem",color:"danger",className:"round me-1",title:`confirm drop ${t}`,onClick:()=>{b(!1),k(!0),_()},children:(0,A.jsx)("i",{className:"fa fa-check text-white"})}),(0,A.jsx)(h.A,{id:"cancelDropItem",color:"black",className:"round",title:`Cancel drop ${t}`,onClick:()=>{b(!1)},children:(0,A.jsx)("i",{className:"fa fa-times text-white"})})]}):u?(0,A.jsx)(h.A,{id:"dropItem",color:"danger",className:"round",title:`Drop ${t}`,onClick:()=>{b(t),c(!1)},children:(0,A.jsx)("i",{className:"fa fa-minus text-white"})}):r?(0,A.jsx)(h.A,{tabIndex:"-1",color:"purple",className:"round",children:(0,A.jsx)("i",{className:"fa fa-chevron-right"})}):null})]},t)};const Xe=function(e){let{items:t,toggleDropItem:n,isDropping:a,toggleCreate:s,project:r,isCreating:l,restarting:c,itemType:u,showForm:d}=e;return(0,A.jsxs)(o.A,{className:"floating-card-header",children:[(0,A.jsx)(i.A,{children:"projects"===u?"projects":`/${r}/${u}`}),d&&null!==t&&void 0!==t&&t.length?(0,A.jsxs)(i.A,{className:"text-end",children:[(0,A.jsx)(h.A,{disabled:c,id:"toggleRemove",color:"link",title:"Remove Functions",className:"add-remove me-3",onClick:()=>{n(!a),s(!1)},children:(0,A.jsx)("i",{className:"fa fa-minus"})}),(0,A.jsx)(h.A,{disabled:c,id:"toggleCreate",color:"link",title:"Add Function",className:"add-remove me-1",onClick:()=>{s(!l),n(!1)},children:(0,A.jsx)("i",{className:"fa fa-plus"})})]}):null]})};const et=function(e){let{items:t,activeItem:n,baseUrl:s,restarting:r,itemType:l,project:o,showForm:i}=e;const[d,p]=(0,a.useState)(!1),[m,h]=(0,a.useState)(!1);return(0,a.useEffect)((()=>{h(),p()}),[n,t.length]),(0,A.jsxs)("div",{className:"entity-manager",children:[(0,A.jsx)(Xe,{items:t,itemType:l,isDropping:d,toggleDropItem:p,isCreating:m,toggleCreate:h,restarting:r,project:o,showForm:i}),(0,A.jsxs)(c.A,{className:"my-3",children:[t&&t.length?(0,A.jsx)(u.A,{className:"scrollable "+(m?"creating":""),children:t.map((e=>(0,A.jsx)(Qe,{item:e,baseUrl:s,isActive:n===e,isDropping:d,toggleDropItem:p,itemType:l,restarting:r},e)))}):null,i&&t&&!t.length||m?(0,A.jsx)(u.A,{children:(0,A.jsx)(Ye,{items:t,itemType:l,baseUrl:s,isDropping:d,toggleDropItem:p,isCreating:m,toggleCreate:h,restarting:r,project:o})}):!t||t.length||m?null:(0,A.jsx)(u.A,{children:(0,A.jsx)("div",{className:"py-3 text-center no-content",children:"no functions found"})})]})]})};const tt=function(){const e=(0,d.Zp)(),t=(0,E.MW)(),{customer_id:n,compute_stack_id:r,project:p,type:m,file:f}=(0,d.g)(),g=(0,s.O$)(l.A,(e=>e.auth)),j=(0,s.O$)(l.A,(e=>e.url)),[v,b]=(0,a.useState)(""),[y,N]=(0,a.useState)(""),k=(0,a.useCallback)((async()=>{if(p&&m&&f&&"undefined"!==f){const e=await(async e=>{let{auth:t,url:n,project:a,type:s,file:r}=e;return(0,x.A)({operation:{operation:"get_custom_function",project:a,type:s,file:r},auth:t,url:n})})({auth:g,url:j,project:p,type:m,file:f});b(null===e||void 0===e?void 0:e.message),N(null===e||void 0===e?void 0:e.message)}else b("")}),[g,j,p,m,f,b]);return(0,a.useEffect)((()=>{k()}),[p,f,k,r]),(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(o.A,{className:"floating-card-header",children:[(0,A.jsxs)(i.A,{children:["edit >\xa0",(0,A.jsxs)("i",{children:["/",p,f&&"undefined"!==f&&`/${m}/${f}.js`]})]}),(0,A.jsxs)(i.A,{className:"text-end",children:[(0,A.jsxs)(h.A,{onClick:k,color:"link",className:"me-2",children:[(0,A.jsx)("span",{className:"me-2",children:"reload"}),(0,A.jsx)("i",{title:"Reload File",className:"fa fa-sync-alt"})]}),(0,A.jsx)("span",{className:"mx-3 text",children:"|"}),(0,A.jsxs)(h.A,{onClick:()=>e(`/o/${n}/i/${r}/functions/deploy/${p}`),color:"link",className:"me-2",children:[(0,A.jsx)("span",{className:"me-2",children:"deploy"}),(0,A.jsx)("i",{title:"Deploy Project",className:"fa fa-share"})]})]})]}),(0,A.jsx)(c.A,{className:"my-3",children:v?(0,A.jsxs)(u.A,{children:[(0,A.jsx)("div",{className:"code-editor-holder",children:(0,A.jsx)(J.Ay,{height:"100%",defaultLanguage:"javascript",value:v,theme:"vs-dark",onChange:b})}),(0,A.jsxs)(o.A,{children:[(0,A.jsx)(i.A,{md:"6",className:"mt-2",children:(0,A.jsx)(h.A,{block:!0,color:"grey",title:"Revert Code to Last Saved State",disabled:v===y,onClick:k,id:"reset",children:(0,A.jsx)("i",{className:"fa fa-undo"})})}),(0,A.jsx)(i.A,{md:"6",className:"mt-2",children:(0,A.jsx)(h.A,{block:!0,title:"Save Code to Instance",color:"success",id:"addEditItem",onClick:async()=>{const e=await Ve({auth:g,url:j,function_content:v,project:p,type:m,file:f});e.error?t.error(e.message):(setTimeout((()=>(0,U.A)({auth:g,url:j,service:"custom_functions"})),500),t.success(e.message)),k()},children:(0,A.jsx)("i",{className:"fa fa-save"})})})]})]}):(0,A.jsx)(u.A,{children:(0,A.jsxs)("div",{className:"empty-prompt narrow",children:[(0,A.jsx)("div",{className:"mt-3 text-bold",children:"This project does not yet have any routes or helpers"}),(0,A.jsx)("div",{className:"mt-3",children:"Add some using the form fields at left."})]})})})]})};var nt=n(4343);const at=e=>{let{initializing:t,loading:n,handleClick:a}=e;return[{Header:"instance name",accessor:"instance_name"},{Header:"instance url",accessor:"url"},{Header:"cf capable",id:"hdb-narrow-cfcapable",Cell:e=>{let{row:{original:{custom_functions_status:t}}}=e;return t.error?"no":"yes"}},{Header:"cf enabled",id:"hdb-narrow-cfenabled",Cell:e=>{let{row:{original:{custom_functions_status:t}}}=e;return t.is_enabled?"yes":"no"}},{Header:"has project",id:"hdb-narrow-cfhasproject",Cell:e=>{let{row:{original:{has_current_project:t}}}=e;return t?"yes":"no"}},{Header:"deploy",id:"hdb-narrow-deploy",Cell:e=>{let{row:{original:{compute_stack_id:s,custom_functions_status:r,has_auth:l}}}=e;return r.is_enabled&&l?(0,A.jsx)(h.A,{color:"success",block:!0,size:"sm",disabled:t||n[s],onClick:()=>a(s,"deploy"),children:(0,A.jsx)("i",{className:"fa "+("deploy"===n[s]?"fa-spinner fa-spin":"fa-share")})}):null}},{Header:"remove",id:"hdb-narrow-remove",Cell:e=>{let{row:{original:{compute_stack_id:t,custom_functions_status:s,has_current_project:r,has_auth:l}}}=e;return s.is_enabled&&r&&l?(0,A.jsx)(h.A,{color:"danger",block:!0,size:"sm",disabled:n[t],onClick:()=>a(t,"drop"),children:(0,A.jsx)("i",{className:"fa "+("drop"===n[t]?"fa-spinner fa-spin":"fa-trash")})}):null}}]},st={filtered:[],sorted:[],page:0,totalPages:1,pageSize:20,autoRefresh:!1,showFilter:!1,lastUpdate:!1};const rt=function(){const{customer_id:e,compute_stack_id:t,project:n}=(0,d.g)(),r=(0,d.Zp)(),[p]=(0,L.A)({}),m=(0,s.O$)(l.A,(e=>e.auth)),f=(0,s.O$)(l.A,(e=>e.url)),b=(0,s.O$)(l.A,(e=>{var t;return null===(t=e.registration)||void 0===t?void 0:t.version})),[{payload:y,file:N},k]=(0,a.useState)([]),C=`/o/${e}/i/${t}/functions/edit/${n}`,w=(0,s.O$)(D.A,(e=>e.instances.filter((e=>e.compute_stack_id!==t)))),[_,S]=b.split("."),F=_>=3&&(_>3||S>=3),[O,P]=(0,a.useState)([]),[$,E]=(0,a.useState)(F),[I,T]=(0,a.useReducer)(((e,t)=>({...e,...t})),{}),[R,z]=(0,a.useState)(st),W=(0,a.useCallback)((()=>r(C)),[r,C]),M=(0,a.useCallback)((async(e,t)=>{const a=O.find((t=>t.compute_stack_id===e)),s=p[e];if(a&&s){T({[e]:t});let r=!1;const l=await j({auth:s,url:a.url});if(!l.error){const e=await v({auth:s,url:a.url});r=Object.keys(e).includes(n)}const o=O.map((t=>(t.compute_stack_id===e&&(t.custom_functions_status=l,t.has_current_project=r),t)));P(o),T({[e]:null})}}),[p,n,O]),q=(0,a.useCallback)((async(e,t)=>{const a=O.find((t=>t.compute_stack_id===e)),s=p[e];a&&s&&(T({[e]:t}),"deploy"===t?(await(async e=>{let{auth:t,url:n,project:a,payload:s,file:r}=e;return(0,x.A)({operation:{operation:"deploy_custom_function_project",project:a,payload:s,file:r},auth:t,url:n})})({auth:s,url:a.url,payload:y,project:n,file:N}),$&&await(async e=>{let{auth:t,url:n,projects:a,dry_run:s=!1}=e;return(0,x.A)({operation:{operation:"install_node_modules",projects:a,dry_run:s},auth:t,url:n})})({auth:s,url:a.url,projects:[n]}),await(0,U.A)({auth:s,url:a.url,service:"custom_functions"})):await Je({auth:s,url:a.url,project:n}),setTimeout((()=>{T({[e]:!1}),M(e,t)}),1e3))}),[N,p,y,n,O,M,$]);return g()((async()=>{if(m&&f&&n){k(!1);const e=await(async e=>{let{auth:t,url:n,project:a,skip_node_modules:s}=e;return(0,x.A)({operation:{operation:"package_custom_function_project",project:a,skip_node_modules:s},auth:t,url:n})})({auth:m,url:f,project:n,skip_node_modules:$});k(e)}}),[m,f,n,$]),g()((async()=>{if(w){const e=await Promise.all(w.map((async e=>{const t=p[e.compute_stack_id];let a={};if(t){const s=await j({auth:t,url:e.url});return s.error||(a=await v({auth:t,url:e.url})),{...e,custom_functions_status:s,has_auth:!0,has_current_project:Object.keys(a).includes(n)}}return{...e,custom_functions_status:!1}})));P(e)}}),[w,n]),(0,a.useEffect)((()=>{z({...R,totalPages:Math.ceil((O.length||R.pageSize)/R.pageSize)})}),[z,R.pageSize]),(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(o.A,{className:"floating-card-header",children:[(0,A.jsxs)(i.A,{children:["deploy ",n&&`> ${n}`]}),(0,A.jsxs)(i.A,{className:"text-end",children:[F&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(h.A,{color:"link",title:"Turn on au