The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Remove the dead workflow mirror write code (#27883)
Thomas Trompetted1891ad0f997
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-core-sync.service.ts b/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-core-sync.service.tsindex 8f503935d45..8712003c49b 100644--- a/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-core-sync.service.ts+++ b/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-core-sync.service.ts@@ -1,12 +1,8 @@-import { Injectable, Logger } from '@nestjs/common';+import { Injectable } from '@nestjs/common';import { InjectRepository } from '@nestjs/typeorm';-import { isNonEmptyString } from '@sniptt/guards';-import { WorkflowVisibility } from 'twenty-shared/types';-import { STANDARD_OBJECTS } from 'twenty-shared/metadata';-import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';+import { isDefined } from 'twenty-shared/utils';import { In, Repository } from 'typeorm';-import { v4 as uuidv4 } from 'uuid';import { WorkflowEntity } from 'src/engine/core-modules/workflow/entities/workflow.entity';import { ApplicationService } from 'src/engine/core-modules/application/application.service';@@ -18,33 +14,22 @@ import {import { type AllFlatEntityOperationByMetadataName } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-to-create-delete-update.type';import { WorkspaceMigrationBuilderException } from 'src/engine/workspace-manager/workspace-migration/exceptions/workspace-migration-builder-exception';import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';-import { type UniversalFlatWorkflow } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-workflow.type';import { WorkspaceManyOrAllFlatEntityMapsCacheService } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.service';import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';-import { WorkspaceOrmManager } from 'src/engine/twenty-orm/workspace-orm.manager';import { InjectWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/inject-workspace-scoped-repository.decorator';import { WorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/workspace-scoped-repository';-import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';-import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';-import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';-import { type WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';-import { type WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';const CORE_WORKFLOW_DELETION_LOCK_TTL_MS = 30_000;const CORE_WORKFLOW_DELETION_LOCK_RETRY_INTERVAL_MS = 100;@Injectable()export class WorkflowCoreSyncService {- private readonly logger = new Logger(WorkflowCoreSyncService.name);-constructor(@InjectWorkspaceScopedRepository(WorkflowEntity)private readonly coreWorkflowRepository: WorkspaceScopedRepository<WorkflowEntity>,@InjectRepository(WorkspaceEntity)private readonly workspaceRepository: Repository<WorkspaceEntity>,- private readonly workspaceOrmManager: WorkspaceOrmManager,- private readonly workspaceCacheService: WorkspaceCacheService,private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,private readonly applicationService: ApplicationService,private readonly flatEntityMapsCacheService: WorkspaceManyOrAllFlatEntityMapsCacheService,@@ -88,405 +73,6 @@ export class WorkflowCoreSyncService {}}- async upsertToCore(- workspaceId: string,- workspaceWorkflowIds: string[],- ): Promise<void> {- if (workspaceWorkflowIds.length === 0) {- return;- }-- const liveWorkflows =- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {- const workflowRepository =- this.workspaceOrmManager.getRepository<WorkflowWorkspaceEntity>(- 'workflow',- { shouldBypassPermissionChecks: true },- );-- return workflowRepository.find({- where: { id: In(workspaceWorkflowIds) },- });- }, buildSystemAuthContext(workspaceId));-- if (liveWorkflows.length === 0) {- return;- }-- const { workspaceCustomFlatApplication } =- await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(- { workspaceId },- );-- const workspaceWorkflowIdByOwnedCoreWorkflowId =- await this.resolveWorkspaceWorkflowIdByOwnedCoreWorkflowId(- workspaceId,- liveWorkflows,- );-- const coreVersionIdByWorkspaceVersionId =- await this.resolveCoreVersionIdByWorkspaceVersionId(- workspaceId,- liveWorkflows,- );-- const coreWorkflowIdByWorkspaceRecordId = new Map<string, string>();-- const coreRows = liveWorkflows.map((workflow) => {- const candidateCoreWorkflowId = workflow.coreWorkflowId;-- const linkedCoreWorkflowId =- isNonEmptyString(candidateCoreWorkflowId) &&- workspaceWorkflowIdByOwnedCoreWorkflowId.has(candidateCoreWorkflowId)- ? candidateCoreWorkflowId- : null;-- const coreWorkflowId = linkedCoreWorkflowId ?? uuidv4();-- if (!isDefined(linkedCoreWorkflowId)) {- coreWorkflowIdByWorkspaceRecordId.set(workflow.id, coreWorkflowId);- }-- const storedWorkspaceWorkflowId = isDefined(linkedCoreWorkflowId)- ? workspaceWorkflowIdByOwnedCoreWorkflowId.get(linkedCoreWorkflowId)- : null;-- return {- id: coreWorkflowId,- name: workflow.name ?? null,- workspaceWorkflowId: isNonEmptyString(storedWorkspaceWorkflowId)- ? storedWorkspaceWorkflowId- : workflow.id,- lastPublishedVersionId: isNonEmptyString(- workflow.lastPublishedVersionId,- )- ? workflow.lastPublishedVersionId- : null,- lastPublishedCoreWorkflowVersionId: isNonEmptyString(- workflow.lastPublishedVersionId,- )- ? (coreVersionIdByWorkspaceVersionId.get(- workflow.lastPublishedVersionId,- ) ?? null)- : null,- createdAt: new Date(workflow.createdAt),- universalIdentifier: uuidv4(),- };- });-- const { flatWorkflowMaps } =- await this.flatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps(- { workspaceId, flatMapsKeys: ['flatWorkflowMaps'] },- );-- const flatWorkflowsToCreate: (UniversalFlatWorkflow & { id?: string })[] =- [];- const flatWorkflowsToUpdate: UniversalFlatWorkflow[] = [];-- // read the table, not the cache: a stale map would send a persisted id to create and hit the primary key- const persistedCoreWorkflowIds = new Set(- (- await this.coreWorkflowRepository.find(workspaceId, {- where: { id: In(coreRows.map(({ id }) => id)) },- select: { id: true },- })- ).map(({ id }) => id),- );-- for (const coreRow of coreRows) {- const existingFlatWorkflow = persistedCoreWorkflowIds.has(coreRow.id)- ? findFlatEntityByIdInFlatEntityMaps({- flatEntityId: coreRow.id,- flatEntityMaps: flatWorkflowMaps,- })- : undefined;-- if (- persistedCoreWorkflowIds.has(coreRow.id) &&- !isDefined(existingFlatWorkflow)- ) {- throw new CoreWorkflowMetadataException(- `Core workflow ${coreRow.id} is persisted but missing from the flat entity maps`,- CoreWorkflowMetadataExceptionCode.WORKFLOW_NOT_FOUND,- );- }-- const flatWorkflow: UniversalFlatWorkflow = {- universalIdentifier: coreRow.universalIdentifier,- name: coreRow.name,- versionDefinitionHash:- existingFlatWorkflow?.versionDefinitionHash ?? null,- workspaceWorkflowId: coreRow.workspaceWorkflowId,- lastPublishedVersionId: coreRow.lastPublishedVersionId,- lastPublishedCoreWorkflowVersionId:- coreRow.lastPublishedCoreWorkflowVersionId,- isSystem: false,- visibility: WorkflowVisibility.WORKSPACE,- createdByUserWorkspaceId: null,- applicationUniversalIdentifier:- workspaceCustomFlatApplication.universalIdentifier,- createdAt: coreRow.createdAt.toISOString(),- updatedAt: new Date().toISOString(),- };-- if (isDefined(existingFlatWorkflow)) {- flatWorkflowsToUpdate.push({- ...existingFlatWorkflow,- ...flatWorkflow,- universalIdentifier: existingFlatWorkflow.universalIdentifier,- createdAt: existingFlatWorkflow.createdAt,- isSystem: existingFlatWorkflow.isSystem,- visibility: existingFlatWorkflow.visibility,- createdByUserWorkspaceId:- existingFlatWorkflow.createdByUserWorkspaceId,- });- } else {- flatWorkflowsToCreate.push({ ...flatWorkflow, id: coreRow.id });- }- }-- await this.runCoreWorkflowMigration({- workspaceId,- applicationUniversalIdentifier:- workspaceCustomFlatApplication.universalIdentifier,- failureMessage:- 'Multiple validation errors occurred while mirroring workflows to core',- operations: {- workflow: {- flatEntityToCreate: flatWorkflowsToCreate,- flatEntityToDelete: [],- flatEntityToUpdate: flatWorkflowsToUpdate,- },- },- });-- await this.writeBackCoreWorkflowIds(- workspaceId,- coreWorkflowIdByWorkspaceRecordId,- );- }-- async reconcileWorkspaceWorkflows(- workspaceId: string,- workspaceWorkflowIds: string[],- ): Promise<void> {- const schema = getWorkspaceSchemaName(workspaceId);- const coreWorkflowIdsToDelete: string[] = [];- const coreWorkflowUpdates: {- coreWorkflowId: string;- name: string | null;- lastPublishedVersionId: string | null;- lastPublishedCoreWorkflowVersionId: string | null;- }[] = [];-- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {- await this.workspaceOrmManager.runInWorkspaceTransaction(- async (transactionScope) => {- for (const workspaceWorkflowId of [- ...new Set(workspaceWorkflowIds),- ].sort()) {- const workflows = (await transactionScope.executeRawQuery(- `SELECT * FROM "${schema}"."workflow" WHERE id = $1 FOR UPDATE`,- [workspaceWorkflowId],- )) as Pick<- WorkflowWorkspaceEntity,- | 'id'- | 'name'- | 'coreWorkflowId'- | 'lastPublishedVersionId'- | 'deletedAt'- >[];- const workflow = workflows[0];-- if (!isDefined(workflow) || isDefined(workflow.deletedAt)) {- const orphanCoreWorkflows =- (await transactionScope.executeRawQuery(- `SELECT id FROM core."workflow" WHERE "workspaceId" = $1 AND "workspaceWorkflowId" = $2`,- [workspaceId, workspaceWorkflowId],- )) as { id: string }[];-- coreWorkflowIdsToDelete.push(- ...orphanCoreWorkflows.map(({ id }) => id),- );- continue;- }-- const coreWorkflows = (await transactionScope.executeRawQuery(- `SELECT id FROM core."workflow" WHERE "workspaceId" = $1 AND "workspaceWorkflowId" = $2 FOR UPDATE`,- [workspaceId, workspaceWorkflowId],- )) as { id: string }[];-- if (- coreWorkflows.length !== 1 ||- workflow.coreWorkflowId !== coreWorkflows[0].id- ) {- throw new Error(- `Invalid core mapping for workflow ${workspaceWorkflowId} in workspace ${workspaceId}`,- );- }-- const coreWorkflowId = coreWorkflows[0].id;- let coreWorkflowVersionId: string | null = null;-- if (isNonEmptyString(workflow.lastPublishedVersionId)) {- const versions = (await transactionScope.executeRawQuery(- `SELECT id FROM core."workflowVersion" WHERE "workspaceId" = $1 AND "workspaceWorkflowVersionId" = $2 AND "coreWorkflowId" = $3`,- [workspaceId, workflow.lastPublishedVersionId, coreWorkflowId],- )) as { id: string }[];-- if (versions.length !== 1) {- throw new Error(- `Invalid published core version mapping for workflow ${workspaceWorkflowId} in workspace ${workspaceId}`,- );- }-- coreWorkflowVersionId = versions[0].id;- }-- coreWorkflowUpdates.push({- coreWorkflowId,- name: workflow.name ?? null,- lastPublishedVersionId: isNonEmptyString(- workflow.lastPublishedVersionId,- )- ? workflow.lastPublishedVersionId- : null,- lastPublishedCoreWorkflowVersionId: coreWorkflowVersionId,- });- }- },- );- }, buildSystemAuthContext(workspaceId));-- // the locks above only cover workspace rows, so core writes go through the runner after commit- await this.applyReconciledCoreWorkflowUpdates(- workspaceId,- coreWorkflowUpdates,- );-- await this.deleteFromCore(workspaceId, coreWorkflowIdsToDelete);- }-- private async applyReconciledCoreWorkflowUpdates(- workspaceId: string,- coreWorkflowUpdates: {- coreWorkflowId: string;- name: string | null;- lastPublishedVersionId: string | null;- lastPublishedCoreWorkflowVersionId: string | null;- }[],- ): Promise<void> {- if (!isNonEmptyArray(coreWorkflowUpdates)) {- return;- }-- const { flatWorkflowMaps } =- await this.flatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps(- { workspaceId, flatMapsKeys: ['flatWorkflowMaps'] },- );-- const { workspaceCustomFlatApplication } =- await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(- { workspaceId },- );-- const flatWorkflowsToUpdate = coreWorkflowUpdates.flatMap(- ({ coreWorkflowId, ...coreWorkflowUpdate }) => {- const existingFlatWorkflow = findFlatEntityByIdInFlatEntityMaps({- flatEntityId: coreWorkflowId,- flatEntityMaps: flatWorkflowMaps,- });-- if (!isDefined(existingFlatWorkflow)) {- throw new CoreWorkflowMetadataException(- `Core workflow ${coreWorkflowId} is persisted but missing from the flat entity maps`,- CoreWorkflowMetadataExceptionCode.WORKFLOW_NOT_FOUND,- );- }-- return [- {- ...existingFlatWorkflow,- ...coreWorkflowUpdate,- updatedAt: new Date().toISOString(),- },- ];- },- );-- await this.runCoreWorkflowMigration({- workspaceId,- applicationUniversalIdentifier:- workspaceCustomFlatApplication.universalIdentifier,- failureMessage:- 'Multiple validation errors occurred while reconciling workflows with the workspace mirror',- operations: {- workflow: {- flatEntityToCreate: [],- flatEntityToDelete: [],- flatEntityToUpdate: flatWorkflowsToUpdate,- },- },- });- }-- private async resolveCoreVersionIdByWorkspaceVersionId(- workspaceId: string,- workflows: WorkflowWorkspaceEntity[],- ): Promise<Map<string, string>> {- const publishedVersionIds = workflows- .map((workflow) => workflow.lastPublishedVersionId)- .filter(isNonEmptyString);-- if (publishedVersionIds.length === 0) {- return new Map();- }-- return this.workspaceOrmManager.executeInWorkspaceContext(async () => {- const workflowVersionRepository =- this.workspaceOrmManager.getRepository<WorkflowVersionWorkspaceEntity>(- 'workflowVersion',- { shouldBypassPermissionChecks: true },- );-- const rows = await workflowVersionRepository.find({- where: { id: In(publishedVersionIds) },- select: { id: true, coreWorkflowVersionId: true },- });-- return new Map(- rows.flatMap((row) =>- isNonEmptyString(row.coreWorkflowVersionId)- ? [[row.id, row.coreWorkflowVersionId] as const]- : [],- ),- );- }, buildSystemAuthContext(workspaceId));- }-- // coreWorkflowId is caller-writable, so it may point at another workspace's core row- private async resolveWorkspaceWorkflowIdByOwnedCoreWorkflowId(- workspaceId: string,- workflows: WorkflowWorkspaceEntity[],- ): Promise<Map<string, string | null>> {- const candidateIds = workflows- .map((workflow) => workflow.coreWorkflowId)- .filter(isNonEmptyString);-- if (candidateIds.length === 0) {- return new Map();- }-- const ownedRows = await this.coreWorkflowRepository.find(workspaceId, {- where: { id: In(candidateIds) },- select: { id: true, workspaceWorkflowId: true },- });-- return new Map(- ownedRows.map((row) => [row.id, row.workspaceWorkflowId ?? null]),- );- }-async deleteFromCore(workspaceId: string,coreWorkflowIds: string[],@@ -590,55 +176,6 @@ export class WorkflowCoreSyncService {return workflows[0] ?? null;}- private async writeBackCoreWorkflowIds(- workspaceId: string,- coreWorkflowIdByWorkspaceRecordId: Map<string, string>,- ): Promise<void> {- if (coreWorkflowIdByWorkspaceRecordId.size === 0) {- return;- }-- if (!(await this.workspaceHasCoreWorkflowIdField(workspaceId))) {- this.logger.warn(- `workflow.coreWorkflowId field missing for workspace ${workspaceId}, skipping core id write-back`,- );-- return;- }-- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {- const workspaceWorkflowRepository =- this.workspaceOrmManager.getRepository<WorkflowWorkspaceEntity>(- 'workflow',- { shouldBypassPermissionChecks: true },- );-- for (const [- workspaceRecordId,- coreWorkflowId,- ] of coreWorkflowIdByWorkspaceRecordId) {- await workspaceWorkflowRepository.update(workspaceRecordId, {- coreWorkflowId,- });- }- }, buildSystemAuthContext(workspaceId));- }-- private async workspaceHasCoreWorkflowIdField(- workspaceId: string,- ): Promise<boolean> {- const { flatFieldMetadataMaps } =- await this.workspaceCacheService.getOrRecompute(workspaceId, [- 'flatFieldMetadataMaps',- ]);-- return isDefined(- flatFieldMetadataMaps.byUniversalIdentifier[- STANDARD_OBJECTS.workflow.fields.coreWorkflowId.universalIdentifier- ],- );- }-async getCustomApplicationIdOrThrow(workspaceId: string): Promise<string> {const workspace = await this.workspaceRepository.findOne({where: { id: workspaceId },diff --git a/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-version-core-sync.service.ts b/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-version-core-sync.service.tsindex 300aafa4ea4..323849f1ebe 100644--- a/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-version-core-sync.service.ts+++ b/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-version-core-sync.service.ts@@ -16,36 +16,25 @@ import { isDefined } from 'twenty-shared/utils';import { In, Repository } from 'typeorm';import { v4 as uuidv4 } from 'uuid';-import {- WorkflowVersionEntity,- WorkflowVersionStatus,-} from 'src/engine/core-modules/workflow/entities/workflow-version.entity';+import { WorkflowVersionEntity } from 'src/engine/core-modules/workflow/entities/workflow-version.entity';import {CoreWorkflowMetadataException,CoreWorkflowMetadataExceptionCode,} from 'src/engine/core-modules/workflow/exceptions/core-workflow-metadata.exception';-import { RecordPositionService } from 'src/engine/core-modules/record-position/services/record-position.service';-import { hasCoreWorkflowWorkspaceVersionIdColumn } from 'src/engine/core-modules/workflow/utils/has-core-workflow-workspace-version-id-column.util';-import { hasCoreWorkflowWorkspaceWorkflowIdColumn } from 'src/engine/core-modules/workflow/utils/has-core-workflow-workspace-workflow-id-column.util';import { resolveCoreWorkflowIdsByWorkspaceWorkflowId } from 'src/engine/core-modules/workflow/utils/resolve-core-workflow-ids-by-workspace-workflow-id.util';import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';import { WorkspaceOrmManager } from 'src/engine/twenty-orm/workspace-orm.manager';-import { type WorkspaceTransactionScope } from 'src/engine/twenty-orm/types/workspace-transaction-scope.type';-import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace-repository';import { InjectWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/inject-workspace-scoped-repository.decorator';import { WorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/workspace-scoped-repository';import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';import { InjectCacheStorage } from 'src/engine/core-modules/cache-storage/decorators/cache-storage.decorator';import { CacheStorageService } from 'src/engine/core-modules/cache-storage/services/cache-storage.service';import { CacheStorageNamespace } from 'src/engine/core-modules/cache-storage/types/cache-storage-namespace.enum';-import { WORKFLOW_CRON_TRIGGER_CACHE_KEY } from 'src/modules/workflow/workflow-trigger/automated-trigger/crons/constants/workflow-cron-trigger-cache-key.constant';import { type CachedCronTrigger } from 'src/modules/workflow/workflow-trigger/automated-trigger/crons/types/cached-cron-trigger.type';import { publishCronTriggerCacheEntry } from 'src/modules/workflow/workflow-trigger/automated-trigger/crons/utils/publish-cron-trigger-cache-entry.util';import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';import { type WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';import { type WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';-import { WorkflowMetadataReadService } from 'src/modules/workflow/common/workspace-services/workflow-metadata-read.workspace-service';-import { assertWorkflowVersionIsNotMalformedOrThrow } from 'src/modules/workflow/workflow-builder/workflow-validation/utils/assert-workflow-version-is-not-malformed-or-throw.util';@Injectable()export class WorkflowVersionCoreSyncService {@@ -58,8 +47,6 @@ export class WorkflowVersionCoreSyncService {private readonly workspaceRepository: Repository<WorkspaceEntity>,private readonly workspaceOrmManager: WorkspaceOrmManager,private readonly workspaceCacheService: WorkspaceCacheService,- private readonly recordPositionService: RecordPositionService,- private readonly workflowMetadataReadService: WorkflowMetadataReadService,private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,private readonly flatEntityMapsCacheService: WorkspaceManyOrAllFlatEntityMapsCacheService,private readonly applicationService: ApplicationService,@@ -283,31 +270,6 @@ export class WorkflowVersionCoreSyncService {);}- async deleteFromCore(- workspaceId: string,- coreWorkflowVersionIds: string[],- ): Promise<void> {- if (coreWorkflowVersionIds.length === 0) {- return;- }-- const deletedVersions = await this.coreWorkflowVersionRepository.find(- workspaceId,- {- where: { id: In(coreWorkflowVersionIds) },- select: { id: true, coreWorkflowId: true, status: true },- },- );-- await this.deleteCoreVersionsThroughMigration({- workspaceId,- coreWorkflowVersionIds,- });-- await this.invalidateAutomatedTriggerMaps(workspaceId);- await this.evictCronTriggerCacheEntries(deletedVersions);- }-async publishCronTriggerCacheEntries(cachedTriggers: CachedCronTrigger[],): Promise<void> {@@ -320,92 +282,6 @@ export class WorkflowVersionCoreSyncService {}}- private async evictCronTriggerCacheEntries(- deletedVersions: Pick<WorkflowVersionEntity, 'coreWorkflowId' | 'status'>[],- ): Promise<void> {- const fields = [- ...new Set(- deletedVersions- .filter((version) => version.status === WorkflowVersionStatus.ACTIVE)- .map((version) => version.coreWorkflowId)- .filter(isNonEmptyString),- ),- ];-- for (const field of fields) {- await this.cacheStorageService.hashDelete({- key: WORKFLOW_CRON_TRIGGER_CACHE_KEY,- field,- });- }- }-- private async deleteCoreVersionsThroughMigration({- workspaceId,- coreWorkflowVersionIds,- }: {- workspaceId: string;- coreWorkflowVersionIds: string[];- }): Promise<void> {- if (coreWorkflowVersionIds.length === 0) {- return;- }-- const { flatWorkflowVersionMaps } =- await this.flatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps(- { workspaceId, flatMapsKeys: ['flatWorkflowVersionMaps'] },- );-- const resolvedFlatVersions = coreWorkflowVersionIds.map(- (coreWorkflowVersionId) =>- findFlatEntityByIdInFlatEntityMaps({- flatEntityId: coreWorkflowVersionId,- flatEntityMaps: flatWorkflowVersionMaps,- }),- );-- const missingCoreWorkflowVersionIds = coreWorkflowVersionIds.filter(- (_, index) => !isDefined(resolvedFlatVersions[index]),- );-- // gone from the table means the dual-write listener already deleted it; still there means a stale cache, so fail rather than orphan it- if (missingCoreWorkflowVersionIds.length > 0) {- const stillPersisted = await this.coreWorkflowVersionRepository.find(- workspaceId,- {- where: { id: In(missingCoreWorkflowVersionIds) },- select: { id: true },- },- );-- if (stillPersisted.length > 0) {- throw new CoreWorkflowMetadataException(- `Core workflow versions ${stillPersisted.map(({ id }) => id).join(', ')} are persisted but missing from the flat entity maps`,- CoreWorkflowMetadataExceptionCode.WORKFLOW_VERSION_NOT_FOUND,- );- }- }-- const flatVersionsToDelete = resolvedFlatVersions.filter(isDefined);-- if (flatVersionsToDelete.length === 0) {- return;- }-- await this.runCoreWorkflowMigration({- workspaceId,- failureMessage:- 'Multiple validation errors occurred while deleting workflow versions',- operations: {- workflowVersion: {- flatEntityToCreate: [],- flatEntityToDelete: flatVersionsToDelete,- flatEntityToUpdate: [],- },- },- });- }-async findCoreVersionById(workspaceId: string,coreWorkflowVersionId: string,@@ -472,153 +348,6 @@ export class WorkflowVersionCoreSyncService {}, buildSystemAuthContext(workspaceId));}- async mirrorWorkflowVersionWrite({- workspaceId,- transactionScope,- workflowVersion,- applicationId,- }: {- workspaceId: string;- transactionScope: WorkspaceTransactionScope;- workflowVersion: WorkflowVersionWorkspaceEntity;- applicationId?: string;- }): Promise<{ coreWorkflowVersionId: string } | null> {- if (!(await this.workspaceHasCoreWorkflowVersionIdField(workspaceId))) {- this.logger.warn(- `workflowVersion.coreWorkflowVersionId field missing for workspace ${workspaceId}, skipping transactional core mirror`,- );-- return null;- }-- const resolvedApplicationId =- applicationId ?? (await this.getCustomApplicationIdOrThrow(workspaceId));-- const hasWorkspaceVersionMapping =- await hasCoreWorkflowWorkspaceVersionIdColumn((query) =>- transactionScope.executeRawQuery(query),- );- const candidateCoreVersionId = workflowVersion.coreWorkflowVersionId;- const candidateRows = isNonEmptyString(candidateCoreVersionId)- ? ((await transactionScope.executeRawQuery(- `SELECT "id", "workspaceId", "workflowId", "coreWorkflowId"${hasWorkspaceVersionMapping ? ', "workspaceWorkflowVersionId"' : ''} FROM core."workflowVersion" WHERE id = $1 FOR UPDATE`,- [candidateCoreVersionId],- )) as {- id: string;- workspaceId: string;- workflowId: string | null;- coreWorkflowId: string | null;- workspaceWorkflowVersionId?: string | null;- }[])- : [];- const candidate = candidateRows[0];-- if (- isDefined(candidate) &&- (candidate.workspaceId !== workspaceId ||- candidate.workflowId !== workflowVersion.workflowId ||- (isDefined(candidate.workspaceWorkflowVersionId) &&- candidate.workspaceWorkflowVersionId !== workflowVersion.id))- ) {- throw new Error(- `Conflicting core mapping for workflow version ${workflowVersion.id} in workspace ${workspaceId}`,- );- }-- const reverseRows = hasWorkspaceVersionMapping- ? ((await transactionScope.executeRawQuery(- `SELECT id, "coreWorkflowId" FROM core."workflowVersion" WHERE "workspaceId" = $1 AND "workspaceWorkflowVersionId" = $2 FOR UPDATE`,- [workspaceId, workflowVersion.id],- )) as { id: string; coreWorkflowId: string | null }[])- : [];-- if (- reverseRows.length > 1 ||- (isDefined(candidate) &&- isDefined(reverseRows[0]) &&- reverseRows[0].id !== candidate.id)- ) {- throw new Error(- `Ambiguous core mapping for workflow version ${workflowVersion.id} in workspace ${workspaceId}`,- );- }-- const existingCoreRow = reverseRows[0] ?? candidate;-- const coreWorkflowVersionId =- existingCoreRow?.id ?? candidateCoreVersionId ?? uuidv4();- const isNewLink =- workflowVersion.coreWorkflowVersionId !== coreWorkflowVersionId;-- const coreWorkflowId =- (await this.resolveCoreWorkflowIdInTransaction({- workspaceId,- workflowId: workflowVersion.workflowId,- transactionScope,- })) ?? existingCoreRow?.coreWorkflowId;-- if (!isNonEmptyString(coreWorkflowId)) {- throw new CoreWorkflowMetadataException(- `Core workflow for workflow ${workflowVersion.workflowId} not found in workspace ${workspaceId}`,- CoreWorkflowMetadataExceptionCode.WORKFLOW_VERSION_MISSING_WORKFLOW,- );- }-- // the conflict target is the primary key alone, so the workspaceId predicate keeps another workspace's row from being overwritten- const mirroredRows = await transactionScope.executeRawQuery(- `INSERT INTO core."workflowVersion"- ("id", "workspaceId", "workflowId", "triggers", "steps", "status", "universalIdentifier", "applicationId", "coreWorkflowId"${hasWorkspaceVersionMapping ? ', "workspaceWorkflowVersionId"' : ''})- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9${hasWorkspaceVersionMapping ? ', $10' : ''})- ON CONFLICT ("id") DO UPDATE SET- ${hasWorkspaceVersionMapping ? '"workspaceWorkflowVersionId" = EXCLUDED."workspaceWorkflowVersionId",' : ''}- "triggers" = EXCLUDED."triggers",- "steps" = EXCLUDED."steps",- "status" = EXCLUDED."status",- "coreWorkflowId" = EXCLUDED."coreWorkflowId"- WHERE core."workflowVersion"."workspaceId" = EXCLUDED."workspaceId" RETURNING id`,- [- coreWorkflowVersionId,- workspaceId,- workflowVersion.workflowId,- isDefined(workflowVersion.trigger)- ? JSON.stringify([workflowVersion.trigger])- : null,- isDefined(workflowVersion.steps)- ? JSON.stringify(workflowVersion.steps)- : null,- workflowVersion.status,- uuidv4(),- resolvedApplicationId,- coreWorkflowId,- ...(hasWorkspaceVersionMapping ? [workflowVersion.id] : []),- ],- );-- if (mirroredRows.length !== 1) {- throw new Error(- `Core workflow version ${coreWorkflowVersionId} could not be mirrored in workspace ${workspaceId}`,- );- }-- if (isNewLink) {- await this.writeBackCoreVersionIdInTransaction(- workflowVersion.id,- coreWorkflowVersionId,- transactionScope,- );- }-- // raw SQL inside the caller's transaction bypasses the runner, so flat entity maps must be invalidated by hand- transactionScope.afterCommit(async () => {- await this.flatEntityMapsCacheService.invalidateFlatEntityMaps({- workspaceId,- flatMapsKeys: ['flatWorkflowVersionMaps'],- });- });-- return { coreWorkflowVersionId };- }-private async resolveCoreWorkflowIdByWorkflowId(workspaceId: string,workflowIds: string[],@@ -678,212 +407,6 @@ export class WorkflowVersionCoreSyncService {return coreWorkflowIdByWorkflowId;}- private async resolveCoreWorkflowIdInTransaction({- workspaceId,- workflowId,- transactionScope,- }: {- workspaceId: string;- workflowId: string;- transactionScope: WorkspaceTransactionScope;- }): Promise<string | null> {- const workflow = await transactionScope- .getRepository<WorkflowWorkspaceEntity>('workflow', {- shouldBypassPermissionChecks: true,- })- .findOne({ where: { id: workflowId }, withDeleted: true });-- const pointedCoreWorkflowId = workflow?.coreWorkflowId ?? null;-- const isColumnAvailable = await hasCoreWorkflowWorkspaceWorkflowIdColumn(- (query) => transactionScope.executeRawQuery(query),- );-- if (!isColumnAvailable) {- return pointedCoreWorkflowId;- }-- if (isNonEmptyString(pointedCoreWorkflowId)) {- const pointedRows = (await transactionScope.executeRawQuery(- `SELECT "workspaceId", "workspaceWorkflowId" FROM core."workflow" WHERE id = $1 FOR UPDATE`,- [pointedCoreWorkflowId],- )) as { workspaceId: string; workspaceWorkflowId: string | null }[];- const pointed = pointedRows[0];-- if (isDefined(pointed)) {- if (- pointed.workspaceId !== workspaceId ||- pointed.workspaceWorkflowId !== workflowId- ) {- throw new Error(- `Conflicting core mapping for workflow ${workflowId} in workspace ${workspaceId}`,- );- }- return pointedCoreWorkflowId;- }- }-- const coreWorkflowIdByWorkspaceWorkflowId =- await resolveCoreWorkflowIdsByWorkspaceWorkflowId({- executeQuery: (query, parameters) =>- transactionScope.executeRawQuery(query, parameters),- workspaceId,- workspaceWorkflowIds: [workflowId],- });-- return coreWorkflowIdByWorkspaceWorkflowId.get(workflowId) ?? null;- }-- async mirrorWorkflowVersionWrites({- workspaceId,- transactionScope,- workflowVersions,- }: {- workspaceId: string;- transactionScope: WorkspaceTransactionScope;- workflowVersions: WorkflowVersionWorkspaceEntity[];- }): Promise<Map<string, string>> {- const coreIdByWorkspaceRecordId = new Map<string, string>();-- if (workflowVersions.length === 0) {- return coreIdByWorkspaceRecordId;- }-- const applicationId = await this.getCustomApplicationIdOrThrow(workspaceId);-- for (const workflowVersion of workflowVersions) {- const result = await this.mirrorWorkflowVersionWrite({- workspaceId,- transactionScope,- workflowVersion,- applicationId,- });-- if (isDefined(result)) {- coreIdByWorkspaceRecordId.set(- workflowVersion.id,- result.coreWorkflowVersionId,- );- }- }-- return coreIdByWorkspaceRecordId;- }-- async createInitialDraftVersionForWorkflow(- workspaceId: string,- workflowId: string,- ): Promise<void> {- await this.writeWorkflowVersionAndMirror(- workspaceId,- async (workflowVersionRepository) => {- const position = await this.recordPositionService.buildRecordPosition({- value: 'first',- objectMetadata: {- isCustom: false,- nameSingular: 'workflowVersion',- },- workspaceId,- });-- const insertResult = await workflowVersionRepository.insert({- workflowId,- status: WorkflowVersionStatus.DRAFT,- name: 'v1',- position,- });-- return (insertResult.generatedMaps[0] as WorkflowVersionWorkspaceEntity)- .id;- },- );- }-- async writeWorkflowVersionAndMirror(- workspaceId: string,- write: (- workflowVersionRepository: WorkspaceRepository<WorkflowVersionWorkspaceEntity>,- transactionScope: WorkspaceTransactionScope,- ) => Promise<string>,- ): Promise<void> {- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {- await this.workspaceOrmManager.runInWorkspaceTransaction(- async (transactionScope) => {- const workflowVersionRepository =- transactionScope.getRepository<WorkflowVersionWorkspaceEntity>(- 'workflowVersion',- { shouldBypassPermissionChecks: true },- );-- const workflowVersionId = await write(- workflowVersionRepository,- transactionScope,- );-- const workflowVersion = await workflowVersionRepository.findOne({- where: { id: workflowVersionId },- });-- if (isDefined(workflowVersion)) {- const {- flatObjectMetadataMaps,- flatFieldMetadataMaps,- objectIdByNameSingular,- } =- await this.workflowMetadataReadService.getFlatEntityMaps(- workspaceId,- );-- assertWorkflowVersionIsNotMalformedOrThrow({- trigger: workflowVersion.trigger,- steps: workflowVersion.steps,- flatObjectMetadataMaps,- flatFieldMetadataMaps,- objectIdByNameSingular,- });-- await this.mirrorWorkflowVersionWrite({- workspaceId,- transactionScope,- workflowVersion,- });- }- },- );- }, buildSystemAuthContext(workspaceId));-- await this.invalidateAutomatedTriggerMaps(workspaceId);- }-- async deleteCoreVersionsByWorkspaceVersionIds(- workspaceId: string,- workflowVersionIds: string[],- ): Promise<void> {- if (workflowVersionIds.length === 0) {- return;- }-- const coreWorkflowVersionIds =- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {- const workflowVersionRepository =- this.workspaceOrmManager.getRepository<WorkflowVersionWorkspaceEntity>(- 'workflowVersion',- { shouldBypassPermissionChecks: true },- );-- const versions = await workflowVersionRepository.find({- where: { id: In(workflowVersionIds) },- withDeleted: true,- });-- return versions- .map((version) => version.coreWorkflowVersionId)- .filter(isNonEmptyString);- }, buildSystemAuthContext(workspaceId));-- await this.deleteFromCore(workspaceId, coreWorkflowVersionIds);- }-private async writeBackCoreVersionIds(workspaceId: string,coreVersionIdByWorkspaceRecordId: Map<string, string>,@@ -918,23 +441,6 @@ export class WorkflowVersionCoreSyncService {}, buildSystemAuthContext(workspaceId));}- private async writeBackCoreVersionIdInTransaction(- workflowVersionId: string,- coreWorkflowVersionId: string,- transactionScope: WorkspaceTransactionScope,- ): Promise<void> {- const workspaceWorkflowVersionRepository =- transactionScope.getRepository<WorkflowVersionWorkspaceEntity>(- 'workflowVersion',- { shouldBypassPermissionChecks: true },- );-- await workspaceWorkflowVersionRepository.update(- { id: workflowVersionId },- { coreWorkflowVersionId },- );- }-private async workspaceHasCoreWorkflowVersionIdField(workspaceId: string,): Promise<boolean> {@@ -951,23 +457,6 @@ export class WorkflowVersionCoreSyncService {);}- private async getCustomApplicationIdOrThrow(- workspaceId: string,- ): Promise<string> {- const workspace = await this.workspaceRepository.findOne({- where: { id: workspaceId },- select: ['id', 'workspaceCustomApplicationId'],- });-- if (!isDefined(workspace?.workspaceCustomApplicationId)) {- throw new Error(- `Workspace custom application not found for workspace ${workspaceId}`,- );- }-- return workspace.workspaceCustomApplicationId;- }-async invalidateAutomatedTriggerMaps(workspaceId: string): Promise<void> {await this.workspaceCacheService.invalidateAndRecompute(workspaceId, ['workflowAutomatedTriggerMaps',diff --git a/packages/twenty-server/src/engine/core-modules/workflow/utils/has-core-workflow-workspace-version-id-column.util.ts b/packages/twenty-server/src/engine/core-modules/workflow/utils/has-core-workflow-workspace-version-id-column.util.tsdeleted file mode 100644index cce6a4d0a0c..00000000000--- a/packages/twenty-server/src/engine/core-modules/workflow/utils/has-core-workflow-workspace-version-id-column.util.ts+++ /dev/null@@ -1,11 +0,0 @@-export const hasCoreWorkflowWorkspaceVersionIdColumn = async (- executeQuery: (query: string) => Promise<unknown[]>,-): Promise<boolean> => {- const rows = await executeQuery(- `SELECT 1 FROM information_schema.columns- WHERE table_schema = 'core' AND table_name = 'workflowVersion'- AND column_name = 'workspaceWorkflowVersionId'`,- );-- return rows.length > 0;-};diff --git a/packages/twenty-server/src/modules/workflow/workflow-runner/workspace-services/workflow-runner.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-runner/workspace-services/workflow-runner.workspace-service.tsindex 9ac6a30f49e..67333559622 100644--- a/packages/twenty-server/src/modules/workflow/workflow-runner/workspace-services/workflow-runner.workspace-service.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-runner/workspace-services/workflow-runner.workspace-service.ts@@ -1,7 +1,6 @@import { Injectable } from '@nestjs/common';import { isString } from '@sniptt/guards';-import { type ActorMetadata } from 'twenty-shared/types';import { isDefined, isPlainObject, isValidUuid } from 'twenty-shared/utils';import { StepStatus } from 'twenty-shared/workflow';import { msg } from '@lingui/core/macro';@@ -35,8 +34,6 @@ import { buildRunWorkflowJobOptions } from 'src/modules/workflow/workflow-runnerimport { getRunnableStepIds } from 'src/modules/workflow/workflow-runner/utils/get-runnable-step-ids.util';import { WorkflowThrottlingWorkspaceService } from 'src/modules/workflow/workflow-runner/workflow-run-queue/workspace-services/workflow-throttling.workspace-service';import { WorkflowRunWorkspaceService } from 'src/modules/workflow/workflow-runner/workflow-run/workflow-run.workspace-service';-import { CoreWorkflowRunnerService } from 'src/modules/workflow/workflow-runner/services/core-workflow-runner.service';-import { WorkflowVersionCoreSyncService } from 'src/engine/core-modules/workflow/services/workflow-version-core-sync.service';@Injectable()export class WorkflowRunnerWorkspaceService {@@ -46,46 +43,9 @@ export class WorkflowRunnerWorkspaceService {private readonly messageQueueService: MessageQueueService,private readonly workflowVersionStepOperationsWorkspaceService: WorkflowVersionStepOperationsWorkspaceService,private readonly workflowThrottlingWorkspaceService: WorkflowThrottlingWorkspaceService,- private readonly coreWorkflowRunnerService: CoreWorkflowRunnerService,- private readonly workflowVersionCoreSyncService: WorkflowVersionCoreSyncService,private readonly workflowExecutionContextService: WorkflowExecutionContextService,) {}- async run({- workspaceId,- workflowVersionId,- payload,- source,- workflowRunId: initialWorkflowRunId,- }: {- workspaceId: string;- workflowVersionId: string;- payload: object;- source: ActorMetadata;- workflowRunId?: string;- }) {- const coreWorkflowVersion =- await this.workflowVersionCoreSyncService.findCoreVersionByWorkspaceVersionId(- workspaceId,- workflowVersionId,- );-- if (!isDefined(coreWorkflowVersion)) {- throw new WorkflowRunException(- 'Workspace workflow version has no core execution mapping',- WorkflowRunExceptionCode.WORKFLOW_RUN_INVALID,- );- }-- return this.coreWorkflowRunnerService.run({- workspaceId,- coreWorkflowVersionId: coreWorkflowVersion.id,- workflowRunId: initialWorkflowRunId,- payload,- source,- });- }-async resume({workspaceId,workflowRunId,diff --git a/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module.ts b/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module.tsindex 74b81aa079e..e421a94bc18 100644--- a/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module.ts@@ -9,7 +9,6 @@ import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entimport { RecordShareModule } from 'src/engine/core-modules/record-share/record-share.module';import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';import { WorkflowCommonModule } from 'src/modules/workflow/common/workflow-common.module';-import { AutomatedTriggerWorkspaceService } from 'src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.workspace-service';import { WorkflowCronTriggerCronCommand } from 'src/modules/workflow/workflow-trigger/automated-trigger/crons/commands/workflow-cron-trigger.cron.command';import { WorkflowCronTriggerCronJob } from 'src/modules/workflow/workflow-trigger/automated-trigger/crons/jobs/workflow-cron-trigger-cron.job';import { WorkflowDatabaseEventTriggerListener } from 'src/modules/workflow/workflow-trigger/automated-trigger/listeners/workflow-database-event-trigger.listener';@@ -25,11 +24,10 @@ import { WorkflowDatabaseEventTriggerListener } from 'src/modules/workflow/workfWorkspaceCacheModule,],providers: [- AutomatedTriggerWorkspaceService,WorkflowDatabaseEventTriggerListener,WorkflowCronTriggerCronJob,WorkflowCronTriggerCronCommand,],- exports: [AutomatedTriggerWorkspaceService, WorkflowCronTriggerCronCommand],+ exports: [WorkflowCronTriggerCronCommand],})export class AutomatedTriggerModule {}diff --git a/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.workspace-service.tsdeleted file mode 100644index 59e0acb0430..00000000000--- a/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.workspace-service.ts+++ /dev/null@@ -1,88 +0,0 @@-import { Injectable } from '@nestjs/common';-import { isDefined } from 'twenty-shared/utils';--import { type AutomatedTriggerType } from 'src/engine/core-modules/workflow/enums/automated-trigger-type.enum';-import { WorkspaceOrmManager } from 'src/engine/twenty-orm/workspace-orm.manager';-import { type WorkspaceTransactionScope } from 'src/engine/twenty-orm/types/workspace-transaction-scope.type';-import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';-import { type WorkflowAutomatedTriggerWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-automated-trigger.workspace-entity';-import { type AutomatedTriggerSettings } from 'src/modules/workflow/workflow-trigger/automated-trigger/constants/automated-trigger-settings';--@Injectable()-export class AutomatedTriggerWorkspaceService {- constructor(private readonly workspaceOrmManager: WorkspaceOrmManager) {}-- async addAutomatedTrigger({- workflowId,- type,- settings,- workspaceId,- transactionScope,- }: {- workflowId: string;- type: AutomatedTriggerType;- settings: AutomatedTriggerSettings;- workspaceId: string;- transactionScope?: WorkspaceTransactionScope;- }) {- if (isDefined(transactionScope)) {- await transactionScope- .getRepository<WorkflowAutomatedTriggerWorkspaceEntity>(- 'workflowAutomatedTrigger',- { shouldBypassPermissionChecks: true },- )- .insert({ type, settings, workflowId });-- return;- }-- const authContext = buildSystemAuthContext(workspaceId);-- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {- const workflowAutomatedTriggerRepository =- this.workspaceOrmManager.getRepository<WorkflowAutomatedTriggerWorkspaceEntity>(- 'workflowAutomatedTrigger',- { shouldBypassPermissionChecks: true },- );-- await workflowAutomatedTriggerRepository.insert({- type,- settings,- workflowId,- });- }, authContext);- }-- async deleteAutomatedTrigger({- workflowId,- workspaceId,- transactionScope,- }: {- workflowId: string;- workspaceId: string;- transactionScope?: WorkspaceTransactionScope;- }) {- if (isDefined(transactionScope)) {- await transactionScope- .getRepository<WorkflowAutomatedTriggerWorkspaceEntity>(- 'workflowAutomatedTrigger',- { shouldBypassPermissionChecks: true },- )- .delete({ workflowId });-- return;- }-- const authContext = buildSystemAuthContext(workspaceId);-- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {- const workflowAutomatedTriggerRepository =- this.workspaceOrmManager.getRepository<WorkflowAutomatedTriggerWorkspaceEntity>(- 'workflowAutomatedTrigger',- { shouldBypassPermissionChecks: true },- );-- await workflowAutomatedTriggerRepository.delete({ workflowId });- }, authContext);- }-}