Two cleanups in one pass for the v1.14.0 'works on any platform' theme: 1. Response helpers — merged src/utils/responses.js and the root-level response-helpers.js into a single module at src/utils/responses.js. The old module had a richer set (created, noContent, validationError, unauthorized, forbidden, notFound, conflict) and is now re-exported from the new location. Updated 15 routes to import from src/utils/responses and deleted the root response-helpers.js. 2. Error logger — error-handler.js now uses the unified src/utils/logging.js#logError (same one src/app.js uses), so all errors go to one log file with one rotation policy. Removed the dead asyncHandler export (the real one is in src/utils/async-handler.js and is used everywhere). Deleted the legacy error-logger.js. Both are invisible to users — same HTTP response shapes, same log file path, same error format. Internal-only refactor.
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
const { success, error: errorResponse } = require('../src/utils/responses');
|
|
|
|
/**
|
|
* Credentials routes factory
|
|
* @param {Object} deps - Explicit dependencies
|
|
* @param {Object} deps.credentialManager - Credential storage manager
|
|
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
|
* @returns {express.Router}
|
|
*/
|
|
module.exports = function({ credentialManager, asyncHandler }) {
|
|
const router = express.Router();
|
|
|
|
// List all stored credentials (keys only, no values)
|
|
router.get('/credentials/list', asyncHandler(async (req, res) => {
|
|
const keys = await credentialManager.list();
|
|
success(res, { credentials: keys, count: keys.length });
|
|
}, 'credentials-list'));
|
|
|
|
// Rotate encryption key — re-encrypts all stored credentials
|
|
router.post('/credentials/rotate-key', asyncHandler(async (req, res) => {
|
|
const rotateSuccess = await credentialManager.rotateEncryptionKey();
|
|
if (rotateSuccess) {
|
|
success(res, { message: 'Encryption key rotated, all credentials re-encrypted' });
|
|
} else {
|
|
// Error handled by middleware
|
|
}
|
|
}, 'credentials-rotate'));
|
|
|
|
return router;
|
|
};
|