blue-terminal-api-lib v2.0.2
What is this?
This library is an abstraction for terminal-api usage.
It exposes certain functions to interact with the api
Install:
npm install --save blue-terminal-api-lib
Usage:
Code
const terminalInstanceCreator = require("blue-terminal-api-lib");
const terminalInstance = terminalInstanceCreator({...options});
const foldersFunctions = terminalInstance.folders;
const downloadsFunctions = terminalInstance.downloads;
const uploadsFunctions = terminalInstance.uploads;
// now you can use all functions.
Options
terminalUrl: (critical!) url to terminal api - example:
http://terminal-api/api/v1
- default =http://localhost:8100
apiKey: (critical!) full apiKey to authenticate terminal api with as a specific service - default:
'key'
useBearer: set to false to not use
'Bearer'
keyword in Authorization header of api request - default:true
foldersEndpoint: the url endpoint for accessing the "folders" resource - default:
/static/folders
uploadEndpoint: the url endpoint for accessing the "upload" resource - default:
/static/upload
downloadEndpoint: the url endpoint for accessing the "download" resource - default:
/static/download
fileIdAccessString: the (string) property name of the "id" attribute in the returned File object ( when accessing files ) - default:
id
Functions:
- All functions return a promise that resolves as an object such as the following:
{
status: Number,
message: String,
data: Object
}
- example:
const getDataFromFunction = async () => {
const {status, message, data} = await terminalInstance.folderOrUploadOrDownload.someFunction();
return data;
}
Folder Functions:
- createFolder:
/**
* recieve folder metadata and creates new folder in terminal-api
* @param {String} title - folder title
* @param {String} sourceNetwork - source network
* @param {String} destinationNetwork - destination network
* @param {[String]} to - array of user id's to send file to
* @param {String} from - file senders user id
* @returns {Object} - folder object from terminal-api
*/
function createFolder(title, sourceNetwork, destinationNetwork, to, from)
- getAll:
/**
* gets all folders from terminal api
* @returns {Object} - folder objects from terminal
*/
function getAll()
- getAllByType:
/**
* gets all folders with given "type"
* @param {String} type - folder type
* @returns {[Object]} - terminal folder objects
*/
function getAllByType(type)
- getAllIncomingByServiceType:
/**
* gets all folders with given "service" attribute
* @param {String} type - folder service
* @returns {[Object]} - terminal folder objects
*/
function getAllIncomingByServiceType(service)
- getById:
/**
* gets a single folder with given id
* @param {String} folderId - given folder id
* @returns {Object} - folder object from terminal
*/
function getById(folderId)
- getFiles:
/**
* gets all files in folder by folder id
* @param {String} folderId - folder id
* @returns {[Object]} - arrray of file objects from terminal
*/
function getFiles(folderId)
- getFileFromFolder:
/**
* returns specific file from folder based on folder and file ids
* @param {String} folderId - folder id
* @param {String} fileId - file id
* @returns {Object} - file object from terminal
*/
function getFileFromFolder(folderId, fileId);
- sendFolder:
/**
* marks a folder as available for sending to other side
* @param {String} folderId
*/
function sendFolder(folderId)
- acknowlegeFolder:
/**
* marks an "incoming" folder as viewed and handled ( acknowleges it )
* @param {String} folderId
*/
function acknowlegeFolder(folderId)
Download Functions:
- downloadFolder:
/**
* returns a base64 string representing the folder (by id) with all its files in .zip format
* @param {String} folderId
*/
function downloadFolder(folderId)
- downloadFileFromFolder:
/**
* returns a base64 string representing the specific file in given file format
* @param {String} folderId
* @param {String} fileId
*/
function downloadFileFromFolder(folderId, fileId)
- downloadFileFromFolderAsStream:
/**
* returns a readable stream representing the specific file
* @param {String} folderId
* @param {String} fileId
*/
function downloadFileFromFolderAsStream(folderId, fileId)
Upload Functions:
- uploadFileToFolder:
/**
* uploads a file to folder with given metadata
* @param {String} folderId - existing folder if
* @param {String} fileName - name to give to file
* @param {String} content - base64 string representing the file
* @param {String} relativePath - (optional) relative path to save in metadata
*/
function uploadFileToFolder(folderId, fileName, content, relativePath = '/tmp')
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago