feat: add volunteer shift signup app

Initial source, tests, migrations, and local Docker setup for the Hope Food Pantry volunteer scheduler.
This commit is contained in:
blake committed 2026-10-16 09:33:39 -05:00
commit f1a46e2ba7
129 files changed
+25290

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
// Development entry point. The command itself is src/recover-coordinator.ts, which the image builds into dist/.
import '../src/recover-coordinator.ts';
+39
View File
@@ -0,0 +1,39 @@
# Restore a local backup
This puts a saved copy back into the live data directory on this computer. It does not test an offsite copy. Offsite storage is still decision D6.
Stop the app first. A restore while Hope Volunteer is running can leave a half-written database.
1. Stop the container, or stop `npm run dev` if that is what is running.
2. Copy the current data directory aside, including `app.db`, `app.db-wal`, and `app.db-shm`, so you can put it back if the restore is wrong.
3. Pick one file from `data/backups`. Daily copies are named `daily-YYYY-MM-DD.db`. Sunday copies are named `weekly-YYYY-MM-DD.db`. A file named `pre-migrate-` is the database from before a production migration, not the daily schedule.
4. Check the file before replacing the live database:
```bash
sqlite3 data/backups/daily-YYYY-MM-DD.db "PRAGMA integrity_check;"
```
The result should be `ok`.
5. Replace the live database with that file. Remove any `app.db-wal` and `app.db-shm` left from the old live database. The saved copy is one file and does not need those sidecars.
```bash
rm -f data/app.db data/app.db-wal data/app.db-shm
cp data/backups/daily-YYYY-MM-DD.db data/app.db
```
6. While the app is still stopped, revoke sign-in cookies from the restored copy and hold mail that was waiting. Otherwise a restored cookie still signs a coordinator in, and waiting messages are sent after startup.
```bash
sqlite3 data/app.db "DELETE FROM sessions; DELETE FROM login_tokens; UPDATE outbox SET status = 'cancelled', last_error = 'Held after a restore.' WHERE status IN ('pending', 'sending');"
```
7. If Docker runs the app, the `node` user inside the image must be able to write the data directory. That user is uid 1000. Do not make the directory writable by everyone.
```bash
sudo chown 1000:1000 data data/app.db
sudo chmod 750 data
```
8. Start the app again. Startup still removes personal details that are past the retention period. Check `/healthz` and a roster before treating the restore as finished.
A backup taken before a cleanup still contains the old names and email addresses. Restoring it brings those details back into the live database.
+6
View File
@@ -0,0 +1,6 @@
import { runSeedCli } from '../src/dev/seed.ts';
runSeedCli().catch((err) => {
console.error(err instanceof Error ? err.message : err);
process.exit(1);
});
+123
View File
@@ -0,0 +1,123 @@
import crypto from 'node:crypto';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const HEADER_RE = /^\/\* Hope Volunteer brand tokens[\s\S]*?\*\/\r?\n+/;
const LICENSE_NAMES = new Set(['OFL.txt', 'OFL.md', 'LICENSE', 'LICENSE.txt', 'LICENSE.md']);
/**
* Copy tokens.css and fonts from BRAND_SRC into public/brand.
* This is a development and build-prep step, not a runtime dependency.
* A missing source keeps the files already in public/brand.
*/
export function syncBrand({ source, dest, syncedAt }) {
const resolvedSource = path.resolve(source);
const resolvedDest = path.resolve(dest);
const warnings = [];
if (!fs.existsSync(resolvedSource) || !fs.statSync(resolvedSource).isDirectory()) {
warnings.push(
`Brand source not found at ${resolvedSource}. Keeping the existing assets in ${resolvedDest}.`,
);
return { copied: false, warnings, fonts: [] };
}
fs.mkdirSync(resolvedDest, { recursive: true });
const tokensPath = path.join(resolvedSource, 'tokens.css');
if (!isFile(tokensPath)) {
warnings.push(`No tokens.css in ${resolvedSource}. Keeping the current tokens.css.`);
} else {
const css = fs.readFileSync(tokensPath, 'utf8');
const body = css.replace(HEADER_RE, '');
const header = `/* Hope Volunteer brand tokens\n Source: ${resolvedSource}\n Synced: ${syncedAt}\n Generated by scripts/sync-brand.mjs. Do not add this header to font files.\n*/\n`;
replaceFile(path.join(resolvedDest, 'tokens.css'), header + body);
}
const fontsDest = path.join(resolvedDest, 'fonts');
fs.mkdirSync(fontsDest, { recursive: true });
const fonts = [];
const fontsSource = path.join(resolvedSource, 'fonts');
if (fs.existsSync(fontsSource) && fs.statSync(fontsSource).isDirectory()) {
for (const entry of fs.readdirSync(fontsSource, { withFileTypes: true })) {
if (!entry.isFile()) continue;
const from = path.join(fontsSource, entry.name);
const to = path.join(fontsDest, entry.name);
replaceFile(to, fs.readFileSync(from));
fonts.push(fileRecord(entry.name, to));
}
}
const licenses = [];
for (const name of LICENSE_NAMES) {
const from = path.join(resolvedSource, name);
if (!isFile(from)) continue;
const to = path.join(resolvedDest, name);
replaceFile(to, fs.readFileSync(from));
licenses.push(fileRecord(name, to));
}
const manifest = {
source: resolvedSource,
syncedAt,
note:
fonts.length === 0
? 'No self-hosted font files were in the source. The app falls back to system-ui and cursive. Files already in the destination that were not in the source were left in place.'
: 'Files already in the destination that were not in the source were left in place.',
fonts,
licenses,
};
replaceFile(path.join(resolvedDest, 'fonts.manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`);
return { copied: true, warnings, fonts };
}
function replaceFile(destination, contents) {
const temporary = `${destination}.next`;
fs.writeFileSync(temporary, contents);
fs.renameSync(temporary, destination);
}
function fileRecord(file, fullPath) {
const bytes = fs.readFileSync(fullPath);
return {
file,
bytes: bytes.length,
sha256: crypto.createHash('sha256').update(bytes).digest('hex'),
};
}
function isFile(file) {
return fs.existsSync(file) && fs.statSync(file).isFile();
}
function readEnvFile(file) {
if (!fs.existsSync(file)) return;
for (const line of fs.readFileSync(file, 'utf8').split('\n')) {
const trimmed = line.trim();
if (trimmed === '' || trimmed.startsWith('#')) continue;
const eq = trimmed.indexOf('=');
if (eq === -1) continue;
const key = trimmed.slice(0, eq).trim();
let value = trimmed.slice(eq + 1).trim();
if (
(value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))
) {
value = value.slice(1, -1);
}
if (process.env[key] === undefined) process.env[key] = value;
}
}
const entry = process.argv[1];
if (entry && import.meta.url === pathToFileURL(path.resolve(entry)).href) {
readEnvFile(path.join(projectRoot, '.env'));
const source = process.env.BRAND_SRC ?? '../Hope Food Pantry Website/brand';
const result = syncBrand({
source,
dest: path.join(projectRoot, 'public/brand'),
syncedAt: new Date().toISOString(),
});
for (const warning of result.warnings) console.warn(warning);
if (result.copied) console.log(`Brand sync wrote ${result.fonts.length} font file(s).`);
}