# Operational scripts All scripts load `.env` from the repo root and run against the **live** database/bucket — there is no staging environment. Run them from the monorepo root. ## Scheduled jobs (set up as daily crons on the production server) ```cron # Daily at 03:00 — enforce Privacy Policy retention windows 0 3 * * * cd /path/to/app && npm run cron:retention >> logs/retention.log 2>&1 # Daily at 08:00 — mark past-due invoices overdue + email client reminders 0 8 * * * cd /path/to/app && npm run cron:overdue >> logs/overdue.log 2>&1 ``` | Script | npm alias | What it does | | --- | --- | --- | | `retention-sweep.ts` | `npm run cron:retention` | Purges expired sessions, consumed/expired reset & verification tokens, login attempts and tool usage > 90 days, contact messages and audit log > 24 months. | | `send-overdue-reminders.ts` | `npm run cron:overdue` | Flips past-due `sent` invoices to `overdue` and emails the client once, on the transition. | ## Maintenance / one-off | Script | npm alias | What it does | | --- | --- | --- | | `sweep-orphaned-storage.ts` | `npm run storage:sweep` | Reconciles DO Spaces against the `documents` table. Dry-run by default; add `-- --delete` to remove orphans. Only document-shaped keys (`uuid/uuid/uuid.ext`) are ever deleted. | | `create-admin.ts` | — | Creates a superadmin user (credentials via env/argv). | | `seed-demo.ts` | — | Seeds demo data. **Live DB — use with care.** | | `migrate-storage-to-spaces.ts` | — | One-time migration of legacy local files to Spaces (historical). |