@xtr-dev/payload-automation 0.0.42 → 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/fields/parameter.js +8 -3
- package/dist/fields/parameter.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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/steps/create-step.ts"],"sourcesContent":["import type { Field, JsonObject, PayloadRequest, TaskConfig, TaskHandler } from 'payload'\n\n/**\n * Configuration for creating a step with the factory.\n */\nexport interface StepDefinition<TSlug extends string> {\n /** Unique identifier for the step */\n slug: TSlug\n /** Human-readable label for the step (optional, defaults to slug) */\n label?: string\n /** Input fields schema */\n inputSchema: Field[]\n /** Output fields schema */\n outputSchema: Field[]\n /**\n * Optional validation function. Throw an error if validation fails.\n * Runs before the execute function.\n */\n validate?: (input: JsonObject) => void\n /**\n * The main execution function for the step.\n * Should return the output data on success, or throw an error on failure.\n */\n execute: (input: JsonObject, req: PayloadRequest) => Promise<JsonObject>\n}\n\n/**\n * The result type returned by createStep.\n * Combines TaskConfig with the handler for convenience.\n */\nexport type StepTask<TSlug extends string> = TaskConfig<TSlug>\n\n/**\n * Creates a step definition that combines TaskConfig and handler in one place.\n *\n * This factory eliminates the need for separate `{step}.ts` and `{step}-handler.ts` files\n * by providing a single unified definition.\n *\n * @example\n * ```typescript\n * export const myStep = createStep({\n * slug: 'my-step',\n * inputSchema: [\n * { name: 'url', type: 'text', required: true }\n * ],\n * outputSchema: [\n * { name: 'result', type: 'json' }\n * ],\n * validate: (input) => {\n * if (!input.url) throw new Error('URL is required')\n * },\n * execute: async (input, req) => {\n * const response = await fetch(input.url)\n * return { result: await response.json() }\n * }\n * })\n * ```\n */\nexport function createStep<TSlug extends string>(\n definition: StepDefinition<TSlug>\n): StepTask<TSlug> {\n const { slug, label, inputSchema, outputSchema, validate, execute } = definition\n\n // Create the handler that wraps validation and execution\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handler = async ({ input, req }: any) => {\n try {\n const jsonInput = (input ?? {}) as JsonObject\n\n // Run validation if provided\n if (validate) {\n validate(jsonInput)\n }\n\n // Execute the step\n const output = await execute(jsonInput, req)\n return {\n output,\n state: 'succeeded'\n }\n } catch (error) {\n return {\n errorMessage: error instanceof Error ? error.message : 'Unknown error',\n state: 'failed'\n }\n }\n }\n\n return {\n slug,\n label,\n handler,\n inputSchema,\n outputSchema\n } as StepTask<TSlug>\n}\n\n/**\n * Helper type to extract input type from a step's inputSchema.\n * Note: This provides a basic type based on field names, not full type inference.\n */\nexport type StepInput<T extends StepTask<string>> = T extends StepTask<infer _>\n ? Record<string, unknown>\n : never\n\n/**\n * Helper type to extract output type from a step's outputSchema.\n * Note: This provides a basic type based on field names, not full type inference.\n */\nexport type StepOutput<T extends StepTask<string>> = T extends StepTask<infer _>\n ? Record<string, unknown>\n : never\n"],"names":["createStep","definition","slug","label","inputSchema","outputSchema","validate","execute","handler","input","req","jsonInput","output","state","error","errorMessage","Error","message"],"mappings":"AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,SAASA,WACdC,UAAiC;IAEjC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,WAAW,EAAEC,YAAY,EAAEC,QAAQ,EAAEC,OAAO,EAAE,GAAGN;IAEtE,yDAAyD;IACzD,8DAA8D;IAC9D,MAAMO,UAAU,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAO;QACxC,IAAI;YACF,MAAMC,YAAaF,SAAS,CAAC;YAE7B,6BAA6B;YAC7B,IAAIH,UAAU;gBACZA,SAASK;YACX;YAEA,mBAAmB;YACnB,MAAMC,SAAS,MAAML,QAAQI,WAAWD;YACxC,OAAO;gBACLE;gBACAC,OAAO;YACT;QACF,EAAE,OAAOC,OAAO;YACd,OAAO;gBACLC,cAAcD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;gBACvDJ,OAAO;YACT;QACF;IACF;IAEA,OAAO;QACLX;QACAC;QACAK;QACAJ;QACAC;IACF;AACF"}
|
package/dist/steps/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { createStep } from './create-step.js';
|
|
2
|
+
export type { StepDefinition, StepTask } from './create-step.js';
|
|
1
3
|
export { CreateDocumentStepTask } from './create-document.js';
|
|
2
4
|
export { createDocumentHandler } from './create-document-handler.js';
|
|
3
5
|
export { DeleteDocumentStepTask } from './delete-document.js';
|
package/dist/steps/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Step factory for creating new steps
|
|
2
|
+
export { createStep } from './create-step.js';
|
|
3
|
+
// Built-in steps
|
|
1
4
|
export { CreateDocumentStepTask } from './create-document.js';
|
|
2
5
|
export { createDocumentHandler } from './create-document-handler.js';
|
|
3
6
|
export { DeleteDocumentStepTask } from './delete-document.js';
|
package/dist/steps/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/steps/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/steps/index.ts"],"sourcesContent":["// Step factory for creating new steps\nexport { createStep } from './create-step.js'\nexport type { StepDefinition, StepTask } from './create-step.js'\n\n// Built-in steps\nexport { CreateDocumentStepTask } from './create-document.js'\nexport { createDocumentHandler } from './create-document-handler.js'\nexport { DeleteDocumentStepTask } from './delete-document.js'\nexport { deleteDocumentHandler } from './delete-document-handler.js'\nexport { HttpRequestStepTask } from './http-request.js'\nexport { httpStepHandler } from './http-request-handler.js'\n\nexport { ReadDocumentStepTask } from './read-document.js'\nexport { readDocumentHandler } from './read-document-handler.js'\nexport { SendEmailStepTask } from './send-email.js'\nexport { sendEmailHandler } from './send-email-handler.js'\nexport { UpdateDocumentStepTask } from './update-document.js'\nexport { updateDocumentHandler } from './update-document-handler.js'\n"],"names":["createStep","CreateDocumentStepTask","createDocumentHandler","DeleteDocumentStepTask","deleteDocumentHandler","HttpRequestStepTask","httpStepHandler","ReadDocumentStepTask","readDocumentHandler","SendEmailStepTask","sendEmailHandler","UpdateDocumentStepTask","updateDocumentHandler"],"mappings":"AAAA,sCAAsC;AACtC,SAASA,UAAU,QAAQ,mBAAkB;AAG7C,iBAAiB;AACjB,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SAASC,qBAAqB,QAAQ,+BAA8B;AACpE,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SAASC,qBAAqB,QAAQ,+BAA8B;AACpE,SAASC,mBAAmB,QAAQ,oBAAmB;AACvD,SAASC,eAAe,QAAQ,4BAA2B;AAE3D,SAASC,oBAAoB,QAAQ,qBAAoB;AACzD,SAASC,mBAAmB,QAAQ,6BAA4B;AAChE,SAASC,iBAAiB,QAAQ,kBAAiB;AACnD,SAASC,gBAAgB,QAAQ,0BAAyB;AAC1D,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SAASC,qBAAqB,QAAQ,+BAA8B"}
|
|
@@ -44,7 +44,7 @@ export const readDocumentHandler = async ({ input, req })=>{
|
|
|
44
44
|
};
|
|
45
45
|
} catch (error) {
|
|
46
46
|
return {
|
|
47
|
-
|
|
47
|
+
errorMessage: error instanceof Error ? error.message : 'Failed to read document(s)',
|
|
48
48
|
state: 'failed'
|
|
49
49
|
};
|
|
50
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/steps/read-document-handler.ts"],"sourcesContent":["import type { TaskHandler } from \"payload\"\n\nexport const readDocumentHandler: TaskHandler<'read-document'> = async ({ input, req }) => {\n if (!input) {\n throw new Error('No input provided')\n }\n\n const { id, collectionSlug, depth, limit, locale, sort, where } = input\n\n if (!collectionSlug || typeof collectionSlug !== 'string') {\n throw new Error('Collection slug is required')\n }\n\n try {\n // If ID is provided, find by ID\n if (id) {\n const result = await req.payload.findByID({\n id: id.toString(),\n collection: collectionSlug,\n depth: typeof depth === 'number' ? depth : undefined,\n locale: locale || undefined,\n req\n })\n\n return {\n output: {\n doc: result,\n totalDocs: 1\n },\n state: 'succeeded'\n }\n }\n\n // Otherwise, find multiple documents\n const parsedWhere = where ? (typeof where === 'string' ? JSON.parse(where) : where) : {}\n\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: typeof depth === 'number' ? depth : undefined,\n limit: typeof limit === 'number' ? limit : 10,\n locale: locale || undefined,\n req,\n sort: sort || undefined,\n where: parsedWhere\n })\n\n return {\n output: {\n doc: result.docs,\n totalDocs: result.totalDocs\n },\n state: 'succeeded'\n }\n } catch (error) {\n return {\n
|
|
1
|
+
{"version":3,"sources":["../../src/steps/read-document-handler.ts"],"sourcesContent":["import type { TaskHandler } from \"payload\"\n\nexport const readDocumentHandler: TaskHandler<'read-document'> = async ({ input, req }) => {\n if (!input) {\n throw new Error('No input provided')\n }\n\n const { id, collectionSlug, depth, limit, locale, sort, where } = input\n\n if (!collectionSlug || typeof collectionSlug !== 'string') {\n throw new Error('Collection slug is required')\n }\n\n try {\n // If ID is provided, find by ID\n if (id) {\n const result = await req.payload.findByID({\n id: id.toString(),\n collection: collectionSlug,\n depth: typeof depth === 'number' ? depth : undefined,\n locale: locale || undefined,\n req\n })\n\n return {\n output: {\n doc: result,\n totalDocs: 1\n },\n state: 'succeeded'\n }\n }\n\n // Otherwise, find multiple documents\n const parsedWhere = where ? (typeof where === 'string' ? JSON.parse(where) : where) : {}\n\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: typeof depth === 'number' ? depth : undefined,\n limit: typeof limit === 'number' ? limit : 10,\n locale: locale || undefined,\n req,\n sort: sort || undefined,\n where: parsedWhere\n })\n\n return {\n output: {\n doc: result.docs,\n totalDocs: result.totalDocs\n },\n state: 'succeeded'\n }\n } catch (error) {\n return {\n errorMessage: error instanceof Error ? error.message : 'Failed to read document(s)',\n state: 'failed'\n }\n }\n}\n"],"names":["readDocumentHandler","input","req","Error","id","collectionSlug","depth","limit","locale","sort","where","result","payload","findByID","toString","collection","undefined","output","doc","totalDocs","state","parsedWhere","JSON","parse","find","docs","error","errorMessage","message"],"mappings":"AAEA,OAAO,MAAMA,sBAAoD,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAE;IACpF,IAAI,CAACD,OAAO;QACV,MAAM,IAAIE,MAAM;IAClB;IAEA,MAAM,EAAEC,EAAE,EAAEC,cAAc,EAAEC,KAAK,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAE,GAAGT;IAElE,IAAI,CAACI,kBAAkB,OAAOA,mBAAmB,UAAU;QACzD,MAAM,IAAIF,MAAM;IAClB;IAEA,IAAI;QACF,gCAAgC;QAChC,IAAIC,IAAI;YACN,MAAMO,SAAS,MAAMT,IAAIU,OAAO,CAACC,QAAQ,CAAC;gBACxCT,IAAIA,GAAGU,QAAQ;gBACfC,YAAYV;gBACZC,OAAO,OAAOA,UAAU,WAAWA,QAAQU;gBAC3CR,QAAQA,UAAUQ;gBAClBd;YACF;YAEA,OAAO;gBACLe,QAAQ;oBACNC,KAAKP;oBACLQ,WAAW;gBACb;gBACAC,OAAO;YACT;QACF;QAEA,qCAAqC;QACrC,MAAMC,cAAcX,QAAS,OAAOA,UAAU,WAAWY,KAAKC,KAAK,CAACb,SAASA,QAAS,CAAC;QAEvF,MAAMC,SAAS,MAAMT,IAAIU,OAAO,CAACY,IAAI,CAAC;YACpCT,YAAYV;YACZC,OAAO,OAAOA,UAAU,WAAWA,QAAQU;YAC3CT,OAAO,OAAOA,UAAU,WAAWA,QAAQ;YAC3CC,QAAQA,UAAUQ;YAClBd;YACAO,MAAMA,QAAQO;YACdN,OAAOW;QACT;QAEA,OAAO;YACLJ,QAAQ;gBACNC,KAAKP,OAAOc,IAAI;gBAChBN,WAAWR,OAAOQ,SAAS;YAC7B;YACAC,OAAO;QACT;IACF,EAAE,OAAOM,OAAO;QACd,OAAO;YACLC,cAAcD,iBAAiBvB,QAAQuB,MAAME,OAAO,GAAG;YACvDR,OAAO;QACT;IACF;AACF,EAAC"}
|
|
@@ -31,7 +31,7 @@ export const updateDocumentHandler = async ({ input, req })=>{
|
|
|
31
31
|
};
|
|
32
32
|
} catch (error) {
|
|
33
33
|
return {
|
|
34
|
-
|
|
34
|
+
errorMessage: error instanceof Error ? error.message : 'Failed to update document',
|
|
35
35
|
state: 'failed'
|
|
36
36
|
};
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/steps/update-document-handler.ts"],"sourcesContent":["import type { TaskHandler } from \"payload\"\n\nexport const updateDocumentHandler: TaskHandler<'update-document'> = async ({ input, req }) => {\n if (!input) {\n throw new Error('No input provided')\n }\n\n const { id, collectionSlug, data, draft, locale } = input\n\n if (!collectionSlug || typeof collectionSlug !== 'string') {\n throw new Error('Collection slug is required')\n }\n\n if (!id) {\n throw new Error('Document ID is required')\n }\n\n if (!data) {\n throw new Error('Update data is required')\n }\n\n try {\n const parsedData = typeof data === 'string' ? JSON.parse(data) : data\n\n const result = await req.payload.update({\n id: id.toString(),\n collection: collectionSlug,\n data: parsedData,\n draft: draft || false,\n locale: locale || undefined,\n req\n })\n\n return {\n output: {\n id: result.id,\n doc: result\n },\n state: 'succeeded'\n }\n } catch (error) {\n return {\n
|
|
1
|
+
{"version":3,"sources":["../../src/steps/update-document-handler.ts"],"sourcesContent":["import type { TaskHandler } from \"payload\"\n\nexport const updateDocumentHandler: TaskHandler<'update-document'> = async ({ input, req }) => {\n if (!input) {\n throw new Error('No input provided')\n }\n\n const { id, collectionSlug, data, draft, locale } = input\n\n if (!collectionSlug || typeof collectionSlug !== 'string') {\n throw new Error('Collection slug is required')\n }\n\n if (!id) {\n throw new Error('Document ID is required')\n }\n\n if (!data) {\n throw new Error('Update data is required')\n }\n\n try {\n const parsedData = typeof data === 'string' ? JSON.parse(data) : data\n\n const result = await req.payload.update({\n id: id.toString(),\n collection: collectionSlug,\n data: parsedData,\n draft: draft || false,\n locale: locale || undefined,\n req\n })\n\n return {\n output: {\n id: result.id,\n doc: result\n },\n state: 'succeeded'\n }\n } catch (error) {\n return {\n errorMessage: error instanceof Error ? error.message : 'Failed to update document',\n state: 'failed'\n }\n }\n}\n"],"names":["updateDocumentHandler","input","req","Error","id","collectionSlug","data","draft","locale","parsedData","JSON","parse","result","payload","update","toString","collection","undefined","output","doc","state","error","errorMessage","message"],"mappings":"AAEA,OAAO,MAAMA,wBAAwD,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAE;IACxF,IAAI,CAACD,OAAO;QACV,MAAM,IAAIE,MAAM;IAClB;IAEA,MAAM,EAAEC,EAAE,EAAEC,cAAc,EAAEC,IAAI,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAGP;IAEpD,IAAI,CAACI,kBAAkB,OAAOA,mBAAmB,UAAU;QACzD,MAAM,IAAIF,MAAM;IAClB;IAEA,IAAI,CAACC,IAAI;QACP,MAAM,IAAID,MAAM;IAClB;IAEA,IAAI,CAACG,MAAM;QACT,MAAM,IAAIH,MAAM;IAClB;IAEA,IAAI;QACF,MAAMM,aAAa,OAAOH,SAAS,WAAWI,KAAKC,KAAK,CAACL,QAAQA;QAEjE,MAAMM,SAAS,MAAMV,IAAIW,OAAO,CAACC,MAAM,CAAC;YACtCV,IAAIA,GAAGW,QAAQ;YACfC,YAAYX;YACZC,MAAMG;YACNF,OAAOA,SAAS;YAChBC,QAAQA,UAAUS;YAClBf;QACF;QAEA,OAAO;YACLgB,QAAQ;gBACNd,IAAIQ,OAAOR,EAAE;gBACbe,KAAKP;YACP;YACAQ,OAAO;QACT;IACF,EAAE,OAAOC,OAAO;QACd,OAAO;YACLC,cAAcD,iBAAiBlB,QAAQkB,MAAME,OAAO,GAAG;YACvDH,OAAO;QACT;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
export interface HookOption {
|
|
6
|
+
value: string;
|
|
7
|
+
label: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface HookOptionGroup {
|
|
11
|
+
label: string;
|
|
12
|
+
options: HookOption[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Collection hook options grouped by category.
|
|
16
|
+
*/
|
|
17
|
+
export declare const collectionHookGroups: HookOptionGroup[];
|
|
18
|
+
/**
|
|
19
|
+
* Global hook options grouped by category.
|
|
20
|
+
*/
|
|
21
|
+
export declare const globalHookGroups: HookOptionGroup[];
|
|
22
|
+
/**
|
|
23
|
+
* Flat list of collection hook options for select fields.
|
|
24
|
+
*/
|
|
25
|
+
export declare const collectionHookOptions: HookOption[];
|
|
26
|
+
/**
|
|
27
|
+
* Flat list of global hook options for select fields.
|
|
28
|
+
*/
|
|
29
|
+
export declare const globalHookOptions: HookOption[];
|
|
30
|
+
/**
|
|
31
|
+
* All hook values as a simple string array for validation.
|
|
32
|
+
*/
|
|
33
|
+
export declare const allCollectionHooks: string[];
|
|
34
|
+
export declare const allGlobalHooks: string[];
|
|
@@ -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,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.
|
|
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>;
|