Skip to content

The open alternative to Salesforce, designed for AI.

Add workflow runner (#6458)

martmull6b4c79ff0dc1
diff --git a/packages/twenty-front/src/generated-metadata/gql.ts b/packages/twenty-front/src/generated-metadata/gql.ts
index d0d3459d93a..1aca61a965d 100644
--- a/packages/twenty-front/src/generated-metadata/gql.ts
+++ b/packages/twenty-front/src/generated-metadata/gql.ts
@@ -36,7 +36,7 @@ const documents = {
"\n fragment ServerlessFunctionFields on ServerlessFunction {\n id\n name\n description\n sourceCodeHash\n sourceCodeFullPath\n runtime\n syncStatus\n createdAt\n updatedAt\n }\n": types.ServerlessFunctionFieldsFragmentDoc,
"\n \n mutation CreateOneServerlessFunctionItem(\n $input: CreateServerlessFunctionInput!\n ) {\n createOneServerlessFunction(input: $input) {\n ...ServerlessFunctionFields\n }\n }\n": types.CreateOneServerlessFunctionItemDocument,
"\n \n mutation DeleteOneServerlessFunction($input: DeleteServerlessFunctionInput!) {\n deleteOneServerlessFunction(input: $input) {\n ...ServerlessFunctionFields\n }\n }\n": types.DeleteOneServerlessFunctionDocument,
- "\n mutation ExecuteOneServerlessFunction($id: UUID!, $payload: JSON!) {\n executeOneServerlessFunction(id: $id, payload: $payload) {\n result\n }\n }\n": types.ExecuteOneServerlessFunctionDocument,
+ "\n mutation ExecuteOneServerlessFunction($id: UUID!, $payload: JSON!) {\n executeOneServerlessFunction(id: $id, payload: $payload) {\n data\n duration\n status\n error\n }\n }\n": types.ExecuteOneServerlessFunctionDocument,
"\n \n mutation UpdateOneServerlessFunction($input: UpdateServerlessFunctionInput!) {\n updateOneServerlessFunction(input: $input) {\n ...ServerlessFunctionFields\n }\n }\n": types.UpdateOneServerlessFunctionDocument,
"\n \n query GetManyServerlessFunctions {\n serverlessFunctions(paging: { first: 100 }) {\n edges {\n node {\n ...ServerlessFunctionFields\n }\n }\n }\n }\n": types.GetManyServerlessFunctionsDocument,
"\n \n query GetOneServerlessFunction($id: UUID!) {\n serverlessFunction(id: $id) {\n ...ServerlessFunctionFields\n }\n }\n": types.GetOneServerlessFunctionDocument,
@@ -151,7 +151,7 @@ export function graphql(source: "\n \n mutation DeleteOneServerlessFunction($i
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
-export function graphql(source: "\n mutation ExecuteOneServerlessFunction($id: UUID!, $payload: JSON!) {\n executeOneServerlessFunction(id: $id, payload: $payload) {\n result\n }\n }\n"): (typeof documents)["\n mutation ExecuteOneServerlessFunction($id: UUID!, $payload: JSON!) {\n executeOneServerlessFunction(id: $id, payload: $payload) {\n result\n }\n }\n"];
+export function graphql(source: "\n mutation ExecuteOneServerlessFunction($id: UUID!, $payload: JSON!) {\n executeOneServerlessFunction(id: $id, payload: $payload) {\n data\n duration\n status\n error\n }\n }\n"): (typeof documents)["\n mutation ExecuteOneServerlessFunction($id: UUID!, $payload: JSON!) {\n executeOneServerlessFunction(id: $id, payload: $payload) {\n data\n duration\n status\n error\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index 0acd5cac71b..df44e015212 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -442,6 +442,7 @@ export type Mutation = {
disablePostgresProxy: PostgresCredentials;
emailPasswordResetLink: EmailPasswordResetLink;
enablePostgresProxy: PostgresCredentials;
+ enableWorkflowTrigger: Scalars['Boolean']['output'];
exchangeAuthorizationCode: ExchangeAuthCode;
executeOneServerlessFunction: ServerlessFunctionExecutionResult;
generateApiKeyToken: ApiKeyToken;
@@ -455,6 +456,7 @@ export type Mutation = {
syncRemoteTable: RemoteTable;
syncRemoteTableSchemaChanges: RemoteTable;
track: Analytics;
+ triggerWorkflow: WorkflowTriggerResult;
unsyncRemoteTable: RemoteTable;
updateBillingSubscription: UpdateBillingEntity;
updateOneField: Field;
@@ -567,6 +569,11 @@ export type MutationEmailPasswordResetLinkArgs = {
};
+export type MutationEnableWorkflowTriggerArgs = {
+ workflowVersionId: Scalars['String']['input'];
+};
+
+
export type MutationExchangeAuthorizationCodeArgs = {
authorizationCode: Scalars['String']['input'];
clientSecret?: InputMaybe<Scalars['String']['input']>;
@@ -630,6 +637,11 @@ export type MutationTrackArgs = {
};
+export type MutationTriggerWorkflowArgs = {
+ workflowVersionId: Scalars['String']['input'];
+};
+
+
export type MutationUnsyncRemoteTableArgs = {
input: RemoteTableInput;
};
@@ -1003,7 +1015,7 @@ export type Sentry = {
export type ServerlessFunction = {
__typename?: 'ServerlessFunction';
createdAt: Scalars['DateTime']['output'];
- description: Scalars['String']['output'];
+ description?: Maybe<Scalars['String']['output']>;
id: Scalars['UUID']['output'];
name: Scalars['String']['output'];
runtime: Scalars['String']['output'];
@@ -1032,9 +1044,21 @@ export type ServerlessFunctionEdge = {
export type ServerlessFunctionExecutionResult = {
__typename?: 'ServerlessFunctionExecutionResult';
/** Execution result in JSON format */
- result: Scalars['JSON']['output'];
+ data?: Maybe<Scalars['JSON']['output']>;
+ /** Execution duration in milliseconds */
+ duration: Scalars['Float']['output'];
+ /** Execution error in JSON format */
+ error?: Maybe<Scalars['JSON']['output']>;
+ /** Execution status */
+ status: ServerlessFunctionExecutionStatus;
};
+/** Status of the table */
+export enum ServerlessFunctionExecutionStatus {
+ Error = 'ERROR',
+ Success = 'SUCCESS'
+}
+
export type ServerlessFunctionFilter = {
and?: InputMaybe<Array<ServerlessFunctionFilter>>;
id?: InputMaybe<UuidFilterComparison>;
@@ -1333,9 +1357,15 @@ export type Verify = {
user: User;
};
+export type WorkflowTriggerResult = {
+ __typename?: 'WorkflowTriggerResult';
+ /** Execution result in JSON format */
+ result?: Maybe<Scalars['JSON']['output']>;
+};
+
export type Workspace = {
__typename?: 'Workspace';
- activationStatus: Scalars['String']['output'];
+ activationStatus: WorkspaceActivationStatus;
allowImpersonation: Scalars['Boolean']['output'];
billingSubscriptions?: Maybe<Array<BillingSubscription>>;
createdAt: Scalars['DateTime']['output'];
@@ -1364,6 +1394,11 @@ export type WorkspaceFeatureFlagsArgs = {
sorting?: Array<FeatureFlagSort>;
};
+export enum WorkspaceActivationStatus {
+ Active = 'ACTIVE',
+ Inactive = 'INACTIVE'
+}
+
export type WorkspaceEdge = {
__typename?: 'WorkspaceEdge';
/** Cursor for this node. */
@@ -1381,11 +1416,29 @@ export type WorkspaceMember = {
__typename?: 'WorkspaceMember';
avatarUrl?: Maybe<Scalars['String']['output']>;
colorScheme: Scalars['String']['output'];
+ dateFormat?: Maybe<WorkspaceMemberDateFormatEnum>;
id: Scalars['UUID']['output'];
- locale: Scalars['String']['output'];
+ locale?: Maybe<Scalars['String']['output']>;
name: FullName;
+ timeFormat?: Maybe<WorkspaceMemberTimeFormatEnum>;
+ timeZone?: Maybe<Scalars['String']['output']>;
};
+/** Date format as Month first, Day first, Year first or system as default */
+export enum WorkspaceMemberDateFormatEnum {
+ DayFirst = 'DAY_FIRST',
+ MonthFirst = 'MONTH_FIRST',
+ System = 'SYSTEM',
+ YearFirst = 'YEAR_FIRST'
+}
+
+/** Time time as Military, Standard or system as default */
+export enum WorkspaceMemberTimeFormatEnum {
+ Hour_12 = 'HOUR_12',
+ Hour_24 = 'HOUR_24',
+ System = 'SYSTEM'
+}
+
export type Field = {
__typename?: 'field';
createdAt: Scalars['DateTime']['output'];
@@ -1625,21 +1678,21 @@ export type ObjectMetadataItemsQueryVariables = Exact<{
export type ObjectMetadataItemsQuery = { __typename?: 'Query', objects: { __typename?: 'ObjectConnection', edges: Array<{ __typename?: 'objectEdge', node: { __typename?: 'object', id: any, dataSourceId: string, nameSingular: string, namePlural: string, labelSingular: string, labelPlural: string, description?: string | null, icon?: string | null, isCustom: boolean, isRemote: boolean, isActive: boolean, isSystem: boolean, createdAt: any, updatedAt: any, labelIdentifierFieldMetadataId?: string | null, imageIdentifierFieldMetadataId?: string | null, fields: { __typename?: 'ObjectFieldsConnection', edges: Array<{ __typename?: 'fieldEdge', node: { __typename?: 'field', id: any, type: FieldMetadataType, name: string, label: string, description?: string | null, icon?: string | null, isCustom?: boolean | null, isActive?: boolean | null, isSystem?: boolean | null, isNullable?: boolean | null, createdAt: any, updatedAt: any, defaultValue?: any | null, options?: any | null, fromRelationMetadata?: { __typename?: 'relation', id: any, relationType: RelationMetadataType, toFieldMetadataId: string, toObjectMetadata: { __typename?: 'object', id: any, dataSourceId: string, nameSingular: string, namePlural: string, isSystem: boolean, isRemote: boolean } } | null, toRelationMetadata?: { __typename?: 'relation', id: any, relationType: RelationMetadataType, fromFieldMetadataId: string, fromObjectMetadata: { __typename?: 'object', id: any, dataSourceId: string, nameSingular: string, namePlural: string, isSystem: boolean, isRemote: boolean } } | null, relationDefinition?: { __typename?: 'RelationDefinition', relationId: any, direction: RelationDefinitionType, sourceObjectMetadata: { __typename?: 'object', id: any, nameSingular: string, namePlural: string }, sourceFieldMetadata: { __typename?: 'field', id: any, name: string }, targetObjectMetadata: { __typename?: 'object', id: any, nameSingular: string, namePlural: string }, targetFieldMetadata: { __typename?: 'field', id: any, name: string } } | null } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage?: boolean | null, hasPreviousPage?: boolean | null, startCursor?: any | null, endCursor?: any | null } } } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage?: boolean | null, hasPreviousPage?: boolean | null, startCursor?: any | null, endCursor?: any | null } } };
-export type ServerlessFunctionFieldsFragment = { __typename?: 'ServerlessFunction', id: any, name: string, description: string, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any };
+export type ServerlessFunctionFieldsFragment = { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any };
export type CreateOneServerlessFunctionItemMutationVariables = Exact<{
input: CreateServerlessFunctionInput;
}>;
-export type CreateOneServerlessFunctionItemMutation = { __typename?: 'Mutation', createOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description: string, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } };
+export type CreateOneServerlessFunctionItemMutation = { __typename?: 'Mutation', createOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } };
export type DeleteOneServerlessFunctionMutationVariables = Exact<{
input: DeleteServerlessFunctionInput;
}>;
-export type DeleteOneServerlessFunctionMutation = { __typename?: 'Mutation', deleteOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description: string, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } };
+export type DeleteOneServerlessFunctionMutation = { __typename?: 'Mutation', deleteOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } };
export type ExecuteOneServerlessFunctionMutationVariables = Exact<{
id: Scalars['UUID']['input'];
@@ -1647,26 +1700,26 @@ export type ExecuteOneServerlessFunctionMutationVariables = Exact<{
}>;
-export type ExecuteOneServerlessFunctionMutation = { __typename?: 'Mutation', executeOneServerlessFunction: { __typename?: 'ServerlessFunctionExecutionResult', result: any } };
+export type ExecuteOneServerlessFunctionMutation = { __typename?: 'Mutation', executeOneServerlessFunction: { __typename?: 'ServerlessFunctionExecutionResult', data?: any | null, duration: number, status: ServerlessFunctionExecutionStatus, error?: any | null } };
export type UpdateOneServerlessFunctionMutationVariables = Exact<{
input: UpdateServerlessFunctionInput;
}>;
-export type UpdateOneServerlessFunctionMutation = { __typename?: 'Mutation', updateOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description: string, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } };
+export type UpdateOneServerlessFunctionMutation = { __typename?: 'Mutation', updateOneServerlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } };
export type GetManyServerlessFunctionsQueryVariables = Exact<{ [key: string]: never; }>;
-export type GetManyServerlessFunctionsQuery = { __typename?: 'Query', serverlessFunctions: { __typename?: 'ServerlessFunctionConnection', edges: Array<{ __typename?: 'ServerlessFunctionEdge', node: { __typename?: 'ServerlessFunction', id: any, name: string, description: string, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } }> } };
+export type GetManyServerlessFunctionsQuery = { __typename?: 'Query', serverlessFunctions: { __typename?: 'ServerlessFunctionConnection', edges: Array<{ __typename?: 'ServerlessFunctionEdge', node: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } }> } };
export type GetOneServerlessFunctionQueryVariables = Exact<{
id: Scalars['UUID']['input'];
}>;
-export type GetOneServerlessFunctionQuery = { __typename?: 'Query', serverlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description: string, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } };
+export type GetOneServerlessFunctionQuery = { __typename?: 'Query', serverlessFunction: { __typename?: 'ServerlessFunction', id: any, name: string, description?: string | null, sourceCodeHash: string, sourceCodeFullPath: string, runtime: string, syncStatus: ServerlessFunctionSyncStatus, createdAt: any, updatedAt: any } };
export const RemoteServerFieldsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"RemoteServerFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"RemoteServer"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"foreignDataWrapperId"}},{"kind":"Field","name":{"kind":"Name","value":"foreignDataWrapperOptions"}},{"kind":"Field","name":{"kind":"Name","value":"foreignDataWrapperType"}},{"kind":"Field","name":{"kind":"Name","value":"userMappingOptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"user"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"schema"}},{"kind":"Field","name":{"kind":"Name","value":"label"}}]}}]} as unknown as DocumentNode<RemoteServerFieldsFragment, unknown>;
export const RemoteTableFieldsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"RemoteTableFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"RemoteTable"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"schema"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"schemaPendingUpdates"}}]}}]} as unknown as DocumentNode<RemoteTableFieldsFragment, unknown>;
@@ -1691,7 +1744,7 @@ export const DeleteOneRelationMetadataItemDocument = {"kind":"Document","definit
export const ObjectMetadataItemsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ObjectMetadataItems"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"objectFilter"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"objectFilter"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"fieldFilter"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"fieldFilter"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"objects"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"paging"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"first"},"value":{"kind":"IntValue","value":"1000"}}]}},{"kind":"Argument","name":{"kind":"Name","value":"filter"},"value":{"kind":"Variable","name":{"kind":"Name","value":"objectFilter"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"dataSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}},{"kind":"Field","name":{"kind":"Name","value":"labelSingular"}},{"kind":"Field","name":{"kind":"Name","value":"labelPlural"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"isRemote"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"labelIdentifierFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"imageIdentifierFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"paging"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"first"},"value":{"kind":"IntValue","value":"1000"}}]}},{"kind":"Argument","name":{"kind":"Name","value":"filter"},"value":{"kind":"Variable","name":{"kind":"Name","value":"fieldFilter"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isNullable"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"fromRelationMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"relationType"}},{"kind":"Field","name":{"kind":"Name","value":"toObjectMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"dataSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isRemote"}}]}},{"kind":"Field","name":{"kind":"Name","value":"toFieldMetadataId"}}]}},{"kind":"Field","name":{"kind":"Name","value":"toRelationMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"relationType"}},{"kind":"Field","name":{"kind":"Name","value":"fromObjectMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"dataSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isRemote"}}]}},{"kind":"Field","name":{"kind":"Name","value":"fromFieldMetadataId"}}]}},{"kind":"Field","name":{"kind":"Name","value":"defaultValue"}},{"kind":"Field","name":{"kind":"Name","value":"options"}},{"kind":"Field","name":{"kind":"Name","value":"relationDefinition"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"relationId"}},{"kind":"Field","name":{"kind":"Name","value":"direction"}},{"kind":"Field","name":{"kind":"Name","value":"sourceObjectMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}}]}},{"kind":"Field","name":{"kind":"Name","value":"sourceFieldMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"targetObjectMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}}]}},{"kind":"Field","name":{"kind":"Name","value":"targetFieldMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"hasPreviousPage"}},{"kind":"Field","name":{"kind":"Name","value":"startCursor"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"hasPreviousPage"}},{"kind":"Field","name":{"kind":"Name","value":"startCursor"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}}]}}]}}]} as unknown as DocumentNode<ObjectMetadataItemsQuery, ObjectMetadataItemsQueryVariables>;
export const CreateOneServerlessFunctionItemDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateOneServerlessFunctionItem"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateServerlessFunctionInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createOneServerlessFunction"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ServerlessFunctionFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ServerlessFunctionFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerlessFunction"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeHash"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeFullPath"}},{"kind":"Field","name":{"kind":"Name","value":"runtime"}},{"kind":"Field","name":{"kind":"Name","value":"syncStatus"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<CreateOneServerlessFunctionItemMutation, CreateOneServerlessFunctionItemMutationVariables>;
export const DeleteOneServerlessFunctionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteOneServerlessFunction"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"DeleteServerlessFunctionInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteOneServerlessFunction"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ServerlessFunctionFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ServerlessFunctionFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerlessFunction"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeHash"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeFullPath"}},{"kind":"Field","name":{"kind":"Name","value":"runtime"}},{"kind":"Field","name":{"kind":"Name","value":"syncStatus"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<DeleteOneServerlessFunctionMutation, DeleteOneServerlessFunctionMutationVariables>;
-export const ExecuteOneServerlessFunctionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"ExecuteOneServerlessFunction"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"payload"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"JSON"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"executeOneServerlessFunction"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}},{"kind":"Argument","name":{"kind":"Name","value":"payload"},"value":{"kind":"Variable","name":{"kind":"Name","value":"payload"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"result"}}]}}]}}]} as unknown as DocumentNode<ExecuteOneServerlessFunctionMutation, ExecuteOneServerlessFunctionMutationVariables>;
+export const ExecuteOneServerlessFunctionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"ExecuteOneServerlessFunction"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"payload"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"JSON"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"executeOneServerlessFunction"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}},{"kind":"Argument","name":{"kind":"Name","value":"payload"},"value":{"kind":"Variable","name":{"kind":"Name","value":"payload"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"data"}},{"kind":"Field","name":{"kind":"Name","value":"duration"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"error"}}]}}]}}]} as unknown as DocumentNode<ExecuteOneServerlessFunctionMutation, ExecuteOneServerlessFunctionMutationVariables>;
export const UpdateOneServerlessFunctionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateOneServerlessFunction"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateServerlessFunctionInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateOneServerlessFunction"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ServerlessFunctionFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ServerlessFunctionFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerlessFunction"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeHash"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeFullPath"}},{"kind":"Field","name":{"kind":"Name","value":"runtime"}},{"kind":"Field","name":{"kind":"Name","value":"syncStatus"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<UpdateOneServerlessFunctionMutation, UpdateOneServerlessFunctionMutationVariables>;
export const GetManyServerlessFunctionsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetManyServerlessFunctions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"serverlessFunctions"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"paging"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"first"},"value":{"kind":"IntValue","value":"100"}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ServerlessFunctionFields"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ServerlessFunctionFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerlessFunction"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeHash"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeFullPath"}},{"kind":"Field","name":{"kind":"Name","value":"runtime"}},{"kind":"Field","name":{"kind":"Name","value":"syncStatus"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<GetManyServerlessFunctionsQuery, GetManyServerlessFunctionsQueryVariables>;
-export const GetOneServerlessFunctionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOneServerlessFunction"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"serverlessFunction"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ServerlessFunctionFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ServerlessFunctionFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerlessFunction"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeHash"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeFullPath"}},{"kind":"Field","name":{"kind":"Name","value":"runtime"}},{"kind":"Field","name":{"kind":"Name","value":"syncStatus"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<GetOneServerlessFunctionQuery, GetOneServerlessFunctionQueryVariables>;
+export const GetOneServerlessFunctionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOneServerlessFunction"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"serverlessFunction"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ServerlessFunctionFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ServerlessFunctionFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerlessFunction"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeHash"}},{"kind":"Field","name":{"kind":"Name","value":"sourceCodeFullPath"}},{"kind":"Field","name":{"kind":"Name","value":"runtime"}},{"kind":"Field","name":{"kind":"Name","value":"syncStatus"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<GetOneServerlessFunctionQuery, GetOneServerlessFunctionQueryVariables>;
\ No newline at end of file
diff --git a/packages/twenty-front/src/modules/settings/serverless-functions/components/SettingsServerlessFunctionsOutputMetadataInfo.tsx b/packages/twenty-front/src/modules/settings/serverless-functions/components/SettingsServerlessFunctionsOutputMetadataInfo.tsx
new file mode 100644
index 00000000000..b8e26097b30
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/serverless-functions/components/SettingsServerlessFunctionsOutputMetadataInfo.tsx
@@ -0,0 +1,39 @@
+import { useRecoilValue } from 'recoil';
+import {
+ DEFAULT_OUTPUT_VALUE,
+ settingsServerlessFunctionOutputState,
+} from '@/settings/serverless-functions/states/settingsServerlessFunctionOutputState';
+import styled from '@emotion/styled';
+import { IconSquareRoundedCheck } from 'twenty-ui';
+import { useTheme } from '@emotion/react';
+import { ServerlessFunctionExecutionStatus } from '~/generated-metadata/graphql';
+
+const StyledOutput = styled.div<{ status?: ServerlessFunctionExecutionStatus }>`
+ align-items: center;
+ gap: ${({ theme }) => theme.spacing(1)};
+ color: ${({ theme, status }) =>
+ status === ServerlessFunctionExecutionStatus.Success
+ ? theme.color.turquoise
+ : theme.color.red};
+ display: flex;
+`;
+
+export const SettingsServerlessFunctionsOutputMetadataInfo = () => {
+ const theme = useTheme();
+ const settingsServerlessFunctionOutput = useRecoilValue(
+ settingsServerlessFunctionOutputState,
+ );
+ return settingsServerlessFunctionOutput.data === DEFAULT_OUTPUT_VALUE ? (
+ 'Output'
+ ) : (
+ <StyledOutput status={settingsServerlessFunctionOutput.status}>
+ <IconSquareRoundedCheck size={theme.icon.size.md} />
+ {settingsServerlessFunctionOutput.status ===
+ ServerlessFunctionExecutionStatus.Success
+ ? '200 OK'
+ : '500 Error'}
+ {' - '}
+ {settingsServerlessFunctionOutput.duration}ms
+ </StyledOutput>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTab.tsx b/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTab.tsx
index d6209611243..68d61dcd5a1 100644
--- a/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTab.tsx
+++ b/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTab.tsx
@@ -10,6 +10,7 @@ import { useRecoilState, useRecoilValue } from 'recoil';
import { settingsServerlessFunctionOutputState } from '@/settings/serverless-functions/states/settingsServerlessFunctionOutputState';
import { settingsServerlessFunctionInputState } from '@/settings/serverless-functions/states/settingsServerlessFunctionInputState';
import { settingsServerlessFunctionCodeEditorOutputParamsState } from '@/settings/serverless-functions/states/settingsServerlessFunctionCodeEditorOutputParamsState';
+import { SettingsServerlessFunctionsOutputMetadataInfo } from '@/settings/serverless-functions/components/SettingsServerlessFunctionsOutputMetadataInfo';
const StyledInputsContainer = styled.div`
display: flex;
@@ -31,27 +32,32 @@ export const SettingsServerlessFunctionTestTab = ({
const [settingsServerlessFunctionInput, setSettingsServerlessFunctionInput] =
useRecoilState(settingsServerlessFunctionInputState);
- const InputHeaderButton = (
- <Button
- title="Run Function"
- variant="primary"
- accent="blue"
- size="small"
- Icon={IconPlayerPlay}
- onClick={handleExecute}
- />
- );
+ const result =
+ settingsServerlessFunctionOutput.data ||
+ settingsServerlessFunctionOutput.error ||
+ '';
const InputHeader = (
- <CoreEditorHeader title={'Input'} rightNodes={[InputHeaderButton]} />
- );
-
- const OutputHeaderButton = (
- <LightCopyIconButton copyText={settingsServerlessFunctionOutput} />
+ <CoreEditorHeader
+ title={'Input'}
+ rightNodes={[
+ <Button
+ title="Run Function"
+ variant="primary"
+ accent="blue"
+ size="small"
+ Icon={IconPlayerPlay}
+ onClick={handleExecute}
+ />,
+ ]}
+ />
);
const OutputHeader = (
- <CoreEditorHeader title={'Output'} rightNodes={[OutputHeaderButton]} />
+ <CoreEditorHeader
+ leftNodes={[<SettingsServerlessFunctionsOutputMetadataInfo />]}
+ rightNodes={[<LightCopyIconButton copyText={result} />]}
+ />
);
return (
@@ -69,7 +75,7 @@ export const SettingsServerlessFunctionTestTab = ({
header={InputHeader}
/>
<CodeEditor
- value={settingsServerlessFunctionOutput}
+ value={result}
height={settingsServerlessFunctionCodeEditorOutputParams.height}
language={settingsServerlessFunctionCodeEditorOutputParams.language}
options={{ readOnly: true, domReadOnly: true }}
diff --git a/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTabEffect.tsx b/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTabEffect.tsx
index 67ac1e7ea84..64cff208b49 100644
--- a/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTabEffect.tsx
+++ b/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTabEffect.tsx
@@ -1,6 +1,9 @@
import React from 'react';
import { useRecoilValue, useSetRecoilState } from 'recoil';
-import { settingsServerlessFunctionOutputState } from '@/settings/serverless-functions/states/settingsServerlessFunctionOutputState';
+import {
+ DEFAULT_OUTPUT_VALUE,
+ settingsServerlessFunctionOutputState,
+} from '@/settings/serverless-functions/states/settingsServerlessFunctionOutputState';
import { settingsServerlessFunctionCodeEditorOutputParamsState } from '@/settings/serverless-functions/states/settingsServerlessFunctionCodeEditorOutputParamsState';
export const SettingsServerlessFunctionTestTabEffect = () => {
@@ -10,14 +13,11 @@ export const SettingsServerlessFunctionTestTabEffect = () => {
const setSettingsServerlessFunctionCodeEditorOutputParams = useSetRecoilState(
settingsServerlessFunctionCodeEditorOutputParamsState,
);
- try {
- JSON.parse(settingsServerlessFunctionOutput);
+ if (settingsServerlessFunctionOutput.data !== DEFAULT_OUTPUT_VALUE) {
setSettingsServerlessFunctionCodeEditorOutputParams({
language: 'json',
height: 300,
});
- } catch {
- return <></>;
}
return <></>;
};
diff --git a/packages/twenty-front/src/modules/settings/serverless-functions/graphql/mutations/executeOneServerlessFunction.ts b/packages/twenty-front/src/modules/settings/serverless-functions/graphql/mutations/executeOneServerlessFunction.ts
index 050ac816e96..9054e26abcb 100644
--- a/packages/twenty-front/src/modules/settings/serverless-functions/graphql/mutations/executeOneServerlessFunction.ts
+++ b/packages/twenty-front/src/modules/settings/serverless-functions/graphql/mutations/executeOneServerlessFunction.ts
@@ -3,7 +3,10 @@ import { gql } from '@apollo/client';
export const EXECUTE_ONE_SERVERLESS_FUNCTION = gql`
mutation ExecuteOneServerlessFunction($id: UUID!, $payload: JSON!) {
executeOneServerlessFunction(id: $id, payload: $payload) {
- result
+ data
+ duration
+ status
+ error
}
}
`;
diff --git a/packages/twenty-front/src/modules/settings/serverless-functions/states/settingsServerlessFunctionOutputState.ts b/packages/twenty-front/src/modules/settings/serverless-functions/states/settingsServerlessFunctionOutputState.ts
index 40a3237dbb1..385109961db 100644
--- a/packages/twenty-front/src/modules/settings/serverless-functions/states/settingsServerlessFunctionOutputState.ts
+++ b/packages/twenty-front/src/modules/settings/serverless-functions/states/settingsServerlessFunctionOutputState.ts
@@ -1,6 +1,18 @@
import { createState } from 'twenty-ui';
+import { ServerlessFunctionExecutionStatus } from '~/generated-metadata/graphql';
-export const settingsServerlessFunctionOutputState = createState<string>({
- key: 'settingsServerlessFunctionOutputState',
- defaultValue: 'Enter an input above then press "run Function"',
-});
+type settingsServerlessFunctionOutput = {
+ data?: string;
+ duration?: number;
+ status?: ServerlessFunctionExecutionStatus;
+ error?: string;
+};
+
+export const DEFAULT_OUTPUT_VALUE =
+ 'Enter an input above then press "run Function"';
+
+export const settingsServerlessFunctionOutputState =
+ createState<settingsServerlessFunctionOutput>({
+ key: 'settingsServerlessFunctionOutputState',
+ defaultValue: { data: DEFAULT_OUTPUT_VALUE },
+ });
diff --git a/packages/twenty-front/src/pages/settings/serverless-functions/SettingsServerlessFunctionDetail.tsx b/packages/twenty-front/src/pages/settings/serverless-functions/SettingsServerlessFunctionDetail.tsx
index b20dbd389d2..afb03cd87a5 100644
--- a/packages/twenty-front/src/pages/settings/serverless-functions/SettingsServerlessFunctionDetail.tsx
+++ b/packages/twenty-front/src/pages/settings/serverless-functions/SettingsServerlessFunctionDetail.tsx
@@ -78,13 +78,24 @@ export const SettingsServerlessFunctionDetail = () => {
serverlessFunctionId,
JSON.parse(settingsServerlessFunctionInput),
);
- setSettingsServerlessFunctionOutput(
- JSON.stringify(
- result?.data?.executeOneServerlessFunction?.result,
- null,
- 4,
- ),
- );
+ setSettingsServerlessFunctionOutput({
+ data: result?.data?.executeOneServerlessFunction?.data
+ ? JSON.stringify(
+ result?.data?.executeOneServerlessFunction?.data,
+ null,
+ 4,
+ )
+ : undefined,
+ duration: result?.data?.executeOneServerlessFunction?.duration,
+ status: result?.data?.executeOneServerlessFunction?.status,
+ error: result?.data?.executeOneServerlessFunction?.error
+ ? JSON.stringify(
+ result?.data?.executeOneServerlessFunction?.error,
+ null,
+ 4,
+ )
+ : undefined,
+ });
} catch (err) {
enqueueSnackBar(
(err as Error)?.message || 'An error occurred while executing function',
@@ -92,7 +103,6 @@ export const SettingsServerlessFunctionDetail = () => {
variant: SnackBarVariant.Error,
},
);
- setSettingsServerlessFunctionOutput(JSON.stringify(err, null, 4));
}
setActiveTabId('test');
};
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/dtos/workflow-trigger-result.dto.ts b/packages/twenty-server/src/engine/core-modules/workflow/dtos/workflow-trigger-result.dto.ts
new file mode 100644
index 00000000000..d5433e5b1a7
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/workflow/dtos/workflow-trigger-result.dto.ts
@@ -0,0 +1,14 @@
+import { Field, ObjectType } from '@nestjs/graphql';
+
+import { IsObject } from 'class-validator';
+import graphqlTypeJson from 'graphql-type-json';
+
+@ObjectType('WorkflowTriggerResult')
+export class WorkflowTriggerResultDTO {
+ @IsObject()
+ @Field(() => graphqlTypeJson, {
+ description: 'Execution result in JSON format',
+ nullable: true,
+ })
+ result?: JSON;
+}
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/utils/workflow-trigger-graphql-api-exception-handler.util.ts b/packages/twenty-server/src/engine/core-modules/workflow/utils/workflow-trigger-graphql-api-exception-handler.util.ts
index de2fb83eb94..e3ac10a136c 100644
--- a/packages/twenty-server/src/engine/core-modules/workflow/utils/workflow-trigger-graphql-api-exception-handler.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/workflow/utils/workflow-trigger-graphql-api-exception-handler.util.ts
@@ -14,6 +14,7 @@ export const workflowTriggerGraphqlApiExceptionHandler = (error: Error) => {
throw new UserInputError(error.message);
case WorkflowTriggerExceptionCode.INVALID_WORKFLOW_TRIGGER:
case WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION:
+ case WorkflowTriggerExceptionCode.INVALID_ACTION_TYPE:
default:
throw new InternalServerError(error.message);
}
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/workflow-trigger.module.ts b/packages/twenty-server/src/engine/core-modules/workflow/workflow-trigger.module.ts
index 5b56f7baaff..4b4d66018ca 100644
--- a/packages/twenty-server/src/engine/core-modules/workflow/workflow-trigger.module.ts
+++ b/packages/twenty-server/src/engine/core-modules/workflow/workflow-trigger.module.ts
@@ -1,9 +1,12 @@
import { Module } from '@nestjs/common';
import { WorkflowTriggerResolver } from 'src/engine/core-modules/workflow/workflow-trigger.resolver';
+import { WorkflowCommonModule } from 'src/modules/workflow/common/workflow-common.module';
import { WorkflowTriggerService } from 'src/modules/workflow/workflow-trigger/workflow-trigger.service';
+import { WorkflowRunnerModule } from 'src/modules/workflow/workflow-runner/workflow-runner.module';
@Module({
+ imports: [WorkflowCommonModule, WorkflowRunnerModule],
providers: [WorkflowTriggerService, WorkflowTriggerResolver],
})
export class WorkflowTriggerModule {}
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/workflow-trigger.resolver.ts b/packages/twenty-server/src/engine/core-modules/workflow/workflow-trigger.resolver.ts
index e66784d08e5..5c39f4605d8 100644
--- a/packages/twenty-server/src/engine/core-modules/workflow/workflow-trigger.resolver.ts
+++ b/packages/twenty-server/src/engine/core-modules/workflow/workflow-trigger.resolver.ts
@@ -6,6 +6,7 @@ import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
import { JwtAuthGuard } from 'src/engine/guards/jwt.auth.guard';
import { WorkflowTriggerService } from 'src/modules/workflow/workflow-trigger/workflow-trigger.service';
+import { WorkflowTriggerResultDTO } from 'src/engine/core-modules/workflow/dtos/workflow-trigger-result.dto';
@UseGuards(JwtAuthGuard)
@Resolver()
@@ -28,4 +29,21 @@ export class WorkflowTriggerResolver {
workflowTriggerGraphqlApiExceptionHandler(error);
}
}
+
+ @Mutation(() => WorkflowTriggerResultDTO)
+ async triggerWorkflow(
+ @AuthWorkspace() { id: workspaceId }: Workspace,
+ @Args('workflowVersionId') workflowVersionId: string,
+ ) {
+ try {
+ return {
+ result: await this.workflowTriggerService.runWorkflow(
+ workspaceId,
+ workflowVersionId,
+ ),
+ };
+ } catch (error) {
+ workflowTriggerGraphqlApiExceptionHandler(error);
+ }
+ }
}
diff --git a/packages/twenty-server/src/engine/integrations/message-queue/message-queue.constants.ts b/packages/twenty-server/src/engine/integrations/message-queue/message-queue.constants.ts
index e78cc50939b..55e36c79935 100644
--- a/packages/twenty-server/src/engine/integrations/message-queue/message-queue.constants.ts
+++ b/packages/twenty-server/src/engine/integrations/message-queue/message-queue.constants.ts
@@ -16,4 +16,5 @@ export enum MessageQueue {
recordPositionBackfillQueue = 'record-position-backfill-queue',
entityEventsToDbQueue = 'entity-events-to-db-queue',
testQueue = 'test-queue',
+ workflowQueue = 'workflow-queue',
}
diff --git a/packages/twenty-server/src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface.ts b/packages/twenty-server/src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface.ts
index c15eb07ca45..21f87ef926d 100644
--- a/packages/twenty-server/src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface.ts
+++ b/packages/twenty-server/src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface.ts
@@ -1,4 +1,18 @@
import { ServerlessFunctionEntity } from 'src/engine/metadata-modules/serverless-function/serverless-function.entity';
+import { ServerlessFunctionExecutionStatus } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto';
+
+export type ServerlessExecuteError = {
+ errorType: string;
+ errorMessage: string;
+ stackTrace: string;
+};
+
+export type ServerlessExecuteResult = {
+ data: object | null;
+ duration: number;
+ status: ServerlessFunctionExecutionStatus;
+ error?: ServerlessExecuteError;
+};
export interface ServerlessDriver {
delete(serverlessFunction: ServerlessFunctionEntity): Promise<void>;
@@ -6,5 +20,5 @@ export interface ServerlessDriver {
execute(
serverlessFunction: ServerlessFunctionEntity,
payload: object | undefined,
- ): Promise<object>;
+ ): Promise<ServerlessExecuteResult>;
}
diff --git a/packages/twenty-server/src/engine/integrations/serverless/drivers/lambda.driver.ts b/packages/twenty-server/src/engine/integrations/serverless/drivers/lambda.driver.ts
index 9820aa8d8b8..4889ff0fcb1 100644
--- a/packages/twenty-server/src/engine/integrations/serverless/drivers/lambda.driver.ts
+++ b/packages/twenty-server/src/engine/integrations/serverless/drivers/lambda.driver.ts
@@ -13,13 +13,17 @@ import {
import { CreateFunctionCommandInput } from '@aws-sdk/client-lambda/dist-types/commands/CreateFunctionCommand';
import { UpdateFunctionCodeCommandInput } from '@aws-sdk/client-lambda/dist-types/commands/UpdateFunctionCodeCommand';
-import { ServerlessDriver } from 'src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface';
+import {
+ ServerlessDriver,
+ ServerlessExecuteResult,
+} from 'src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface';
import { createZipFile } from 'src/engine/integrations/serverless/drivers/utils/create-zip-file';
import { ServerlessFunctionEntity } from 'src/engine/metadata-modules/serverless-function/serverless-function.entity';
import { FileStorageService } from 'src/engine/integrations/file-storage/file-storage.service';
import { BaseServerlessDriver } from 'src/engine/integrations/serverless/drivers/base-serverless.driver';
import { BuildDirectoryManagerService } from 'src/engine/integrations/serverless/drivers/services/build-directory-manager.service';
+import { ServerlessFunctionExecutionStatus } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto';
export interface LambdaDriverOptions extends LambdaClientConfig {
fileStorageService: FileStorageService;
@@ -134,7 +138,8 @@ export class LambdaDriver
async execute(
functionToExecute: ServerlessFunctionEntity,
payload: object | undefined = undefined,
- ): Promise<object> {
+ ): Promise<ServerlessExecuteResult> {
+ const startTime = Date.now();
const params = {
FunctionName: functionToExecute.id,
Payload: JSON.stringify(payload),
@@ -144,10 +149,25 @@ export class LambdaDriver
const result = await this.lambdaClient.send(command);
- if (!result.Payload) {
- return {};
+ const parsedResult = result.Payload
+ ? JSON.parse(result.Payload.transformToString())
+ : {};
+
+ const duration = Date.now() - startTime;
+
+ if (result.FunctionError) {
+ return {
+ data: null,
+ duration,
+ status: ServerlessFunctionExecutionStatus.ERROR,
+ error: parsedResult,
+ };
}
- return JSON.parse(result.Payload.transformToString());
+ return {
+ data: parsedResult,
+ duration,
+ status: ServerlessFunctionExecutionStatus.SUCCESS,
+ };
}
}
diff --git a/packages/twenty-server/src/engine/integrations/serverless/drivers/local.driver.ts b/packages/twenty-server/src/engine/integrations/serverless/drivers/local.driver.ts
index 5f661b4938c..c811426b3cd 100644
--- a/packages/twenty-server/src/engine/integrations/serverless/drivers/local.driver.ts
+++ b/packages/twenty-server/src/engine/integrations/serverless/drivers/local.driver.ts
@@ -5,13 +5,18 @@ import { fork } from 'child_process';
import { v4 } from 'uuid';
-import { ServerlessDriver } from 'src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface';
+import {
+ ServerlessDriver,
+ ServerlessExecuteError,
+ ServerlessExecuteResult,
+} from 'src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface';
import { FileStorageService } from 'src/engine/integrations/file-storage/file-storage.service';
import { readFileContent } from 'src/engine/integrations/file-storage/utils/read-file-content';
import { ServerlessFunctionEntity } from 'src/engine/metadata-modules/serverless-function/serverless-function.entity';
import { BUILD_FILE_NAME } from 'src/engine/integrations/serverless/drivers/constants/build-file-name';
import { BaseServerlessDriver } from 'src/engine/integrations/serverless/drivers/base-serverless.driver';
+import { ServerlessFunctionExecutionStatus } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto';
export interface LocalDriverOptions {
fileStorageService: FileStorageService;
@@ -51,7 +56,8 @@ export class LocalDriver
async execute(
serverlessFunction: ServerlessFunctionEntity,
payload: object | undefined = undefined,
- ): Promise<object> {
+ ): Promise<ServerlessExecuteResult> {
+ const startTime = Date.now();
const fileStream = await this.fileStorageService.read({
folderPath: this.getFolderPath(serverlessFunction),
filename: BUILD_FILE_NAME,
@@ -83,8 +89,23 @@ export class LocalDriver
return await new Promise((resolve, reject) => {
const child = fork(tmpFilePath, { silent: true });
- child.on('message', (message: object) => {
- resolve(message);
+ child.on('message', (message: object | ServerlessExecuteError) => {
+ const duration = Date.now() - startTime;
+
+ if ('errorType' in message) {
+ resolve({
+ data: null,
+ duration,
+ error: message,
+ status: ServerlessFunctionExecutionStatus.ERROR,
+ });
+ } else {
+ resolve({
+ data: message,
+ duration,
+ status: ServerlessFunctionExecutionStatus.SUCCESS,
+ });
+ }
child.kill();
fs.unlink(tmpFilePath);
});
@@ -93,8 +114,8 @@ export class LocalDriver
const stackTrace = data
.toString()
.split('\n')
- .filter((line) => line.trim() !== '');
- const errorTrace = stackTrace.filter((line) =>
+ .filter((line: string) => line.trim() !== '');
+ const errorTrace = stackTrace.filter((line: string) =>
line.includes('Error: '),
)?.[0];
@@ -105,11 +126,17 @@ export class LocalDriver
errorType = errorTrace.split(':')[0];
errorMessage = errorTrace.split(': ')[1];
}
+ const duration = Date.now() - startTime;
resolve({
- errorType,
- errorMessage,
- stackTrace: stackTrace,
+ data: null,
+ duration,
+ status: ServerlessFunctionExecutionStatus.ERROR,
+ error: {
+ errorType,
+ errorMessage,
+ stackTrace: stackTrace,
+ },
});
child.kill();
fs.unlink(tmpFilePath);
diff --git a/packages/twenty-server/src/engine/integrations/serverless/serverless.service.ts b/packages/twenty-server/src/engine/integrations/serverless/serverless.service.ts
index 372b2cb3b55..4ca59624575 100644
--- a/packages/twenty-server/src/engine/integrations/serverless/serverless.service.ts
+++ b/packages/twenty-server/src/engine/integrations/serverless/serverless.service.ts
@@ -1,6 +1,9 @@
import { Inject, Injectable } from '@nestjs/common';
-import { ServerlessDriver } from 'src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface';
+import {
+ ServerlessDriver,
+ ServerlessExecuteResult,
+} from 'src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface';
import { SERVERLESS_DRIVER } from 'src/engine/integrations/serverless/serverless.constants';
import { ServerlessFunctionEntity } from 'src/engine/metadata-modules/serverless-function/serverless-function.entity';
@@ -20,7 +23,7 @@ export class ServerlessService implements ServerlessDriver {
async execute(
serverlessFunction: ServerlessFunctionEntity,
payload: object | undefined = undefined,
- ) {
+ ): Promise<ServerlessExecuteResult> {
return this.driver.execute(serverlessFunction, payload);
}
}
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto.ts
index 06caa4042fe..cbd87a3dcc2 100644
--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto.ts
@@ -1,13 +1,44 @@
-import { Field, ObjectType } from '@nestjs/graphql';
+import { Field, ObjectType, registerEnumType } from '@nestjs/graphql';
-import { IsObject } from 'class-validator';
+import { IsObject, IsOptional } from 'class-validator';
import graphqlTypeJson from 'graphql-type-json';
+export enum ServerlessFunctionExecutionStatus {
+ SUCCESS = 'SUCCESS',
+ ERROR = 'ERROR',
+}
+
+registerEnumType(ServerlessFunctionExecutionStatus, {
+ name: 'ServerlessFunctionExecutionStatus',
+ description: 'Status of the serverless function execution',
+});
+
@ObjectType('ServerlessFunctionExecutionResult')
-export class ServerlessFunctionExecutionResultDto {
+export class ServerlessFunctionExecutionResultDTO {
@IsObject()
@Field(() => graphqlTypeJson, {
description: 'Execution result in JSON format',
+ nullable: true,
+ })
+ data?: JSON;
+
+ @Field({ description: 'Execution duration in milliseconds' })
+ duration: number;
+
+ @Field(() => ServerlessFunctionExecutionStatus, {
+ description: 'Execution status',
+ })
+ status: ServerlessFunctionExecutionStatus;
+
+ @IsObject()
+ @IsOptional()
+ @Field(() => graphqlTypeJson, {
+ description: 'Execution error in JSON format',
+ nullable: true,
})
- result: JSON;
+ error?: {
+ errorType: string;
+ errorMessage: string;
+ stackTrace: string;
+ };
}
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts
index df293846c48..3d348fdb336 100644
--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts
@@ -36,7 +36,7 @@ registerEnumType(ServerlessFunctionSyncStatus, {
defaultResultSize: 10,
maxResultsSize: 1000,
})
-export class ServerlessFunctionDto {
+export class ServerlessFunctionDTO {
@IsUUID()
@IsNotEmpty()
@IDField(() => UUIDScalarType)
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts
index 25a4714103e..5f2d3ac85a7 100644
--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts
@@ -13,7 +13,7 @@ import { ServerlessModule } from 'src/engine/integrations/serverless/serverless.
import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
import { ServerlessFunctionResolver } from 'src/engine/metadata-modules/serverless-function/serverless-function.resolver';
import { JwtAuthGuard } from 'src/engine/guards/jwt.auth.guard';
-import { ServerlessFunctionDto } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto';
+import { ServerlessFunctionDTO } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto';
import { FileUploadModule } from 'src/engine/core-modules/file/file-upload/file-upload.module';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
@@ -32,7 +32,7 @@ import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-
resolvers: [
{
EntityClass: ServerlessFunctionEntity,
- DTOClass: ServerlessFunctionDto,
+ DTOClass: ServerlessFunctionDTO,
ServiceClass: ServerlessFunctionService,
pagingStrategy: PagingStrategies.CURSOR,
read: {
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.resolver.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.resolver.ts
index 7b84cbf768e..9e59b0bf520 100644
--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.resolver.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.resolver.ts
@@ -14,8 +14,8 @@ import { CreateServerlessFunctionFromFileInput } from 'src/engine/metadata-modul
import { CreateServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/create-serverless-function.input';
import { DeleteServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/delete-serverless-function.input';
import { ExecuteServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/execute-serverless-function.input';
-import { ServerlessFunctionExecutionResultDto } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto';
-import { ServerlessFunctionDto } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto';
+import { ServerlessFunctionExecutionResultDTO } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-execution-result.dto';
+import { ServerlessFunctionDTO } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto';
import { UpdateServerlessFunctionInput } from 'src/engine/metadata-modules/serverless-function/dtos/update-serverless-function.input';
import {
ServerlessFunctionException,
@@ -49,7 +49,7 @@ export class ServerlessFunctionResolver {
}
}
- @Mutation(() => ServerlessFunctionDto)
+ @Mutation(() => ServerlessFunctionDTO)
async deleteOneServerlessFunction(
@Args('input') input: DeleteServerlessFunctionInput,
@AuthWorkspace() { id: workspaceId }: Workspace,
@@ -66,7 +66,7 @@ export class ServerlessFunctionResolver {
}
}
- @Mutation(() => ServerlessFunctionDto)
+ @Mutation(() => ServerlessFunctionDTO)
async updateOneServerlessFunction(
@Args('input')
input: UpdateServerlessFunctionInput,
@@ -84,7 +84,7 @@ export class ServerlessFunctionResolver {
}
}
- @Mutation(() => ServerlessFunctionDto)
+ @Mutation(() => ServerlessFunctionDTO)
async createOneServerlessFunction(
@Args('input')
input: CreateServerlessFunctionInput,
@@ -106,7 +106,7 @@ export class ServerlessFunctionResolver {
}
}
- @Mutation(() => ServerlessFunctionDto)
+ @Mutation(() => ServerlessFunctionDTO)
async createOneServerlessFunctionFromFile(
@Args({ name: 'file', type: () => GraphQLUpload })
file: FileUpload,
@@ -127,7 +127,7 @@ export class ServerlessFunctionResolver {
}
}
- @Mutation(() => ServerlessFunctionExecutionResultDto)
+ @Mutation(() => ServerlessFunctionExecutionResultDTO)
async executeOneServerlessFunction(
@Args() executeServerlessFunctionInput: ExecuteServerlessFunctionInput,
@AuthWorkspace() { id: workspaceId }: Workspace,
@@ -136,13 +136,11 @@ export class ServerlessFunctionResolver {
await this.checkFeatureFlag(workspaceId);
const { id, payload } = executeServerlessFunctionInput;
- return {
- result: await this.serverlessFunctionService.executeOne(
- id,
- workspaceId,
- payload,
- ),
- };
+ return await this.serverlessFunctionService.executeOne(
+ id,
+ workspaceId,
+ payload,
+ );
} catch (error) {
serverlessFunctionGraphQLApiExceptionHandler(error);
}
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
index 01881cfb1af..2fa2e0b8e36 100644
--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
@@ -9,6 +9,7 @@ import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
import { v4 } from 'uuid';
import { FileFolder } from 'src/engine/core-modules/file/interfaces/file-folder.interface';
+import { ServerlessExecuteResult } from 'src/engine/integrations/serverless/drivers/interfaces/serverless-driver.interface';
import { ServerlessService } from 'src/engine/integrations/serverless/serverless.service';
import {
@@ -41,7 +42,7 @@ export class ServerlessFunctionService extends TypeOrmQueryService<ServerlessFun
id: string,
workspaceId: string,
payload: object | undefined = undefined,
- ) {
+ ): Promise<ServerlessExecuteResult> {
const functionToExecute = await this.serverlessFunctionRepository.findOne({
where: {
id,
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-objects/index.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-objects/index.ts
index 87d8813b2ca..b0f3ba66312 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-objects/index.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-objects/index.ts
@@ -26,9 +26,9 @@ import { ViewFilterWorkspaceEntity } from 'src/modules/view/standard-objects/vie
import { ViewSortWorkspaceEntity } from 'src/modules/view/standard-objects/view-sort.workspace-entity';
import { ViewWorkspaceEntity } from 'src/modules/view/standard-objects/view.workspace-entity';
import { WebhookWorkspaceEntity } from 'src/modules/webhook/standard-objects/webhook.workspace-entity';
-import { WorkflowEventListenerWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow-event-listener.workspace-entity';
-import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow-version.workspace-entity';
-import { WorkflowWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow.workspace-entity';
+import { WorkflowEventListenerWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-event-listener.workspace-entity';
+import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
+import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
// TODO: Maybe we should automate this with the DiscoverService of Nest.JS
diff --git a/packages/twenty-server/src/modules/activity/standard-objects/activity-target.workspace-entity.ts b/packages/twenty-server/src/modules/activity/standard-objects/activity-target.workspace-entity.ts
index 907e16b9f0e..41967728a94 100644
--- a/packages/twenty-server/src/modules/activity/standard-objects/activity-target.workspace-entity.ts
+++ b/packages/twenty-server/src/modules/activity/standard-objects/activity-target.workspace-entity.ts
@@ -17,7 +17,7 @@ import { ActivityWorkspaceEntity } from 'src/modules/activity/standard-objects/a
import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity';
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
-import { WorkflowWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow.workspace-entity';
+import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.activityTarget,
diff --git a/packages/twenty-server/src/modules/attachment/standard-objects/attachment.workspace-entity.ts b/packages/twenty-server/src/modules/attachment/standard-objects/attachment.workspace-entity.ts
index d80c0ec8c7d..93c218515fa 100644
--- a/packages/twenty-server/src/modules/attachment/standard-objects/attachment.workspace-entity.ts
+++ b/packages/twenty-server/src/modules/attachment/standard-objects/attachment.workspace-entity.ts
@@ -20,7 +20,7 @@ import { ActivityWorkspaceEntity } from 'src/modules/activity/standard-objects/a
import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity';
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
-import { WorkflowWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow.workspace-entity';
+import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
@WorkspaceEntity({
diff --git a/packages/twenty-server/src/modules/favorite/standard-objects/favorite.workspace-entity.ts b/packages/twenty-server/src/modules/favorite/standard-objects/favorite.workspace-entity.ts
index e0f8dbbea50..e09681a2326 100644
--- a/packages/twenty-server/src/modules/favorite/standard-objects/favorite.workspace-entity.ts
+++ b/packages/twenty-server/src/modules/favorite/standard-objects/favorite.workspace-entity.ts
@@ -19,7 +19,7 @@ import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync
import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity';
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
-import { WorkflowWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow.workspace-entity';
+import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
@WorkspaceEntity({
diff --git a/packages/twenty-server/src/modules/modules.module.ts b/packages/twenty-server/src/modules/modules.module.ts
index a3571e12392..1872d8fa08c 100644
--- a/packages/twenty-server/src/modules/modules.module.ts
+++ b/packages/twenty-server/src/modules/modules.module.ts
@@ -4,6 +4,7 @@ import { CalendarModule } from 'src/modules/calendar/calendar.module';
import { ConnectedAccountModule } from 'src/modules/connected-account/connected-account.module';
import { MessagingModule } from 'src/modules/messaging/messaging.module';
import { ViewModule } from 'src/modules/view/view.module';
+import { WorkflowModule } from 'src/modules/workflow/workflow.module';
@Module({
imports: [
@@ -11,6 +12,7 @@ import { ViewModule } from 'src/modules/view/view.module';
CalendarModule,
ConnectedAccountModule,
ViewModule,
+ WorkflowModule,
],
providers: [],
exports: [],
diff --git a/packages/twenty-server/src/modules/timeline/standard-objects/timeline-activity.workspace-entity.ts b/packages/twenty-server/src/modules/timeline/standard-objects/timeline-activity.workspace-entity.ts
index dc1942ac416..c5fef98970e 100644
--- a/packages/twenty-server/src/modules/timeline/standard-objects/timeline-activity.workspace-entity.ts
+++ b/packages/twenty-server/src/modules/timeline/standard-objects/timeline-activity.workspace-entity.ts
@@ -19,7 +19,7 @@ import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync
import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity';
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
-import { WorkflowWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow.workspace-entity';
+import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
@WorkspaceEntity({
diff --git a/packages/twenty-server/src/modules/workflow/standard-objects/workflow-event-listener.workspace-entity.ts b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-event-listener.workspace-entity.ts
similarity index 95%
rename from packages/twenty-server/src/modules/workflow/standard-objects/workflow-event-listener.workspace-entity.ts
rename to packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-event-listener.workspace-entity.ts
index ce84c6227ba..7994c56a348 100644
--- a/packages/twenty-server/src/modules/workflow/standard-objects/workflow-event-listener.workspace-entity.ts
+++ b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-event-listener.workspace-entity.ts
@@ -13,7 +13,7 @@ import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { WORKFLOW_EVENT_LISTENER_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
-import { WorkflowWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow.workspace-entity';
+import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.workflowEventListener,
diff --git a/packages/twenty-server/src/modules/workflow/standard-objects/workflow-version.workspace-entity.ts b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-version.workspace-entity.ts
similarity index 87%
rename from packages/twenty-server/src/modules/workflow/standard-objects/workflow-version.workspace-entity.ts
rename to packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-version.workspace-entity.ts
index 57b478ca239..3c52fb22f31 100644
--- a/packages/twenty-server/src/modules/workflow/standard-objects/workflow-version.workspace-entity.ts
+++ b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow-version.workspace-entity.ts
@@ -13,21 +13,8 @@ import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { WORKFLOW_VERSION_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
-import { WorkflowWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow.workspace-entity';
-
-export enum WorkflowTriggerType {
- DATABASE_EVENT = 'DATABASE_EVENT',
-}
-
-export type WorkflowDatabaseEventTrigger = {
- type: WorkflowTriggerType.DATABASE_EVENT;
- settings: {
- eventName: string;
- triggerName: string;
- };
-};
-
-export type WorkflowTrigger = WorkflowDatabaseEventTrigger;
+import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
+import { WorkflowTrigger } from 'src/modules/workflow/common/types/workflow-trigger.type';
@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.workflowVersion,
@@ -60,7 +47,7 @@ export class WorkflowVersionWorkspaceEntity extends BaseWorkspaceEntity {
icon: 'IconPlayerPlay',
})
@WorkspaceIsNullable()
- trigger: JSON | null;
+ trigger: WorkflowTrigger | null;
// Relations
@WorkspaceRelation({
diff --git a/packages/twenty-server/src/modules/workflow/standard-objects/workflow.workspace-entity.ts b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow.workspace-entity.ts
similarity index 97%
rename from packages/twenty-server/src/modules/workflow/standard-objects/workflow.workspace-entity.ts
rename to packages/twenty-server/src/modules/workflow/common/standard-objects/workflow.workspace-entity.ts
index 7bbaef2e93d..800d1a0ce62 100644
--- a/packages/twenty-server/src/modules/workflow/standard-objects/workflow.workspace-entity.ts
+++ b/packages/twenty-server/src/modules/workflow/common/standard-objects/workflow.workspace-entity.ts
@@ -19,8 +19,8 @@ import { ActivityTargetWorkspaceEntity } from 'src/modules/activity/standard-obj
import { AttachmentWorkspaceEntity } from 'src/modules/attachment/standard-objects/attachment.workspace-entity';
import { FavoriteWorkspaceEntity } from 'src/modules/favorite/standard-objects/favorite.workspace-entity';
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
-import { WorkflowEventListenerWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow-event-listener.workspace-entity';
-import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow-version.workspace-entity';
+import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
+import { WorkflowEventListenerWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-event-listener.workspace-entity';
@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.workflow,
diff --git a/packages/twenty-server/src/modules/workflow/common/types/workflow-action.type.ts b/packages/twenty-server/src/modules/workflow/common/types/workflow-action.type.ts
new file mode 100644
index 00000000000..c630ab0a2f7
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/common/types/workflow-action.type.ts
@@ -0,0 +1,14 @@
+import { WorkflowSettingsType } from 'src/modules/workflow/common/types/workflow-settings.type';
+
+export enum WorkflowActionType {
+ CODE = 'CODE',
+}
+
+export type WorkflowAction = {
+ name: string;
+ displayName: string;
+ type: WorkflowActionType;
+ valid: boolean;
+ settings: WorkflowSettingsType;
+ nextAction?: WorkflowAction;
+};
diff --git a/packages/twenty-server/src/modules/workflow/common/types/workflow-settings.type.ts b/packages/twenty-server/src/modules/workflow/common/types/workflow-settings.type.ts
new file mode 100644
index 00000000000..344f4b01a06
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/common/types/workflow-settings.type.ts
@@ -0,0 +1,14 @@
+export type WorkflowCodeSettingsType = {
+ serverlessFunctionId: string;
+};
+
+export type WorkflowSettingsType = {
+ errorHandlingOptions: {
+ retryOnFailure: {
+ value: boolean;
+ };
+ continueOnFailure: {
+ value: boolean;
+ };
+ };
+} & WorkflowCodeSettingsType;
diff --git a/packages/twenty-server/src/modules/workflow/common/types/workflow-trigger.type.ts b/packages/twenty-server/src/modules/workflow/common/types/workflow-trigger.type.ts
new file mode 100644
index 00000000000..ffd25f4df9d
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/common/types/workflow-trigger.type.ts
@@ -0,0 +1,28 @@
+import { WorkflowAction } from 'src/modules/workflow/common/types/workflow-action.type';
+
+export enum WorkflowTriggerType {
+ DATABASE_EVENT = 'DATABASE_EVENT',
+ MANUAL = 'MANUAL',
+}
+
+type BaseTrigger = {
+ type: WorkflowTriggerType;
+ input?: object;
+ nextAction?: WorkflowAction;
+};
+
+export type WorkflowDatabaseEventTrigger = BaseTrigger & {
+ type: WorkflowTriggerType.DATABASE_EVENT;
+ settings: {
+ eventName: string;
+ triggerName: string;
+ };
+};
+
+type WorkflowManualTrigger = BaseTrigger & {
+ type: WorkflowTriggerType.MANUAL;
+};
+
+export type WorkflowTrigger =
+ | WorkflowDatabaseEventTrigger
+ | WorkflowManualTrigger;
diff --git a/packages/twenty-server/src/modules/workflow/common/workflow-common.module.ts b/packages/twenty-server/src/modules/workflow/common/workflow-common.module.ts
new file mode 100644
index 00000000000..1285f8ed713
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/common/workflow-common.module.ts
@@ -0,0 +1,9 @@
+import { Global, Module } from '@nestjs/common';
+
+import { WorkflowCommonService } from 'src/modules/workflow/common/workflow-common.services';
+
+@Module({
+ providers: [WorkflowCommonService],
+ exports: [WorkflowCommonService],
+})
+export class WorkflowCommonModule {}
diff --git a/packages/twenty-server/src/modules/workflow/common/workflow-common.services.ts b/packages/twenty-server/src/modules/workflow/common/workflow-common.services.ts
new file mode 100644
index 00000000000..7012de0865a
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/common/workflow-common.services.ts
@@ -0,0 +1,53 @@
+import { Injectable } from '@nestjs/common';
+
+import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
+import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
+import {
+ WorkflowTriggerException,
+ WorkflowTriggerExceptionCode,
+} from 'src/modules/workflow/workflow-trigger/workflow-trigger.exception';
+import { WorkflowTrigger } from 'src/modules/workflow/common/types/workflow-trigger.type';
+
+@Injectable()
+export class WorkflowCommonService {
+ constructor(
+ private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
+ ) {}
+
+ async getWorkflowVersion(
+ workspaceId: string,
+ workflowVersionId: string,
+ ): Promise<
+ Omit<WorkflowVersionWorkspaceEntity, 'trigger'> & {
+ trigger: WorkflowTrigger;
+ }
+ > {
+ const workflowVersionRepository =
+ await this.twentyORMGlobalManager.getRepositoryForWorkspace<WorkflowVersionWorkspaceEntity>(
+ workspaceId,
+ 'workflowVersion',
+ );
+
+ const workflowVersion = await workflowVersionRepository.findOne({
+ where: {
+ id: workflowVersionId,
+ },
+ });
+
+ if (!workflowVersion) {
+ throw new WorkflowTriggerException(
+ 'Workflow version not found',
+ WorkflowTriggerExceptionCode.INVALID_INPUT,
+ );
+ }
+
+ if (!workflowVersion.trigger || !workflowVersion.trigger?.type) {
+ throw new WorkflowTriggerException(
+ 'Workflow version does not contains trigger',
+ WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION,
+ );
+ }
+
+ return { ...workflowVersion, trigger: workflowVersion.trigger };
+ }
+}
diff --git a/packages/twenty-server/src/modules/workflow/workflow-runner/workflow-runner.job.ts b/packages/twenty-server/src/modules/workflow/workflow-runner/workflow-runner.job.ts
new file mode 100644
index 00000000000..46a742e089f
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-runner/workflow-runner.job.ts
@@ -0,0 +1,32 @@
+import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator';
+import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
+import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator';
+import { WorkflowRunnerService } from 'src/modules/workflow/workflow-runner/workflow-runner.service';
+import { WorkflowCommonService } from 'src/modules/workflow/common/workflow-common.services';
+
+type RunWorkflowJobData = { workspaceId: string; workflowVersionId: string };
+
+@Processor(MessageQueue.workflowQueue)
+export class WorkflowRunnerJob {
+ constructor(
+ private readonly workflowCommonService: WorkflowCommonService,
+ private readonly workflowRunnerService: WorkflowRunnerService,
+ ) {}
+
+ @Process(WorkflowRunnerJob.name)
+ async handle({
+ workspaceId,
+ workflowVersionId,
+ }: RunWorkflowJobData): Promise<void> {
+ const workflowVersion = await this.workflowCommonService.getWorkflowVersion(
+ workspaceId,
+ workflowVersionId,
+ );
+
+ await this.workflowRunnerService.run({
+ action: workflowVersion.trigger.nextAction,
+ workspaceId,
+ payload: workflowVersion.trigger.input,
+ });
+ }
+}
diff --git a/packages/twenty-server/src/modules/workflow/workflow-runner/workflow-runner.module.ts b/packages/twenty-server/src/modules/workflow/workflow-runner/workflow-runner.module.ts
new file mode 100644
index 00000000000..1ba558f7314
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-runner/workflow-runner.module.ts
@@ -0,0 +1,13 @@
+import { Module } from '@nestjs/common';
+
+import { WorkflowRunnerService } from 'src/modules/workflow/workflow-runner/workflow-runner.service';
+import { WorkflowRunnerJob } from 'src/modules/workflow/workflow-runner/workflow-runner.job';
+import { WorkflowCommonModule } from 'src/modules/workflow/common/workflow-common.module';
+import { ServerlessFunctionModule } from 'src/engine/metadata-modules/serverless-function/serverless-function.module';
+
+@Module({
+ imports: [WorkflowCommonModule, ServerlessFunctionModule],
+ providers: [WorkflowRunnerService, WorkflowRunnerJob],
+ exports: [WorkflowRunnerService],
+})
+export class WorkflowRunnerModule {}
diff --git a/packages/twenty-server/src/modules/workflow/workflow-runner/workflow-runner.service.ts b/packages/twenty-server/src/modules/workflow/workflow-runner/workflow-runner.service.ts
new file mode 100644
index 00000000000..6bc19e2b530
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-runner/workflow-runner.service.ts
@@ -0,0 +1,82 @@
+import { Injectable } from '@nestjs/common';
+
+import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
+import {
+ WorkflowTriggerException,
+ WorkflowTriggerExceptionCode,
+} from 'src/modules/workflow/workflow-trigger/workflow-trigger.exception';
+import {
+ WorkflowAction,
+ WorkflowActionType,
+} from 'src/modules/workflow/common/types/workflow-action.type';
+
+const MAX_RETRIES_ON_FAILURE = 3;
+
+@Injectable()
+export class WorkflowRunnerService {
+ constructor(
+ private readonly serverlessFunctionService: ServerlessFunctionService,
+ ) {}
+
+ async run({
+ action,
+ workspaceId,
+ payload,
+ attemptCount = 1,
+ }: {
+ action?: WorkflowAction;
+ workspaceId: string;
+ payload?: object;
+ attemptCount?: number;
+ }) {
+ if (!action) {
+ return payload;
+ }
+
+ let result: object | undefined = undefined;
+
+ switch (action.type) {
+ case WorkflowActionType.CODE: {
+ const executionResult = await this.serverlessFunctionService.executeOne(
+ action.settings.serverlessFunctionId,
+ workspaceId,
+ payload,
+ );
+
+ if (executionResult.data) {
+ result = executionResult.data;
+ }
+ if (!executionResult.error) {
+ throw new Error('Execution result error, no data or error');
+ }
+ if (action.settings.errorHandlingOptions.continueOnFailure.value) {
+ result = payload;
+ break;
+ } else if (
+ action.settings.errorHandlingOptions.retryOnFailure.value &&
+ attemptCount < MAX_RETRIES_ON_FAILURE
+ ) {
+ return await this.run({
+ action,
+ workspaceId,
+ payload,
+ attemptCount: attemptCount + 1,
+ });
+ } else {
+ return executionResult.error;
+ }
+ }
+ default:
+ throw new WorkflowTriggerException(
+ `Unknown action type '${action.type}'`,
+ WorkflowTriggerExceptionCode.INVALID_ACTION_TYPE,
+ );
+ }
+
+ return await this.run({
+ action: action.nextAction,
+ workspaceId,
+ payload: result,
+ });
+ }
+}
diff --git a/packages/twenty-server/src/modules/workflow/workflow-trigger/workflow-trigger.exception.ts b/packages/twenty-server/src/modules/workflow/workflow-trigger/workflow-trigger.exception.ts
index d153e827d00..2f462109506 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-trigger/workflow-trigger.exception.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-trigger/workflow-trigger.exception.ts
@@ -11,4 +11,5 @@ export enum WorkflowTriggerExceptionCode {
INVALID_INPUT = 'INVALID_INPUT',
INVALID_WORKFLOW_TRIGGER = 'INVALID_WORKFLOW_TRIGGER',
INVALID_WORKFLOW_VERSION = 'INVALID_WORKFLOW_VERSION',
+ INVALID_ACTION_TYPE = 'INVALID_ACTION_TYPE',
}
diff --git a/packages/twenty-server/src/modules/workflow/workflow-trigger/workflow-trigger.service.ts b/packages/twenty-server/src/modules/workflow/workflow-trigger/workflow-trigger.service.ts
index 5f73e58ab5a..7f23bffb56b 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-trigger/workflow-trigger.service.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-trigger/workflow-trigger.service.ts
@@ -1,59 +1,51 @@
import { Injectable } from '@nestjs/common';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
-import { WorkflowEventListenerWorkspaceEntity } from 'src/modules/workflow/standard-objects/workflow-event-listener.workspace-entity';
-import {
- WorkflowDatabaseEventTrigger,
- WorkflowTrigger,
- WorkflowTriggerType,
- WorkflowVersionWorkspaceEntity,
-} from 'src/modules/workflow/standard-objects/workflow-version.workspace-entity';
+import { WorkflowEventListenerWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-event-listener.workspace-entity';
import {
WorkflowTriggerException,
WorkflowTriggerExceptionCode,
} from 'src/modules/workflow/workflow-trigger/workflow-trigger.exception';
+import {
+ WorkflowDatabaseEventTrigger,
+ WorkflowTriggerType,
+} from 'src/modules/workflow/common/types/workflow-trigger.type';
+import { WorkflowCommonService } from 'src/modules/workflow/common/workflow-common.services';
+import { WorkflowRunnerService } from 'src/modules/workflow/workflow-runner/workflow-runner.service';
@Injectable()
export class WorkflowTriggerService {
constructor(
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
+ private readonly workflowCommonService: WorkflowCommonService,
+ private readonly workflowRunnerService: WorkflowRunnerService,
) {}
- async enableWorkflowTrigger(workspaceId: string, workflowVersionId: string) {
- const workflowVersionRepository =
- await this.twentyORMGlobalManager.getRepositoryForWorkspace<WorkflowVersionWorkspaceEntity>(
- workspaceId,
- 'workflowVersion',
- );
+ async runWorkflow(workspaceId: string, workflowVersionId: string) {
+ const workflowVersion = await this.workflowCommonService.getWorkflowVersion(
+ workspaceId,
+ workflowVersionId,
+ );
- const workflowVersion = await workflowVersionRepository.findOne({
- where: {
- id: workflowVersionId,
- },
+ return await this.workflowRunnerService.run({
+ action: workflowVersion.trigger.nextAction,
+ workspaceId,
+ payload: workflowVersion.trigger.input,
});
+ }
- if (!workflowVersion) {
- throw new WorkflowTriggerException(
- 'Workflow version not found',
- WorkflowTriggerExceptionCode.INVALID_INPUT,
- );
- }
-
- const trigger = workflowVersion.trigger as unknown as WorkflowTrigger;
-
- if (!trigger || !trigger?.type) {
- throw new WorkflowTriggerException(
- 'Workflow version does not contains trigger',
- WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION,
- );
- }
+ async enableWorkflowTrigger(workspaceId: string, workflowVersionId: string) {
+ const workflowVersion = await this.workflowCommonService.getWorkflowVersion(
+ workspaceId,
+ workflowVersionId,
+ );
- switch (trigger.type) {
+ switch (workflowVersion.trigger.type) {
case WorkflowTriggerType.DATABASE_EVENT:
await this.upsertWorkflowEventListener(
workspaceId,
workflowVersion.workflowId,
- trigger,
+ workflowVersion.trigger,
);
break;
default:
diff --git a/packages/twenty-server/src/modules/workflow/workflow.module.ts b/packages/twenty-server/src/modules/workflow/workflow.module.ts
new file mode 100644
index 00000000000..88b9529f958
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow.module.ts
@@ -0,0 +1,8 @@
+import { Module } from '@nestjs/common';
+
+import { WorkflowRunnerModule } from 'src/modules/workflow/workflow-runner/workflow-runner.module';
+
+@Module({
+ imports: [WorkflowRunnerModule],
+})
+export class WorkflowModule {}