mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-10 08:53:23 +00:00
Major Features: • Add persistent error tracking for timeout/network failures that bypasses PayloadCMS output limitations • Implement smart error classification (timeout, DNS, connection, network) with duration-based detection • Add comprehensive test infrastructure with MongoDB in-memory testing and enhanced mocking • Fix HTTP request handler error preservation with detailed context storage • Add independent execution tracking with success/failure status and duration metrics Technical Improvements: • Update JSONPath documentation to use correct $.trigger.doc syntax across all step types • Fix PayloadCMS job execution to use runByID instead of run() for reliable task processing • Add enhanced HTTP error handling that preserves outputs for 4xx/5xx status codes • Implement proper nock configuration with undici for Node.js 22 fetch interception • Add comprehensive unit tests for WorkflowExecutor with mocked PayloadCMS instances Developer Experience: • Add detailed error information in workflow context with URL, method, timeout, attempts • Update README with HTTP error handling patterns and enhanced error tracking examples • Add test helpers and setup infrastructure for reliable integration testing • Fix workflow step validation and JSONPath field descriptions Breaking Changes: None - fully backward compatible 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
118 lines
2.8 KiB
TypeScript
118 lines
2.8 KiB
TypeScript
import type {CollectionSlug, TypedJobs} from 'payload';
|
|
|
|
import {sqliteAdapter} from "@payloadcms/db-sqlite"
|
|
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
import { MongoMemoryReplSet } from 'mongodb-memory-server'
|
|
import path from 'path'
|
|
import {buildConfig} from 'payload'
|
|
import sharp from 'sharp'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import {workflowsPlugin} from "../src/plugin/index.js"
|
|
import {HttpRequestStepTask} from "../src/steps/http-request.js"
|
|
import {CreateDocumentStepTask} from "../src/steps/index.js"
|
|
import { testEmailAdapter } from './helpers/testEmailAdapter.js'
|
|
import { seed } from './seed.js'
|
|
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
|
|
if (!process.env.ROOT_DIR) {
|
|
process.env.ROOT_DIR = dirname
|
|
}
|
|
|
|
const buildConfigWithMemoryDB = async () => {
|
|
// Use MongoDB adapter for testing instead of SQLite
|
|
const { mongooseAdapter } = await import('@payloadcms/db-mongodb')
|
|
|
|
return buildConfig({
|
|
admin: {
|
|
importMap: {
|
|
baseDir: path.resolve(dirname, '..'),
|
|
},
|
|
},
|
|
collections: [
|
|
{
|
|
slug: 'posts',
|
|
fields: [
|
|
{
|
|
name: 'content',
|
|
type: 'textarea'
|
|
}
|
|
],
|
|
},
|
|
{
|
|
slug: 'media',
|
|
fields: [],
|
|
upload: {
|
|
staticDir: path.resolve(dirname, 'media'),
|
|
},
|
|
},
|
|
{
|
|
slug: 'auditLog',
|
|
fields: [
|
|
{
|
|
name: 'post',
|
|
type: 'relationship',
|
|
relationTo: 'posts'
|
|
},
|
|
{
|
|
name: 'user',
|
|
type: 'relationship',
|
|
relationTo: 'users',
|
|
required: false
|
|
},
|
|
{
|
|
name: 'message',
|
|
type: 'textarea'
|
|
}
|
|
]
|
|
}
|
|
],
|
|
db: mongooseAdapter({
|
|
url: process.env.DATABASE_URI || 'mongodb://localhost:27017/payload-test',
|
|
}),
|
|
editor: lexicalEditor(),
|
|
email: testEmailAdapter,
|
|
jobs: {
|
|
deleteJobOnComplete: false,
|
|
jobsCollectionOverrides: ({ defaultJobsCollection }) => {
|
|
return {
|
|
...defaultJobsCollection,
|
|
admin: {
|
|
...(defaultJobsCollection.admin ?? {}),
|
|
hidden: false,
|
|
},
|
|
}
|
|
},
|
|
tasks: []
|
|
},
|
|
onInit: async (payload) => {
|
|
await seed(payload)
|
|
},
|
|
plugins: [
|
|
workflowsPlugin<CollectionSlug>({
|
|
collectionTriggers: {
|
|
posts: true,
|
|
media: true
|
|
},
|
|
steps: [
|
|
HttpRequestStepTask,
|
|
CreateDocumentStepTask
|
|
],
|
|
triggers: [
|
|
|
|
],
|
|
webhookPrefix: '/workflows-webhook'
|
|
}),
|
|
],
|
|
secret: process.env.PAYLOAD_SECRET || 'test-secret_key',
|
|
sharp,
|
|
typescript: {
|
|
outputFile: path.resolve(dirname, 'payload-types.ts'),
|
|
},
|
|
})
|
|
}
|
|
|
|
export default buildConfigWithMemoryDB()
|