@xtr-dev/payload-automation 0.0.7 → 0.0.8
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 +1 -1
- package/dist/collections/Workflow.js.map +1 -1
- package/dist/plugin/init-collection-hooks.js +3 -3
- package/dist/plugin/init-collection-hooks.js.map +1 -1
- package/dist/plugin/logger.js +0 -4
- package/dist/plugin/logger.js.map +1 -1
- package/dist/steps/create-document-handler.js +3 -3
- package/dist/steps/create-document-handler.js.map +1 -1
- package/dist/steps/create-document.js +1 -1
- package/dist/steps/create-document.js.map +1 -1
- package/dist/steps/delete-document-handler.js +5 -5
- package/dist/steps/delete-document-handler.js.map +1 -1
- package/dist/steps/delete-document.js +1 -1
- package/dist/steps/delete-document.js.map +1 -1
- package/dist/steps/read-document-handler.js +4 -4
- package/dist/steps/read-document-handler.js.map +1 -1
- package/dist/steps/read-document.js +1 -1
- package/dist/steps/read-document.js.map +1 -1
- package/dist/steps/update-document-handler.js +3 -3
- package/dist/steps/update-document-handler.js.map +1 -1
- package/dist/steps/update-document.js +1 -1
- package/dist/steps/update-document.js.map +1 -1
- package/package.json +1 -1
|
@@ -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: '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: 'collection',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'collection-trigger',\n description: 'Collection that triggers the workflow',\n },\n options: Object.keys(collectionTriggers || {})\n },\n {\n name: 'operation',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'collection-trigger',\n description: 'Collection operation that triggers the workflow',\n },\n options: [\n 'create',\n 'delete',\n 'read',\n 'update',\n ]\n },\n {\n name: '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 validate: (value: any, {siblingData}: any) => {\n if (siblingData?.type === 'webhook-trigger' && !value) {\n return 'Webhook path is required for webhook triggers'\n }\n return true\n }\n },\n {\n name: 'global',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'global-trigger',\n description: 'Global that triggers the workflow',\n },\n options: [] // Will be populated dynamically based on available globals\n },\n {\n name: 'globalOperation',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'global-trigger',\n description: 'Global operation that triggers the workflow',\n },\n options: [\n 'update'\n ]\n },\n {\n name: '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 validate: (value: any, {siblingData}: any) => {\n if (siblingData?.type === 'cron-trigger' && !value) {\n return 'Cron expression is required for cron triggers'\n }\n\n // Validate cron expression format if provided\n if (siblingData?.type === 'cron-trigger' && value) {\n // Basic format validation - should be 5 parts separated by spaces\n const cronParts = value.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 },\n {\n name: '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 validate: (value: any, {siblingData}: any) => {\n if (siblingData?.type === 'cron-trigger' && value) {\n try {\n // Test if timezone is valid by trying to create a date with it\n new Intl.DateTimeFormat('en', {timeZone: value})\n return true\n } catch {\n return `Invalid timezone: ${value}. Please use a valid IANA timezone identifier (e.g., \"America/New_York\", \"Europe/London\")`\n }\n }\n return true\n }\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., \"$.doc.status == \\'published\\'\")'\n },\n required: false\n },\n ...(triggers || []).flatMap(t => (t.inputs || []).map(f => ({\n ...f,\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 } 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 {\n name: 'input',\n type: 'json',\n required: false\n },\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","options","map","t","condition","_","siblingData","Object","keys","validate","value","placeholder","cronParts","trim","split","length","defaultValue","Intl","DateTimeFormat","timeZone","flatMap","inputs","f","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;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;gBACNF,QAAQ;oBACN;wBACEC,MAAM;wBACNC,MAAM;wBACNE,SAAS;4BACP;4BACA;4BACA;4BACA;+BACG,AAAChB,CAAAA,YAAY,EAAE,AAAD,EAAGiB,GAAG,CAACC,CAAAA,IAAKA,EAAEjB,IAAI;yBACpC;oBACH;oBACA;wBACEY,MAAM;wBACNC,MAAM;wBACNP,OAAO;4BACLY,WAAW,CAACC,GAAGC,cAAgBA,aAAaP,SAAS;4BACrDL,aAAa;wBACf;wBACAO,SAASM,OAAOC,IAAI,CAACzB,sBAAsB,CAAC;oBAC9C;oBACA;wBACEe,MAAM;wBACNC,MAAM;wBACNP,OAAO;4BACLY,WAAW,CAACC,GAAGC,cAAgBA,aAAaP,SAAS;4BACrDL,aAAa;wBACf;wBACAO,SAAS;4BAC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BACZ;oBACA;wBACEF,MAAM;wBACNC,MAAM;wBACNP,OAAO;4BACLE,aAAa;wBACf;wBACAM,UAAU;oBACZ;iBACD;YACH;SACD;QACD0B,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: '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: 'collectionSlug',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'collection-trigger',\n description: 'Collection that triggers the workflow',\n },\n options: Object.keys(collectionTriggers || {})\n },\n {\n name: 'operation',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'collection-trigger',\n description: 'Collection operation that triggers the workflow',\n },\n options: [\n 'create',\n 'delete',\n 'read',\n 'update',\n ]\n },\n {\n name: '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 validate: (value: any, {siblingData}: any) => {\n if (siblingData?.type === 'webhook-trigger' && !value) {\n return 'Webhook path is required for webhook triggers'\n }\n return true\n }\n },\n {\n name: 'global',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'global-trigger',\n description: 'Global that triggers the workflow',\n },\n options: [] // Will be populated dynamically based on available globals\n },\n {\n name: 'globalOperation',\n type: 'select',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'global-trigger',\n description: 'Global operation that triggers the workflow',\n },\n options: [\n 'update'\n ]\n },\n {\n name: '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 validate: (value: any, {siblingData}: any) => {\n if (siblingData?.type === 'cron-trigger' && !value) {\n return 'Cron expression is required for cron triggers'\n }\n\n // Validate cron expression format if provided\n if (siblingData?.type === 'cron-trigger' && value) {\n // Basic format validation - should be 5 parts separated by spaces\n const cronParts = value.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 },\n {\n name: '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 validate: (value: any, {siblingData}: any) => {\n if (siblingData?.type === 'cron-trigger' && value) {\n try {\n // Test if timezone is valid by trying to create a date with it\n new Intl.DateTimeFormat('en', {timeZone: value})\n return true\n } catch {\n return `Invalid timezone: ${value}. Please use a valid IANA timezone identifier (e.g., \"America/New_York\", \"Europe/London\")`\n }\n }\n return true\n }\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., \"$.doc.status == \\'published\\'\")'\n },\n required: false\n },\n ...(triggers || []).flatMap(t => (t.inputs || []).map(f => ({\n ...f,\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 } 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 {\n name: 'input',\n type: 'json',\n required: false\n },\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","options","map","t","condition","_","siblingData","Object","keys","validate","value","placeholder","cronParts","trim","split","length","defaultValue","Intl","DateTimeFormat","timeZone","flatMap","inputs","f","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;gBAAQ;aAAY;YACrCC,aAAa;YACbC,OAAO;YACPC,YAAY;QACd;QACAC,QAAQ;Y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CACJ9B,OAAO;oCACL,GAAI8B,EAAE9B,KAAK,IAAI,CAAC,CAAC;oCACjBY,WAAW,CAAC,GAAGmB,OAASA,IAAI,CAAC,EAAE,EAAExB,SAASI,EAAEjB,IAAI,IAC9CoC,CAAAA,EAAE9B,KAAK,EAAEY,YACPkB,EAAE9B,KAAK,CAACY,SAAS,CAACoB,IAAI,CAAC,IAAI,KAAKD,QAChC,IAAG;gCAET;4BACF,CAAA;iBACD;YACH;YACA;gBACEzB,MAAM;gBACNC,MAAM;gBACNF,QAAQ;oBACN;wBACEE,MAAM;wBACNF,QAAQ;4BACN;gCACEC,MAAM;gCACNC,MAAM;gCACNE,SAASjB,MAAMkB,GAAG,CAACC,CAAAA,IAAKA,EAAEjB,IAAI;4BAChC;4BACA;gCACEY,MAAM;gCACNC,MAAM;4BACR;yBACD;oBACH;oBACA;wBACED,MAAM;wBACNC,MAAM;wBACNC,UAAU;oBACZ;oBACA;wBACEF,MAAM;wBACNC,MAAM;wBACNP,OAAO;4BACLE,aAAa;wBACf;wBACA+B,SAAS;wBACTzB,UAAU;oBACZ;oBACA;wBACEF,MAAM;wBACNC,MAAM;wBACNP,OAAO;4BACLE,aAAa;wBACf;wBACAM,UAAU;oBACZ;iBACD;YACH;SACD;QACD0B,UAAU;YACRC,QAAQ;gBACNC,UAAU;YACZ;YACAC,WAAW;QACb;IACF,CAAA,EAAE"}
|
|
@@ -30,7 +30,7 @@ export function initCollectionHooks(pluginOptions, payload, logger, executor) {
|
|
|
30
30
|
collection.config.hooks.afterChange.push(async (change)=>{
|
|
31
31
|
const operation = change.operation;
|
|
32
32
|
logger.debug({
|
|
33
|
-
|
|
33
|
+
slug: change.collection.slug,
|
|
34
34
|
operation
|
|
35
35
|
}, 'Collection hook triggered');
|
|
36
36
|
// Execute workflows for this trigger
|
|
@@ -41,7 +41,7 @@ export function initCollectionHooks(pluginOptions, payload, logger, executor) {
|
|
|
41
41
|
collection.config.hooks.afterRead = collection.config.hooks.afterRead || [];
|
|
42
42
|
collection.config.hooks.afterRead.push(async (change)=>{
|
|
43
43
|
logger.debug({
|
|
44
|
-
|
|
44
|
+
slug: change.collection.slug,
|
|
45
45
|
operation: 'read'
|
|
46
46
|
}, 'Collection hook triggered');
|
|
47
47
|
// Execute workflows for this trigger
|
|
@@ -52,7 +52,7 @@ export function initCollectionHooks(pluginOptions, payload, logger, executor) {
|
|
|
52
52
|
collection.config.hooks.afterDelete = collection.config.hooks.afterDelete || [];
|
|
53
53
|
collection.config.hooks.afterDelete.push(async (change)=>{
|
|
54
54
|
logger.debug({
|
|
55
|
-
|
|
55
|
+
slug: change.collection.slug,
|
|
56
56
|
operation: 'delete'
|
|
57
57
|
}, 'Collection hook triggered');
|
|
58
58
|
// Execute workflows for this trigger
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin/init-collection-hooks.ts"],"sourcesContent":["import type {Payload} from \"payload\"\nimport type {Logger} from \"pino\"\n\nimport type { WorkflowExecutor } from \"../core/workflow-executor.js\"\nimport type {CollectionTriggerConfigCrud, WorkflowsPluginConfig} from \"./config-types.js\"\n\nexport function initCollectionHooks<T extends string>(pluginOptions: WorkflowsPluginConfig<T>, payload: Payload, logger: Payload['logger'], executor: WorkflowExecutor) {\n \n if (!pluginOptions.collectionTriggers || Object.keys(pluginOptions.collectionTriggers).length === 0) {\n logger.warn('No collection triggers configured in plugin options')\n return\n }\n\n logger.info({\n configuredCollections: Object.keys(pluginOptions.collectionTriggers),\n availableCollections: Object.keys(payload.collections)\n }, 'Starting collection hook registration')\n\n // Add hooks to configured collections\n for (const [collectionSlug, triggerConfig] of Object.entries(pluginOptions.collectionTriggers)) {\n if (!triggerConfig) {\n logger.debug({collectionSlug}, 'Skipping collection with falsy trigger config')\n continue\n }\n\n const collection = payload.collections[collectionSlug as T]\n const crud: CollectionTriggerConfigCrud = triggerConfig === true ? {\n create: true,\n delete: true,\n read: true,\n update: true,\n } : triggerConfig\n\n if (!collection.config.hooks) {\n collection.config.hooks = {} as typeof collection.config.hooks\n }\n\n if (crud.update || crud.create) {\n collection.config.hooks.afterChange = collection.config.hooks.afterChange || []\n collection.config.hooks.afterChange.push(async (change) => {\n const operation = change.operation as 'create' | 'update'\n logger.debug({\n
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/init-collection-hooks.ts"],"sourcesContent":["import type {Payload} from \"payload\"\nimport type {Logger} from \"pino\"\n\nimport type { WorkflowExecutor } from \"../core/workflow-executor.js\"\nimport type {CollectionTriggerConfigCrud, WorkflowsPluginConfig} from \"./config-types.js\"\n\nexport function initCollectionHooks<T extends string>(pluginOptions: WorkflowsPluginConfig<T>, payload: Payload, logger: Payload['logger'], executor: WorkflowExecutor) {\n \n if (!pluginOptions.collectionTriggers || Object.keys(pluginOptions.collectionTriggers).length === 0) {\n logger.warn('No collection triggers configured in plugin options')\n return\n }\n\n logger.info({\n configuredCollections: Object.keys(pluginOptions.collectionTriggers),\n availableCollections: Object.keys(payload.collections)\n }, 'Starting collection hook registration')\n\n // Add hooks to configured collections\n for (const [collectionSlug, triggerConfig] of Object.entries(pluginOptions.collectionTriggers)) {\n if (!triggerConfig) {\n logger.debug({collectionSlug}, 'Skipping collection with falsy trigger config')\n continue\n }\n\n const collection = payload.collections[collectionSlug as T]\n const crud: CollectionTriggerConfigCrud = triggerConfig === true ? {\n create: true,\n delete: true,\n read: true,\n update: true,\n } : triggerConfig\n\n if (!collection.config.hooks) {\n collection.config.hooks = {} as typeof collection.config.hooks\n }\n\n if (crud.update || crud.create) {\n collection.config.hooks.afterChange = collection.config.hooks.afterChange || []\n collection.config.hooks.afterChange.push(async (change) => {\n const operation = change.operation as 'create' | 'update'\n logger.debug({\n slug: change.collection.slug,\n operation,\n }, 'Collection hook triggered')\n\n // Execute workflows for this trigger\n await executor.executeTriggeredWorkflows(\n change.collection.slug,\n operation,\n change.doc,\n change.previousDoc,\n change.req\n )\n })\n }\n\n if (crud.read) {\n collection.config.hooks.afterRead = collection.config.hooks.afterRead || []\n collection.config.hooks.afterRead.push(async (change) => {\n logger.debug({\n slug: change.collection.slug,\n operation: 'read',\n }, 'Collection hook triggered')\n\n // Execute workflows for this trigger\n await executor.executeTriggeredWorkflows(\n change.collection.slug,\n 'read',\n change.doc,\n undefined,\n change.req\n )\n })\n }\n\n if (crud.delete) {\n collection.config.hooks.afterDelete = collection.config.hooks.afterDelete || []\n collection.config.hooks.afterDelete.push(async (change) => {\n logger.debug({\n slug: change.collection.slug,\n operation: 'delete',\n }, 'Collection hook triggered')\n\n // Execute workflows for this trigger\n await executor.executeTriggeredWorkflows(\n change.collection.slug,\n 'delete',\n change.doc,\n undefined,\n change.req\n )\n })\n }\n\n if (collection) {\n logger.info({\n collectionSlug,\n hooksRegistered: {\n afterChange: crud.update || crud.create,\n afterRead: crud.read,\n afterDelete: crud.delete\n }\n }, 'Collection hooks registered successfully')\n } else {\n logger.error({\n collectionSlug,\n availableCollections: Object.keys(payload.collections)\n }, 'Collection not found for trigger configuration - check collection slug spelling')\n }\n }\n}\n"],"names":["initCollectionHooks","pluginOptions","payload","logger","executor","collectionTriggers","Object","keys","length","warn","info","configuredCollections","availableCollections","collections","collectionSlug","triggerConfig","entries","debug","collection","crud","create","delete","read","update","config","hooks","afterChange","push","change","operation","slug","executeTriggeredWorkflows","doc","previousDoc","req","afterRead","undefined","afterDelete","hooksRegistered","error"],"mappings":"AAMA,OAAO,SAASA,oBAAsCC,aAAuC,EAAEC,OAAgB,EAAEC,MAAyB,EAAEC,QAA0B;IAEpK,IAAI,CAACH,cAAcI,kBAAkB,IAAIC,OAAOC,IAAI,CAACN,cAAcI,kBAAkB,EAAEG,MAAM,KAAK,GAAG;QACnGL,OAAOM,IAAI,CAAC;QACZ;IACF;IAEAN,OAAOO,IAAI,CAAC;QACVC,uBAAuBL,OAAOC,IAAI,CAACN,cAAcI,kBAAkB;QACnEO,sBAAsBN,OAAOC,IAAI,CAACL,QAAQW,WAAW;IACvD,GAAG;IAEH,sCAAsC;IACtC,KAAK,MAAM,CAACC,gB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gBACrC,MAAMzB,SAAS2B,yBAAyB,CACtCH,OAAOV,UAAU,CAACY,IAAI,EACtB,QACAF,OAAOI,GAAG,EACVI,WACAR,OAAOM,GAAG;YAEd;QACF;QAEA,IAAIf,KAAKE,MAAM,EAAE;YACfH,WAAWM,MAAM,CAACC,KAAK,CAACY,WAAW,GAAGnB,WAAWM,MAAM,CAACC,KAAK,CAACY,WAAW,IAAI,EAAE;YAC/EnB,WAAWM,MAAM,CAACC,KAAK,CAACY,WAAW,CAACV,IAAI,CAAC,OAAOC;gBAC9CzB,OAAOc,KAAK,CAAC;oBACXa,MAAMF,OAAOV,UAAU,CAACY,IAAI;oBAC5BD,WAAW;gBACb,GAAG;gBAEH,qCAAqC;gBACrC,MAAMzB,SAAS2B,yBAAyB,CACtCH,OAAOV,UAAU,CAACY,IAAI,EACtB,UACAF,OAAOI,GAAG,EACVI,WACAR,OAAOM,GAAG;YAEd;QACF;QAEA,IAAIhB,YAAY;YACdf,OAAOO,IAAI,CAAC;gBACVI;gBACAwB,iBAAiB;oBACfZ,aAAaP,KAAKI,MAAM,IAAIJ,KAAKC,MAAM;oBACvCe,WAAWhB,KAAKG,IAAI;oBACpBe,aAAalB,KAAKE,MAAM;gBAC1B;YACF,GAAG;QACL,OAAO;YACLlB,OAAOoC,KAAK,CAAC;gBACXzB;gBACAF,sBAAsBN,OAAOC,IAAI,CAACL,QAAQW,WAAW;YACvD,GAAG;QACL;IACF;AACF"}
|
package/dist/plugin/logger.js
CHANGED
|
@@ -5,28 +5,24 @@ let pluginLogger = null;
|
|
|
5
5
|
* Uses console with plugin prefix since Payload logger isn't available yet
|
|
6
6
|
*/ const configLogger = {
|
|
7
7
|
debug: (message, ...args)=>{
|
|
8
|
-
console.log('process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING', process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING);
|
|
9
8
|
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {
|
|
10
9
|
return;
|
|
11
10
|
}
|
|
12
11
|
console.log(`[payload-automation] ${message}`, ...args);
|
|
13
12
|
},
|
|
14
13
|
error: (message, ...args)=>{
|
|
15
|
-
console.log('process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING', process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING);
|
|
16
14
|
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {
|
|
17
15
|
return;
|
|
18
16
|
}
|
|
19
17
|
console.error(`[payload-automation] ${message}`, ...args);
|
|
20
18
|
},
|
|
21
19
|
info: (message, ...args)=>{
|
|
22
|
-
console.log('process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING', process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING);
|
|
23
20
|
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {
|
|
24
21
|
return;
|
|
25
22
|
}
|
|
26
23
|
console.log(`[payload-automation] ${message}`, ...args);
|
|
27
24
|
},
|
|
28
25
|
warn: (message, ...args)=>{
|
|
29
|
-
console.log('process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING', process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING);
|
|
30
26
|
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {
|
|
31
27
|
return;
|
|
32
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin/logger.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n// Global logger instance - use Payload's logger type\nlet pluginLogger: null | Payload['logger'] = null\n\n/**\n * Simple config-time logger for use during plugin configuration\n * Uses console with plugin prefix since Payload logger isn't available yet\n */\nconst configLogger = {\n debug: <T>(message: string, ...args: T[]) => {\n
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/logger.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n// Global logger instance - use Payload's logger type\nlet pluginLogger: null | Payload['logger'] = null\n\n/**\n * Simple config-time logger for use during plugin configuration\n * Uses console with plugin prefix since Payload logger isn't available yet\n */\nconst configLogger = {\n debug: <T>(message: string, ...args: T[]) => {\n if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}\n console.log(`[payload-automation] ${message}`, ...args)\n },\n error: <T>(message: string, ...args: T[]) => {\n if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}\n console.error(`[payload-automation] ${message}`, ...args)\n },\n info: <T>(message: string, ...args: T[]) => {\n if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}\n console.log(`[payload-automation] ${message}`, ...args)\n },\n warn: <T>(message: string, ...args: T[]) => {\n if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}\n console.warn(`[payload-automation] ${message}`, ...args)\n }\n}\n\n/**\n * Get a logger for config-time use (before Payload initialization)\n */\nexport function getConfigLogger() {\n return configLogger\n}\n\n/**\n * Initialize the plugin logger using Payload's Pino instance\n * This creates a child logger with plugin identification\n */\nexport function initializeLogger(payload: Payload): Payload['logger'] {\n // Create a child logger with plugin identification\n pluginLogger = payload.logger.child({\n level: process.env.PAYLOAD_AUTOMATION_LOGGING || 'silent',\n plugin: '@xtr-dev/payload-automation'\n })\n return pluginLogger\n}\n\n/**\n * Get the plugin logger instance\n * Throws error if not initialized\n */\nexport function getLogger(): Payload['logger'] {\n if (!pluginLogger) {\n throw new Error('@xtr-dev/payload-automation: Logger not initialized. Make sure the plugin is properly configured.')\n }\n\n return pluginLogger\n}\n"],"names":["pluginLogger","configLogger","debug","message","args","process","env","PAYLOAD_AUTOMATION_CONFIG_LOGGING","console","log","error","info","warn","getConfigLogger","initializeLogger","payload","logger","child","level","PAYLOAD_AUTOMATION_LOGGING","plugin","getLogger","Error"],"mappings":"AAEA,qDAAqD;AACrD,IAAIA,eAAyC;AAE7C;;;CAGC,GACD,MAAMC,eAAe;IACnBC,OAAO,CAAIC,SAAiB,GAAGC;QAC7B,IAAI,CAACC,QAAQC,GAAG,CAACC,iCAAiC,EAAE;YAAC;QAAM;QAC3DC,QAAQC,GAAG,CAAC,CAAC,qBAAqB,EAAEN,SAAS,KAAKC;IACpD;IACAM,OAAO,CAAIP,SAAiB,GAAGC;QAC7B,IAAI,CAACC,QAAQC,GAAG,CAACC,iCAAiC,EAAE;YAAC;QAAM;QAC3DC,QAAQE,KAAK,CAAC,CAAC,qBAAqB,EAAEP,SAAS,KAAKC;IACtD;IACAO,MAAM,CAAIR,SAAiB,GAAGC;QAC5B,IAAI,CAACC,QAAQC,GAAG,CAACC,iCAAiC,EAAE;YAAC;QAAM;QAC3DC,QAAQC,GAAG,CAAC,CAAC,qBAAqB,EAAEN,SAAS,KAAKC;IACpD;IACAQ,MAAM,CAAIT,SAAiB,GAAGC;QAC5B,IAAI,CAACC,QAAQC,GAAG,CAACC,iCAAiC,EAAE;YAAC;QAAM;QAC3DC,QAAQI,IAAI,CAAC,CAAC,qBAAqB,EAAET,SAAS,KAAKC;IACrD;AACF;AAEA;;CAEC,GACD,OAAO,SAASS;IACd,OAAOZ;AACT;AAEA;;;CAGC,GACD,OAAO,SAASa,iBAAiBC,OAAgB;IAC/C,mDAAmD;IACnDf,eAAee,QAAQC,MAAM,CAACC,KAAK,CAAC;QAClCC,OAAOb,QAAQC,GAAG,CAACa,0BAA0B,IAAI;QACjDC,QAAQ;IACV;IACA,OAAOpB;AACT;AAEA;;;CAGC,GACD,OAAO,SAASqB;IACd,IAAI,CAACrB,cAAc;QACjB,MAAM,IAAIsB,MAAM;IAClB;IAEA,OAAOtB;AACT"}
|
|
@@ -2,8 +2,8 @@ export const createDocumentHandler = async ({ input, req })=>{
|
|
|
2
2
|
if (!input) {
|
|
3
3
|
throw new Error('No input provided');
|
|
4
4
|
}
|
|
5
|
-
const {
|
|
6
|
-
if (!
|
|
5
|
+
const { collectionSlug, data, draft, locale } = input;
|
|
6
|
+
if (!collectionSlug || typeof collectionSlug !== 'string') {
|
|
7
7
|
throw new Error('Collection slug is required');
|
|
8
8
|
}
|
|
9
9
|
if (!data) {
|
|
@@ -12,7 +12,7 @@ export const createDocumentHandler = async ({ input, req })=>{
|
|
|
12
12
|
try {
|
|
13
13
|
const parsedData = typeof data === 'string' ? JSON.parse(data) : data;
|
|
14
14
|
const result = await req.payload.create({
|
|
15
|
-
collection,
|
|
15
|
+
collection: collectionSlug,
|
|
16
16
|
data: parsedData,
|
|
17
17
|
draft: draft || false,
|
|
18
18
|
locale: locale || undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/steps/create-document-handler.ts"],"sourcesContent":["import type { TaskHandler } from \"payload\"\n\nexport const createDocumentHandler: TaskHandler<'create-document'> = async ({ input, req }) => {\n if (!input) {\n throw new Error('No input provided')\n }\n\n const {
|
|
1
|
+
{"version":3,"sources":["../../src/steps/create-document-handler.ts"],"sourcesContent":["import type { TaskHandler } from \"payload\"\n\nexport const createDocumentHandler: TaskHandler<'create-document'> = async ({ input, req }) => {\n if (!input) {\n throw new Error('No input provided')\n }\n\n const { collectionSlug, data, draft, locale } = input\n\n if (!collectionSlug || typeof collectionSlug !== 'string') {\n throw new Error('Collection slug is required')\n }\n\n if (!data) {\n throw new Error('Document data is required')\n }\n\n try {\n const parsedData = typeof data === 'string' ? JSON.parse(data) : data\n\n const result = await req.payload.create({\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 create document',\n state: 'failed'\n }\n }\n}\n"],"names":["createDocumentHandler","input","req","Error","collectionSlug","data","draft","locale","parsedData","JSON","parse","result","payload","create","collection","undefined","output","id","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,cAAc,EAAEC,IAAI,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAGN;IAEhD,IAAI,CAACG,kBAAkB,OAAOA,mBAAmB,UAAU;QACzD,MAAM,IAAID,MAAM;IAClB;IAEA,IAAI,CAACE,MAAM;QACT,MAAM,IAAIF,MAAM;IAClB;IAEA,IAAI;QACF,MAAMK,aAAa,OAAOH,SAAS,WAAWI,KAAKC,KAAK,CAACL,QAAQA;QAEjE,MAAMM,SAAS,MAAMT,IAAIU,OAAO,CAACC,MAAM,CAAC;YACtCC,YAAYV;YACZC,MAAMG;YACNF,OAAOA,SAAS;YAChBC,QAAQA,UAAUQ;YAClBb;QACF;QAEA,OAAO;YACLc,QAAQ;gBACNC,IAAIN,OAAOM,EAAE;gBACbC,KAAKP;YACP;YACAQ,OAAO;QACT;IACF,EAAE,OAAOC,OAAO;QACd,OAAO;YACLC,cAAcD,iBAAiBjB,QAAQiB,MAAME,OAAO,GAAG;YACvDH,OAAO;QACT;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/steps/create-document.ts"],"sourcesContent":["import type { TaskConfig } from \"payload\"\n\nimport { createDocumentHandler } from \"./create-document-handler.js\"\n\nexport const CreateDocumentStepTask = {\n slug: 'create-document',\n handler: createDocumentHandler,\n inputSchema: [\n {\n name: '
|
|
1
|
+
{"version":3,"sources":["../../src/steps/create-document.ts"],"sourcesContent":["import type { TaskConfig } from \"payload\"\n\nimport { createDocumentHandler } from \"./create-document-handler.js\"\n\nexport const CreateDocumentStepTask = {\n slug: 'create-document',\n handler: createDocumentHandler,\n inputSchema: [\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n description: 'The collection slug to create a document in'\n },\n required: true\n },\n {\n name: 'data',\n type: 'json',\n admin: {\n description: 'The document data to create'\n },\n required: true\n },\n {\n name: 'draft',\n type: 'checkbox',\n admin: {\n description: 'Create as draft (if collection has drafts enabled)'\n }\n },\n {\n name: 'locale',\n type: 'text',\n admin: {\n description: 'Locale for the document (if localization is enabled)'\n }\n }\n ],\n outputSchema: [\n {\n name: 'doc',\n type: 'json',\n admin: {\n description: 'The created document'\n }\n },\n {\n name: 'id',\n type: 'text',\n admin: {\n description: 'The ID of the created document'\n }\n }\n ]\n} satisfies TaskConfig<'create-document'>"],"names":["createDocumentHandler","CreateDocumentStepTask","slug","handler","inputSchema","name","type","admin","description","required","outputSchema"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,+BAA8B;AAEpE,OAAO,MAAMC,yBAAyB;IACpCC,MAAM;IACNC,SAASH;IACTI,aAAa;QACX;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;YACAC,UAAU;QACZ;QACA;YACEJ,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;YACAC,UAAU;QACZ;QACA;YACEJ,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;KACD;IACDE,cAAc;QACZ;YACEL,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;KACD;AACH,EAAyC"}
|
|
@@ -2,8 +2,8 @@ export const deleteDocumentHandler = async ({ input, req })=>{
|
|
|
2
2
|
if (!input) {
|
|
3
3
|
throw new Error('No input provided');
|
|
4
4
|
}
|
|
5
|
-
const { id,
|
|
6
|
-
if (!
|
|
5
|
+
const { id, collectionSlug, where } = input;
|
|
6
|
+
if (!collectionSlug || typeof collectionSlug !== 'string') {
|
|
7
7
|
throw new Error('Collection slug is required');
|
|
8
8
|
}
|
|
9
9
|
try {
|
|
@@ -11,7 +11,7 @@ export const deleteDocumentHandler = async ({ input, req })=>{
|
|
|
11
11
|
if (id) {
|
|
12
12
|
const result = await req.payload.delete({
|
|
13
13
|
id: id.toString(),
|
|
14
|
-
collection,
|
|
14
|
+
collection: collectionSlug,
|
|
15
15
|
req
|
|
16
16
|
});
|
|
17
17
|
return {
|
|
@@ -29,7 +29,7 @@ export const deleteDocumentHandler = async ({ input, req })=>{
|
|
|
29
29
|
const parsedWhere = typeof where === 'string' ? JSON.parse(where) : where;
|
|
30
30
|
// First find the documents to delete
|
|
31
31
|
const toDelete = await req.payload.find({
|
|
32
|
-
collection,
|
|
32
|
+
collection: collectionSlug,
|
|
33
33
|
limit: 1000,
|
|
34
34
|
req,
|
|
35
35
|
where: parsedWhere
|
|
@@ -39,7 +39,7 @@ export const deleteDocumentHandler = async ({ input, req })=>{
|
|
|
39
39
|
for (const doc of toDelete.docs){
|
|
40
40
|
const result = await req.payload.delete({
|
|
41
41
|
id: doc.id,
|
|
42
|
-
collection,
|
|
42
|
+
collection: collectionSlug,
|
|
43
43
|
req
|
|
44
44
|
});
|
|
45
45
|
deleted.push(result);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/steps/delete-document-handler.ts"],"sourcesContent":["import type { TaskHandler } from \"payload\"\n\nexport const deleteDocumentHandler: TaskHandler<'delete-document'> = async ({ input, req }) => {\n if (!input) {\n throw new Error('No input provided')\n }\n\n const { id,
|
|
1
|
+
{"version":3,"sources":["../../src/steps/delete-document-handler.ts"],"sourcesContent":["import type { TaskHandler } from \"payload\"\n\nexport const deleteDocumentHandler: TaskHandler<'delete-document'> = async ({ input, req }) => {\n if (!input) {\n throw new Error('No input provided')\n }\n\n const { id, collectionSlug, 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, delete by ID\n if (id) {\n const result = await req.payload.delete({\n id: id.toString(),\n collection: collectionSlug,\n req\n })\n\n return {\n output: {\n deletedCount: 1,\n doc: result\n },\n state: 'succeeded'\n }\n }\n\n // Otherwise, delete multiple documents\n if (!where) {\n throw new Error('Either ID or where conditions must be provided')\n }\n\n const parsedWhere = typeof where === 'string' ? JSON.parse(where) : where\n\n // First find the documents to delete\n const toDelete = await req.payload.find({\n collection: collectionSlug,\n limit: 1000, // Set a reasonable limit\n req,\n where: parsedWhere\n })\n\n // Delete each document\n const deleted = []\n for (const doc of toDelete.docs) {\n const result = await req.payload.delete({\n id: doc.id,\n collection: collectionSlug,\n req\n })\n deleted.push(result)\n }\n\n return {\n output: {\n deletedCount: deleted.length,\n doc: deleted\n },\n state: 'succeeded'\n }\n } catch (error) {\n return {\n errorMessage: error instanceof Error ? error.message : 'Failed to delete document(s)',\n state: 'failed'\n }\n }\n}\n"],"names":["deleteDocumentHandler","input","req","Error","id","collectionSlug","where","result","payload","delete","toString","collection","output","deletedCount","doc","state","parsedWhere","JSON","parse","toDelete","find","limit","deleted","docs","push","length","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,KAAK,EAAE,GAAGL;IAEtC,IAAI,CAACI,kBAAkB,OAAOA,mBAAmB,UAAU;QACzD,MAAM,IAAIF,MAAM;IAClB;IAEA,IAAI;QACF,kCAAkC;QAClC,IAAIC,IAAI;YACN,MAAMG,SAAS,MAAML,IAAIM,OAAO,CAACC,MAAM,CAAC;gBACtCL,IAAIA,GAAGM,QAAQ;gBACfC,YAAYN;gBACZH;YACF;YAEA,OAAO;gBACLU,QAAQ;oBACNC,cAAc;oBACdC,KAAKP;gBACP;gBACAQ,OAAO;YACT;QACF;QAEA,uCAAuC;QACvC,IAAI,CAACT,OAAO;YACV,MAAM,IAAIH,MAAM;QAClB;QAEA,MAAMa,cAAc,OAAOV,UAAU,WAAWW,KAAKC,KAAK,CAACZ,SAASA;QAEpE,qCAAqC;QACrC,MAAMa,WAAW,MAAMjB,IAAIM,OAAO,CAACY,IAAI,CAAC;YACtCT,YAAYN;YACZgB,OAAO;YACPnB;YACAI,OAAOU;QACT;QAEA,uBAAuB;QACvB,MAAMM,UAAU,EAAE;QAClB,KAAK,MAAMR,OAAOK,SAASI,IAAI,CAAE;YAC/B,MAAMhB,SAAS,MAAML,IAAIM,OAAO,CAACC,MAAM,CAAC;gBACtCL,IAAIU,IAAIV,EAAE;gBACVO,YAAYN;gBACZH;YACF;YACAoB,QAAQE,IAAI,CAACjB;QACf;QAEA,OAAO;YACLK,QAAQ;gBACNC,cAAcS,QAAQG,MAAM;gBAC5BX,KAAKQ;YACP;YACAP,OAAO;QACT;IACF,EAAE,OAAOW,OAAO;QACd,OAAO;YACLC,cAAcD,iBAAiBvB,QAAQuB,MAAME,OAAO,GAAG;YACvDb,OAAO;QACT;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/steps/delete-document.ts"],"sourcesContent":["import type { TaskConfig } from \"payload\"\n\nimport { deleteDocumentHandler } from \"./delete-document-handler.js\"\n\nexport const DeleteDocumentStepTask = {\n slug: 'delete-document',\n handler: deleteDocumentHandler,\n inputSchema: [\n {\n name: '
|
|
1
|
+
{"version":3,"sources":["../../src/steps/delete-document.ts"],"sourcesContent":["import type { TaskConfig } from \"payload\"\n\nimport { deleteDocumentHandler } from \"./delete-document-handler.js\"\n\nexport const DeleteDocumentStepTask = {\n slug: 'delete-document',\n handler: deleteDocumentHandler,\n inputSchema: [\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n description: 'The collection slug to delete from'\n },\n required: true\n },\n {\n name: 'id',\n type: 'text',\n admin: {\n description: 'The ID of a specific document to delete (leave empty to delete multiple)'\n }\n },\n {\n name: 'where',\n type: 'json',\n admin: {\n description: 'Query conditions to find documents to delete (used when ID is not provided)'\n }\n }\n ],\n outputSchema: [\n {\n name: 'doc',\n type: 'json',\n admin: {\n description: 'The deleted document(s)'\n }\n },\n {\n name: 'deletedCount',\n type: 'number',\n admin: {\n description: 'Number of documents deleted'\n }\n }\n ]\n} satisfies TaskConfig<'delete-document'>"],"names":["deleteDocumentHandler","DeleteDocumentStepTask","slug","handler","inputSchema","name","type","admin","description","required","outputSchema"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,+BAA8B;AAEpE,OAAO,MAAMC,yBAAyB;IACpCC,MAAM;IACNC,SAASH;IACTI,aAAa;QACX;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;YACAC,UAAU;QACZ;QACA;YACEJ,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;KACD;IACDE,cAAc;QACZ;YACEL,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;KACD;AACH,EAAyC"}
|
|
@@ -2,8 +2,8 @@ export const readDocumentHandler = async ({ input, req })=>{
|
|
|
2
2
|
if (!input) {
|
|
3
3
|
throw new Error('No input provided');
|
|
4
4
|
}
|
|
5
|
-
const { id,
|
|
6
|
-
if (!
|
|
5
|
+
const { id, collectionSlug, depth, limit, locale, sort, where } = input;
|
|
6
|
+
if (!collectionSlug || typeof collectionSlug !== 'string') {
|
|
7
7
|
throw new Error('Collection slug is required');
|
|
8
8
|
}
|
|
9
9
|
try {
|
|
@@ -11,7 +11,7 @@ export const readDocumentHandler = async ({ input, req })=>{
|
|
|
11
11
|
if (id) {
|
|
12
12
|
const result = await req.payload.findByID({
|
|
13
13
|
id: id.toString(),
|
|
14
|
-
collection,
|
|
14
|
+
collection: collectionSlug,
|
|
15
15
|
depth: typeof depth === 'number' ? depth : undefined,
|
|
16
16
|
locale: locale || undefined,
|
|
17
17
|
req
|
|
@@ -27,7 +27,7 @@ export const readDocumentHandler = async ({ input, req })=>{
|
|
|
27
27
|
// Otherwise, find multiple documents
|
|
28
28
|
const parsedWhere = where ? typeof where === 'string' ? JSON.parse(where) : where : {};
|
|
29
29
|
const result = await req.payload.find({
|
|
30
|
-
collection,
|
|
30
|
+
collection: collectionSlug,
|
|
31
31
|
depth: typeof depth === 'number' ? depth : undefined,
|
|
32
32
|
limit: typeof limit === 'number' ? limit : 10,
|
|
33
33
|
locale: locale || undefined,
|
|
@@ -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,
|
|
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 errorName: 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","tot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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/steps/read-document.ts"],"sourcesContent":["import type { TaskConfig } from \"payload\"\n\nimport { readDocumentHandler } from \"./read-document-handler.js\"\n\nexport const ReadDocumentStepTask = {\n slug: 'read-document',\n handler: readDocumentHandler,\n inputSchema: [\n {\n name: '
|
|
1
|
+
{"version":3,"sources":["../../src/steps/read-document.ts"],"sourcesContent":["import type { TaskConfig } from \"payload\"\n\nimport { readDocumentHandler } from \"./read-document-handler.js\"\n\nexport const ReadDocumentStepTask = {\n slug: 'read-document',\n handler: readDocumentHandler,\n inputSchema: [\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n description: 'The collection slug to read from'\n },\n required: true\n },\n {\n name: 'id',\n type: 'text',\n admin: {\n description: 'The ID of a specific document to read (leave empty to find multiple)'\n }\n },\n {\n name: 'where',\n type: 'json',\n admin: {\n description: 'Query conditions to find documents (used when ID is not provided)'\n }\n },\n {\n name: 'limit',\n type: 'number',\n admin: {\n description: 'Maximum number of documents to return (default: 10)'\n }\n },\n {\n name: 'sort',\n type: 'text',\n admin: {\n description: 'Field to sort by (prefix with - for descending order)'\n }\n },\n {\n name: 'locale',\n type: 'text',\n admin: {\n description: 'Locale for the document (if localization is enabled)'\n }\n },\n {\n name: 'depth',\n type: 'number',\n admin: {\n description: 'Depth of relationships to populate (0-10)'\n }\n }\n ],\n outputSchema: [\n {\n name: 'doc',\n type: 'json',\n admin: {\n description: 'The document(s) found'\n }\n },\n {\n name: 'totalDocs',\n type: 'number',\n admin: {\n description: 'Total number of documents matching the query'\n }\n }\n ]\n} satisfies TaskConfig<'read-document'>"],"names":["readDocumentHandler","ReadDocumentStepTask","slug","handler","inputSchema","name","type","admin","description","required","outputSchema"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ,6BAA4B;AAEhE,OAAO,MAAMC,uBAAuB;IAClCC,MAAM;IACNC,SAASH;IACTI,aAAa;QACX;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;YACAC,UAAU;QACZ;QACA;YACEJ,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;KACD;IACDE,cAAc;QACZ;YACEL,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;KACD;AACH,EAAuC"}
|
|
@@ -2,8 +2,8 @@ export const updateDocumentHandler = async ({ input, req })=>{
|
|
|
2
2
|
if (!input) {
|
|
3
3
|
throw new Error('No input provided');
|
|
4
4
|
}
|
|
5
|
-
const { id,
|
|
6
|
-
if (!
|
|
5
|
+
const { id, collectionSlug, data, draft, locale } = input;
|
|
6
|
+
if (!collectionSlug || typeof collectionSlug !== 'string') {
|
|
7
7
|
throw new Error('Collection slug is required');
|
|
8
8
|
}
|
|
9
9
|
if (!id) {
|
|
@@ -16,7 +16,7 @@ export const updateDocumentHandler = async ({ input, req })=>{
|
|
|
16
16
|
const parsedData = typeof data === 'string' ? JSON.parse(data) : data;
|
|
17
17
|
const result = await req.payload.update({
|
|
18
18
|
id: id.toString(),
|
|
19
|
-
collection,
|
|
19
|
+
collection: collectionSlug,
|
|
20
20
|
data: parsedData,
|
|
21
21
|
draft: draft || false,
|
|
22
22
|
locale: locale || undefined,
|
|
@@ -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,
|
|
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 errorName: 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","errorName","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,WAAWD,iBAAiBlB,QAAQkB,MAAME,OAAO,GAAG;YACpDH,OAAO;QACT;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/steps/update-document.ts"],"sourcesContent":["import type { TaskConfig } from \"payload\"\n\nimport { updateDocumentHandler } from \"./update-document-handler.js\"\n\nexport const UpdateDocumentStepTask = {\n slug: 'update-document',\n handler: updateDocumentHandler,\n inputSchema: [\n {\n name: '
|
|
1
|
+
{"version":3,"sources":["../../src/steps/update-document.ts"],"sourcesContent":["import type { TaskConfig } from \"payload\"\n\nimport { updateDocumentHandler } from \"./update-document-handler.js\"\n\nexport const UpdateDocumentStepTask = {\n slug: 'update-document',\n handler: updateDocumentHandler,\n inputSchema: [\n {\n name: 'collectionSlug',\n type: 'text',\n admin: {\n description: 'The collection slug to update a document in'\n },\n required: true\n },\n {\n name: 'id',\n type: 'text',\n admin: {\n description: 'The ID of the document to update'\n },\n required: true\n },\n {\n name: 'data',\n type: 'json',\n admin: {\n description: 'The data to update the document with'\n },\n required: true\n },\n {\n name: 'draft',\n type: 'checkbox',\n admin: {\n description: 'Update as draft (if collection has drafts enabled)'\n }\n },\n {\n name: 'locale',\n type: 'text',\n admin: {\n description: 'Locale for the document (if localization is enabled)'\n }\n }\n ],\n outputSchema: [\n {\n name: 'doc',\n type: 'json',\n admin: {\n description: 'The updated document'\n }\n },\n {\n name: 'id',\n type: 'text',\n admin: {\n description: 'The ID of the updated document'\n }\n }\n ]\n} satisfies TaskConfig<'update-document'>"],"names":["updateDocumentHandler","UpdateDocumentStepTask","slug","handler","inputSchema","name","type","admin","description","required","outputSchema"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,+BAA8B;AAEpE,OAAO,MAAMC,yBAAyB;IACpCC,MAAM;IACNC,SAASH;IACTI,aAAa;QACX;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;YACAC,UAAU;QACZ;QACA;YACEJ,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;YACAC,UAAU;QACZ;QACA;YACEJ,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;YACAC,UAAU;QACZ;QACA;YACEJ,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;KACD;IACDE,cAAc;QACZ;YACEL,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;QACF;KACD;AACH,EAAyC"}
|
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.8",
|
|
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",
|