UNPKG

grafo-client

Version:

Grafo Client API Library

1 lines 8.41 kB
"use strict";var AuthApi=require("./auth_api"),DocumentApi=require("./document_api"),EkgApi=require("./ekg_api"),EkgDocument=require("./models/ekg_document"),Document=require("./models/document"),Folder=require("./models/folder"),ConversationApi=require("./conversation_api"),CommentApi=require("./comment_api"),DocumentShare=require("./models/document_share"),Comment=require("./models/comment"),Reply=require("./models/reply"),winston=require("winston");function GrafoClient(){}module.exports=GrafoClient;var createLoggerOptions=function(){return{console:{level:"debug",handleExceptions:!0,json:!1,colorize:!0}}};GrafoClient.prototype.init=async function(e,t){if(t)this.logger=t;else{var o=createLoggerOptions();this.logger=winston.createLogger({level:"debug",transports:[new winston.transports.Console(o.console)],exceptionHandlers:[new winston.transports.Console]})}this.config=e,this.authApi=new AuthApi(e,this.logger),this.sessionCookie=await this.authApi.loginWithEmailPasswordToken(),this.userProfile=await this.authApi.getUserProfile(),this.documentApi=new DocumentApi(e,this.sessionCookie,this.logger),this.ekgApi=new EkgApi(this.logger),this.ekgApi.init(this.config,this.userProfile.id,this.sessionCookie),this.conversationApi=new ConversationApi("",e,this.sessionCookie,this.logger),this.commentApi=new CommentApi(e,this.sessionCookie,this.logger),this.grafoClientStandAlone=!0},GrafoClient.prototype.initServer=function(e,t,o){return this.logger=o,this.userProfile=t,this.ekgApi=new EkgApi(this.logger),this.ekgApi.initServer(e,t.userId),this},GrafoClient.prototype.getEkgApi=async function(e,t){return this.ekg=await this.ekgApi.getEkgProxy(e,t),this.ekgApi},GrafoClient.prototype.getDocuments=async function(e){var t=await this.documentApi.listDocuments(e);this.documents=[];for(var o=0;o<t.documents.length;o++)this.documents.push(new Document(t.documents[o]));return this.documents},GrafoClient.prototype.getDocument=async function(e){var t=await this.documentApi.getDocument(e);return this.document=new Document(t),this.document},GrafoClient.prototype.createDocument=async function(e){var t=await this.documentApi.createDocument(e),o=await this.documentApi.getDocument(t.id);return this.document=new Document(o),this.document},GrafoClient.prototype.updateDocument=async function(e){var t=await this.documentApi.updateDocument(e);return this.document=new Document(t),this.document},GrafoClient.prototype.deleteDocument=async function(e){return this.deletedDoc=await this.documentApi.deleteDocument(e),this.deletedDoc},GrafoClient.prototype.createEkgDocument=async function(e,t){var o;this.grafoClientStandAlone&&(e&&e.id?await this.getDocument(e.id):e=await this.createDocument(e)),this.document&&(o=this.document.sessionId),this.ekgDocument=new EkgDocument(e,this.logger),this.ekgApi.initDocBuilder(this.ekgDocument);await this.ekgApi.initAdapter(e.id,o,!0),await this.ekgDocument.createDbCollectionAndEKGDoc(t);return this.ekgDocument},GrafoClient.prototype.getEkgDocument=async function(e){var t;this.grafoClientStandAlone&&e&&e.id&&await this.getDocument(e.id),this.logger.debug("Fetching document Id : "+e.id),this.ekgDocument=new EkgDocument(e,this.logger),this.ekgApi.initDocBuilder(this.ekgDocument),this.document&&(t=this.document.sessionId);await this.ekgApi.initAdapter(e.id,t,!0);return this.ekgDocument},GrafoClient.prototype.updateEkgDocument=async function(e,t,o){this.grafoClientStandAlone&&e&&e.id&&await this.getDocument(e.id),this.logger.debug("Updating document Id : "+e.id),this.ekgDocument=new EkgDocument(e,this.logger),this.ekgApi.initDocBuilder(this.ekgDocument);await this.ekgApi.initAdapter(e.id,o,!0),await this.ekgDocument.updateDbCollectionAndEKGDoc(t);return this.ekgDocument},GrafoClient.prototype.deleteEkgDocument=function(e){return this.deleteDocument(e)},GrafoClient.prototype.getSharedDocumentsWithMe=async function(e){var t=await this.documentApi.listSharedWithMeDocuments(e);this.documents=[];for(var o=0;o<t.documents.length;o++)this.documents.push(new Document(t.documents[o]));return this.documents},GrafoClient.prototype.getSharedDocumentWithMe=async function(e){var t=await this.documentApi.getSharedWithMeDocById(e);return this.sharedDocument=new Document(t),this.sharedDocument},GrafoClient.prototype.getFolders=async function(e){var t=await this.documentApi.listFolders(e);this.folders=[];for(var o=0;o<t.folders.length;o++)this.folders.push(new Folder(t.folders[o]));return this.folders},GrafoClient.prototype.getFolder=async function(e){var t=await this.documentApi.getFolder(e);return this.folder=new Folder(t),this.folder},GrafoClient.prototype.createFolder=async function(e){var t=await this.documentApi.createFolder(e);return this.folder=new Folder(t),this.folder},GrafoClient.prototype.updateFolder=async function(e){var t=await this.documentApi.updateFolder(e);return this.folder=new Folder(t),this.folder},GrafoClient.prototype.deleteFolder=async function(e){return this.deletedFolder=await this.documentApi.deleteFolder(e),this.deletedFolder},GrafoClient.prototype.getShareFolders=async function(e){var t=await this.documentApi.listSharedWithMeFolders(e);this.folders=[];for(var o=0;o<t.folders.length;o++)this.folders.push(new Folder(t.folders[o]));return this.folders},GrafoClient.prototype.getShareFolder=async function(e){var t=await this.documentApi.getShareFolder(e);return this.folder=new Folder(t),this.folder},GrafoClient.prototype.createShareFolder=async function(e){var t=await this.documentApi.createShareFolder(e);return this.folder=new Folder(t),this.folder},GrafoClient.prototype.updateShareFolder=async function(e){var t=await this.documentApi.updateShareFolder(e);return this.folder=new Folder(t),this.folder},GrafoClient.prototype.getDocumentShares=async function(e){var t=await this.documentApi.listDocumentShare(e);this.docShares=[];for(var o=0;o<t.length;o++){var i=new DocumentShare(t[o]);this.docShares.push(i)}return this.docShares},GrafoClient.prototype.getDocumentShare=async function(e,t){var o=await this.documentApi.getDocumentShare(e,t);return this.docShare=new DocumentShare(o),this.docShare},GrafoClient.prototype.createDocumentShare=async function(e,t){var o=await this.documentApi.createDocumentShare(e,t);this.docShare=[];for(var i=0;i<o.length;i++){var n=new DocumentShare(o[i]);this.docShare.push(n)}return this.docShare},GrafoClient.prototype.updateDocumentShare=async function(e){var t=await this.documentApi.updateDocumentShare(e);this.docShare=[];for(var o=0;o<t.length;o++){var i=new DocumentShare(t[o]);this.docShare.push(i)}return this.docShare},GrafoClient.prototype.deleteDocumentShare=async function(e,t){return this.deletedDocShare=await this.documentApi.deleteDocumentShare(e,t),this.deletedDocShare},GrafoClient.prototype.getConceptByName=function(e){return this.ekgApi.getConceptByName(e)},GrafoClient.prototype.getAttributeByName=function(e){return this.ekgApi.getAttribute(e)},GrafoClient.prototype.createLink=function(e){return this.ekgApi.createLink(e)},GrafoClient.prototype.addComment=function(e,t,o,i){if(void 0===this.conversationApi){if(null==this.ekgApi)throw new Error("Cannot add comment without referencing a documentEkg. Call createDocument or getDocument first");this.conversationApi=this.ekgApi.getConversationApi()}return this.conversationApi.addComment(e,t,o,i)},GrafoClient.prototype.getConversations=function(e,t){return new Promise((o,i)=>{return new ConversationApi("",this.config,this.sessionCookie).getConversationsByNode(e,t,this.userProfile.id).then(function(e){this.logger.debug("data**"),this.logger.debug(e),o(e)}).catch(function(e){i(e)})})},GrafoClient.prototype.getComments=async function(e){var t=await this.commentApi.listComments(e);this.comments=[];for(var o=0;o<t.comments.length;o++){var i=new Comment(t.comments[o]);this.comments.push(i)}return this.comments},GrafoClient.prototype.getReplies=async function(e){var t=await this.commentApi.listReplies(e);this.replies=[];for(var o=0;o<t.replies.length;o++){var i=new Reply(t.replies[o]);this.replies.push(i)}return this.replies},GrafoClient.prototype.close=async function(){await this.ekgApi.close()},console.log("***************************************"),console.log(" Grafo Client v1.0.0"),console.log(" © Copyright 2015-2019 Capsenta Inc."),console.log(" All rights reserved"),console.log(" See License for more information"),console.log("***************************************");