Repository navigation
ONE-168 nav v1 子单 A:后端与仓库骨架(D1 schema、鉴权、三组 API、setup) - #2
Merged
Merged
Conversation
…ate/admin APIs, setup) - Monorepo: worker/ (Hono + D1) + web/ (placeholder for frontend sub-issue) - D1 schema & idempotent migrations: users, passkey_credentials, sessions, login_attempts, challenges, categories, links, search_engines, settings - Auth (single-owner, no registration): password login + TOTP 2FA, Passkey (WebAuthn via @simplewebauthn/server v14, eNotify-aligned), HttpOnly/Secure/ SameSite session cookie backed by sessions table, login throttling + 15-min lockout after 5 consecutive failures, X-Setup-Secret owner setup that closes permanently once created - APIs per frozen contract (docs/api-contract.md): GET /api/public (public categories/links only, publicly cacheable), GET /api/private (session required, 401 JSON + no-store otherwise), /api/admin/* CRUD + reorder for categories/links/search_engines/settings - Visibility = stricter of category and link; private rows never appear in public payloads - GitHub Actions: CI (lint/format/typecheck/build/test) and deploy to Cloudflare via wrangler-action; secrets documented in README - Tests: 17 vitest cases (real in-memory SQLite) covering migrations idempotence, public/private isolation, 401 contract, setup lifecycle, password+TOTP login, lockout
Blocking: - B1 deploy.yml: replace broken inline node -e with scripts/materialize-secrets.mjs (validated locally, 0600 perms, missing- secret guard) - B2 CI red: pnpm format applied, unused readJson import removed, biome schema migrated (2.5.0 -> 2.6.2), generated schema file excluded from formatter - B3 root deploy script now targets the real worker deploy (pnpm --filter worker deploy) Should-fix: - S1 links table: reserved SPEC §5 columns click_count / status / last_checked_at; Link type updated; contract doc synced - S2 admin link DTO now includes visibility + createdAt/updatedAt (PUT + GET /api/admin/links) per frozen contract - S3 ensureSchema runs at most once per isolate (in-memory flag) - S4 passkey auth success path clears stale failure counters - S5 deleting a category explicitly deletes its links (D1 does not enforce FKs); covered by regression test Nits: - N1 scheduled handler kept; cron trigger intentionally not enabled for v1 (cleanup is opportunistic on session ops), noted in README - N2 .dev.vars.example comments now use # comments - N3 dynamic UPDATE builders validate column names against whitelists Tests: 20 passed (adds orphan-link regression, admin DTO contract test, reserved-columns schema test)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
对应 Multica 子单 ONE-168(父单 ONE-167)。后端全部与仓库骨架;前端由兄弟子单在
web/开发。改了什么
worker/Hono + D1、web/前端占位)、Workers Static Assets、wrangler.toml含 D1 binding。worker/src/db/schema.sql,全部IF NOT EXISTS / OR IGNORE,可重复执行):users、passkey_credentials、sessions、login_attempts、challenges、categories、links、search_engines、settings。links.icon_url 可空;点击计数、健康状态按 SPEC 预留不实现。@simplewebauthn/serverv14(eNotify 同款库),凭证存passkey_credentialsnav_sessionCookie,HttpOnly / Secure / SameSite=Lax,HS256 JWT +sessions表可吊销,7 天login_attempts,按 username+IP);/2fa/verify同 tempToken 连错 5 次作废X-Setup-Secret创建唯一所有者,创建后永久关闭docs/api-contract.md,DTO 冻结清单在内):GET /api/public:只含公开分类+公开链接(private 分类下的 public 链接也按「取更严一方」不下发),可公开缓存GET /api/private:未登录 401{"error":"unauthorized"}+Cache-Control: no-store;已登录同结构全量数据,no-store/api/admin/*:categories / links / search_engines / settings 的 CRUD 与排序更新,未登录一律 401 JSON.github/workflows/ci.yml(lint/format/typecheck/build/test)、deploy.yml(CI 绿后合并 main 自动wrangler deploy,合并关口归用户)。迁移与回滚
worker/src/db/schema.sql(幂等,读接口前自动 ensure);空库可重复执行。DROP TABLE(links 级联随 categories 删除)。自测证据
pnpm typecheck(web+worker)✅pnpm test:17 passed / 0 failed(vitest + 真 SQLite 内存库):迁移幂等 ×3、公开/私有隔离与 401 契约 ×3、setup 生命周期与无注册 ×3、密码登录/锁住 ×3、密码+TOTP 登录 ×2、登录后访问/登出 ×2(另有 TOTP secret/uri 断言)pnpm build(web+worker)✅pnpm lint/pnpm format:check✅wrangler dev实测:/api/public无任何私有数据(含 private 分类下 public 链接)、/api/private未登录 401 + no-store、setup 创建后关闭、密码登录 + TOTP 两步登录各走通、5 次失败后 429 锁定、passkey 注册 options 正常(浏览器侧断言需真实认证器,留待前端联调)需要用户配置的 Secrets(凭证不入库)
CLOUDFLARE_API_TOKEN、CLOUDFLARE_ACCOUNT_ID、SESSION_SECRET(≥16 位随机)、SETUP_SECRET;wrangler.toml中CLOUDFLARE_ACCOUNT_ID_PLACEHOLDER/D1_DATABASE_ID_PLACEHOLDER需替换实际值。与 eNotify/Zeta 的对齐说明
X-Setup-Secret之外的运维路径(重置方式在后续子单/运维文档明确),不开放自助找回,避免引入邮件依赖。此处如需调整请父单拍板。