@xtr-dev/payload-automation 0.0.26 → 0.0.28
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/dist/collections/Workflow.js +3 -27
- package/dist/collections/Workflow.js.map +1 -1
- package/dist/exports/helpers.d.ts +14 -15
- package/dist/exports/helpers.js +14 -16
- package/dist/exports/helpers.js.map +1 -1
- package/dist/utils/trigger-helpers.d.ts +49 -40
- package/dist/utils/trigger-helpers.js +96 -77
- package/dist/utils/trigger-helpers.js.map +1 -1
- package/dist/utils/trigger-presets.d.ts +6 -42
- package/dist/utils/trigger-presets.js +106 -101
- package/dist/utils/trigger-presets.js.map +1 -1
- package/package.json +1 -1
|
@@ -311,33 +311,9 @@ export const createWorkflowCollection = ({ collectionTriggers, steps, triggers }
|
|
|
311
311
|
required: false
|
|
312
312
|
},
|
|
313
313
|
// Virtual fields for custom triggers
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
name: `__${t.slug}_${f.name}`,
|
|
318
|
-
admin: {
|
|
319
|
-
...f.admin || {},
|
|
320
|
-
condition: (...args)=>args[1]?.type === t.slug && (f.admin?.condition ? f.admin.condition.call(this, ...args) : true)
|
|
321
|
-
},
|
|
322
|
-
hooks: {
|
|
323
|
-
afterRead: [
|
|
324
|
-
({ siblingData })=>{
|
|
325
|
-
return siblingData?.parameters?.[f.name] || undefined;
|
|
326
|
-
}
|
|
327
|
-
],
|
|
328
|
-
beforeChange: [
|
|
329
|
-
({ siblingData, value })=>{
|
|
330
|
-
if (!siblingData.parameters) {
|
|
331
|
-
siblingData.parameters = {};
|
|
332
|
-
}
|
|
333
|
-
siblingData.parameters[f.name] = value;
|
|
334
|
-
return undefined // Virtual field, don't store directly
|
|
335
|
-
;
|
|
336
|
-
}
|
|
337
|
-
]
|
|
338
|
-
},
|
|
339
|
-
virtual: true
|
|
340
|
-
})))
|
|
314
|
+
// Note: Custom trigger fields from trigger-helpers already have unique names
|
|
315
|
+
// We just need to pass them through without modification
|
|
316
|
+
...(triggers || []).flatMap((t)=>t.inputs || [])
|
|
341
317
|
]
|
|
342
318
|
},
|
|
343
319
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/Workflow.ts"],"sourcesContent":["import type {CollectionConfig, Field} from 'payload'\n\nimport type {WorkflowsPluginConfig} from \"../plugin/config-types.js\"\n\nexport const createWorkflowCollection: <T extends string>(options: WorkflowsPluginConfig<T>) => CollectionConfig = ({\n collectionTriggers,\n steps,\n triggers\n }) => ({\n slug: 'workflows',\n access: {\n create: () => true,\n delete: () => true,\n read: () => true,\n update: () => true,\n },\n admin: {\n defaultColumns: ['name', 'updatedAt'],\n description: 'Create and manage automated workflows.',\n group: 'Automation',\n useAsTitle: 'name',\n },\n fields: [\n {\n name: 'name',\n type: 'text',\n admin: {\n description: 'Human-readable name for the workflow',\n },\n required: true,\n },\n {\n name: 'description',\n type: 'textarea',\n admin: {\n description: 'Optional description of what this workflow does',\n },\n },\n {\n name: 'executionStatus',\n type: 'ui',\n admin: {\n components: {\n Field: '@/components/WorkflowExecutionStatus'\n },\n condition: (data) => !!data?.id // Only show for existing workflows\n }\n },\n {\n name: 'triggers',\n type: 'array',\n fields: [\n {\n name: 'type',\n type: 'select',\n options: [\n 'collection-trigger',\n 'webhook-trigger',\n 'global-trigger',\n 'cron-trigger',\n ...(triggers || []).map(t => t.slug)\n ]\n },\n {\n name: 'parameters',\n type: 'json',\n admin: {\n hidden: true,\n },\n defaultValue: {}\n },\n // Virtual fields for collection trigger\n {\n name: '__builtin_collectionSlug',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'collection-trigger',\n description: 'Collection that triggers the workflow',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.collectionSlug || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.collectionSlug = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n options: Object.keys(collectionTriggers || {}),\n virtual: true,\n },\n {\n name: '__builtin_operation',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'collection-trigger',\n description: 'Collection operation that triggers the workflow',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.operation || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.operation = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n options: [\n 'create',\n 'delete',\n 'read',\n 'update',\n ],\n virtual: true,\n },\n // Virtual fields for webhook trigger\n {\n name: '__builtin_webhookPath',\n type: 'text',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'webhook-trigger',\n description: 'URL path for the webhook (e.g., \"my-webhook\"). Full URL will be /api/workflows-webhook/my-webhook',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.webhookPath || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.webhookPath = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n validate: (value: any, {siblingData}: any) => {\n if (siblingData?.type === 'webhook-trigger' && !value && !siblingData?.parameters?.webhookPath) {\n return 'Webhook path is required for webhook triggers'\n }\n return true\n },\n virtual: true,\n },\n // Virtual fields for global trigger\n {\n name: '__builtin_global',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'global-trigger',\n description: 'Global that triggers the workflow',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.global || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.global = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n options: [], // Will be populated dynamically based on available globals\n virtual: true,\n },\n {\n name: '__builtin_globalOperation',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'global-trigger',\n description: 'Global operation that triggers the workflow',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.globalOperation || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.globalOperation = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n options: [\n 'update'\n ],\n virtual: true,\n },\n // Virtual fields for cron trigger\n {\n name: '__builtin_cronExpression',\n type: 'text',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'cron-trigger',\n description: 'Cron expression for scheduled execution (e.g., \"0 0 * * *\" for daily at midnight)',\n placeholder: '0 0 * * *'\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.cronExpression || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.cronExpression = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n validate: (value: any, {siblingData}: any) => {\n const cronValue = value || siblingData?.parameters?.cronExpression\n if (siblingData?.type === 'cron-trigger' && !cronValue) {\n return 'Cron expression is required for cron triggers'\n }\n\n // Validate cron expression format if provided\n if (siblingData?.type === 'cron-trigger' && cronValue) {\n // Basic format validation - should be 5 parts separated by spaces\n const cronParts = cronValue.trim().split(/\\s+/)\n if (cronParts.length !== 5) {\n return 'Invalid cron expression format. Expected 5 parts: \"minute hour day month weekday\" (e.g., \"0 9 * * 1\")'\n }\n\n // Additional validation could use node-cron but we avoid dynamic imports here\n // The main validation happens at runtime in the cron scheduler\n }\n\n return true\n },\n virtual: true,\n },\n {\n name: '__builtin_timezone',\n type: 'text',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'cron-trigger',\n description: 'Timezone for cron execution (e.g., \"America/New_York\", \"Europe/London\"). Defaults to UTC.',\n placeholder: 'UTC'\n },\n defaultValue: 'UTC',\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.timezone || 'UTC'\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.timezone = value || 'UTC'\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n validate: (value: any, {siblingData}: any) => {\n const tzValue = value || siblingData?.parameters?.timezone\n if (siblingData?.type === 'cron-trigger' && tzValue) {\n try {\n // Test if timezone is valid by trying to create a date with it\n new Intl.DateTimeFormat('en', {timeZone: tzValue})\n return true\n } catch {\n return `Invalid timezone: ${tzValue}. Please use a valid IANA timezone identifier (e.g., \"America/New_York\", \"Europe/London\")`\n }\n }\n return true\n },\n virtual: true,\n },\n {\n name: 'condition',\n type: 'text',\n admin: {\n description: 'JSONPath expression that must evaluate to true for this trigger to execute the workflow (e.g., \"$.trigger.doc.status == \\'published\\'\")'\n },\n required: false\n },\n // Virtual fields for custom triggers\n ...(triggers || []).flatMap(t => (t.inputs || []).filter(f => 'name' in f && f.name).map(f => ({\n ...f,\n // Prefix field name with trigger slug to avoid conflicts\n name: `__${t.slug}_${(f as any).name}`,\n admin: {\n ...(f.admin || {}),\n condition: (...args) => args[1]?.type === t.slug && (\n f.admin?.condition ?\n f.admin.condition.call(this, ...args) :\n true\n ),\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.[(f as any).name] || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters[(f as any).name] = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n virtual: true,\n } as Field)))\n ]\n },\n {\n name: 'steps',\n type: 'array',\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'step',\n type: 'select',\n options: steps.map(t => t.slug)\n },\n {\n name: 'name',\n type: 'text',\n }\n ]\n },\n ...(steps || []).flatMap(step => (step.inputSchema || []).map(field => ({\n ...field,\n admin: {\n ...(field.admin || {}),\n condition: (...args) => args[1]?.step === step.slug && (\n field.admin?.condition ?\n field.admin.condition.call(this, ...args) :\n true\n ),\n },\n } as Field))),\n {\n name: 'dependencies',\n type: 'text',\n admin: {\n description: 'Step names that must complete before this step can run'\n },\n hasMany: true,\n required: false\n },\n {\n name: 'condition',\n type: 'text',\n admin: {\n description: 'JSONPath expression that must evaluate to true for this step to execute (e.g., \"$.trigger.doc.status == \\'published\\'\")'\n },\n required: false\n },\n ],\n }\n ],\n versions: {\n drafts: {\n autosave: false,\n },\n maxPerDoc: 10,\n },\n})\n"],"names":["createWorkflowCollection","collectionTriggers","steps","triggers","slug","access","create","delete","read","update","admin","defaultColumns","description","group","useAsTitle","fields","name","type","required","components","Field","condition","data","id","options","map","t","hidden","defaultValue","_","siblingData","hooks","afterRead","parameters","collectionSlug","undefined","beforeChange","value","Object","keys","virtual","operation","webhookPath","validate","global","globalOperation","placeholder","cronExpression","cronValue","cronParts","trim","split","length","timezone","tzValue","Intl","DateTimeFormat","timeZone","flatMap","inputs","filter","f","args","call","step","inputSchema","field","hasMany","versions","drafts","autosave","maxPerDoc"],"mappings":"AAIA,OAAO,MAAMA,2BAAsG,CAAC,EACZC,kBAAkB,EAClBC,KAAK,EACLC,QAAQ,EACT,GAAM,CAAA;QAC3GC,MAAM;QACNC,QAAQ;YACNC,QAAQ,IAAM;YACdC,QAAQ,IAAM;YACdC,MAAM,IAAM;YACZC,QAAQ,IAAM;QAChB;QACAC,OAAO;YACLC,gBAAgB;gBAAC;gBAAQ;aAAY;YACrCC,aAAa;YACbC,OAAO;YACPC,YAAY;QACd;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNP,OAAO;oBACLE,aAAa;gBACf;gBACAM,UAAU;YACZ;YACA;gBACEF,MAAM;gBACNC,MAAM;gBACNP,OAAO;oBACLE,aAAa;gBACf;YACF;YACA;gBACEI,MAAM;gBACNC,MAAM;gBACNP,OAAO;oBACLS,YAAY;wBACVC,OAAO;oBACT;oBACAC,WA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C;4BACA;gCACEY,MAAM;gCACNC,MAAM;4BACR;yBACD;oBACH;uBACG,AAACf,CAAAA,SAAS,EAAE,AAAD,EAAGwD,OAAO,CAACM,CAAAA,OAAQ,AAACA,CAAAA,KAAKC,WAAW,IAAI,EAAE,AAAD,EAAGxC,GAAG,CAACyC,CAAAA,QAAU,CAAA;gCACtE,GAAGA,KAAK;gCACRxD,OAAO;oCACL,GAAIwD,MAAMxD,KAAK,IAAI,CAAC,CAAC;oCACrBW,WAAW,CAAC,GAAGyC,OAASA,IAAI,CAAC,EAAE,EAAEE,SAASA,KAAK5D,IAAI,IACjD8D,CAAAA,MAAMxD,KAAK,EAAEW,YACX6C,MAAMxD,KAAK,CAACW,SAAS,CAAC0C,IAAI,CAAC,IAAI,KAAKD,QACpC,IAAG;gCAET;4BACF,CAAA;oBACA;wBACE9C,MAAM;wBACNC,MAAM;wBACNP,OAAO;4BACLE,aAAa;wBACf;wBACAuD,SAAS;wBACTjD,UAAU;oBACZ;oBACA;wBACEF,MAAM;wBACNC,MAAM;wBACNP,OAAO;4BACLE,aAAa;wBACf;wBACAM,UAAU;oBACZ;iBACD;YACH;SACD;QACDkD,UAAU;YACRC,QAAQ;gBACNC,UAAU;YACZ;YACAC,WAAW;QACb;IACF,CAAA,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/collections/Workflow.ts"],"sourcesContent":["import type {CollectionConfig, Field} from 'payload'\n\nimport type {WorkflowsPluginConfig} from \"../plugin/config-types.js\"\n\nexport const createWorkflowCollection: <T extends string>(options: WorkflowsPluginConfig<T>) => CollectionConfig = ({\n collectionTriggers,\n steps,\n triggers\n }) => ({\n slug: 'workflows',\n access: {\n create: () => true,\n delete: () => true,\n read: () => true,\n update: () => true,\n },\n admin: {\n defaultColumns: ['name', 'updatedAt'],\n description: 'Create and manage automated workflows.',\n group: 'Automation',\n useAsTitle: 'name',\n },\n fields: [\n {\n name: 'name',\n type: 'text',\n admin: {\n description: 'Human-readable name for the workflow',\n },\n required: true,\n },\n {\n name: 'description',\n type: 'textarea',\n admin: {\n description: 'Optional description of what this workflow does',\n },\n },\n {\n name: 'executionStatus',\n type: 'ui',\n admin: {\n components: {\n Field: '@/components/WorkflowExecutionStatus'\n },\n condition: (data) => !!data?.id // Only show for existing workflows\n }\n },\n {\n name: 'triggers',\n type: 'array',\n fields: [\n {\n name: 'type',\n type: 'select',\n options: [\n 'collection-trigger',\n 'webhook-trigger',\n 'global-trigger',\n 'cron-trigger',\n ...(triggers || []).map(t => t.slug)\n ]\n },\n {\n name: 'parameters',\n type: 'json',\n admin: {\n hidden: true,\n },\n defaultValue: {}\n },\n // Virtual fields for collection trigger\n {\n name: '__builtin_collectionSlug',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'collection-trigger',\n description: 'Collection that triggers the workflow',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.collectionSlug || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.collectionSlug = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n options: Object.keys(collectionTriggers || {}),\n virtual: true,\n },\n {\n name: '__builtin_operation',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'collection-trigger',\n description: 'Collection operation that triggers the workflow',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.operation || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.operation = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n options: [\n 'create',\n 'delete',\n 'read',\n 'update',\n ],\n virtual: true,\n },\n // Virtual fields for webhook trigger\n {\n name: '__builtin_webhookPath',\n type: 'text',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'webhook-trigger',\n description: 'URL path for the webhook (e.g., \"my-webhook\"). Full URL will be /api/workflows-webhook/my-webhook',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.webhookPath || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.webhookPath = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n validate: (value: any, {siblingData}: any) => {\n if (siblingData?.type === 'webhook-trigger' && !value && !siblingData?.parameters?.webhookPath) {\n return 'Webhook path is required for webhook triggers'\n }\n return true\n },\n virtual: true,\n },\n // Virtual fields for global trigger\n {\n name: '__builtin_global',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'global-trigger',\n description: 'Global that triggers the workflow',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.global || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.global = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n options: [], // Will be populated dynamically based on available globals\n virtual: true,\n },\n {\n name: '__builtin_globalOperation',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'global-trigger',\n description: 'Global operation that triggers the workflow',\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.globalOperation || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.globalOperation = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n options: [\n 'update'\n ],\n virtual: true,\n },\n // Virtual fields for cron trigger\n {\n name: '__builtin_cronExpression',\n type: 'text',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'cron-trigger',\n description: 'Cron expression for scheduled execution (e.g., \"0 0 * * *\" for daily at midnight)',\n placeholder: '0 0 * * *'\n },\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.cronExpression || undefined\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.cronExpression = value\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n validate: (value: any, {siblingData}: any) => {\n const cronValue = value || siblingData?.parameters?.cronExpression\n if (siblingData?.type === 'cron-trigger' && !cronValue) {\n return 'Cron expression is required for cron triggers'\n }\n\n // Validate cron expression format if provided\n if (siblingData?.type === 'cron-trigger' && cronValue) {\n // Basic format validation - should be 5 parts separated by spaces\n const cronParts = cronValue.trim().split(/\\s+/)\n if (cronParts.length !== 5) {\n return 'Invalid cron expression format. Expected 5 parts: \"minute hour day month weekday\" (e.g., \"0 9 * * 1\")'\n }\n\n // Additional validation could use node-cron but we avoid dynamic imports here\n // The main validation happens at runtime in the cron scheduler\n }\n\n return true\n },\n virtual: true,\n },\n {\n name: '__builtin_timezone',\n type: 'text',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'cron-trigger',\n description: 'Timezone for cron execution (e.g., \"America/New_York\", \"Europe/London\"). Defaults to UTC.',\n placeholder: 'UTC'\n },\n defaultValue: 'UTC',\n hooks: {\n afterRead: [\n ({ siblingData }) => {\n return siblingData?.parameters?.timezone || 'UTC'\n }\n ],\n beforeChange: [\n ({ siblingData, value }) => {\n if (!siblingData.parameters) {siblingData.parameters = {}}\n siblingData.parameters.timezone = value || 'UTC'\n return undefined // Virtual field, don't store directly\n }\n ]\n },\n validate: (value: any, {siblingData}: any) => {\n const tzValue = value || siblingData?.parameters?.timezone\n if (siblingData?.type === 'cron-trigger' && tzValue) {\n try {\n // Test if timezone is valid by trying to create a date with it\n new Intl.DateTimeFormat('en', {timeZone: tzValue})\n return true\n } catch {\n return `Invalid timezone: ${tzValue}. Please use a valid IANA timezone identifier (e.g., \"America/New_York\", \"Europe/London\")`\n }\n }\n return true\n },\n virtual: true,\n },\n {\n name: 'condition',\n type: 'text',\n admin: {\n description: 'JSONPath expression that must evaluate to true for this trigger to execute the workflow (e.g., \"$.trigger.doc.status == \\'published\\'\")'\n },\n required: false\n },\n // Virtual fields for custom triggers\n // Note: Custom trigger fields from trigger-helpers already have unique names\n // We just need to pass them through without modification\n ...(triggers || []).flatMap(t => (t.inputs || []))\n ]\n },\n {\n name: 'steps',\n type: 'array',\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'step',\n type: 'select',\n options: steps.map(t => t.slug)\n },\n {\n name: 'name',\n type: 'text',\n }\n ]\n },\n ...(steps || []).flatMap(step => (step.inputSchema || []).map(field => ({\n ...field,\n admin: {\n ...(field.admin || {}),\n condition: (...args) => args[1]?.step === step.slug && (\n field.admin?.condition ?\n field.admin.condition.call(this, ...args) :\n true\n ),\n },\n } as Field))),\n {\n name: 'dependencies',\n type: 'text',\n admin: {\n description: 'Step names that must complete before this step can run'\n },\n hasMany: true,\n required: false\n },\n {\n name: 'condition',\n type: 'text',\n admin: {\n description: 'JSONPath expression that must evaluate to true for this step to execute (e.g., \"$.trigger.doc.status == \\'published\\'\")'\n },\n required: false\n },\n ],\n }\n ],\n versions: {\n drafts: {\n autosave: false,\n },\n maxPerDoc: 10,\n },\n})\n"],"names":["createWorkflowCollection","collectionTriggers","steps","triggers","slug","access","create","delete","read","update","admin","defaultColumns","description","group","useAsTitle","fields","name","type","required","components","Field","condition","data","id","options","map","t","hidden","defaultValue","_","siblingData","hooks","afterRead","parameters","collectionSlug","undefined","beforeChange","value","Object","keys","virtual","operation","webhookPath","validate","global","globalOperation","placeholder","cronExpression","cronValue","cronParts","trim","split","length","timezone","tzValue","Intl","DateTimeFormat","timeZone","flatMap","inputs","step","inputSchema","field","args","call","hasMany","versions","drafts","autosave","maxPerDoc"],"mappings":"AAIA,OAAO,MAAMA,2BAAsG,CAAC,EACZC,kBAAkB,EAClBC,KAAK,EACLC,QAAQ,EACT,GAAM,CAAA;QAC3GC,MAAM;QACNC,QAAQ;YACNC,QAAQ,IAAM;YACdC,QAAQ,IAAM;YACdC,MAAM,IAAM;YACZC,QAAQ,IAAM;QAChB;QACAC,OAAO;YACLC,gBAAgB;gBAAC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ACT/C,UAAU;oBACZ;oBACA;wBACEF,MAAM;wBACNC,MAAM;wBACNP,OAAO;4BACLE,aAAa;wBACf;wBACAM,UAAU;oBACZ;iBACD;YACH;SACD;QACDgD,UAAU;YACRC,QAAQ;gBACNC,UAAU;YACZ;YACAC,WAAW;QACb;IACF,CAAA,EAAE"}
|
|
@@ -3,24 +3,23 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
5
|
* ```typescript
|
|
6
|
-
* import { createTrigger, webhookTrigger } from '@xtr-dev/payload-automation/helpers'
|
|
6
|
+
* import { createTrigger, createTriggerField, webhookTrigger } from '@xtr-dev/payload-automation/helpers'
|
|
7
7
|
*
|
|
8
|
-
* // Simple trigger
|
|
9
|
-
* const myTrigger = createTrigger('my-trigger'
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* // Simple trigger with array of fields
|
|
9
|
+
* const myTrigger = createTrigger('my-trigger', [
|
|
10
|
+
* { name: 'apiKey', type: 'text', required: true },
|
|
11
|
+
* { name: 'timeout', type: 'number', defaultValue: 30 }
|
|
12
|
+
* ])
|
|
13
13
|
*
|
|
14
|
-
* //
|
|
14
|
+
* // Single field with virtual storage
|
|
15
|
+
* const field = createTriggerField(
|
|
16
|
+
* { name: 'webhookUrl', type: 'text', required: true },
|
|
17
|
+
* 'my-trigger'
|
|
18
|
+
* )
|
|
19
|
+
*
|
|
20
|
+
* // Webhook trigger preset
|
|
15
21
|
* const orderWebhook = webhookTrigger('order-webhook')
|
|
16
|
-
* .parameter('orderTypes', {
|
|
17
|
-
* type: 'select',
|
|
18
|
-
* hasMany: true,
|
|
19
|
-
* options: ['regular', 'subscription']
|
|
20
|
-
* })
|
|
21
|
-
* .build()
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export {
|
|
24
|
+
export { createTriggerField, createTrigger } from '../utils/trigger-helpers.js';
|
|
25
25
|
export { webhookTrigger, cronTrigger, eventTrigger, manualTrigger, apiTrigger } from '../utils/trigger-presets.js';
|
|
26
|
-
export { webhookParameters, cronParameters, eventParameters } from '../utils/trigger-presets.js';
|
package/dist/exports/helpers.js
CHANGED
|
@@ -3,28 +3,26 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
5
|
* ```typescript
|
|
6
|
-
* import { createTrigger, webhookTrigger } from '@xtr-dev/payload-automation/helpers'
|
|
6
|
+
* import { createTrigger, createTriggerField, webhookTrigger } from '@xtr-dev/payload-automation/helpers'
|
|
7
7
|
*
|
|
8
|
-
* // Simple trigger
|
|
9
|
-
* const myTrigger = createTrigger('my-trigger'
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* // Simple trigger with array of fields
|
|
9
|
+
* const myTrigger = createTrigger('my-trigger', [
|
|
10
|
+
* { name: 'apiKey', type: 'text', required: true },
|
|
11
|
+
* { name: 'timeout', type: 'number', defaultValue: 30 }
|
|
12
|
+
* ])
|
|
13
13
|
*
|
|
14
|
-
* //
|
|
14
|
+
* // Single field with virtual storage
|
|
15
|
+
* const field = createTriggerField(
|
|
16
|
+
* { name: 'webhookUrl', type: 'text', required: true },
|
|
17
|
+
* 'my-trigger'
|
|
18
|
+
* )
|
|
19
|
+
*
|
|
20
|
+
* // Webhook trigger preset
|
|
15
21
|
* const orderWebhook = webhookTrigger('order-webhook')
|
|
16
|
-
* .parameter('orderTypes', {
|
|
17
|
-
* type: 'select',
|
|
18
|
-
* hasMany: true,
|
|
19
|
-
* options: ['regular', 'subscription']
|
|
20
|
-
* })
|
|
21
|
-
* .build()
|
|
22
22
|
* ```
|
|
23
23
|
*/ // Core helpers
|
|
24
|
-
export {
|
|
24
|
+
export { createTriggerField, createTrigger } from '../utils/trigger-helpers.js';
|
|
25
25
|
// Preset builders
|
|
26
26
|
export { webhookTrigger, cronTrigger, eventTrigger, manualTrigger, apiTrigger } from '../utils/trigger-presets.js';
|
|
27
|
-
// Common parameter sets for extending
|
|
28
|
-
export { webhookParameters, cronParameters, eventParameters } from '../utils/trigger-presets.js';
|
|
29
27
|
|
|
30
28
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/helpers.ts"],"sourcesContent":["/**\n * Trigger builder helpers for creating custom triggers with less boilerplate\n * \n * @example\n * ```typescript\n * import { createTrigger, webhookTrigger } from '@xtr-dev/payload-automation/helpers'\n * \n * // Simple trigger\n * const myTrigger = createTrigger('my-trigger'
|
|
1
|
+
{"version":3,"sources":["../../src/exports/helpers.ts"],"sourcesContent":["/**\n * Trigger builder helpers for creating custom triggers with less boilerplate\n * \n * @example\n * ```typescript\n * import { createTrigger, createTriggerField, webhookTrigger } from '@xtr-dev/payload-automation/helpers'\n * \n * // Simple trigger with array of fields\n * const myTrigger = createTrigger('my-trigger', [\n * { name: 'apiKey', type: 'text', required: true },\n * { name: 'timeout', type: 'number', defaultValue: 30 }\n * ])\n * \n * // Single field with virtual storage\n * const field = createTriggerField(\n * { name: 'webhookUrl', type: 'text', required: true },\n * 'my-trigger'\n * )\n * \n * // Webhook trigger preset\n * const orderWebhook = webhookTrigger('order-webhook')\n * ```\n */\n\n// Core helpers\nexport {\n createTriggerField,\n createTrigger\n} from '../utils/trigger-helpers.js'\n\n// Preset builders\nexport {\n webhookTrigger,\n cronTrigger,\n eventTrigger,\n manualTrigger,\n apiTrigger\n} from '../utils/trigger-presets.js'"],"names":["createTriggerField","createTrigger","webhookTrigger","cronTrigger","eventTrigger","manualTrigger","apiTrigger"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GAED,eAAe;AACf,SACEA,kBAAkB,EAClBC,aAAa,QACR,8BAA6B;AAEpC,kBAAkB;AAClB,SACEC,cAAc,EACdC,WAAW,EACXC,YAAY,EACZC,aAAa,EACbC,UAAU,QACL,8BAA6B"}
|
|
@@ -1,46 +1,55 @@
|
|
|
1
1
|
import type { Field } from 'payload';
|
|
2
2
|
import type { CustomTriggerConfig } from '../plugin/config-types.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Creates a virtual field for a trigger parameter that stores its value in the parameters JSON field
|
|
5
|
+
*
|
|
6
|
+
* @param field - Standard PayloadCMS field configuration (must be a data field with a name)
|
|
7
|
+
* @param triggerSlug - The slug of the trigger this field belongs to
|
|
8
|
+
* @returns Modified field with virtual storage hooks and proper naming
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const myTrigger: CustomTriggerConfig = {
|
|
13
|
+
* slug: 'my-trigger',
|
|
14
|
+
* inputs: [
|
|
15
|
+
* createTriggerField({
|
|
16
|
+
* name: 'webhookUrl',
|
|
17
|
+
* type: 'text',
|
|
18
|
+
* required: true,
|
|
19
|
+
* admin: {
|
|
20
|
+
* description: 'URL to call when triggered'
|
|
21
|
+
* }
|
|
22
|
+
* }, 'my-trigger')
|
|
23
|
+
* ]
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
6
26
|
*/
|
|
7
|
-
export declare function
|
|
8
|
-
triggerSlug: string): Field;
|
|
27
|
+
export declare function createTriggerField(field: any, triggerSlug: string): Field;
|
|
9
28
|
/**
|
|
10
|
-
*
|
|
29
|
+
* Creates a custom trigger configuration with the provided fields
|
|
30
|
+
*
|
|
31
|
+
* @param slug - Unique identifier for the trigger
|
|
32
|
+
* @param fields - Array of PayloadCMS fields that will be shown as trigger parameters
|
|
33
|
+
* @returns Complete trigger configuration
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const webhookTrigger = createTrigger('webhook', [
|
|
38
|
+
* {
|
|
39
|
+
* name: 'url',
|
|
40
|
+
* type: 'text',
|
|
41
|
+
* required: true,
|
|
42
|
+
* admin: {
|
|
43
|
+
* description: 'Webhook URL'
|
|
44
|
+
* }
|
|
45
|
+
* },
|
|
46
|
+
* {
|
|
47
|
+
* name: 'method',
|
|
48
|
+
* type: 'select',
|
|
49
|
+
* options: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
50
|
+
* defaultValue: 'POST'
|
|
51
|
+
* }
|
|
52
|
+
* ])
|
|
53
|
+
* ```
|
|
11
54
|
*/
|
|
12
|
-
export declare function
|
|
13
|
-
/**
|
|
14
|
-
* Main trigger builder function that creates a fluent API for defining triggers
|
|
15
|
-
*/
|
|
16
|
-
export declare function createTrigger<TSlug extends string>(slug: TSlug): {
|
|
17
|
-
/**
|
|
18
|
-
* Define parameters for this trigger using a clean object syntax
|
|
19
|
-
* @param paramConfig - Object where keys are parameter names and values are Field configs
|
|
20
|
-
* @returns Complete CustomTriggerConfig ready for use
|
|
21
|
-
*/
|
|
22
|
-
parameters(paramConfig: Record<string, any>): CustomTriggerConfig;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Advanced trigger builder with chainable methods for more complex scenarios
|
|
26
|
-
*/
|
|
27
|
-
export declare function createAdvancedTrigger<TSlug extends string>(slug: TSlug): {
|
|
28
|
-
slug: TSlug;
|
|
29
|
-
_parameters: Record<string, any>;
|
|
30
|
-
/**
|
|
31
|
-
* Set all parameters at once
|
|
32
|
-
*/
|
|
33
|
-
parameters(paramConfig: Record<string, any>): /*elided*/ any;
|
|
34
|
-
/**
|
|
35
|
-
* Add a single parameter
|
|
36
|
-
*/
|
|
37
|
-
parameter(name: string, fieldConfig: any): /*elided*/ any;
|
|
38
|
-
/**
|
|
39
|
-
* Extend with existing parameter sets (useful for common patterns)
|
|
40
|
-
*/
|
|
41
|
-
extend(baseParameters: Record<string, any>): /*elided*/ any;
|
|
42
|
-
/**
|
|
43
|
-
* Build the final trigger configuration
|
|
44
|
-
*/
|
|
45
|
-
build(): CustomTriggerConfig;
|
|
46
|
-
};
|
|
55
|
+
export declare function createTrigger(slug: string, fields: Field[]): CustomTriggerConfig;
|
|
@@ -1,102 +1,121 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
2
|
+
* Creates a virtual field for a trigger parameter that stores its value in the parameters JSON field
|
|
3
|
+
*
|
|
4
|
+
* @param field - Standard PayloadCMS field configuration (must be a data field with a name)
|
|
5
|
+
* @param triggerSlug - The slug of the trigger this field belongs to
|
|
6
|
+
* @returns Modified field with virtual storage hooks and proper naming
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const myTrigger: CustomTriggerConfig = {
|
|
11
|
+
* slug: 'my-trigger',
|
|
12
|
+
* inputs: [
|
|
13
|
+
* createTriggerField({
|
|
14
|
+
* name: 'webhookUrl',
|
|
15
|
+
* type: 'text',
|
|
16
|
+
* required: true,
|
|
17
|
+
* admin: {
|
|
18
|
+
* description: 'URL to call when triggered'
|
|
19
|
+
* }
|
|
20
|
+
* }, 'my-trigger')
|
|
21
|
+
* ]
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/ export function createTriggerField(field, triggerSlug) {
|
|
25
|
+
const originalName = field.name;
|
|
26
|
+
if (!originalName) {
|
|
27
|
+
throw new Error('Field must have a name property');
|
|
28
|
+
}
|
|
5
29
|
// Create a unique field name by prefixing with trigger slug
|
|
6
|
-
const uniqueFieldName = `__trigger_${triggerSlug}_${
|
|
7
|
-
|
|
8
|
-
...
|
|
30
|
+
const uniqueFieldName = `__trigger_${triggerSlug}_${originalName}`;
|
|
31
|
+
const resultField = {
|
|
32
|
+
...field,
|
|
9
33
|
name: uniqueFieldName,
|
|
10
34
|
virtual: true,
|
|
11
35
|
admin: {
|
|
12
|
-
...
|
|
13
|
-
condition: (
|
|
36
|
+
...field.admin || {},
|
|
37
|
+
condition: (data, siblingData)=>{
|
|
38
|
+
// Only show this field when the trigger type matches
|
|
39
|
+
const triggerMatches = siblingData?.type === triggerSlug;
|
|
40
|
+
// If the original field had a condition, combine it with our trigger condition
|
|
41
|
+
if (field.admin?.condition) {
|
|
42
|
+
return triggerMatches && field.admin.condition(data, siblingData);
|
|
43
|
+
}
|
|
44
|
+
return triggerMatches;
|
|
45
|
+
}
|
|
14
46
|
},
|
|
15
47
|
hooks: {
|
|
16
|
-
...
|
|
48
|
+
...field.hooks || {},
|
|
17
49
|
afterRead: [
|
|
18
|
-
...
|
|
19
|
-
({ siblingData })=>
|
|
50
|
+
...field.hooks?.afterRead || [],
|
|
51
|
+
({ siblingData })=>{
|
|
52
|
+
// Read the value from the parameters JSON field
|
|
53
|
+
return siblingData?.parameters?.[originalName] ?? field.defaultValue;
|
|
54
|
+
}
|
|
20
55
|
],
|
|
21
56
|
beforeChange: [
|
|
22
|
-
...
|
|
57
|
+
...field.hooks?.beforeChange || [],
|
|
23
58
|
({ value, siblingData })=>{
|
|
24
|
-
|
|
25
|
-
siblingData.parameters
|
|
59
|
+
// Store the value in the parameters JSON field
|
|
60
|
+
if (!siblingData.parameters) {
|
|
61
|
+
siblingData.parameters = {};
|
|
62
|
+
}
|
|
63
|
+
siblingData.parameters[originalName] = value;
|
|
26
64
|
return undefined // Virtual field, don't store directly
|
|
27
65
|
;
|
|
28
66
|
}
|
|
29
67
|
]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
// Only add validate if the field supports it (data fields)
|
|
71
|
+
if (field.validate || field.required) {
|
|
72
|
+
resultField.validate = (value, args)=>{
|
|
73
|
+
const paramValue = value ?? args.siblingData?.parameters?.[originalName];
|
|
74
|
+
// Check required validation
|
|
75
|
+
if (field.required && args.siblingData?.type === triggerSlug && !paramValue) {
|
|
76
|
+
const label = field.label || field.admin?.description || originalName;
|
|
77
|
+
return `${label} is required for ${triggerSlug}`;
|
|
36
78
|
}
|
|
37
79
|
// Run original validation if present
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return Object.entries(parameters).map(([name, fieldConfig])=>createTriggerParameter(name, fieldConfig, triggerSlug));
|
|
80
|
+
if (field.validate) {
|
|
81
|
+
return field.validate(paramValue, args);
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return resultField;
|
|
46
87
|
}
|
|
47
88
|
/**
|
|
48
|
-
*
|
|
49
|
-
|
|
89
|
+
* Creates a custom trigger configuration with the provided fields
|
|
90
|
+
*
|
|
91
|
+
* @param slug - Unique identifier for the trigger
|
|
92
|
+
* @param fields - Array of PayloadCMS fields that will be shown as trigger parameters
|
|
93
|
+
* @returns Complete trigger configuration
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const webhookTrigger = createTrigger('webhook', [
|
|
98
|
+
* {
|
|
99
|
+
* name: 'url',
|
|
100
|
+
* type: 'text',
|
|
101
|
+
* required: true,
|
|
102
|
+
* admin: {
|
|
103
|
+
* description: 'Webhook URL'
|
|
104
|
+
* }
|
|
105
|
+
* },
|
|
106
|
+
* {
|
|
107
|
+
* name: 'method',
|
|
108
|
+
* type: 'select',
|
|
109
|
+
* options: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
110
|
+
* defaultValue: 'POST'
|
|
111
|
+
* }
|
|
112
|
+
* ])
|
|
113
|
+
* ```
|
|
114
|
+
*/ export function createTrigger(slug, fields) {
|
|
50
115
|
return {
|
|
51
|
-
/**
|
|
52
|
-
* Define parameters for this trigger using a clean object syntax
|
|
53
|
-
* @param paramConfig - Object where keys are parameter names and values are Field configs
|
|
54
|
-
* @returns Complete CustomTriggerConfig ready for use
|
|
55
|
-
*/ parameters (paramConfig) {
|
|
56
|
-
return {
|
|
57
|
-
slug,
|
|
58
|
-
inputs: Object.entries(paramConfig).map(([name, fieldConfig])=>createTriggerParameter(name, fieldConfig, slug))
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Advanced trigger builder with chainable methods for more complex scenarios
|
|
65
|
-
*/ export function createAdvancedTrigger(slug) {
|
|
66
|
-
const builder = {
|
|
67
116
|
slug,
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Set all parameters at once
|
|
71
|
-
*/ parameters (paramConfig) {
|
|
72
|
-
this._parameters = paramConfig;
|
|
73
|
-
return this;
|
|
74
|
-
},
|
|
75
|
-
/**
|
|
76
|
-
* Add a single parameter
|
|
77
|
-
*/ parameter (name, fieldConfig) {
|
|
78
|
-
this._parameters[name] = fieldConfig;
|
|
79
|
-
return this;
|
|
80
|
-
},
|
|
81
|
-
/**
|
|
82
|
-
* Extend with existing parameter sets (useful for common patterns)
|
|
83
|
-
*/ extend (baseParameters) {
|
|
84
|
-
this._parameters = {
|
|
85
|
-
...baseParameters,
|
|
86
|
-
...this._parameters
|
|
87
|
-
};
|
|
88
|
-
return this;
|
|
89
|
-
},
|
|
90
|
-
/**
|
|
91
|
-
* Build the final trigger configuration
|
|
92
|
-
*/ build () {
|
|
93
|
-
return {
|
|
94
|
-
slug: this.slug,
|
|
95
|
-
inputs: Object.entries(this._parameters).map(([name, fieldConfig])=>createTriggerParameter(name, fieldConfig, this.slug))
|
|
96
|
-
};
|
|
97
|
-
}
|
|
117
|
+
inputs: fields.map((field)=>createTriggerField(field, slug))
|
|
98
118
|
};
|
|
99
|
-
return builder;
|
|
100
119
|
}
|
|
101
120
|
|
|
102
121
|
//# sourceMappingURL=trigger-helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/trigger-helpers.ts"],"sourcesContent":["import type { Field } from 'payload'\nimport type { CustomTriggerConfig } from '../plugin/config-types.js'\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../../src/utils/trigger-helpers.ts"],"sourcesContent":["import type { Field } from 'payload'\nimport type { CustomTriggerConfig } from '../plugin/config-types.js'\n\n/**\n * Creates a virtual field for a trigger parameter that stores its value in the parameters JSON field\n * \n * @param field - Standard PayloadCMS field configuration (must be a data field with a name)\n * @param triggerSlug - The slug of the trigger this field belongs to\n * @returns Modified field with virtual storage hooks and proper naming\n * \n * @example\n * ```typescript\n * const myTrigger: CustomTriggerConfig = {\n * slug: 'my-trigger',\n * inputs: [\n * createTriggerField({\n * name: 'webhookUrl',\n * type: 'text',\n * required: true,\n * admin: {\n * description: 'URL to call when triggered'\n * }\n * }, 'my-trigger')\n * ]\n * }\n * ```\n */\nexport function createTriggerField(field: any, triggerSlug: string): Field {\n const originalName = field.name\n if (!originalName) {\n throw new Error('Field must have a name property')\n }\n\n // Create a unique field name by prefixing with trigger slug\n const uniqueFieldName = `__trigger_${triggerSlug}_${originalName}`\n \n const resultField: any = {\n ...field,\n name: uniqueFieldName,\n virtual: true,\n admin: {\n ...(field.admin || {}),\n condition: (data: any, siblingData: any) => {\n // Only show this field when the trigger type matches\n const triggerMatches = siblingData?.type === triggerSlug\n \n // If the original field had a condition, combine it with our trigger condition\n if (field.admin?.condition) {\n return triggerMatches && field.admin.condition(data, siblingData)\n }\n \n return triggerMatches\n }\n },\n hooks: {\n ...(field.hooks || {}),\n afterRead: [\n ...(field.hooks?.afterRead || []),\n ({ siblingData }: any) => {\n // Read the value from the parameters JSON field\n return siblingData?.parameters?.[originalName] ?? field.defaultValue\n }\n ],\n beforeChange: [\n ...(field.hooks?.beforeChange || []),\n ({ value, siblingData }: any) => {\n // Store the value in the parameters JSON field\n if (!siblingData.parameters) {\n siblingData.parameters = {}\n }\n siblingData.parameters[originalName] = value\n return undefined // Virtual field, don't store directly\n }\n ]\n }\n }\n\n // Only add validate if the field supports it (data fields)\n if (field.validate || field.required) {\n resultField.validate = (value: any, args: any) => {\n const paramValue = value ?? args.siblingData?.parameters?.[originalName]\n \n // Check required validation\n if (field.required && args.siblingData?.type === triggerSlug && !paramValue) {\n const label = field.label || field.admin?.description || originalName\n return `${label} is required for ${triggerSlug}`\n }\n \n // Run original validation if present\n if (field.validate) {\n return field.validate(paramValue, args)\n }\n \n return true\n }\n }\n\n return resultField as Field\n}\n\n/**\n * Creates a custom trigger configuration with the provided fields\n * \n * @param slug - Unique identifier for the trigger\n * @param fields - Array of PayloadCMS fields that will be shown as trigger parameters\n * @returns Complete trigger configuration\n * \n * @example\n * ```typescript\n * const webhookTrigger = createTrigger('webhook', [\n * {\n * name: 'url',\n * type: 'text',\n * required: true,\n * admin: {\n * description: 'Webhook URL'\n * }\n * },\n * {\n * name: 'method',\n * type: 'select',\n * options: ['GET', 'POST', 'PUT', 'DELETE'],\n * defaultValue: 'POST'\n * }\n * ])\n * ```\n */\nexport function createTrigger(slug: string, fields: Field[]): CustomTriggerConfig {\n return {\n slug,\n inputs: fields.map(field => createTriggerField(field, slug))\n }\n}"],"names":["createTriggerField","field","triggerSlug","originalName","name","Error","uniqueFieldName","resultField","virtual","admin","condition","data","siblingData","triggerMatches","type","hooks","afterRead","parameters","defaultValue","beforeChange","value","undefined","validate","required","args","paramValue","label","description","createTrigger","slug","fields","inputs","map"],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASA,mBAAmBC,KAAU,EAAEC,WAAmB;IAChE,MAAMC,eAAeF,MAAMG,IAAI;IAC/B,IAAI,CAACD,cAAc;QACjB,MAAM,IAAIE,MAAM;IAClB;IAEA,4DAA4D;IAC5D,MAAMC,kBAAkB,CAAC,UAAU,EAAEJ,YAAY,CAAC,EAAEC,cAAc;IAElE,MAAMI,cAAmB;QACvB,GAAGN,KAAK;QACRG,MAAME;QACNE,SAAS;QACTC,OAAO;YACL,GAAIR,MAAMQ,KAAK,IAAI,CAAC,CAAC;YACrBC,WAAW,CAACC,MAAWC;gBACrB,qDAAqD;gBACrD,MAAMC,iBAAiBD,aAAaE,SAASZ;gBAE7C,+EAA+E;gBAC/E,IAAID,MAAMQ,KAAK,EAAEC,WAAW;oBAC1B,OAAOG,kBAAkBZ,MAAMQ,KAAK,CAACC,SAAS,CAACC,MAAMC;gBACvD;gBAEA,OAAOC;YACT;QACF;QACAE,OAAO;YACL,GAAId,MAAMc,KAAK,IAAI,CAAC,CAA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@
|
|
|
1
|
-
|
|
2
|
-
* Common parameter sets for reuse across different triggers
|
|
3
|
-
*/
|
|
4
|
-
export declare const webhookParameters: Record<string, any>;
|
|
5
|
-
export declare const cronParameters: Record<string, any>;
|
|
6
|
-
export declare const eventParameters: Record<string, any>;
|
|
1
|
+
import type { CustomTriggerConfig } from '../plugin/config-types.js';
|
|
7
2
|
/**
|
|
8
3
|
* Preset trigger builders for common patterns
|
|
9
4
|
*/
|
|
10
5
|
/**
|
|
11
6
|
* Create a webhook trigger with common webhook parameters pre-configured
|
|
12
7
|
*/
|
|
13
|
-
export declare function webhookTrigger
|
|
14
|
-
slug: TSlug;
|
|
15
|
-
_parameters: Record<string, any>;
|
|
16
|
-
parameters(paramConfig: Record<string, any>): /*elided*/ any;
|
|
17
|
-
parameter(name: string, fieldConfig: any): /*elided*/ any;
|
|
18
|
-
extend(baseParameters: Record<string, any>): /*elided*/ any;
|
|
19
|
-
build(): import("../plugin/config-types.js").CustomTriggerConfig;
|
|
20
|
-
};
|
|
8
|
+
export declare function webhookTrigger(slug: string): CustomTriggerConfig;
|
|
21
9
|
/**
|
|
22
10
|
* Create a scheduled/cron trigger with timing parameters pre-configured
|
|
23
11
|
*/
|
|
24
|
-
export declare function cronTrigger
|
|
25
|
-
slug: TSlug;
|
|
26
|
-
_parameters: Record<string, any>;
|
|
27
|
-
parameters(paramConfig: Record<string, any>): /*elided*/ any;
|
|
28
|
-
parameter(name: string, fieldConfig: any): /*elided*/ any;
|
|
29
|
-
extend(baseParameters: Record<string, any>): /*elided*/ any;
|
|
30
|
-
build(): import("../plugin/config-types.js").CustomTriggerConfig;
|
|
31
|
-
};
|
|
12
|
+
export declare function cronTrigger(slug: string): CustomTriggerConfig;
|
|
32
13
|
/**
|
|
33
14
|
* Create an event-driven trigger with event filtering parameters
|
|
34
15
|
*/
|
|
35
|
-
export declare function eventTrigger
|
|
36
|
-
slug: TSlug;
|
|
37
|
-
_parameters: Record<string, any>;
|
|
38
|
-
parameters(paramConfig: Record<string, any>): /*elided*/ any;
|
|
39
|
-
parameter(name: string, fieldConfig: any): /*elided*/ any;
|
|
40
|
-
extend(baseParameters: Record<string, any>): /*elided*/ any;
|
|
41
|
-
build(): import("../plugin/config-types.js").CustomTriggerConfig;
|
|
42
|
-
};
|
|
16
|
+
export declare function eventTrigger(slug: string): CustomTriggerConfig;
|
|
43
17
|
/**
|
|
44
18
|
* Create a simple manual trigger (no parameters needed)
|
|
45
19
|
*/
|
|
46
|
-
export declare function manualTrigger
|
|
47
|
-
slug: TSlug;
|
|
48
|
-
inputs: never[];
|
|
49
|
-
};
|
|
20
|
+
export declare function manualTrigger(slug: string): CustomTriggerConfig;
|
|
50
21
|
/**
|
|
51
22
|
* Create an API trigger for external systems to call
|
|
52
23
|
*/
|
|
53
|
-
export declare function apiTrigger
|
|
54
|
-
slug: TSlug;
|
|
55
|
-
_parameters: Record<string, any>;
|
|
56
|
-
parameters(paramConfig: Record<string, any>): /*elided*/ any;
|
|
57
|
-
parameter(name: string, fieldConfig: any): /*elided*/ any;
|
|
58
|
-
extend(baseParameters: Record<string, any>): /*elided*/ any;
|
|
59
|
-
build(): import("../plugin/config-types.js").CustomTriggerConfig;
|
|
60
|
-
};
|
|
24
|
+
export declare function apiTrigger(slug: string): CustomTriggerConfig;
|
|
@@ -1,113 +1,115 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createTrigger } from './trigger-helpers.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
* Preset trigger builders for common patterns
|
|
4
|
+
*/ /**
|
|
5
|
+
* Create a webhook trigger with common webhook parameters pre-configured
|
|
6
|
+
*/ export function webhookTrigger(slug) {
|
|
7
|
+
return createTrigger(slug, [
|
|
8
|
+
{
|
|
9
|
+
name: 'path',
|
|
10
|
+
type: 'text',
|
|
11
|
+
required: true,
|
|
12
|
+
admin: {
|
|
13
|
+
description: 'URL path for the webhook endpoint (e.g., "my-webhook")'
|
|
14
|
+
},
|
|
15
|
+
validate: (value)=>{
|
|
16
|
+
if (typeof value === 'string' && value.includes(' ')) {
|
|
17
|
+
return 'Webhook path cannot contain spaces';
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
14
20
|
}
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
secret: {
|
|
19
|
-
type: 'text',
|
|
20
|
-
admin: {
|
|
21
|
-
description: 'Secret key for webhook signature validation (optional but recommended)'
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
headers: {
|
|
25
|
-
type: 'json',
|
|
26
|
-
admin: {
|
|
27
|
-
description: 'Expected HTTP headers for validation (JSON object)'
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
export const cronParameters = {
|
|
32
|
-
expression: {
|
|
33
|
-
type: 'text',
|
|
34
|
-
required: true,
|
|
35
|
-
admin: {
|
|
36
|
-
description: 'Cron expression for scheduling (e.g., "0 9 * * 1" for every Monday at 9 AM)',
|
|
37
|
-
placeholder: '0 9 * * 1'
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
timezone: {
|
|
41
|
-
type: 'text',
|
|
42
|
-
defaultValue: 'UTC',
|
|
43
|
-
admin: {
|
|
44
|
-
description: 'Timezone for cron execution (e.g., "America/New_York", "Europe/London")',
|
|
45
|
-
placeholder: 'UTC'
|
|
46
21
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
return true;
|
|
54
|
-
} catch {
|
|
55
|
-
return `Invalid timezone: ${value}. Please use a valid IANA timezone identifier`;
|
|
56
|
-
}
|
|
22
|
+
{
|
|
23
|
+
name: 'secret',
|
|
24
|
+
type: 'text',
|
|
25
|
+
admin: {
|
|
26
|
+
description: 'Secret key for webhook signature validation (optional but recommended)'
|
|
57
27
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
type: 'select',
|
|
65
|
-
hasMany: true,
|
|
66
|
-
options: [
|
|
67
|
-
{
|
|
68
|
-
label: 'User Created',
|
|
69
|
-
value: 'user.created'
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
label: 'User Updated',
|
|
73
|
-
value: 'user.updated'
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
label: 'Document Published',
|
|
77
|
-
value: 'document.published'
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
label: 'Payment Completed',
|
|
81
|
-
value: 'payment.completed'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'headers',
|
|
31
|
+
type: 'json',
|
|
32
|
+
admin: {
|
|
33
|
+
description: 'Expected HTTP headers for validation (JSON object)'
|
|
82
34
|
}
|
|
83
|
-
],
|
|
84
|
-
admin: {
|
|
85
|
-
description: 'Event types that should trigger this workflow'
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
filters: {
|
|
89
|
-
type: 'json',
|
|
90
|
-
admin: {
|
|
91
|
-
description: 'JSON filters to apply to event data (e.g., {"status": "active"})'
|
|
92
35
|
}
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Preset trigger builders for common patterns
|
|
97
|
-
*/ /**
|
|
98
|
-
* Create a webhook trigger with common webhook parameters pre-configured
|
|
99
|
-
*/ export function webhookTrigger(slug) {
|
|
100
|
-
return createAdvancedTrigger(slug).extend(webhookParameters);
|
|
36
|
+
]);
|
|
101
37
|
}
|
|
102
38
|
/**
|
|
103
39
|
* Create a scheduled/cron trigger with timing parameters pre-configured
|
|
104
40
|
*/ export function cronTrigger(slug) {
|
|
105
|
-
return
|
|
41
|
+
return createTrigger(slug, [
|
|
42
|
+
{
|
|
43
|
+
name: 'expression',
|
|
44
|
+
type: 'text',
|
|
45
|
+
required: true,
|
|
46
|
+
admin: {
|
|
47
|
+
description: 'Cron expression for scheduling (e.g., "0 9 * * 1" for every Monday at 9 AM)',
|
|
48
|
+
placeholder: '0 9 * * 1'
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'timezone',
|
|
53
|
+
type: 'text',
|
|
54
|
+
defaultValue: 'UTC',
|
|
55
|
+
admin: {
|
|
56
|
+
description: 'Timezone for cron execution (e.g., "America/New_York", "Europe/London")',
|
|
57
|
+
placeholder: 'UTC'
|
|
58
|
+
},
|
|
59
|
+
validate: (value)=>{
|
|
60
|
+
if (value) {
|
|
61
|
+
try {
|
|
62
|
+
new Intl.DateTimeFormat('en', {
|
|
63
|
+
timeZone: value
|
|
64
|
+
});
|
|
65
|
+
return true;
|
|
66
|
+
} catch {
|
|
67
|
+
return `Invalid timezone: ${value}. Please use a valid IANA timezone identifier`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
]);
|
|
106
74
|
}
|
|
107
75
|
/**
|
|
108
76
|
* Create an event-driven trigger with event filtering parameters
|
|
109
77
|
*/ export function eventTrigger(slug) {
|
|
110
|
-
return
|
|
78
|
+
return createTrigger(slug, [
|
|
79
|
+
{
|
|
80
|
+
name: 'eventTypes',
|
|
81
|
+
type: 'select',
|
|
82
|
+
hasMany: true,
|
|
83
|
+
options: [
|
|
84
|
+
{
|
|
85
|
+
label: 'User Created',
|
|
86
|
+
value: 'user.created'
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
label: 'User Updated',
|
|
90
|
+
value: 'user.updated'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
label: 'Document Published',
|
|
94
|
+
value: 'document.published'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: 'Payment Completed',
|
|
98
|
+
value: 'payment.completed'
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
admin: {
|
|
102
|
+
description: 'Event types that should trigger this workflow'
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'filters',
|
|
107
|
+
type: 'json',
|
|
108
|
+
admin: {
|
|
109
|
+
description: 'JSON filters to apply to event data (e.g., {"status": "active"})'
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
]);
|
|
111
113
|
}
|
|
112
114
|
/**
|
|
113
115
|
* Create a simple manual trigger (no parameters needed)
|
|
@@ -120,15 +122,17 @@ export const eventParameters = {
|
|
|
120
122
|
/**
|
|
121
123
|
* Create an API trigger for external systems to call
|
|
122
124
|
*/ export function apiTrigger(slug) {
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
+
return createTrigger(slug, [
|
|
126
|
+
{
|
|
127
|
+
name: 'endpoint',
|
|
125
128
|
type: 'text',
|
|
126
129
|
required: true,
|
|
127
130
|
admin: {
|
|
128
131
|
description: 'API endpoint path (e.g., "/api/triggers/my-trigger")'
|
|
129
132
|
}
|
|
130
133
|
},
|
|
131
|
-
|
|
134
|
+
{
|
|
135
|
+
name: 'method',
|
|
132
136
|
type: 'select',
|
|
133
137
|
options: [
|
|
134
138
|
'GET',
|
|
@@ -141,7 +145,8 @@ export const eventParameters = {
|
|
|
141
145
|
description: 'HTTP method for the API endpoint'
|
|
142
146
|
}
|
|
143
147
|
},
|
|
144
|
-
|
|
148
|
+
{
|
|
149
|
+
name: 'authentication',
|
|
145
150
|
type: 'select',
|
|
146
151
|
options: [
|
|
147
152
|
{
|
|
@@ -166,7 +171,7 @@ export const eventParameters = {
|
|
|
166
171
|
description: 'Authentication method for the API endpoint'
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
|
-
|
|
174
|
+
]);
|
|
170
175
|
}
|
|
171
176
|
|
|
172
177
|
//# sourceMappingURL=trigger-presets.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/trigger-presets.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/trigger-presets.ts"],"sourcesContent":["import { createTrigger } from './trigger-helpers.js'\nimport type { CustomTriggerConfig } from '../plugin/config-types.js'\n\n/**\n * Preset trigger builders for common patterns\n */\n\n/**\n * Create a webhook trigger with common webhook parameters pre-configured\n */\nexport function webhookTrigger(slug: string): CustomTriggerConfig {\n return createTrigger(slug, [\n {\n name: 'path',\n type: 'text',\n required: true,\n admin: {\n description: 'URL path for the webhook endpoint (e.g., \"my-webhook\")'\n },\n validate: (value: any) => {\n if (typeof value === 'string' && value.includes(' ')) {\n return 'Webhook path cannot contain spaces'\n }\n return true\n }\n },\n {\n name: 'secret',\n type: 'text',\n admin: {\n description: 'Secret key for webhook signature validation (optional but recommended)'\n }\n },\n {\n name: 'headers',\n type: 'json',\n admin: {\n description: 'Expected HTTP headers for validation (JSON object)'\n }\n }\n ])\n}\n\n/**\n * Create a scheduled/cron trigger with timing parameters pre-configured\n */\nexport function cronTrigger(slug: string): CustomTriggerConfig {\n return createTrigger(slug, [\n {\n name: 'expression',\n type: 'text',\n required: true,\n admin: {\n description: 'Cron expression for scheduling (e.g., \"0 9 * * 1\" for every Monday at 9 AM)',\n placeholder: '0 9 * * 1'\n }\n },\n {\n name: 'timezone',\n type: 'text',\n defaultValue: 'UTC',\n admin: {\n description: 'Timezone for cron execution (e.g., \"America/New_York\", \"Europe/London\")',\n placeholder: 'UTC'\n },\n validate: (value: any) => {\n if (value) {\n try {\n new Intl.DateTimeFormat('en', { timeZone: value as string })\n return true\n } catch {\n return `Invalid timezone: ${value}. Please use a valid IANA timezone identifier`\n }\n }\n return true\n }\n }\n ])\n}\n\n/**\n * Create an event-driven trigger with event filtering parameters\n */\nexport function eventTrigger(slug: string): CustomTriggerConfig {\n return createTrigger(slug, [\n {\n name: 'eventTypes',\n type: 'select',\n hasMany: true,\n options: [\n { label: 'User Created', value: 'user.created' },\n { label: 'User Updated', value: 'user.updated' },\n { label: 'Document Published', value: 'document.published' },\n { label: 'Payment Completed', value: 'payment.completed' }\n ],\n admin: {\n description: 'Event types that should trigger this workflow'\n }\n },\n {\n name: 'filters',\n type: 'json',\n admin: {\n description: 'JSON filters to apply to event data (e.g., {\"status\": \"active\"})'\n }\n }\n ])\n}\n\n/**\n * Create a simple manual trigger (no parameters needed)\n */\nexport function manualTrigger(slug: string): CustomTriggerConfig {\n return {\n slug,\n inputs: []\n }\n}\n\n/**\n * Create an API trigger for external systems to call\n */\nexport function apiTrigger(slug: string): CustomTriggerConfig {\n return createTrigger(slug, [\n {\n name: 'endpoint',\n type: 'text',\n required: true,\n admin: {\n description: 'API endpoint path (e.g., \"/api/triggers/my-trigger\")'\n }\n },\n {\n name: 'method',\n type: 'select',\n options: ['GET', 'POST', 'PUT', 'PATCH'],\n defaultValue: 'POST',\n admin: {\n description: 'HTTP method for the API endpoint'\n }\n },\n {\n name: 'authentication',\n type: 'select',\n options: [\n { label: 'None', value: 'none' },\n { label: 'API Key', value: 'api-key' },\n { label: 'Bearer Token', value: 'bearer' },\n { label: 'Basic Auth', value: 'basic' }\n ],\n defaultValue: 'api-key',\n admin: {\n description: 'Authentication method for the API endpoint'\n }\n }\n ])\n}"],"names":["createTrigger","webhookTrigger","slug","name","type","required","admin","description","validate","value","includes","cronTrigger","placeholder","defaultValue","Intl","DateTimeFormat","timeZone","eventTrigger","hasMany","options","label","manualTrigger","inputs","apiTrigger"],"mappings":"AAAA,SAASA,aAAa,QAAQ,uBAAsB;AAGpD;;CAEC,GAED;;CAEC,GACD,OAAO,SAASC,eAAeC,IAAY;IACzC,OAAOF,cAAcE,MAAM;QACzB;YACEC,MAAM;YACNC,MAAM;YACNC,UAAU;YACVC,OAAO;gBACLC,aAAa;YACf;YACAC,UAAU,CAACC;gBACT,IAAI,OAAOA,UAAU,YAAYA,MAAMC,QAAQ,CAAC,MAAM;oBACpD,OAAO;gBACT;gBACA,OAAO;YACT;QACF;QACA;YACEP,MAAM;YACNC,MAAM;YACNE,OAAO;gBACL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AAa;YACf;QACF;QACA;YACEJ,MAAM;YACNC,MAAM;YACNe,SAAS;gBAAC;gBAAO;gBAAQ;gBAAO;aAAQ;YACxCN,cAAc;YACdP,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEJ,MAAM;YACNC,MAAM;YACNe,SAAS;gBACP;oBAAEC,OAAO;oBAAQX,OAAO;gBAAO;gBAC/B;oBAAEW,OAAO;oBAAWX,OAAO;gBAAU;gBACrC;oBAAEW,OAAO;oBAAgBX,OAAO;gBAAS;gBACzC;oBAAEW,OAAO;oBAAcX,OAAO;gBAAQ;aACvC;YACDI,cAAc;YACdP,OAAO;gBACLC,aAAa;YACf;QACF;KACD;AACH"}
|
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.28",
|
|
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",
|