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
- Publishing gudhub lib to npm
- Initialization
- Utils
- App Processor
- Authentication
- Items Processor
- Field Processor
- File Processor
- Document Processor
- PipeService
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.
In order to publish new version of the GudHub Lib you have to:
- Change version in
package.json
- Commit your changes into repository to the
master
branch - Run
npm publish
command which will publish new version to npm
If you want to develop the GudHub Lib in another environment, say in GudHubClient, you need to do the following:
- You should go to the
gudhub
folder and run therenpm init @gudhub/core
command, it will install the @gudhub/core package in to your global environment - Then you have to add
@gudhub/core
to yourpackage.json
as a dependency. - Then package will be downloaded from your local computer after you run
npm run dev
ornpm install
command
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 |
With this method you can get json according to the scheme.
gudhub.jsonConstructor(scheme, item, variables)
Read more information about jsonConstructor on GudHub.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
This method is used when the user logs out of his/her account.
gudhub.logout(token);
Read more information about logout on GudHub.
This method is used to register a user account in GudHub.
gudhub.signup(user);
Read more information about signup on GudHub.
This method gets user from user list who have access to the application.
gudhub.getUserById(userId);
Read more information about getUserById on GudHub.
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.
This is the method used to update user account data.
gudhub.updateUser(userData);
Read more information about updateUser on GudHub.
This method is used to get the current token.
gudhub.getToken();
Read more information about getToken on GudHub.
This method is called when the token is updated.
gudhub.updateToken(auth_key)
Read more information about updateToken on GudHub.
This method is used when user changes his photo of the account.
gudhub.updateAvatar(imageData);
Read more information about updateAvatar on GudHub.
This method is used for getting needed user from the user list during sharing.
gudhub.getUserFromStorage(id);
Read more information about getUserFromStorage on GudHub.
This method allows you to add new user to the user list.
gudhub.saveUserToStorage(saveUser);
Read more information about saveUserToStorage on GudHub.
Use this method to to find out the current version of the GudHub.
gudhub.getVersion();
Read more information about getVersion on GudHub.
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.
Use this method to add new items to the items list.
await gudhub.addNewItems(app_id, itemsList);
Read more information about addNewItems on GudHub.
This method is used to update certain items.
await gudhub.updateItems(app_id, itemsList);
Read more information about updateItems on GudHub.
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.
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.
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.
The method is created for deleting field from the application.
await gudhub.deleteField(app_id, field_id);
Read more information about deleteField on GudHub.
This method is used for getting a list of field models.
await gudhub.getFieldModels(app_id);
Read more information about getFieldModels on GudHub.
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.
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.
This method is called to get file from the application.
gudhub.getFile(app_id, file_id);
Read more information about getFile on GudHub.
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.
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.
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.
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.
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.
This method is used to create the duplicate of the file.
await gudhub.duplicateFile(files)
Read more information about duplicateFile on GudHub.
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.
Due to this method files can be deleted from the application.
gudhub.deleteFile(app_id, file_id);
Read more information about deleteFile on GudHub.
This method is called for creating a new document in the certain application.
gudhub.createDocument(documentObject);
Read more information about createDocument on GudHub.
The method for getting needed document from the applications documents list.
gudhub.getDocument(documentAddress);
Read more information about getDocument on GudHub.
This method is called to get array of documents from the application.
gudhub.getDocuments(documentsAddresses);
Read more information about getDocuments on GudHub.
Due to this method you can delete document from the application.
gudhub.deleteDocumentApi(documentAddress);
Read more information about deleteDocument on GudHub.
This is the method that is called for getting subscription.
gudhub.on(event, address, myFunction);
Read more information about On on GudHub.
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.
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.