refactor: replace exceljs with write-excel-file for analytics export
Build & Push Docker Image / build (push) Successful in 3m57s

exceljs (latest 4.4.0) ships years-old transitive dependencies that
npm flags as deprecated on every install (rimraf 2, glob 7, inflight,
fstream, lodash.isequal) and needed a uuid override for a security
advisory. It was only used for the single-sheet analytics XLSX export,
which write-excel-file covers with the same output (column widths,
bold/grey header, formula-injection escaping).

Removes the now-unneeded exceljs uuid override.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 09:40:53 +02:00
co-authored by Claude Fable 5
parent fcd73d0667
commit 8c65e4acd2
3 changed files with 37 additions and 814 deletions
+16 -18
View File
@@ -1,6 +1,6 @@
import { Router, json } from 'express';
import crypto from 'crypto';
import ExcelJS from 'exceljs';
import writeXlsxFile from 'write-excel-file/node';
import PDFDocument from 'pdfkit';
import { getDb } from '../config/database.js';
import { authenticateToken } from '../middleware/auth.js';
@@ -246,26 +246,24 @@ router.get('/:id/export/:format', authenticateToken, async (req, res) => {
if (format === 'xlsx') {
// Prefix-escape strings that would otherwise be evaluated as formulas.
const sanitizeXlsx = (r) => {
const out = {};
for (const k of Object.keys(r)) {
const v = r[k];
out[k] = (typeof v === 'string' && /^[=+\-@\t\r]/.test(v)) ? "'" + v : v;
}
return out;
};
const workbook = new ExcelJS.Workbook();
const sheet = workbook.addWorksheet('Analytics');
sheet.columns = COLUMNS;
rows.forEach(r => sheet.addRow(sanitizeXlsx(r)));
// Style header row
sheet.getRow(1).font = { bold: true };
sheet.getRow(1).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE0E0E0' } };
const sanitizeXlsx = (v) =>
(typeof v === 'string' && /^[=+\-@\t\r]/.test(v)) ? "'" + v : v;
const headerRow = COLUMNS.map(c => ({
value: c.header,
fontWeight: 'bold',
backgroundColor: '#e0e0e0',
}));
const dataRows = rows.map(r => COLUMNS.map(c => ({ value: sanitizeXlsx(r[c.key]) })));
const buffer = await writeXlsxFile([headerRow, ...dataRows], {
columns: COLUMNS.map(c => ({ width: c.width })),
sheet: 'Analytics',
}).toBuffer();
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
res.setHeader('Content-Disposition', `attachment; filename="${safeName}.xlsx"`);
await workbook.xlsx.write(res);
return res.end();
return res.send(buffer);
}
if (format === 'pdf') {