@xtr-dev/payload-automation 0.0.43 → 0.0.45
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.
- package/README.md +221 -49
- package/dist/collections/Steps.d.ts +6 -0
- package/dist/collections/Steps.js +166 -0
- package/dist/collections/Steps.js.map +1 -0
- package/dist/collections/Triggers.d.ts +7 -0
- package/dist/collections/Triggers.js +224 -0
- package/dist/collections/Triggers.js.map +1 -0
- package/dist/collections/Workflow.d.ts +5 -2
- package/dist/collections/Workflow.js +179 -39
- package/dist/collections/Workflow.js.map +1 -1
- package/dist/collections/WorkflowRuns.d.ts +4 -0
- package/dist/collections/WorkflowRuns.js +219 -24
- package/dist/collections/WorkflowRuns.js.map +1 -1
- package/dist/components/WorkflowBuilder/WorkflowBuilder.js.map +1 -1
- package/dist/core/expression-engine.d.ts +58 -0
- package/dist/core/expression-engine.js +191 -0
- package/dist/core/expression-engine.js.map +1 -0
- package/dist/core/workflow-executor.d.ts +70 -56
- package/dist/core/workflow-executor.js +354 -677
- package/dist/core/workflow-executor.js.map +1 -1
- package/dist/exports/client.js +1 -3
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/views.js +2 -4
- package/dist/exports/views.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin/config-types.d.ts +43 -5
- package/dist/plugin/config-types.js +3 -1
- package/dist/plugin/config-types.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/index.js +82 -28
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/trigger-hook.d.ts +13 -0
- package/dist/plugin/trigger-hook.js +184 -0
- package/dist/plugin/trigger-hook.js.map +1 -0
- package/dist/steps/create-step.d.ts +66 -0
- package/dist/steps/create-step.js +59 -0
- package/dist/steps/create-step.js.map +1 -0
- package/dist/steps/index.d.ts +2 -0
- package/dist/steps/index.js +3 -0
- package/dist/steps/index.js.map +1 -1
- package/dist/steps/read-document-handler.js +1 -1
- package/dist/steps/read-document-handler.js.map +1 -1
- package/dist/steps/update-document-handler.js +1 -1
- package/dist/steps/update-document-handler.js.map +1 -1
- package/dist/triggers/hook-options.d.ts +34 -0
- package/dist/triggers/hook-options.js +158 -0
- package/dist/triggers/hook-options.js.map +1 -0
- package/dist/triggers/index.d.ts +2 -2
- package/dist/triggers/index.js +1 -2
- package/dist/triggers/index.js.map +1 -1
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +4 -5
- package/dist/types/index.js.map +1 -1
- package/dist/utils/validation.d.ts +64 -0
- package/dist/utils/validation.js +107 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +2 -1
- package/dist/plugin/collection-hook.d.ts +0 -1
- package/dist/plugin/collection-hook.js +0 -92
- package/dist/plugin/collection-hook.js.map +0 -1
- package/dist/plugin/global-hook.d.ts +0 -1
- package/dist/plugin/global-hook.js +0 -83
- package/dist/plugin/global-hook.js.map +0 -1
- package/dist/triggers/collection-trigger.d.ts +0 -2
- package/dist/triggers/collection-trigger.js +0 -36
- package/dist/triggers/collection-trigger.js.map +0 -1
- package/dist/triggers/global-trigger.d.ts +0 -2
- package/dist/triggers/global-trigger.js +0 -29
- package/dist/triggers/global-trigger.js.map +0 -1
- package/dist/triggers/types.d.ts +0 -5
- package/dist/triggers/types.js +0 -3
- package/dist/triggers/types.js.map +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grouped hook options for better UX in the admin panel.
|
|
3
|
+
* Organized by category instead of a flat list of 32+ hooks.
|
|
4
|
+
*/ /**
|
|
5
|
+
* Collection hook options grouped by category.
|
|
6
|
+
*/ export const collectionHookGroups = [
|
|
7
|
+
{
|
|
8
|
+
label: 'Document Lifecycle',
|
|
9
|
+
options: [
|
|
10
|
+
{
|
|
11
|
+
value: 'afterChange',
|
|
12
|
+
label: 'After Create/Update',
|
|
13
|
+
description: 'Fires after a document is created or updated'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
value: 'afterDelete',
|
|
17
|
+
label: 'After Delete',
|
|
18
|
+
description: 'Fires after a document is deleted'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
value: 'afterRead',
|
|
22
|
+
label: 'After Read',
|
|
23
|
+
description: 'Fires after a document is fetched'
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'Before Operations',
|
|
29
|
+
options: [
|
|
30
|
+
{
|
|
31
|
+
value: 'beforeValidate',
|
|
32
|
+
label: 'Before Validate',
|
|
33
|
+
description: 'Fires before field validation runs'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
value: 'beforeChange',
|
|
37
|
+
label: 'Before Save',
|
|
38
|
+
description: 'Fires after validation, before saving'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
value: 'beforeDelete',
|
|
42
|
+
label: 'Before Delete',
|
|
43
|
+
description: 'Fires before a document is deleted'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
value: 'beforeRead',
|
|
47
|
+
label: 'Before Read',
|
|
48
|
+
description: 'Fires before a document is fetched'
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: 'Authentication',
|
|
54
|
+
options: [
|
|
55
|
+
{
|
|
56
|
+
value: 'afterLogin',
|
|
57
|
+
label: 'After Login',
|
|
58
|
+
description: 'Fires after user successfully logs in'
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
value: 'afterLogout',
|
|
62
|
+
label: 'After Logout',
|
|
63
|
+
description: 'Fires after user logs out'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
value: 'beforeLogin',
|
|
67
|
+
label: 'Before Login',
|
|
68
|
+
description: 'Fires before login attempt'
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
value: 'afterForgotPassword',
|
|
72
|
+
label: 'After Forgot Password',
|
|
73
|
+
description: 'Fires after forgot password request'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
value: 'afterRefresh',
|
|
77
|
+
label: 'After Token Refresh',
|
|
78
|
+
description: 'Fires after auth token is refreshed'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: 'afterMe',
|
|
82
|
+
label: 'After Me Query',
|
|
83
|
+
description: 'Fires after /me endpoint is called'
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
label: 'Advanced',
|
|
89
|
+
options: [
|
|
90
|
+
{
|
|
91
|
+
value: 'beforeOperation',
|
|
92
|
+
label: 'Before Operation',
|
|
93
|
+
description: 'Fires before any CRUD operation'
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
value: 'afterOperation',
|
|
97
|
+
label: 'After Operation',
|
|
98
|
+
description: 'Fires after any CRUD operation'
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
value: 'afterError',
|
|
102
|
+
label: 'After Error',
|
|
103
|
+
description: 'Fires when an error occurs'
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
];
|
|
108
|
+
/**
|
|
109
|
+
* Global hook options grouped by category.
|
|
110
|
+
*/ export const globalHookGroups = [
|
|
111
|
+
{
|
|
112
|
+
label: 'Document Lifecycle',
|
|
113
|
+
options: [
|
|
114
|
+
{
|
|
115
|
+
value: 'afterChange',
|
|
116
|
+
label: 'After Update',
|
|
117
|
+
description: 'Fires after the global is updated'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
value: 'afterRead',
|
|
121
|
+
label: 'After Read',
|
|
122
|
+
description: 'Fires after the global is fetched'
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
label: 'Before Operations',
|
|
128
|
+
options: [
|
|
129
|
+
{
|
|
130
|
+
value: 'beforeValidate',
|
|
131
|
+
label: 'Before Validate',
|
|
132
|
+
description: 'Fires before field validation runs'
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
value: 'beforeChange',
|
|
136
|
+
label: 'Before Save',
|
|
137
|
+
description: 'Fires after validation, before saving'
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
value: 'beforeRead',
|
|
141
|
+
label: 'Before Read',
|
|
142
|
+
description: 'Fires before the global is fetched'
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
];
|
|
147
|
+
/**
|
|
148
|
+
* Flat list of collection hook options for select fields.
|
|
149
|
+
*/ export const collectionHookOptions = collectionHookGroups.flatMap((group)=>group.options);
|
|
150
|
+
/**
|
|
151
|
+
* Flat list of global hook options for select fields.
|
|
152
|
+
*/ export const globalHookOptions = globalHookGroups.flatMap((group)=>group.options);
|
|
153
|
+
/**
|
|
154
|
+
* All hook values as a simple string array for validation.
|
|
155
|
+
*/ export const allCollectionHooks = collectionHookOptions.map((opt)=>opt.value);
|
|
156
|
+
export const allGlobalHooks = globalHookOptions.map((opt)=>opt.value);
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=hook-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/triggers/hook-options.ts"],"sourcesContent":["/**\n * Grouped hook options for better UX in the admin panel.\n * Organized by category instead of a flat list of 32+ hooks.\n */\n\nexport interface HookOption {\n value: string\n label: string\n description?: string\n}\n\nexport interface HookOptionGroup {\n label: string\n options: HookOption[]\n}\n\n/**\n * Collection hook options grouped by category.\n */\nexport const collectionHookGroups: HookOptionGroup[] = [\n {\n label: 'Document Lifecycle',\n options: [\n { value: 'afterChange', label: 'After Create/Update', description: 'Fires after a document is created or updated' },\n { value: 'afterDelete', label: 'After Delete', description: 'Fires after a document is deleted' },\n { value: 'afterRead', label: 'After Read', description: 'Fires after a document is fetched' },\n ]\n },\n {\n label: 'Before Operations',\n options: [\n { value: 'beforeValidate', label: 'Before Validate', description: 'Fires before field validation runs' },\n { value: 'beforeChange', label: 'Before Save', description: 'Fires after validation, before saving' },\n { value: 'beforeDelete', label: 'Before Delete', description: 'Fires before a document is deleted' },\n { value: 'beforeRead', label: 'Before Read', description: 'Fires before a document is fetched' },\n ]\n },\n {\n label: 'Authentication',\n options: [\n { value: 'afterLogin', label: 'After Login', description: 'Fires after user successfully logs in' },\n { value: 'afterLogout', label: 'After Logout', description: 'Fires after user logs out' },\n { value: 'beforeLogin', label: 'Before Login', description: 'Fires before login attempt' },\n { value: 'afterForgotPassword', label: 'After Forgot Password', description: 'Fires after forgot password request' },\n { value: 'afterRefresh', label: 'After Token Refresh', description: 'Fires after auth token is refreshed' },\n { value: 'afterMe', label: 'After Me Query', description: 'Fires after /me endpoint is called' },\n ]\n },\n {\n label: 'Advanced',\n options: [\n { value: 'beforeOperation', label: 'Before Operation', description: 'Fires before any CRUD operation' },\n { value: 'afterOperation', label: 'After Operation', description: 'Fires after any CRUD operation' },\n { value: 'afterError', label: 'After Error', description: 'Fires when an error occurs' },\n ]\n }\n]\n\n/**\n * Global hook options grouped by category.\n */\nexport const globalHookGroups: HookOptionGroup[] = [\n {\n label: 'Document Lifecycle',\n options: [\n { value: 'afterChange', label: 'After Update', description: 'Fires after the global is updated' },\n { value: 'afterRead', label: 'After Read', description: 'Fires after the global is fetched' },\n ]\n },\n {\n label: 'Before Operations',\n options: [\n { value: 'beforeValidate', label: 'Before Validate', description: 'Fires before field validation runs' },\n { value: 'beforeChange', label: 'Before Save', description: 'Fires after validation, before saving' },\n { value: 'beforeRead', label: 'Before Read', description: 'Fires before the global is fetched' },\n ]\n }\n]\n\n/**\n * Flat list of collection hook options for select fields.\n */\nexport const collectionHookOptions: HookOption[] = collectionHookGroups.flatMap(group => group.options)\n\n/**\n * Flat list of global hook options for select fields.\n */\nexport const globalHookOptions: HookOption[] = globalHookGroups.flatMap(group => group.options)\n\n/**\n * All hook values as a simple string array for validation.\n */\nexport const allCollectionHooks = collectionHookOptions.map(opt => opt.value)\nexport const allGlobalHooks = globalHookOptions.map(opt => opt.value)\n"],"names":["collectionHookGroups","label","options","value","description","globalHookGroups","collectionHookOptions","flatMap","group","globalHookOptions","allCollectionHooks","map","opt","allGlobalHooks"],"mappings":"AAAA;;;CAGC,GAaD;;CAEC,GACD,OAAO,MAAMA,uBAA0C;IACrD;QACEC,OAAO;QACPC,SAAS;YACP;gBAAEC,OAAO;gBAAeF,OAAO;gBAAuBG,aAAa;YAA+C;YAClH;gBAAED,OAAO;gBAAeF,OAAO;gBAAgBG,aAAa;YAAoC;YAChG;gBAAED,OAAO;gBAAaF,OAAO;gBAAcG,aAAa;YAAoC;SAC7F;IACH;IACA;QACEH,OAAO;QACPC,SAAS;YACP;gBAAEC,OAAO;gBAAkBF,OAAO;gBAAmBG,aAAa;YAAqC;YACvG;gBAAED,OAAO;gBAAgBF,OAAO;gBAAeG,aAAa;YAAwC;YACpG;gBAAED,OAAO;gBAAgBF,OAAO;gBAAiBG,aAAa;YAAqC;YACnG;gBAAED,OAAO;gBAAcF,OAAO;gBAAeG,aAAa;YAAqC;SAChG;IACH;IACA;QACEH,OAAO;QACPC,SAAS;YACP;gBAAEC,OAAO;gBAAcF,OAAO;gBAAeG,aAAa;YAAwC;YAClG;gBAAED,OAAO;gBAAeF,OAAO;gBAAgBG,aAAa;YAA4B;YACxF;gBAAED,OAAO;gBAAeF,OAAO;gBAAgBG,aAAa;YAA6B;YACzF;gBAAED,OAAO;gBAAuBF,OAAO;gBAAyBG,aAAa;YAAsC;YACnH;gBAAED,OAAO;gBAAgBF,OAAO;gBAAuBG,aAAa;YAAsC;YAC1G;gBAAED,OAAO;gBAAWF,OAAO;gBAAkBG,aAAa;YAAqC;SAChG;IACH;IACA;QACEH,OAAO;QACPC,SAAS;YACP;gBAAEC,OAAO;gBAAmBF,OAAO;gBAAoBG,aAAa;YAAkC;YACtG;gBAAED,OAAO;gBAAkBF,OAAO;gBAAmBG,aAAa;YAAiC;YACnG;gBAAED,OAAO;gBAAcF,OAAO;gBAAeG,aAAa;YAA6B;SACxF;IACH;CACD,CAAA;AAED;;CAEC,GACD,OAAO,MAAMC,mBAAsC;IACjD;QACEJ,OAAO;QACPC,SAAS;YACP;gBAAEC,OAAO;gBAAeF,OAAO;gBAAgBG,aAAa;YAAoC;YAChG;gBAAED,OAAO;gBAAaF,OAAO;gBAAcG,aAAa;YAAoC;SAC7F;IACH;IACA;QACEH,OAAO;QACPC,SAAS;YACP;gBAAEC,OAAO;gBAAkBF,OAAO;gBAAmBG,aAAa;YAAqC;YACvG;gBAAED,OAAO;gBAAgBF,OAAO;gBAAeG,aAAa;YAAwC;YACpG;gBAAED,OAAO;gBAAcF,OAAO;gBAAeG,aAAa;YAAqC;SAChG;IACH;CACD,CAAA;AAED;;CAEC,GACD,OAAO,MAAME,wBAAsCN,qBAAqBO,OAAO,CAACC,CAAAA,QAASA,MAAMN,OAAO,EAAC;AAEvG;;CAEC,GACD,OAAO,MAAMO,oBAAkCJ,iBAAiBE,OAAO,CAACC,CAAAA,QAASA,MAAMN,OAAO,EAAC;AAE/F;;CAEC,GACD,OAAO,MAAMQ,qBAAqBJ,sBAAsBK,GAAG,CAACC,CAAAA,MAAOA,IAAIT,KAAK,EAAC;AAC7E,OAAO,MAAMU,iBAAiBJ,kBAAkBE,GAAG,CAACC,CAAAA,MAAOA,IAAIT,KAAK,EAAC"}
|
package/dist/triggers/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { collectionHookGroups, collectionHookOptions, globalHookGroups, globalHookOptions, allCollectionHooks, allGlobalHooks } from './hook-options.js';
|
|
2
|
+
export type { HookOption, HookOptionGroup } from './hook-options.js';
|
package/dist/triggers/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { globalTrigger } from './global-trigger.js';
|
|
1
|
+
export { collectionHookGroups, collectionHookOptions, globalHookGroups, globalHookOptions, allCollectionHooks, allGlobalHooks } from './hook-options.js';
|
|
3
2
|
|
|
4
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/triggers/index.ts"],"sourcesContent":["export {
|
|
1
|
+
{"version":3,"sources":["../../src/triggers/index.ts"],"sourcesContent":["export {\n collectionHookGroups,\n collectionHookOptions,\n globalHookGroups,\n globalHookOptions,\n allCollectionHooks,\n allGlobalHooks\n} from './hook-options.js'\n\nexport type { HookOption, HookOptionGroup } from './hook-options.js'\n"],"names":["collectionHookGroups","collectionHookOptions","globalHookGroups","globalHookOptions","allCollectionHooks","allGlobalHooks"],"mappings":"AAAA,SACEA,oBAAoB,EACpBC,qBAAqB,EACrBC,gBAAgB,EAChBC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,QACT,oBAAmB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -22,3 +22,11 @@ export interface ExecutionContext {
|
|
|
22
22
|
req: any;
|
|
23
23
|
}
|
|
24
24
|
export type { WorkflowsPluginConfig, SeedWorkflow } from '../plugin/config-types.js';
|
|
25
|
+
/**
|
|
26
|
+
* Logging configuration options for the workflows plugin.
|
|
27
|
+
* @deprecated Use the full WorkflowsPluginConfig from '@xtr-dev/payload-automation/server' instead.
|
|
28
|
+
*/
|
|
29
|
+
export interface WorkflowLoggingConfig {
|
|
30
|
+
level?: 'debug' | 'info' | 'warn' | 'error';
|
|
31
|
+
enabled?: boolean;
|
|
32
|
+
}
|
package/dist/types/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// Pure type definitions for client-safe exports
|
|
2
2
|
// This file contains NO runtime code and can be safely bundled
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export { };
|
|
3
|
+
/**
|
|
4
|
+
* Logging configuration options for the workflows plugin.
|
|
5
|
+
* @deprecated Use the full WorkflowsPluginConfig from '@xtr-dev/payload-automation/server' instead.
|
|
6
|
+
*/ export { };
|
|
8
7
|
|
|
9
8
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["// Pure type definitions for client-safe exports\n// This file contains NO runtime code and can be safely bundled\n\nexport interface CustomTriggerOptions {\n workflowId: string\n triggerData?: any\n req?: any // PayloadRequest type, but avoiding import to keep this client-safe\n}\n\nexport interface TriggerResult {\n success: boolean\n runId?: string\n error?: string\n}\n\nexport interface ExecutionContext {\n trigger: {\n type: string\n doc?: any\n data?: any\n }\n steps: Record<string, {\n output?: any\n state: 'pending' | 'running' | 'succeeded' | 'failed'\n }>\n payload: any // Payload instance\n req: any // PayloadRequest\n}\n\n// NOTE: Workflow, WorkflowStep, and WorkflowTrigger types are now imported from the generated PayloadCMS types\n// These interfaces have been removed to avoid duplication and inconsistencies\n// Import them from 'payload' or the generated payload-types.ts file instead\n\
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["// Pure type definitions for client-safe exports\n// This file contains NO runtime code and can be safely bundled\n\nexport interface CustomTriggerOptions {\n workflowId: string\n triggerData?: any\n req?: any // PayloadRequest type, but avoiding import to keep this client-safe\n}\n\nexport interface TriggerResult {\n success: boolean\n runId?: string\n error?: string\n}\n\nexport interface ExecutionContext {\n trigger: {\n type: string\n doc?: any\n data?: any\n }\n steps: Record<string, {\n output?: any\n state: 'pending' | 'running' | 'succeeded' | 'failed'\n }>\n payload: any // Payload instance\n req: any // PayloadRequest\n}\n\n// NOTE: Workflow, WorkflowStep, and WorkflowTrigger types are now imported from the generated PayloadCMS types\n// These interfaces have been removed to avoid duplication and inconsistencies\n// Import them from 'payload' or the generated payload-types.ts file instead\n\nexport type { WorkflowsPluginConfig, SeedWorkflow } from '../plugin/config-types.js'\n\n/**\n * Logging configuration options for the workflows plugin.\n * @deprecated Use the full WorkflowsPluginConfig from '@xtr-dev/payload-automation/server' instead.\n */\nexport interface WorkflowLoggingConfig {\n level?: 'debug' | 'info' | 'warn' | 'error'\n enabled?: boolean\n}\n"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,+DAA+D;AAkC/D;;;CAGC,GACD,WAGC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for step handlers.
|
|
3
|
+
* Reduces boilerplate by providing common validation functions.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ValidationError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Validates that required fields are present and non-null in the input object.
|
|
10
|
+
* @throws ValidationError if any required field is missing
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateRequired<T extends Record<string, unknown>>(input: T | null | undefined, fields: (keyof T)[]): asserts input is T;
|
|
13
|
+
/**
|
|
14
|
+
* Validates that a string field is present and is actually a string.
|
|
15
|
+
* @throws ValidationError if the field is missing or not a string
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateString(value: unknown, fieldName: string): asserts value is string;
|
|
18
|
+
/**
|
|
19
|
+
* Validates that a URL is valid.
|
|
20
|
+
* @throws ValidationError if the URL is invalid
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateUrl(url: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Validates that the value is a valid email address.
|
|
25
|
+
* Uses a simple regex for basic validation.
|
|
26
|
+
* @throws ValidationError if the email is invalid
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateEmail(email: string, fieldName?: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Parses a value that might be JSON string or already an object.
|
|
31
|
+
* @returns The parsed object
|
|
32
|
+
* @throws ValidationError if parsing fails
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseJsonOrObject<T = unknown>(value: string | T, fieldName: string): T;
|
|
35
|
+
/**
|
|
36
|
+
* Validates that a number is within a range.
|
|
37
|
+
* @throws ValidationError if the value is out of range
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateNumberRange(value: number, fieldName: string, min?: number, max?: number): void;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a standardized failed response for step handlers.
|
|
42
|
+
*/
|
|
43
|
+
export declare function createFailedResponse(error: unknown): {
|
|
44
|
+
errorMessage: string;
|
|
45
|
+
state: "failed";
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Creates a standardized success response for step handlers.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createSuccessResponse<T>(output: T): {
|
|
51
|
+
output: T;
|
|
52
|
+
state: "succeeded";
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Wraps a step handler function with automatic error handling.
|
|
56
|
+
* Catches errors and returns standardized failed responses.
|
|
57
|
+
*/
|
|
58
|
+
export declare function withErrorHandling<TInput, TOutput>(handler: (input: TInput) => Promise<TOutput>): (input: TInput) => Promise<{
|
|
59
|
+
output: TOutput;
|
|
60
|
+
state: 'succeeded';
|
|
61
|
+
} | {
|
|
62
|
+
errorMessage: string;
|
|
63
|
+
state: 'failed';
|
|
64
|
+
}>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for step handlers.
|
|
3
|
+
* Reduces boilerplate by providing common validation functions.
|
|
4
|
+
*/ export class ValidationError extends Error {
|
|
5
|
+
constructor(message){
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'ValidationError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validates that required fields are present and non-null in the input object.
|
|
12
|
+
* @throws ValidationError if any required field is missing
|
|
13
|
+
*/ export function validateRequired(input, fields) {
|
|
14
|
+
if (!input) {
|
|
15
|
+
throw new ValidationError('No input provided');
|
|
16
|
+
}
|
|
17
|
+
for (const field of fields){
|
|
18
|
+
const value = input[field];
|
|
19
|
+
if (value === undefined || value === null) {
|
|
20
|
+
throw new ValidationError(`${String(field)} is required`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates that a string field is present and is actually a string.
|
|
26
|
+
* @throws ValidationError if the field is missing or not a string
|
|
27
|
+
*/ export function validateString(value, fieldName) {
|
|
28
|
+
if (!value || typeof value !== 'string') {
|
|
29
|
+
throw new ValidationError(`${fieldName} is required and must be a string`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validates that a URL is valid.
|
|
34
|
+
* @throws ValidationError if the URL is invalid
|
|
35
|
+
*/ export function validateUrl(url) {
|
|
36
|
+
try {
|
|
37
|
+
new URL(url);
|
|
38
|
+
} catch {
|
|
39
|
+
throw new ValidationError(`Invalid URL: ${url}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validates that the value is a valid email address.
|
|
44
|
+
* Uses a simple regex for basic validation.
|
|
45
|
+
* @throws ValidationError if the email is invalid
|
|
46
|
+
*/ export function validateEmail(email, fieldName = 'email') {
|
|
47
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
48
|
+
if (!emailRegex.test(email)) {
|
|
49
|
+
throw new ValidationError(`${fieldName} must be a valid email address`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parses a value that might be JSON string or already an object.
|
|
54
|
+
* @returns The parsed object
|
|
55
|
+
* @throws ValidationError if parsing fails
|
|
56
|
+
*/ export function parseJsonOrObject(value, fieldName) {
|
|
57
|
+
if (typeof value === 'string') {
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(value);
|
|
60
|
+
} catch {
|
|
61
|
+
throw new ValidationError(`${fieldName} must be valid JSON`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validates that a number is within a range.
|
|
68
|
+
* @throws ValidationError if the value is out of range
|
|
69
|
+
*/ export function validateNumberRange(value, fieldName, min, max) {
|
|
70
|
+
if (min !== undefined && value < min) {
|
|
71
|
+
throw new ValidationError(`${fieldName} must be at least ${min}`);
|
|
72
|
+
}
|
|
73
|
+
if (max !== undefined && value > max) {
|
|
74
|
+
throw new ValidationError(`${fieldName} must be at most ${max}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates a standardized failed response for step handlers.
|
|
79
|
+
*/ export function createFailedResponse(error) {
|
|
80
|
+
return {
|
|
81
|
+
errorMessage: error instanceof Error ? error.message : 'Unknown error',
|
|
82
|
+
state: 'failed'
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a standardized success response for step handlers.
|
|
87
|
+
*/ export function createSuccessResponse(output) {
|
|
88
|
+
return {
|
|
89
|
+
output,
|
|
90
|
+
state: 'succeeded'
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Wraps a step handler function with automatic error handling.
|
|
95
|
+
* Catches errors and returns standardized failed responses.
|
|
96
|
+
*/ export function withErrorHandling(handler) {
|
|
97
|
+
return async (input)=>{
|
|
98
|
+
try {
|
|
99
|
+
const output = await handler(input);
|
|
100
|
+
return createSuccessResponse(output);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return createFailedResponse(error);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/validation.ts"],"sourcesContent":["/**\n * Validation utilities for step handlers.\n * Reduces boilerplate by providing common validation functions.\n */\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'ValidationError'\n }\n}\n\n/**\n * Validates that required fields are present and non-null in the input object.\n * @throws ValidationError if any required field is missing\n */\nexport function validateRequired<T extends Record<string, unknown>>(\n input: T | null | undefined,\n fields: (keyof T)[]\n): asserts input is T {\n if (!input) {\n throw new ValidationError('No input provided')\n }\n\n for (const field of fields) {\n const value = input[field]\n if (value === undefined || value === null) {\n throw new ValidationError(`${String(field)} is required`)\n }\n }\n}\n\n/**\n * Validates that a string field is present and is actually a string.\n * @throws ValidationError if the field is missing or not a string\n */\nexport function validateString(\n value: unknown,\n fieldName: string\n): asserts value is string {\n if (!value || typeof value !== 'string') {\n throw new ValidationError(`${fieldName} is required and must be a string`)\n }\n}\n\n/**\n * Validates that a URL is valid.\n * @throws ValidationError if the URL is invalid\n */\nexport function validateUrl(url: string): void {\n try {\n new URL(url)\n } catch {\n throw new ValidationError(`Invalid URL: ${url}`)\n }\n}\n\n/**\n * Validates that the value is a valid email address.\n * Uses a simple regex for basic validation.\n * @throws ValidationError if the email is invalid\n */\nexport function validateEmail(email: string, fieldName = 'email'): void {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n if (!emailRegex.test(email)) {\n throw new ValidationError(`${fieldName} must be a valid email address`)\n }\n}\n\n/**\n * Parses a value that might be JSON string or already an object.\n * @returns The parsed object\n * @throws ValidationError if parsing fails\n */\nexport function parseJsonOrObject<T = unknown>(\n value: string | T,\n fieldName: string\n): T {\n if (typeof value === 'string') {\n try {\n return JSON.parse(value) as T\n } catch {\n throw new ValidationError(`${fieldName} must be valid JSON`)\n }\n }\n return value as T\n}\n\n/**\n * Validates that a number is within a range.\n * @throws ValidationError if the value is out of range\n */\nexport function validateNumberRange(\n value: number,\n fieldName: string,\n min?: number,\n max?: number\n): void {\n if (min !== undefined && value < min) {\n throw new ValidationError(`${fieldName} must be at least ${min}`)\n }\n if (max !== undefined && value > max) {\n throw new ValidationError(`${fieldName} must be at most ${max}`)\n }\n}\n\n/**\n * Creates a standardized failed response for step handlers.\n */\nexport function createFailedResponse(error: unknown) {\n return {\n errorMessage: error instanceof Error ? error.message : 'Unknown error',\n state: 'failed' as const\n }\n}\n\n/**\n * Creates a standardized success response for step handlers.\n */\nexport function createSuccessResponse<T>(output: T) {\n return {\n output,\n state: 'succeeded' as const\n }\n}\n\n/**\n * Wraps a step handler function with automatic error handling.\n * Catches errors and returns standardized failed responses.\n */\nexport function withErrorHandling<TInput, TOutput>(\n handler: (input: TInput) => Promise<TOutput>\n): (input: TInput) => Promise<{ output: TOutput; state: 'succeeded' } | { errorMessage: string; state: 'failed' }> {\n return async (input: TInput) => {\n try {\n const output = await handler(input)\n return createSuccessResponse(output)\n } catch (error) {\n return createFailedResponse(error)\n }\n }\n}\n"],"names":["ValidationError","Error","message","name","validateRequired","input","fields","field","value","undefined","String","validateString","fieldName","validateUrl","url","URL","validateEmail","email","emailRegex","test","parseJsonOrObject","JSON","parse","validateNumberRange","min","max","createFailedResponse","error","errorMessage","state","createSuccessResponse","output","withErrorHandling","handler"],"mappings":"AAAA;;;CAGC,GAED,OAAO,MAAMA,wBAAwBC;IACnC,YAAYC,OAAe,CAAE;QAC3B,KAAK,CAACA;QACN,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA;;;CAGC,GACD,OAAO,SAASC,iBACdC,KAA2B,EAC3BC,MAAmB;IAEnB,IAAI,CAACD,OAAO;QACV,MAAM,IAAIL,gBAAgB;IAC5B;IAEA,KAAK,MAAMO,SAASD,OAAQ;QAC1B,MAAME,QAAQH,KAAK,CAACE,MAAM;QAC1B,IAAIC,UAAUC,aAAaD,UAAU,MAAM;YACzC,MAAM,IAAIR,gBAAgB,GAAGU,OAAOH,OAAO,YAAY,CAAC;QAC1D;IACF;AACF;AAEA;;;CAGC,GACD,OAAO,SAASI,eACdH,KAAc,EACdI,SAAiB;IAEjB,IAAI,CAACJ,SAAS,OAAOA,UAAU,UAAU;QACvC,MAAM,IAAIR,gBAAgB,GAAGY,UAAU,iCAAiC,CAAC;IAC3E;AACF;AAEA;;;CAGC,GACD,OAAO,SAASC,YAAYC,GAAW;IACrC,IAAI;QACF,IAAIC,IAAID;IACV,EAAE,OAAM;QACN,MAAM,IAAId,gBAAgB,CAAC,aAAa,EAAEc,KAAK;IACjD;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASE,cAAcC,KAAa,EAA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|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.45",
|
|
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",
|
|
@@ -138,6 +138,7 @@
|
|
|
138
138
|
"dependencies": {
|
|
139
139
|
"@xyflow/react": "^12.10.0",
|
|
140
140
|
"handlebars": "^4.7.8",
|
|
141
|
+
"jsonata": "^2.1.0",
|
|
141
142
|
"node-cron": "^4.2.1",
|
|
142
143
|
"pino": "^9.9.0"
|
|
143
144
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createCollectionTriggerHook: (collectionSlug: string, hookType: string) => (args: any) => Promise<void>;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { WorkflowExecutor } from "../core/workflow-executor.js";
|
|
2
|
-
export const createCollectionTriggerHook = (collectionSlug, hookType)=>{
|
|
3
|
-
return async (args)=>{
|
|
4
|
-
const req = 'req' in args ? args.req : 'args' in args ? args.args.req : undefined;
|
|
5
|
-
if (!req) {
|
|
6
|
-
throw new Error('No request object found in hook arguments');
|
|
7
|
-
}
|
|
8
|
-
const payload = req.payload;
|
|
9
|
-
const { docs: workflows } = await payload.find({
|
|
10
|
-
collection: 'workflows',
|
|
11
|
-
depth: 2,
|
|
12
|
-
limit: 100,
|
|
13
|
-
where: {
|
|
14
|
-
'triggers.parameters.collectionSlug': {
|
|
15
|
-
equals: collectionSlug
|
|
16
|
-
},
|
|
17
|
-
'triggers.parameters.hook': {
|
|
18
|
-
equals: hookType
|
|
19
|
-
},
|
|
20
|
-
'triggers.type': {
|
|
21
|
-
equals: 'collection-hook'
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const executor = new WorkflowExecutor(payload, payload.logger);
|
|
26
|
-
// invoke each workflow
|
|
27
|
-
for (const workflow of workflows){
|
|
28
|
-
// Create execution context
|
|
29
|
-
const context = {
|
|
30
|
-
steps: {},
|
|
31
|
-
trigger: {
|
|
32
|
-
...args,
|
|
33
|
-
type: 'collection',
|
|
34
|
-
collection: collectionSlug
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
// Check if any trigger has a condition and evaluate it
|
|
38
|
-
let shouldExecute = false;
|
|
39
|
-
for (const trigger of workflow.triggers || []){
|
|
40
|
-
if (trigger.type === 'collection-hook' && trigger.parameters?.collectionSlug === collectionSlug && trigger.parameters?.hook === hookType) {
|
|
41
|
-
if (trigger.condition) {
|
|
42
|
-
// Evaluate the condition
|
|
43
|
-
try {
|
|
44
|
-
const conditionMet = executor.evaluateCondition(trigger.condition, context);
|
|
45
|
-
if (conditionMet) {
|
|
46
|
-
shouldExecute = true;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
} catch (error) {
|
|
50
|
-
payload.logger.error({
|
|
51
|
-
workflowId: workflow.id,
|
|
52
|
-
condition: trigger.condition,
|
|
53
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
54
|
-
}, 'Failed to evaluate trigger condition');
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
// No condition means always execute
|
|
58
|
-
shouldExecute = true;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (!shouldExecute) {
|
|
64
|
-
payload.logger.debug({
|
|
65
|
-
workflowId: workflow.id,
|
|
66
|
-
collection: collectionSlug,
|
|
67
|
-
hookType
|
|
68
|
-
}, 'Workflow skipped due to unmet condition');
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
await executor.execute(workflow, context, req);
|
|
74
|
-
payload.logger.info({
|
|
75
|
-
workflowId: workflow.id,
|
|
76
|
-
collection: collectionSlug,
|
|
77
|
-
hookType
|
|
78
|
-
}, 'Workflow executed successfully');
|
|
79
|
-
} catch (error) {
|
|
80
|
-
payload.logger.error({
|
|
81
|
-
workflowId: workflow.id,
|
|
82
|
-
collection: collectionSlug,
|
|
83
|
-
hookType,
|
|
84
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
85
|
-
}, 'Workflow execution failed');
|
|
86
|
-
// Don't throw to prevent breaking the original operation
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
//# sourceMappingURL=collection-hook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin/collection-hook.ts"],"sourcesContent":["import {WorkflowExecutor} from \"../core/workflow-executor.js\"\n\nexport const createCollectionTriggerHook = (collectionSlug: string, hookType: string) => {\n return async (args: any) => {\n const req = 'req' in args ? args.req :\n 'args' in args ? args.args.req :\n undefined\n if (!req) {\n throw new Error('No request object found in hook arguments')\n }\n const payload = req.payload\n const {docs: workflows} = await payload.find({\n collection: 'workflows',\n depth: 2,\n limit: 100,\n where: {\n 'triggers.parameters.collectionSlug': {\n equals: collectionSlug\n },\n 'triggers.parameters.hook': {\n equals: hookType\n },\n 'triggers.type': {\n equals: 'collection-hook'\n }\n }\n })\n const executor = new WorkflowExecutor(payload, payload.logger)\n // invoke each workflow\n for (const workflow of workflows) {\n // Create execution context\n const context = {\n steps: {},\n trigger: {\n ...args,\n type: 'collection',\n collection: collectionSlug,\n }\n }\n\n // Check if any trigger has a condition and evaluate it\n let shouldExecute = false\n for (const trigger of workflow.triggers || []) {\n if (trigger.type === 'collection-hook' && \n trigger.parameters?.collectionSlug === collectionSlug && \n trigger.parameters?.hook === hookType) {\n \n if (trigger.condition) {\n // Evaluate the condition\n try {\n const conditionMet = executor.evaluateCondition(trigger.condition, context)\n if (conditionMet) {\n shouldExecute = true\n break\n }\n } catch (error) {\n payload.logger.error({\n workflowId: workflow.id,\n condition: trigger.condition,\n error: error instanceof Error ? error.message : 'Unknown error'\n }, 'Failed to evaluate trigger condition')\n }\n } else {\n // No condition means always execute\n shouldExecute = true\n break\n }\n }\n }\n\n if (!shouldExecute) {\n payload.logger.debug({\n workflowId: workflow.id,\n collection: collectionSlug,\n hookType\n }, 'Workflow skipped due to unmet condition')\n continue\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n await executor.execute(workflow as any, context, req)\n payload.logger.info({\n workflowId: workflow.id,\n collection: collectionSlug,\n hookType\n }, 'Workflow executed successfully')\n } catch (error) {\n payload.logger.error({\n workflowId: workflow.id,\n collection: collectionSlug,\n hookType,\n error: error instanceof Error ? error.message : 'Unknown error'\n }, 'Workflow execution failed')\n // Don't throw to prevent breaking the original operation\n }\n }\n }\n}\n"],"names":["WorkflowExecutor","createCollectionTriggerHook","collectionSlug","hookType","args","req","undefined","Error","payload","docs","workflows","find","collection","depth","limit","where","equals","executor","logger","workflow","context","steps","trigger","type","shouldExecute","triggers","parameters","hook","condition","conditionMet","evaluateCondition","error","workflowId","id","message","debug","execute","info"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,+BAA8B;AAE7D,OAAO,MAAMC,8BAA8B,CAACC,gBAAwBC;IAClE,OAAO,OAAOC;QACZ,MAAMC,MAAM,SAASD,OAAOA,KAAKC,GAAG,GAClC,UAAUD,OAAOA,KAAKA,IAAI,CAACC,GAAG,GAC5BC;QACJ,IAAI,CAACD,KAAK;YACR,MAAM,IAAIE,MAAM;QAClB;QACA,MAAMC,UAAUH,IAAIG,OAAO;QAC3B,MAAM,EAACC,MAAMC,SAAS,EAAC,GAAG,MAAMF,QAAQG,IAAI,CAAC;YAC3CC,YAAY;YACZC,OAAO;YACPC,OAAO;YACPC,OAAO;gBACL,sCAAsC;oBACpCC,QAAQd;gBACV;gBACA,4BAA4B;oBAC1Bc,QAAQb;gBACV;gBACA,iBAAiB;oBACfa,QAAQ;gBACV;YACF;QACF;QACA,MAAMC,WAAW,IAAIjB,iBAAiBQ,SAASA,QAAQU,MAAM;QAC7D,uBAAuB;QACvB,KAAK,MAAMC,YAAYT,UAAW;Y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iBAAiBxB,QAAQwB,MAAMG,OAAO,GAAG;gBAClD,GAAG;YACH,yDAAyD;YAC3D;QACF;IACF;AACF,EAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createGlobalTriggerHook: (globalSlug: string, hookType: string) => (args: any) => Promise<void>;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { WorkflowExecutor } from '../core/workflow-executor.js';
|
|
2
|
-
export const createGlobalTriggerHook = (globalSlug, hookType)=>{
|
|
3
|
-
return async function payloadGlobalAutomationHook(args) {
|
|
4
|
-
const req = 'req' in args ? args.req : 'args' in args ? args.args.req : undefined;
|
|
5
|
-
if (!req) {
|
|
6
|
-
throw new Error('No request object found in global hook arguments');
|
|
7
|
-
}
|
|
8
|
-
const payload = req.payload;
|
|
9
|
-
const logger = payload.logger;
|
|
10
|
-
try {
|
|
11
|
-
logger.info({
|
|
12
|
-
global: globalSlug,
|
|
13
|
-
hookType,
|
|
14
|
-
operation: hookType
|
|
15
|
-
}, 'Global automation hook triggered');
|
|
16
|
-
// Create executor on-demand
|
|
17
|
-
const executor = new WorkflowExecutor(payload, logger);
|
|
18
|
-
logger.debug('Executing triggered global workflows...');
|
|
19
|
-
// Find workflows with matching global triggers
|
|
20
|
-
const { docs: workflows } = await payload.find({
|
|
21
|
-
collection: 'workflows',
|
|
22
|
-
depth: 2,
|
|
23
|
-
limit: 100,
|
|
24
|
-
where: {
|
|
25
|
-
'triggers.parameters.global': {
|
|
26
|
-
equals: globalSlug
|
|
27
|
-
},
|
|
28
|
-
'triggers.parameters.operation': {
|
|
29
|
-
equals: hookType
|
|
30
|
-
},
|
|
31
|
-
'triggers.type': {
|
|
32
|
-
equals: 'global-hook'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
// Execute each matching workflow
|
|
37
|
-
for (const workflow of workflows){
|
|
38
|
-
// Create execution context
|
|
39
|
-
const context = {
|
|
40
|
-
steps: {},
|
|
41
|
-
trigger: {
|
|
42
|
-
...args,
|
|
43
|
-
type: 'global',
|
|
44
|
-
global: globalSlug,
|
|
45
|
-
operation: hookType,
|
|
46
|
-
req
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
try {
|
|
50
|
-
await executor.execute(workflow, context, req);
|
|
51
|
-
logger.info({
|
|
52
|
-
workflowId: workflow.id,
|
|
53
|
-
global: globalSlug,
|
|
54
|
-
hookType
|
|
55
|
-
}, 'Global workflow executed successfully');
|
|
56
|
-
} catch (error) {
|
|
57
|
-
logger.error({
|
|
58
|
-
workflowId: workflow.id,
|
|
59
|
-
global: globalSlug,
|
|
60
|
-
hookType,
|
|
61
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
62
|
-
}, 'Global workflow execution failed');
|
|
63
|
-
// Don't throw to prevent breaking the original operation
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
logger.info({
|
|
67
|
-
global: globalSlug,
|
|
68
|
-
hookType
|
|
69
|
-
}, 'Global workflow execution completed successfully');
|
|
70
|
-
} catch (error) {
|
|
71
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
72
|
-
logger.error({
|
|
73
|
-
global: globalSlug,
|
|
74
|
-
hookType,
|
|
75
|
-
error: errorMessage,
|
|
76
|
-
errorStack: error instanceof Error ? error.stack : undefined
|
|
77
|
-
}, 'Global hook execution failed');
|
|
78
|
-
// Don't throw to prevent breaking the original operation
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
//# sourceMappingURL=global-hook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin/global-hook.ts"],"sourcesContent":["import {WorkflowExecutor} from '../core/workflow-executor.js'\n\nexport const createGlobalTriggerHook = (globalSlug: string, hookType: string) => {\n return async function payloadGlobalAutomationHook(args: any) {\n const req = 'req' in args ? args.req :\n 'args' in args ? args.args.req :\n undefined\n if (!req) {\n throw new Error('No request object found in global hook arguments')\n }\n\n const payload = req.payload\n const logger = payload.logger\n\n try {\n logger.info({\n global: globalSlug,\n hookType,\n operation: hookType\n }, 'Global automation hook triggered')\n\n // Create executor on-demand\n const executor = new WorkflowExecutor(payload, logger)\n\n logger.debug('Executing triggered global workflows...')\n\n // Find workflows with matching global triggers\n const {docs: workflows} = await payload.find({\n collection: 'workflows',\n depth: 2,\n limit: 100,\n where: {\n 'triggers.parameters.global': {\n equals: globalSlug\n },\n 'triggers.parameters.operation': {\n equals: hookType\n },\n 'triggers.type': {\n equals: 'global-hook'\n }\n }\n })\n\n // Execute each matching workflow\n for (const workflow of workflows) {\n // Create execution context\n const context = {\n steps: {},\n trigger: {\n ...args,\n type: 'global',\n global: globalSlug,\n operation: hookType,\n req\n }\n }\n\n try {\n await executor.execute(workflow, context, req)\n logger.info({\n workflowId: workflow.id,\n global: globalSlug,\n hookType\n }, 'Global workflow executed successfully')\n } catch (error) {\n logger.error({\n workflowId: workflow.id,\n global: globalSlug,\n hookType,\n error: error instanceof Error ? error.message : 'Unknown error'\n }, 'Global workflow execution failed')\n // Don't throw to prevent breaking the original operation\n }\n }\n\n logger.info({\n global: globalSlug,\n hookType\n }, 'Global workflow execution completed successfully')\n\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n\n logger.error({\n global: globalSlug,\n hookType,\n error: errorMessage,\n errorStack: error instanceof Error ? error.stack : undefined\n }, 'Global hook execution failed')\n\n // Don't throw to prevent breaking the original operation\n }\n }\n}\n"],"names":["WorkflowExecutor","createGlobalTriggerHook","globalSlug","hookType","payloadGlobalAutomationHook","args","req","undefined","Error","payload","logger","info","global","operation","executor","debug","docs","workflows","find","collection","depth","limit","where","equals","workflow","context","steps","trigger","type","execute","workflowId","id","error","message","errorMessage","errorStack","stack"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,+BAA8B;AAE7D,OAAO,MAAMC,0BAA0B,CAACC,YAAoBC;IAC1D,OAAO,eAAeC,4BAA4BC,IAAS;QACzD,MAAMC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