Files
PIKKIE/scripts/seed-demo.mjs
T
juli d24415ecf9 PIKKIE: picky issues keeper & knitpick ideas explorer
Self-hosted beta-tester issue tracker with a Kotlin Android companion.

- Bullet-point reports (classic and rapid fire), .txt/.md import,
  evidence by paste, drag, camera or gallery
- Projects, calibers (.22 -> 12 gauge) as weights, public overview
- Threaded discussions, "me too", admin flagging with messages and files
- Board with polls and an off-topic image board with link previews
- Profiles with avatars, in-app inbox, opt-in e-mail and phone alerts
- Invites, optional open sign-up, TOTP 2FA with admin policy
- MCP endpoint with per-user API keys
- QR login both ways, built for an HTTPS reverse proxy
- Encryption at rest for 2FA secrets and the SMTP password
- Android app with full tester/admin parity, in-app updates, no Google
  services required
- Interactive first-run tutorial
2026-11-10 23:51:30 +01:00

165 lines
9.3 KiB
JavaScript

#!/usr/bin/env node
/* Fills a FRESH PIKKIE instance with demo data (fictional testers, projects, bullets, a poll…).
* PIKKIE_DATA=/tmp/pikkie-demo PORT=1313 node server/src/index.js &
* node scripts/seed-demo.mjs http://localhost:1313
* Prints the demo admin login at the end. Never run this against a real instance.
*/
import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
import { fileURLToPath } from 'node:url';
const BASE = (process.argv[2] || 'http://localhost:1313').replace(/\/$/, '');
const here = path.dirname(fileURLToPath(import.meta.url));
const PW = crypto.randomBytes(9).toString('base64url');
const jars = {};
async function call(who, method, url, body) {
const headers = {};
if (jars[who]) headers.cookie = jars[who];
let payload = body;
if (body && !(body instanceof FormData)) {
headers['content-type'] = 'application/json';
payload = JSON.stringify(body);
}
const r = await fetch(BASE + url, { method, headers, body: payload });
const sc = r.headers.get('set-cookie');
if (sc) jars[who] = sc.split(';')[0];
const j = await r.json().catch(() => ({}));
if (!r.ok) throw new Error(`${method} ${url}: ${j.error || r.status}`);
return j;
}
const status = await call('anon', 'GET', '/api/status');
if (!status.needs_setup) {
console.error('This instance is already set up. The demo seeder only runs on a fresh, empty instance.');
process.exit(1);
}
const people = {
admin: { email: 'captain@demo.test', name: 'Captain Picky' },
mosh: { email: 'mosh@demo.test', name: 'Mosh' },
riot: { email: 'riot@demo.test', name: 'Riot Grrl' },
nul: { email: 'null@demo.test', name: 'NullPointer' },
sk8: { email: 'sk8@demo.test', name: 'Sk8 Vicious' },
};
await call('admin', 'POST', '/api/setup', { ...people.admin, password: PW });
for (const k of ['mosh', 'riot', 'nul', 'sk8']) {
await call('admin', 'POST', '/api/admin/users', { ...people[k], password: PW, role: 'tester' });
await call(k, 'POST', '/api/login', { email: people[k].email, password: PW });
}
const proj = {};
await call('admin', 'PATCH', '/api/admin/projects/1', { name: 'Website', description: 'The marketing site + web app', color: '#6cb6ff' });
proj.web = 1;
proj.app = (await call('admin', 'POST', '/api/admin/projects', { name: 'Android app', description: 'The phone app, all flavours', color: '#3ddc97' })).id;
proj.api = (await call('admin', 'POST', '/api/admin/projects', { name: 'Sync engine', description: 'Offline sync & backend', color: '#ff2e93' })).id;
const logoPng = fs.existsSync(path.join(here, '..', 'docs', 'assets', 'attachment.png'))
? fs.readFileSync(path.join(here, '..', 'docs', 'assets', 'attachment.png'))
: null;
async function report(who, project, bullets, { weight, version, files = [] } = {}) {
const fd = new FormData();
fd.append('bullets', bullets);
fd.append('project_id', String(project));
if (weight) fd.append('weight', String(weight));
if (version) fd.append('version', version);
for (const [name, buf, type] of files) fd.append('files', new Blob([buf], { type }), name);
return (await call(who, 'POST', '/api/reports', fd)).ids;
}
async function flag(id, status, message) {
const fd = new FormData();
fd.append('status', status);
fd.append('message', message);
return call('admin', 'POST', `/api/items/${id}/status`, fd);
}
async function comment(who, id, body, parent) {
const fd = new FormData();
fd.append('body', body);
if (parent) fd.append('parent_id', String(parent));
return (await call(who, 'POST', `/api/items/${id}/comments`, fd)).id;
}
const a = await report('mosh', proj.app, '- [12g] App crashes when you rotate on the login screen\n- [.45] Toast covers the save button\n- Back button closes the app instead of going back', {
weight: 2, version: '0.9.3', files: logoPng ? [['crash-screenshot.png', logoPng, 'image/png']] : [],
});
const b = await report('riot', proj.web, '- [.22] Logo kerning is 1px off on Safari\n- [9mm] Dark mode chart legend is unreadable\n legend text is #333 on #222\n- [7.62] Password reset mail never arrives', { version: '2.1.0' });
const c = await report('nul', proj.api, '- [12 gauge] Offline edits vanish after sync conflict\n- [7.62] Sync spinner spins forever on flaky wifi', { version: '0.9.3' });
const d = await report('sk8', proj.app, '- [.22] Settings icon is slightly blurry on Pixel\n- [9mm] Haptic feedback fires twice on long-press', { version: '0.9.3' });
await flag(a[0], 'fixed', 'Rotation handled properly now. Ships in 0.9.4. Thanks for the stack trace!');
await flag(b[2], 'needs_info', 'Which mail provider? Can you check your spam folder?');
await flag(c[0], 'in_progress', 'Reproduced. Working on a merge strategy.');
await flag(b[0], 'declined', 'Safari renders it that way on purpose, we will leave it.');
await flag(d[1], 'finished', 'Single haptic now, verified on 3 devices.');
const t1 = await comment('sk8', c[0], 'Same here, lost a whole shopping list 😭');
await comment('nul', c[0], 'Happens when two devices edit the same note within ~5 seconds.', t1);
await comment('mosh', c[0], 'Can confirm on a tablet too.');
for (const who of ['mosh', 'riot', 'sk8']) await call(who, 'POST', `/api/items/${c[0]}/metoo`);
await call('riot', 'POST', `/api/items/${a[1]}/metoo`);
await comment('riot', b[2], 'Gmail. Nothing in spam either.');
const key = (await call('admin', 'POST', '/api/keys', { name: 'fixbot' })).key;
await fetch(`${BASE}/mcp`, {
method: 'POST',
headers: { authorization: `Bearer ${key}`, 'content-type': 'application/json' },
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'submit_bullets', arguments: { project: 'Sync engine', bullets: ['[7.62] Retry loop ignores HTTP 429 Retry-After header'] } } }),
});
await fetch(`${BASE}/mcp`, {
method: 'POST',
headers: { authorization: `Bearer ${key}`, 'content-type': 'application/json' },
body: JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'set_status', arguments: { id: c[1], status: 'fixed', message: 'Added exponential backoff with jitter and a 30s cap. PR #42.' } } }),
});
const poll = (await call('riot', 'POST', '/api/posts', { type: 'poll', title: 'Codename for the next release?', body: 'Vote, picky ones 🤘', options: ['Safety Pin', 'Mohawk', 'Tiny Riot'] })).id;
const opts = (await call('riot', 'GET', `/api/posts/${poll}`)).options;
await call('mosh', 'POST', `/api/posts/${poll}/vote`, { option_id: opts[2].id });
await call('sk8', 'POST', `/api/posts/${poll}/vote`, { option_id: opts[2].id });
await call('nul', 'POST', `/api/posts/${poll}/vote`, { option_id: opts[1].id });
await call('admin', 'POST', `/api/posts/${poll}/pin`, { pinned: true });
const post = (await call('mosh', 'POST', '/api/posts', { title: 'Beta 0.9.3 feels fast!', body: 'Startup went from 3s to under 1s on my old phone. Nice work.' })).id;
await call('nul', 'POST', `/api/posts/${post}/replies`, { body: 'Agreed, scrolling is buttery now.' });
await call('admin', 'POST', '/api/admin/invites', { emails: 'newbie@demo.test, punk@demo.test', message: 'Welcome to the beta!' });
// --- social: avatars, bios, off-topic board
const art = (f) => {
const fp = path.join(here, '..', 'docs', 'assets', 'demo', f);
return fs.existsSync(fp) ? fs.readFileSync(fp) : null;
};
const bios = {
admin: ['captain', 'Herding bugs since 2009. Will flag your bullet as needs-info at 3am.'],
mosh: ['mosh', 'Android power user. Rotates screens for fun. 12 gauge enthusiast.'],
riot: ['riot', 'Front-end nitpicker. If it is 1px off, I will find it.'],
nul: ['null', 'Breaks sync engines for a living. Ask me about race conditions.'],
sk8: ['sk8', 'Tests on 6 phones, one of them held together with tape.'],
};
for (const [who, [file, bio]] of Object.entries(bios)) {
const png = art(`av-${file}.png`);
if (png) {
const fd = new FormData();
fd.append('avatar', new Blob([png], { type: 'image/png' }), 'avatar.png');
await call(who, 'POST', '/api/me/avatar', fd);
}
await call(who, 'PATCH', '/api/me', { bio, tutorial_done: true }); // demo users skip the first-run tour
}
async function boardPost(who, board, title, body, images = []) {
const fd = new FormData();
fd.append('board', board);
fd.append('title', title);
fd.append('body', body);
for (const f of images) { const b = art(f); if (b) fd.append('files', new Blob([b], { type: 'image/png' }), f); }
return (await call(who, 'POST', '/api/posts', fd)).id;
}
const m1 = await boardPost('mosh', 'offtopic', 'every single standup', 'you know the one', ['meme-works.png']);
await boardPost('riot', 'offtopic', 'my QA lead, apparently', '', ['meme-cat.png']);
await boardPost('nul', 'offtopic', 'new desk setup 🎛️', 'finally cable-managed. ignore the 14 test phones.', ['meme-setup.png', 'meme-works.png']);
if (process.env.DEMO_OFFLINE !== '1') await boardPost('sk8', 'offtopic', 'testing soundtrack', 'this is what I blast while hunting 12 gauges https://www.youtube.com/watch?v=dQw4w9WgXcQ');
const rfd = new FormData();
rfd.append('body', 'literally me yesterday 😂');
const cat = art('meme-cat.png');
if (cat) rfd.append('files', new Blob([cat], { type: 'image/png' }), 'reply.png');
await call('riot', 'POST', `/api/posts/${m1}/replies`, rfd);
console.log(`Demo ready on ${BASE}\n admin: ${people.admin.email}\n testers: ${['mosh', 'riot', 'nul', 'sk8'].map((k) => people[k].email).join(', ')}\n password (all): ${PW}`);