Skip to main content

Creating new lib

Create new group action library

  1. Create new lib with command: npx nx g @nrwl/node:library actions/<action-group-name>

  2. Add new enum for action group inside libs/types/src/lib/actions.ts

     export enum PlaywrightActionType {
    LONG_BROWSER_AUTO_PLAYWRIGHT = 'long_browser_auto_playwright',
    SHORT_BROWSER_AUTO_PLAYWRIGHT = 'short_browser_auto_playwright',
    BROWSER_AUTO = 'browser_auto',
    }
  3. Extend ActionType object and type in the same file below:

    export const ActionType = {
    ...PlaywrightActionType,
    ...MicrosoftActionType,
    ...CommonActionType,
    };

    export type ActionType =
    | PlaywrightActionType
    | MicrosoftActionType
    | CommonActionType;
  4. create new folder for settings and output for this action group(if not exist) in libs/types/src/lib/${action-group-name}/index.ts

  5. extend action settings with ActionSettingsBase and add it to libs/types/src/lib/settings.ts add to libs/types/src/lib/${action-group-name}/index.ts

     export interface YourNewActionSettings extends ActionSettingsBase {
    workerId: number;
    customer_id: number;
    inputs: any[];
    }

    register in libs/types/src/lib/settings.ts

     export interface ActionsSettings {
    [ActionType.INCOMING_TWILIO]: IncomingTwilioSMSSettings;
    [ActionType.INCOMING_GENERAL]: IncomingGeneralSettings;
    [ActionType.YOUR_NEW_ACTION_TYPE]: YourNewActionSettings;
  6. specify output interface for new action settings and add it to libs/types/src/lib/output.ts add it to libs/types/src/lib/${action-group-name}/index.ts

     export interface YourNewActionOutput {
    message?: string;
    data?: any;
    model?: any;
    }

    register in libs/types/src/lib/settings.ts

     export interface SuccessfullActionOutput {
    [ActionType.INCOMING_TWILIO]: IncomingTwilioOutput;
    [ActionType.INCOMING_GENERAL]: IncomingGeneralOutput;
    [ActionType.YOUR_NEW_ACTION_TYPE]: YourNewActionOutput
    }
  7. If it is new action group, add new export to libs/types/src/index.js as 'export * from './lib/group-name/index'

  8. Create new class that will represents action from this group (in libs/actions/${your-action}/src/lib), extend it from ActionTemplate<typeof ActionType.{action-group-name}> or ActionTemplate<{group-name-type}.{group-action-name}>

        export class YourNewAction extends ActionTemplate<typeof ActionType.YOUR_NEW_ACTION_TYPE> {
    }
  9. Implement all abstract fields (press option/alt + and choose Implement inherited abstract class). Press Option/Alt + Enter on 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;
    }
  1. In the folder create new file called action-mapping.ts and map action your actions to classes that you created. It should satisfy ActionTypeToClassMap type
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