Workerbase SDK for JavaScript
Installing
Install with npm:
npm install @workerbase/sdk
Typescript
Workerbase SDK fully supports typescript with .d.ts
files and the types will be maintained in the next releases.
Usage
You can use a default import with typescript
import workerbase from '@workerbase/sdk';
However we recommend using the following syntax with CommonJS to get the typings for autocomplete.
const { Workerbase } = require('@workerbase/sdk');
Example
const workerbase = require('@workerbase/sdk');
const updateUserName = async (userId) => {
const { firstName } = await workerbase.users.get(userId);
await workerbase.users.update(userId, { firstName: firstName + "v2" });
};
const createDbAndInsertItems = async () => {
const database = await workerbase.databases.create({
name: "test",
columns: [
{ name: "field1", type: "String" },
{ name: "value", type: "Integer" },
],
});
await database.items.create({ field1: "abc" }, "item1");
await database.items.update("item1", { payload: { value: "5" } });
await database.items.create({ field1: "abcd" }, "item2");
await database.items.delete("item2");
await database.items.query({$or: [{field1: "abc"}, {value: {$gt: 4}}]}, {populate: true});
};
};
const getAllUserDepartments = () =>
workerbase.users.list().distinctBy("department");
const getAllUsersWithName = (userLastname) =>
workerbase.users.list().filterBy({ lastName: userLastname });
const getAllUserDepartmentsWithName = (userLastName) =>
workerbase.users
.list()
.filterBy({ lastName: userLastName })
.distinctBy("department");
const invokeFunction = async (functionId) => {
try {
return await workerbase.functions.invoke(functionId, { some: "data" });
} catch (err) {
console.log(err.logs);
}
};
Methods
Databases
workerbase.databases.list(\[listConfig\])
workerbase.databases.get(id)
Database Items
Database.items.list(\[listConfig\])
Database.items.get(id)
Database.items.create(value\[,externalId\])
Database.items.createMany(values)
Database.items.update(id,value)
Database.items.delete(id)
Database.items.query(query, options)
More about Database.items.query
can be found here.
More about List Configs
can be found here.
Events / Connectors
workerbase.connectors.list(\[listConfig\])
workerbase.connectors.get(id)
workerbase.connectors.create(value)
workerbase.connectors.update(id,value)
workerbase.connectors.delete(id)
workerbase.connectors.trigger(id,payload)
More about List Configs
can be found here.
Deprecated usage:
workerbase.events.list(\[listConfig\])
workerbase.events.get(id)
workerbase.events.create(value)
workerbase.events.update(id,value)
workerbase.events.delete(id)
workerbase.events.trigger(id,payload)
Functions
workerbase.functions.list(\[listConfig\])
workerbase.functions.get(id)
workerbase.functions.deploy(id)
workerbase.functions.invoke(id,payload)
More about List Configs
can be found here.
Locations
workerbase.locations.list(\[listConfig\])
workerbase.locations.get(id)
workerbase.locations.create(value)
workerbase.locations.update(id,value)
workerbase.locations.delete(id)
workerbase.locations.getPartsByLevel(levelId)
workerbase.locations.getLevels()
More about List Configs
can be found here.
Media
workerbase.media.list(\[listConfig\])
workerbase.media.get(id)
workerbase.media.delete(id)
More about List Configs
can be found here.
Roles
workerbase.roles.list(\[listConfig\])
workerbase.roles.get(id)
workerbase.roles.create(value)
workerbase.roles.update(id,value)
workerbase.roles.delete(id)
More about List Configs
can be found here.
Skills
workerbase.skills.list(\[listConfig\])
workerbase.skills.get(id)
workerbase.skills.create(value)
workerbase.skills.update(id,value)
workerbase.skills.delete(id)
More about List Configs
can be found here.
Users
workerbase.users.list(\[listConfig\])
workerbase.users.get(id)
workerbase.users.create(value)
workerbase.users.update(id,value)
workerbase.users.delete(id)
More about List Configs
can be found here.
List documentation
ListConfig
interface ListConfig {
page?: number;
perpage?: number;
sort?: string;
order?: 'desc' | 'asc';
fields?: string;
}
List Response Methods
We added some builtin methods in Workerbase SDK to help you work with the data on the list responses.
See the examples above, to see how to use them.
list().filterBy(condition)
Filter the list to keep only the values that match the condition object.
Example:
const filteredList = await workerbase.users
.list({
page: 1,
perpage: 10,
sort: 'firstName',
order: 'desc',
fields: 'firstName lastName',
})
.filterBy({ firstName: 'Anna' });
list().distinctBy(field)
Return the list of all distinct values of the specified field.
Example:
const getAllUserDepartments = await workerbase.users
.list()
.distinctBy('department');
Database Items Query
Getting started
The Database.items.query()
function allows complex queries to Workerbase databases.
The following example explains a simple first query:
The example is done with the database Employee
.
Employee
database
ID | Name | Email | Birthday | Department | Office |
---|
String | String | String | Date | Reference [Department] | Location |
1 | Vannie Doulden | vannie@company.com | 12.11.1988 | 1 | North America / New York |
2 | Marijo Stede | marijo@company.com | 03.06.1994 | 2 | Europe / Munich |
3 | Jade Plante | jade@company.com | 27.02.1990 | 2 | Europe / Munich |
All employees where the birthday is after the 01.01.1989
and the name ends on Stede
should be queried.
const EmployeeDB = async workerbase.databases.get("Employee");
const result = await EmployeeDB.items.query({
Birthday: {
$gt: "01.01.1989"
},
Name: {
$like: "%Stede"
}
})
The result
variable will contain the employee Marijo Stede
.
[
{
"_id": "634fc1e9d64ce49dd554c2db",
"meta": {
"createdAt": "2022-10-19T09:22:49.782Z",
"updatedAt": "2022-10-19T09:27:50.733Z"
},
"database": "634fbc5cd64ce49dd554bdb0",
"payload": {
"Name": "Marijo Stede",
"Email": "marijo@company.com",
"Birthday": "1994-06-03T00:00:00.000Z",
"Department": "634fbc8dd64ce49dd554bde6",
"Office": "634fc1825025ac5347b21ffc"
},
"deleted": false,
"externalId": "2"
}
]
Advanced features of the Database.items.query()
function are described in the sections Query Operators, Pagination, Sorting, Population, Nested Property Queries
Before looking into advanced features we recomment to review the Typings Definition of the query function.
Typings Definition
type QueryFunction = (query: Query, options: ListOptions): Promise<DatabaseItem[]>
type Query = Record<QueryOperator, string | number | boolean | Query>;
enum QueryOperator {
EQ = '$eq',
NE = '$ne',
GT = '$gt',
GTE = '$gte',
LT = '$lt',
LTE = '$lte',
IN = '$in',
NIN = '$nin',
EXISTS = '$exists',
AND = '$and',
OR = '$or',
LIKE = '$like',
NOT_LIKE = '$notLike',
}
interface ListOptions {
page?: number;
perpage?: number;
sort?: string;
order?: 'desc' | 'asc';
populate?: boolean;
}
interface DatabaseItem {
_id: string;
externalId?: string;
payload: ItemPayload;
}
type ItemPayload = Record<string, any>;
Query Operators
The following query operators are supported.
enum QueryOperator {
EQ = '$eq',
NE = '$ne',
GT = '$gt',
GTE = '$gte',
LT = '$lt',
LTE = '$lte',
IN = '$in',
NIN = '$nin',
EXISTS = '$exists',
AND = '$and',
OR = '$or',
LIKE = '$like',
NOT_LIKE = '$notLike',
}
The result of the query function can be paginated with the page
and perpage
properties of the options
parameter.
type QueryFunction = (query: Query, options: ListOptions): Promise<DatabaseItem[]>
interface ListOptions {
page?: number;
perpage?: number;
sort?: string;
order?: 'desc' | 'asc';
populate?: boolean;
}
Example: If the database Employee
contains 100
items, the last 10 items (91-100) can be requested with the following query.
const EmployeeDB = async workerbase.databases.get("Employee");
const result = await EmployeeDB.items.query({}, { page: 10, perpage: 10 });
Sorting
Items in the result can be sorted with the sort
and order
properties of the options
parameter.
Example: In order to sort items from the Employee
database by their age starting with the oldest one, the following query has to be run.
const EmployeeDB = async workerbase.databases.get("Employee");
const result = await EmployeeDB.items.query({}, { sort: 'Birthday', order: 'desc' });
Population
Databases Items in Workerbase can have references to other Database Items and to User
, Role
and Location
items in the platform. Those references can be directly included into the result by adding { populate: true }
to the options parameter.
Example: The Department column of the Employee
database is of type Reference
and points to the database Department
. Furthermore the Employee
database has a column Office
which is of type Location
and points to locations in the Workerbase platform.
Employee
database
ID | Name | Email | Birthday | Department | Office |
---|
String | String | String | Date | Reference [Department] | Location |
1 | Vannie Doulden | vannie@company.com | 12.11.1988 | 1 | North America / New York |
2 | Marijo Stede | marijo@company.com | 03.06.1994 | 2 | Europe / Munich |
3 | Jade Plante | jade@company.com | 27.02.1990 | 2 | Europe / Munich |
Department
database
ID | Name | Headcount |
---|
String | String | Number |
1 | Product Management | 10 |
2 | Engineering | 25 |
The employee Vannie Doulden
is queried with the { populate: true }
option, which includes the references Department
and Location
as objects into the result.
When the { populate: true }
option is not set, the IDs
of the references Department
and Location
are added instead of objects to the result.
const EmployeeDB = async workerbase.databases.get("Employee");
const result = await EmployeeDB.items.query({ Name: 'Vannie Doulden' }, { populate: true });
The result
variable will contain the employee Vannie Doulden
with populated references.
[
{
"_id": "634fc1b3d64ce49dd554c24c",
"meta": {
"createdAt": "2022-10-19T09:21:55.713Z",
"updatedAt": "2022-10-19T09:22:24.916Z"
},
"database": "634fbc5cd64ce49dd554bdb0",
"payload": {
"Name": "Vannie Doulden",
"Email": "vannie@company.com",
"Birthday": "1988-11-12T00:00:00.000Z",
"Department": {
"_id": "634fbc85d64ce49dd554bdd1",
"meta": {
"createdAt": "2022-10-19T08:59:49.755Z",
"updatedAt": "2022-10-19T09:00:04.742Z"
},
"database": "634fbc75d64ce49dd554bdc2",
"payload": {
"Name": "Product Management",
"Headcount": 10
},
"deleted": false,
"externalId": "1"
},
"Office": {
"_id": "634fc1905025ac5347b22020",
"externalId": "649f9110-4f8f-11ed-967c-0b922c03bae6",
"name": "North America / New York"
}
},
"deleted": false,
"externalId": "1"
}
]
Nested Property Queries
In order to filter on references of items, conditions on nested properties have to be added to the query
parameter. Nested properties are specified by adding $
in the beginning and end of a path i.e. $Office.Name$
.
Please keep in mind that nested property queries can only be used when { populate: true }
is added to the options
parameter.
Example: All employees whose Department
has a Headcount
less than 20
should be queried.
The example is based on the data shown in the section Population.
const EmployeeDB = async workerbase.databases.get("Employee");
const result = await EmployeeDB.items.query({ "$Department.Headcount$": { $lt: 20 } }, { populate: true });
The result
variable will contain the employee Vannie Doulden
.
[
{
"_id": "634fc1b3d64ce49dd554c24c",
"meta": {
"createdAt": "2022-10-19T09:21:55.713Z",
"updatedAt": "2022-10-19T09:22:24.916Z"
},
"database": "634fbc5cd64ce49dd554bdb0",
"payload": {
"Name": "Vannie Doulden",
"Email": "vannie@company.com",
"Birthday": "1988-11-12T00:00:00.000Z",
"Department": {
"_id": "634fbc85d64ce49dd554bdd1",
"meta": {
"createdAt": "2022-10-19T08:59:49.755Z",
"updatedAt": "2022-10-19T09:00:04.742Z"
},
"database": "634fbc75d64ce49dd554bdc2",
"payload": {
"Name": "Product Management",
"Headcount": 10
},
"deleted": false,
"externalId": "1"
},
"Office": {
"_id": "634fc1905025ac5347b22020",
"externalId": "649f9110-4f8f-11ed-967c-0b922c03bae6",
"name": "North America / New York"
}
},
"deleted": false,
"externalId": "1"
}
]
Steps documentation
Workinstruction steps, buttons, and actions can now be defined with the SDK:
Example
const workerbase = require('@workerbase/sdk');
const { FLEX_DIRECTION } = require('@workerbase/sdk');
const infoText = workerbase.steps.InfoText({
title: 'Info Text Step',
description: '',
});
const photoStep = workerbase.steps.InfoPhoto({
title: 'Info Photo Step',
mediaId: '5d9f0653e762e70006ab9ecd',
description: '',
});
const flexStep = workerbase.steps.LayoutFlex({
title: 'Layout Flex Step',
direction: FLEX_DIRECTION.COLUMN,
});
flexStep.addButton(workerbase.buttons.Finish({}));
flexStep.addButtons([
workerbase.buttons.Close({}),
workerbase.buttons.Suspend({}),
]);
const flexGroup = flexStep.createGroup({
direction: FLEX_DIRECTION.COLUMN,
flex: 8,
});
flexGroup.addStep({ flex: 10, step: infoText });
flexStep.addGroup({ group: flexGroup });
flexStep.addStep({ flex: 1, step: photoStep });
Usage
Actions
const close = workerbase.actions.Close();
const finish = workerbase.actions.Finish();
const suspend = workerbase.actions.Suspend();
const nextStepFunctionId = workerbase.actions.NextStepFunctionId('functionId');
const nextActionFunctionId = workerbase.actions.NextActionFunctionId(
'functionId',
);
const nextWorkinstruction = workerbase.actions.NextWorkinstruction(
'workinstructionsId',
);
const nextStepId = workerbase.actions.NextStepId('stepId');
const nextTaskId = workerbase.actions.NextTaskId('taskId');
Buttons
const close = workerbase.buttons.Close();
const finish = workerbase.buttons.Finish();
const suspend = workerbase.buttons.Suspend();
const nextStepFunctionId = workerbase.buttons.NextStepFunctionId('functionId');
const nextActionFunctionId = workerbase.buttons.NextActionFunctionId(
'functionId',
);
const nextWorkinstruction = workerbase.buttons.NextWorkinstruction(
'workinstructionId',
);
const nextStepId = workerbase.buttons.NextStepId('stepId');
const nextTaskId = workerbase.buttons.NextTaskId('taskId');
Each button has additional optional values: text
, icon
, and id
. If some of these values are not set by the user, the SDK auto-assigns values to them.
The variables can be specified for each button as follows:
const { ACTION_ICONS } = require('@workerbase/sdk');
const close = workerbase.buttons.Close({
text: 'Button Text',
icon: ACTION_ICONS.CLOSE,
id: 'my id',
});
const nextActionFunctionId = workerbase.buttons.NextActionFunctionId(
'functionId',
{
text: 'Button Text',
icon: ACTION_ICONS.CONFIRM,
id: 'my id',
},
);
-> ACTION_ICONS
enum can be viewed here.
Info Steps:
Each step has an optional id
value. If it is not set by the user, the SDK will assign a value to it.
For each step, buttons can be added as follows:
const step = workerbase.steps.InfoText({
title: '',
description: '',
});
step.addButton(workerbase.buttons.Close({}));
step.addButtons([
workerbase.buttons.Finish({}),
workerbase.buttons.Suspend({}),
]);
-
Info Text Step
const step = workerbase.steps.InfoText({
title: '',
description: '',
id: '',
});
-
Info Text Large Step
const step = workerbase.steps.InfoTextLarge({
title: '',
description: '',
id: '',
});
-
Info Qr Code Step
const step = workerbase.steps.InfoQrCode({
title: '',
payload: '',
id: '',
});
-
Info Status Step
const {
STATUS_SCREEN_COLORS,
STATUS_SCREEN_ICONS,
} = require('@workerbase/sdk');
const step = workerbase.steps.InfoStatus({
title: '',
description: '',
headline: '',
id: '',
});
step.setIcon(STATUS_SCREEN_ICONS.SUCCESS);
step.setColor(STATUS_SCREEN_COLORS.GREEN);
-> More information on STATUS_SCREEN_COLORS
and STATUS_SCREEN_ICONS
enums can be found here.
-
Info WebView Step
const step = workerbase.steps.InfoWebview({
title: '',
url: '',
id: '',
});
-
Info Photo Step
const step = workerbase.steps.InfoPhoto({
title: '',
mediaId: '',
description: '',
id: '',
});
step.showFullPicture(false);
-
Info Audio Step
const step = workerbase.steps.InfoAudio({
title: '',
mediaId: '',
description: '',
id: '',
});
-
Info Video Step
const step = workerbase.steps.InfoVideo({
title: '',
mediaId: '',
description: '',
id: '',
});
-
Info Pdf Step
const step = workerbase.steps.InfoPdf({
title: '',
mediaId: '',
description: '',
id: '',
});
step.enableSlideMode();
step.disableSlideMode();
step.setPageNumber(3);
-
Info Loading Step
const step = workerbase.steps.InfoLoading({
title: '',
taskAppearingDuration: '',
id: '',
});
-
Info Location Direction Step
const step = workerbase.steps.InfoLocationDirection({
title: '',
gpsLocationLatitude: '',
gpsLocationLongitude: '',
description: '',
id: '',
});
Input Steps:
-
Input Text Step
const step = workerbase.steps.InputText({
title: '',
outputVarName: '',
description: '',
id: '',
});
-
Input Barcode Step
const step = workerbase.steps.InputBarcode({
title: '',
outputVarName: '',
description: '',
id: '',
});
step.setAutoContinue(true);
step.setAllowManualBarcodeInput(true);
step.addRegex('d');
step.addMultipleRegex(['d', 'code']);
step.addRegexOperation(workerbase.steps.regex.Begins('abc'));
step.addRegexOperations([
workerbase.steps.regex.Contains('abc'),
workerbase.steps.regex.Ends('abc'),
workerbase.steps.regex.Equals('abc'),
workerbase.steps.regex.EqualsVar('abc'),
workerbase.steps.regex.Regex('abc'),
]);
-
Input Number Picker Step
const step = workerbase.steps.InputNumberPicker({
title: '',
outputVarName: '',
description: '',
id: '',
});
step.setIntegerDigits(2);
step.setDecimalDigits(3);
step.setDefaultValueDecimal('10.000');
-
Input Number Step
const step = workerbase.steps.InputNumber({
title: '',
outputVarName: '',
id: '',
});
step.setIntegerDigits(2);
step.setDecimalDigits(3);
step.setDefaultValueDecimal('10.000');
-
Input Location Step
const step = workerbase.steps.InputLocation({
title: '',
outputVarName: '',
minAccuracyInMeters: 3,
description: '',
id: '',
});
-
Input Audio Step
const step = workerbase.steps.InputAudio({
title: '',
outputVarName: '',
id: '',
});
-
Input Video Step
const step = workerbase.steps.InputVideo({
title: '',
outputVarName: '',
id: '',
});
-
Input Photo Step
const step = workerbase.steps.InputPhoto({
title: '',
outputVarName: '',
id: '',
});
-
Input Noise Level Step
const step = workerbase.steps.InputNoiseLevel({
title: '',
outputVarName: '',
measureDurationInSec: 5,
id: '',
});
step.setAutoContinue(true);
step.setAutoStartMeasurement(false);
step.setInputRequired(false);
step.setWarningThresholdInDecibel(200);
Input List Steps
For each Input List Step, you can add custom options or load options from a function.
The options input type (options array, or function ID) can be specified with the source
input variable and LIST_OPTIONS_SOURCE
enum. More information about this enum can be found here.
-
Input Value List Step
Options for this step can be added with ValueListOption
method:
workerbase.steps.options.ValueListOption({
text: '',
id: '',
action: ... ,
custom: ... ,
});
The Step can be defined as follows:
const { LIST_OPTIONS_SOURCE } = require('@workerbase/sdk');
const step = workerbase.steps.InputValueList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.OPTIONS,
id: '',
});
step.setAutoContinue(true);
step.setRequireSelection(true);
step.addOption(workerbase.steps.options.ValueListOption({ text: '1' }));
step.addOptions([
workerbase.steps.options.ValueListOption({ text: '2' }),
workerbase.steps.options.ValueListOption({ text: '3' }),
]);
step.setCustomNextStep(true);
step.addOption(
workerbase.steps.options.ValueListOption({
text: '1',
action: workerbase.actions.Close(),
}),
);
step.addOption(
workerbase.steps.options.ValueListOption({
text: '1',
action: workerbase.actions.Close(),
custom: { yourVariableName: 'yourVariableValue' },
}),
);
const optionsFromFunction = workerbase.steps.InputValueList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.CONNECTOR,
id: '',
});
optionsFromFunction.setLoadOptionsFromUrl('functionId');
-
Input Index List Step
Options for this step can be added with IndexListOption
method:
workerbase.steps.options.IndexListOption({
text: '',
isHeadline: false,
id: '',
custom: ... ,
});
The Step can be defined as follows:
const { LIST_OPTIONS_SOURCE } = require('@workerbase/sdk');
const step = workerbase.steps.InputIndexList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.OPTIONS,
id: '',
});
step.setAutoContinue(true);
step.setRequireSelection(true);
step.addOption(
workerbase.steps.options.IndexListOption({
text: '1',
isHeadline: true,
}),
);
step.addOptions([
workerbase.steps.options.IndexListOption({ text: '2', isHeadline: true }),
workerbase.steps.options.IndexListOption({ text: '3', isHeadline: false }),
]);
step.setAutoContinue(true);
step.setRequireSelection(true);
const optionsFromFunction = workerbase.steps.InputIndexList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.CONNECTOR,
id: '',
});
optionsFromFunction.setLoadOptionsFromUrl('functionId');
-
Input Tile List Step
Options for this step can be added with TileListOption
method:
workerbase.steps.options.TileListOption({
text: '',
id: '',
action: ... ,
custom: ... ,
});
The Step can be defined as follows:
const { LIST_OPTIONS_SOURCE } = require('@workerbase/sdk');
const step = workerbase.steps.InputTileList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.OPTIONS,
id: '',
});
step.setAutoContinue(true);
step.setRequireSelection(true);
step.addOption(
workerbase.steps.options.TileListOption({
text: '1',
custom: { test: 'test' },
}),
);
step.addOptions([
workerbase.steps.options.TileListOption({ text: '2' }),
workerbase.steps.options.TileListOption({ text: '3' }),
]);
step.setCustomNextStep(true);
step.addOption(
workerbase.steps.options.TileListOption({
text: '1',
action: workerbase.actions.Close(),
}),
);
step.setCustomNextStep(true);
step.addOption(
workerbase.steps.options.TileListOption({
text: 'text',
action: workerbase.actions.Suspend(),
custom: { test: 'test' },
}),
);
const optionsFromFunction = workerbase.steps.InputTileList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.CONNECTOR,
id: '',
});
optionsFromFunction.setLoadOptionsFromUrl('functionId');
-
Input Checkbox List
Options for this step can be added with CheckboxListOption
method:
workerbase.steps.options.CheckboxListOption({
text: '',
isChecked: false,
id: '',
custom: ... ,
});
The Step can be defined as follows:
const { LIST_OPTIONS_SOURCE } = require('@workerbase/sdk');
const step = workerbase.steps.InputCheckboxList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.OPTIONS,
id: '',
});
step.setAutoContinue(true);
step.setRequireSelection(true);
step.addOption(
workerbase.steps.options.CheckboxListOption({
text: 'text',
isChecked: false,
custom: { test: 'test' },
}),
);
step.addOptions([
workerbase.steps.options.CheckboxListOption({
text: '2',
isChecked: false,
}),
workerbase.steps.options.CheckboxListOption({
text: '3',
isChecked: false,
}),
]);
const optionsFromFunction = workerbase.steps.InputCheckboxList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.CONNECTOR,
id: '',
});
optionsFromFunction.setLoadOptionsFromUrl('functionId');
-
Input Button List
Options for this step can be added with ButtonListOption
method:
const { OPTION_ICONS } = require('@workerbase/sdk');
workerbase.steps.options.ButtonListOption({
text: '',
id: '',
action: workerbase.actions.Finish(),
icon: OPTION_ICONS.INFO,
custom: undefined,
});
The step can be defined as follows:
const { LIST_OPTIONS_SOURCE, OPTION_ICONS } = require('@workerbase/sdk');
const step = workerbase.steps.InputButtonList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.OPTIONS,
});
step.setAutoContinue(true);
step.setRequireSelection(true);
step.displayPhoto('mediaId');
step.addOption(
workerbase.steps.options.ButtonListOption({
text: 'text',
custom: { test: 'test' },
}),
);
step.addOptions([
workerbase.steps.options.ButtonListOption({ text: '2' }),
workerbase.steps.options.ButtonListOption({ text: '3' }),
]);
step.setCustomNextStep(true);
step.addOption(
workerbase.steps.options.ButtonListOption({
text: 'text',
action: workerbase.actions.Suspend(),
custom: { test: 'test' },
}),
);
step.addOption(
workerbase.steps.options.ButtonListOption({
text: 'text',
custom: { test: 'test' },
icon: OPTION_ICONS.INFO,
}),
);
const optionsFromFunction = workerbase.steps.InputButtonList({
title: '',
outputVarName: '',
source: LIST_OPTIONS_SOURCE.CONNECTOR,
id: '',
});
optionsFromFunction.setLoadOptionsFromUrl('functionId');
-> More information on OPTION_ICONS
enum can be found here.
Flex Step
We added the possibility to define a custom step, consisting of multiple other steps. This can be done via the FlexStep
.
You can add a single step, or a group of steps to the FlexStep
:
const { FLEX_DIRECTION } = require('@workerbase/sdk');
const infoText = workerbase.steps.InfoText({
title: '',
description: 'This is the description of the step',
});
const photoStep = workerbase.steps.InfoPhoto({
title: '',
mediaId: '5d9f0653e762e70006ab9ecd',
description: 'This is the description of the photo',
});
const flexStep = workerbase.steps.LayoutFlex({
title: 'My Layout Flex Step',
direction: FLEX_DIRECTION.COLUMN,
});
flexStep.addButtons([
workerbase.buttons.Suspend({}),
workerbase.buttons.Finish({}),
]);
const flexGroup = flexStep.createGroup({
direction: FLEX_DIRECTION.COLUMN,
flex: 8,
});
flexGroup.addStep({ flex: 10, step: infoText });
flexStep.addGroup(flexGroup);
flexStep.addStep({ flex: 1, step: photoStep });
-> More information on FLEX_DIRECTION
enum can be found here.
Enums
enum STATUS_SCREEN_ICON {
SUCCESS,
INFO,
ERROR,
}
enum STATUS_SCREEN_COLORS {
GREY,
RED,
GREEN,
}
enum LIST_OPTIONS_SOURCE {
CONNECTOR,
OPTIONS,
}
enum ACTION_ICONS {
CONFIRM,
CLOSE,
QUESTION_YELLOW,
REPEAT,
WARNING_RED_CLEAR_BG,
WARNING_RED,
WARNING_YELLOW,
WARNING,
REFRESH,
INFO,
INFO_BLUE,
BACK,
NEXT,
CONFIRM_ENCIRCLED,
CONFIRM_ENCIRCLED_GREEN,
PLUS,
MINUS,
INSTRUCTIONS,
LIST,
HOME,
}
enum OPTION_ICONS {
INFO,
ERROR,
SUCCESS,
SUPPORT,
}
enum FLEX_DIRECTION {
ROW,
COLUMN,
}