Creating new lib
Create new group action library
Create new lib with command:
npx nx g @nrwl/node:library actions/<action-group-name>Add new enum for action group inside
libs/types/src/lib/actions.tsexport enum PlaywrightActionType {
LONG_BROWSER_AUTO_PLAYWRIGHT = 'long_browser_auto_playwright',
SHORT_BROWSER_AUTO_PLAYWRIGHT = 'short_browser_auto_playwright',
BROWSER_AUTO = 'browser_auto',
}Extend ActionType object and type in the same file below:
export const ActionType = {
...PlaywrightActionType,
...MicrosoftActionType,
...CommonActionType,
};
export type ActionType =
| PlaywrightActionType
| MicrosoftActionType
| CommonActionType;create new folder for settings and output for this action group(if not exist) in
libs/types/src/lib/${action-group-name}/index.tsextend action settings with
ActionSettingsBaseand add it tolibs/types/src/lib/settings.tsadd tolibs/types/src/lib/${action-group-name}/index.tsexport interface YourNewActionSettings extends ActionSettingsBase {
workerId: number;
customer_id: number;
inputs: any[];
}register in
libs/types/src/lib/settings.tsexport interface ActionsSettings {
[ActionType.INCOMING_TWILIO]: IncomingTwilioSMSSettings;
[ActionType.INCOMING_GENERAL]: IncomingGeneralSettings;
[ActionType.YOUR_NEW_ACTION_TYPE]: YourNewActionSettings;specify output interface for new action settings and add it to
libs/types/src/lib/output.tsadd it tolibs/types/src/lib/${action-group-name}/index.tsexport interface YourNewActionOutput {
message?: string;
data?: any;
model?: any;
}register in
libs/types/src/lib/settings.tsexport interface SuccessfullActionOutput {
[ActionType.INCOMING_TWILIO]: IncomingTwilioOutput;
[ActionType.INCOMING_GENERAL]: IncomingGeneralOutput;
[ActionType.YOUR_NEW_ACTION_TYPE]: YourNewActionOutput
}If it is new action group, add new export to
libs/types/src/index.jsas'export * from './lib/group-name/index'Create new class that will represents action from this group (in
libs/actions/${your-action}/src/lib), extend it fromActionTemplate<typeof ActionType.{action-group-name}>orActionTemplate<{group-name-type}.{group-action-name}>export class YourNewAction extends ActionTemplate<typeof ActionType.YOUR_NEW_ACTION_TYPE> {
}Implement all abstract fields (press option/alt + and choose Implement inherited abstract class). Press
Option/Alt + Enteron class name, it will do below step automatically (except constructor)export class YourNewAction extends ActionTemplate<ActionType.YOUR_NEW_ACTION_TYPE> {
protected testMode: boolean;
protected name: string;
protected id: string;
protected settings: YourNewActionSettings;
protected customer_id: number;
public output: null;
protected credentials: any;
}
//validate here
constructor(
description: ActionDescription<ActionType>,
options: WorkflowOptions
) {
super(ActionType.YOUR_NEW_ACTION_TYPE, description as any, options);
}
- Implement do_action method, it's important that output of the action result is set as inner properties e.g. <---- New, after microsoft action
do_action(input: any) {
//it can be ommited
this.output = input;
//this is important !!!
return this.output;
}
- In the folder create new file called
action-mapping.tsand map action your actions to classes that you created. It should satisfyActionTypeToClassMaptype
export const CommonActionMapping: ActionTypeToClassMap<CommonActionType> = {
[ActionType.EXECUTE_JAVASCRIPT]: ExecuteJavascript,
[CommonActionType.LOG]: Log,
[CommonActionType.DELAY]: Delay,
[CommonActionType.CONDITIONAL]: Conditional,
[CommonActionType.OBJECT_HELPER]: undefined,
[CommonActionType.HUMAN_IN_THE_LOOP]: undefined,
[CommonActionType.INCOMING_TWILIO]: undefined,
[CommonActionType.INCOMING_GENERAL]: undefined,
[CommonActionType.INCOMING_JOT_FORM]: undefined,
[CommonActionType.LIST_FILTER]: undefined,
[CommonActionType.GET_RECENT_RIBBONS]: undefined,
};
Create new action in existed library
Complete actions from point 2 in the previous chapter
Create new non action library
Depending on type of lib you can create NestJs library or typescript library
Run next command to create nestJs library
npx nx g @nrwl/nest:library <lib-name>
Run next command to create typescript library
nx g @nrwl/js:library <lib-name>
Recommendation:
In most cases you need to create NestJs library