put-trigger.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * @node put-trigger
  3. * @name PUT Trigger
  4. * @category triggers
  5. * @version 1.0.0
  6. * @description Triggers workflow on HTTP PUT request with JSON body validation
  7. * @trigger
  8. * @icon upload
  9. */
  10. const configSchema = {
  11. type: 'object',
  12. properties: {
  13. path: {
  14. type: 'string',
  15. title: 'Path Filter',
  16. description: 'Optional path suffix to match (e.g., /orders/{id}). Leave empty to match any path.',
  17. default: ''
  18. },
  19. contentType: {
  20. type: 'string',
  21. title: 'Content Type',
  22. description: 'Required content type for the request',
  23. enum: ['application/json'],
  24. default: 'application/json'
  25. },
  26. validateBody: {
  27. type: 'boolean',
  28. title: 'Validate Body',
  29. description: 'Enable JSON Schema validation for request body',
  30. default: false
  31. },
  32. bodySchema: {
  33. type: 'object',
  34. title: 'Body Schema',
  35. description: 'JSON Schema to validate request body against',
  36. format: 'json-schema',
  37. default: {
  38. type: 'object',
  39. properties: {},
  40. required: []
  41. },
  42. 'x-if': 'validateBody'
  43. },
  44. requireAuth: {
  45. type: 'boolean',
  46. title: 'Require Authentication',
  47. description: 'Require API key in request header',
  48. default: false
  49. },
  50. apiKeyHeader: {
  51. type: 'string',
  52. title: 'API Key Header',
  53. description: 'Header name containing the API key',
  54. default: 'X-API-Key',
  55. 'x-if': 'requireAuth'
  56. },
  57. apiKey: {
  58. type: 'string',
  59. title: 'API Key',
  60. description: 'Expected API key value',
  61. format: 'password',
  62. 'x-if': 'requireAuth'
  63. }
  64. }
  65. };
  66. const inputSchema = {
  67. type: 'object',
  68. properties: {}
  69. };
  70. const outputSchema = {
  71. type: 'object',
  72. properties: {
  73. method: {
  74. type: 'string',
  75. description: 'HTTP method (PUT)'
  76. },
  77. path: {
  78. type: 'string',
  79. description: 'Request path after /webhook/{workflow_id}'
  80. },
  81. query: {
  82. type: 'object',
  83. description: 'Query parameters as key-value pairs'
  84. },
  85. headers: {
  86. type: 'object',
  87. description: 'Request headers as key-value pairs'
  88. },
  89. body: {
  90. type: 'object',
  91. description: 'Parsed JSON request body'
  92. },
  93. timestamp: {
  94. type: 'number',
  95. description: 'Unix timestamp when request was received'
  96. },
  97. clientIp: {
  98. type: 'string',
  99. description: 'Client IP address'
  100. }
  101. }
  102. };
  103. async function execute(config, input, context) {
  104. smartbotic.log.info('PUT trigger activated');
  105. // The trigger data comes from the webhook controller
  106. const triggerData = context.triggerData || {};
  107. return {
  108. method: triggerData.method || 'PUT',
  109. path: triggerData.path || '',
  110. query: triggerData.query || {},
  111. headers: triggerData.headers || {},
  112. body: triggerData.body || {},
  113. timestamp: Date.now(),
  114. clientIp: triggerData.clientIp || ''
  115. };
  116. }
  117. module.exports = { configSchema, inputSchema, outputSchema, execute };