subapp-props.ts
1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type { RemoteRequest, SubAppProps } from '@uj/contracts';
import { http } from '@/api/core/http';
import { getLoginSession, getUserPermCodes } from '@/access/session';
import { themeConfig } from '@/theme/themeConfig';
/**
* 主壳 -> 子应用的显式契约(唯一构造点)。
*
* request 只有一行 `http.request(req)`:把子应用传来的完整 axios config 原样交给
* 主壳那份请求引擎——它现在是 @uj/api-core 统一 Request 门面的装配点
* (选 strategies.webHost 方案、注入 axios 作 transport、把 RSA 注册成具名签名策略),
* 加签 / 验签 / context-path / 401 统一登出 / 业务码归一全部由方案策略与门面负责,
* 与四个原生小程序同一套机制。
* 于是全项目只有一份签名状态(_signInitPromise、setServerPublicKey、PEM、VITE_*)。
*
* 为什么能传函数:wujie 的 iframe 是同源 srcdoc,props 是**引用传递**而非
* postMessage 序列化。storeDownload.ts 的 transformResponse 回调、Blob、Promise
* 都能原样跨越,不需要任何序列化层。
*
* ⚠️ 反过来,如果把 api/core 打进子应用,backend-resolver.ts 读到的会是 wujie
* 代理过的 location.host(子应用自己的域名),BASE_URL 算错且签名 canonical 第 2 行
* 不一致 -> 后端 10011。这条约束由 check-boundaries.mjs 静态复查。
*/
export function createSubAppProps(options: {
shortName: string;
page: string;
navigate: (path: string) => void;
}): SubAppProps {
const { shortName, page, navigate } = options;
return {
request: (req: RemoteRequest) => http.request(req as never) as unknown as Promise<unknown>,
session: getLoginSession() ?? null,
permCodes: getUserPermCodes(),
theme: themeConfig as unknown as Record<string, unknown>,
page,
navigate,
shortName,
};
}