@h-ai/serv 0.1.0-alpha.61 → 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.
@@ -111,9 +111,11 @@ interface ServSession {
111
111
  * 模块消费者**无需**知道 IAM 内部 Session 类型与 ServSession 的差异:结构类型确保兼容。
112
112
  */
113
113
  interface ServIam {
114
- readonly session: {
115
- /** 校验访问令牌,成功返回会话快照(结构上是 ServSession 的超集即可)。 */
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` / `x-forwarded-for` / `x-real-ip` / `user-agent`
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.session.verifyToken(token)` 或自定义函数)
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, buildAuthContextFactory as c, type CreateServContextInput as d, type RefreshTokenPair as e, parseRequestContext as p };
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.61",
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.61",
39
- "@h-ai/iam": "0.1.0-alpha.61",
40
- "@h-ai/storage": "0.1.0-alpha.61"
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.61",
55
- "@h-ai/core": "0.1.0-alpha.61",
56
- "@h-ai/crypto": "0.1.0-alpha.61",
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.61",
68
- "@h-ai/iam": "0.1.0-alpha.61",
69
- "@h-ai/storage": "0.1.0-alpha.61",
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",