diff --git a/bin/events.js b/bin/events.js index c13c9a9..773724e 100644 --- a/bin/events.js +++ b/bin/events.js @@ -17,6 +17,7 @@ import { q } from '../src/db.js'; const args = process.argv.slice(2); const cmd = args[0]; const EMAIL_RE = /^[^@\s]+@[^@\s]+\.[^@\s]+$/; +const ALLOWED_EVENT_TYPES = new Set(['login', 'timeline_view']); function help() { console.log('Usage:'); @@ -49,7 +50,13 @@ function metaCompact(m) { switch (cmd) { case 'list': { const type = parseFlag('--type'); - const limit = Number(parseFlag('--limit') || 200); + if (type && !ALLOWED_EVENT_TYPES.has(type)) { + console.error(`unknown --type: ${type} (valid: ${[...ALLOWED_EVENT_TYPES].join(', ')})`); + process.exit(1); + } + const rawLimit = parseFlag('--limit'); + const parsedLimit = rawLimit == null ? 200 : Number.parseInt(rawLimit, 10); + const limit = Number.isFinite(parsedLimit) && parsedLimit > 0 ? parsedLimit : 200; const rows = type ? q.listEventsByType.all(type, limit) : q.listEvents.all(limit);