Web modeler SDK

The web modeler SDK is available in the web modeler, It allows users access resources from user interface and execute complexe computational in the user interface run time.

The SDK has the following classes

class SoftyFlow {}
class Collection {}
class SQLDatabase {}
class CustomList {}
class Report {}
class Instance {}
class Task {}
class Api {}
class Email {}
class File {}

In the following sections we will explicit each class and the allowed methods.

1 - SoftyFlow#


The SoftyFlow class has the SoftyFlow system methods

Usage#

This class is instantiated by default as object named SF when the user interface is loaded, so you can use methods directly by calling them via object "SF"

//using SF object
let currentMode = this.SF.getSF_mode();
// instantiate new object
const softyflow = new SoftyFlow();

getSF_mode#

Description#

Is a function that return the mode of the running user interface

/**
* @return {string} Return string ('test', 'uat', 'prod')
*/

Examples#

let currentMode = this.SF.getSF_mode();

getSF_Version#

Description#

Is a function that return the version of the running user interface

/**
* @return {string} Return string ('test', 'uat', 'prod')
*/

Examples#

let currentVersion = this.SF.getSF_Version();

queryParams#

Description#

Is a function that return the query parameters

paramsDescription
selectoptional. The fields to select (fields: SF_mode, SF_version, SF_screen)
/**
* @param {string} select The selected fields
*
* @return {string} Return string
*/

Examples#

let currentMode = this.SF.getSF_mode('SF_mode SF_version');
console.log(currentMode)
// ?SF_mode=test&SF_version=versionId

startProcess#

Description#

Is a function that start specific process

/**
*@param {string} id Process id
*@param {object} body Json of process variables
*
* @return {promise} Return promise
*/

Examples#

let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await this.SF.startProcess('processId', variables);

saveNew#

Description#

Is a function that allow to you to save the user interface state

/**
*@param {string} id interface id
*@param {object} body Json of interface variables
*
* @return {promise} Return promise
*/

Examples#

let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await this.SF.saveNew('interfaceId', variables);

saveTask#

Description#

Is a function that allow to you to save the task interface state

/**
*@param {string} id task id
*@param {object} body Json of task variables
*
* @return {promise} Return promise
*/

Examples#

let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await this.SF.saveTask('taskId', variables);

validateTask#

Description#

Is a function that allow to validate Task

/**
*@param {string} id task id
*@param {object} body Json of task variables
*
* @return {promise} Return promise
*/

Examples#

let variables = {
"variable1": "value1",
"variable2": 1,
"variable3": true
}
await this.SF.validateTask('taskId', variables);

getUserPendingTask#

Description#

Is a function that allow to get pending Task assigned to connected user.

/**
*@param {string} limit limit of result per page.
*@param {string} page number of page
*@param {string} dueDate related date.
*@param {string} fields fileds.
*
* @return {promise} Return promise
*/

Examples#

await this.SF.getUserPendingTask('limit', 'page', 'dueDate', 'fields');

setListFromCollection#

Description#

Is a function that allow to set list of data from a specific collection.

/**
*@param {string} collection collection ID.
*@param {object} criteria Query json.
*@param {string} limit limit of result.
*@param {string} sort sort option.
*
* @return {promise} Return promise
*/

Examples#

let criteria = {
firstName: new RegExp("p", "i")
}
await this.SF.setListFromCollection('collectionId', criteria, 10, 'sort');

setListFromSQL#

Description#

Is a function that allow to set list of data from client database.

/**
*@param {string} clientDatabase clientDatabase ID.
*@param {string} query Query table.
*
* @return {promise} Return promise
*/

Examples#

await this.SF.setListFromSQL('clientDatabaseID', "code='MMA'");

setListFromCustomList#

Description#

Is a function that allow to set list of data from CustomList.

/**
*@param {string} CustomList CustomList ID.
*
* @return {promise} Return promise
*/

Examples#

await this.SF.setListFromCustomList('CustomListID');

aggregateQuery#

Description#

Is a function that allow to set list of data from CustomList.

/**
*@param {string} type type of the resource (collection, report, users, projects, external databases).
*@param {string} id Id of the resource.
*@param {object} query Json of a value to be matched in the resource.
*
* @return {promise} Return promise
*/

Examples#

await this.SF.aggregateQuery('collection', '610c0343f6ebc7ddcb49cc3b', {value : "it"});

deleteFile#

Description#

Is a function that allow to delete a file using it ID.

/**
*@param {string} id Id of the resource.
*
* @return {promise} Return promise
*/

Examples#

await this.SF.deleteFile('610c0343f6ebc7ddcb49cc3b');

2 - Users#


The Users class has the methods that will allow you to manage the users.

Usage#

const users = new Users();

create#

Description#

Allow to create new user.

/**
* @param {object} data Json content user data
*
* @return {promise} Return promise
*/

Data#

This is the allowed user data:

fieldDescription
emailRequired and Unique. The user email (string)
lastNameRequired. The user last name (string)
firstNameRequired. The user first name (string)
groupRequired. The user groups ids (array)
metadataoptional. The user metadata (json)
ideAccessRequired. IDE access right (boolean)
blockedoptional. User blocking (boolean)

Examples#

let user = {
email: "email@softydev.com",
lastName : "last name",
firstName: "first name",
group: [],
metadata: {},
ideAccess: true,
blocked: false
}
await users.create(user);

update#

Description#

Allow to update a user

/**
* @param {string} id user id.
* @param {object} data User data.
*
* @return {promise} Return promise
*/

Data#

The same allowed data in creation of user. The fields are optional.

Examples#

let newData = {
ideAccess: false
}
await users.update("userId", newData);

delete#

Description#

Allow to delete a user.

/**
* @param {string} id user id.
*
* @return {promise} Return promise
*/

Examples#

await users.delete("userId");

findById#

Description#

Allow to get a user by id.

/**
* @param {string} id user id.
*
* @return {promise} Return promise
*/

Examples#

let user = await users.findById("userId");

find#

Description#

Allow to list the users.

/**
* @param {object} criteria Query json.
*
* @return {promise} Return promise
*/

Examples#

let criteria = {
firstName: new RegExp("p", "i")
}
let usersList = await users.find(criteria);

count#

Description#

Allow to get the count of users.

/**
* @param {object} criteria Query json
*
* @return {promise} Return promise
*/

Examples#

let criteria = {
blocked: false
}
let count = await users.count(criteria);

findAndCount#

Description#

get a list and the count of users

/**
* @param {object} body Json of options.
*
* @return {promise} Return promise
*/

Options#

This options are optional

OptionDescription
criteriaSpecifies selection filter (default : {})
fieldsSelect specific fields (example: "createdAt email")
limitNumber of instances returned (default : 100/ no limit : 0)
pagePage number depends on the limit (default : 0)
sortbySorts the results by key (default : createdAt)
directionAscending (1) or descending (-1) order (default : -1)

Examples#

let body = {
criteria: {
firstName: new RegExp("p", "i")
},
limit: 10,
page: 0,
sortBy: "createdAt",
direction: -1
}
let res = await users.findAndCount(body);
let usersList = res.data;
let count = res.count;

aggregate#

Description#

Aggregation operations process data records and return computed results

/**
* @param {array} aggregation aggregation array
*
* @return {promise} Return promise
*/

Examples#

let aggregation = [
{
"$match": { "firstName": new RegExp("z", "i") }
},
{
"$project" : {
"_id": 1,
"firstName": 1,
"lastName": 1,
"email": 1
}
}
]
let usersList = await users.aggregate([aggregation]);

addRole#

Description#

Add role to user using user ID & group ID.

/**
* @param {string} userId user ID.
*
* @param {string} groupid group ID.
*
* @param {string} mode mode of the running user. interface
*
* @return {promise} Return promise
*/

Examples#

await users.addRole("userId","groupId","SF_mode");

removeRole#

Description#

Remove role from user using user ID & group ID.

/**
* @param {string} userId user ID.
*
* @param {string} groupid group ID.
*
* @param {string} mode mode of the running user interface
*
* @return {promise} Return promise
*/

Examples#

await users.removeRole("userId","groupId","SF_mode");

3 - Collection#


The collection class has the methods that will allow you to manage your collection

Usage#

You can instantiate a Collection class with id or name of collection. You can add mode option

OptionDescription
idRequired. id or name of collection
modeoptional. Specifies mode of collection (default : "test")
const collection = new Collection({ id: 'collectionId', mode: 'test' });

insert#

Description#

Allow to insert a json into a collection

/**
* @param {object} data Json of a value to be inserted in to the collection.
*
* @return {promise} Return promise
*/

Examples#

await collection.insert({ name: "name1", type : "type1" });

insertMany#

Description#

Allow to insert an array of json in to a collection.

/**
* @param {object} data Json of a value to be inserted in to the collection.
*
* @return {promise} Return promise
*/

Examples#

await collection.insertMany([{label : "IT", value : "it"}]);

updateMany#

Description#

update all the documents that satisfies the specified query criteria .

/**
* @param {object} criteria Query json.
* @param {object} data Json of a new data.
* @param {object} options Json of options
*
* @return {promise} Return promise
*/

Examples#

let criteria = {
firstName: new RegExp("p", "i")
}
await collection.updateMany(criteria, [{ type : "type2" }], { upsert: true });

update#

Description#

Allow to update a document in collection

/**
* @param {string} id Document id.
* @param {object} data Json of a new data.
*
* @return {promise} Return promise
*/

Examples#

await collection.update("documentId", { type : "type2" });

delete#

Description#

Allow to delete a document from collection

/**
* @param {string} id Document id.
*
* @return {promise} Return promise
*/

Examples#

await collection.delete("documentId");

findById#

Description#

Allow to get a object by id from the collection

/**
* @param {string} id Document id.
*
* @return {promise} Return promise
*/

Examples#

let document = await collection.findById(id);

find#

Description#

Allow to select the documents in a collection

/**
* @param {object} body Json of options.
*
* @return {promise} Return promise
*/

Options#

This options are optional

OptionDescription
criteriaSpecifies selection filter (default : {})
limitNumber of documents returned (default : 100/ no limit : 0)
pagePage number depends on the limit (default : 0)
sortbySorts the results by key (default : createdAt)
directionAscending (1) or descending (-1) order (default : -1)

Examples#

let body = {
criteria: {
name: new RegExp("p", "i"),
type: "type1"
},
limit: 10,
page: 0,
sortBy: "createdAt",
direction: -1
}
let documents = await collection.find(body);

count#

Description#

Allow to get the count of documents that would match a query for the collection

/**
* @param {object} criteria Query json
*
* @return {promise} Return promise
*/

Examples#

let count = await collection.count({ type: "type1" });

aggregate#

Description#

Aggregation operations process data records and return computed results

/**
* @param {array} aggregation aggregation array
*
* @return {promise} Return promise
*/

Examples#

let aggregation = [
{
"$match": { "type": "type1" }
},
{
"$project" : {
"_id": 1,
"name": 1
}
}
]
let documents = await collection.aggregate([aggregation]);

4 - SQLDatabase#


Manage your external SQL Databases Through the SQLDatabase class.

Usage#

You can instantiate an SQL class with id and mode(optional).

OptionDescription
idRequired. id or name of Database
modeoptional. Specifies mode of Database (default : "test")
const sql = new SQLDatabase({ id: '610c0343f6ebc7ddcb49cc3b', mode: 'test' });

findOne#

Description#

Get a table row data

/**
* @param {string} tableName table name.
*
* @param {string} Criteria query table.
*
* @return {object}
*/

Examples#

let res = await sql.findOne("client", "code='MMA'"))

find#

Description#

list multiple rows from sql table

/**
* @param {string} tableName table name.
*
* @param {string} options query table.
*
* @return {array}
*/

Examples#

let res = sql.find("client", "code='MMA'")

count#

Description#

Get the row count for a table with a criteria

/**
* @param {string} tableName table name.
*
* @param {string} options query table.
*
* @return {array} array with one element contining count
*/

Examples#

let count = await sql.count("client", "code='MMA'");

execute#

Description#

Execute a custom query on the database.

/**
* @param {string} query string of query.
*
* @return {array} Return array.
*/

Examples#

sql.execute("INSERT INTO client(code, intitule, representant, codepostal) VALUES('MDSX', 'holder', 'holder', 14000)")

insert#

Description#

Insert one row into a table.

/**
* @param {string} tableName table name.
*
* @param {object} data JSON body.
*
* @return {array}
*/

Examples#

sql.insert("client", {
code: 'HelloWord',
codepostal: 14000
}

insertMany#

Description#

Insert multiple rows into

/**
* @param {string} tableName table name.
*
* @param {array} data JSON body.
*
* @return {array}
*/

Examples#

sql.insertMany("client", [
{ code: '#1' },
{ code: '#2' }
])

update#

Description#

Update rows.

/**
* @param {string} tableName table name.
*
* @param {string} query query table.
*
* @param {object} data updated JSON body.
*
* @return {object}
*/

Examples#

sql.update('client', "code='MMA'",
{
code: "MQS"
})

delete#

Description#

Delete row/rows in your table.

/**
* @param {string} tableName table name.
*
* @param {string} query query table.
*
* @return {object}
*/

Examples#

sql.delete("client", "id=223")

5 - CustomList#


The CustomList class has the methods that will allow you to manage your Custom List

Usage#

You can instantiate a CustomList class with id of custom list. You can add other options (mode, versionId)

OptionDescription
idRequired. id of custom list
modeoptional. Specifies mode of custom list (default : "test")
versionIdoptional. id of the version from which to get the custom list
const customList = new CustomList({id: 'id', mode: 'test', versionId: "vId"});

get#

Description#

Get a custom list data

/**
* @return {promise} Return promise
*/

Examples#

let customListData = await customList.get();

6 - Report#


The Report class will allow you to manipulate specific report

Usage#

You can instantiate a Report class with id of report. You can add mode option

OptionDescription
idRequired. Specifies mode of custom list (default : "test")
modeoptional. Specifies mode of custom list (default : "test")
const report = new Report({id: 'id', mode: 'test'});

aggregate#

Description#

Aggregation operations process data records and return computed results

/**
* @param {array} aggregation aggregation array
*
* @return {promise} Return promise
*/

Examples#

let aggregation = [
{
"$match": { "SF_status": "Running" }
},
{
"$sort": { "SF_createdAt": -1 }
}
]
let instances = await report.aggregate(aggregation); //report of instances

7 - Instance#


The Instance class has the methods that will allow you to manage the instances

Usage#

const inctance = new Instance();

findById#

Description#

Get a instance by id

/**
* @param {string} id id of instance.
*
* @return {promise} Return promise
*/

Examples#

let oneInctance = await inctance.findById(id);

find#

Description#

list the instances

/**
* @param {object} criteria Json of query.
*
* @return {promise} Return promise
*/

Examples#

let instances = await inctance.find({ status: "Running" });

count#

Description#

Allow to get the count of instances that would match a query

/**
* @param {object} criteria Query json
*
* @return {promise} Return promise
*/

Examples#

let count = await inctance.count({ status: "Running" });

findAndCount#

Description#

get a list and the count of instances

/**
* @param {object} body Json of options.
*
* @return {promise} Return promise
*/

Options#

This options are optional

OptionDescription
criteriaSpecifies selection filter (default : {})
fieldsSelect specific fields (example: "createdAt name status")
limitNumber of instances returned (default : 100/ no limit : 0)
pagePage number depends on the limit (default : 0)
sortbySorts the results by key (default : createdAt)
directionAscending (1) or descending (-1) order (default : -1)

Examples#

let body = {
criteria: {
status: "Running"
},
limit: 10,
page: 0,
sortBy: "createdAt",
direction: -1
}
let res = await inctance.findAndCount(body);
let instances = res.data;
let count = res.count;

aggregate#

Description#

Aggregation operations process data records and return computed results

/**
* @param {array} aggregation aggregation array
*
* @return {promise} Return promise
*/

Examples#

let aggregation = [
{
"$match": { "status": "End" }
},
{
"$project" : {
"_id": 1,
"name": 1
}
}
]
let inctances = await inctance.aggregate([aggregation]);

update#

Description#

Update an instance

/**
* @param {string} id id of instance.
* @param {object} data Json of a new data.
*
* @return {promise} Return promise
*/

Examples#

await inctance.update(id, { status : "End" });

delete#

Description#

Delete an instance

/**
* @param {string} id id of instance.
*
* @return {promise} Return promise
*/

Examples#

await inctance.delete(id);

history#

Description#

Get instance history.

/**
* @param {string} id id of instance.
* @param {object} data Json of data.
*
* @return {promise} Return promise
*/

Examples#

await inctance.history(id, { status : "End" });

8 - Task#


The Task class has the methods that will allow you to manage the tasks

Usage#

const task = new Task();

findById#

Description#

Get a task by id

/**
* @param {string} id id of task.
*
* @return {promise} Return promise
*/

Examples#

let oneTask = await task.findById(id);

find#

Description#

list the tasks

/**
* @param {object} criteria Json of query.
*
* @return {promise} Return promise
*/

Examples#

let tasks = await task.find({ instanceId: "instanceId" });

count#

Description#

Allow to get the count of tasks that would match a query

/**
* @param {object} criteria Query json
*
* @return {promise} Return promise
*/

Examples#

let count = await task.count({ instanceId: "instanceId" });

findAndCount#

Description#

get a list and the count of tasks

/**
* @param {object} body Json of options.
*
* @return {promise} Return promise
*/

Options#

This options are optional

OptionDescription
criteriaSpecifies selection filter (default : {})
assignedToConnectedTo get tasks of connected user (default : false)
fieldsSelect specific fields (example: "createdAt name status")
limitNumber of instances returned (default : 100/ no limit : 0)
pagePage number depends on the limit (default : 0)
sortbySorts the results by key (default : createdAt)
directionAscending (1) or descending (-1) order (default : -1)

Examples#

let body = {
criteria: {
status: "Running"
},
assignedToConnected: true,
limit: 10,
page: 0,
sortBy: "createdAt",
direction: -1
}
let res = await task.findAndCount(body);
let tasks = res.data;
let count = res.count;

aggregate#

Description#

Aggregation operations process data records and return computed results

/**
* @param {array} aggregation aggregation array
*
* @return {promise} Return promise
*/

Examples#

let aggregation = [
{
"$match": { "status": "End" }
},
{
"$project" : {
"_id": 1,
"name": 1
}
}
]
let tasks = await task.aggregate([aggregation]);

update#

Description#

Update an task

/**
* @param {string} id id of task.
* @param {object} data Json of a new data.
*
* @return {promise} Return promise
*/

Examples#

await task.update(id, { status : "End" });

delete#

Description#

Delete an task

/**
* @param {string} id id of task.
*
* @return {promise} Return promise
*/

Examples#

await task.delete(id);

getNextValue#

Description#

Get next value of an task.

/**
* @param {string} name name of the variable.
* @param {number} [padding] Padding of result with 000000.
* @param {string} mode mode of the running user.
*
* @return {promise} Return promise
*/

Examples#

await task.getNextValue("name",5,"SF_mode");

9 - Api#


The Api class has the methods that will allow you to manage your Apis.

Usage#

const api = new Api();

invoke#

Description#

Invoke an api.

/**
* @param {object} body Json of options.
*
* @return {promise} Return promise
*/

Examples#

let body = {
const myElement = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
myElement.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
myElement.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
}
await api.invoke(body);

10 - Email#


The Email class has the methods that will allow you to manage your emails.

Usage#

const email = new Email();

send#

Description#

Send an email.

/**
* @param {string} assignee Assignee user email.
* @param {string} subject Subject of the email.
* @param {object} variables Json of options.
* @param {object} mailTemplate Email template.
* @param {object} mailProvider SoftyFlow default provider.
* @param {string} cc Json of options.
* @param {string} from Sender user email.
* @param {string} replyTo
*
* @return {promise} Return promise
*/

Examples#

await email.send("assignee","subject",{"var1", "var2"},{"mailTemplate"},{"mailProvider"},"mail of user in cc", "senderMail","replyTo");