@allbluecn/admin-app 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/components/user-avatar.tsx +2 -2
- package/src/lib/__tests__/avatar-shape.test.ts +17 -1
- package/src/lib/avatar-shape.ts +9 -0
- package/src/server/__tests__/security-headers.test.ts +29 -0
- package/src/server/middlewares/security-headers.ts +6 -1
- package/src/server/serverFns/dependency/sync.ts +6 -1
- package/src/start.ts +33 -18
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbluecn/admin-app",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@allbluecn/database": "0.
|
|
9
|
-
"@allbluecn/kernel": "0.
|
|
8
|
+
"@allbluecn/database": "0.12.1",
|
|
9
|
+
"@allbluecn/kernel": "0.12.0",
|
|
10
10
|
"@auth/core": "^0.41.2",
|
|
11
11
|
"@base-ui/react": "^1.8.0",
|
|
12
12
|
"@fontsource-variable/inter": "^5.3.0",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
import { NotionAvatar } from "./notion-avatar"
|
|
20
|
-
import { toAvatarShape } from "@/lib/avatar-shape"
|
|
20
|
+
import { hasAvatarConfig, toAvatarShape } from "@/lib/avatar-shape"
|
|
21
21
|
import type { AvatarConfig } from "@allbluecn/kernel"
|
|
22
22
|
|
|
23
23
|
type UserAvatarProps = {
|
|
@@ -56,7 +56,7 @@ export function UserAvatar({
|
|
|
56
56
|
const shapeClass =
|
|
57
57
|
shape === "circle" ? "rounded-full" : shape === "square" ? "rounded-none" : "rounded-lg"
|
|
58
58
|
|
|
59
|
-
if (avatarConfig) {
|
|
59
|
+
if (hasAvatarConfig(avatarConfig)) {
|
|
60
60
|
return (
|
|
61
61
|
<NotionAvatar
|
|
62
62
|
config={avatarConfig}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
18
|
import { describe, it, expect } from "vitest";
|
|
19
|
-
import { AVATAR_SHAPES, toAvatarShape } from "../avatar-shape";
|
|
19
|
+
import { AVATAR_SHAPES, hasAvatarConfig, toAvatarShape } from "../avatar-shape";
|
|
20
20
|
|
|
21
21
|
describe("AVATAR_SHAPES", () => {
|
|
22
22
|
it("与 kernel ShapeType 三值一致", () => {
|
|
@@ -42,3 +42,19 @@ describe("toAvatarShape", () => {
|
|
|
42
42
|
expect(toAvatarShape(undefined)).toBeNull();
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
|
+
|
|
46
|
+
describe("hasAvatarConfig", () => {
|
|
47
|
+
it("空对象(DB 列默认值)不算已配置", () => {
|
|
48
|
+
expect(hasAvatarConfig({})).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("空值不算已配置", () => {
|
|
52
|
+
expect(hasAvatarConfig(null)).toBe(false);
|
|
53
|
+
expect(hasAvatarConfig(undefined)).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("非空对象算已配置", () => {
|
|
57
|
+
expect(hasAvatarConfig({ face: 0 })).toBe(true);
|
|
58
|
+
expect(hasAvatarConfig({ face: 3, hair: 1 })).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
package/src/lib/avatar-shape.ts
CHANGED
|
@@ -33,3 +33,12 @@ export const AVATAR_SHAPES = [
|
|
|
33
33
|
export function toAvatarShape(v: string | null | undefined): ShapeType | null {
|
|
34
34
|
return AVATAR_SHAPES.find((shape) => shape === v) ?? null
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* DB 列默认值是空对象 `avatarConfig Json? @default("{}")`——`{}` 为 truthy,
|
|
39
|
+
* 直接 if 判断会走 NotionAvatar 渲染出「白底空脸」隐形框(部件 SVG 404)。
|
|
40
|
+
* 与 web 端 shared-kit/avatars/avatar-shape.ts 同构(双端 UI 不共享,各自维护)。
|
|
41
|
+
*/
|
|
42
|
+
export function hasAvatarConfig(config: unknown): config is Record<string, unknown> {
|
|
43
|
+
return !!config && typeof config === "object" && Object.keys(config).length > 0
|
|
44
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from "vitest";
|
|
6
|
+
import { buildSecurityHeaders } from "../middlewares/security-headers";
|
|
7
|
+
|
|
8
|
+
// CSP script-src 必须含 'unsafe-inline':TanStack Start SSR 向 HTML 注入内联
|
|
9
|
+
// dehydration 脚本(window.$_TSR),收紧为 'self' 会拦截 hydration → 客户端
|
|
10
|
+
// 崩溃整站按钮死(web 端 2026-09-11 Pro 生产已复现的同型事故;admin 生产
|
|
11
|
+
// CSP 曾缺失该指令,2026-10-30 修复)。本测试钉死该教训。
|
|
12
|
+
function csp(prod: boolean): string {
|
|
13
|
+
const headers = buildSecurityHeaders(prod);
|
|
14
|
+
return headers["Content-Security-Policy"] ?? "";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("security-headers CSP", () => {
|
|
18
|
+
it("生产 script-src 含 'unsafe-inline'(dehydration 内联脚本必需)", () => {
|
|
19
|
+
expect(csp(true)).toMatch(/script-src[^;]*'unsafe-inline'/);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("开发 script-src 含 'unsafe-inline'", () => {
|
|
23
|
+
expect(csp(false)).toMatch(/script-src[^;]*'unsafe-inline'/);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("生产附带 HSTS", () => {
|
|
27
|
+
expect(buildSecurityHeaders(true)["Strict-Transport-Security"]).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -20,7 +20,12 @@ import { rebuildResponse, responseOf } from './middleware-utils'
|
|
|
20
20
|
|
|
21
21
|
const PROD_CSP = [
|
|
22
22
|
"default-src 'self'",
|
|
23
|
-
|
|
23
|
+
// ⚠ 必须含 'unsafe-inline':TanStack Start SSR 向 HTML 注入内联 dehydration 脚本
|
|
24
|
+
// (window.$_TSR,每请求变化,hash/nonce 均不可用——start-server-core 无 SSR
|
|
25
|
+
// nonce 注入)。收紧为 'self' 会拦截 hydration 脚本 → $_TSR undefined → 客户端
|
|
26
|
+
// 崩溃整站按钮死(web 端同型事故 Pro 生产 2026-09-11 已复现,教训见
|
|
27
|
+
// apps/web/src/server/middlewares/security-headers.ts 头注)。
|
|
28
|
+
"script-src 'self' 'unsafe-inline'",
|
|
24
29
|
"style-src 'self' 'unsafe-inline'",
|
|
25
30
|
"img-src 'self' data: blob: https:",
|
|
26
31
|
"font-src 'self' data:",
|
|
@@ -21,7 +21,12 @@ import { z } from "zod"
|
|
|
21
21
|
import { getPrisma } from "@allbluecn/database/get-prisma"
|
|
22
22
|
import type { SyncDependencyResult } from "@allbluecn/kernel"
|
|
23
23
|
import { requireAdmin } from "@/server/auth-helpers"
|
|
24
|
-
import {
|
|
24
|
+
import { syncOneDependency } from "@/server/dependency/helpers"
|
|
25
|
+
|
|
26
|
+
// 包名正则本地定义(勿从 helpers import):本文件在模块顶层 zod schema 中消费
|
|
27
|
+
// 该绑定,客户端 split stub 会保留顶层 import——helpers 引 node:fs/get-prisma,
|
|
28
|
+
// 会把 server-only 链拖进浏览器(口径⑤,check-serverfn-purity)
|
|
29
|
+
const NPM_PACKAGE_NAME_PATTERN = /^(@[a-z0-9-][a-z0-9-._]*\/)?[a-z0-9-][a-z0-9-._]{0,213}$/i
|
|
25
30
|
|
|
26
31
|
const packageNameSchema = z
|
|
27
32
|
.string()
|
package/src/start.ts
CHANGED
|
@@ -22,13 +22,13 @@ import {
|
|
|
22
22
|
import { createStart, createMiddleware, createCsrfMiddleware } from '@tanstack/react-start'
|
|
23
23
|
import { securityHeadersMiddleware } from '@/server/middlewares/security-headers'
|
|
24
24
|
import { requestContextMiddleware } from '@/server/middlewares/request'
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
|
|
26
|
+
// ⚠ start.ts 是同构文件(start-client-core hydrateStart 在客户端静态加载本模块),
|
|
27
|
+
// 顶层值 import 链会整体进入浏览器 bundle。@/server/observability 的 index re-export
|
|
28
|
+
// 含 health-check(顶层 import node:fs/promises + get-prisma)——静态引入会令客户端
|
|
29
|
+
// 模块图在求值期直接抛错(browser-external 代理 / dotenv),整站 hydration 死亡、
|
|
30
|
+
// 所有按钮无响应(2026-10-30 实锤)。observability 全链必须在 SSR 守卫内动态 import;
|
|
31
|
+
// 客户端图守护测试见 src/server/__tests__/start-client-graph.test.ts。
|
|
32
32
|
|
|
33
33
|
const csrfMiddleware = createCsrfMiddleware({
|
|
34
34
|
filter: (ctx) => ctx.handlerType === 'serverFn',
|
|
@@ -87,17 +87,32 @@ const apiCorsMiddleware = createMiddleware().server(async ({ request, next }) =>
|
|
|
87
87
|
return { ...result, response }
|
|
88
88
|
})
|
|
89
89
|
|
|
90
|
-
if (typeof process !== 'undefined' && process.versions?.node && process.env.NODE_ENV !== 'test') {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
if (import.meta.env.SSR && typeof process !== 'undefined' && process.versions?.node && process.env.NODE_ENV !== 'test') {
|
|
91
|
+
void (async () => {
|
|
92
|
+
try {
|
|
93
|
+
const { initErrorCollector, getHealthCheckEnabled, startHealthCheckTimer } = await import('@/server/observability')
|
|
94
|
+
initErrorCollector()
|
|
95
|
+
const enabled = await getHealthCheckEnabled()
|
|
96
|
+
if (enabled) {
|
|
97
|
+
startHealthCheckTimer(30_000)
|
|
98
|
+
}
|
|
99
|
+
} catch (e: unknown) {
|
|
100
|
+
console.error('[HealthCheckInit]', e)
|
|
96
101
|
}
|
|
97
|
-
})
|
|
102
|
+
})()
|
|
98
103
|
}
|
|
99
104
|
|
|
100
|
-
export const startInstance = createStart(() =>
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
export const startInstance = createStart(async () => {
|
|
106
|
+
// observability/debug 仅服务端管线需要,SSR 守卫内动态引入并保持原相对顺序
|
|
107
|
+
// (securityHeaders → sentry → requestContext → observability → debug → apiCors → csrf)
|
|
108
|
+
const requestMiddleware = [securityHeadersMiddleware, sentryGlobalRequestMiddleware, requestContextMiddleware]
|
|
109
|
+
if (import.meta.env.SSR) {
|
|
110
|
+
const { observabilityMiddleware, debugMiddleware } = await import('@/server/observability')
|
|
111
|
+
requestMiddleware.push(observabilityMiddleware, debugMiddleware)
|
|
112
|
+
}
|
|
113
|
+
requestMiddleware.push(apiCorsMiddleware, csrfMiddleware)
|
|
114
|
+
return {
|
|
115
|
+
requestMiddleware,
|
|
116
|
+
functionMiddleware: [sentryGlobalFunctionMiddleware],
|
|
117
|
+
}
|
|
118
|
+
})
|