DC-010: Convert remaining bare res.json({success,...}) envelopes to response helper
Routes covered in this batch:
- routes/events.js (1 call: GET /status)
- routes/workflows.js (6 calls: GET/POST/PUT/DELETE /workflows, POST /test, POST /:id/toggle)
- routes/openclaw.js (4 calls: GET /:hostname, DELETE /:hostname, POST /connect, GET /status)
- routes/dns.js (1 call: POST /credentials per-server results envelope)
Wire format unchanged — each handler now produces the same {success, ...} shape via success(). Net result: every {success, ...} envelope in routes/ now flows through the response helper, leaving only the intentional raw-array calls (services.js) and error-path envelopes for separate cleanup.
This commit is contained in:
@@ -6,60 +6,61 @@ const express = require('express');
|
||||
* @param {Object} deps.workflowEngine - WorkflowEngine instance
|
||||
* @param {Object} deps.licenseManager - License manager for premium gating
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Function} deps.ok - Success response helper
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
module.exports = function({ workflowEngine, licenseManager, asyncHandler }) {
|
||||
module.exports = function({ workflowEngine, licenseManager, asyncHandler, ok }) {
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
// Apply premium gating to all workflows routes
|
||||
router.use(licenseManager.requirePremium('workflows'));
|
||||
|
||||
|
||||
// ===== WORKFLOW MANAGEMENT ENDPOINTS =====
|
||||
|
||||
|
||||
// List all bundled workflows
|
||||
router.get('/workflows', asyncHandler(async (req, res) => {
|
||||
const workflows = workflowEngine.listWorkflows();
|
||||
res.json({ success: true, workflows });
|
||||
ok(res, { workflows });
|
||||
}, 'workflows-list'));
|
||||
|
||||
|
||||
// Enable a workflow
|
||||
router.post('/workflows/:workflowId/enable', asyncHandler(async (req, res) => {
|
||||
const { workflowId } = req.params;
|
||||
const result = workflowEngine.setWorkflowEnabled(workflowId, true);
|
||||
res.json({ success: true, ...result });
|
||||
ok(res, { ...result });
|
||||
}, 'workflows-enable'));
|
||||
|
||||
|
||||
// Disable a workflow
|
||||
router.post('/workflows/:workflowId/disable', asyncHandler(async (req, res) => {
|
||||
const { workflowId } = req.params;
|
||||
const result = workflowEngine.setWorkflowEnabled(workflowId, false);
|
||||
res.json({ success: true, ...result });
|
||||
ok(res, { ...result });
|
||||
}, 'workflows-disable'));
|
||||
|
||||
|
||||
// Manually trigger a workflow
|
||||
router.post('/workflows/:workflowId/run', asyncHandler(async (req, res) => {
|
||||
const { workflowId } = req.params;
|
||||
const triggerData = req.body || {};
|
||||
triggerData.trigger = 'manual';
|
||||
|
||||
|
||||
const result = await workflowEngine.executeWorkflow(workflowId, triggerData);
|
||||
res.json({ success: true, result });
|
||||
ok(res, { result });
|
||||
}, 'workflows-run'));
|
||||
|
||||
|
||||
// Get execution history for a workflow
|
||||
router.get('/workflows/:workflowId/history', asyncHandler(async (req, res) => {
|
||||
const { workflowId } = req.params;
|
||||
const limit = parseInt(req.query.limit) || 50;
|
||||
const history = workflowEngine.getHistory(workflowId, limit);
|
||||
res.json({ success: true, history });
|
||||
ok(res, { history });
|
||||
}, 'workflows-history'));
|
||||
|
||||
|
||||
// Get all workflow execution history
|
||||
router.get('/workflows/history', asyncHandler(async (req, res) => {
|
||||
const limit = parseInt(req.query.limit) || 100;
|
||||
const history = workflowEngine.getHistory(null, limit);
|
||||
res.json({ success: true, history });
|
||||
ok(res, { history });
|
||||
}, 'workflows-all-history'));
|
||||
|
||||
|
||||
return router;
|
||||
};
|
||||
Reference in New Issue
Block a user