@autional/shared 0.1.0-rc.58 → 0.1.0-rc.60

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.
@@ -1,349 +1,349 @@
1
- /**
2
- * 门户注册表 —— **门户元数据的单一真源**。
3
- *
4
- * 过去「门户清单」被写了十几次(`PORTAL_DEFAULTS` / `SLUG_PORTALS` /
5
- * `getAppPortalSlugs()` / 重定向白名单 / `isPortalVisible` 的角色集 /
6
- * `DEFAULT_EXCLUDE` / `PORTAL_KEY_MAP`,以及 6 个站点各持一份 `CONSOLE_PORTALS`)。
7
- * 每加一个门户要改 7 个仓,且靠"进名单"才可见(小圈子)。
8
- *
9
- * 现在只有这张表。其余全部由它派生:
10
- *
11
- * 表字段 → 派生
12
- * host / base → config.PORTAL_DEFAULTS、getPortalUrl()
13
- * slugScoped → config.SLUG_PORTALS(入口是否拼 /<tenantSlug>)
14
- * routerSlug → config.getAppPortalSlugs()(/<tenant>/<portal> 路由 basename)
15
- * legacyEnvKey → config.PORTAL_KEY_MAP(旧 env.js VITE_*_URL)
16
- * — → getAllowedRedirectOrigins()(redirect 白名单 = 全部 code)
17
- * audience → hooks.isPortalVisible()(谁能看见:入口门禁的镜像)
18
- * inSwitcher → usePortalCatalog DEFAULT_EXCLUDE(默认排除 = !inSwitcher)
19
- * family='console' → getConsolePortalCodes()(控制台切换器全集,替代各站白名单)
20
- *
21
- * 新增门户 = 在这里加一行(若后端目录已透出 host/base,则连这一行都可省)。
22
- * **禁止**在其它文件再写门户 code 字面量数组/Set。
23
- */
24
-
25
- /** 可见性受众 = 登录入口门禁的镜像(谁能登录,谁才看见)。 */
26
- export type PortalAudience = 'public' | 'admin' | 'platform';
27
-
28
- /**
29
- * 门户族群:
30
- * - `console`:管理面/用户面控制台(互相出现在切换器里)
31
- * - `content`:内容站(developer / status / trust / brand / docs …)
32
- * - `app`:App 形态(authenticator:TOTP/push,不列入桌面切换器)
33
- * - `auth` / `landing`:认证与落地站,非切换目标
34
- */
35
- export type PortalFamily = 'console' | 'content' | 'app' | 'auth' | 'landing';
36
-
37
- export interface PortalDefinition {
38
- /** 门户 code(后端 applications.code,全环境同值) */
39
- code: string;
40
- /** 子域前缀;空串 = 落在根域(landing) */
41
- host: string;
42
- /** 子域下的固定路径前缀(env 可覆盖,如 admin 的 '/admin') */
43
- base: string;
44
- /** 入口是否拼租户段 `/<slug>`(拼错会命中不存在的路由 ⇒ 空白/404) */
45
- slugScoped: boolean;
46
- /** 是否参与 `/<tenant>/<portal>` 路由 basename 解析 */
47
- routerSlug: boolean;
48
- /**
49
- * `getAppPortalSlugs()` 的返回顺序(历史上是 `admin, developer, security, platform, status, trust`)。
50
- * 该数组是导出 API,顺序可观测 ⇒ 用显式序号保序,而不是依赖表顺序。
51
- */
52
- routerOrder?: number;
53
- family: PortalFamily;
54
- audience: PortalAudience;
55
- /** 默认进入 `usePortalCatalog` 的门户清单(false ⇒ 进 DEFAULT_EXCLUDE) */
56
- inSwitcher: boolean;
57
- /** 旧 env.js 直连 URL 键(VITE_*_URL)→ 向后兼容映射用 */
58
- legacyEnvKey?: string;
59
- /** 备注(为什么这个门户这样配置) */
60
- note?: string;
61
- }
62
-
63
- /** 管理面平面角色集(admin / security / config / secret 的门户 = 登录入口门禁同集)。 */
64
- export const ADMIN_PLANE_ROLES: readonly string[] = [
65
- 'super_admin',
66
- 'admin',
67
- 'security_admin',
68
- 'user_manager',
69
- ];
70
-
71
- /**
72
- * 注册表本体(顺序 = 重定向白名单推导顺序)。
73
- *
74
- * 前 13 项与迁移前 `PORTAL_DEFAULTS` 逐项等价(见 `__tests__/registry.test.ts` 的 oracle 断言);
75
- * 后 4 项(docs / wiki / reference / consent)是此前**漏登记**的内容站 —— 之前 `getPortalUrl('docs')`
76
- * 会退化成 `${origin}/docs`,任何控制台都链不到文档中心。这里补齐,属新增能力,不改变前 13 项行为。
77
- */
78
- export const PORTALS: readonly PortalDefinition[] = [
79
- {
80
- code: 'auth',
81
- host: 'auth',
82
- base: '',
83
- slugScoped: true,
84
- routerSlug: false,
85
- family: 'auth',
86
- audience: 'public',
87
- inSwitcher: false,
88
- legacyEnvKey: 'VITE_AUTH_PAGES_URL',
89
- note: '认证门户:授权码 + PKCE 入口',
90
- },
91
- {
92
- code: 'admin',
93
- host: 'admin',
94
- base: '',
95
- slugScoped: true,
96
- routerSlug: true,
97
- routerOrder: 1,
98
- family: 'console',
99
- audience: 'admin',
100
- inSwitcher: true,
101
- legacyEnvKey: 'VITE_ADMIN_CONSOLE_URL',
102
- note: '管理控制台;env 可覆盖为 app.<root>/admin',
103
- },
104
- {
105
- code: 'developer',
106
- host: 'developer',
107
- base: '',
108
- slugScoped: false,
109
- routerSlug: true,
110
- routerOrder: 2,
111
- family: 'content',
112
- audience: 'public',
113
- inSwitcher: true,
114
- legacyEnvKey: 'VITE_DEVELOPER_PORTAL_URL',
115
- },
116
- {
117
- code: 'user',
118
- host: 'user',
119
- base: '',
120
- slugScoped: true,
121
- routerSlug: false,
122
- family: 'console',
123
- audience: 'public',
124
- inSwitcher: true,
125
- legacyEnvKey: 'VITE_END_USER_PORTAL_URL',
126
- note: '用户门户:全角色可见(非管理面)',
127
- },
128
- {
129
- code: 'security',
130
- host: 'security',
131
- base: '',
132
- slugScoped: true,
133
- routerSlug: true,
134
- routerOrder: 3,
135
- family: 'console',
136
- audience: 'admin',
137
- inSwitcher: true,
138
- legacyEnvKey: 'VITE_SECURITY_DASHBOARD_URL',
139
- },
140
- {
141
- code: 'status',
142
- host: 'status',
143
- base: '',
144
- slugScoped: false,
145
- routerSlug: true,
146
- routerOrder: 5,
147
- family: 'content',
148
- audience: 'public',
149
- inSwitcher: true,
150
- legacyEnvKey: 'VITE_STATUS_PAGE_URL',
151
- },
152
- {
153
- code: 'landing',
154
- host: '',
155
- base: '',
156
- slugScoped: false,
157
- routerSlug: false,
158
- family: 'landing',
159
- audience: 'public',
160
- inSwitcher: false,
161
- legacyEnvKey: 'VITE_LANDING_SITE_URL',
162
- note: '落根域(无子域前缀)',
163
- },
164
- {
165
- code: 'authenticator',
166
- host: 'authenticator',
167
- base: '',
168
- slugScoped: true,
169
- routerSlug: false,
170
- family: 'app',
171
- audience: 'public',
172
- inSwitcher: false,
173
- legacyEnvKey: 'VITE_AUTHENTICATOR_APP_URL',
174
- note: 'App 形态(TOTP/push),不做桌面门户切换目标',
175
- },
176
- {
177
- code: 'trust',
178
- host: 'trust',
179
- base: '',
180
- slugScoped: false,
181
- routerSlug: true,
182
- routerOrder: 6,
183
- family: 'content',
184
- audience: 'public',
185
- inSwitcher: true,
186
- legacyEnvKey: 'VITE_TRUST_CENTER_URL',
187
- },
188
- {
189
- code: 'platform',
190
- host: 'platform',
191
- base: '',
192
- slugScoped: true,
193
- routerSlug: true,
194
- routerOrder: 4,
195
- family: 'console',
196
- audience: 'platform',
197
- inSwitcher: true,
198
- legacyEnvKey: 'VITE_PLATFORM_CONSOLE_URL',
199
- note: '仅平台租户成员;租户段挂载(OAuth client 按 slug 解析)',
200
- },
201
- {
202
- code: 'brand',
203
- host: 'brand',
204
- base: '',
205
- slugScoped: false,
206
- routerSlug: false,
207
- family: 'content',
208
- audience: 'public',
209
- inSwitcher: true,
210
- note: '选品牌落地站;无旧 env 键',
211
- },
212
- {
213
- code: 'secret',
214
- host: 'secret',
215
- base: '',
216
- slugScoped: false,
217
- routerSlug: false,
218
- family: 'console',
219
- audience: 'admin',
220
- inSwitcher: true,
221
- },
222
- {
223
- code: 'config',
224
- host: 'config',
225
- base: '',
226
- slugScoped: false,
227
- routerSlug: false,
228
- family: 'console',
229
- audience: 'admin',
230
- inSwitcher: true,
231
- },
232
- {
233
- code: 'docs',
234
- host: 'docs',
235
- base: '',
236
- slugScoped: false,
237
- routerSlug: false,
238
- family: 'content',
239
- audience: 'public',
240
- inSwitcher: true,
241
- note: '此前未登记(getPortalUrl 退化成 <origin>/docs)',
242
- },
243
- {
244
- code: 'wiki',
245
- host: 'wiki',
246
- base: '',
247
- slugScoped: false,
248
- routerSlug: false,
249
- family: 'content',
250
- audience: 'public',
251
- inSwitcher: true,
252
- note: '此前未登记',
253
- },
254
- {
255
- code: 'reference',
256
- host: 'reference',
257
- base: '',
258
- slugScoped: false,
259
- routerSlug: false,
260
- family: 'content',
261
- audience: 'public',
262
- inSwitcher: true,
263
- note: '此前未登记',
264
- },
265
- {
266
- code: 'consent',
267
- host: 'consent',
268
- base: '',
269
- slugScoped: false,
270
- routerSlug: false,
271
- family: 'content',
272
- audience: 'public',
273
- inSwitcher: true,
274
- note: '此前未登记',
275
- },
276
- ];
277
-
278
- const BY_CODE: ReadonlyMap<string, PortalDefinition> = new Map(
279
- PORTALS.map((p) => [p.code, p] as const),
280
- );
281
-
282
- /** 全部门户 code(顺序同表)。 */
283
- export const PORTAL_CODES: readonly string[] = PORTALS.map((p) => p.code);
284
-
285
- /** 取门户定义;未登记返回 undefined(调用方按旧口径兜底)。 */
286
- export function getPortalDefinition(code: string): PortalDefinition | undefined {
287
- return BY_CODE.get(code);
288
- }
289
-
290
- /** 入口是否拼租户段 `/<slug>`。 */
291
- export function isSlugScopedPortal(code: string): boolean {
292
- return BY_CODE.get(code)?.slugScoped === true;
293
- }
294
-
295
- /** 是否控制台族(控制台切换器的候选集)。 */
296
- export function isConsolePortal(code: string): boolean {
297
- return BY_CODE.get(code)?.family === 'console';
298
- }
299
-
300
- /** 控制台族 code 清单(替代各站 `CONSOLE_PORTALS` 字面量)。 */
301
- export function getConsolePortalCodes(): string[] {
302
- return PORTALS.filter((p) => p.family === 'console').map((p) => p.code);
303
- }
304
-
305
- /** 默认进入切换器清单的 code(`usePortalCatalog` 不传 exclude 时的基线)。 */
306
- export function getSwitcherIncludedCodes(): string[] {
307
- return PORTALS.filter((p) => p.inSwitcher).map((p) => p.code);
308
- }
309
-
310
- /** 默认不进切换器清单的 code(`usePortalCatalog` 的 DEFAULT_EXCLUDE)。 */
311
- export function getSwitcherExcludedCodes(): string[] {
312
- return PORTALS.filter((p) => !p.inSwitcher).map((p) => p.code);
313
- }
314
-
315
- /** 参与 `/<tenant>/<portal>` 路由 basename 解析的 code(按历史顺序 routerOrder 升序)。 */
316
- export function getRouterPortalCodes(): string[] {
317
- return PORTALS.filter((p) => p.routerSlug)
318
- .slice()
319
- .sort((a, b) => (a.routerOrder ?? Number.MAX_SAFE_INTEGER) - (b.routerOrder ?? Number.MAX_SAFE_INTEGER))
320
- .map((p) => p.code);
321
- }
322
-
323
- /** 旧 env.js 直连 URL 键(VITE_*_URL)→ code 的反向映射源。 */
324
- export function getLegacyEnvKey(code: string): string | undefined {
325
- return BY_CODE.get(code)?.legacyEnvKey;
326
- }
327
-
328
- /**
329
- * 按**受众**判定可见性(入口门禁镜像)。
330
- *
331
- * 同一函数服务两个数据源:注册表的 `audience` 与服务端目录里的 `config.portal.audience`。
332
- * 未知/缺失受众一律按 `public`(叠加原则,不误伤新门户)。
333
- */
334
- export function isPortalVisibleByAudience(
335
- audience: string | null | undefined,
336
- ctx: { role: string | null; isPlatformMember: boolean },
337
- ): boolean {
338
- if (audience === 'platform') return ctx.isPlatformMember;
339
- if (audience === 'admin') return ctx.role !== null && ADMIN_PLANE_ROLES.includes(ctx.role);
340
- return true;
341
- }
342
-
343
- /** 未登记的门户默认放行(叠加原则,不误伤)。 */
344
- export function isPortalVisibleForAudience(
345
- code: string,
346
- ctx: { role: string | null; isPlatformMember: boolean },
347
- ): boolean {
348
- return isPortalVisibleByAudience(BY_CODE.get(code)?.audience, ctx);
349
- }
1
+ /**
2
+ * 门户注册表 —— **门户元数据的单一真源**。
3
+ *
4
+ * 过去「门户清单」被写了十几次(`PORTAL_DEFAULTS` / `SLUG_PORTALS` /
5
+ * `getAppPortalSlugs()` / 重定向白名单 / `isPortalVisible` 的角色集 /
6
+ * `DEFAULT_EXCLUDE` / `PORTAL_KEY_MAP`,以及 6 个站点各持一份 `CONSOLE_PORTALS`)。
7
+ * 每加一个门户要改 7 个仓,且靠"进名单"才可见(小圈子)。
8
+ *
9
+ * 现在只有这张表。其余全部由它派生:
10
+ *
11
+ * 表字段 → 派生
12
+ * host / base → config.PORTAL_DEFAULTS、getPortalUrl()
13
+ * slugScoped → config.SLUG_PORTALS(入口是否拼 /<tenantSlug>)
14
+ * routerSlug → config.getAppPortalSlugs()(/<tenant>/<portal> 路由 basename)
15
+ * legacyEnvKey → config.PORTAL_KEY_MAP(旧 env.js VITE_*_URL)
16
+ * — → getAllowedRedirectOrigins()(redirect 白名单 = 全部 code)
17
+ * audience → hooks.isPortalVisible()(谁能看见:入口门禁的镜像)
18
+ * inSwitcher → usePortalCatalog DEFAULT_EXCLUDE(默认排除 = !inSwitcher)
19
+ * family='console' → getConsolePortalCodes()(控制台切换器全集,替代各站白名单)
20
+ *
21
+ * 新增门户 = 在这里加一行(若后端目录已透出 host/base,则连这一行都可省)。
22
+ * **禁止**在其它文件再写门户 code 字面量数组/Set。
23
+ */
24
+
25
+ /** 可见性受众 = 登录入口门禁的镜像(谁能登录,谁才看见)。 */
26
+ export type PortalAudience = 'public' | 'admin' | 'platform';
27
+
28
+ /**
29
+ * 门户族群:
30
+ * - `console`:管理面/用户面控制台(互相出现在切换器里)
31
+ * - `content`:内容站(developer / status / trust / brand / docs …)
32
+ * - `app`:App 形态(authenticator:TOTP/push,不列入桌面切换器)
33
+ * - `auth` / `landing`:认证与落地站,非切换目标
34
+ */
35
+ export type PortalFamily = 'console' | 'content' | 'app' | 'auth' | 'landing';
36
+
37
+ export interface PortalDefinition {
38
+ /** 门户 code(后端 applications.code,全环境同值) */
39
+ code: string;
40
+ /** 子域前缀;空串 = 落在根域(landing) */
41
+ host: string;
42
+ /** 子域下的固定路径前缀(env 可覆盖,如 admin 的 '/admin') */
43
+ base: string;
44
+ /** 入口是否拼租户段 `/<slug>`(拼错会命中不存在的路由 ⇒ 空白/404) */
45
+ slugScoped: boolean;
46
+ /** 是否参与 `/<tenant>/<portal>` 路由 basename 解析 */
47
+ routerSlug: boolean;
48
+ /**
49
+ * `getAppPortalSlugs()` 的返回顺序(历史上是 `admin, developer, security, platform, status, trust`)。
50
+ * 该数组是导出 API,顺序可观测 ⇒ 用显式序号保序,而不是依赖表顺序。
51
+ */
52
+ routerOrder?: number;
53
+ family: PortalFamily;
54
+ audience: PortalAudience;
55
+ /** 默认进入 `usePortalCatalog` 的门户清单(false ⇒ 进 DEFAULT_EXCLUDE) */
56
+ inSwitcher: boolean;
57
+ /** 旧 env.js 直连 URL 键(VITE_*_URL)→ 向后兼容映射用 */
58
+ legacyEnvKey?: string;
59
+ /** 备注(为什么这个门户这样配置) */
60
+ note?: string;
61
+ }
62
+
63
+ /** 管理面平面角色集(admin / security / config / secret 的门户 = 登录入口门禁同集)。 */
64
+ export const ADMIN_PLANE_ROLES: readonly string[] = [
65
+ 'super_admin',
66
+ 'admin',
67
+ 'security_admin',
68
+ 'user_manager',
69
+ ];
70
+
71
+ /**
72
+ * 注册表本体(顺序 = 重定向白名单推导顺序)。
73
+ *
74
+ * 前 13 项与迁移前 `PORTAL_DEFAULTS` 逐项等价(见 `__tests__/registry.test.ts` 的 oracle 断言);
75
+ * 后 4 项(docs / wiki / reference / consent)是此前**漏登记**的内容站 —— 之前 `getPortalUrl('docs')`
76
+ * 会退化成 `${origin}/docs`,任何控制台都链不到文档中心。这里补齐,属新增能力,不改变前 13 项行为。
77
+ */
78
+ export const PORTALS: readonly PortalDefinition[] = [
79
+ {
80
+ code: 'auth',
81
+ host: 'auth',
82
+ base: '',
83
+ slugScoped: true,
84
+ routerSlug: false,
85
+ family: 'auth',
86
+ audience: 'public',
87
+ inSwitcher: false,
88
+ legacyEnvKey: 'VITE_AUTH_PAGES_URL',
89
+ note: '认证门户:授权码 + PKCE 入口',
90
+ },
91
+ {
92
+ code: 'admin',
93
+ host: 'admin',
94
+ base: '',
95
+ slugScoped: true,
96
+ routerSlug: true,
97
+ routerOrder: 1,
98
+ family: 'console',
99
+ audience: 'admin',
100
+ inSwitcher: true,
101
+ legacyEnvKey: 'VITE_ADMIN_CONSOLE_URL',
102
+ note: '管理控制台;env 可覆盖为 app.<root>/admin',
103
+ },
104
+ {
105
+ code: 'developer',
106
+ host: 'developer',
107
+ base: '',
108
+ slugScoped: false,
109
+ routerSlug: true,
110
+ routerOrder: 2,
111
+ family: 'content',
112
+ audience: 'public',
113
+ inSwitcher: true,
114
+ legacyEnvKey: 'VITE_DEVELOPER_PORTAL_URL',
115
+ },
116
+ {
117
+ code: 'user',
118
+ host: 'user',
119
+ base: '',
120
+ slugScoped: true,
121
+ routerSlug: false,
122
+ family: 'console',
123
+ audience: 'public',
124
+ inSwitcher: true,
125
+ legacyEnvKey: 'VITE_END_USER_PORTAL_URL',
126
+ note: '用户门户:全角色可见(非管理面)',
127
+ },
128
+ {
129
+ code: 'security',
130
+ host: 'security',
131
+ base: '',
132
+ slugScoped: true,
133
+ routerSlug: true,
134
+ routerOrder: 3,
135
+ family: 'console',
136
+ audience: 'admin',
137
+ inSwitcher: true,
138
+ legacyEnvKey: 'VITE_SECURITY_DASHBOARD_URL',
139
+ },
140
+ {
141
+ code: 'status',
142
+ host: 'status',
143
+ base: '',
144
+ slugScoped: false,
145
+ routerSlug: true,
146
+ routerOrder: 5,
147
+ family: 'content',
148
+ audience: 'public',
149
+ inSwitcher: true,
150
+ legacyEnvKey: 'VITE_STATUS_PAGE_URL',
151
+ },
152
+ {
153
+ code: 'landing',
154
+ host: '',
155
+ base: '',
156
+ slugScoped: false,
157
+ routerSlug: false,
158
+ family: 'landing',
159
+ audience: 'public',
160
+ inSwitcher: false,
161
+ legacyEnvKey: 'VITE_LANDING_SITE_URL',
162
+ note: '落根域(无子域前缀)',
163
+ },
164
+ {
165
+ code: 'authenticator',
166
+ host: 'authenticator',
167
+ base: '',
168
+ slugScoped: true,
169
+ routerSlug: false,
170
+ family: 'app',
171
+ audience: 'public',
172
+ inSwitcher: false,
173
+ legacyEnvKey: 'VITE_AUTHENTICATOR_APP_URL',
174
+ note: 'App 形态(TOTP/push),不做桌面门户切换目标',
175
+ },
176
+ {
177
+ code: 'trust',
178
+ host: 'trust',
179
+ base: '',
180
+ slugScoped: false,
181
+ routerSlug: true,
182
+ routerOrder: 6,
183
+ family: 'content',
184
+ audience: 'public',
185
+ inSwitcher: true,
186
+ legacyEnvKey: 'VITE_TRUST_CENTER_URL',
187
+ },
188
+ {
189
+ code: 'platform',
190
+ host: 'platform',
191
+ base: '',
192
+ slugScoped: true,
193
+ routerSlug: true,
194
+ routerOrder: 4,
195
+ family: 'console',
196
+ audience: 'platform',
197
+ inSwitcher: true,
198
+ legacyEnvKey: 'VITE_PLATFORM_CONSOLE_URL',
199
+ note: '仅平台租户成员;租户段挂载(OAuth client 按 slug 解析)',
200
+ },
201
+ {
202
+ code: 'brand',
203
+ host: 'brand',
204
+ base: '',
205
+ slugScoped: false,
206
+ routerSlug: false,
207
+ family: 'content',
208
+ audience: 'public',
209
+ inSwitcher: true,
210
+ note: '选品牌落地站;无旧 env 键',
211
+ },
212
+ {
213
+ code: 'secret',
214
+ host: 'secret',
215
+ base: '',
216
+ slugScoped: false,
217
+ routerSlug: false,
218
+ family: 'console',
219
+ audience: 'admin',
220
+ inSwitcher: true,
221
+ },
222
+ {
223
+ code: 'config',
224
+ host: 'config',
225
+ base: '',
226
+ slugScoped: false,
227
+ routerSlug: false,
228
+ family: 'console',
229
+ audience: 'admin',
230
+ inSwitcher: true,
231
+ },
232
+ {
233
+ code: 'docs',
234
+ host: 'docs',
235
+ base: '',
236
+ slugScoped: false,
237
+ routerSlug: false,
238
+ family: 'content',
239
+ audience: 'public',
240
+ inSwitcher: true,
241
+ note: '此前未登记(getPortalUrl 退化成 <origin>/docs)',
242
+ },
243
+ {
244
+ code: 'wiki',
245
+ host: 'wiki',
246
+ base: '',
247
+ slugScoped: false,
248
+ routerSlug: false,
249
+ family: 'content',
250
+ audience: 'public',
251
+ inSwitcher: true,
252
+ note: '此前未登记',
253
+ },
254
+ {
255
+ code: 'reference',
256
+ host: 'reference',
257
+ base: '',
258
+ slugScoped: false,
259
+ routerSlug: false,
260
+ family: 'content',
261
+ audience: 'public',
262
+ inSwitcher: true,
263
+ note: '此前未登记',
264
+ },
265
+ {
266
+ code: 'consent',
267
+ host: 'consent',
268
+ base: '',
269
+ slugScoped: false,
270
+ routerSlug: false,
271
+ family: 'content',
272
+ audience: 'public',
273
+ inSwitcher: true,
274
+ note: '此前未登记',
275
+ },
276
+ ];
277
+
278
+ const BY_CODE: ReadonlyMap<string, PortalDefinition> = new Map(
279
+ PORTALS.map((p) => [p.code, p] as const),
280
+ );
281
+
282
+ /** 全部门户 code(顺序同表)。 */
283
+ export const PORTAL_CODES: readonly string[] = PORTALS.map((p) => p.code);
284
+
285
+ /** 取门户定义;未登记返回 undefined(调用方按旧口径兜底)。 */
286
+ export function getPortalDefinition(code: string): PortalDefinition | undefined {
287
+ return BY_CODE.get(code);
288
+ }
289
+
290
+ /** 入口是否拼租户段 `/<slug>`。 */
291
+ export function isSlugScopedPortal(code: string): boolean {
292
+ return BY_CODE.get(code)?.slugScoped === true;
293
+ }
294
+
295
+ /** 是否控制台族(控制台切换器的候选集)。 */
296
+ export function isConsolePortal(code: string): boolean {
297
+ return BY_CODE.get(code)?.family === 'console';
298
+ }
299
+
300
+ /** 控制台族 code 清单(替代各站 `CONSOLE_PORTALS` 字面量)。 */
301
+ export function getConsolePortalCodes(): string[] {
302
+ return PORTALS.filter((p) => p.family === 'console').map((p) => p.code);
303
+ }
304
+
305
+ /** 默认进入切换器清单的 code(`usePortalCatalog` 不传 exclude 时的基线)。 */
306
+ export function getSwitcherIncludedCodes(): string[] {
307
+ return PORTALS.filter((p) => p.inSwitcher).map((p) => p.code);
308
+ }
309
+
310
+ /** 默认不进切换器清单的 code(`usePortalCatalog` 的 DEFAULT_EXCLUDE)。 */
311
+ export function getSwitcherExcludedCodes(): string[] {
312
+ return PORTALS.filter((p) => !p.inSwitcher).map((p) => p.code);
313
+ }
314
+
315
+ /** 参与 `/<tenant>/<portal>` 路由 basename 解析的 code(按历史顺序 routerOrder 升序)。 */
316
+ export function getRouterPortalCodes(): string[] {
317
+ return PORTALS.filter((p) => p.routerSlug)
318
+ .slice()
319
+ .sort((a, b) => (a.routerOrder ?? Number.MAX_SAFE_INTEGER) - (b.routerOrder ?? Number.MAX_SAFE_INTEGER))
320
+ .map((p) => p.code);
321
+ }
322
+
323
+ /** 旧 env.js 直连 URL 键(VITE_*_URL)→ code 的反向映射源。 */
324
+ export function getLegacyEnvKey(code: string): string | undefined {
325
+ return BY_CODE.get(code)?.legacyEnvKey;
326
+ }
327
+
328
+ /**
329
+ * 按**受众**判定可见性(入口门禁镜像)。
330
+ *
331
+ * 同一函数服务两个数据源:注册表的 `audience` 与服务端目录里的 `config.portal.audience`。
332
+ * 未知/缺失受众一律按 `public`(叠加原则,不误伤新门户)。
333
+ */
334
+ export function isPortalVisibleByAudience(
335
+ audience: string | null | undefined,
336
+ ctx: { role: string | null; isPlatformMember: boolean },
337
+ ): boolean {
338
+ if (audience === 'platform') return ctx.isPlatformMember;
339
+ if (audience === 'admin') return ctx.role !== null && ADMIN_PLANE_ROLES.includes(ctx.role);
340
+ return true;
341
+ }
342
+
343
+ /** 未登记的门户默认放行(叠加原则,不误伤)。 */
344
+ export function isPortalVisibleForAudience(
345
+ code: string,
346
+ ctx: { role: string | null; isPlatformMember: boolean },
347
+ ): boolean {
348
+ return isPortalVisibleByAudience(BY_CODE.get(code)?.audience, ctx);
349
+ }