@h-ai/serv 0.1.0-alpha.60 → 0.1.0-alpha.62
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/README.en.md +12 -8
- package/README.ja.md +12 -8
- package/README.md +12 -8
- package/dist/features/ai.d.ts +1 -1
- package/dist/features/iam.d.ts +2 -1
- package/dist/features/storage.d.ts +1 -1
- package/dist/index.d.ts +13 -8
- package/dist/index.js +83 -9
- package/dist/index.js.map +1 -1
- package/dist/{serv-context-CkbS0M9G.d.ts → serv-context-CWzyrsdq.d.ts} +14 -6
- package/package.json +10 -10
|
@@ -111,9 +111,11 @@ interface ServSession {
|
|
|
111
111
|
* 模块消费者**无需**知道 IAM 内部 Session 类型与 ServSession 的差异:结构类型确保兼容。
|
|
112
112
|
*/
|
|
113
113
|
interface ServIam {
|
|
114
|
-
readonly
|
|
115
|
-
/**
|
|
114
|
+
readonly auth: {
|
|
115
|
+
/** 验证会话并读取当前有效的用户与授权;不依赖最大努力会话同步。 */
|
|
116
116
|
verifyToken: (accessToken: string) => Promise<HaiResult<ServSession>>;
|
|
117
|
+
};
|
|
118
|
+
readonly session: {
|
|
117
119
|
/** 使用 refresh token 换发新的 token 对。仅 `refreshCookie` 启用时被调用。 */
|
|
118
120
|
refresh: (refreshToken: string) => Promise<HaiResult<RefreshTokenPair>>;
|
|
119
121
|
};
|
|
@@ -129,16 +131,22 @@ interface ServContext {
|
|
|
129
131
|
readonly request: Request;
|
|
130
132
|
readonly logger: Logger;
|
|
131
133
|
}
|
|
134
|
+
/** 运行时提供的连接元数据;必须来自 socket/平台,不能从请求头复制。 */
|
|
135
|
+
interface ServRequestMetadata {
|
|
136
|
+
readonly remoteAddress?: string;
|
|
137
|
+
}
|
|
132
138
|
/** 创建上下文所需的输入。 */
|
|
133
|
-
interface CreateServContextInput {
|
|
139
|
+
interface CreateServContextInput extends ServRequestMetadata {
|
|
134
140
|
readonly request: Request;
|
|
141
|
+
/** createApp 已按 trustedProxies 解析的客户端地址,供自定义上下文复用。 */
|
|
142
|
+
readonly ip?: string;
|
|
135
143
|
}
|
|
136
144
|
/** 应用可传入的上下文工厂。 */
|
|
137
145
|
type CreateServContext = (input: CreateServContextInput) => ServContext | Promise<ServContext>;
|
|
138
146
|
/**
|
|
139
147
|
* 解析 HTTP 请求元数据并构造基础 ServContext(**同步**,**不**填充 session)。
|
|
140
148
|
*
|
|
141
|
-
* - 提取 `x-request-id` / `accept-language` / `
|
|
149
|
+
* - 提取 `x-request-id` / `accept-language` / `user-agent`;IP 仅来自运行时元数据
|
|
142
150
|
* - 从 `Authorization: Bearer <token>` 提取 `accessToken`
|
|
143
151
|
* - **不会**读取 refresh token:refresh token 若启用 `refreshCookie`,只走专属刷新路由
|
|
144
152
|
*
|
|
@@ -166,9 +174,9 @@ declare function parseRequestContext(input: CreateServContextInput): ServContext
|
|
|
166
174
|
* - `verifyToken` 失败时**不**抛错,统一收敛为 `session=undefined`,交由 guard 返回未认证的失败 HaiResult
|
|
167
175
|
* - 异常通过 try/catch 兜底,避免向 HTTP 层泄漏堆栈
|
|
168
176
|
*
|
|
169
|
-
* @param verifyToken - 访问令牌校验回调(通常是 `token => iam.
|
|
177
|
+
* @param verifyToken - 访问令牌校验回调(通常是 `token => iam.auth.verifyToken(token)` 或自定义函数)
|
|
170
178
|
* @returns 异步上下文工厂
|
|
171
179
|
*/
|
|
172
180
|
declare function buildAuthContextFactory(verifyToken: (accessToken: string) => Promise<HaiResult<ServSession>>): CreateServContext;
|
|
173
181
|
|
|
174
|
-
export { type CreateServContext as C, type NativeRefreshTokenTransportConfig as N, type RefreshCookieConfig as R, type ServContext as S, type ServSession as a, type ServIam as b,
|
|
182
|
+
export { type CreateServContext as C, type NativeRefreshTokenTransportConfig as N, type RefreshCookieConfig as R, type ServContext as S, type ServSession as a, type ServIam as b, type ServRequestMetadata as c, buildAuthContextFactory as d, type CreateServContextInput as e, type RefreshTokenPair as f, parseRequestContext as p };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-ai/serv",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.0-alpha.
|
|
4
|
+
"version": "0.1.0-alpha.62",
|
|
5
5
|
"description": "Hai Framework service runtime powered by Hono and oRPC.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"exports": {
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@h-ai/ai": "0.1.0-alpha.
|
|
39
|
-
"@h-ai/iam": "0.1.0-alpha.
|
|
40
|
-
"@h-ai/storage": "0.1.0-alpha.
|
|
38
|
+
"@h-ai/ai": "0.1.0-alpha.62",
|
|
39
|
+
"@h-ai/iam": "0.1.0-alpha.62",
|
|
40
|
+
"@h-ai/storage": "0.1.0-alpha.62"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
43
43
|
"@h-ai/ai": {
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@h-ai/api-contract": "0.1.0-alpha.
|
|
55
|
-
"@h-ai/core": "0.1.0-alpha.
|
|
56
|
-
"@h-ai/crypto": "0.1.0-alpha.
|
|
54
|
+
"@h-ai/api-contract": "0.1.0-alpha.62",
|
|
55
|
+
"@h-ai/core": "0.1.0-alpha.62",
|
|
56
|
+
"@h-ai/crypto": "0.1.0-alpha.62",
|
|
57
57
|
"@hono/node-server": "^2.1.4",
|
|
58
58
|
"@orpc/openapi": "^1.15.5",
|
|
59
59
|
"@orpc/server": "^1.15.5",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"zod": "^4.6.5"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@h-ai/ai": "0.1.0-alpha.
|
|
68
|
-
"@h-ai/iam": "0.1.0-alpha.
|
|
69
|
-
"@h-ai/storage": "0.1.0-alpha.
|
|
67
|
+
"@h-ai/ai": "0.1.0-alpha.62",
|
|
68
|
+
"@h-ai/iam": "0.1.0-alpha.62",
|
|
69
|
+
"@h-ai/storage": "0.1.0-alpha.62",
|
|
70
70
|
"@types/node": "^26.6.5",
|
|
71
71
|
"@types/ws": "^8.18.2",
|
|
72
72
|
"rimraf": "^6.1.3",
|