Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6658 workflows add a first twenty piece email sender #6965

Merged
merged 24 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
WIP: move workflow actions to dedicated modules
  • Loading branch information
martmull committed Sep 12, 2024
commit 7afe454d8f61af716f4efd0f24f836bf27ee6439
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const ACTIONS: Array<{
}> = [
{
label: 'Serverless Function',
type: 'CODE_ACTION',
type: 'CODE',
icon: IconSettingsAutomation,
},
];
4 changes: 2 additions & 2 deletions packages/twenty-front/src/modules/workflow/types/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type WorkflowCodeSettingsType = WorkflowBaseSettingsType & {
serverlessFunctionId: string;
};

export type WorkflowActionType = 'CODE_ACTION';
export type WorkflowActionType = 'CODE';

type CommonWorkflowAction = {
id: string;
Expand All @@ -22,7 +22,7 @@ type CommonWorkflowAction = {
};

type WorkflowCodeAction = CommonWorkflowAction & {
type: 'CODE_ACTION';
type: 'CODE';
settings: WorkflowCodeSettingsType;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('addCreateStepNodes', () => {
{
id: 'step1',
name: 'Step 1',
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
settings: {
errorHandlingOptions: {
Expand All @@ -27,7 +27,7 @@ describe('addCreateStepNodes', () => {
{
id: 'step2',
name: 'Step 2',
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
settings: {
errorHandlingOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('generateWorkflowDiagram', () => {
{
id: 'step1',
name: 'Step 1',
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
settings: {
errorHandlingOptions: {
Expand All @@ -48,7 +48,7 @@ describe('generateWorkflowDiagram', () => {
{
id: 'step2',
name: 'Step 2',
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
settings: {
errorHandlingOptions: {
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('generateWorkflowDiagram', () => {
{
id: 'step1',
name: 'Step 1',
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
settings: {
errorHandlingOptions: {
Expand All @@ -101,7 +101,7 @@ describe('generateWorkflowDiagram', () => {
{
id: 'step2',
name: 'Step 2',
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
settings: {
errorHandlingOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('getWorkflowVersionDiagram', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('insertStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
};

Expand Down Expand Up @@ -65,7 +65,7 @@ describe('insertStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
};

Expand Down Expand Up @@ -97,7 +97,7 @@ describe('insertStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
},
{
Expand All @@ -110,7 +110,7 @@ describe('insertStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
},
],
Expand All @@ -131,7 +131,7 @@ describe('insertStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
};

Expand Down Expand Up @@ -167,7 +167,7 @@ describe('insertStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
},
{
Expand All @@ -180,7 +180,7 @@ describe('insertStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
},
],
Expand All @@ -201,7 +201,7 @@ describe('insertStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('replaceStep', () => {
},
serverlessFunctionId: 'first',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
} satisfies WorkflowStep;
const workflowVersionInitial = {
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('replaceStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
};
const workflowVersionInitial = {
Expand All @@ -79,7 +79,7 @@ describe('replaceStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
},
stepToBeReplaced,
Expand All @@ -93,7 +93,7 @@ describe('replaceStep', () => {
},
serverlessFunctionId: 'a5434be2-c10b-465c-acec-46492782a997',
},
type: 'CODE_ACTION',
type: 'CODE',
valid: true,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export const getStepDefaultDefinition = (
const newStepId = v4();

switch (type) {
case 'CODE_ACTION': {
case 'CODE': {
return {
id: newStepId,
name: 'Code',
type: 'CODE_ACTION',
type: 'CODE',
valid: false,
settings: {
serverlessFunctionId: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import {
ValidateIf,
validateSync,
} from 'class-validator';
import { CastToBoolean } from 'src/engine/core-modules/environment/decorators/cast-to-boolean.decorator';
import { CastToLogLevelArray } from 'src/engine/core-modules/environment/decorators/cast-to-log-level-array.decorator';
import { CastToPositiveNumber } from 'src/engine/core-modules/environment/decorators/cast-to-positive-number.decorator';
import { IsAWSRegion } from 'src/engine/core-modules/environment/decorators/is-aws-region.decorator';
import { IsDuration } from 'src/engine/core-modules/environment/decorators/is-duration.decorator';

import { EmailDriver } from 'src/engine/core-modules/email/interfaces/email.interface';
import { NodeEnvironment } from 'src/engine/core-modules/environment/interfaces/node-environment.interface';
Expand All @@ -27,6 +22,11 @@ import { LLMTracingDriver } from 'src/engine/core-modules/llm-tracing/interfaces
import { AwsRegion } from 'src/engine/core-modules/environment/interfaces/aws-region.interface';
import { SupportDriver } from 'src/engine/core-modules/environment/interfaces/support.interface';

import { IsDuration } from 'src/engine/core-modules/environment/decorators/is-duration.decorator';
import { IsAWSRegion } from 'src/engine/core-modules/environment/decorators/is-aws-region.decorator';
import { CastToPositiveNumber } from 'src/engine/core-modules/environment/decorators/cast-to-positive-number.decorator';
import { CastToLogLevelArray } from 'src/engine/core-modules/environment/decorators/cast-to-log-level-array.decorator';
import { CastToBoolean } from 'src/engine/core-modules/environment/decorators/cast-to-boolean.decorator';
import { CacheStorageType } from 'src/engine/core-modules/cache-storage/types/cache-storage-type.enum';
import { CaptchaDriverType } from 'src/engine/core-modules/captcha/interfaces';
import { CastToStringArray } from 'src/engine/core-modules/environment/decorators/cast-to-string-array.decorator';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
OPTIONS_TYPE,
ASYNC_OPTIONS_TYPE,
} from 'src/engine/core-modules/exception-handler/exception-handler.module-definition';

import { ExceptionHandlerConsoleDriver } from 'src/engine/core-modules/exception-handler/drivers/console.driver';
import { ExceptionHandlerSentryDriver } from 'src/engine/core-modules/exception-handler/drivers/sentry.driver';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Inject, Injectable } from '@nestjs/common';

import { Readable } from 'stream';

import { STORAGE_DRIVER } from 'src/engine/core-modules/file-storage/file-storage.constants';

import { StorageDriver } from 'src/engine/core-modules/file-storage/drivers/interfaces/storage-driver.interface';

import { STORAGE_DRIVER } from 'src/engine/core-modules/file-storage/file-storage.constants';

@Injectable()
export class FileStorageService implements StorageDriver {
constructor(@Inject(STORAGE_DRIVER) private driver: StorageDriver) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ConfigurableModuleClass,
OPTIONS_TYPE,
} from 'src/engine/core-modules/logger/logger.module-definition';

import { LoggerDriverType } from 'src/engine/core-modules/logger/interfaces';

@Global()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import { Module } from '@nestjs/core/injector/module';
import { Injector } from '@nestjs/core/injector/injector';
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';

import { MessageQueueMetadataAccessor } from 'src/engine/core-modules/message-queue/message-queue-metadata.accessor';

import { MessageQueueWorkerOptions } from 'src/engine/core-modules/message-queue/interfaces/message-queue-worker-options.interface';
import {
MessageQueueJob,
MessageQueueJobData,
} from 'src/engine/core-modules/message-queue/interfaces/message-queue-job.interface';

import { MessageQueueMetadataAccessor } from 'src/engine/core-modules/message-queue/message-queue-metadata.accessor';
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
import { getQueueToken } from 'src/engine/core-modules/message-queue/utils/get-queue-token.util';
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import DOMPurify from 'dompurify';
import { WorkflowActionEmail } from 'twenty-emails';
import { render } from '@react-email/components';

import { WorkflowStepResult } from 'src/modules/workflow/workflow-executor/types/workflow-step-result.type';
import { WorkflowSendEmailStep } from 'src/modules/workflow/workflow-executor/types/workflow-step.type';
import { WorkflowActionResult } from 'src/modules/workflow/workflow-executor/types/workflow-action-result.type';
import { WorkflowSendEmailStep } from 'src/modules/workflow/workflow-executor/types/workflow-action.type';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import { EmailService } from 'src/engine/core-modules/email/email.service';

@Injectable()
export class SendEmailWorkflowStepExecutor {
private readonly logger = new Logger(SendEmailWorkflowStepExecutor.name);
export class SendEmailWorkflowAction {
private readonly logger = new Logger(SendEmailWorkflowAction.name);
constructor(
private readonly environmentService: EnvironmentService,
private readonly emailService: EmailService,
Expand All @@ -29,7 +29,7 @@ export class SendEmailWorkflowStepExecutor {
email: string;
[key: string]: string;
};
}): Promise<WorkflowStepResult> {
}): Promise<WorkflowActionResult> {
try {
const emailSchema = z.string().trim().email('Invalid email');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Injectable } from '@nestjs/common';

import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory';
import { WorkflowStepResult } from 'src/modules/workflow/workflow-executor/types/workflow-step-result.type';
import { WorkflowCodeStep } from 'src/modules/workflow/workflow-executor/types/workflow-step.type';
import { WorkflowActionResult } from 'src/modules/workflow/workflow-executor/types/workflow-action-result.type';
import { WorkflowCodeStep } from 'src/modules/workflow/workflow-executor/types/workflow-action.type';
import {
WorkflowStepExecutorException,
WorkflowStepExecutorExceptionCode,
} from 'src/modules/workflow/workflow-executor/exceptions/workflow-step-executor.exception';

@Injectable()
export class CodeWorkflowStepExecutor {
export class CodeWorkflowAction {
constructor(
private readonly serverlessFunctionService: ServerlessFunctionService,
private readonly scopedWorkspaceContextFactory: ScopedWorkspaceContextFactory,
Expand All @@ -22,7 +22,7 @@ export class CodeWorkflowStepExecutor {
}: {
step: WorkflowCodeStep;
payload?: object;
}): Promise<WorkflowStepResult> {
}): Promise<WorkflowActionResult> {
const { workspaceId } = this.scopedWorkspaceContextFactory.create();

if (!workspaceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { WorkflowRunWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
import { WorkflowStep } from 'src/modules/workflow/workflow-executor/types/workflow-step.type';
import { WorkflowStep } from 'src/modules/workflow/workflow-executor/types/workflow-action.type';
import { WorkflowTrigger } from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';

export enum WorkflowVersionStatus {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable } from '@nestjs/common';

import { WorkflowAction } from 'src/modules/workflow/workflow-executor/interfaces/workflow-action.interface';

import { WorkflowActionType } from 'src/modules/workflow/workflow-executor/types/workflow-action.type';
import {
WorkflowStepExecutorException,
WorkflowStepExecutorExceptionCode,
} from 'src/modules/workflow/workflow-executor/exceptions/workflow-step-executor.exception';
import { CodeWorkflowAction } from 'src/modules/serverless/workflow-actions/code.workflow-action';
import { SendEmailWorkflowAction } from 'src/modules/mail-sender/workflow-actions/send-email.workflow-action';

@Injectable()
export class WorkflowActionFactory {
constructor(
private readonly codeWorkflowAction: CodeWorkflowAction,
private readonly sendEmailWorkflowAction: SendEmailWorkflowAction,
) {}

get(stepType: WorkflowActionType): WorkflowAction {
switch (stepType) {
case WorkflowActionType.CODE:
return this.codeWorkflowAction;
case WorkflowActionType.SEND_EMAIL:
return this.sendEmailWorkflowAction;
default:
throw new WorkflowStepExecutorException(
`Workflow step executor not found for step type '${stepType}'`,
WorkflowStepExecutorExceptionCode.INVALID_STEP_TYPE,
);
}
}
}
Loading
Loading