@gudhub/core

1.2.4-beta.10 • Public • Published

GudHub logo

npm version npm version

npm version npm downloads

GUDHUB

I't a Library to simplify work with GudHub API. Also this Library contains utilities for better operation with items, fields and apps!

npm Package

The package name is @gudhub/core. This is a private package, so the .npmrc file must be in the root folder in order to load it from npm. This means that if you have @gudhub/core in package.json for GudHubClient, the .npmrc file should be in the root folder too.

Publishing gudhub lib to npm

In order to publish new version of the GudHub Lib you have to:

  1. Change version in package.json
  2. Commit your changes into repository to the master branch
  3. Run npm publish command which will publish new version to npm

Development gudhub lib

If you want to develop the GudHub Lib in another environment, say in GudHubClient, you need to do the following:

  1. You should go to the gudhub folder and run there npm init @gudhub/core command, it will install the @gudhub/core package in to your global environment
  2. Then you have to add @gudhub/core to your package.json as a dependency.
  3. Then package will be downloaded from your local computer after you run npm run dev or npm install command

Initialization

There are several ways to initialize GudHub. The most simple way is initializing gudhub without arguments. In this case only the utils will be available.

import {GudHub} from '@gudhub/core';
const gudhub = new GudHub();

The second way is initialization GudHub with authorization key. It's the most common way for using GudHub in your project. You just need to pass auth_key as argument. In this case you will be able to work with GudHub data and use all the methods listed below.

import {GudHub} from '@gudhub/core';
const auth_key = 'JLKHKJSKJhkjsclkdjcijIOIoiuSTg';
const gudhub = new GudHub(auth_key);

The third way is initialization GudHub with additional parameters. It's useful for development server app on Node.js and for testing on local server. In the example below you can see how to initialize GudHub (in the example you can see default params).

import {GudHub} from '@gudhub/core';
const auth_key = 'JLKHKJSKJhkjsclkdjcijIOIoiuSTg';
const gudhub = new GudHub(auth_key,{
    server_url : "https://gudhub.com/GudHub", 
    wss_url : "wss://gudhub.com/GudHub/ws/app/", 
    initWebsocket : false
});
Param Name Description Default Value
server_url All request will send to this url https://gudhub.com/GudHub
wss_url url to setup websoket connection wss://gudhub.com/GudHub/ws/app/
initWebsocket here we can turn off websoket connection false

Utils

jsonConstructor()

With this method you can get json according to the scheme.

gudhub.jsonConstructor(scheme, item, variables)

Read more information about jsonConstructor on GudHub.

jsonToItems()

This method converts json to gudhub items. The conversion is made based on fieldMap. After generating items, you can send them to create new items.

gudhub.jsonToItems(json, fieldsMap);

Read more information about jsonConstructor on GudHub.

populateWithItemRef()

This method updates destination items with item_ref of source items. The connection between sorceItemsRef & srcFieldIdToCompare is checked with srcFieldIdToCompare & destFieldIdToCompare. After connection is detected we save the item_ref into destFieldForRef.

gudhub.populateWithItemRef(sorceItemsRef, srcFieldIdToCompare, destinationItems, destFieldIdToCompare, destFieldForRef, APPID)

Read more information about populateWithItemRef on GudHub.

mergeItems()

The current method replaces all fields with values in destinationItems by values from sorceItems. If destinationItems does not have the fields that sorceItems has, they will be created in destinationItems.

gudhub.mergeItems(sorceItems, destinationItems, mergeByFieldId);

Read more information about mergeItems on GudHub.

compareItems()

This method compare fields of sorceItems with fields of destinationItems. This means that if sorceItems has the same fields with the same values as destinationItems, they will be described as 'same_items' even if destinationItems has additional fields that sorceItems does not have.

gudhub.compareItems(sorceItems, destinationItems, fieldToCompare);

Read more information about compareItems on GudHub.

getDate()

This method will return a date according to specified namespace. The name space should be in string format

gudhub.getDate(date_type);

Read more information about getDate on GudHub.

makeNestedList()

This method creates the list of fields with infinite nesting. It takes an array of fields and depends of their IDs makes attachments for each of them.

gudhub.makeNestedList(arr, 'id', 'parent_id', 'children_property', 'priority')

Read more information about makeNestedList on GudHub.

App Processor

getAppInfo()

This is the method that returns application with empty arrays: field_list, items_list, file_list, views_list. Such simple data needed to render App Icons, and do some simple updates in App like: updating App name icon permissions etc when full app data is not needed

gudhub.getAppInfo(app_id);

Read more information about getAppInfo on GudHub.

getApp()

This method is called to get an application by its ID specified as an argument.

gudhub.getApp(app_id);

Read more information about getApp on GudHub.

getAppsList()

This method is called after logging in to get a list of user`s applications. It has no arguments. getAppList return list of applications that are shared to users.

gudhub.getAppsList();

Read more information about getApp on GudHub.

Authentication

login()

This method is used for getting access to the account. It can be called with login and password or the authentication key with or without additional parameters.

gudhub.login(data);

Read more information about login on GudHub.

logout()

This method is used when the user logs out of his/her account.

gudhub.logout(token);

Read more information about logout on GudHub.

signup()

This method is used to register a user account in GudHub.

gudhub.signup(user);

Read more information about signup on GudHub.

getUserById()

This method gets user from user list who have access to the application.

gudhub.getUserById(userId);

Read more information about getUserById on GudHub.

getUsersList()

This method is called during the search for users to share. Namely, when you enter a keyword into the search box, GudHub displays all users whose names match that word.

gudhub.getUsersList(keyword);

Read more information about getUsersList on GudHub.

updateUser()

This is the method used to update user account data.

gudhub.updateUser(userData);

Read more information about updateUser on GudHub.

getToken()

This method is used to get the current token.

gudhub.getToken();

Read more information about getToken on GudHub.

updateToken()

This method is called when the token is updated.

gudhub.updateToken(auth_key)

Read more information about updateToken on GudHub.

updateAvatar()

This method is used when user changes his photo of the account.

gudhub.updateAvatar(imageData);

Read more information about updateAvatar on GudHub.

getUserFromStorage()

This method is used for getting needed user from the user list during sharing.

gudhub.getUserFromStorage(id);

Read more information about getUserFromStorage on GudHub.

saveUserToStorage()

This method allows you to add new user to the user list.

gudhub.saveUserToStorage(saveUser);

Read more information about saveUserToStorage on GudHub.

getVersion()

Use this method to to find out the current version of the GudHub.

gudhub.getVersion();

Read more information about getVersion on GudHub.

Items Processor

getItems()

This method is used to get the items of the current application.

await gudhub.getItems(app_id, trash);

Read more information about getItems on GudHub.

addNewItems()

Use this method to add new items to the items list.

await gudhub.addNewItems(app_id, itemsList);

Read more information about addNewItems on GudHub.

updateItems()

This method is used to update certain items.

await gudhub.updateItems(app_id, itemsList);

Read more information about updateItems on GudHub.

deleteItems()

Due to this method you can delete one and more items from thee application.

await gudhub.deleteItems(app_id, itemsIds);

Read more information about deleteItems on GudHub.

Field Processor

getField()

Due to this method you can get field from the relevant application.

await gudhub.getField(app_id, field_id);

Read more information about getField on GudHub.

updateField()

This method allows you to update field model of the current application.

await gudhub.updateField(app_id, fieldModel);

Read more information about updateField on GudHub.

deleteField()

The method is created for deleting field from the application.

await gudhub.deleteField(app_id, field_id);

Read more information about deleteField on GudHub.

getFieldModels()

This method is used for getting a list of field models.

await gudhub.getFieldModels(app_id);

Read more information about getFieldModels on GudHub.

getFieldValue()

This method is responsible for getting the value from the desired field.

await gudhub.getFieldValue(app_id, item_id, field_id);

Read more information about getFieldValue on GudHub.

setFieldValue()

This method is called to set value in the desired field.

await gudhub.setFieldValue(app_id, item_id, field_id, field_value);

Read more information about setFieldValue on GudHub.

File Processor

getFile()

This method is called to get file from the application.

gudhub.getFile(app_id, file_id);

Read more information about getFile on GudHub.

getFiles()

This method is called for getting a list of files from current application.

gudhub.getFiles(app_id, filesId);

Read more information about getFiles on GudHub.

uploadFile()

The current method allows to upload files. It transfers the file through the form.

await gudhub.uploadFile(fileData, app_id, file_id)

Read more information about uploadFile on GudHub.

uploadFileFromString()

This is the method that allows to upload different files in base64 format to the application.

await gudhub.uploadFileFromString(fileObject);

Read more information about uploadFileFromString on GudHub.

isFileExists()

Due to this method you can check whether the file with the following ID exists in such an application.

await gudhub.isFileExists(app_id, file_id)

Read more information about isFileExists on GudHub.

updateFileFromString()

The current method allows to update the data and name of the certain file.

await gudhub.updateFileFromString(data, file_id, file_name, extension, format)

Read more information about updateFileFromString on GudHub.

duplicateFile()

This method is used to create the duplicate of the file.

await gudhub.duplicateFile(files)

Read more information about duplicateFile on GudHub.

downloadFileFromString()

Use this method to download the file from the fil list.

await gudhub.downloadFileFromString(app_id,file_id)

Read more information about downloadFileFromString on GudHub.

deleteFile()

Due to this method files can be deleted from the application.

gudhub.deleteFile(app_id, file_id);

Read more information about deleteFile on GudHub.

Document Processor

createDocument()

This method is called for creating a new document in the certain application.

gudhub.createDocument(documentObject);

Read more information about createDocument on GudHub.

getDocument()

The method for getting needed document from the applications documents list.

gudhub.getDocument(documentAddress);

Read more information about getDocument on GudHub.

getDocuments()

This method is called to get array of documents from the application.

gudhub.getDocuments(documentsAddresses);

Read more information about getDocuments on GudHub.

deleteDocument()

Due to this method you can delete document from the application.

gudhub.deleteDocumentApi(documentAddress);

Read more information about deleteDocument on GudHub.

PipeService

on()

This is the method that is called for getting subscription.

gudhub.on(event, address, myFunction);

Read more information about On on GudHub.

emit()

This is the method that is used by GudHub itself. It is called for getting existing subscription.

gudhub.on(event, address, myFunction);

Read more information about Emit on GudHub.

destroy()

This method exists for ruining extra subscriptions and for optimization the process.

gudhub.destroy('gh_app_views_update', address, myFunction);

Read more information about Destroy on GudHub.

Readme

Keywords

none

Package Sidebar

Install

npm i @gudhub/core

Weekly Downloads

206

Version

1.2.4-beta.10

License

ISC

Unpacked Size

9.43 MB

Total Files

128

Last publish

Collaborators

  • gudhub