Add Logbuch: project update blog with admin, media and API

Public archive with sidebar navigation, project pages, month archive,
search and entry pages with image blocks. Admin area for brands,
projects, post types, users, api clients, media and the entry editor
with drag and drop images, preview per audience, scheduling and
publish checks. Read and write API with bearer tokens, audience
scoping, idempotent creation, OpenAPI document and editorial guide.
Magic link login with configurable allowed domains, whole app behind
the session gate. 456 tests including design rule checks.
This commit is contained in:
Matthias Giesselmann
2026-07-31 21:33:42 +02:00
commit b90ff252d1
291 changed files with 43671 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
import { randomUUID } from 'node:crypto'
import { desc, sql } from 'drizzle-orm'
import { db } from '~/data/db'
import { auditLog, brands, projects, users, type AuditEntry, type Brand, type Project, type User } from '~/data/schema'
import type { Viewer } from '~/lib/auth-access'
export async function resetAccounts(): Promise<void> {
await db.execute(sql`truncate table audit_log, user_project_role, "user" restart identity cascade`)
}
export function form(values: Record<string, string>): FormData {
const data = new FormData()
for (const [key, value] of Object.entries(values)) {
data.set(key, value)
}
return data
}
export function adminViewer(overrides: Partial<Viewer> = {}): Viewer {
return {
id: 'admin-1',
name: 'Admin',
email: 'admin@example.test',
isAdmin: true,
assignments: [],
...overrides,
}
}
export function moderatorViewer(projectIds: string[] = [], overrides: Partial<Viewer> = {}): Viewer {
return {
id: 'moderator-1',
name: 'Moderator',
email: 'moderator@example.test',
isAdmin: false,
assignments: projectIds.map(projectId => ({ projectId, role: 'moderator' as const })),
...overrides,
}
}
export async function makeBrand(slug = 'nyo', name = 'NYO'): Promise<Brand> {
const rows = await db.insert(brands).values({ slug, name }).returning()
return rows[0]!
}
export async function makeProject(brandId: string, slug = 'trakk', name = 'Trakk'): Promise<Project> {
const rows = await db.insert(projects).values({ brandId, slug, name }).returning()
return rows[0]!
}
export async function makeUser(email = 'paul@example.test', name = 'Paul'): Promise<User> {
const rows = await db.insert(users).values({ id: randomUUID(), email, name }).returning()
return rows[0]!
}
export async function auditEntries(): Promise<AuditEntry[]> {
return db.select().from(auditLog).orderBy(desc(auditLog.createdAt))
}
+49
View File
@@ -0,0 +1,49 @@
import { randomUUID } from 'node:crypto'
import { db } from '~/data/db'
import { media, posts, type Media, type Post } from '~/data/schema'
import { postTypeId } from './post-types'
import type { EntryInput } from '~/lib/entry-types'
export async function makeMedia(projectId: string, alt: string | null = 'Ein Bild'): Promise<Media> {
const id = randomUUID()
const rows = await db.insert(media).values({
id,
projectId,
kind: 'image',
originalFilename: 'bild.png',
path: `${projectId}/${id}/original.png`,
mime: 'image/png',
width: 1200,
height: 800,
byteSize: 2048,
variants: [],
alt,
}).returning()
return rows[0]!
}
export async function makePost(projectId: string, values: Partial<typeof posts.$inferInsert> = {}): Promise<Post> {
const rows = await db.insert(posts).values({
projectId,
number: 1,
slug: 'ein-beitrag',
title: 'Ein Beitrag',
...values,
}).returning()
return rows[0]!
}
export function entryInput(projectId: string, overrides: Partial<EntryInput> = {}): EntryInput {
return {
projectId,
title: 'Regel-Engine',
teaser: 'Bedingung trifft Aktion.',
typeId: postTypeId('feature'),
audience: 'internal',
coverMediaId: null,
blocks: [{ type: 'text', data: { text: 'Der Worker prüft jede Bedingung.' } }],
...overrides,
}
}
+38
View File
@@ -0,0 +1,38 @@
import { db } from '~/data/db'
import { postTypes, type PostTypeRow } from '~/data/schema'
import { defaultPostTypes } from '~/domain/post-type'
export const fixedPostTypeIds: Record<string, string> = {
feature: '11111111-1111-4111-8111-000000000001',
improvement: '11111111-1111-4111-8111-000000000002',
fix: '11111111-1111-4111-8111-000000000003',
breaking: '11111111-1111-4111-8111-000000000004',
info: '11111111-1111-4111-8111-000000000005',
}
export function postTypeId(key: string): string {
const id = fixedPostTypeIds[key]
if (!id) {
throw new Error(`unknown post type ${key}`)
}
return id
}
export async function insertDefaultPostTypes(): Promise<void> {
await db.insert(postTypes).values(defaultPostTypes.map(row => ({ ...row, id: postTypeId(row.key) })))
}
export async function makePostType(values: Partial<typeof postTypes.$inferInsert> = {}): Promise<PostTypeRow> {
const rows = await db.insert(postTypes).values({
key: 'notiz',
labelDe: 'Notiz',
labelEn: 'Note',
color: '#4a5560',
sort: 90,
...values,
}).returning()
return rows[0]!
}