mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-12 17:43:23 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 964b11c0c9 | |||
| 3d7b746779 | |||
| 7686495283 | |||
| 265d5affc6 | |||
| 06571a4aae | |||
| c5b2e6f286 | |||
| 7cf102e0b9 |
29
.github/workflows/publish.yml
vendored
29
.github/workflows/publish.yml
vendored
@@ -35,25 +35,34 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
- name: Check if version changed
|
- name: Check if should publish
|
||||||
id: version-check
|
id: version-check
|
||||||
run: |
|
run: |
|
||||||
# Get current version from package.json
|
# Get current version from package.json
|
||||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||||
|
|
||||||
# Get previous commit's version
|
|
||||||
git show HEAD~1:package.json > prev-package.json 2>/dev/null || echo '{"version":"0.0.0"}' > prev-package.json
|
|
||||||
PREVIOUS_VERSION=$(node -p "require('./prev-package.json').version")
|
|
||||||
|
|
||||||
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||||
echo "previous=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
|
# Check if this is a version bump commit (created by npm version)
|
||||||
|
COMMIT_MSG=$(git log -1 --pretty=%B)
|
||||||
|
if echo "$COMMIT_MSG" | grep -q "^Release v[0-9]\|^v[0-9]"; then
|
||||||
echo "changed=true" >> $GITHUB_OUTPUT
|
echo "changed=true" >> $GITHUB_OUTPUT
|
||||||
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
|
echo "Version bump commit detected: $COMMIT_MSG"
|
||||||
|
# Or check if package.json was modified in this commit
|
||||||
|
elif git diff --name-only HEAD~1 HEAD | grep -q "package.json"; then
|
||||||
|
# Check if the version actually changed
|
||||||
|
git show HEAD~1:package.json > prev-package.json 2>/dev/null || echo '{"version":"0.0.0"}' > prev-package.json
|
||||||
|
PREVIOUS_VERSION=$(node -p "require('./prev-package.json').version")
|
||||||
|
|
||||||
|
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
|
||||||
|
echo "changed=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
|
||||||
|
else
|
||||||
|
echo "changed=false" >> $GITHUB_OUTPUT
|
||||||
|
echo "package.json modified but version unchanged: $CURRENT_VERSION"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "changed=false" >> $GITHUB_OUTPUT
|
echo "changed=false" >> $GITHUB_OUTPUT
|
||||||
echo "Version unchanged: $CURRENT_VERSION"
|
echo "No version change detected"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Publish to NPM
|
- name: Publish to NPM
|
||||||
|
|||||||
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.10",
|
"version": "0.0.13",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@xtr-dev/payload-workflows",
|
"name": "@xtr-dev/payload-workflows",
|
||||||
"version": "0.0.10",
|
"version": "0.0.13",
|
||||||
"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.10",
|
"version": "0.0.13",
|
||||||
"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",
|
||||||
|
|||||||
@@ -606,6 +606,12 @@ export class WorkflowExecutor {
|
|||||||
previousDoc: unknown,
|
previousDoc: unknown,
|
||||||
req: PayloadRequest
|
req: PayloadRequest
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
this.logger.info({
|
||||||
|
collection,
|
||||||
|
operation,
|
||||||
|
docId: (doc as any)?.id
|
||||||
|
}, 'executeTriggeredWorkflows called')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Find workflows with matching triggers
|
// Find workflows with matching triggers
|
||||||
const workflows = await this.payload.find({
|
const workflows = await this.payload.find({
|
||||||
@@ -615,21 +621,46 @@ export class WorkflowExecutor {
|
|||||||
req
|
req
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.logger.info({
|
||||||
|
workflowCount: workflows.docs.length
|
||||||
|
}, 'Found workflows to check')
|
||||||
|
|
||||||
for (const workflow of workflows.docs) {
|
for (const workflow of workflows.docs) {
|
||||||
// Check if this workflow has a matching trigger
|
// Check if this workflow has a matching trigger
|
||||||
const triggers = workflow.triggers as Array<{
|
const triggers = workflow.triggers as Array<{
|
||||||
collection: string
|
collection?: string
|
||||||
|
collectionSlug?: string
|
||||||
condition?: string
|
condition?: string
|
||||||
operation: string
|
operation: string
|
||||||
type: string
|
type: string
|
||||||
}>
|
}>
|
||||||
|
|
||||||
|
this.logger.debug({
|
||||||
|
workflowId: workflow.id,
|
||||||
|
workflowName: workflow.name,
|
||||||
|
triggerCount: triggers?.length || 0,
|
||||||
|
triggers: triggers?.map(t => ({
|
||||||
|
type: t.type,
|
||||||
|
collection: t.collection,
|
||||||
|
collectionSlug: t.collectionSlug,
|
||||||
|
operation: t.operation
|
||||||
|
}))
|
||||||
|
}, 'Checking workflow triggers')
|
||||||
|
|
||||||
const matchingTriggers = triggers?.filter(trigger =>
|
const matchingTriggers = triggers?.filter(trigger =>
|
||||||
trigger.type === 'collection-trigger' &&
|
trigger.type === 'collection-trigger' &&
|
||||||
trigger.collection === collection &&
|
(trigger.collection === collection || trigger.collectionSlug === collection) &&
|
||||||
trigger.operation === operation
|
trigger.operation === operation
|
||||||
) || []
|
) || []
|
||||||
|
|
||||||
|
this.logger.info({
|
||||||
|
workflowId: workflow.id,
|
||||||
|
workflowName: workflow.name,
|
||||||
|
matchingTriggerCount: matchingTriggers.length,
|
||||||
|
targetCollection: collection,
|
||||||
|
targetOperation: operation
|
||||||
|
}, 'Matching triggers found')
|
||||||
|
|
||||||
for (const trigger of matchingTriggers) {
|
for (const trigger of matchingTriggers) {
|
||||||
// Create execution context for condition evaluation
|
// Create execution context for condition evaluation
|
||||||
const context: ExecutionContext = {
|
const context: ExecutionContext = {
|
||||||
|
|||||||
14
src/index.ts
14
src/index.ts
@@ -1,10 +1,16 @@
|
|||||||
// Main export contains only types and client-safe utilities
|
// Main export contains only types and client-safe utilities
|
||||||
// Server-side functions are exported via '@xtr-dev/payload-automation/server'
|
// Server-side functions are exported via '@xtr-dev/payload-automation/server'
|
||||||
|
|
||||||
// Types only - safe for client bundling
|
// Pure types only - completely safe for client bundling
|
||||||
export type { CustomTriggerOptions, TriggerResult } from './core/trigger-custom-workflow.js'
|
export type {
|
||||||
export type { ExecutionContext, Workflow, WorkflowStep, WorkflowTrigger } from './core/workflow-executor.js'
|
CustomTriggerOptions,
|
||||||
export type { WorkflowsPluginConfig } from './plugin/config-types.js'
|
TriggerResult,
|
||||||
|
ExecutionContext,
|
||||||
|
Workflow,
|
||||||
|
WorkflowStep,
|
||||||
|
WorkflowTrigger,
|
||||||
|
WorkflowsPluginConfig
|
||||||
|
} from './types/index.js'
|
||||||
|
|
||||||
// Server-side functions are NOT re-exported here to avoid bundling issues
|
// Server-side functions are NOT re-exported here to avoid bundling issues
|
||||||
// Import server-side functions from the /server export instead
|
// Import server-side functions from the /server export instead
|
||||||
|
|||||||
62
src/types/index.ts
Normal file
62
src/types/index.ts
Normal file
@@ -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<string, {
|
||||||
|
output?: any
|
||||||
|
state: 'pending' | 'running' | 'succeeded' | 'failed'
|
||||||
|
}>
|
||||||
|
payload: any // Payload instance
|
||||||
|
req: any // PayloadRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WorkflowStep {
|
||||||
|
id: string
|
||||||
|
type: string
|
||||||
|
input: Record<string, any>
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user