mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-11 17:23:23 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c050ee835a | |||
| 1f80028042 | |||
| 14d1ecf036 | |||
| 3749881d5f | |||
| c46b58f43e | |||
| 398a2d160e |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/payload-workflows",
|
"name": "@xtr-dev/payload-workflows",
|
||||||
"version": "0.0.30",
|
"version": "0.0.33",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@xtr-dev/payload-workflows",
|
"name": "@xtr-dev/payload-workflows",
|
||||||
"version": "0.0.30",
|
"version": "0.0.33",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"jsonpath-plus": "^10.3.0",
|
"jsonpath-plus": "^10.3.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/payload-automation",
|
"name": "@xtr-dev/payload-automation",
|
||||||
"version": "0.0.30",
|
"version": "0.0.33",
|
||||||
"description": "PayloadCMS Automation Plugin - Comprehensive workflow automation system with visual workflow building, execution tracking, and step types",
|
"description": "PayloadCMS Automation Plugin - Comprehensive workflow automation system with visual workflow building, execution tracking, and step types",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -319,17 +319,45 @@ export const createWorkflowCollection: <T extends string>(options: WorkflowsPlug
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
...(steps || []).flatMap(step => (step.inputSchema || []).map(field => ({
|
...(steps || []).flatMap(step => (step.inputSchema || []).map(field => {
|
||||||
|
const originalName = (field as any).name;
|
||||||
|
const resultField: any = {
|
||||||
...field,
|
...field,
|
||||||
|
// Prefix field name with step slug to avoid conflicts
|
||||||
|
name: `__step_${step.slug}_${originalName}`,
|
||||||
admin: {
|
admin: {
|
||||||
...(field.admin || {}),
|
...(field.admin || {}),
|
||||||
condition: (...args) => args[1]?.step === step.slug && (
|
condition: (...args: any[]) => args[1]?.step === step.slug && (
|
||||||
field.admin?.condition ?
|
(field.admin as any)?.condition ?
|
||||||
field.admin.condition.call(this, ...args) :
|
(field.admin as any).condition.call(this, ...args) :
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
} as Field))),
|
virtual: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add hooks to store/retrieve from the step's input data
|
||||||
|
resultField.hooks = {
|
||||||
|
...((field as any).hooks || {}),
|
||||||
|
afterRead: [
|
||||||
|
...(((field as any).hooks)?.afterRead || []),
|
||||||
|
({ siblingData }: any) => {
|
||||||
|
// Read from step input data using original field name
|
||||||
|
return siblingData?.[originalName] || (field as any).defaultValue;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
beforeChange: [
|
||||||
|
...(((field as any).hooks)?.beforeChange || []),
|
||||||
|
({ siblingData, value }: any) => {
|
||||||
|
// Store in step data using original field name
|
||||||
|
siblingData[originalName] = value;
|
||||||
|
return undefined; // Don't store the prefixed field
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
return resultField as Field;
|
||||||
|
})),
|
||||||
{
|
{
|
||||||
name: 'dependencies',
|
name: 'dependencies',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
|||||||
@@ -1035,11 +1035,18 @@ export class WorkflowExecutor {
|
|||||||
triggerCount: triggers?.length || 0,
|
triggerCount: triggers?.length || 0,
|
||||||
triggers: triggers?.map(t => ({
|
triggers: triggers?.map(t => ({
|
||||||
type: t.type,
|
type: t.type,
|
||||||
|
parameters: t.parameters,
|
||||||
collection: t.parameters?.collection,
|
collection: t.parameters?.collection,
|
||||||
collectionSlug: t.parameters?.collectionSlug,
|
collectionSlug: t.parameters?.collectionSlug,
|
||||||
operation: t.parameters?.operation
|
operation: t.parameters?.operation,
|
||||||
}))
|
// Debug matching criteria
|
||||||
}, 'Checking workflow triggers')
|
typeMatch: t.type === 'collection-trigger',
|
||||||
|
collectionMatch: (t.parameters?.collection === collection || t.parameters?.collectionSlug === collection),
|
||||||
|
operationMatch: t.parameters?.operation === operation
|
||||||
|
})),
|
||||||
|
targetCollection: collection,
|
||||||
|
targetOperation: operation
|
||||||
|
}, 'Checking workflow triggers with detailed matching info')
|
||||||
|
|
||||||
const matchingTriggers = triggers?.filter(trigger =>
|
const matchingTriggers = triggers?.filter(trigger =>
|
||||||
trigger.type === 'collection-trigger' &&
|
trigger.type === 'collection-trigger' &&
|
||||||
|
|||||||
@@ -186,19 +186,40 @@ export const workflowsPlugin =
|
|||||||
}, 'Collection automation hook triggered')
|
}, 'Collection automation hook triggered')
|
||||||
|
|
||||||
if (!registry.isInitialized) {
|
if (!registry.isInitialized) {
|
||||||
logger.warn('Workflow executor not yet initialized, skipping execution')
|
logger.warn('Workflow executor not yet initialized, attempting lazy initialization')
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try to create executor if we have a payload instance
|
||||||
|
if (args.req?.payload) {
|
||||||
|
logger.info('Creating workflow executor via lazy initialization')
|
||||||
|
const { WorkflowExecutor } = await import('../core/workflow-executor.js')
|
||||||
|
const executor = new WorkflowExecutor(args.req.payload, logger)
|
||||||
|
setWorkflowExecutor(executor, logger)
|
||||||
|
logger.info('Lazy initialization successful')
|
||||||
|
} else {
|
||||||
|
logger.error('Cannot lazy initialize - no payload instance available')
|
||||||
|
await createFailedWorkflowRun(args, 'Workflow executor not initialized and lazy initialization failed - no payload instance', logger)
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Lazy initialization failed:', error)
|
||||||
|
const errorMessage = error instanceof Error ? error.message : String(error)
|
||||||
|
await createFailedWorkflowRun(args, `Workflow executor lazy initialization failed: ${errorMessage}`, logger)
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!registry.executor) {
|
// Re-check registry after potential lazy initialization
|
||||||
|
const updatedRegistry = getExecutorRegistry()
|
||||||
|
if (!updatedRegistry.executor) {
|
||||||
logger.error('Workflow executor is null despite being marked as initialized')
|
logger.error('Workflow executor is null despite being marked as initialized')
|
||||||
// Create a failed workflow run to track this issue
|
// Create a failed workflow run to track this issue
|
||||||
await createFailedWorkflowRun(args, 'Executor not available', logger)
|
await createFailedWorkflowRun(args, 'Executor not available after initialization', logger)
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('Executing triggered workflows...')
|
logger.debug('Executing triggered workflows...')
|
||||||
await registry.executor.executeTriggeredWorkflows(
|
await updatedRegistry.executor.executeTriggeredWorkflows(
|
||||||
args.collection.slug,
|
args.collection.slug,
|
||||||
args.operation,
|
args.operation,
|
||||||
args.doc,
|
args.doc,
|
||||||
|
|||||||
Reference in New Issue
Block a user