@autional/shared 0.1.0-rc.42 → 0.1.0-rc.43
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
CHANGED
package/src/api/client.ts
CHANGED
|
@@ -182,6 +182,10 @@ export function createApiClient(baseUrl: string): AxiosInstance {
|
|
|
182
182
|
const instance = axios.create({
|
|
183
183
|
baseURL: baseUrl,
|
|
184
184
|
timeout: 30000,
|
|
185
|
+
// 平台跨源只认 Authorization 头(网关 cors.allow_credentials=false):
|
|
186
|
+
// 显式关闭凭证,避免将来默认值/调用方改动把 cookie 带进跨源请求
|
|
187
|
+
// (带凭证的跨源要求网关回写 ACAC,而动态租户 origin 永不回写)。
|
|
188
|
+
withCredentials: false,
|
|
185
189
|
headers: { 'Content-Type': 'application/json' },
|
|
186
190
|
});
|
|
187
191
|
setupInterceptors(instance);
|
package/src/generated/types.ts
CHANGED
|
@@ -3196,6 +3196,25 @@ export interface PublicCertificationListResponse {
|
|
|
3196
3196
|
total?: number; // 总条数(平铺,便于直接读取)
|
|
3197
3197
|
}
|
|
3198
3198
|
|
|
3199
|
+
// P2 四态评估(2026-10-27)—— 手改 additive:本源生成器 scripts/generate_api_ts.py
|
|
3200
|
+
// 仍在旧 monorepo(D:/go/auth_ms_new),多仓工作区不可用;字段与 compliance-service
|
|
3201
|
+
// swagger(PublicComplianceStatusResponse / SecurityScore)逐字段对齐,重生成前勿改形状。
|
|
3202
|
+
export interface AssessmentCoveragePublic {
|
|
3203
|
+
assessed?: number; // @example 7
|
|
3204
|
+
percent?: number; // @example 70
|
|
3205
|
+
total?: number; // @example 10
|
|
3206
|
+
}
|
|
3207
|
+
|
|
3208
|
+
export interface FrameworkAssessmentPublic {
|
|
3209
|
+
controlsAssessed?: number; // @example 7
|
|
3210
|
+
controlsTotal?: number; // @example 10
|
|
3211
|
+
controlsUnknown?: number; // @example 3
|
|
3212
|
+
displayName?: string; // @example ISO/IEC 27001:2022
|
|
3213
|
+
framework?: string; // 门禁键;独立标准为空 | @example iso27001
|
|
3214
|
+
standardId?: string; // @example iso27001_2022
|
|
3215
|
+
status?: string; // compliant / non_compliant / not_assessed / evaluation_error | @example not_assessed
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3199
3218
|
export interface PublicComplianceStatusDetailResponse {
|
|
3200
3219
|
code?: number;
|
|
3201
3220
|
data?: PublicComplianceStatusResponse;
|
|
@@ -3204,13 +3223,17 @@ export interface PublicComplianceStatusDetailResponse {
|
|
|
3204
3223
|
}
|
|
3205
3224
|
|
|
3206
3225
|
export interface PublicComplianceStatusResponse {
|
|
3226
|
+
assessmentCoverage?: AssessmentCoveragePublic;
|
|
3227
|
+
assessmentVersion?: string; // @example assessment-v2
|
|
3228
|
+
evaluationError?: boolean; // 只表示"是否发生评估异常",不含内部错误串 | @example False
|
|
3229
|
+
frameworkAssessments?: FrameworkAssessmentPublic[]; // 已启用门禁的评估结果(四态 + 覆盖度)
|
|
3207
3230
|
frameworksEnabled?: string[]; // @example ['["gdpr"', '"iso27001"', '"sox"]']
|
|
3208
|
-
gdprCompliant?: boolean; // @example True
|
|
3231
|
+
gdprCompliant?: boolean; // legacy:gate 已启用且状态为 compliant 才为 true | @example True
|
|
3209
3232
|
iso27001Compliant?: boolean; // @example True
|
|
3210
3233
|
lastAuditDate?: string; // @example 2026-03-15
|
|
3211
3234
|
nextAuditDate?: string; // @example 2026-09-15
|
|
3212
3235
|
openIssuesRange?: string; // @example 1-5
|
|
3213
|
-
overallStatus?: string; // @example compliant
|
|
3236
|
+
overallStatus?: string; // compliant / non_compliant / not_assessed / evaluation_error | @example compliant
|
|
3214
3237
|
soxCompliant?: boolean; // @example True
|
|
3215
3238
|
}
|
|
3216
3239
|
|
|
@@ -3565,12 +3588,14 @@ export interface ScoreSnapshotItem {
|
|
|
3565
3588
|
}
|
|
3566
3589
|
|
|
3567
3590
|
export interface SecurityScore {
|
|
3591
|
+
assessmentCoverage?: AssessmentCoveragePublic;
|
|
3568
3592
|
calculatedAt?: string; // @example 2026-05-09T12:00:00Z
|
|
3569
3593
|
dimensions?: SecurityScoreDim[];
|
|
3570
3594
|
grade?: string; // @example A
|
|
3571
3595
|
maxScore?: number; // @example 100
|
|
3572
|
-
methodologyVersion?: string; // @example
|
|
3596
|
+
methodologyVersion?: string; // @example assessment-v2
|
|
3573
3597
|
overallScore?: number; // @example 94
|
|
3598
|
+
scoreAvailable?: boolean; // false = 无任何框架完成评估,overallScore 无意义 | @example True
|
|
3574
3599
|
}
|
|
3575
3600
|
|
|
3576
3601
|
export interface SecurityScoreDim {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
4
|
-
import { renderHook, cleanup } from '@testing-library/react';
|
|
4
|
+
import { renderHook, cleanup, waitFor } from '@testing-library/react';
|
|
5
5
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
6
6
|
|
|
7
7
|
// ============================================================
|
|
@@ -10,11 +10,12 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
|
10
10
|
// 而 RequireAuth(唯一登录交棒点)在 Outlet 内 ⇒ 无会话冷启动永停 Spin。
|
|
11
11
|
// ============================================================
|
|
12
12
|
|
|
13
|
-
const { mockQueries } = vi.hoisted(() => ({
|
|
13
|
+
const { mockQueries, mockProfileAvatar } = vi.hoisted(() => ({
|
|
14
14
|
mockQueries: {
|
|
15
15
|
perms: { data: undefined as unknown, isError: false },
|
|
16
16
|
tenants: { data: undefined as unknown, isError: false },
|
|
17
17
|
},
|
|
18
|
+
mockProfileAvatar: vi.fn(),
|
|
18
19
|
}));
|
|
19
20
|
|
|
20
21
|
vi.mock('../../auth/auth-queries', () => ({
|
|
@@ -22,6 +23,11 @@ vi.mock('../../auth/auth-queries', () => ({
|
|
|
22
23
|
useTenantsQuery: () => mockQueries.tenants,
|
|
23
24
|
}));
|
|
24
25
|
|
|
26
|
+
// U447:启动补读头像走生成客户端(动态 import);此处拦截模块,避免测试打真实网络。
|
|
27
|
+
vi.mock('../../generated/api', () => ({
|
|
28
|
+
profileAvatar: mockProfileAvatar,
|
|
29
|
+
}));
|
|
30
|
+
|
|
25
31
|
import { useBootstrap } from '../useBootstrap';
|
|
26
32
|
import { useAuthStore } from '../../auth/store';
|
|
27
33
|
|
|
@@ -50,6 +56,8 @@ describe('useBootstrap(F-W5b 无会话语义)', () => {
|
|
|
50
56
|
resetAuthStore();
|
|
51
57
|
mockQueries.perms = { data: undefined, isError: false };
|
|
52
58
|
mockQueries.tenants = { data: undefined, isError: false };
|
|
59
|
+
mockProfileAvatar.mockReset();
|
|
60
|
+
mockProfileAvatar.mockResolvedValue({});
|
|
53
61
|
});
|
|
54
62
|
|
|
55
63
|
afterEach(() => {
|
|
@@ -88,4 +96,33 @@ describe('useBootstrap(F-W5b 无会话语义)', () => {
|
|
|
88
96
|
const { result } = renderHook(() => useBootstrap(), { wrapper });
|
|
89
97
|
expect(result.current).toBe('loading');
|
|
90
98
|
});
|
|
99
|
+
|
|
100
|
+
// U447:登录响应与 /auth/me 都不含 avatarUrl —— 启动必须补读一次 profile 头像,
|
|
101
|
+
// 否则换浏览器/新登录后顶栏头像恒为首字母。
|
|
102
|
+
it('U447:有会话 → 补读 /profile/avatar 并写回认证快照', async () => {
|
|
103
|
+
useAuthStore.setState({
|
|
104
|
+
accessToken: 'token-xyz',
|
|
105
|
+
user: { id: 'u-1', username: 'demo', email: 'demo@example.com', status: 'active' },
|
|
106
|
+
permissions: ['user.read'],
|
|
107
|
+
tenants: [{ id: 't1', name: 'demo', role: 'member' }],
|
|
108
|
+
});
|
|
109
|
+
mockProfileAvatar.mockResolvedValue({ avatarUrl: 'https://cdn.example.com/a.png' });
|
|
110
|
+
renderHook(() => useBootstrap(), { wrapper });
|
|
111
|
+
await waitFor(() =>
|
|
112
|
+
expect(useAuthStore.getState().user?.avatarUrl).toBe('https://cdn.example.com/a.png'),
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('U447:头像接口失败/为空 → 快照保持原样(展示层回落首字母)', async () => {
|
|
117
|
+
useAuthStore.setState({
|
|
118
|
+
accessToken: 'token-xyz',
|
|
119
|
+
user: { id: 'u-1', username: 'demo', email: 'demo@example.com', status: 'active' },
|
|
120
|
+
permissions: ['user.read'],
|
|
121
|
+
tenants: [{ id: 't1', name: 'demo', role: 'member' }],
|
|
122
|
+
});
|
|
123
|
+
mockProfileAvatar.mockRejectedValue(new Error('profile down'));
|
|
124
|
+
renderHook(() => useBootstrap(), { wrapper });
|
|
125
|
+
await waitFor(() => expect(mockProfileAvatar).toHaveBeenCalled());
|
|
126
|
+
expect(useAuthStore.getState().user?.avatarUrl).toBeUndefined();
|
|
127
|
+
});
|
|
91
128
|
});
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -59,6 +59,10 @@ function shallowEqual(a: AuthSnapshot, b: AuthSnapshot): boolean {
|
|
|
59
59
|
if (a.currentTenantId !== b.currentTenantId) return false;
|
|
60
60
|
if (a.user?.username !== b.user?.username) return false;
|
|
61
61
|
if (a.user?.email !== b.user?.email) return false;
|
|
62
|
+
// 头像/展示名可在登录后原地更新(个人资料页上传头像、magic-link 补全资料):
|
|
63
|
+
// 不参与比较时快照被判定"未变化",顶部头像会停在旧值直到刷新页面。
|
|
64
|
+
if (a.user?.avatarUrl !== b.user?.avatarUrl) return false;
|
|
65
|
+
if (a.user?.displayName !== b.user?.displayName) return false;
|
|
62
66
|
if (a.permissions.length !== b.permissions.length) return false;
|
|
63
67
|
if (a.tenants.length !== b.tenants.length) return false;
|
|
64
68
|
// 简化的数组比较:内容变更时下个事件循环会触发重新计算
|
|
@@ -46,6 +46,33 @@ export function useBootstrap(): BootstrapState {
|
|
|
46
46
|
}
|
|
47
47
|
}, [tentsQuery.data]);
|
|
48
48
|
|
|
49
|
+
// U447:头像补读 —— 登录响应与 /auth/me 都不含 avatarUrl(头像存在 profile 服务),
|
|
50
|
+
// 认证快照里的头像只在上传当次或同浏览器持久化后才有值。启动时补读一次
|
|
51
|
+
// GET /profile/avatar 并写回快照,顶栏 UserMenu 才能显示账号真实头像;
|
|
52
|
+
// 失败静默(展示层回落首字母,不影响任何业务流程)。
|
|
53
|
+
// 用动态 import 引生成客户端:generated/api 反向 import '@autional/shared',
|
|
54
|
+
// 静态导入会在包入口形成循环,动态导入等入口初始化完再求值。
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!hasToken) return;
|
|
57
|
+
let cancelled = false;
|
|
58
|
+
void import('../generated/api')
|
|
59
|
+
.then(({ profileAvatar }) => profileAvatar())
|
|
60
|
+
.then((res) => {
|
|
61
|
+
const avatarUrl = ((res as { avatarUrl?: string } | undefined)?.avatarUrl ?? '').trim();
|
|
62
|
+
if (cancelled || !avatarUrl) return;
|
|
63
|
+
const current = useAuthStore.getState().user;
|
|
64
|
+
if (current && current.avatarUrl !== avatarUrl) {
|
|
65
|
+
useAuthStore.getState().setUser({ ...current, avatarUrl });
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
.catch(() => {
|
|
69
|
+
/* 忽略:缺头像不影响启动 */
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
cancelled = true;
|
|
73
|
+
};
|
|
74
|
+
}, [hasToken]);
|
|
75
|
+
|
|
49
76
|
// 无会话 = 无数据可引导:返回 'idle',登录交棒由 RequireAuth/守卫决策(见上)。
|
|
50
77
|
// 不得返回 'loading':Layout 消费者(platform-console)以 bootstrap==='loading'
|
|
51
78
|
// 挡 Outlet,而 RequireAuth 在 Outlet 里 ⇒ 无会话冷启动永停 Spin、守卫永不挂载(F-W5b)。
|