@xtr-dev/payload-automation 0.0.43 → 0.0.46

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.
Files changed (74) hide show
  1. package/README.md +221 -49
  2. package/dist/collections/Steps.d.ts +6 -0
  3. package/dist/collections/Steps.js +166 -0
  4. package/dist/collections/Steps.js.map +1 -0
  5. package/dist/collections/Triggers.d.ts +7 -0
  6. package/dist/collections/Triggers.js +224 -0
  7. package/dist/collections/Triggers.js.map +1 -0
  8. package/dist/collections/Workflow.d.ts +5 -2
  9. package/dist/collections/Workflow.js +179 -39
  10. package/dist/collections/Workflow.js.map +1 -1
  11. package/dist/collections/WorkflowRuns.d.ts +4 -0
  12. package/dist/collections/WorkflowRuns.js +219 -24
  13. package/dist/collections/WorkflowRuns.js.map +1 -1
  14. package/dist/components/WorkflowBuilder/WorkflowBuilder.js.map +1 -1
  15. package/dist/core/expression-engine.d.ts +58 -0
  16. package/dist/core/expression-engine.js +191 -0
  17. package/dist/core/expression-engine.js.map +1 -0
  18. package/dist/core/workflow-executor.d.ts +70 -56
  19. package/dist/core/workflow-executor.js +354 -677
  20. package/dist/core/workflow-executor.js.map +1 -1
  21. package/dist/exports/client.js +1 -3
  22. package/dist/exports/client.js.map +1 -1
  23. package/dist/exports/views.js +2 -4
  24. package/dist/exports/views.js.map +1 -1
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.js +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/plugin/config-types.d.ts +43 -5
  29. package/dist/plugin/config-types.js +3 -1
  30. package/dist/plugin/config-types.js.map +1 -1
  31. package/dist/plugin/index.d.ts +1 -1
  32. package/dist/plugin/index.js +150 -55
  33. package/dist/plugin/index.js.map +1 -1
  34. package/dist/plugin/trigger-hook.d.ts +13 -0
  35. package/dist/plugin/trigger-hook.js +184 -0
  36. package/dist/plugin/trigger-hook.js.map +1 -0
  37. package/dist/steps/create-step.d.ts +66 -0
  38. package/dist/steps/create-step.js +59 -0
  39. package/dist/steps/create-step.js.map +1 -0
  40. package/dist/steps/index.d.ts +2 -0
  41. package/dist/steps/index.js +3 -0
  42. package/dist/steps/index.js.map +1 -1
  43. package/dist/steps/read-document-handler.js +1 -1
  44. package/dist/steps/read-document-handler.js.map +1 -1
  45. package/dist/steps/update-document-handler.js +1 -1
  46. package/dist/steps/update-document-handler.js.map +1 -1
  47. package/dist/triggers/hook-options.d.ts +34 -0
  48. package/dist/triggers/hook-options.js +158 -0
  49. package/dist/triggers/hook-options.js.map +1 -0
  50. package/dist/triggers/index.d.ts +2 -2
  51. package/dist/triggers/index.js +1 -2
  52. package/dist/triggers/index.js.map +1 -1
  53. package/dist/types/index.d.ts +8 -0
  54. package/dist/types/index.js +4 -5
  55. package/dist/types/index.js.map +1 -1
  56. package/dist/utils/validation.d.ts +64 -0
  57. package/dist/utils/validation.js +107 -0
  58. package/dist/utils/validation.js.map +1 -0
  59. package/package.json +2 -1
  60. package/dist/plugin/collection-hook.d.ts +0 -1
  61. package/dist/plugin/collection-hook.js +0 -92
  62. package/dist/plugin/collection-hook.js.map +0 -1
  63. package/dist/plugin/global-hook.d.ts +0 -1
  64. package/dist/plugin/global-hook.js +0 -83
  65. package/dist/plugin/global-hook.js.map +0 -1
  66. package/dist/triggers/collection-trigger.d.ts +0 -2
  67. package/dist/triggers/collection-trigger.js +0 -36
  68. package/dist/triggers/collection-trigger.js.map +0 -1
  69. package/dist/triggers/global-trigger.d.ts +0 -2
  70. package/dist/triggers/global-trigger.js +0 -29
  71. package/dist/triggers/global-trigger.js.map +0 -1
  72. package/dist/triggers/types.d.ts +0 -5
  73. package/dist/triggers/types.js +0 -3
  74. package/dist/triggers/types.js.map +0 -1
@@ -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,EAAEL,YAAY,OAAO;IAC9D,MAAMM,aAAa;IACnB,IAAI,CAACA,WAAWC,IAAI,CAACF,QAAQ;QAC3B,MAAM,IAAIjB,gBAAgB,GAAGY,UAAU,8BAA8B,CAAC;IACxE;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASQ,kBACdZ,KAAiB,EACjBI,SAAiB;IAEjB,IAAI,OAAOJ,UAAU,UAAU;QAC7B,IAAI;YACF,OAAOa,KAAKC,KAAK,CAACd;QACpB,EAAE,OAAM;YACN,MAAM,IAAIR,gBAAgB,GAAGY,UAAU,mBAAmB,CAAC;QAC7D;IACF;IACA,OAAOJ;AACT;AAEA;;;CAGC,GACD,OAAO,SAASe,oBACdf,KAAa,EACbI,SAAiB,EACjBY,GAAY,EACZC,GAAY;IAEZ,IAAID,QAAQf,aAAaD,QAAQgB,KAAK;QACpC,MAAM,IAAIxB,gBAAgB,GAAGY,UAAU,kBAAkB,EAAEY,KAAK;IAClE;IACA,IAAIC,QAAQhB,aAAaD,QAAQiB,KAAK;QACpC,MAAM,IAAIzB,gBAAgB,GAAGY,UAAU,iBAAiB,EAAEa,KAAK;IACjE;AACF;AAEA;;CAEC,GACD,OAAO,SAASC,qBAAqBC,KAAc;IACjD,OAAO;QACLC,cAAcD,iBAAiB1B,QAAQ0B,MAAMzB,OAAO,GAAG;QACvD2B,OAAO;IACT;AACF;AAEA;;CAEC,GACD,OAAO,SAASC,sBAAyBC,MAAS;IAChD,OAAO;QACLA;QACAF,OAAO;IACT;AACF;AAEA;;;CAGC,GACD,OAAO,SAASG,kBACdC,OAA4C;IAE5C,OAAO,OAAO5B;QACZ,IAAI;YACF,MAAM0B,SAAS,MAAME,QAAQ5B;YAC7B,OAAOyB,sBAAsBC;QAC/B,EAAE,OAAOJ,OAAO;YACd,OAAOD,qBAAqBC;QAC9B;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtr-dev/payload-automation",
3
- "version": "0.0.43",
3
+ "version": "0.0.46",
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;YAChC,2BAA2B;YAC3B,MAAMU,UAAU;gBACdC,OAAO,CAAC;gBACRC,SAAS;oBACP,GAAGlB,IAAI;oBACPmB,MAAM;oBACNX,YAAYV;gBACd;YACF;YAEA,uDAAuD;YACvD,IAAIsB,gBAAgB;YACpB,KAAK,MAAMF,WAAWH,SAASM,QAAQ,IAAI,EAAE,CAAE;gBAC7C,IAAIH,QAAQC,IAAI,KAAK,qBACjBD,QAAQI,UAAU,EAAExB,mBAAmBA,kBACvCoB,QAAQI,UAAU,EAAEC,SAASxB,UAAU;oBAEzC,IAAImB,QAAQM,SAAS,EAAE;wBACrB,yBAAyB;wBACzB,IAAI;4BACF,MAAMC,eAAeZ,SAASa,iBAAiB,CAACR,QAAQM,SAAS,EAAER;4BACnE,IAAIS,cAAc;gCAChBL,gBAAgB;gCAChB;4BACF;wBACF,EAAE,OAAOO,OAAO;4BACdvB,QAAQU,MAAM,CAACa,KAAK,CAAC;gCACnBC,YAAYb,SAASc,EAAE;gCACvBL,WAAWN,QAAQM,SAAS;gCAC5BG,OAAOA,iBAAiBxB,QAAQwB,MAAMG,OAAO,GAAG;4BAClD,GAAG;wBACL;oBACF,OAAO;wBACL,oCAAoC;wBACpCV,gBAAgB;wBAChB;oBACF;gBACF;YACF;YAEA,IAAI,CAACA,eAAe;gBAClBhB,QAAQU,MAAM,CAACiB,KAAK,CAAC;oBACnBH,YAAYb,SAASc,EAAE;oBACvBrB,YAAYV;oBACZC;gBACF,GAAG;gBACH;YACF;YAEA,IAAI;gBACF,8DAA8D;gBAC9D,MAAMc,SAASmB,OAAO,CAACjB,UAAiBC,SAASf;gBACjDG,QAAQU,MAAM,CAACmB,IAAI,CAAC;oBAClBL,YAAYb,SAASc,EAAE;oBACvBrB,YAAYV;oBACZC;gBACF,GAAG;YACL,EAAE,OAAO4B,OAAO;gBACdvB,QAAQU,MAAM,CAACa,KAAK,CAAC;oBACnBC,YAAYb,SAASc,EAAE;oBACvBrB,YAAYV;oBACZC;oBACA4B,OAAOA,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,MAAM,SAASD,OAAOA,KAAKC,GAAG,GAClC,UAAUD,OAAOA,KAAKA,IAAI,CAACC,GAAG,GAC9BC;QACF,IAAI,CAACD,KAAK;YACR,MAAM,IAAIE,MAAM;QAClB;QAEA,MAAMC,UAAUH,IAAIG,OAAO;QAC3B,MAAMC,SAASD,QAAQC,MAAM;QAE7B,IAAI;YACFA,OAAOC,IAAI,CAAC;gBACVC,QAAQV;gBACRC;gBACAU,WAAWV;YACb,GAAG;YAEH,4BAA4B;YAC5B,MAAMW,WAAW,IAAId,iBAAiBS,SAASC;YAE/CA,OAAOK,KAAK,CAAC;YAEb,+CAA+C;YAC/C,MAAM,EAACC,MAAMC,SAAS,EAAC,GAAG,MAAMR,QAAQS,IAAI,CAAC;gBAC3CC,YAAY;gBACZC,OAAO;gBACPC,OAAO;gBACPC,OAAO;oBACL,8BAA8B;wBAC5BC,QAAQrB;oBACV;oBACA,iCAAiC;wBAC/BqB,QAAQpB;oBACV;oBACA,iBAAiB;wBACfoB,QAAQ;oBACV;gBACF;YACF;YAEA,iCAAiC;YACjC,KAAK,MAAMC,YAAYP,UAAW;gBAChC,2BAA2B;gBAC3B,MAAMQ,UAAU;oBACdC,OAAO,CAAC;oBACRC,SAAS;wBACP,GAAGtB,IAAI;wBACPuB,MAAM;wBACNhB,QAAQV;wBACRW,WAAWV;wBACXG;oBACF;gBACF;gBAEA,IAAI;oBACF,MAAMQ,SAASe,OAAO,CAACL,UAAUC,SAASnB;oBAC1CI,OAAOC,IAAI,CAAC;wBACVmB,YAAYN,SAASO,EAAE;wBACvBnB,QAAQV;wBACRC;oBACF,GAAG;gBACL,EAAE,OAAO6B,OAAO;oBACdtB,OAAOsB,KAAK,CAAC;wBACXF,YAAYN,SAASO,EAAE;wBACvBnB,QAAQV;wBACRC;wBACA6B,OAAOA,iBAAiBxB,QAAQwB,MAAMC,OAAO,GAAG;oBAClD,GAAG;gBACH,yDAAyD;gBAC3D;YACF;YAEAvB,OAAOC,IAAI,CAAC;gBACVC,QAAQV;gBACRC;YACF,GAAG;QAEL,EAAE,OAAO6B,OAAO;YACd,MAAME,eAAeF,iBAAiBxB,QAAQwB,MAAMC,OAAO,GAAG;YAE9DvB,OAAOsB,KAAK,CAAC;gBACXpB,QAAQV;gBACRC;gBACA6B,OAAOE;gBACPC,YAAYH,iBAAiBxB,QAAQwB,MAAMI,KAAK,GAAG7B;YACrD,GAAG;QAEH,yDAAyD;QAC3D;IACF;AACF,EAAC"}
@@ -1,2 +0,0 @@
1
- import type { TriggerConfig } from '../plugin/config-types.js';
2
- export declare const collectionTrigger: TriggerConfig;
@@ -1,36 +0,0 @@
1
- export const collectionTrigger = ({ collectionTriggers })=>({
2
- slug: 'collection-hook',
3
- parameters: [
4
- {
5
- name: 'collectionSlug',
6
- type: 'select',
7
- options: Object.keys(collectionTriggers || {})
8
- },
9
- {
10
- name: 'hook',
11
- type: 'select',
12
- options: [
13
- "afterChange",
14
- "afterDelete",
15
- "afterError",
16
- "afterForgotPassword",
17
- "afterLogin",
18
- "afterLogout",
19
- "afterMe",
20
- "afterOperation",
21
- "afterRead",
22
- "afterRefresh",
23
- "beforeChange",
24
- "beforeDelete",
25
- "beforeLogin",
26
- "beforeOperation",
27
- "beforeRead",
28
- "beforeValidate",
29
- "me",
30
- "refresh"
31
- ]
32
- }
33
- ]
34
- });
35
-
36
- //# sourceMappingURL=collection-trigger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/triggers/collection-trigger.ts"],"sourcesContent":["import type {TriggerConfig} from '../plugin/config-types.js'\n\nexport const collectionTrigger: TriggerConfig = ({collectionTriggers}) => ({\n slug: 'collection-hook',\n parameters: [\n {\n name: 'collectionSlug',\n type: 'select',\n options: Object.keys(collectionTriggers || {}),\n },\n {\n name: 'hook',\n type: 'select',\n options: [\n \"afterChange\",\n \"afterDelete\",\n \"afterError\",\n \"afterForgotPassword\",\n \"afterLogin\",\n \"afterLogout\",\n \"afterMe\",\n \"afterOperation\",\n \"afterRead\",\n \"afterRefresh\",\n \"beforeChange\",\n \"beforeDelete\",\n \"beforeLogin\",\n \"beforeOperation\",\n \"beforeRead\",\n \"beforeValidate\",\n \"me\",\n \"refresh\"\n ]\n }\n ]\n})\n"],"names":["collectionTrigger","collectionTriggers","slug","parameters","name","type","options","Object","keys"],"mappings":"AAEA,OAAO,MAAMA,oBAAmC,CAAC,EAACC,kBAAkB,EAAC,GAAM,CAAA;QACzEC,MAAM;QACNC,YAAY;YACV;gBACEC,MAAM;gBACNC,MAAM;gBACNC,SAASC,OAAOC,IAAI,CAACP,sBAAsB,CAAC;YAC9C;YACA;gBACEG,MAAM;gBACNC,MAAM;gBACNC,SAAS;oBACP;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;iBACD;YACH;SACD;IACH,CAAA,EAAE"}
@@ -1,2 +0,0 @@
1
- import type { TriggerConfig } from '../plugin/config-types.js';
2
- export declare const globalTrigger: TriggerConfig;
@@ -1,29 +0,0 @@
1
- export const globalTrigger = ({ globalTriggers })=>({
2
- slug: 'global-hook',
3
- parameters: [
4
- {
5
- name: 'global',
6
- type: 'select',
7
- admin: {
8
- description: 'Global that triggers the workflow'
9
- },
10
- options: Object.keys(globalTriggers || {})
11
- },
12
- {
13
- name: 'operation',
14
- type: 'select',
15
- admin: {
16
- description: 'Global hook that triggers the workflow'
17
- },
18
- options: [
19
- "afterChange",
20
- "afterRead",
21
- "beforeChange",
22
- "beforeRead",
23
- "beforeValidate"
24
- ]
25
- }
26
- ]
27
- });
28
-
29
- //# sourceMappingURL=global-trigger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/triggers/global-trigger.ts"],"sourcesContent":["import type {TriggerConfig} from '../plugin/config-types.js'\n\nexport const globalTrigger: TriggerConfig = ({globalTriggers}) => ({\n slug: 'global-hook',\n parameters: [\n {\n name: 'global',\n type: 'select',\n admin: {\n description: 'Global that triggers the workflow',\n },\n options: Object.keys(globalTriggers || {}),\n },\n {\n name: 'operation',\n type: 'select',\n admin: {\n description: 'Global hook that triggers the workflow',\n },\n options: [\n \"afterChange\",\n \"afterRead\", \n \"beforeChange\",\n \"beforeRead\",\n \"beforeValidate\"\n ],\n }\n ]\n})\n"],"names":["globalTrigger","globalTriggers","slug","parameters","name","type","admin","description","options","Object","keys"],"mappings":"AAEA,OAAO,MAAMA,gBAA+B,CAAC,EAACC,cAAc,EAAC,GAAM,CAAA;QACjEC,MAAM;QACNC,YAAY;YACV;gBACEC,MAAM;gBACNC,MAAM;gBACNC,OAAO;oBACLC,aAAa;gBACf;gBACAC,SAASC,OAAOC,IAAI,CAACT,kBAAkB,CAAC;YAC1C;YACA;gBACEG,MAAM;gBACNC,MAAM;gBACNC,OAAO;oBACLC,aAAa;gBACf;gBACAC,SAAS;oBACP;oBACA;oBACA;oBACA;oBACA;iBACD;YACH;SACD;IACH,CAAA,EAAE"}
@@ -1,5 +0,0 @@
1
- import type { Field } from "payload";
2
- export type Trigger = {
3
- slug: string;
4
- parameters: Field[];
5
- };
@@ -1,3 +0,0 @@
1
- export { };
2
-
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/triggers/types.ts"],"sourcesContent":["import type {Field} from \"payload\"\n\nexport type Trigger = {\n slug: string\n parameters: Field[]\n}\n"],"names":[],"mappings":"AAEA,WAGC"}