diff --git a/packages/framework/src/client.ts b/packages/framework/src/client.ts index 5fa59ccccd9..b90fd7d9585 100644 --- a/packages/framework/src/client.ts +++ b/packages/framework/src/client.ts @@ -13,7 +13,6 @@ import { ProviderNotFoundError, StepControlCompilationFailedError, StepNotFoundError, - WorkflowAlreadyExistsError, WorkflowNotFoundError, StepExecutionFailedError, isFrameworkError, @@ -46,6 +45,7 @@ import { import { validateData } from './validators'; import { mockSchema } from './jsonSchemaFaker'; +import { prettyPrintDiscovery } from './resources/workflow/pretty-print-discovery'; function isRuntimeInDevelopment() { return ['development', undefined].includes(process.env.NODE_ENV); @@ -94,12 +94,13 @@ export class Client { return builtConfiguration; } - public async addWorkflows(workflows: Array) { + public async addWorkflows(workflows: Array): Promise { for (const workflow of workflows) { - const definition = await workflow.discover(); - if (this.discoveredWorkflows.some((existing) => existing.workflowId === definition.workflowId)) { - throw new WorkflowAlreadyExistsError(definition.workflowId); + if (this.discoveredWorkflows.some((existing) => existing.workflowId === workflow.id)) { + return; } else { + const definition = await workflow.discover(); + prettyPrintDiscovery(definition); this.discoveredWorkflows.push(definition); } } diff --git a/packages/framework/src/resources/workflow/workflow.resource.ts b/packages/framework/src/resources/workflow/workflow.resource.ts index 7de9023d20f..c6d868d6558 100644 --- a/packages/framework/src/resources/workflow/workflow.resource.ts +++ b/packages/framework/src/resources/workflow/workflow.resource.ts @@ -18,7 +18,6 @@ import { discoverActionStepFactory } from './discover-action-step-factory'; import { discoverChannelStepFactory } from './discover-channel-step-factory'; import { discoverCustomStepFactory } from './discover-custom-step-factory'; import { mapPreferences } from './map-preferences'; -import { prettyPrintDiscovery } from './pretty-print-discovery'; /** * Define a new notification workflow. @@ -149,12 +148,11 @@ export function workflow< } as never, }); - prettyPrintDiscovery(newWorkflow); - return newWorkflow; }; return { + id: workflowId, trigger, discover, }; diff --git a/packages/framework/src/types/discover.types.ts b/packages/framework/src/types/discover.types.ts index a8e711ea107..0af4e50ee0c 100644 --- a/packages/framework/src/types/discover.types.ts +++ b/packages/framework/src/types/discover.types.ts @@ -67,6 +67,10 @@ export type DiscoverWorkflowOutput = { // eslint-disable-next-line @typescript-eslint/no-explicit-any export type Workflow = { + /** + * The unique identifier of the workflow. + */ + id: string; /** * Trigger an event for this workflow with a strongly typed and validated `payload`, derived from the `payloadSchema`. *