feat(demo): DEMO_MODE lock, seed:demo and the demo banner (MODULE_API 1.18.0)
Core half of the public demo (docs/website/DEMO_MODE.md §10 step 1, website#222).
Nothing here runs unless DEMO_MODE=true.
- server/src/demo/: the lock at /api/v1, ahead of every router. It covers every
Tier A row of §3.3, the shared-login conditions, POST /auth/register (DM16),
DELETE /auth/me/sessions/:id on a demo account (DM17), and the PUT
/admin/settings keys that reach a Tier A lock. Any multipart request is refused
app-wide. noindex and robots.txt. A condition that cannot decide refuses.
- Loader: demoLocks in module.json (writes only, under the module's own mounts),
ctx.demoMode, and api.onDemoSeed (DM15). MODULE_API 1.18.0 on both halves.
- GET /public/settings carries demo: { resetsAt, logins } on the demo only.
- npm run seed:demo -- <fixture>: upserts the four accounts, sets the site live
with registration disabled, seeds content on the first run only, calls each
module's onDemoSeed, and stamps demo_state. It resolves $env: strings and
refuses to run off the demo.
- Client: the banner, one DEMO_LOCKED toast fed from the request primitive (so
module screens get it too), and the published logins on both sign-in pages.
Dashboard and register say the demo message instead of blaming a role.
- OpenAPI: DemoLocked schema, the demo block, and a note that any write may
answer DEMO_LOCKED on the demo.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
47
client/src/components/DemoBanner.jsx
Normal file
47
client/src/components/DemoBanner.jsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Link } from 'react-router-dom'
|
||||
import { useSite } from '../contexts/SiteContext.jsx'
|
||||
import { formatResetTime } from '../lib/demoNotice.js'
|
||||
|
||||
// The public demo's strip, on every page (docs/website/DEMO_MODE.md §6).
|
||||
// Renders nothing unless GET /public/settings carries a `demo` block, which the
|
||||
// server sends only with DEMO_MODE on — so a real shard never draws it, and the
|
||||
// banner needs no schedule of its own: `resetsAt` is stamped by every wipe.
|
||||
export default function DemoBanner() {
|
||||
const { settings } = useSite()
|
||||
const demo = settings.demo
|
||||
if (!demo) return null
|
||||
|
||||
const at = demo.resetsAt ? formatResetTime(demo.resetsAt) : null
|
||||
const names = (demo.logins || []).map((l) => l.username)
|
||||
|
||||
return (
|
||||
<div
|
||||
role="note"
|
||||
className="sans"
|
||||
style={{
|
||||
padding: '7px 16px',
|
||||
textAlign: 'center',
|
||||
fontSize: '0.82rem',
|
||||
lineHeight: 1.45,
|
||||
color: 'var(--head)',
|
||||
background: 'var(--bg-deep)',
|
||||
borderBottom: '1px solid var(--accent)',
|
||||
}}
|
||||
>
|
||||
<strong style={{ color: 'var(--accent)' }}>Demo site</strong>
|
||||
{' — anything you change is wiped '}
|
||||
{at ? `at ${at}` : 'every two hours'}.
|
||||
{names.length > 0 && (
|
||||
<>
|
||||
{' Sign-ins: '}
|
||||
{names.join(' / ')}
|
||||
{' — passwords on the '}
|
||||
<Link to="/account/login" style={{ color: 'var(--accent)' }}>
|
||||
sign-in page
|
||||
</Link>
|
||||
.
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user