| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /**
- * @node post-trigger
- * @name POST Trigger
- * @category triggers
- * @version 1.0.0
- * @description Triggers workflow on HTTP POST request with JSON body validation
- * @trigger
- * @icon upload
- */
- const configSchema = {
- type: 'object',
- properties: {
- path: {
- type: 'string',
- title: 'Path Filter',
- description: 'Optional path suffix to match (e.g., /orders). Leave empty to match any path.',
- default: ''
- },
- contentType: {
- type: 'string',
- title: 'Content Type',
- description: 'Required content type for the request',
- enum: ['application/json'],
- default: 'application/json'
- },
- validateBody: {
- type: 'boolean',
- title: 'Validate Body',
- description: 'Enable JSON Schema validation for request body',
- default: false
- },
- bodySchema: {
- type: 'object',
- title: 'Body Schema',
- description: 'JSON Schema to validate request body against',
- format: 'json-schema',
- default: {
- type: 'object',
- properties: {},
- required: []
- },
- 'x-if': 'validateBody'
- },
- requireAuth: {
- type: 'boolean',
- title: 'Require Authentication',
- description: 'Require API key in request header',
- default: false
- },
- apiKeyHeader: {
- type: 'string',
- title: 'API Key Header',
- description: 'Header name containing the API key',
- default: 'X-API-Key',
- 'x-if': 'requireAuth'
- },
- apiKey: {
- type: 'string',
- title: 'API Key',
- description: 'Expected API key value',
- format: 'password',
- 'x-if': 'requireAuth'
- }
- }
- };
- const inputSchema = {
- type: 'object',
- properties: {}
- };
- const outputSchema = {
- type: 'object',
- properties: {
- method: {
- type: 'string',
- description: 'HTTP method (POST)'
- },
- path: {
- type: 'string',
- description: 'Request path after /webhook/{workflow_id}'
- },
- query: {
- type: 'object',
- description: 'Query parameters as key-value pairs'
- },
- headers: {
- type: 'object',
- description: 'Request headers as key-value pairs'
- },
- body: {
- type: 'object',
- description: 'Parsed JSON request body'
- },
- timestamp: {
- type: 'number',
- description: 'Unix timestamp when request was received'
- },
- clientIp: {
- type: 'string',
- description: 'Client IP address'
- }
- }
- };
- async function execute(config, input, context) {
- smartbotic.log.info('POST trigger activated');
- // The trigger data comes from the webhook controller
- const triggerData = context.triggerData || {};
- return {
- method: triggerData.method || 'POST',
- path: triggerData.path || '',
- query: triggerData.query || {},
- headers: triggerData.headers || {},
- body: triggerData.body || {},
- timestamp: Date.now(),
- clientIp: triggerData.clientIp || ''
- };
- }
- module.exports = { configSchema, inputSchema, outputSchema, execute };
|