From 265d5affc6b9eb00380c6ca786c3f18c872d799a Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sun, 31 Aug 2025 20:35:09 +0200 Subject: [PATCH] Fix ES module bundling issues by isolating pure types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create dedicated types-only module (src/types/index.ts) with pure type definitions - Update main index.ts to export only pure types without runtime imports - Removes need for serverExternalPackages in Next.js configuration - Plugin now works "out of the box" without bundling workarounds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/index.ts | 14 ++++++++--- src/types/index.ts | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/types/index.ts diff --git a/src/index.ts b/src/index.ts index 399d76e..fe355f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,16 @@ // Main export contains only types and client-safe utilities // Server-side functions are exported via '@xtr-dev/payload-automation/server' -// Types only - safe for client bundling -export type { CustomTriggerOptions, TriggerResult } from './core/trigger-custom-workflow.js' -export type { ExecutionContext, Workflow, WorkflowStep, WorkflowTrigger } from './core/workflow-executor.js' -export type { WorkflowsPluginConfig } from './plugin/config-types.js' +// Pure types only - completely safe for client bundling +export type { + CustomTriggerOptions, + TriggerResult, + ExecutionContext, + Workflow, + WorkflowStep, + WorkflowTrigger, + WorkflowsPluginConfig +} from './types/index.js' // Server-side functions are NOT re-exported here to avoid bundling issues // Import server-side functions from the /server export instead diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 0000000..0cccd8e --- /dev/null +++ b/src/types/index.ts @@ -0,0 +1,62 @@ +// Pure type definitions for client-safe exports +// This file contains NO runtime code and can be safely bundled + +export interface CustomTriggerOptions { + workflowId: string + triggerData?: any + req?: any // PayloadRequest type, but avoiding import to keep this client-safe +} + +export interface TriggerResult { + success: boolean + runId?: string + error?: string +} + +export interface ExecutionContext { + trigger: { + type: string + doc?: any + data?: any + } + steps: Record + payload: any // Payload instance + req: any // PayloadRequest +} + +export interface WorkflowStep { + id: string + type: string + input: Record + dependencies?: string[] +} + +export interface WorkflowTrigger { + type: 'collection' | 'global' | 'webhook' | 'cron' | 'manual' + collection?: string + global?: string + event?: 'create' | 'update' | 'delete' | 'read' + path?: string + cron?: string +} + +export interface Workflow { + id: string + name: string + description?: string + active: boolean + triggers: WorkflowTrigger[] + steps: WorkflowStep[] +} + +export interface WorkflowsPluginConfig { + collections?: string[] + globals?: string[] + logging?: { + level?: 'debug' | 'info' | 'warn' | 'error' + enabled?: boolean + } +} \ No newline at end of file