@js4cytoscape/ndex-client 0.6.0-alpha.1 → 0.6.0-alpha.3

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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import $ from'axios';/* NDEx Client Library - Modern TypeScript implementation */
2
- var I=(r=>(r.NONE="NONE",r.BASIC="BASIC",r.FULL="FULL",r))(I||{}),p=class extends Error{constructor(t,r,s,n){super(t);this.statusCode=r;this.errorCode=s;this.description=n;this.name="NDExError";}},N=class extends p{constructor(t,r){super(t,void 0,"NETWORK_ERROR");this.originalError=r;this.name="NDExNetworkError";}},C=class extends p{constructor(e="Authentication failed",t=401){super(e,t,"AUTH_ERROR"),this.name="NDExAuthError";}},P=class extends p{constructor(e="Resource not found",t=404){super(e,t,"NOT_FOUND"),this.name="NDExNotFoundError";}},x=class extends p{constructor(e,t=400){super(e,t,"VALIDATION_ERROR"),this.name="NDExValidationError";}},S=class extends p{constructor(e="Internal server error",t=500){super(e,t,"SERVER_ERROR"),this.name="NDExServerError";}};var m=class a{constructor(e){this.CXVersion="2.0";this.hasFragments=false;this.metaData=[];e&&Object.assign(this,e),this.ensureRequiredMetadata();}static createEmpty(){let e=new a;return e.nodes=[],e.edges=[],e.metaData=[{name:"nodes",elementCount:0},{name:"edges",elementCount:0}],e}static fromJSON(e){let t=typeof e=="string"?JSON.parse(e):e;return new a(t)}static fromNetworkSummary(e){let t=a.createEmpty();return t.networkAttributes=[{name:e.name},...e.description?[{description:e.description}]:[],...e.version?[{version:e.version}]:[]],e.properties&&Object.entries(e.properties).forEach(([r,s])=>{t.networkAttributes?.push({[r]:s.v});}),t}addNode(e,t){this.nodes||(this.nodes=[]);let r={id:e};return t&&(r.v=t),this.nodes.push(r),this.updateNodeCount(),r}addEdge(e,t,r,s){this.edges||(this.edges=[]);let n={id:e,s:t,t:r};return s&&(n.v=s),this.edges.push(n),this.updateEdgeCount(),n}addNodeAttribute(e,t,r){let s=this.nodes.find(n=>n.id===e);s&&(s.v||(s.v={}),s.v[t]=r);}addEdgeAttribute(e,t,r){let s=this.edges.find(n=>n.id===e);s&&(s.v||(s.v={}),s.v[t]=r);}setNodeCoordinates(e,t,r,s){this.nodes||(this.nodes=[]);let n=this.nodes.find(i=>i.id===e);n||(n={id:e},this.nodes.push(n),this.updateNodeCount()),n.x=t,n.y=r,s!==void 0&&(n.z=s);}getNode(e){return this.nodes?.find(t=>t.id===e)}getEdge(e){return this.edges?.find(t=>t.id===e)}getNodes(){return this.nodes||[]}getEdges(){return this.edges||[]}getNodeCount(){return this.nodes?.length||0}getEdgeCount(){return this.edges?.length||0}getNetworkName(){return this.networkAttributes?.find(e=>"name"in e)?.name}setNetworkName(e){this.networkAttributes||(this.networkAttributes=[]),this.networkAttributes=this.networkAttributes.filter(t=>!("name"in t)),this.networkAttributes.push({name:e});}getNetworkAttribute(e){return this.networkAttributes?.find(t=>e in t)?.[e]}setNetworkAttribute(e,t){this.networkAttributes||(this.networkAttributes=[]),this.networkAttributes=this.networkAttributes.filter(r=>!(e in r)),this.networkAttributes.push({[e]:t});}validate(){let e=[];return this.CXVersion||e.push("CXVersion is required"),this.hasFragments===void 0&&e.push("hasFragments is required"),(!this.metaData||this.metaData.length===0)&&e.push("metaData is required and must not be empty"),this.metaData?.forEach((t,r)=>{t.name||e.push(`metaData[${r}] is missing required 'name' field`);}),this.nodes&&this.nodes.forEach((t,r)=>{(t.id===void 0||t.id===null)&&e.push(`nodes[${r}] is missing required 'id' field`);}),this.edges&&this.edges.forEach((t,r)=>{if((t.id===void 0||t.id===null)&&e.push(`edges[${r}] is missing required 'id' field`),(t.s===void 0||t.s===null)&&e.push(`edges[${r}] is missing required 's' (source) field`),(t.t===void 0||t.t===null)&&e.push(`edges[${r}] is missing required 't' (target) field`),this.nodes&&t.s!==void 0&&t.t!==void 0){let s=this.nodes.some(i=>i.id===t.s),n=this.nodes.some(i=>i.id===t.t);s||e.push(`edges[${r}] references non-existent source node ${t.s}`),n||e.push(`edges[${r}] references non-existent target node ${t.t}`);}}),{isValid:e.length===0,errors:e}}toJSON(){return JSON.stringify(this,null,2)}clone(){return new a(JSON.parse(this.toJSON()))}getStatistics(){return {nodeCount:this.getNodeCount(),edgeCount:this.getEdgeCount(),hasCoordinates:!!(this.nodes&&this.nodes.some(e=>e.x!==void 0||e.y!==void 0||e.z!==void 0)),hasVisualProperties:!!(this.visualProperties&&(this.visualProperties.default||this.visualProperties.edgeMapping||this.visualProperties.nodeMapping))}}ensureRequiredMetadata(){this.metaData||(this.metaData=[]),this.nodes&&!this.metaData.find(e=>e.name==="nodes")&&this.metaData.push({name:"nodes",elementCount:this.nodes.length}),this.edges&&!this.metaData.find(e=>e.name==="edges")&&this.metaData.push({name:"edges",elementCount:this.edges.length});}updateNodeCount(){let e=this.metaData?.find(t=>t.name==="nodes");e&&(e.elementCount=this.nodes?.length||0);}updateEdgeCount(){let e=this.metaData?.find(t=>t.name==="edges");e&&(e.elementCount=this.edges?.length||0);}};var R="0.6.0-alpha.1";var h=class{constructor(e={}){this.config={baseURL:"https://www.ndexbio.org",timeout:3e4,retries:3,retryDelay:1e3,debug:false,...e};let t={"Content-Type":"application/json",...this.config.headers,...this.getAuthHeaders()};typeof window>"u"&&(t["User-Agent"]=`NDEx-JS-Client/${R}`),this.axiosInstance=$.create({baseURL:this.config.baseURL,timeout:this.config.timeout,headers:t}),this.setupInterceptors();}getAuthHeaders(){return this.config.auth?this.config.auth.type==="basic"?{Authorization:`Basic ${btoa(`${this.config.auth.username}:${this.config.auth.password}`)}`}:this.config.auth.type==="oauth"?{Authorization:`Bearer ${this.config.auth.idToken}`}:{}:{}}buildUrl(e,t="v2"){let r=e.startsWith("/")?e.slice(1):e;return `/${t}/${r}`}async get(e,t){let{version:r,...s}=t||{},n=this.buildUrl(e,r);try{let i=await this.axiosInstance.get(n,s);return this.handleResponse(i)}catch(i){this.handleError(i);}}async post(e,t,r){let{version:s,...n}=r||{},i=this.buildUrl(e,s);try{let o=await this.axiosInstance.post(i,t,n);return this.handleResponse(o)}catch(o){this.handleError(o);}}async put(e,t,r){let{version:s,...n}=r||{},i=this.buildUrl(e,s);try{let o=await this.axiosInstance.put(i,t,n);return this.handleResponse(o)}catch(o){this.handleError(o);}}async delete(e,t){let{version:r,...s}=t||{},n=this.buildUrl(e,r);try{let i=await this.axiosInstance.delete(n,s);return this.handleResponse(i)}catch(i){this.handleError(i);}}async uploadFile(e,t,r={}){let{version:s,onProgress:n,filename:i,contentType:o,...d}=r,c=this.buildUrl(e,s),u=new FormData;if(t instanceof File)u.append("file",t,i||t.name);else if(t instanceof Blob)u.append("file",t,i||"file.cx2");else if(typeof t=="string"){let g=new Blob([t],{type:o||"application/json"});u.append("file",g,i||"file.cx2");}else u.append("file",t,i||"file.cx2");try{let g=await this.axiosInstance.post(c,u,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:n?T=>{let A=Math.round(T.loaded*100/(T.total||1));n(A);}:void 0,...d});return this.handleResponse(g)}catch(g){this.handleError(g);}}setupInterceptors(){this.axiosInstance.interceptors.request.use(e=>(this.config.debug&&console.log("NDEx API Request:",{method:e.method?.toUpperCase(),url:e.url,headers:e.headers}),e),e=>(this.config.debug&&console.error("NDEx API Request Error:",e),Promise.reject(e))),this.axiosInstance.interceptors.response.use(e=>(this.config.debug&&console.log("NDEx API Response:",{status:e.status,url:e.config.url,data:e.data}),e),e=>(this.config.debug&&console.error("NDEx API Response Error:",e.response?.data||e.message),Promise.reject(e)));}handleResponse(e){return e.data&&typeof e.data=="object"&&"errorCode"in e.data&&this.throwNDExError(e.data.message||"Unknown error occurred",e.status,e.data.errorCode||"UNKNOWN_ERROR",e.data.description),e.data&&typeof e.data=="object"&&"data"in e.data?e.data.data:e.data}handleError(e){if(e.response){let t=e.response.data?.message||e.message,r=e.response.data?.errorCode||`HTTP_${e.response.status}`,s=e.response.data?.description;this.throwNDExError(t,e.response.status,r,s);}else throw e.request?new N("Network error - no response received",e):new p(e.message||"Unknown error occurred",void 0,"CLIENT_ERROR",e.toString())}throwNDExError(e,t,r,s){switch(t){case 400:throw new x(e,t);case 401:case 403:throw new C(e,t);case 404:throw new P(e,t);case 500:case 502:case 503:case 504:throw new S(e,t);default:throw new p(e,t,r,s)}}updateConfig(e){if(this.config={...this.config,...e},e.baseURL&&(this.axiosInstance.defaults.baseURL=e.baseURL),e.timeout&&(this.axiosInstance.defaults.timeout=e.timeout),e.headers&&Object.assign(this.axiosInstance.defaults.headers,e.headers),"auth"in e){let t=this.getAuthHeaders();delete this.axiosInstance.defaults.headers.common.Authorization,Object.assign(this.axiosInstance.defaults.headers.common,t);}}getConfig(){return {...this.config}}getAuthType(){return this.config.auth?.type}getIdToken(){return this.config.auth?.type==="oauth"?this.config.auth.idToken:void 0}setIdToken(e){this.updateConfig({auth:{type:"oauth",idToken:e}});}};var f=class{constructor(e){this.http=e;}async getRawCX1Network(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`network/${e}${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2",headers:{Accept:"application/json"}})}async getNetworkSummary(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`network/${e}/summary${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2"})}async copyNetwork(e){let t=`network/${e}/copy`;return this.http.post(t,{},{version:"v2"})}async searchNetworks(e,t,r,s){let n={};t!==void 0&&(n.start=t.toString()),r!==void 0&&(n.limit=r.toString());let i={searchString:e};return s!==void 0&&(s.permission!==void 0&&(i.permission=s.permission),s.includeGroups!==void 0&&(i.includeGroups=s.includeGroups),s.accountName!==void 0&&(i.accountName=s.accountName)),this.http.post("search/network",i,{version:"v2",params:n})}async createNetworkFromRawCX1(e,t={}){let n=(await this.http.post("network",e,{version:"v2",params:t})).split("/");return n[n.length-1]}async updateNetworkFromRawCX1(e,t){let r=`network/${e}`;return this.http.put(r,t,{version:"v2"})}async deleteNetwork(e){let t=`network/${e}`;return this.http.delete(t,{version:"v2"})}async getNetworkSummariesByUUIDs(e,t){let r=t?{accesskey:t}:void 0;return this.http.post("batch/network/summary",e,{version:"v2",params:r})}async getUserNetworks(e,t={}){let r=new URLSearchParams;t.start!==void 0&&r.append("start",t.start.toString()),t.size!==void 0&&r.append("size",t.size.toString());let s=`user/${e}/networks${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2"})}async setNetworkSystemProperties(e,t){let r=`networks/${e}/systemproperty`;return this.http.put(r,t,{version:"v2"})}async getNetworkPermissions(e){let t=`networks/${e}/permission`;return this.http.get(t,{version:"v2"})}async setNetworkPermissions(e,t){let r=`networks/${e}/permission`;return this.http.put(r,t,{version:"v2"})}async grantNetworkPermission(e,t,r){let s=`networks/${e}/permission`,n={memberUUID:t,permission:r};return this.http.post(s,n,{version:"v2"})}async revokeNetworkPermission(e,t){let r=`networks/${e}/permission`;return this.http.delete(r,{version:"v2",data:{memberUUID:t}})}async getNetworkProfile(e){let t=`networks/${e}/profile`;return this.http.get(t,{version:"v2"})}async setNetworkProfile(e,t){let r=`networks/${e}/profile`;return this.http.put(r,t,{version:"v2"})}async makeNetworkPublic(e){let t=`networks/${e}/systemproperty`,r={visibility:"PUBLIC"};return this.http.put(t,r,{version:"v2"})}async makeNetworkPrivate(e){let t=`networks/${e}/systemproperty`,r={visibility:"PRIVATE"};return this.http.put(t,r,{version:"v2"})}async getNetworkSample(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`networks/${e}/sample${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2"})}async getMetaData(e,t){let r=new URLSearchParams;t!==void 0&&r.append("accesskey",t);let s=`network/${e}/aspect${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2"})}async getAccessKey(e){let t=`networks/${e}/accesskey`;return this.http.get(t,{version:"v2"})}async updateAccessKey(e,t){let r=`networks/${e}/accesskey`;return this.http.put(r,{action:t},{version:"v2"})}};var y=class{constructor(e){this.http=e;}async getNetworkSummary(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`networks/${e}/summary${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v3"})}async getRawCX2Network(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`networks/${e}${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v3"})}async createNetworkDOI(e,t,r){let s=new URLSearchParams;s.append("key",t),s.append("email",r);let n=`networks/${e}/DOI?${s.toString()}`;return this.http.get(n,{version:"v3"})}async getAttributesOfSelectedNodes(e,t,r={}){let s=new URLSearchParams;r.accesskey&&s.append("accesskey",r.accesskey);let n={ids:t.ids,attributeNames:t.attributeNames},i=`search/networks/${e}/nodes${s.toString()?`?${s.toString()}`:""}`;return this.http.post(i,n,{version:"v3"})}async getNetworkSummariesV3ByUUIDs(e,t,r){let s={format:r===void 0?"FULL":r};return t!=null&&(s.accesskey=t),this.http.post("batch/networks/summary",e,{version:"v3",params:s})}async searchNetworks(e={}){let t=new URLSearchParams;e.searchString&&t.append("searchString",e.searchString),e.accountName&&t.append("accountName",e.accountName),e.permission&&t.append("permission",e.permission),e.includeGroups!==void 0&&t.append("includeGroups",e.includeGroups.toString()),e.admin&&t.append("admin",e.admin),e.start!==void 0&&t.append("start",e.start.toString()),e.size!==void 0&&t.append("size",e.size.toString()),e.source&&t.append("source",e.source);let r=`search/network${t.toString()?`?${t.toString()}`:""}`;return this.http.get(r,{version:"v3"})}async getNetworkAsCX2Object(e,t={}){let r=await this.getRawCX2Network(e,t);return new m(r)}async createNetworkFromCX2(e,t={}){let r="networks/cx2",s=e instanceof m?JSON.parse(e.toJSON()):e;return this.http.post(r,s,{version:"v3",params:t})}async updateNetworkCX2(e,t){let r=`networks/${e}/cx2`,s=t instanceof m?JSON.parse(t.toJSON()):t;return this.http.put(r,s,{version:"v3"})}async uploadNetworkFile(e,t={}){return this.http.uploadFile("networks/upload",e,{version:"v3",...t})}async getNetworkMetadata(e){let t=`networks/${e}/metadata`;return this.http.get(t,{version:"v3"})}async updateNetworkMetadata(e,t){let r=`networks/${e}/metadata`;return this.http.put(r,t,{version:"v3"})}async getNetworkAspect(e,t,r={}){let s=new URLSearchParams;r.accesskey&&s.append("accesskey",r.accesskey);let n=`networks/${e}/aspects/${t}${s.toString()?`?${s.toString()}`:""}`;return this.http.get(n,{version:"v3"})}};var l=class{constructor(e){this.http=e;this.v2Service=new f(e),this.v3Service=new y(e);}async getNetworkSummary(e,t={}){return this.v3Service.getNetworkSummary(e,t)}async getRawCX1Network(e,t={}){return this.v2Service.getRawCX1Network(e,t)}async getRawCX2Network(e,t={}){return this.v3Service.getRawCX2Network(e,t)}async deleteNetwork(e){return this.v2Service.deleteNetwork(e)}async createNetworkDOI(e,t,r){return this.v3Service.createNetworkDOI(e,t,r)}async getAttributesOfSelectedNodes(e,t,r={}){return this.v3Service.getAttributesOfSelectedNodes(e,t,r)}async neighborhoodQuery(e,t,r,s,n=false){let i={};r!==void 0&&r===true&&(i.save="true");let o={searchString:t,searchDepth:1};if(s!==void 0&&(s.searchDepth!==void 0&&(o.searchDepth=s.searchDepth),s.edgeLimit!==void 0&&(o.edgeLimit=s.edgeLimit),s.errorWhenLimitIsOver!==void 0&&(o.errorWhenLimitIsOver=s.errorWhenLimitIsOver),s.directOnly!==void 0&&(o.directOnly=s.directOnly),s.nodeIds!=null&&(o.nodeIds=s.nodeIds)),n){let c=`search/network/${e}/query`;return this.http.post(c,o,{version:"v3",params:i})}let d=`search/network/${e}/query`;return this.http.post(d,o,{version:"v2",params:i})}async interConnectQuery(e,t,r,s,n=false){let i={};r!==void 0&&r===true&&(i.save="true");let o={searchString:t};if(s!==void 0&&(s.edgeLimit!==void 0&&(o.edgeLimit=s.edgeLimit),s.errorWhenLimitIsOver!==void 0&&(o.errorWhenLimitIsOver=s.errorWhenLimitIsOver),s.nodeIds!=null&&(o.nodeIds=s.nodeIds)),n){let c=`search/networks/${e}/interconnectquery`;return this.http.post(c,o,{version:"v3",params:i})}let d=`search/network/${e}/interconnectquery`;return this.http.post(d,o,{version:"v2",params:i})}async getNetworkPermissionsByUUIDs(e){return this.http.post("batch/network/permission",e,{version:"v2"})}async exportNetworks(e){return this.http.post("batch/network/export",e,{version:"v2"})}async moveNetworks(e,t){if(!Array.isArray(e))throw new Error("Invalid networkIds - must be an array");let r="batch/networks/move",s={targetFolder:t,networks:e};return this.http.post(r,s,{version:"v3"})}async setNetworksVisibility(e,t){this.validateShareData(e);let r="batch/networks/visibility",s={items:e,visibility:t};return this.http.post(r,s,{version:"v3"})}async getRandomEdges(e,t,r){if(t<=0)throw new Error("Value of parameter limit has to be greater than 0.");let s={size:t.toString(),method:"random"};r!==void 0&&(s.accesskey=r);let n=`networks/${e}/aspects/edges`;return this.http.get(n,{version:"v3",params:s})}validateShareData(e){if(typeof e!="object"||e===null||e.files===void 0)throw new Error('Data must be an object with a "files" property');if(typeof e.files!="object"||e.files===null)throw new Error('The "files" property must be an object');let t=["NETWORK","FOLDER","SHORTCUT"];for(let[r,s]of Object.entries(e.files)){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(r))throw new Error(`Invalid UUID format: ${r}`);if(!t.includes(s))throw new Error(`Invalid file type for ${r}: ${s}. Must be one of: ${t.join(", ")}`)}}async getAspectElements(e,t,r,s){let n={};r!==void 0&&(n.size=r.toString()),s!==void 0&&(n.accesskey=s);let i=`networks/${e}/aspects/${t}`;return this.http.get(i,{version:"v3",params:n})}async getFilteredEdges(e,t,r,s,n,i,o,d){let c={};n!==void 0&&(c.size=n.toString()),i!==void 0&&(c.order=i),d!==void 0&&(c.accesskey=d),o!==void 0&&(c.format=o);let u={name:t,value:r,operator:s},g=`search/networks/${e}/edges`;return this.http.post(g,u,{version:"v3",params:c})}async getCX2MetaData(e,t){let r={};t!==void 0&&(r.accesskey=t);let s=`networks/${e}/aspects`;return this.http.get(s,{version:"v3",params:r})}async createNetworkFromRawCX2(e,t=false){let r={visibility:t?"PUBLIC":"PRIVATE"},i=(await this.http.post("networks",e,{version:"v3",params:r})).split("/").pop();if(!i)throw new Error("Failed to extract network UUID from response");return {uuid:i}}async updateNetworkFromRawCX2(e,t){let r=`networks/${e}`;return this.http.put(r,t,{version:"v3"})}get v2(){return this.v2Service}get v3(){return this.v3Service}};var v=class{constructor(e){this.http=e;}copyFile(e,t,r,s){let n={};return s!==void 0&&(n.accesskey=s),this.http.post("files/copy",{from_uuid:e,type:r,to_path:t},{params:n,version:"v3"})}getCount(){return this.http.get("files/count",{version:"v3"})}getTrash(){return this.http.get("files/trash",{version:"v3"})}emptyTrash(){return this.http.delete("files/trash",{version:"v3"})}permanentlyDeleteFile(e){return this.http.delete(`files/trash/${e}`,{version:"v3"})}restoreFile(e,t,r){return this.http.post("files/trash/restore",{networks:e,folders:t,shortcuts:r},{version:"v3"})}_validateShareData(e){if(typeof e!="object"||e===null||e.files===void 0)throw new Error('Data must be an object with a "files" property');if(typeof e.files!="object"||e.files===null)throw new Error('The "files" property must be an object');let t=["NETWORK","FOLDER","SHORTCUT"];for(let[r,s]of Object.entries(e.files)){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(r))throw new Error(`Invalid UUID format: ${r}`);if(!t.includes(s))throw new Error(`Invalid file type for ${r}: ${s}. Must be one of: ${t.join(", ")}`)}}_validateMemberData(e){if(typeof e!="object"||e===null||e.members===void 0)throw new Error('Data must be an object with a "members" property');let t=["READ","WRITE"];for(let[r,s]of Object.entries(e.members)){if(!t.includes(s))throw new Error(`Invalid permission for ${r}: ${s}. Must be one of: ${t.join(", ")}`);if(typeof r!="string"||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(r))throw new Error(`Invalid UUID format: ${r}`)}}updateMember(e,t){return this._validateShareData({files:e}),this._validateMemberData({members:t}),this.http.post("files/sharing/members",{files:e,members:t},{version:"v3"})}listMembers(e){return this.http.get("files/sharing/members/list",{params:e,version:"v3"})}transferOwnership(e,t){return this._validateShareData({files:e}),this.http.post("files/sharing/transfer_ownership",{files:e,new_owner:t},{version:"v3"})}listShares(e){let t={};return e!==void 0&&(t.limit=e),this.http.post("files/sharing/list",t,{version:"v3"})}share(e){return this._validateShareData({files:e}),this.http.post("files/sharing/share",{files:e},{version:"v3"})}unshare(e){return this._validateShareData({files:e}),this.http.post("files/sharing/unshare",{files:e},{version:"v3"})}getFolders(e){let t={};return e!==void 0&&(t.limit=e),this.http.get("files/folders",{params:t,version:"v3"})}createFolder(e,t){return this.http.post("files/folders",{name:e,parent:t},{version:"v3"})}getFolder(e,t){let r={};return t!==void 0&&(r.accesskey=t),this.http.get(`files/folders/${e}`,{params:r,version:"v3"})}updateFolder(e,t,r){return this.http.put(`files/folders/${e}`,{name:t,parent:r},{version:"v3"})}deleteFolder(e){return this.http.delete(`files/folders/${e}`,{version:"v3"})}getFolderCount(e,t){let r={};return t!==void 0&&(r.accesskey=t),this.http.get(`files/folders/${e}/count`,{params:r,version:"v3"})}getFolderList(e,t,r,s){let n={};return t!==void 0&&(n.accesskey=t),r!==void 0&&(n.format=r),s!==void 0&&(n.type=s),this.http.get(`files/folders/${e}/list`,{params:n,version:"v3"})}getShortcuts(e){let t={};return e!==void 0&&(t.limit=e),this.http.get("files/shortcuts",{params:t,version:"v3"})}createShortcut(e,t,r,s){return this.http.post("files/shortcuts",{name:e,parent:t,target:r,targetType:s},{version:"v3"})}getShortcut(e,t){let r={};return t!==void 0&&(r.accesskey=t),this.http.get(`files/shortcuts/${e}`,{params:r,version:"v3"})}updateShortcut(e,t,r,s,n){return this.http.put(`files/shortcuts/${e}`,{name:t,parent:r,target:s,targetType:n},{version:"v3"})}deleteShortcut(e){return this.http.delete(`files/shortcuts/${e}`,{version:"v3"})}};var w=class{constructor(e){this.http=e;}async createCyWebWorkspace(e){return this.http.post("workspaces",e,{version:"v3"})}async getCyWebWorkspace(e){let t=`workspaces/${e}`;return this.http.get(t,{version:"v3"})}async deleteCyWebWorkspace(e){let t=`workspaces/${e}`;return this.http.delete(t,{version:"v3"})}async updateCyWebWorkspace(e,t){let r=`workspaces/${e}`;return this.http.put(r,t,{version:"v3"})}async updateCyWebWorkspaceName(e,t){let r=`workspaces/${e}/name`;return this.http.put(r,{name:t},{version:"v3"})}async updateCyWebWorkspaceNetworks(e,t){let r=`workspaces/${e}/networkids`;return this.http.put(r,t,{version:"v3"})}async getUserCyWebWorkspaces(){let t=`users/${(await this.http.get("user",{params:{valid:true}})).externalId}/workspaces`;return this.http.get(t,{version:"v3"})}};var k=class{constructor(e){this.http=e;}async authenticate(){let e=this.http.getAuthType();if(!e)throw new Error("Authentication parameters are missing in NDEx client.");if(e==="basic"){let t="user",r={valid:true};return this.http.get(t,{params:r})}else if(e==="oauth"){let t=this.http.getIdToken();if(!t)throw new Error("OAuth ID token is missing.");let r="users/signin",s={idToken:t};return this.http.post(r,s,{version:"v3"})}throw new Error(`Unsupported authentication type: ${e}`)}async getCurrentUser(){if(!this.http.getAuthType())throw new Error("Authentication parameters are missing in NDEx client.");let t="user",r={valid:true};return this.http.get(t,{params:r})}async updateCurrentUser(e){if(!e.externalId)throw new Error("User uuid is required in userUpdate object");let t=`user/${e.externalId}`;return this.http.put(t,e)}async requestPasswordReset(e){return this.http.post("user/forgot-password",{email:e})}async resetPassword(e,t){let r=`user/${e}/password`,s={headers:{"Content-Type":"text/plain"}};return this.http.put(r,t,s)}async getUser(e){let t=`user/${e}`;return this.http.get(t)}async getUserByNameOrEmail(e){let t=new URLSearchParams;"username"in e?t.append("username",e.username):"email"in e&&t.append("email",e.email);let r=`user?${t.toString()}`;return this.http.get(r)}async getUsersByUUIDs(e){return this.http.post("batch/user",e)}async searchUsers(e,t,r){let s={};t!==void 0&&(s.start=t.toString()),r!==void 0&&(s.limit=r.toString());let n={searchString:e};return this.http.post("search/user",n,{params:s})}async getAccountPageNetworks(e,t,r){let s={};t!==void 0&&(s.offset=t.toString()),r!==void 0&&(s.limit=r.toString());let n=`user/${e}/networksummary`;return this.http.get(n,{params:s})}async deleteUserAccount(e){let t=`user/${e}`;return this.http.delete(t)}};var b=class{constructor(e){this.http=e;}};var E=class{constructor(e=1234,t){this._port=e,this.cyRestBaseURL=t?.cyRestBaseURL||"http://127.0.0.1",this.ndexBaseURL=t?.ndexBaseURL||"https://www.ndexbio.org",this.axiosInstance=$.create({baseURL:this.cyRestURL(),timeout:3e4,headers:{"Content-Type":"application/json"}});}get port(){return this._port}static get cyRestBaseURL(){return "http://127.0.0.1"}setNDExBaseURL(e){e?.trim()&&(this.ndexBaseURL=e.trim());}getNDExBaseURL(){return this.ndexBaseURL}setBasicAuth(e,t){e?.trim()&&t&&(this.authConfig={type:"basic",username:e.trim(),password:t});}setAuthToken(e){e?.trim()&&(this.authConfig={type:"oauth",idToken:e.trim()});}clearAuth(){this.authConfig=void 0;}cyRestURL(){return `${this.cyRestBaseURL}:${this._port}`}getAuthFields(){if(!this.authConfig)return {};switch(this.authConfig.type){case "basic":return {username:this.authConfig.username,password:this.authConfig.password};case "oauth":return {idToken:this.authConfig.idToken};default:return {}}}async _httpGet(e){return (await this.axiosInstance.get(e)).data}async _httpPost(e,t,r){return (await this.axiosInstance.post(e,r,{params:t})).data}async _httpPut(e,t,r){return (await this.axiosInstance.put(e,r,{params:t})).data}async getCyNDExStatus(){return this._httpGet("/cyndex2/v1")}async getCytoscapeNetworkSummary(e="current"){return this._httpGet(`/cyndex2/v1/networks/${e}`)}async postNDExNetworkToCytoscape(e,t,r){let s={serverUrl:`${this.ndexBaseURL}/v2`,uuid:e,accessKey:t,createView:r,...this.getAuthFields()};return this._httpPost("/cyndex2/v1/networks",void 0,s)}async postCXNetworkToCytoscape(e){return this._httpPost("/cyndex2/v1/networks/cx",void 0,e)}async postCX2NetworkToCytoscape(e,t,r){let s={format:"cx2",collection:r,title:t};return this._httpPost("/v1/networks",s,e)}async postCytoscapeNetworkToNDEx(e="current"){let t={serverUrl:`${this.ndexBaseURL}/v2`,...this.getAuthFields()};return this._httpPost(`/cyndex2/v1/networks/${e}`,void 0,t)}async putCytoscapeNetworkInNDEx(e="current",t){let r={serverUrl:`${this.ndexBaseURL}/v2`,uuid:t,...this.getAuthFields()};return this._httpPut(`/cyndex2/v1/networks/${e}`,void 0,r)}};var D=class{constructor(e={}){this.httpService=new h(e),this.networks=new l(this.httpService),this.files=new v(this.httpService),this.workspace=new w(this.httpService),this.user=new k(this.httpService),this.admin=new b(this.httpService);}logout(){this.httpService.updateConfig({auth:void 0});}async getServerStatus(e){let t=new URLSearchParams;e&&t.append("format",e);let r=`admin/status${t.toString()?`?${t.toString()}`:""}`;return this.httpService.get(r)}hasAuthInfo(){let e=this.httpService.getConfig().auth;return e?e.type==="basic"?!!e.username&&!!e.password:e.type==="oauth"?!!e.idToken:false:false}updateConfig(e){this.httpService.updateConfig(e);}getConfig(){return this.httpService.getConfig()}get http(){return this.httpService}get v2(){return {networks:this.networks.v2}}get v3(){return {networks:this.networks.v3}}},ve=R;
3
- export{b as AdminService,m as CX2Network,E as CyNDEx,E as CyNDExService,v as FilesService,h as HTTPService,C as NDExAuthError,D as NDExClient,p as NDExError,N as NDExNetworkError,P as NDExNotFoundError,S as NDExServerError,x as NDExValidationError,I as NetworkIndexLevel,f as NetworkServiceV2,y as NetworkServiceV3,l as UnifiedNetworkService,k as UserService,w as WorkspaceService,ve as version};//# sourceMappingURL=index.mjs.map
1
+ import O from'axios';/* NDEx Client Library - Modern TypeScript implementation */
2
+ var X=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var $=(r=>(r.NONE="NONE",r.BASIC="BASIC",r.FULL="FULL",r))($||{}),g=class extends Error{constructor(t,r,s,i){super(t);this.statusCode=r;this.errorCode=s;this.description=i;this.name="NDExError";}},C=class extends g{constructor(t,r){super(t,void 0,"NETWORK_ERROR");this.originalError=r;this.name="NDExNetworkError";}},x=class extends g{constructor(e="Authentication failed",t=401){super(e,t,"AUTH_ERROR"),this.name="NDExAuthError";}},P=class extends g{constructor(e="Resource not found",t=404){super(e,t,"NOT_FOUND"),this.name="NDExNotFoundError";}},T=class extends g{constructor(e,t=400){super(e,t,"VALIDATION_ERROR"),this.name="NDExValidationError";}},E=class extends g{constructor(e="Internal server error",t=500){super(e,t,"SERVER_ERROR"),this.name="NDExServerError";}};var u={BASIC:"basic",OAUTH:"oauth"},M={PUBLIC:"PUBLIC",PRIVATE:"PRIVATE",UNLISTED:"UNLISTED"},_={READ:"READ",WRITE:"WRITE",ADMIN:"ADMIN"},W={NETWORK:"NETWORK",FOLDER:"FOLDER",SHORTCUT:"SHORTCUT"},H={DISCRETE:"DISCRETE",CONTINUOUS:"CONTINUOUS",PASSTHROUGH:"PASSTHROUGH"},q={STRING:"string",LONG:"long",INTEGER:"integer",DOUBLE:"double",BOOLEAN:"boolean",LIST_OF_STRING:"list_of_string",LIST_OF_LONG:"list_of_long",LIST_OF_INTEGER:"list_of_integer",LIST_OF_DOUBLE:"list_of_double",LIST_OF_BOOLEAN:"list_of_boolean"};var h=class a{constructor(e){this.CXVersion="2.0";this.hasFragments=false;this.metaData=[];e&&Object.assign(this,e),this.ensureRequiredMetadata();}static createEmpty(){let e=new a;return e.nodes=[],e.edges=[],e.metaData=[{name:"nodes",elementCount:0},{name:"edges",elementCount:0}],e}static fromJSON(e){let t=typeof e=="string"?JSON.parse(e):e;return new a(t)}static fromNetworkSummary(e){let t=a.createEmpty();return t.networkAttributes=[{name:e.name},...e.description?[{description:e.description}]:[],...e.version?[{version:e.version}]:[]],e.properties&&Object.entries(e.properties).forEach(([r,s])=>{t.networkAttributes?.push({[r]:s.v});}),t}addNode(e,t){this.nodes||(this.nodes=[]);let r={id:e};return t&&(r.v=t),this.nodes.push(r),this.updateNodeCount(),r}addEdge(e,t,r,s){this.edges||(this.edges=[]);let i={id:e,s:t,t:r};return s&&(i.v=s),this.edges.push(i),this.updateEdgeCount(),i}addNodeAttribute(e,t,r){let s=this.nodes?.find(i=>i.id===e);s&&(s.v||(s.v={}),s.v[t]=r);}addEdgeAttribute(e,t,r){let s=this.edges?.find(i=>i.id===e);s&&(s.v||(s.v={}),s.v[t]=r);}setNodeCoordinates(e,t,r,s){this.nodes||(this.nodes=[]);let i=this.nodes.find(n=>n.id===e);i||(i={id:e},this.nodes.push(i),this.updateNodeCount()),i.x=t,i.y=r,s!==void 0&&(i.z=s);}getNode(e){return this.nodes?.find(t=>t.id===e)}getEdge(e){return this.edges?.find(t=>t.id===e)}getNodes(){return this.nodes||[]}getEdges(){return this.edges||[]}getNodeCount(){return this.nodes?.length||0}getEdgeCount(){return this.edges?.length||0}getNetworkName(){return this.networkAttributes?.find(e=>"name"in e)?.name}setNetworkName(e){this.networkAttributes||(this.networkAttributes=[]),this.networkAttributes=this.networkAttributes.filter(t=>!("name"in t)),this.networkAttributes.push({name:e});}getNetworkAttribute(e){return this.networkAttributes?.find(t=>e in t)?.[e]}setNetworkAttribute(e,t){this.networkAttributes||(this.networkAttributes=[]),this.networkAttributes=this.networkAttributes.filter(r=>!(e in r)),this.networkAttributes.push({[e]:t});}validate(){let e=[];return this.CXVersion||e.push("CXVersion is required"),this.hasFragments===void 0&&e.push("hasFragments is required"),(!this.metaData||this.metaData.length===0)&&e.push("metaData is required and must not be empty"),this.metaData?.forEach((t,r)=>{t.name||e.push(`metaData[${r}] is missing required 'name' field`);}),this.nodes&&this.nodes.forEach((t,r)=>{(t.id===void 0||t.id===null)&&e.push(`nodes[${r}] is missing required 'id' field`);}),this.edges&&this.edges.forEach((t,r)=>{if((t.id===void 0||t.id===null)&&e.push(`edges[${r}] is missing required 'id' field`),(t.s===void 0||t.s===null)&&e.push(`edges[${r}] is missing required 's' (source) field`),(t.t===void 0||t.t===null)&&e.push(`edges[${r}] is missing required 't' (target) field`),this.nodes&&t.s!==void 0&&t.t!==void 0){let s=this.nodes.some(n=>n.id===t.s),i=this.nodes.some(n=>n.id===t.t);s||e.push(`edges[${r}] references non-existent source node ${t.s}`),i||e.push(`edges[${r}] references non-existent target node ${t.t}`);}}),{isValid:e.length===0,errors:e}}toJSON(){return JSON.stringify(this,null,2)}clone(){return new a(JSON.parse(this.toJSON()))}getStatistics(){return {nodeCount:this.getNodeCount(),edgeCount:this.getEdgeCount(),hasCoordinates:!!(this.nodes&&this.nodes.some(e=>e.x!==void 0||e.y!==void 0||e.z!==void 0)),hasVisualProperties:!!(this.visualProperties&&(this.visualProperties.default||this.visualProperties.edgeMapping||this.visualProperties.nodeMapping))}}ensureRequiredMetadata(){this.metaData||(this.metaData=[]),this.nodes&&!this.metaData.find(e=>e.name==="nodes")&&this.metaData.push({name:"nodes",elementCount:this.nodes.length}),this.edges&&!this.metaData.find(e=>e.name==="edges")&&this.metaData.push({name:"edges",elementCount:this.edges.length});}updateNodeCount(){let e=this.metaData?.find(t=>t.name==="nodes");e&&(e.elementCount=this.nodes?.length||0);}updateEdgeCount(){let e=this.metaData?.find(t=>t.name==="edges");e&&(e.elementCount=this.edges?.length||0);}};var f=class{constructor(e){this.http=e;}async getRawCX1Network(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`network/${e}${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2",headers:{Accept:"application/json"}})}async getNetworkSummary(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`network/${e}/summary${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2"})}async updateNetworkSummary(e,t){let r=`network/${e}/summary`;return this.http.put(r,t,{version:"v2"})}async copyNetwork(e){let t=`network/${e}/copy`;return this.http.post(t,{},{version:"v2"})}async searchNetworks(e,t,r,s){let i={};t!==void 0&&(i.start=t.toString()),r!==void 0&&(i.limit=r.toString());let n={searchString:e};return s!==void 0&&(s.permission!==void 0&&(n.permission=s.permission),s.includeGroups!==void 0&&(n.includeGroups=s.includeGroups),s.accountName!==void 0&&(n.accountName=s.accountName)),this.http.post("search/network",n,{version:"v2",params:i})}async createNetworkFromRawCX1(e,t={}){let i=(await this.http.post("network",e,{version:"v2",params:t})).split("/"),n=i[i.length-1];if(!n)throw new Error("Failed to extract UUID from response");return n}async updateNetworkFromRawCX1(e,t){let r=`network/${e}`;return this.http.put(r,t,{version:"v2"})}async deleteNetwork(e){let t=`network/${e}`;return this.http.delete(t,{version:"v2"})}async getNetworkSummariesByUUIDs(e,t){let r=t?{accesskey:t}:void 0;return this.http.post("batch/network/summary",e,{version:"v2",params:r})}async getUserNetworks(e,t={}){let r=new URLSearchParams;t.start!==void 0&&r.append("start",t.start.toString()),t.size!==void 0&&r.append("size",t.size.toString());let s=`user/${e}/networks${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2"})}async setNetworkSystemProperties(e,t){let r=`networks/${e}/systemproperty`;return this.http.put(r,t,{version:"v2"})}async getNetworkPermissions(e){let t=`networks/${e}/permission`;return this.http.get(t,{version:"v2"})}async setNetworkPermissions(e,t){let r=`networks/${e}/permission`;return this.http.put(r,t,{version:"v2"})}async grantNetworkPermission(e,t,r){let s=`networks/${e}/permission`,i={memberUUID:t,permission:r};return this.http.post(s,i,{version:"v2"})}async revokeNetworkPermission(e,t){let r=`networks/${e}/permission`;return this.http.delete(r,{version:"v2",data:{memberUUID:t}})}async getNetworkProfile(e){let t=`networks/${e}/profile`;return this.http.get(t,{version:"v2"})}async setNetworkProfile(e,t){let r=`networks/${e}/profile`;return this.http.put(r,t,{version:"v2"})}async makeNetworkPublic(e){let t=`networks/${e}/systemproperty`,r={visibility:"PUBLIC"};return this.http.put(t,r,{version:"v2"})}async makeNetworkPrivate(e){let t=`networks/${e}/systemproperty`,r={visibility:"PRIVATE"};return this.http.put(t,r,{version:"v2"})}async getNetworkSample(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`networks/${e}/sample${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2"})}async getMetaData(e,t){let r=new URLSearchParams;t!==void 0&&r.append("accesskey",t);let s=`network/${e}/aspect${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v2"})}async getAccessKey(e){let t=`networks/${e}/accesskey`;return this.http.get(t,{version:"v2"})}async updateAccessKey(e,t){let r=`networks/${e}/accesskey`;return this.http.put(r,{action:t},{version:"v2"})}};var y=class{constructor(e){this.http=e;}async getNetworkSummary(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`networks/${e}/summary${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v3"})}async getRawCX2Network(e,t={}){let r=new URLSearchParams;t.accesskey&&r.append("accesskey",t.accesskey);let s=`networks/${e}${r.toString()?`?${r.toString()}`:""}`;return this.http.get(s,{version:"v3"})}async getAttributesOfSelectedNodes(e,t,r={}){let s=new URLSearchParams;r.accesskey&&s.append("accesskey",r.accesskey);let i={ids:t.ids,attributeNames:t.attributeNames},n=`search/networks/${e}/nodes${s.toString()?`?${s.toString()}`:""}`;return this.http.post(n,i,{version:"v3"})}async getNetworkSummariesV3ByUUIDs(e,t,r){let s={format:r===void 0?"FULL":r};return t!=null&&(s.accesskey=t),this.http.post("batch/networks/summary",e,{version:"v3",params:s})}async searchNetworks(e={}){let t=new URLSearchParams;e.searchString&&t.append("searchString",e.searchString),e.accountName&&t.append("accountName",e.accountName),e.permission&&t.append("permission",e.permission),e.includeGroups!==void 0&&t.append("includeGroups",e.includeGroups.toString()),e.admin&&t.append("admin",e.admin),e.start!==void 0&&t.append("start",e.start.toString()),e.size!==void 0&&t.append("size",e.size.toString()),e.source&&t.append("source",e.source);let r=`search/network${t.toString()?`?${t.toString()}`:""}`;return this.http.get(r,{version:"v3"})}async getNetworkAsCX2Object(e,t={}){let r=await this.getRawCX2Network(e,t);return new h(r)}async createNetworkFromCX2(e,t={}){let r="networks",s=e instanceof h?JSON.parse(e.toJSON()):e;return this.http.post(r,s,{version:"v3",params:t})}async updateNetworkCX2(e,t){let r=`networks/${e}`,s=t instanceof h?JSON.parse(t.toJSON()):t;return this.http.put(r,s,{version:"v3"})}async uploadCX2Network(e,t={}){let r={};if(t.visibility!==void 0&&(r.visibility=String(t.visibility)),t.folderId!==void 0&&(r.folderId=t.folderId),typeof globalThis.window>"u"){let p;try{p=X("form-data");}catch{p=null;}if(p){let c=new p;if((m=>m&&typeof m=="object"&&typeof m.pipe=="function")(e))c.append("CXNetworkStream",e,{filename:"network.cx2",contentType:"application/json"});else if(typeof globalThis.Buffer<"u"&&globalThis.Buffer.isBuffer(e))c.append("CXNetworkStream",e,{filename:"network.cx2",contentType:"application/json"});else if(typeof e=="string")c.append("CXNetworkStream",globalThis.Buffer.from(e),{filename:"network.cx2",contentType:"application/json"});else if(typeof globalThis.Blob<"u"&&e instanceof globalThis.Blob){let m=await e.arrayBuffer();c.append("CXNetworkStream",globalThis.Buffer.from(m),{filename:"network.cx2",contentType:e.type||"application/json"});}else c.append("CXNetworkStream",globalThis.Buffer.from(String(e)),{filename:"network.cx2",contentType:"application/json"});let S={version:"v3",params:r,headers:c.getHeaders?.()||{},maxBodyLength:1/0};return this.http.post("networks",c,S)}if((c=>c&&typeof c=="object"&&typeof c.pipe=="function")(e))throw new Error("Readable stream upload requires 'form-data' package. Please install 'form-data' or pass a string/Buffer/Blob instead.")}let i=new FormData,n=typeof globalThis.File<"u",o=typeof globalThis.Blob<"u";if(n&&e instanceof globalThis.File)i.append("CXNetworkStream",e,e.name||"network.cx2");else if(o&&e instanceof globalThis.Blob)i.append("CXNetworkStream",e,"network.cx2");else if(typeof e=="string"){let p=new Blob([e],{type:"application/json"});i.append("CXNetworkStream",p,"network.cx2");}else if(typeof globalThis.Buffer<"u"&&globalThis.Buffer.isBuffer(e)){let p=new Blob([e],{type:"application/json"});i.append("CXNetworkStream",p,"network.cx2");}else {let p=new Blob([String(e)],{type:"application/json"});i.append("CXNetworkStream",p,"network.cx2");}let d={version:"v3",params:r};return t.onProgress&&(d.onUploadProgress=p=>{let l=Math.round(p.loaded*100/(p.total||1));t.onProgress(l);}),this.http.post("networks",i,d)}async uploadNetworkFile(e,t={}){let r={};return t.visibility!==void 0&&(r.visibility=t.visibility),t.folderId!==void 0&&(r.folderId=t.folderId),t.onProgress&&(r.onProgress=t.onProgress),this.uploadCX2Network(e,r)}async getNetworkMetadata(e){let t=`networks/${e}/metadata`;return this.http.get(t,{version:"v3"})}async updateNetworkMetadata(e,t){let r=`networks/${e}/metadata`;return this.http.put(r,t,{version:"v3"})}async getNetworkAspect(e,t,r={}){let s=new URLSearchParams;r.accesskey&&s.append("accesskey",r.accesskey);let i=`networks/${e}/aspects/${t}${s.toString()?`?${s.toString()}`:""}`;return this.http.get(i,{version:"v3"})}async deleteNetwork(e,t=false){let r=new URLSearchParams;r.append("permanent",t.toString());let s=`networks/${e}?${r.toString()}`;return this.http.delete(s,{version:"v3"})}};var v=class{constructor(e){this.http=e;this.v2Service=new f(e),this.v3Service=new y(e);}async getNetworkSummary(e,t={}){return this.v3Service.getNetworkSummary(e,t)}async updateNetworkSummary(e,t){let r=this.transformV3ToV2(t);return this.v2Service.updateNetworkSummary(e,r)}transformV3ToV2(e){let{properties:t,...r}=e,s,i=[];if(t)for(let[o,d]of Object.entries(t))o==="version"?s=this.convertValueToString(d.v):i.push({predicateString:o,value:this.convertValueToString(d.v),dataType:d.t});let n={...r,properties:i};return s!==void 0&&(n.version=s),n}convertValueToString(e){return Array.isArray(e)?e.map(t=>String(t)).join(","):String(e)}async getRawCX1Network(e,t={}){return this.v2Service.getRawCX1Network(e,t)}async getRawCX2Network(e,t={}){return this.v3Service.getRawCX2Network(e,t)}async deleteNetwork(e,t=false){return this.v3Service.deleteNetwork(e,t)}async createNetworkDOI(e){let t="admin/request",r={type:"DOI",networkId:e.networkId,properties:{contactEmail:e.contactEmail},isCertified:e.isCertified};return this.http.post(t,r,{version:"v2"})}async getAttributesOfSelectedNodes(e,t,r={}){return this.v3Service.getAttributesOfSelectedNodes(e,t,r)}async neighborhoodQuery(e,t,r,s,i=false){let n={};r!==void 0&&r===true&&(n.save="true");let o={searchString:t,searchDepth:1};if(s!==void 0&&(s.searchDepth!==void 0&&(o.searchDepth=s.searchDepth),s.edgeLimit!==void 0&&(o.edgeLimit=s.edgeLimit),s.errorWhenLimitIsOver!==void 0&&(o.errorWhenLimitIsOver=s.errorWhenLimitIsOver),s.directOnly!==void 0&&(o.directOnly=s.directOnly),s.nodeIds!=null&&(o.nodeIds=s.nodeIds)),i){let p=`search/network/${e}/query`;return this.http.post(p,o,{version:"v3",params:n})}let d=`search/network/${e}/query`;return this.http.post(d,o,{version:"v2",params:n})}async interConnectQuery(e,t,r,s,i=false){let n={};r!==void 0&&r===true&&(n.save="true");let o={searchString:t};if(s!==void 0&&(s.edgeLimit!==void 0&&(o.edgeLimit=s.edgeLimit),s.errorWhenLimitIsOver!==void 0&&(o.errorWhenLimitIsOver=s.errorWhenLimitIsOver),s.nodeIds!=null&&(o.nodeIds=s.nodeIds)),i){let p=`search/networks/${e}/interconnectquery`;return this.http.post(p,o,{version:"v3",params:n})}let d=`search/network/${e}/interconnectquery`;return this.http.post(d,o,{version:"v2",params:n})}async getNetworkPermissionsByUUIDs(e){return this.http.post("batch/network/permission",e,{version:"v2"})}async exportNetworks(e){return this.http.post("batch/network/export",e,{version:"v2"})}async moveNetworks(e,t){if(!Array.isArray(e))throw new Error("Invalid networkIds - must be an array");let r="batch/networks/move",s={targetFolder:t!==void 0?t:null,networks:e};return this.http.post(r,s,{version:"v3"})}async setNetworksVisibility(e,t){this.validateShareData(e);let r="batch/files/setvisibility",s={files:e,visibility:t};return this.http.post(r,s,{version:"v3"})}async getNetworkAccessKey(e){let t=`network/${e}/accesskey`;return this.http.get(t,{version:"v2"})}async getRandomEdges(e,t,r){if(t<=0)throw new Error("Value of parameter limit has to be greater than 0.");let s={size:t.toString(),method:"random"};r!==void 0&&(s.accesskey=r);let i=`networks/${e}/aspects/edges`;return this.http.get(i,{version:"v3",params:s})}validateShareData(e){for(let t of Object.keys(e.files))if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t))throw new Error(`Invalid UUID format: ${t}`)}async getAspectElements(e,t,r,s){let i={};r!==void 0&&(i.size=r.toString()),s!==void 0&&(i.accesskey=s);let n=`networks/${e}/aspects/${t}`;return this.http.get(n,{version:"v3",params:i})}async getFilteredEdges(e,t,r,s,i,n,o,d){let p={};i!==void 0&&(p.size=i.toString()),n!==void 0&&(p.order=n),d!==void 0&&(p.accesskey=d),o!==void 0&&(p.format=o);let l={name:t,value:r,operator:s},c=`search/networks/${e}/edges`;return this.http.post(c,l,{version:"v3",params:p})}async getCX2MetaData(e,t){let r={};t!==void 0&&(r.accesskey=t);let s=`networks/${e}/aspects`;return this.http.get(s,{version:"v3",params:r})}async createNetworkFromRawCX2(e,t={}){return this.v3.createNetworkFromCX2(e,t)}async updateNetworkFromRawCX2(e,t){let r=`networks/${e}`;return this.http.put(r,t,{version:"v3"})}async setReadOnly(e,t){let r=`network/${e}/systemproperty`;return this.http.put(r,{readOnly:t},{version:"v2"})}get v2(){return this.v2Service}get v3(){return this.v3Service}};var b=class{constructor(e){this.http=e;}copyFile(e){if(e.type==="FOLDER")throw new Error("Folder copying is not supported. Only NETWORK and SHORTCUT types are allowed.");let t={};return e.accessKey!==void 0&&(t.accesskey=e.accessKey),this.http.post("files/copy",{fileId:e.fileId,type:e.type,targetId:e.targetId},{params:t,version:"v3"})}getCount(){return this.http.get("files/count",{version:"v3"})}getTrash(){return this.http.get("files/trash",{version:"v3"})}emptyTrash(){return this.http.delete("files/trash",{version:"v3"})}permanentlyDeleteFile(e){return this.http.delete(`files/trash/${e}`,{version:"v3"})}restoreFile(e,t,r){return this.http.post("files/trash/restore",{networks:e,folders:t,shortcuts:r},{version:"v3"})}_validateShareData(e){if(typeof e!="object"||e===null||e.files===void 0)throw new Error('Data must be an object with a "files" property');if(typeof e.files!="object"||e.files===null)throw new Error('The "files" property must be an object');let t=["NETWORK","FOLDER","SHORTCUT"];for(let[r,s]of Object.entries(e.files)){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(r))throw new Error(`Invalid UUID format: ${r}`);if(!t.includes(s))throw new Error(`Invalid file type for ${r}: ${s}. Must be one of: ${t.join(", ")}`)}}_validateMemberData(e){for(let t of Object.keys(e.members))if(typeof t!="string"||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t))throw new Error(`Invalid UUID format: ${t}`)}updateMember(e){return this._validateShareData({files:e.files}),this._validateMemberData({members:e.members}),this.http.post("files/sharing/members",{files:e.files,members:e.members},{version:"v3"})}listMembers(e){return this._validateShareData({files:e}),this.http.post("files/sharing/members/list",e,{version:"v3"})}transferOwnership(e){return this.http.post("files/sharing/transfer",e,{version:"v3"})}listShares(e){let t={};return e!==void 0&&(t.limit=e),this.http.get("files/sharing/list",{params:t,version:"v3"})}share(e){return this._validateShareData({files:e}),this.http.post("files/sharing/share",{files:e},{version:"v3"})}unshare(e){return this._validateShareData({files:e}),this.http.post("files/sharing/unshare",{files:e},{version:"v3"})}getFolders(e){let t={};return e!==void 0&&(t.limit=e),this.http.get("files/folders",{params:t,version:"v3"})}createFolder(e,t){return this.http.post("files/folders",{name:e,parent:t},{version:"v3"})}getFolder(e,t){let r={};return t!==void 0&&(r.accesskey=t),this.http.get(`files/folders/${e}`,{params:r,version:"v3"})}updateFolder(e,t){return this.http.put(`files/folders/${e}`,t,{version:"v3"})}deleteFolder(e){return this.http.delete(`files/folders/${e}`,{version:"v3"})}getFolderCount(e,t){let r={};return t!==void 0&&(r.accesskey=t),this.http.get(`files/folders/${e}/count`,{params:r,version:"v3"})}getFolderList(e,t,r,s){let i={};return t!==void 0&&(i.accesskey=t),r!==void 0&&(i.format=r),s!==void 0&&(i.type=s),this.http.get(`files/folders/${e}/list`,{params:i,version:"v3"})}getFolderAccessKey(e){let t=`files/folders/${e}/accesskey`;return this.http.get(t,{version:"v3"})}getShortcuts(e){let t={};return e!==void 0&&(t.limit=e),this.http.get("files/shortcuts",{params:t,version:"v3"})}createShortcut(e){return this.http.post("files/shortcuts",e,{version:"v3"})}getShortcut(e,t){let r={};return t!==void 0&&(r.accesskey=t),this.http.get(`files/shortcuts/${e}`,{params:r,version:"v3"})}updateShortcut(e,t){return this.http.put(`files/shortcuts/${e}`,{...t,parent:t.parent??null},{version:"v3"})}deleteShortcut(e){return this.http.delete(`files/shortcuts/${e}`,{version:"v3"})}setVisibility(e){return this.http.post("batch/files/setvisibility",{files:e.files,visibility:e.visibility},{version:"v3"})}searchFiles(e){return this.http.post("search/files",e,{version:"v3"})}};var w=class{constructor(e){this.http=e;}async createCyWebWorkspace(e){return this.http.post("workspaces",e,{version:"v3"})}async getCyWebWorkspace(e){let t=`workspaces/${e}`;return this.http.get(t,{version:"v3"})}async deleteCyWebWorkspace(e){let t=`workspaces/${e}`;return this.http.delete(t,{version:"v3"})}async updateCyWebWorkspace(e,t){let r=`workspaces/${e}`;return this.http.put(r,t,{version:"v3"})}async updateCyWebWorkspaceName(e,t){let r=`workspaces/${e}/name`;return this.http.put(r,{name:t},{version:"v3"})}async updateCyWebWorkspaceNetworks(e,t){let r=`workspaces/${e}/networkids`;return this.http.put(r,t,{version:"v3"})}async getUserCyWebWorkspaces(){let t=`users/${(await this.http.get("user",{params:{valid:true}})).externalId}/workspaces`;return this.http.get(t,{version:"v3"})}};var k=class{constructor(e){this.http=e;}async authenticate(){let e=this.http.getAuthType();if(!e)throw new Error("Authentication parameters are missing in NDEx client.");if(e===u.BASIC){let t="user",r={valid:true};return this.http.get(t,{params:r})}else if(e===u.OAUTH){let t=this.http.getIdToken();if(!t)throw new Error("OAuth ID token is missing.");let r="users/signin",s={idToken:t};return this.http.post(r,s,{version:"v3"})}throw new Error(`Unsupported authentication type: ${e}`)}async getCurrentUser(){if(!this.http.getAuthType())throw new Error("Authentication parameters are missing in NDEx client.");let t="user",r={valid:true};return this.http.get(t,{params:r})}async updateCurrentUser(e){if(!e.externalId)throw new Error("User uuid is required in userUpdate object");let t=`user/${e.externalId}`;return this.http.put(t,e)}async requestPasswordReset(e){return this.http.post("user/forgot-password",{email:e})}async resetPassword(e,t){let r=`user/${e}/password`,s={headers:{"Content-Type":"text/plain"}};return this.http.put(r,t,s)}async getUser(e){let t=`user/${e}`;return this.http.get(t)}async getUserByNameOrEmail(e){let t=new URLSearchParams;"username"in e?t.append("username",e.username):"email"in e&&t.append("email",e.email);let r=`user?${t.toString()}`;return this.http.get(r)}async getUsersByUUIDs(e){return this.http.post("batch/user",e)}async searchUsers(e,t,r){let s={};t!==void 0&&(s.start=t.toString()),r!==void 0&&(s.limit=r.toString());let i={searchString:e};return this.http.post("search/user",i,{params:s})}async getAccountPageNetworks(e,t,r){let s={};t!==void 0&&(s.offset=t.toString()),r!==void 0&&(s.limit=r.toString());let i=`user/${e}/networksummary`;return this.http.get(i,{params:s})}async getUserHomeContent(e,t="update"){let r={format:t},s=`users/${e}/home`;return this.http.get(s,{params:r,version:"v3"})}async deleteUserAccount(e){let t=`user/${e}`;return this.http.delete(t)}};var N=class{constructor(){}};var R=class{constructor(e=1234,t){this._port=e,this.cyRestBaseURL=t?.cyRestBaseURL||"http://127.0.0.1",this.ndexBaseURL=t?.ndexBaseURL||"https://www.ndexbio.org",this.axiosInstance=O.create({baseURL:this.cyRestURL(),timeout:3e4,headers:{"Content-Type":"application/json"}});}get port(){return this._port}static get cyRestBaseURL(){return "http://127.0.0.1"}setNDExBaseURL(e){e?.trim()&&(this.ndexBaseURL=e.trim());}getNDExBaseURL(){return this.ndexBaseURL}setBasicAuth(e,t){e?.trim()&&t&&(this.authConfig={type:u.BASIC,username:e.trim(),password:t});}setAuthToken(e){e?.trim()&&(this.authConfig={type:u.OAUTH,idToken:e.trim()});}clearAuth(){delete this.authConfig;}cyRestURL(){return `${this.cyRestBaseURL}:${this._port}`}getAuthFields(){if(!this.authConfig)return {};switch(this.authConfig.type){case u.BASIC:return {username:this.authConfig.username,password:this.authConfig.password};case u.OAUTH:return {idToken:this.authConfig.idToken};default:return {}}}async _httpGet(e){return (await this.axiosInstance.get(e)).data}async _httpPost(e,t,r){return (await this.axiosInstance.post(e,r,{params:t})).data}async _httpPut(e,t,r){return (await this.axiosInstance.put(e,r,{params:t})).data}async getCyNDExStatus(){return this._httpGet("/cyndex2/v1")}async getCytoscapeNetworkSummary(e="current"){return this._httpGet(`/cyndex2/v1/networks/${e}`)}async postNDExNetworkToCytoscape(e,t,r){let s={serverUrl:`${this.ndexBaseURL}/v2`,uuid:e,...this.getAuthFields()};return t!==void 0&&(s.accessKey=t),r!==void 0&&(s.createView=r),this._httpPost("/cyndex2/v1/networks",void 0,s)}async postCXNetworkToCytoscape(e){return this._httpPost("/cyndex2/v1/networks/cx",void 0,e)}async postCX2NetworkToCytoscape(e,t,r){let s={format:"cx2",collection:r,title:t};return this._httpPost("/v1/networks",s,e)}async postCytoscapeNetworkToNDEx(e="current"){let t={serverUrl:`${this.ndexBaseURL}/v2`,...this.getAuthFields()};return this._httpPost(`/cyndex2/v1/networks/${e}`,void 0,t)}async putCytoscapeNetworkInNDEx(e="current",t){let r={serverUrl:`${this.ndexBaseURL}/v2`,uuid:t,...this.getAuthFields()};return this._httpPut(`/cyndex2/v1/networks/${e}`,void 0,r)}};var D="0.6.0-alpha.3";var A=class{constructor(e={}){this.config={baseURL:"https://www.ndexbio.org",timeout:3e4,retries:3,retryDelay:1e3,debug:false,...e};let t={...this.config.headers,...this.getAuthHeaders()};typeof window>"u"&&(t["User-Agent"]=`NDEx-JS-Client/${D}`);let r={headers:t};this.config.baseURL&&(r.baseURL=this.config.baseURL),this.config.timeout&&(r.timeout=this.config.timeout),this.axiosInstance=O.create(r),this.setupInterceptors();}getAuthHeaders(){if(!this.config.auth)return {};if(this.config.auth.type===u.BASIC){let e=`${this.config.auth.username}:${this.config.auth.password}`;return {Authorization:`Basic ${typeof window<"u"&&typeof btoa<"u"?btoa(e):Buffer.from(e,"utf-8").toString("base64")}`}}else if(this.config.auth.type===u.OAUTH)return {Authorization:`Bearer ${this.config.auth.idToken}`};return {}}buildUrl(e,t="v2"){let r=e.startsWith("/")?e.slice(1):e;return `/${t}/${r}`}async get(e,t){let{version:r,...s}=t||{},i=this.buildUrl(e,r);try{let n=await this.axiosInstance.get(i,s);return this.handleResponse(n)}catch(n){this.handleError(n);}}async post(e,t,r){let{version:s,...i}=r||{},n=this.buildUrl(e,s);try{let o=await this.axiosInstance.post(n,t,i);return this.handleResponse(o)}catch(o){this.handleError(o);}}async put(e,t,r){let{version:s,...i}=r||{},n=this.buildUrl(e,s);try{let o=await this.axiosInstance.put(n,t,i);return this.handleResponse(o)}catch(o){this.handleError(o);}}async delete(e,t){let{version:r,...s}=t||{},i=this.buildUrl(e,r);try{let n=await this.axiosInstance.delete(i,s);return this.handleResponse(n)}catch(n){this.handleError(n);}}async uploadFile(e,t,r={}){let{version:s,onProgress:i,contentType:n}=r,o=this.buildUrl(e,s),d=new FormData,p=typeof globalThis.File<"u",l=typeof globalThis.Blob<"u";if(p&&t instanceof globalThis.File)d.append("file",t,t.name);else if(l&&t instanceof globalThis.Blob)d.append("file",t,"file.cx2");else if(typeof t=="string"){let c=new Blob([t],{type:n||"application/json"});d.append("file",c,"file.cx2");}else if(typeof globalThis.Buffer<"u"&&globalThis.Buffer.isBuffer(t)){let c=new Blob([t],{type:n||"application/octet-stream"});d.append("file",c,"file.cx2");}else {let c=new Blob([String(t)],{type:n||"application/octet-stream"});d.append("file",c,"file.cx2");}try{let c={};i&&(c.onUploadProgress=S=>{let m=Math.round(S.loaded*100/(S.total||1));i(m);});let I=await this.axiosInstance.post(o,d,c);return this.handleResponse(I)}catch(c){this.handleError(c);}}setupInterceptors(){this.axiosInstance.interceptors.request.use(e=>(this.config.debug&&console.log("NDEx API Request:",{method:e.method?.toUpperCase(),url:e.url,headers:e.headers}),e),e=>(this.config.debug&&console.error("NDEx API Request Error:",e),Promise.reject(e))),this.axiosInstance.interceptors.response.use(e=>(this.config.debug&&console.log("NDEx API Response:",{status:e.status,url:e.config.url,data:e.data}),e),e=>(this.config.debug&&console.error("NDEx API Response Error:",e.response?.data||e.message),Promise.reject(e)));}handleResponse(e){return e.data&&typeof e.data=="object"&&"errorCode"in e.data&&this.throwNDExError(e.data.message||"Unknown error occurred",e.status,e.data.errorCode||"UNKNOWN_ERROR",e.data.description),e.data&&typeof e.data=="object"&&"data"in e.data?e.data.data:e.data}handleError(e){if(e.response){let t=e.response.data?.message||e.message,r=e.response.data?.errorCode||`HTTP_${e.response.status}`,s=e.response.data?.description;this.throwNDExError(t,e.response.status,r,s);}else throw e.request?new C("Network error - no response received",e):new g(e.message||"Unknown error occurred",void 0,"CLIENT_ERROR",e.toString())}throwNDExError(e,t,r,s){switch(t){case 400:throw new T(e,t);case 401:case 403:throw new x(e,t);case 404:throw new P(e,t);case 500:case 502:case 503:case 504:throw new E(e,t);default:throw new g(e,t,r,s)}}updateConfig(e){if(this.config={...this.config,...e},e.baseURL&&(this.axiosInstance.defaults.baseURL=e.baseURL),e.timeout&&(this.axiosInstance.defaults.timeout=e.timeout),e.headers&&Object.assign(this.axiosInstance.defaults.headers,e.headers),"auth"in e){let t=this.getAuthHeaders();delete this.axiosInstance.defaults.headers.common.Authorization,Object.assign(this.axiosInstance.defaults.headers.common,t);}}getConfig(){return {...this.config}}getAuthType(){return this.config.auth?.type}getIdToken(){return this.config.auth?.type===u.OAUTH?this.config.auth.idToken:void 0}setIdToken(e){this.updateConfig({auth:{type:u.OAUTH,idToken:e}});}};var U=class{constructor(e={}){this.httpService=new A(e),this.networks=new v(this.httpService),this.files=new b(this.httpService),this.workspace=new w(this.httpService),this.user=new k(this.httpService),this.admin=new N;}logout(){this.httpService.updateConfig({});}async getServerStatus(e){let t=new URLSearchParams;e&&t.append("format",e);let r=`admin/status${t.toString()?`?${t.toString()}`:""}`;return this.httpService.get(r)}hasAuthInfo(){let e=this.httpService.getConfig().auth;return e?e.type===u.BASIC?!!e.username&&!!e.password:e.type===u.OAUTH?!!e.idToken:false:false}updateConfig(e){this.httpService.updateConfig(e);}getConfig(){return this.httpService.getConfig()}getAuthType(){return this.httpService.getAuthType()}setIdToken(e){this.httpService.setIdToken(e);}get v2(){return {networks:this.networks.v2}}get v3(){return {networks:this.networks.v3}}},Re=D;
3
+ export{N as AdminService,u as AuthType,h as CX2Network,q as CXDataType,R as CyNDEx,R as CyNDExService,b as FilesService,x as NDExAuthError,U as NDExClient,g as NDExError,W as NDExFileType,C as NDExNetworkError,P as NDExNotFoundError,E as NDExServerError,T as NDExValidationError,$ as NetworkIndexLevel,f as NetworkServiceV2,y as NetworkServiceV3,_ as Permission,v as UnifiedNetworkService,k as UserService,H as VPMappingType,M as Visibility,w as WorkspaceService,Re as version};//# sourceMappingURL=index.mjs.map
4
4
  //# sourceMappingURL=index.mjs.map