@xtr-dev/payload-automation 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -22,11 +22,28 @@ export class WorkflowExecutor {
|
|
|
22
22
|
}, 'Executing step');
|
|
23
23
|
// Check step condition if present
|
|
24
24
|
if (step.condition) {
|
|
25
|
+
this.logger.debug({
|
|
26
|
+
condition: step.condition,
|
|
27
|
+
stepName,
|
|
28
|
+
availableSteps: Object.keys(context.steps),
|
|
29
|
+
completedSteps: Object.entries(context.steps).filter(([_, s])=>s.state === 'succeeded').map(([name])=>name),
|
|
30
|
+
triggerType: context.trigger?.type
|
|
31
|
+
}, 'Evaluating step condition');
|
|
25
32
|
const conditionMet = this.evaluateStepCondition(step.condition, context);
|
|
26
33
|
if (!conditionMet) {
|
|
27
34
|
this.logger.info({
|
|
28
35
|
condition: step.condition,
|
|
29
|
-
stepName
|
|
36
|
+
stepName,
|
|
37
|
+
contextSnapshot: JSON.stringify({
|
|
38
|
+
stepOutputs: Object.entries(context.steps).reduce((acc, [name, step])=>{
|
|
39
|
+
acc[name] = {
|
|
40
|
+
state: step.state,
|
|
41
|
+
hasOutput: !!step.output
|
|
42
|
+
};
|
|
43
|
+
return acc;
|
|
44
|
+
}, {}),
|
|
45
|
+
triggerData: context.trigger?.data ? 'present' : 'absent'
|
|
46
|
+
})
|
|
30
47
|
}, 'Step condition not met, skipping');
|
|
31
48
|
// Mark step as completed but skipped
|
|
32
49
|
context.steps[stepName] = {
|
|
@@ -46,7 +63,17 @@ export class WorkflowExecutor {
|
|
|
46
63
|
}
|
|
47
64
|
this.logger.info({
|
|
48
65
|
condition: step.condition,
|
|
49
|
-
stepName
|
|
66
|
+
stepName,
|
|
67
|
+
contextSnapshot: JSON.stringify({
|
|
68
|
+
stepOutputs: Object.entries(context.steps).reduce((acc, [name, step])=>{
|
|
69
|
+
acc[name] = {
|
|
70
|
+
state: step.state,
|
|
71
|
+
hasOutput: !!step.output
|
|
72
|
+
};
|
|
73
|
+
return acc;
|
|
74
|
+
}, {}),
|
|
75
|
+
triggerData: context.trigger?.data ? 'present' : 'absent'
|
|
76
|
+
})
|
|
50
77
|
}, 'Step condition met, proceeding with execution');
|
|
51
78
|
}
|
|
52
79
|
// Initialize step context
|
|
@@ -210,32 +237,59 @@ export class WorkflowExecutor {
|
|
|
210
237
|
* Resolve step input using JSONPath expressions
|
|
211
238
|
*/ resolveStepInput(config, context) {
|
|
212
239
|
const resolved = {};
|
|
240
|
+
this.logger.debug({
|
|
241
|
+
configKeys: Object.keys(config),
|
|
242
|
+
contextSteps: Object.keys(context.steps),
|
|
243
|
+
triggerType: context.trigger?.type
|
|
244
|
+
}, 'Starting step input resolution');
|
|
213
245
|
for (const [key, value] of Object.entries(config)){
|
|
214
246
|
if (typeof value === 'string' && value.startsWith('$')) {
|
|
215
247
|
// This is a JSONPath expression
|
|
248
|
+
this.logger.debug({
|
|
249
|
+
key,
|
|
250
|
+
jsonPath: value,
|
|
251
|
+
availableSteps: Object.keys(context.steps),
|
|
252
|
+
hasTriggerData: !!context.trigger?.data,
|
|
253
|
+
hasTriggerDoc: !!context.trigger?.doc
|
|
254
|
+
}, 'Resolving JSONPath expression');
|
|
216
255
|
try {
|
|
217
256
|
const result = JSONPath({
|
|
218
257
|
json: context,
|
|
219
258
|
path: value,
|
|
220
259
|
wrap: false
|
|
221
260
|
});
|
|
261
|
+
this.logger.debug({
|
|
262
|
+
key,
|
|
263
|
+
jsonPath: value,
|
|
264
|
+
result: JSON.stringify(result).substring(0, 200),
|
|
265
|
+
resultType: Array.isArray(result) ? 'array' : typeof result
|
|
266
|
+
}, 'JSONPath resolved successfully');
|
|
222
267
|
resolved[key] = result;
|
|
223
268
|
} catch (error) {
|
|
224
269
|
this.logger.warn({
|
|
225
270
|
error: error instanceof Error ? error.message : 'Unknown error',
|
|
226
271
|
key,
|
|
227
|
-
path: value
|
|
272
|
+
path: value,
|
|
273
|
+
contextSnapshot: JSON.stringify(context).substring(0, 500)
|
|
228
274
|
}, 'Failed to resolve JSONPath');
|
|
229
275
|
resolved[key] = value; // Keep original value if resolution fails
|
|
230
276
|
}
|
|
231
277
|
} else if (typeof value === 'object' && value !== null) {
|
|
232
278
|
// Recursively resolve nested objects
|
|
279
|
+
this.logger.debug({
|
|
280
|
+
key,
|
|
281
|
+
nestedKeys: Object.keys(value)
|
|
282
|
+
}, 'Recursively resolving nested object');
|
|
233
283
|
resolved[key] = this.resolveStepInput(value, context);
|
|
234
284
|
} else {
|
|
235
285
|
// Keep literal values as-is
|
|
236
286
|
resolved[key] = value;
|
|
237
287
|
}
|
|
238
288
|
}
|
|
289
|
+
this.logger.debug({
|
|
290
|
+
resolvedKeys: Object.keys(resolved),
|
|
291
|
+
originalKeys: Object.keys(config)
|
|
292
|
+
}, 'Step input resolution completed');
|
|
239
293
|
return resolved;
|
|
240
294
|
}
|
|
241
295
|
/**
|
|
@@ -266,21 +320,43 @@ export class WorkflowExecutor {
|
|
|
266
320
|
/**
|
|
267
321
|
* Evaluate a condition using JSONPath
|
|
268
322
|
*/ evaluateCondition(condition, context) {
|
|
323
|
+
this.logger.debug({
|
|
324
|
+
condition,
|
|
325
|
+
contextKeys: Object.keys(context),
|
|
326
|
+
triggerType: context.trigger?.type,
|
|
327
|
+
triggerData: context.trigger?.data,
|
|
328
|
+
triggerDoc: context.trigger?.doc ? 'present' : 'absent'
|
|
329
|
+
}, 'Starting condition evaluation');
|
|
269
330
|
try {
|
|
270
331
|
const result = JSONPath({
|
|
271
332
|
json: context,
|
|
272
333
|
path: condition,
|
|
273
334
|
wrap: false
|
|
274
335
|
});
|
|
336
|
+
this.logger.debug({
|
|
337
|
+
condition,
|
|
338
|
+
result,
|
|
339
|
+
resultType: Array.isArray(result) ? 'array' : typeof result,
|
|
340
|
+
resultLength: Array.isArray(result) ? result.length : undefined
|
|
341
|
+
}, 'JSONPath evaluation result');
|
|
275
342
|
// Handle different result types
|
|
343
|
+
let finalResult;
|
|
276
344
|
if (Array.isArray(result)) {
|
|
277
|
-
|
|
345
|
+
finalResult = result.length > 0 && Boolean(result[0]);
|
|
346
|
+
} else {
|
|
347
|
+
finalResult = Boolean(result);
|
|
278
348
|
}
|
|
279
|
-
|
|
349
|
+
this.logger.debug({
|
|
350
|
+
condition,
|
|
351
|
+
finalResult,
|
|
352
|
+
originalResult: result
|
|
353
|
+
}, 'Condition evaluation completed');
|
|
354
|
+
return finalResult;
|
|
280
355
|
} catch (error) {
|
|
281
356
|
this.logger.warn({
|
|
282
357
|
condition,
|
|
283
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
358
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
359
|
+
errorStack: error instanceof Error ? error.stack : undefined
|
|
284
360
|
}, 'Failed to evaluate condition');
|
|
285
361
|
// If condition evaluation fails, assume false
|
|
286
362
|
return false;
|
|
@@ -411,6 +487,16 @@ export class WorkflowExecutor {
|
|
|
411
487
|
};
|
|
412
488
|
// Check trigger condition if present
|
|
413
489
|
if (trigger.condition) {
|
|
490
|
+
this.logger.debug({
|
|
491
|
+
collection,
|
|
492
|
+
operation,
|
|
493
|
+
condition: trigger.condition,
|
|
494
|
+
docId: doc?.id,
|
|
495
|
+
docFields: doc ? Object.keys(doc) : [],
|
|
496
|
+
previousDocId: previousDoc?.id,
|
|
497
|
+
workflowId: workflow.id,
|
|
498
|
+
workflowName: workflow.name
|
|
499
|
+
}, 'Evaluating collection trigger condition');
|
|
414
500
|
const conditionMet = this.evaluateCondition(trigger.condition, context);
|
|
415
501
|
if (!conditionMet) {
|
|
416
502
|
this.logger.info({
|
|
@@ -418,7 +504,8 @@ export class WorkflowExecutor {
|
|
|
418
504
|
condition: trigger.condition,
|
|
419
505
|
operation,
|
|
420
506
|
workflowId: workflow.id,
|
|
421
|
-
workflowName: workflow.name
|
|
507
|
+
workflowName: workflow.name,
|
|
508
|
+
docSnapshot: JSON.stringify(doc).substring(0, 200)
|
|
422
509
|
}, 'Trigger condition not met, skipping workflow');
|
|
423
510
|
continue;
|
|
424
511
|
}
|
|
@@ -427,7 +514,8 @@ export class WorkflowExecutor {
|
|
|
427
514
|
condition: trigger.condition,
|
|
428
515
|
operation,
|
|
429
516
|
workflowId: workflow.id,
|
|
430
|
-
workflowName: workflow.name
|
|
517
|
+
workflowName: workflow.name,
|
|
518
|
+
docSnapshot: JSON.stringify(doc).substring(0, 200)
|
|
431
519
|
}, 'Trigger condition met');
|
|
432
520
|
}
|
|
433
521
|
this.logger.info({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/workflow-executor.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\n\nimport { JSONPath } from 'jsonpath-plus'\n\nexport type Workflow = {\n _version?: number\n id: string\n name: string\n steps: WorkflowStep[]\n triggers: WorkflowTrigger[]\n}\n\nexport type WorkflowStep = {\n condition?: string\n dependencies?: string[]\n input?: null | Record<string, unknown>\n name: string\n step: string\n}\n\nexport interface WorkflowTrigger {\n collection?: string\n condition?: string\n global?: string\n globalOperation?: string\n operation?: string\n type: string\n webhookPath?: string\n}\n\nexport interface ExecutionContext {\n steps: Record<string, {\n error?: string\n input: unknown\n output: unknown\n state: 'failed' | 'pending' | 'running' | 'succeeded'\n }>\n trigger: {\n collection?: string\n data?: unknown\n doc?: unknown\n headers?: Record<string, string>\n operation?: string\n path?: string\n previousDoc?: unknown\n req?: PayloadRequest\n triggeredAt?: string\n type: string\n user?: {\n collection?: string\n email?: string\n id?: string\n }\n }\n}\n\nexport class WorkflowExecutor {\n constructor(\n private payload: Payload,\n private logger: Payload['logger']\n ) {}\n\n /**\n * Evaluate a step condition using JSONPath\n */\n private evaluateStepCondition(condition: string, context: ExecutionContext): boolean {\n return this.evaluateCondition(condition, context)\n }\n\n /**\n * Execute a single workflow step\n */\n private async executeStep(\n step: WorkflowStep,\n stepIndex: number,\n context: ExecutionContext,\n req: PayloadRequest,\n workflowRunId?: number | string\n ): Promise<void> {\n const stepName = step.name || 'step-' + stepIndex\n\n this.logger.info({\n hasStep: 'step' in step,\n step: JSON.stringify(step),\n stepName\n }, 'Executing step')\n\n // Check step condition if present\n if (step.condition) {\n const conditionMet = this.evaluateStepCondition(step.condition, context)\n\n if (!conditionMet) {\n this.logger.info({\n condition: step.condition,\n stepName\n }, 'Step condition not met, skipping')\n\n // Mark step as completed but skipped\n context.steps[stepName] = {\n error: undefined,\n input: undefined,\n output: { reason: 'Condition not met', skipped: true },\n state: 'succeeded'\n }\n\n // Update workflow run context if needed\n if (workflowRunId) {\n await this.updateWorkflowRunContext(workflowRunId, context, req)\n }\n\n return\n }\n\n this.logger.info({\n condition: step.condition,\n stepName\n }, 'Step condition met, proceeding with execution')\n }\n\n // Initialize step context\n context.steps[stepName] = {\n error: undefined,\n input: undefined,\n output: undefined,\n state: 'running'\n }\n\n // Move taskSlug declaration outside try block so it's accessible in catch\n const taskSlug = step.step // Use the 'step' field for task type\n\n try {\n // Resolve input data using JSONPath\n const resolvedInput = this.resolveStepInput(step.input || {}, context)\n context.steps[stepName].input = resolvedInput\n\n if (!taskSlug) {\n throw new Error(`Step ${stepName} is missing a task type`)\n }\n\n this.logger.info({\n hasInput: !!resolvedInput,\n hasReq: !!req,\n stepName,\n taskSlug\n }, 'Queueing task')\n\n const job = await this.payload.jobs.queue({\n input: resolvedInput,\n req,\n task: taskSlug\n })\n\n // Run the job immediately\n await this.payload.jobs.run({\n limit: 1,\n req\n })\n\n // Get the job result\n const completedJob = await this.payload.findByID({\n id: job.id,\n collection: 'payload-jobs',\n req\n })\n\n const taskStatus = completedJob.taskStatus?.[completedJob.taskSlug]?.[completedJob.totalTried]\n const isComplete = taskStatus?.complete === true\n const hasError = completedJob.hasError || !isComplete\n\n // Extract error information from job if available\n let errorMessage: string | undefined\n if (hasError) {\n // Try to get error from the latest log entry\n if (completedJob.log && completedJob.log.length > 0) {\n const latestLog = completedJob.log[completedJob.log.length - 1]\n errorMessage = latestLog.error?.message || latestLog.error\n }\n\n // Fallback to top-level error\n if (!errorMessage && completedJob.error) {\n errorMessage = completedJob.error.message || completedJob.error\n }\n\n // Final fallback to generic message\n if (!errorMessage) {\n errorMessage = `Task ${taskSlug} failed without detailed error information`\n }\n }\n\n const result: {\n error: string | undefined\n output: unknown\n state: 'failed' | 'succeeded'\n } = {\n error: errorMessage,\n output: taskStatus?.output || {},\n state: isComplete ? 'succeeded' : 'failed'\n }\n\n // Store the output and error\n context.steps[stepName].output = result.output\n context.steps[stepName].state = result.state\n if (result.error) {\n context.steps[stepName].error = result.error\n }\n\n this.logger.debug({context}, 'Step execution context')\n\n if (result.state !== 'succeeded') {\n throw new Error(result.error || `Step ${stepName} failed`)\n }\n\n this.logger.info({\n output: result.output,\n stepName\n }, 'Step completed')\n\n // Update workflow run with current step results if workflowRunId is provided\n if (workflowRunId) {\n await this.updateWorkflowRunContext(workflowRunId, context, req)\n }\n\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n context.steps[stepName].state = 'failed'\n context.steps[stepName].error = errorMessage\n\n this.logger.error({\n error: errorMessage,\n input: context.steps[stepName].input,\n stepName,\n taskSlug\n }, 'Step execution failed')\n\n // Update workflow run with current step results if workflowRunId is provided\n if (workflowRunId) {\n try {\n await this.updateWorkflowRunContext(workflowRunId, context, req)\n } catch (updateError) {\n this.logger.error({\n error: updateError instanceof Error ? updateError.message : 'Unknown error',\n stepName\n }, 'Failed to update workflow run context after step failure')\n }\n }\n\n throw error\n }\n }\n\n /**\n * Resolve step execution order based on dependencies\n */\n private resolveExecutionOrder(steps: WorkflowStep[]): WorkflowStep[][] {\n const stepMap = new Map<string, WorkflowStep>()\n const dependencyGraph = new Map<string, string[]>()\n const indegree = new Map<string, number>()\n\n // Build the step map and dependency graph\n for (const step of steps) {\n const stepName = step.name || `step-${steps.indexOf(step)}`\n const dependencies = step.dependencies || []\n\n stepMap.set(stepName, { ...step, name: stepName, dependencies })\n dependencyGraph.set(stepName, dependencies)\n indegree.set(stepName, dependencies.length)\n }\n\n // Topological sort to determine execution batches\n const executionBatches: WorkflowStep[][] = []\n const processed = new Set<string>()\n\n while (processed.size < steps.length) {\n const currentBatch: WorkflowStep[] = []\n\n // Find all steps with no remaining dependencies\n for (const [stepName, inDegree] of indegree.entries()) {\n if (inDegree === 0 && !processed.has(stepName)) {\n const step = stepMap.get(stepName)\n if (step) {\n currentBatch.push(step)\n }\n }\n }\n\n if (currentBatch.length === 0) {\n throw new Error('Circular dependency detected in workflow steps')\n }\n\n executionBatches.push(currentBatch)\n\n // Update indegrees for next iteration\n for (const step of currentBatch) {\n processed.add(step.name)\n\n // Reduce indegree for steps that depend on completed steps\n for (const [otherStepName, dependencies] of dependencyGraph.entries()) {\n if (dependencies.includes(step.name) && !processed.has(otherStepName)) {\n indegree.set(otherStepName, (indegree.get(otherStepName) || 0) - 1)\n }\n }\n }\n }\n\n return executionBatches\n }\n\n /**\n * Resolve step input using JSONPath expressions\n */\n private resolveStepInput(config: Record<string, unknown>, context: ExecutionContext): Record<string, unknown> {\n const resolved: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(config)) {\n if (typeof value === 'string' && value.startsWith('$')) {\n // This is a JSONPath expression\n try {\n const result = JSONPath({\n json: context,\n path: value,\n wrap: false\n })\n resolved[key] = result\n } catch (error) {\n this.logger.warn({\n error: error instanceof Error ? error.message : 'Unknown error',\n key,\n path: value\n }, 'Failed to resolve JSONPath')\n resolved[key] = value // Keep original value if resolution fails\n }\n } else if (typeof value === 'object' && value !== null) {\n // Recursively resolve nested objects\n resolved[key] = this.resolveStepInput(value as Record<string, unknown>, context)\n } else {\n // Keep literal values as-is\n resolved[key] = value\n }\n }\n\n return resolved\n }\n\n /**\n * Update workflow run with current context\n */\n private async updateWorkflowRunContext(\n workflowRunId: number | string,\n context: ExecutionContext,\n req: PayloadRequest\n ): Promise<void> {\n const serializeContext = () => ({\n steps: context.steps,\n trigger: {\n type: context.trigger.type,\n collection: context.trigger.collection,\n data: context.trigger.data,\n doc: context.trigger.doc,\n operation: context.trigger.operation,\n previousDoc: context.trigger.previousDoc,\n triggeredAt: context.trigger.triggeredAt,\n user: context.trigger.req?.user\n }\n })\n\n await this.payload.update({\n id: workflowRunId,\n collection: 'workflow-runs',\n data: {\n context: serializeContext()\n },\n req\n })\n }\n\n /**\n * Evaluate a condition using JSONPath\n */\n public evaluateCondition(condition: string, context: ExecutionContext): boolean {\n try {\n const result = JSONPath({\n json: context,\n path: condition,\n wrap: false\n })\n\n // Handle different result types\n if (Array.isArray(result)) {\n return result.length > 0 && Boolean(result[0])\n }\n\n return Boolean(result)\n } catch (error) {\n this.logger.warn({\n condition,\n error: error instanceof Error ? error.message : 'Unknown error'\n }, 'Failed to evaluate condition')\n\n // If condition evaluation fails, assume false\n return false\n }\n }\n\n /**\n * Execute a workflow with the given context\n */\n async execute(workflow: Workflow, context: ExecutionContext, req: PayloadRequest): Promise<void> {\n this.logger.info({\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Starting workflow execution')\n\n const serializeContext = () => ({\n steps: context.steps,\n trigger: {\n type: context.trigger.type,\n collection: context.trigger.collection,\n data: context.trigger.data,\n doc: context.trigger.doc,\n operation: context.trigger.operation,\n previousDoc: context.trigger.previousDoc,\n triggeredAt: context.trigger.triggeredAt,\n user: context.trigger.req?.user\n }\n })\n\n // Create a workflow run record\n const workflowRun = await this.payload.create({\n collection: 'workflow-runs',\n data: {\n context: serializeContext(),\n startedAt: new Date().toISOString(),\n status: 'running',\n triggeredBy: context.trigger.req?.user?.email || 'system',\n workflow: workflow.id,\n workflowVersion: workflow._version || 1\n },\n req\n })\n\n try {\n // Resolve execution order based on dependencies\n const executionBatches = this.resolveExecutionOrder(workflow.steps)\n\n this.logger.info({\n batchSizes: executionBatches.map(batch => batch.length),\n totalBatches: executionBatches.length\n }, 'Resolved step execution order')\n\n // Execute each batch in sequence, but steps within each batch in parallel\n for (let batchIndex = 0; batchIndex < executionBatches.length; batchIndex++) {\n const batch = executionBatches[batchIndex]\n\n this.logger.info({\n batchIndex,\n stepCount: batch.length,\n stepNames: batch.map(s => s.name)\n }, 'Executing batch')\n\n // Execute all steps in this batch in parallel\n const batchPromises = batch.map((step, stepIndex) =>\n this.executeStep(step, stepIndex, context, req, workflowRun.id)\n )\n\n // Wait for all steps in the current batch to complete\n await Promise.all(batchPromises)\n\n this.logger.info({\n batchIndex,\n stepCount: batch.length\n }, 'Batch completed')\n }\n\n // Update workflow run as completed\n await this.payload.update({\n id: workflowRun.id,\n collection: 'workflow-runs',\n data: {\n completedAt: new Date().toISOString(),\n context: serializeContext(),\n status: 'completed'\n },\n req\n })\n\n this.logger.info({\n runId: workflowRun.id,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Workflow execution completed')\n\n } catch (error) {\n // Update workflow run as failed\n await this.payload.update({\n id: workflowRun.id,\n collection: 'workflow-runs',\n data: {\n completedAt: new Date().toISOString(),\n context: serializeContext(),\n error: error instanceof Error ? error.message : 'Unknown error',\n status: 'failed'\n },\n req\n })\n\n this.logger.error({\n error: error instanceof Error ? error.message : 'Unknown error',\n runId: workflowRun.id,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Workflow execution failed')\n\n throw error\n }\n }\n\n /**\n * Find and execute workflows triggered by a collection operation\n */\n async executeTriggeredWorkflows(\n collection: string,\n operation: 'create' | 'delete' | 'read' | 'update',\n doc: unknown,\n previousDoc: unknown,\n req: PayloadRequest\n ): Promise<void> {\n try {\n // Find workflows with matching triggers\n const workflows = await this.payload.find({\n collection: 'workflows',\n depth: 2, // Include steps and triggers\n limit: 100,\n req\n })\n\n for (const workflow of workflows.docs) {\n // Check if this workflow has a matching trigger\n const triggers = workflow.triggers as Array<{\n collection: string\n condition?: string\n operation: string\n type: string\n }>\n\n const matchingTriggers = triggers?.filter(trigger =>\n trigger.type === 'collection-trigger' &&\n trigger.collection === collection &&\n trigger.operation === operation\n ) || []\n\n for (const trigger of matchingTriggers) {\n // Create execution context for condition evaluation\n const context: ExecutionContext = {\n steps: {},\n trigger: {\n type: 'collection',\n collection,\n doc,\n operation,\n previousDoc,\n req\n }\n }\n\n // Check trigger condition if present\n if (trigger.condition) {\n const conditionMet = this.evaluateCondition(trigger.condition, context)\n\n if (!conditionMet) {\n this.logger.info({\n collection,\n condition: trigger.condition,\n operation,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Trigger condition not met, skipping workflow')\n continue\n }\n\n this.logger.info({\n collection,\n condition: trigger.condition,\n operation,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Trigger condition met')\n }\n\n this.logger.info({\n collection,\n operation,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Triggering workflow')\n\n // Execute the workflow\n await this.execute(workflow as Workflow, context, req)\n }\n }\n } catch (error) {\n this.logger.error({ error: error instanceof Error ? error.message : 'Unknown error' }, 'Workflow execution failed')\n this.logger.error({\n collection,\n error: error instanceof Error ? error.message : 'Unknown error',\n operation\n }, 'Failed to execute triggered workflows')\n }\n }\n}\n"],"names":["JSONPath","WorkflowExecutor","payload","logger","evaluateStepCondition","condition","context","evaluateCondition","executeStep","step","stepIndex","req","workflowRunId","stepName","name","info","hasStep","JSON","stringify","conditionMet","steps","error","undefined","input","output","reason","skipped","state","updateWorkflowRunContext","taskSlug","resolvedInput","resolveStepInput","Error","hasInput","hasReq","job","jobs","queue","task","run","limit","completedJob","findByID","id","collection","taskStatus","totalTried","isComplete","complete","hasError","errorMessage","log","length","latestLog","message","result","debug","updateError","resolveExecutionOrder","stepMap","Map","dependencyGraph","indegree","indexOf","dependencies","set","executionBatches","processed","Set","size","currentBatch","inDegree","entries","has","get","push","add","otherStepName","includes","config","resolved","key","value","Object","startsWith","json","path","wrap","warn","serializeContext","trigger","type","data","doc","operation","previousDoc","triggeredAt","user","update","Array","isArray","Boolean","execute","workflow","workflowId","workflowName","workflowRun","create","startedAt","Date","toISOString","status","triggeredBy","email","workflowVersion","_version","batchSizes","map","batch","totalBatches","batchIndex","stepCount","stepNames","s","batchPromises","Promise","all","completedAt","runId","executeTriggeredWorkflows","work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AAiB,CAACmF,QAAQrF,SAAS,EAAEC;wBAE/D,IAAI,CAACa,cAAc;4BACjB,IAAI,CAAChB,MAAM,CAACY,IAAI,CAAC;gCACf6B;gCACAvC,WAAWqF,QAAQrF,SAAS;gCAC5ByF;gCACAU,YAAYD,SAAS5D,EAAE;gCACvB8D,cAAcF,SAASzF,IAAI;4BAC7B,GAAG;4BACH;wBACF;wBAEA,IAAI,CAACX,MAAM,CAACY,IAAI,CAAC;4BACf6B;4BACAvC,WAAWqF,QAAQrF,SAAS;4BAC5ByF;4BACAU,YAAYD,SAAS5D,EAAE;4BACvB8D,cAAcF,SAASzF,IAAI;wBAC7B,GAAG;oBACL;oBAEA,IAAI,CAACX,MAAM,CAACY,IAAI,CAAC;wBACf6B;wBACAkD;wBACAU,YAAYD,SAAS5D,EAAE;wBACvB8D,cAAcF,SAASzF,IAAI;oBAC7B,GAAG;oBAEH,uBAAuB;oBACvB,MAAM,IAAI,CAACwF,OAAO,CAACC,UAAsBjG,SAASK;gBACpD;YACF;QACF,EAAE,OAAOU,OAAO;YACd,IAAI,CAAClB,MAAM,CAACkB,KAAK,CAAC;gBAAEA,OAAOA,iBAAiBW,QAAQX,MAAMiC,OAAO,GAAG;YAAgB,GAAG;YACvF,IAAI,CAACnD,MAAM,CAACkB,KAAK,CAAC;gBAChBuB;gBACAvB,OAAOA,iBAAiBW,QAAQX,MAAMiC,OAAO,GAAG;gBAChDwC;YACF,GAAG;QACL;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/core/workflow-executor.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\n\nimport { JSONPath } from 'jsonpath-plus'\n\nexport type Workflow = {\n _version?: number\n id: string\n name: string\n steps: WorkflowStep[]\n triggers: WorkflowTrigger[]\n}\n\nexport type WorkflowStep = {\n condition?: string\n dependencies?: string[]\n input?: null | Record<string, unknown>\n name: string\n step: string\n}\n\nexport interface WorkflowTrigger {\n collection?: string\n condition?: string\n global?: string\n globalOperation?: string\n operation?: string\n type: string\n webhookPath?: string\n}\n\nexport interface ExecutionContext {\n steps: Record<string, {\n error?: string\n input: unknown\n output: unknown\n state: 'failed' | 'pending' | 'running' | 'succeeded'\n }>\n trigger: {\n collection?: string\n data?: unknown\n doc?: unknown\n headers?: Record<string, string>\n operation?: string\n path?: string\n previousDoc?: unknown\n req?: PayloadRequest\n triggeredAt?: string\n type: string\n user?: {\n collection?: string\n email?: string\n id?: string\n }\n }\n}\n\nexport class WorkflowExecutor {\n constructor(\n private payload: Payload,\n private logger: Payload['logger']\n ) {}\n\n /**\n * Evaluate a step condition using JSONPath\n */\n private evaluateStepCondition(condition: string, context: ExecutionContext): boolean {\n return this.evaluateCondition(condition, context)\n }\n\n /**\n * Execute a single workflow step\n */\n private async executeStep(\n step: WorkflowStep,\n stepIndex: number,\n context: ExecutionContext,\n req: PayloadRequest,\n workflowRunId?: number | string\n ): Promise<void> {\n const stepName = step.name || 'step-' + stepIndex\n\n this.logger.info({\n hasStep: 'step' in step,\n step: JSON.stringify(step),\n stepName\n }, 'Executing step')\n\n // Check step condition if present\n if (step.condition) {\n this.logger.debug({\n condition: step.condition,\n stepName,\n availableSteps: Object.keys(context.steps),\n completedSteps: Object.entries(context.steps)\n .filter(([_, s]) => s.state === 'succeeded')\n .map(([name]) => name),\n triggerType: context.trigger?.type\n }, 'Evaluating step condition')\n\n const conditionMet = this.evaluateStepCondition(step.condition, context)\n\n if (!conditionMet) {\n this.logger.info({\n condition: step.condition,\n stepName,\n contextSnapshot: JSON.stringify({\n stepOutputs: Object.entries(context.steps).reduce((acc, [name, step]) => {\n acc[name] = { state: step.state, hasOutput: !!step.output }\n return acc\n }, {} as Record<string, any>),\n triggerData: context.trigger?.data ? 'present' : 'absent'\n })\n }, 'Step condition not met, skipping')\n\n // Mark step as completed but skipped\n context.steps[stepName] = {\n error: undefined,\n input: undefined,\n output: { reason: 'Condition not met', skipped: true },\n state: 'succeeded'\n }\n\n // Update workflow run context if needed\n if (workflowRunId) {\n await this.updateWorkflowRunContext(workflowRunId, context, req)\n }\n\n return\n }\n\n this.logger.info({\n condition: step.condition,\n stepName,\n contextSnapshot: JSON.stringify({\n stepOutputs: Object.entries(context.steps).reduce((acc, [name, step]) => {\n acc[name] = { state: step.state, hasOutput: !!step.output }\n return acc\n }, {} as Record<string, any>),\n triggerData: context.trigger?.data ? 'present' : 'absent'\n })\n }, 'Step condition met, proceeding with execution')\n }\n\n // Initialize step context\n context.steps[stepName] = {\n error: undefined,\n input: undefined,\n output: undefined,\n state: 'running'\n }\n\n // Move taskSlug declaration outside try block so it's accessible in catch\n const taskSlug = step.step // Use the 'step' field for task type\n\n try {\n // Resolve input data using JSONPath\n const resolvedInput = this.resolveStepInput(step.input || {}, context)\n context.steps[stepName].input = resolvedInput\n\n if (!taskSlug) {\n throw new Error(`Step ${stepName} is missing a task type`)\n }\n\n this.logger.info({\n hasInput: !!resolvedInput,\n hasReq: !!req,\n stepName,\n taskSlug\n }, 'Queueing task')\n\n const job = await this.payload.jobs.queue({\n input: resolvedInput,\n req,\n task: taskSlug\n })\n\n // Run the job immediately\n await this.payload.jobs.run({\n limit: 1,\n req\n })\n\n // Get the job result\n const completedJob = await this.payload.findByID({\n id: job.id,\n collection: 'payload-jobs',\n req\n })\n\n const taskStatus = completedJob.taskStatus?.[completedJob.taskSlug]?.[completedJob.totalTried]\n const isComplete = taskStatus?.complete === true\n const hasError = completedJob.hasError || !isComplete\n\n // Extract error information from job if available\n let errorMessage: string | undefined\n if (hasError) {\n // Try to get error from the latest log entry\n if (completedJob.log && completedJob.log.length > 0) {\n const latestLog = completedJob.log[completedJob.log.length - 1]\n errorMessage = latestLog.error?.message || latestLog.error\n }\n\n // Fallback to top-level error\n if (!errorMessage && completedJob.error) {\n errorMessage = completedJob.error.message || completedJob.error\n }\n\n // Final fallback to generic message\n if (!errorMessage) {\n errorMessage = `Task ${taskSlug} failed without detailed error information`\n }\n }\n\n const result: {\n error: string | undefined\n output: unknown\n state: 'failed' | 'succeeded'\n } = {\n error: errorMessage,\n output: taskStatus?.output || {},\n state: isComplete ? 'succeeded' : 'failed'\n }\n\n // Store the output and error\n context.steps[stepName].output = result.output\n context.steps[stepName].state = result.state\n if (result.error) {\n context.steps[stepName].error = result.error\n }\n\n this.logger.debug({context}, 'Step execution context')\n\n if (result.state !== 'succeeded') {\n throw new Error(result.error || `Step ${stepName} failed`)\n }\n\n this.logger.info({\n output: result.output,\n stepName\n }, 'Step completed')\n\n // Update workflow run with current step results if workflowRunId is provided\n if (workflowRunId) {\n await this.updateWorkflowRunContext(workflowRunId, context, req)\n }\n\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n context.steps[stepName].state = 'failed'\n context.steps[stepName].error = errorMessage\n\n this.logger.error({\n error: errorMessage,\n input: context.steps[stepName].input,\n stepName,\n taskSlug\n }, 'Step execution failed')\n\n // Update workflow run with current step results if workflowRunId is provided\n if (workflowRunId) {\n try {\n await this.updateWorkflowRunContext(workflowRunId, context, req)\n } catch (updateError) {\n this.logger.error({\n error: updateError instanceof Error ? updateError.message : 'Unknown error',\n stepName\n }, 'Failed to update workflow run context after step failure')\n }\n }\n\n throw error\n }\n }\n\n /**\n * Resolve step execution order based on dependencies\n */\n private resolveExecutionOrder(steps: WorkflowStep[]): WorkflowStep[][] {\n const stepMap = new Map<string, WorkflowStep>()\n const dependencyGraph = new Map<string, string[]>()\n const indegree = new Map<string, number>()\n\n // Build the step map and dependency graph\n for (const step of steps) {\n const stepName = step.name || `step-${steps.indexOf(step)}`\n const dependencies = step.dependencies || []\n\n stepMap.set(stepName, { ...step, name: stepName, dependencies })\n dependencyGraph.set(stepName, dependencies)\n indegree.set(stepName, dependencies.length)\n }\n\n // Topological sort to determine execution batches\n const executionBatches: WorkflowStep[][] = []\n const processed = new Set<string>()\n\n while (processed.size < steps.length) {\n const currentBatch: WorkflowStep[] = []\n\n // Find all steps with no remaining dependencies\n for (const [stepName, inDegree] of indegree.entries()) {\n if (inDegree === 0 && !processed.has(stepName)) {\n const step = stepMap.get(stepName)\n if (step) {\n currentBatch.push(step)\n }\n }\n }\n\n if (currentBatch.length === 0) {\n throw new Error('Circular dependency detected in workflow steps')\n }\n\n executionBatches.push(currentBatch)\n\n // Update indegrees for next iteration\n for (const step of currentBatch) {\n processed.add(step.name)\n\n // Reduce indegree for steps that depend on completed steps\n for (const [otherStepName, dependencies] of dependencyGraph.entries()) {\n if (dependencies.includes(step.name) && !processed.has(otherStepName)) {\n indegree.set(otherStepName, (indegree.get(otherStepName) || 0) - 1)\n }\n }\n }\n }\n\n return executionBatches\n }\n\n /**\n * Resolve step input using JSONPath expressions\n */\n private resolveStepInput(config: Record<string, unknown>, context: ExecutionContext): Record<string, unknown> {\n const resolved: Record<string, unknown> = {}\n\n this.logger.debug({\n configKeys: Object.keys(config),\n contextSteps: Object.keys(context.steps),\n triggerType: context.trigger?.type\n }, 'Starting step input resolution')\n\n for (const [key, value] of Object.entries(config)) {\n if (typeof value === 'string' && value.startsWith('$')) {\n // This is a JSONPath expression\n this.logger.debug({\n key,\n jsonPath: value,\n availableSteps: Object.keys(context.steps),\n hasTriggerData: !!context.trigger?.data,\n hasTriggerDoc: !!context.trigger?.doc\n }, 'Resolving JSONPath expression')\n\n try {\n const result = JSONPath({\n json: context,\n path: value,\n wrap: false\n })\n \n this.logger.debug({\n key,\n jsonPath: value,\n result: JSON.stringify(result).substring(0, 200),\n resultType: Array.isArray(result) ? 'array' : typeof result\n }, 'JSONPath resolved successfully')\n \n resolved[key] = result\n } catch (error) {\n this.logger.warn({\n error: error instanceof Error ? error.message : 'Unknown error',\n key,\n path: value,\n contextSnapshot: JSON.stringify(context).substring(0, 500)\n }, 'Failed to resolve JSONPath')\n resolved[key] = value // Keep original value if resolution fails\n }\n } else if (typeof value === 'object' && value !== null) {\n // Recursively resolve nested objects\n this.logger.debug({\n key,\n nestedKeys: Object.keys(value as Record<string, unknown>)\n }, 'Recursively resolving nested object')\n \n resolved[key] = this.resolveStepInput(value as Record<string, unknown>, context)\n } else {\n // Keep literal values as-is\n resolved[key] = value\n }\n }\n\n this.logger.debug({\n resolvedKeys: Object.keys(resolved),\n originalKeys: Object.keys(config)\n }, 'Step input resolution completed')\n\n return resolved\n }\n\n /**\n * Update workflow run with current context\n */\n private async updateWorkflowRunContext(\n workflowRunId: number | string,\n context: ExecutionContext,\n req: PayloadRequest\n ): Promise<void> {\n const serializeContext = () => ({\n steps: context.steps,\n trigger: {\n type: context.trigger.type,\n collection: context.trigger.collection,\n data: context.trigger.data,\n doc: context.trigger.doc,\n operation: context.trigger.operation,\n previousDoc: context.trigger.previousDoc,\n triggeredAt: context.trigger.triggeredAt,\n user: context.trigger.req?.user\n }\n })\n\n await this.payload.update({\n id: workflowRunId,\n collection: 'workflow-runs',\n data: {\n context: serializeContext()\n },\n req\n })\n }\n\n /**\n * Evaluate a condition using JSONPath\n */\n public evaluateCondition(condition: string, context: ExecutionContext): boolean {\n this.logger.debug({\n condition,\n contextKeys: Object.keys(context),\n triggerType: context.trigger?.type,\n triggerData: context.trigger?.data,\n triggerDoc: context.trigger?.doc ? 'present' : 'absent'\n }, 'Starting condition evaluation')\n\n try {\n const result = JSONPath({\n json: context,\n path: condition,\n wrap: false\n })\n\n this.logger.debug({\n condition,\n result,\n resultType: Array.isArray(result) ? 'array' : typeof result,\n resultLength: Array.isArray(result) ? result.length : undefined\n }, 'JSONPath evaluation result')\n\n // Handle different result types\n let finalResult: boolean\n if (Array.isArray(result)) {\n finalResult = result.length > 0 && Boolean(result[0])\n } else {\n finalResult = Boolean(result)\n }\n\n this.logger.debug({\n condition,\n finalResult,\n originalResult: result\n }, 'Condition evaluation completed')\n\n return finalResult\n } catch (error) {\n this.logger.warn({\n condition,\n error: error instanceof Error ? error.message : 'Unknown error',\n errorStack: error instanceof Error ? error.stack : undefined\n }, 'Failed to evaluate condition')\n\n // If condition evaluation fails, assume false\n return false\n }\n }\n\n /**\n * Execute a workflow with the given context\n */\n async execute(workflow: Workflow, context: ExecutionContext, req: PayloadRequest): Promise<void> {\n this.logger.info({\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Starting workflow execution')\n\n const serializeContext = () => ({\n steps: context.steps,\n trigger: {\n type: context.trigger.type,\n collection: context.trigger.collection,\n data: context.trigger.data,\n doc: context.trigger.doc,\n operation: context.trigger.operation,\n previousDoc: context.trigger.previousDoc,\n triggeredAt: context.trigger.triggeredAt,\n user: context.trigger.req?.user\n }\n })\n\n // Create a workflow run record\n const workflowRun = await this.payload.create({\n collection: 'workflow-runs',\n data: {\n context: serializeContext(),\n startedAt: new Date().toISOString(),\n status: 'running',\n triggeredBy: context.trigger.req?.user?.email || 'system',\n workflow: workflow.id,\n workflowVersion: workflow._version || 1\n },\n req\n })\n\n try {\n // Resolve execution order based on dependencies\n const executionBatches = this.resolveExecutionOrder(workflow.steps)\n\n this.logger.info({\n batchSizes: executionBatches.map(batch => batch.length),\n totalBatches: executionBatches.length\n }, 'Resolved step execution order')\n\n // Execute each batch in sequence, but steps within each batch in parallel\n for (let batchIndex = 0; batchIndex < executionBatches.length; batchIndex++) {\n const batch = executionBatches[batchIndex]\n\n this.logger.info({\n batchIndex,\n stepCount: batch.length,\n stepNames: batch.map(s => s.name)\n }, 'Executing batch')\n\n // Execute all steps in this batch in parallel\n const batchPromises = batch.map((step, stepIndex) =>\n this.executeStep(step, stepIndex, context, req, workflowRun.id)\n )\n\n // Wait for all steps in the current batch to complete\n await Promise.all(batchPromises)\n\n this.logger.info({\n batchIndex,\n stepCount: batch.length\n }, 'Batch completed')\n }\n\n // Update workflow run as completed\n await this.payload.update({\n id: workflowRun.id,\n collection: 'workflow-runs',\n data: {\n completedAt: new Date().toISOString(),\n context: serializeContext(),\n status: 'completed'\n },\n req\n })\n\n this.logger.info({\n runId: workflowRun.id,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Workflow execution completed')\n\n } catch (error) {\n // Update workflow run as failed\n await this.payload.update({\n id: workflowRun.id,\n collection: 'workflow-runs',\n data: {\n completedAt: new Date().toISOString(),\n context: serializeContext(),\n error: error instanceof Error ? error.message : 'Unknown error',\n status: 'failed'\n },\n req\n })\n\n this.logger.error({\n error: error instanceof Error ? error.message : 'Unknown error',\n runId: workflowRun.id,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Workflow execution failed')\n\n throw error\n }\n }\n\n /**\n * Find and execute workflows triggered by a collection operation\n */\n async executeTriggeredWorkflows(\n collection: string,\n operation: 'create' | 'delete' | 'read' | 'update',\n doc: unknown,\n previousDoc: unknown,\n req: PayloadRequest\n ): Promise<void> {\n try {\n // Find workflows with matching triggers\n const workflows = await this.payload.find({\n collection: 'workflows',\n depth: 2, // Include steps and triggers\n limit: 100,\n req\n })\n\n for (const workflow of workflows.docs) {\n // Check if this workflow has a matching trigger\n const triggers = workflow.triggers as Array<{\n collection: string\n condition?: string\n operation: string\n type: string\n }>\n\n const matchingTriggers = triggers?.filter(trigger =>\n trigger.type === 'collection-trigger' &&\n trigger.collection === collection &&\n trigger.operation === operation\n ) || []\n\n for (const trigger of matchingTriggers) {\n // Create execution context for condition evaluation\n const context: ExecutionContext = {\n steps: {},\n trigger: {\n type: 'collection',\n collection,\n doc,\n operation,\n previousDoc,\n req\n }\n }\n\n // Check trigger condition if present\n if (trigger.condition) {\n this.logger.debug({\n collection,\n operation,\n condition: trigger.condition,\n docId: (doc as any)?.id,\n docFields: doc ? Object.keys(doc) : [],\n previousDocId: (previousDoc as any)?.id,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Evaluating collection trigger condition')\n\n const conditionMet = this.evaluateCondition(trigger.condition, context)\n\n if (!conditionMet) {\n this.logger.info({\n collection,\n condition: trigger.condition,\n operation,\n workflowId: workflow.id,\n workflowName: workflow.name,\n docSnapshot: JSON.stringify(doc).substring(0, 200)\n }, 'Trigger condition not met, skipping workflow')\n continue\n }\n\n this.logger.info({\n collection,\n condition: trigger.condition,\n operation,\n workflowId: workflow.id,\n workflowName: workflow.name,\n docSnapshot: JSON.stringify(doc).substring(0, 200)\n }, 'Trigger condition met')\n }\n\n this.logger.info({\n collection,\n operation,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Triggering workflow')\n\n // Execute the workflow\n await this.execute(workflow as Workflow, context, req)\n }\n }\n } catch (error) {\n this.logger.error({ error: error instanceof Error ? error.message : 'Unknown error' }, 'Workflow execution failed')\n this.logger.error({\n collection,\n error: error instanceof Error ? error.message : 'Unknown error',\n operation\n }, 'Failed to execute triggered workflows')\n }\n }\n}\n"],"names":["JSONPath","WorkflowExecutor","payload","logger","evaluateStepCondition","condition","context","evaluateCondition","executeStep","step","stepIndex","req","workflowRunId","stepName","name","info","hasStep","JSON","stringify","debug","availableSteps","Object","keys","steps","completedSteps","entries","filter","_","s","state","map","triggerType","trigger","type","conditionMet","contextSnapshot","stepOutputs","reduce","acc","hasOutput","output","triggerData","data","error","undefined","input","reason","skipped","updateWorkflowRunContext","taskSlug","resolvedInput","resolveStepInput","Error","hasInput","hasReq","job","jobs","queue","task","run","limit","completedJob","findByID","id","collection","taskStatus","totalTried","isComplete","complete","hasError","errorMessage","log","length","latestLog","message","result","updateError","resolveExecutionOrder","stepMap","Map","dependencyGraph","indegree","indexOf","dependencies","set","executionBatches","processed","Set","size","currentBatch","inDegree","has","get","push","add","otherStepName","includes","config","resolved","configKeys","contextSteps","key","value","startsWith","jsonPath","hasTriggerData","hasTriggerDoc","doc","json","path","wrap","substring","resultType","Array","isArray","warn","nestedKeys","resolvedKeys","originalKeys","serializeContext","operation","previousDoc","triggeredAt","user","update","contextKeys","triggerDoc","resultLength","finalResult","Boolean","originalResult","errorStack","stack","execute","workflow","workflowId","workflowName","workflowRun","create","startedAt","Date","toISOString","status","triggeredBy","email","workflowVersion","_version","batchSizes","batch","totalBatches","batchIndex","stepCount","stepNames","batchPromises","Promise","all","completedAt","runId","executeTriggeredWorkflows","workflows","find","depth","docs","triggers","matchingTriggers","docId","docFields","previousDocId","docSnapshot"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,gBAAe;AAsDxC,OAAO,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OAAO;YACd,IAAI,CAACxC,MAAM,CAACwC,KAAK,CAAC;gBAAEA,OAAOA,iBAAiBS,QAAQT,MAAM+B,OAAO,GAAG;YAAgB,GAAG;YACvF,IAAI,CAACvE,MAAM,CAACwC,KAAK,CAAC;gBAChBqB;gBACArB,OAAOA,iBAAiBS,QAAQT,MAAM+B,OAAO,GAAG;gBAChD8C;YACF,GAAG;QACL;IACF;AACF"}
|
|
@@ -59,11 +59,20 @@ export function initWebhookEndpoint(config, webhookPrefix = 'webhook') {
|
|
|
59
59
|
const matchingTrigger = triggers?.find((trigger)=>trigger.type === 'webhook-trigger' && trigger.webhookPath === path);
|
|
60
60
|
// Check trigger condition if present
|
|
61
61
|
if (matchingTrigger?.condition) {
|
|
62
|
+
logger.debug({
|
|
63
|
+
condition: matchingTrigger.condition,
|
|
64
|
+
path,
|
|
65
|
+
webhookData: JSON.stringify(webhookData).substring(0, 200),
|
|
66
|
+
headers: Object.keys(context.trigger.headers || {}),
|
|
67
|
+
workflowId: workflow.id,
|
|
68
|
+
workflowName: workflow.name
|
|
69
|
+
}, 'Evaluating webhook trigger condition');
|
|
62
70
|
const conditionMet = executor.evaluateCondition(matchingTrigger.condition, context);
|
|
63
71
|
if (!conditionMet) {
|
|
64
72
|
logger.info({
|
|
65
73
|
condition: matchingTrigger.condition,
|
|
66
74
|
path,
|
|
75
|
+
webhookDataSnapshot: JSON.stringify(webhookData).substring(0, 200),
|
|
67
76
|
workflowId: workflow.id,
|
|
68
77
|
workflowName: workflow.name
|
|
69
78
|
}, 'Webhook trigger condition not met, skipping workflow');
|
|
@@ -76,6 +85,7 @@ export function initWebhookEndpoint(config, webhookPrefix = 'webhook') {
|
|
|
76
85
|
logger.info({
|
|
77
86
|
condition: matchingTrigger.condition,
|
|
78
87
|
path,
|
|
88
|
+
webhookDataSnapshot: JSON.stringify(webhookData).substring(0, 200),
|
|
79
89
|
workflowId: workflow.id,
|
|
80
90
|
workflowName: workflow.name
|
|
81
91
|
}, 'Webhook trigger condition met');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin/init-webhook.ts"],"sourcesContent":["import type {Config, PayloadRequest} from 'payload'\n\nimport {type Workflow, WorkflowExecutor} from '../core/workflow-executor.js'\nimport {getConfigLogger, initializeLogger} from './logger.js'\n\nexport function initWebhookEndpoint(config: Config, webhookPrefix = 'webhook'): void {\n const logger = getConfigLogger()\n // Ensure the prefix starts with a slash\n const normalizedPrefix = webhookPrefix.startsWith('/') ? webhookPrefix : `/${webhookPrefix}`\n logger.debug(`Adding webhook endpoint to config with prefix: ${normalizedPrefix}`)\n logger.debug('Current config.endpoints length:', config.endpoints?.length || 0)\n\n // Define webhook endpoint\n const webhookEndpoint = {\n handler: async (req: PayloadRequest) => {\n const {path} = req.routeParams as { path: string }\n const webhookData = req.body || {}\n\n logger.debug('Webhook endpoint handler called, path: ' + path)\n\n try {\n // Find workflows with matching webhook triggers\n const workflows = await req.payload.find({\n collection: 'workflows',\n depth: 2,\n limit: 100,\n req,\n where: {\n 'triggers.type': {\n equals: 'webhook-trigger'\n },\n 'triggers.webhookPath': {\n equals: path\n }\n }\n })\n\n if (workflows.docs.length === 0) {\n return new Response(\n JSON.stringify({error: 'No workflows found for this webhook path'}),\n {\n headers: {'Content-Type': 'application/json'},\n status: 404\n }\n )\n }\n\n // Create a workflow executor for this request\n const logger = initializeLogger(req.payload)\n const executor = new WorkflowExecutor(req.payload, logger)\n\n const executionPromises = workflows.docs.map(async (workflow) => {\n try {\n // Create execution context for the webhook trigger\n const context = {\n steps: {},\n trigger: {\n type: 'webhook',\n data: webhookData,\n headers: Object.fromEntries(req.headers?.entries() || []),\n path,\n req\n }\n }\n\n // Find the matching trigger and check its condition if present\n const triggers = workflow.triggers as Array<{\n condition?: string\n type: string\n webhookPath?: string\n }>\n\n const matchingTrigger = triggers?.find(trigger =>\n trigger.type === 'webhook-trigger' &&\n trigger.webhookPath === path\n )\n\n // Check trigger condition if present\n if (matchingTrigger?.condition) {\n const conditionMet = executor.evaluateCondition(matchingTrigger.condition, context)\n\n if (!conditionMet) {\n logger.info({\n condition: matchingTrigger.condition,\n path,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Webhook trigger condition not met, skipping workflow')\n\n return { reason: 'Condition not met', status: 'skipped', workflowId: workflow.id }\n }\n\n logger.info({\n condition: matchingTrigger.condition,\n path,\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Webhook trigger condition met')\n }\n\n // Execute the workflow\n await executor.execute(workflow as Workflow, context, req)\n\n return { status: 'triggered', workflowId: workflow.id }\n } catch (error) {\n return {\n error: error instanceof Error ? error.message : 'Unknown error',\n status: 'failed',\n workflowId: workflow.id\n }\n }\n })\n\n const results = await Promise.allSettled(executionPromises)\n const resultsData = results.map((result, index) => {\n const baseResult = { workflowId: workflows.docs[index].id }\n if (result.status === 'fulfilled') {\n return { ...baseResult, ...result.value }\n } else {\n return { ...baseResult, error: result.reason, status: 'failed' }\n }\n })\n\n return new Response(\n JSON.stringify({\n message: `Triggered ${workflows.docs.length} workflow(s)`,\n results: resultsData\n }),\n {\n headers: { 'Content-Type': 'application/json' },\n status: 200\n }\n )\n\n } catch (error) {\n return new Response(\n JSON.stringify({\n details: error instanceof Error ? error.message : 'Unknown error',\n error: 'Failed to process webhook'\n }),\n {\n headers: { 'Content-Type': 'application/json' },\n status: 500\n }\n )\n }\n },\n method: 'post' as const,\n path: `${normalizedPrefix}/:path`\n }\n\n // Check if the webhook endpoint already exists to avoid duplicates\n const existingEndpoint = config.endpoints?.find(endpoint =>\n endpoint.path === webhookEndpoint.path && endpoint.method === webhookEndpoint.method\n )\n\n if (!existingEndpoint) {\n // Combine existing endpoints with the webhook endpoint\n config.endpoints = [...(config.endpoints || []), webhookEndpoint]\n logger.debug(`Webhook endpoint added at path: ${webhookEndpoint.path}`)\n logger.debug('New config.endpoints length:', config.endpoints.length)\n } else {\n logger.debug(`Webhook endpoint already exists at path: ${webhookEndpoint.path}`)\n }\n}\n"],"names":["WorkflowExecutor","getConfigLogger","initializeLogger","initWebhookEndpoint","config","webhookPrefix","logger","normalizedPrefix","startsWith","debug","endpoints","length","webhookEndpoint","handler","req","path","routeParams","webhookData","body","workflows","payload","find","collection","depth","limit","where","equals","docs","Response","JSON","stringify","error","headers","status","executor","executionPromises","map","workflow","context","steps","trigger","type","data","Object","fromEntries","entries","triggers","matchingTrigger","webhookPath","condition","conditionMet","evaluateCondition","info","workflowId","id","workflowName","name","reason","execute","Error","message","results","Promise","allSettled","resultsData","result","index","baseResult","value","details","method","existingEndpoint","endpoint"],"mappings":"AAEA,SAAuBA,gBAAgB,QAAO,+BAA8B;AAC5E,SAAQC,eAAe,EAAEC,gBAAgB,QAAO,cAAa;AAE7D,OAAO,SAASC,oBAAoBC,MAAc,EAAEC,gBAAgB,SAAS;IAC3E,MAAMC,SAASL;IACf,wCAAwC;IACxC,MAAMM,mBAAmBF,cAAcG,UAAU,CAAC,OAAOH,gBAAgB,CAAC,CAAC,EAAEA,eAAe;IAC5FC,OAAOG,KAAK,CAAC,CAAC,+CAA+C,EAAEF,kBAAkB;IACjFD,OAAOG,KAAK,CAAC,oCAAoCL,OAAOM,SAAS,EAAEC,UAAU;IAE7E,0BAA0B;IAC1B,MAAMC,kBAAkB;QACtBC,SAAS,OAAOC;YACd,MAAM,EAACC,IAAI,EAAC,GAAGD,IAAIE,WAAW;YAC9B,MAAMC,cAAcH,IAAII,IAAI,IAAI,CAAC;YAEjCZ,OAAOG,KAAK,CAAC,4CAA4CM;YAEzD,IAAI;gBACF,gDAAgD;gBAChD,MAAMI,YAAY,MAAML,IAAIM,OAAO,CAACC,IAAI,CAAC;oBACvCC,YAAY;oBACZC,OAAO;oBACPC,OAAO;oBACPV;oBACAW,OAAO;wBACL,iBAAiB;4BACfC,QAAQ;wBACV;wBACA,wBAAwB;4BACtBA,QAAQX;wBACV;oBACF;gBACF;gBAEA,IAAII,UAAUQ,IAAI,CAAChB,MAAM,KAAK,GAAG;oBAC/B,OAAO,IAAIiB,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OAAOM,SAAS,EAAEW,KAAKmD,CAAAA,WAC9CA,SAASzD,IAAI,KAAKH,gBAAgBG,IAAI,IAAIyD,SAASF,MAAM,KAAK1D,gBAAgB0D,MAAM;IAGtF,IAAI,CAACC,kBAAkB;QACrB,uDAAuD;QACvDnE,OAAOM,SAAS,GAAG;eAAKN,OAAOM,SAAS,IAAI,EAAE;YAAGE;SAAgB;QACjEN,OAAOG,KAAK,CAAC,CAAC,gCAAgC,EAAEG,gBAAgBG,IAAI,EAAE;QACtET,OAAOG,KAAK,CAAC,gCAAgCL,OAAOM,SAAS,CAACC,MAAM;IACtE,OAAO;QACLL,OAAOG,KAAK,CAAC,CAAC,yCAAyC,EAAEG,gBAAgBG,IAAI,EAAE;IACjF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/init-webhook.ts"],"sourcesContent":["import type {Config, PayloadRequest} from 'payload'\n\nimport {type Workflow, WorkflowExecutor} from '../core/workflow-executor.js'\nimport {getConfigLogger, initializeLogger} from './logger.js'\n\nexport function initWebhookEndpoint(config: Config, webhookPrefix = 'webhook'): void {\n const logger = getConfigLogger()\n // Ensure the prefix starts with a slash\n const normalizedPrefix = webhookPrefix.startsWith('/') ? webhookPrefix : `/${webhookPrefix}`\n logger.debug(`Adding webhook endpoint to config with prefix: ${normalizedPrefix}`)\n logger.debug('Current config.endpoints length:', config.endpoints?.length || 0)\n\n // Define webhook endpoint\n const webhookEndpoint = {\n handler: async (req: PayloadRequest) => {\n const {path} = req.routeParams as { path: string }\n const webhookData = req.body || {}\n\n logger.debug('Webhook endpoint handler called, path: ' + path)\n\n try {\n // Find workflows with matching webhook triggers\n const workflows = await req.payload.find({\n collection: 'workflows',\n depth: 2,\n limit: 100,\n req,\n where: {\n 'triggers.type': {\n equals: 'webhook-trigger'\n },\n 'triggers.webhookPath': {\n equals: path\n }\n }\n })\n\n if (workflows.docs.length === 0) {\n return new Response(\n JSON.stringify({error: 'No workflows found for this webhook path'}),\n {\n headers: {'Content-Type': 'application/json'},\n status: 404\n }\n )\n }\n\n // Create a workflow executor for this request\n const logger = initializeLogger(req.payload)\n const executor = new WorkflowExecutor(req.payload, logger)\n\n const executionPromises = workflows.docs.map(async (workflow) => {\n try {\n // Create execution context for the webhook trigger\n const context = {\n steps: {},\n trigger: {\n type: 'webhook',\n data: webhookData,\n headers: Object.fromEntries(req.headers?.entries() || []),\n path,\n req\n }\n }\n\n // Find the matching trigger and check its condition if present\n const triggers = workflow.triggers as Array<{\n condition?: string\n type: string\n webhookPath?: string\n }>\n\n const matchingTrigger = triggers?.find(trigger =>\n trigger.type === 'webhook-trigger' &&\n trigger.webhookPath === path\n )\n\n // Check trigger condition if present\n if (matchingTrigger?.condition) {\n logger.debug({\n condition: matchingTrigger.condition,\n path,\n webhookData: JSON.stringify(webhookData).substring(0, 200),\n headers: Object.keys(context.trigger.headers || {}),\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Evaluating webhook trigger condition')\n\n const conditionMet = executor.evaluateCondition(matchingTrigger.condition, context)\n\n if (!conditionMet) {\n logger.info({\n condition: matchingTrigger.condition,\n path,\n webhookDataSnapshot: JSON.stringify(webhookData).substring(0, 200),\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Webhook trigger condition not met, skipping workflow')\n\n return { reason: 'Condition not met', status: 'skipped', workflowId: workflow.id }\n }\n\n logger.info({\n condition: matchingTrigger.condition,\n path,\n webhookDataSnapshot: JSON.stringify(webhookData).substring(0, 200),\n workflowId: workflow.id,\n workflowName: workflow.name\n }, 'Webhook trigger condition met')\n }\n\n // Execute the workflow\n await executor.execute(workflow as Workflow, context, req)\n\n return { status: 'triggered', workflowId: workflow.id }\n } catch (error) {\n return {\n error: error instanceof Error ? error.message : 'Unknown error',\n status: 'failed',\n workflowId: workflow.id\n }\n }\n })\n\n const results = await Promise.allSettled(executionPromises)\n const resultsData = results.map((result, index) => {\n const baseResult = { workflowId: workflows.docs[index].id }\n if (result.status === 'fulfilled') {\n return { ...baseResult, ...result.value }\n } else {\n return { ...baseResult, error: result.reason, status: 'failed' }\n }\n })\n\n return new Response(\n JSON.stringify({\n message: `Triggered ${workflows.docs.length} workflow(s)`,\n results: resultsData\n }),\n {\n headers: { 'Content-Type': 'application/json' },\n status: 200\n }\n )\n\n } catch (error) {\n return new Response(\n JSON.stringify({\n details: error instanceof Error ? error.message : 'Unknown error',\n error: 'Failed to process webhook'\n }),\n {\n headers: { 'Content-Type': 'application/json' },\n status: 500\n }\n )\n }\n },\n method: 'post' as const,\n path: `${normalizedPrefix}/:path`\n }\n\n // Check if the webhook endpoint already exists to avoid duplicates\n const existingEndpoint = config.endpoints?.find(endpoint =>\n endpoint.path === webhookEndpoint.path && endpoint.method === webhookEndpoint.method\n )\n\n if (!existingEndpoint) {\n // Combine existing endpoints with the webhook endpoint\n config.endpoints = [...(config.endpoints || []), webhookEndpoint]\n logger.debug(`Webhook endpoint added at path: ${webhookEndpoint.path}`)\n logger.debug('New config.endpoints length:', config.endpoints.length)\n } else {\n logger.debug(`Webhook endpoint already exists at path: ${webhookEndpoint.path}`)\n }\n}\n"],"names":["WorkflowExecutor","getConfigLogger","initializeLogger","initWebhookEndpoint","config","webhookPrefix","logger","normalizedPrefix","startsWith","debug","endpoints","length","webhookEndpoint","handler","req","path","routeParams","webhookData","body","workflows","payload","find","collection","depth","limit","where","equals","docs","Response","JSON","stringify","error","headers","status","executor","executionPromises","map","workflow","context","steps","trigger","type","data","Object","fromEntries","entries","triggers","matchingTrigger","webhookPath","condition","substring","keys","workflowId","id","workflowName","name","conditionMet","evaluateCondition","info","webhookDataSnapshot","reason","execute","Error","message","results","Promise","allSettled","resultsData","result","index","baseResult","value","details","method","existingEndpoint","endpoint"],"mappings":"AAEA,SAAuBA,gBAAgB,QAAO,+BAA8B;AAC5E,SAAQC,eAAe,EAAEC,gBAAgB,QAAO,cAAa;AAE7D,OAAO,SAASC,oBAAoBC,MAAc,EAAEC,gBAAgB,SAAS;IAC3E,MAAMC,SAASL;IACf,wCAAwC;IACxC,MA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tF,IAAI,CAACC,kBAAkB;QACrB,uDAAuD;QACvDtE,OAAOM,SAAS,GAAG;eAAKN,OAAOM,SAAS,IAAI,EAAE;YAAGE;SAAgB;QACjEN,OAAOG,KAAK,CAAC,CAAC,gCAAgC,EAAEG,gBAAgBG,IAAI,EAAE;QACtET,OAAOG,KAAK,CAAC,gCAAgCL,OAAOM,SAAS,CAACC,MAAM;IACtE,OAAO;QACLL,OAAOG,KAAK,CAAC,CAAC,yCAAyC,EAAEG,gBAAgBG,IAAI,EAAE;IACjF;AACF"}
|
package/dist/plugin/logger.js
CHANGED
|
@@ -5,25 +5,25 @@ let pluginLogger = null;
|
|
|
5
5
|
* Uses console with plugin prefix since Payload logger isn't available yet
|
|
6
6
|
*/ const configLogger = {
|
|
7
7
|
debug: (message, ...args)=>{
|
|
8
|
-
if (!process.env.
|
|
8
|
+
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
console.log(`[payload-automation] ${message}`, ...args);
|
|
12
12
|
},
|
|
13
13
|
error: (message, ...args)=>{
|
|
14
|
-
if (!process.env.
|
|
14
|
+
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
console.error(`[payload-automation] ${message}`, ...args);
|
|
18
18
|
},
|
|
19
19
|
info: (message, ...args)=>{
|
|
20
|
-
if (!process.env.
|
|
20
|
+
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
console.log(`[payload-automation] ${message}`, ...args);
|
|
24
24
|
},
|
|
25
25
|
warn: (message, ...args)=>{
|
|
26
|
-
if (!process.env.
|
|
26
|
+
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
console.warn(`[payload-automation] ${message}`, ...args);
|
|
@@ -40,6 +40,7 @@ let pluginLogger = null;
|
|
|
40
40
|
*/ export function initializeLogger(payload) {
|
|
41
41
|
// Create a child logger with plugin identification
|
|
42
42
|
pluginLogger = payload.logger.child({
|
|
43
|
+
level: process.env.PAYLOAD_AUTOMATION_LOGGING || 'silent',
|
|
43
44
|
plugin: '@xtr-dev/payload-automation'
|
|
44
45
|
});
|
|
45
46
|
return pluginLogger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin/logger.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n// Global logger instance - use Payload's logger type\nlet pluginLogger: null | Payload['logger'] = null\n\n/**\n * Simple config-time logger for use during plugin configuration\n * Uses console with plugin prefix since Payload logger isn't available yet\n */\nconst configLogger = {\n debug: <T>(message: string, ...args: T[]) => {\n if (!process.env.
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/logger.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n// Global logger instance - use Payload's logger type\nlet pluginLogger: null | Payload['logger'] = null\n\n/**\n * Simple config-time logger for use during plugin configuration\n * Uses console with plugin prefix since Payload logger isn't available yet\n */\nconst configLogger = {\n debug: <T>(message: string, ...args: T[]) => {\n if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}\n console.log(`[payload-automation] ${message}`, ...args)\n },\n error: <T>(message: string, ...args: T[]) => {\n if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}\n console.error(`[payload-automation] ${message}`, ...args)\n },\n info: <T>(message: string, ...args: T[]) => {\n if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}\n console.log(`[payload-automation] ${message}`, ...args)\n },\n warn: <T>(message: string, ...args: T[]) => {\n if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}\n console.warn(`[payload-automation] ${message}`, ...args)\n }\n}\n\n/**\n * Get a logger for config-time use (before Payload initialization)\n */\nexport function getConfigLogger() {\n return configLogger\n}\n\n/**\n * Initialize the plugin logger using Payload's Pino instance\n * This creates a child logger with plugin identification\n */\nexport function initializeLogger(payload: Payload): Payload['logger'] {\n // Create a child logger with plugin identification\n pluginLogger = payload.logger.child({\n level: process.env.PAYLOAD_AUTOMATION_LOGGING || 'silent',\n plugin: '@xtr-dev/payload-automation'\n })\n return pluginLogger\n}\n\n/**\n * Get the plugin logger instance\n * Throws error if not initialized\n */\nexport function getLogger(): Payload['logger'] {\n if (!pluginLogger) {\n throw new Error('@xtr-dev/payload-automation: Logger not initialized. Make sure the plugin is properly configured.')\n }\n\n return pluginLogger\n}\n"],"names":["pluginLogger","configLogger","debug","message","args","process","env","PAYLOAD_AUTOMATION_CONFIG_LOGGING","console","log","error","info","warn","getConfigLogger","initializeLogger","payload","logger","child","level","PAYLOAD_AUTOMATION_LOGGING","plugin","getLogger","Error"],"mappings":"AAEA,qDAAqD;AACrD,IAAIA,eAAyC;AAE7C;;;CAGC,GACD,MAAMC,eAAe;IACnBC,OAAO,CAAIC,SAAiB,GAAGC;QAC7B,IAAI,CAACC,QAAQC,GAAG,CAACC,iCAAiC,EAAE;YAAC;QAAM;QAC3DC,QAAQC,GAAG,CAAC,CAAC,qBAAqB,EAAEN,SAAS,KAAKC;IACpD;IACAM,OAAO,CAAIP,SAAiB,GAAGC;QAC7B,IAAI,CAACC,QAAQC,GAAG,CAACC,iCAAiC,EAAE;YAAC;QAAM;QAC3DC,QAAQE,KAAK,CAAC,CAAC,qBAAqB,EAAEP,SAAS,KAAKC;IACtD;IACAO,MAAM,CAAIR,SAAiB,GAAGC;QAC5B,IAAI,CAACC,QAAQC,GAAG,CAACC,iCAAiC,EAAE;YAAC;QAAM;QAC3DC,QAAQC,GAAG,CAAC,CAAC,qBAAqB,EAAEN,SAAS,KAAKC;IACpD;IACAQ,MAAM,CAAIT,SAAiB,GAAGC;QAC5B,IAAI,CAACC,QAAQC,GAAG,CAACC,iCAAiC,EAAE;YAAC;QAAM;QAC3DC,QAAQI,IAAI,CAAC,CAAC,qBAAqB,EAAET,SAAS,KAAKC;IACrD;AACF;AAEA;;CAEC,GACD,OAAO,SAASS;IACd,OAAOZ;AACT;AAEA;;;CAGC,GACD,OAAO,SAASa,iBAAiBC,OAAgB;IAC/C,mDAAmD;IACnDf,eAAee,QAAQC,MAAM,CAACC,KAAK,CAAC;QAClCC,OAAOb,QAAQC,GAAG,CAACa,0BAA0B,IAAI;QACjDC,QAAQ;IACV;IACA,OAAOpB;AACT;AAEA;;;CAGC,GACD,OAAO,SAASqB;IACd,IAAI,CAACrB,cAAc;QACjB,MAAM,IAAIsB,MAAM;IAClB;IAEA,OAAOtB;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xtr-dev/payload-automation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "PayloadCMS Automation Plugin - Comprehensive workflow automation system with visual workflow building, execution tracking, and step types",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|