9 Commits

Author SHA1 Message Date
Bas
98854f172d "Claude Code Review workflow" 2025-08-31 18:17:25 +02:00
Bas
1e76d456fc "Claude PR Assistant workflow" 2025-08-31 18:17:24 +02:00
06571a4aae Update workflow to detect 'Release v' prefixed version commits 2025-08-31 18:10:14 +02:00
c5b2e6f286 Release v0.0.11 - Fix ES module bundling issues
- Separated server-side and client-safe exports
- Main export now contains only types to prevent bundling server code
- Updated documentation with new import structure

🤖 Generated with [Claude Code](https://claude.ai/code)
2025-08-31 18:09:52 +02:00
7cf102e0b9 Fix GitHub workflow to properly detect version changes
The workflow now detects version changes by:
1. Looking for version bump commits (created by npm version)
2. Checking if package.json was modified and version actually changed

This works with the npm version workflow where:
1. Make changes and commit them
2. Run npm version patch (creates version commit)
3. Push both commits - workflow publishes on version commit
2025-08-31 18:08:15 +02:00
75ec74270c 0.0.10 2025-08-31 18:06:45 +02:00
cadb40e401 Fix client-side bundling by separating server and client exports
- Create dedicated /server export for server-side functions and plugin
- Main export now contains only types (client-safe)
- Remove problematic /steps export that exposed server functions
- Update README with correct import structure
- Fix tests to use /server export

This prevents server-side code from being bundled in client JavaScript,
eliminating the "require is not defined in ES module scope" runtime error.

Breaking change: workflowsPlugin must now be imported from '/server':
import { workflowsPlugin } from '@xtr-dev/payload-automation/server'

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-31 18:06:39 +02:00
19b9566df6 0.0.9 2025-08-31 17:58:56 +02:00
8ed647587b Fix ES module imports to eliminate runtime require() calls
- Changed node-cron import from namespace import to default import
- Added GitHub workflow for automatic npm publishing on version changes
- Ensured all build output uses pure ES module imports without CommonJS remnants

This fixes the runtime error: "ReferenceError: require is not defined in ES module scope"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-31 17:58:46 +02:00
11 changed files with 277 additions and 26 deletions

View File

@@ -0,0 +1,54 @@
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize]
# Optional: Only run on specific file changes
# paths:
# - "src/**/*.ts"
# - "src/**/*.tsx"
# - "src/**/*.js"
# - "src/**/*.jsx"
jobs:
claude-review:
# Optional: Filter by PR author
# if: |
# github.event.pull_request.user.login == 'external-contributor' ||
# github.event.pull_request.user.login == 'new-developer' ||
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
prompt: |
Please review this pull request and provide feedback on:
- Code quality and best practices
- Potential bugs or issues
- Performance considerations
- Security concerns
- Test coverage
Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.
Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
# or https://docs.anthropic.com/en/docs/claude-code/sdk#command-line for available options
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'

50
.github/workflows/claude.yml vendored Normal file
View File

@@ -0,0 +1,50 @@
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]
jobs:
claude:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
actions: read # Required for Claude to read CI results on PRs
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
# This is an optional setting that allows Claude to read CI results on PRs
additional_permissions: |
actions: read
# Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
# prompt: 'Update the pull request description to include a summary of changes.'
# Optional: Add claude_args to customize behavior and configuration
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
# or https://docs.anthropic.com/en/docs/claude-code/sdk#command-line for available options
# claude_args: '--model claude-opus-4-1-20250805 --allowed-tools Bash(gh pr:*)'

83
.github/workflows/publish.yml vendored Normal file
View File

@@ -0,0 +1,83 @@
name: Publish to NPM
on:
push:
branches: [main]
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run tests
run: pnpm test:int
- name: Build
run: pnpm build
- name: Check if should publish
id: version-check
run: |
# Get current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# 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 "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
echo "changed=false" >> $GITHUB_OUTPUT
echo "No version change detected"
fi
- name: Publish to NPM
if: steps.version-check.outputs.changed == 'true'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: steps.version-check.outputs.changed == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version-check.outputs.current }}
release_name: Release v${{ steps.version-check.outputs.current }}
draft: false
prerelease: false

View File

@@ -27,20 +27,40 @@ yarn add @xtr-dev/payload-automation
```typescript
import { buildConfig } from 'payload'
import { payloadAutomation } from '@xtr-dev/payload-automation'
import { workflowsPlugin } from '@xtr-dev/payload-automation/server'
export default buildConfig({
// ... your config
plugins: [
payloadAutomation({
collections: ['posts', 'users'], // Collections to monitor
globals: ['settings'], // Globals to monitor
workflowsPlugin({
collectionTriggers: {
posts: true, // Enable all CRUD triggers for posts
users: {
create: true, // Only enable create trigger for users
update: true
}
},
enabled: true,
}),
],
})
```
## Import Structure
The plugin uses separate exports to avoid bundling server-side code in client bundles:
```typescript
// Server-side plugin and functions
import { workflowsPlugin } from '@xtr-dev/payload-automation/server'
// Client-side components
import { TriggerWorkflowButton } from '@xtr-dev/payload-automation/client'
// Types only (safe for both server and client)
import type { WorkflowsPluginConfig } from '@xtr-dev/payload-automation'
```
## Step Types
- **HTTP Request** - Make external API calls

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@xtr-dev/payload-workflows",
"version": "0.0.8",
"version": "0.0.11",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@xtr-dev/payload-workflows",
"version": "0.0.8",
"version": "0.0.11",
"license": "MIT",
"dependencies": {
"jsonpath-plus": "^10.3.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@xtr-dev/payload-automation",
"version": "0.0.8",
"version": "0.0.11",
"description": "PayloadCMS Automation Plugin - Comprehensive workflow automation system with visual workflow building, execution tracking, and step types",
"license": "MIT",
"type": "module",
@@ -30,10 +30,10 @@
"types": "./dist/exports/views.d.ts",
"default": "./dist/exports/views.js"
},
"./steps": {
"import": "./dist/steps/index.js",
"types": "./dist/steps/index.d.ts",
"default": "./dist/steps/index.js"
"./server": {
"import": "./dist/exports/server.js",
"types": "./dist/exports/server.d.ts",
"default": "./dist/exports/server.js"
}
},
"main": "dist/index.js",

26
src/exports/server.ts Normal file
View File

@@ -0,0 +1,26 @@
// Server-side only exports - should never be bundled for client
// These contain Node.js dependencies and should only be used server-side
export { triggerCustomWorkflow, triggerWorkflowById } from '../core/trigger-custom-workflow.js'
export { WorkflowExecutor } from '../core/workflow-executor.js'
export { workflowsPlugin } from '../plugin/index.js'
// Export all step handlers (server-side only)
export {
createDocumentHandler,
deleteDocumentHandler,
httpStepHandler,
readDocumentHandler,
sendEmailHandler,
updateDocumentHandler
} from '../steps/index.js'
// Export step tasks configurations (server-side only)
export {
CreateDocumentStepTask,
DeleteDocumentStepTask,
HttpRequestStepTask,
ReadDocumentStepTask,
SendEmailStepTask,
UpdateDocumentStepTask
} from '../steps/index.js'

View File

@@ -1,19 +1,15 @@
export { triggerCustomWorkflow, triggerWorkflowById } from './core/trigger-custom-workflow.js'
// 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 { WorkflowExecutor } from './core/workflow-executor.js'
export type { ExecutionContext, Workflow, WorkflowStep, WorkflowTrigger } from './core/workflow-executor.js'
export type { WorkflowsPluginConfig } from './plugin/config-types.js'
export { workflowsPlugin } from './plugin/index.js'
// Export all step tasks
export {
CreateDocumentStepTask,
DeleteDocumentStepTask,
HttpRequestStepTask,
ReadDocumentStepTask,
SendEmailStepTask,
UpdateDocumentStepTask
} from './steps/index.js'
// Server-side functions are NOT re-exported here to avoid bundling issues
// Import server-side functions from the /server export instead
// UI components are exported via separate client export to avoid CSS import issues during type generation
// Use: import { TriggerWorkflowButton } from '@xtr-dev/payload-automation/client'
// Server functions and plugin should be imported from '/server':
// import { workflowsPlugin } from '@xtr-dev/payload-automation/server'
// UI components should be imported from '/client':
// import { TriggerWorkflowButton } from '@xtr-dev/payload-automation/client'

View File

@@ -1,6 +1,6 @@
import type {Config, Payload, TaskConfig} from 'payload'
import * as cron from 'node-cron'
import cron from 'node-cron'
import {type Workflow, WorkflowExecutor} from '../core/workflow-executor.js'
import {getConfigLogger} from './logger.js'

14
src/test/basic.test.ts Normal file
View File

@@ -0,0 +1,14 @@
import { describe, it, expect } from 'vitest'
describe('PayloadCMS Automation Plugin', () => {
it('should export the plugin function from server export', async () => {
const { workflowsPlugin } = await import('../exports/server.js')
expect(workflowsPlugin).toBeDefined()
expect(typeof workflowsPlugin).toBe('function')
})
it('should have the correct package name', async () => {
// Basic test to ensure the plugin can be imported
expect(true).toBe(true)
})
})

8
vitest.config.ts Normal file
View File

@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'node',
},
})