@appveen/ds-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.3.4 • Public • Published

ds-sdk

The Official SDK for Data.Stack

Setup

npm i --save @appveen/ds-sdk
const  SDK = require('@appveen/ds-sdk');

Example 1

Authenticate using Credentials (Username/password)

const  SDK = require('@appveen/ds-sdk');

const  HOST = 'https://cloud.appveen.com';

const  USERNAME = 'johndoe@appveen.com';

const  PASSWORD = 'johndoehasapassword';

  

(async  function () {

try {

const  dataStack = await  SDK.authenticateByCredentials({

host:  HOST,

username:  USERNAME,

password:  PASSWORD,

});

  

const  app = await  dataStack.App('Adam');

const  dataService = await  app.DataService('Employee');

const  record = await  dataService.DataAPIs().GetRecord('EMP1001');

  

console.log(record);

} catch (e) {

console.error(e);

}

})();

Example 2

Authenticate using JWT Token

const  SDK = require('@appveen/ds-sdk');

const  HOST = 'https://cloud.appveen.com';

const  TOKEN = 'dgdoieruyiueyr794iryewyrye7rbyewr';

  

(async  function () {

try {

const  dataStack = await  SDK.authenticateByToken({

host:  HOST,

token:  TOKEN,

});

  

const  app = await  dataStack.App('Adam');

const  dataService = await  app.DataService('Employee');

const  record = await  dataService.DataAPIs().GetRecord('EMP1001');

  

console.log(record);

} catch (e) {

console.error(e);

}

})();

Example 3

Using Math API

const  SDK = require('@appveen/ds-sdk');

const  HOST = 'https://cloud.appveen.com';

const  USERNAME = 'johndoe@appveen.com';

const  PASSWORD = 'johndoehasapassword';

  

(async  function () {

try {

const  dataStack = await  SDK.authenticateByCredentials({

host:  HOST,

username:  USERNAME,

password:  PASSWORD,

});

  

const  app = await  dataStack.App('Adam');

const  dataService = await  app.DataService('Employee');

const  math = dataService.DataAPIs().PrepareMath();

math.SelectField('salary').Multiply(1.2); // Increment Salary by 20%

const  updatedRecord = await  dataService.DataAPIs().ApplyMath('EMP1001', math);

  

console.log(updatedRecord);

} catch (e) {

console.error(e);

}

})();

APIs

The SDK contains the following apis.


authenticateByCredentials(credentials)

Returns a Promise giving a DataStack object.

credentials

Type: Credentials

host

Type string

The FQDN of the application.

username

Type string

The Username of a user / Client ID of Bot.

password

Type string

The Password of a user / API key of Bot.

trace

Type boolean

If True it will log all SDK events. Default: false

logger

Type Logger

To pass a custom logger for logging events and errors


authenticateByToken(credentials)

Returns a Promise giving a DataStack object.

credentials

Type: Credentials

host

Type string

The FQDN of the application

token

Type string

The JWT token of a User / Bot

trace

Type boolean

If True it will log all SDK events. Default: false

logger

Type Logger

To pass a custom logger for logging events and errors


DataStack

The object contains utility methods to access DataStack.

Logout()

Returns a Void Promise.

App(name)

Returns a Promise giving a DSApp object.

name

Type: string

The name of the App

ListApps()

Returns a Promise giving a DSApp array.

CreateApp(name: string)

Returns a Promise giving a DSApp object.

name

Type: string

The name of the App

DeleteApp(name: string)

Returns a Promise giving the same DataStack object.

name

Type: string

The name of the App


DSApp

The object contains utility methods to access an App of Data Stack.

DataService(name)

Returns a Promise giving a DSDataService object.

name

Type: string

The name of the Data Service.

ListDataServices()

Returns a Promise giving a DSDataService array.

CreateDataService(name)

Returns a Promise giving a DSDataService object.

name

Type: string

The name/id of the Data Service to be Created.

TransactionAPI()

Returns an TransactionMethods object to do Transaction.

StartAllDataServices(filter)

filter

Type: object

Filter to select fewer DS.

Returns a Promise giving the same DSApp object, else will throw an ErrorResponse object.

This will start all the Data Service in the app, if not already stopped.

StopAllDataServices(filter)

filter

Type: object

Filter to select fewer DS.

Returns a Promise giving the same DSApp object, else will throw an ErrorResponse object.

This will stop all the Data Service in the app, if not already stopped.


DSDataService

The object contains utility methods to manage a Data Service.

HasDraft()

Returns an boolean value.

IsDraft()

Returns an boolean value.

SwitchToDraft()

Returns the same DSDataService object.

SwitchToOriginal()

Returns the same DSDataService object.

DiscardDraft()

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

This will discard the draft version of this Data Service.

purgeAllData()

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

This will Delete all data, API logs and audit logs of this Data Service.

PurgeApiLogs()

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

This will Delete all API logs of this Data Service.

PurgeAuditLogs()

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

This will Delete all audit logs of this Data Service.

Delete()

Returns an DSApp object.

This will delete the selected Data Service.

DataAPIs()

Returns an DataMethods object to do Data operations that Data Service.

Start()

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

This will start the Data Service if not already running.

Stop()

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

This will stop the Data Service if not already stopped.

Repair()

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

This will re-deploy the Data Service in the infra layer by re-creating it's service and deployment.

getIntegrations()

Returns an DSDataServiceIntegration object to do manage integrations of Data Service.

setIntegrations(data)

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

data

Type: DSDataServiceIntegration

After making changes to the returned object by getIntegrations() method set that object here in order for the change to be applied.

getRoles()

Returns an DSDataServiceRole object to do manage Roles of Data Service.

setRoles(data)

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

data

Type: DSDataServiceRole

After making changes to the returned object by getRoles() method set that object here in order for the change to be applied.

getSchema()

Returns an DSDataServiceSchema object to do manage Schema of Data Service.

setSchema(data)

Returns a Promise giving the same DSDataService object if the operation is success, else will throw an ErrorResponse object.

data

Type: DSDataServiceSchema

After making changes to the returned object by getSchema() method set that object here in order for the change to be applied.


DataMethods

This Object contains methods to manage data of a Data Service.

NewDocument(data?: any): DataStackDocument

Returns a DataStackDocument object Wrapper Object with useful methods.

CountRecords(filter: object)

Returns a Promise giving a number if the operation is success, else will throw an ErrorResponse object.

filter

Type: object The filter get proper count.

ListRecords(options: ListOptions)

Returns a Promise giving a DataStackDocument array if the operation is success, else will throw an ErrorResponse object.

options

Type: ListOptions The options to list records.

GetRecord(id: string)

Returns a Promise giving a DataStackDocument object if the operation is success, else will throw an ErrorResponse object.

id

Type: string The ID of the record.

UpdateRecord(id: string, data: object, options: APIOptions)

Returns a Promise giving a DataStackDocument object if the operation is success, else will throw an ErrorResponse object.

id

Type: string The ID of the record.

data

Type: object The data the should to be updated.

options

Type: APIOptions Options like expireAt & expireAfter.

UpsertRecord(id: string, data: object, options: APIOptions)

Returns a Promise giving a DataStackDocument object if the operation is success, else will throw an ErrorResponse object.

id

Type: string The ID of the record.

data

Type: object The data the should to be updated.

options

Type: APIOptions Options like expireAt & expireAfter.

CreateRecord(data: object, options: APIOptions)

Returns a Promise giving a DataStackDocument object if the operation is success, else will throw an ErrorResponse object.

data

Type: object The data the should to be created.

options

Type: APIOptions Options like expireAt & expireAfter.

DeleteRecord(id: string)

Returns a Promise giving a message:string if the operation is success, else will throw an ErrorResponse object.

id

Type: string The ID of the record.

PrepareMath()

Returns a MathAPI object to set math operations.

ApplyMath(id: string, math: MathAPI)

Returns a Promise giving a DataStackDocument object if the operation is success, else will throw an ErrorResponse object.

id

Type: string The ID of the record.

math

Type: MathAPI The Math Object that has the operations.

UploadFileFromPath(filePath: string): Promise<FileUploadResponse>

Returns a Promise giving a FileUploadResponse object if the operation is success, else will throw an ErrorResponse object.

filePath

Type: string The file path to upload.

UploadFileAsStream(data: any): Promise<FileUploadResponse>

Returns a Promise giving a FileUploadResponse object if the operation is success, else will throw an ErrorResponse object.

data

Type: stream The file readable stream.


TransactionMethods

This Object contains methods to consume Transactions API.

CreateOperation(dataService: string, data:DataStackDocument): TransactionMethods

Returns a TransactionMethods object Wrapper Object with useful methods.

dataService

Type: string The name of Data Service.

data

Type: object The Data to be created.

UpdateOperation(dataService: string, data:DataStackDocument): TransactionMethods

Returns a TransactionMethods object Wrapper Object with useful methods.

dataService

Type: string The name of Data Service.

data

Type: object The Data to be updated with _id.

DeleteOperation(dataService: string, data:DataStackDocument): TransactionMethods

Returns a TransactionMethods object Wrapper Object with useful methods.

dataService

Type: string The name of Data Service.

data

Type: object The Data Object containing _id of the document to be deleted.

Execute()

Returns a Promise giving a DataStackDocument object if the operation is success, else will throw an ErrorResponse object.


MathAPI

SelectField(path: string): MathAPI;

Selects the field to apply math operation.

Returns the same MathAPI Object to continue API chaning.

path

Type: string

Path of the Field.

Increment(num: number): MathAPI;

Increment the value to the selected field.

Returns the same MathAPI Object to continue API chaning.

num

Type: number

The value to increment. Give negative values to decrement.

Multiply(num: number): MathAPI;

Multiply the value to the selected field.

Returns the same MathAPI Object to continue API chaning.

num

Type: number

The value to multiply.


DSDataServiceIntegration

listPreHook(): WebHook[]

Returns a WebHook array or empty [] if not hooks present.

getPreHook(name: string): WebHook | undefined

Returns a WebHook Object or undefined if not found.

name

Type: string

The Name of the hook that is needed.

addPreHook(data: WebHook): DSDataServiceIntegration

Returns a DSDataServiceIntegration Object for chaning of apis.

data

Type: WebHook

removePreHook(name: string): DSDataServiceIntegration

Returns a DSDataServiceIntegration Object for chaning of apis.

name

Type: string

The Name of the hook that needs to be removed.

listPostHook(): WebHook[]

Returns a WebHook array or empty [] if not hooks present.

getPostHook(name: string): WebHook | undefined

Returns a WebHook Object or undefined if not found.

name

Type: string

The Name of the hook that is needed.

addPostHook(data: WebHook): DSDataServiceIntegration

Returns a DSDataServiceIntegration Object for chaning of apis.

data

Type: WebHook

removePostHook(name: string): DSDataServiceIntegration

Returns a DSDataServiceIntegration Object for chaning of apis.

name

Type: string

The Name of the hook that needs to be removed.


DSDataServiceRole

listRoles(): RoleBlock[]

Returns RoleBlock array

getRole(name: string): RoleBlock | undefined

Returns RoleBlock object or undefined if no roles found.

name

Type: string

The Name of the role that is needed.

createNewRole(name: string, description?: string): RoleBlock

Returns a new RoleBlock object that should be used to add more roles.

name

Type: string

The Name of the new role.

addRole(data: RoleBlock): DSDataServiceRole

Returns DSDataServiceRole object to continue api chaning.

data

Type: RoleBlock

The RoleBlock Object that was returned by createNewRole() method.

removeRole(name: string): DSDataServiceRole

Returns DSDataServiceRole object to continue api chaning.

name

Type: string

The Name of the role that needs to be removed.


DSDataServiceSchema


RoleBlock

The Object used by Roles.

setName(name: string): void

This Method sets Name of the Role.

Returns RoleBlock object to continue api chaning.

setDescription(description?: string): void

This Method sets Description of the Role.

Returns RoleBlock object to continue api chaning.

enableCreate(): RoleBlock

This Method Enables Create Permission in the Role.

Returns RoleBlock object to continue api chaning.

disableCreate(): RoleBlock

This Method Disables Create Permission in the Role.

Returns RoleBlock object to continue api chaning.

enableEdit(): RoleBlock

This Method Enables Edit Permission in the Role.

Returns RoleBlock object to continue api chaning.

disableEdit(): RoleBlock

This Method Disables Edit Permission in the Role.

Returns RoleBlock object to continue api chaning.

enableDelete(): RoleBlock

This Method Enables Delete Permission in the Role.

Returns RoleBlock object to continue api chaning.

disableDelete(): RoleBlock

This Method Disables Delete Permission in the Role.

Returns RoleBlock object to continue api chaning.

enableReview(): RoleBlock

This Method Enables Review Permission in the Role.

Returns RoleBlock object to continue api chaning.

disableReview(): RoleBlock

This Method Disables Review Permission in the Role.

Returns RoleBlock object to continue api chaning.

enableSkipReview(): RoleBlock

This Method Enables Skip Review Permission in the Role.

Returns RoleBlock object to continue api chaning.

disableSkipReview(): RoleBlock

This RoleBlock Disables Skip Review RoleBlock in the Role.

Returns RoleBlock object to continue api chaning.


ListOptions

select: string

To show only selected fields in records.

sort: string

To set the sorting order of records.

page: number

For pagination.

count: number

To Limit the no of records.

filter: object

To filter the records.

expand: boolean

To expand the docs if contains relation.


WebHook

The Object used by pre-hooks and post-hooks.

name

Type: string

A unique name of the hook.

url

Type: string

A URL of the Web-Hook.

failMessage

Type: string

Optional error message to show, when the hook URL is down.


FileUploadResponse

The object is return when a file is uploaded.

_id

Type: string

length

Type: number

chunkSize

Type: number

uploadDate

Type: string

filename

Type: string

md5

Type: string

contentType

Type: string

metadata

Type: object

filename

Type: string


ErrorResponse

The object is return whenever some error occurs.

statusCode

Type: number

The status code returned by the application.

body

Type: object

The response body send by the application in case if error.

message

Type: string

The error message if the error occured in the SDK.


ENV Variables

The Credentials/Token can also be set via ENV.

| ENV Variables | Description |

| ----------------------- | -------------------------------- |

| DATA_STACK_HOST | The FQDN of Data Stack |

| DATA_STACK_USERNAME | Username / Client ID of Bot |

| DATA_STACK_PASSWORD | User's Password / API Key of Bot |

| DATA_STACK_TOKEN | The existing JWT token |

Readme

Keywords

none

Package Sidebar

Install

npm i @appveen/ds-sdk

Weekly Downloads

10

Version

2.3.4

License

MIT

Unpacked Size

146 kB

Total Files

16

Last publish

Collaborators

  • appveen