feat(server): 数据层与密钥(阶段 1)——crypto / 时间工具 / env 加载 + 建表

- crypto:HKDF 派生 hmac/aes 子密钥;HMAC-SHA256 指纹(key_hash);AES-256-GCM 加解密(nonce||tag||ct)
- time:北京时间 +08:00 ISO 序列化、Unix 秒转换、expires_at 0→null、输入宽容解析
- load-env:从仓库根 .env 显式加载(Bun 只自动加载 cwd 的 .env);drizzle.config 同步接入
- 单测 15 项全绿(bun test);db:push 后四表在库(api_keys 17 列 / usage_logs 23 列 + 索引齐)
This commit is contained in:
2026-09-15 00:18:21 +08:00
parent 1295667c94
commit 3ffbd030b9
9 changed files with 243 additions and 2 deletions
+3 -1
View File
@@ -5,6 +5,7 @@
"scripts": {
"dev": "bun run --hot src/index.ts",
"start": "bun run src/index.ts",
"test": "bun test",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push"
@@ -17,6 +18,7 @@
},
"devDependencies": {
"@types/bun": "latest",
"drizzle-kit": "^0.31.10"
"drizzle-kit": "^0.31.10",
"postgres": "^3.4.9"
}
}