@h-ai/serv 1.0.0-beta.2 → 1.0.0-beta.20
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 +172 -124
- package/README.ja.md +172 -124
- package/README.md +172 -124
- package/dist/{chunk-TWMOZPGU.js → chunk-CZ6VA2EN.js} +3 -3
- package/dist/{chunk-TWMOZPGU.js.map → chunk-CZ6VA2EN.js.map} +1 -1
- package/dist/{chunk-I3F7RN4I.js → chunk-PLGCHDZM.js} +30 -13
- package/dist/chunk-PLGCHDZM.js.map +1 -0
- package/dist/features/ai.d.ts +5 -4
- package/dist/features/ai.js +34 -13
- package/dist/features/ai.js.map +1 -1
- package/dist/features/feedback.d.ts +20 -19
- package/dist/features/feedback.js +1 -1
- package/dist/features/feedback.js.map +1 -1
- package/dist/features/iam.d.ts +4 -3
- package/dist/features/iam.js +4 -2
- package/dist/features/iam.js.map +1 -1
- package/dist/features/storage.d.ts +4 -3
- package/dist/features/storage.js +34 -9
- package/dist/features/storage.js.map +1 -1
- package/dist/index.d.ts +97 -68
- package/dist/index.js +338 -222
- package/dist/index.js.map +1 -1
- package/dist/{serv-context-DE1JH5bd.d.ts → serv-context-DSsS_ksL.d.ts} +4 -60
- package/dist/{serv-router-BJk04-oS.d.ts → serv-router-DWjYC0zD.d.ts} +2 -18
- package/package.json +29 -29
- package/dist/chunk-I3F7RN4I.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as _h_ai_core from '@h-ai/core';
|
|
2
2
|
import { HaiResult, TrustedProxies, RequestAccessConfigInput, ValidationFormError } from '@h-ai/core';
|
|
3
|
+
import { ProcedureHandler, ErrorMap, Meta, ProcedureHandlerOptions, ORPCErrorConstructorMap, Router, ContractRouter } from '@orpc/server';
|
|
3
4
|
import { AIFunctions, AudioWsStartMessage, AudioFormat } from '@h-ai/ai';
|
|
4
5
|
import { AnyContractRouter, OpenAPI } from '@orpc/contract';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export { e as CreateServContextInput, N as NativeRefreshTokenTransportConfig, f as RefreshTokenPair } from './serv-context-DE1JH5bd.js';
|
|
6
|
+
import { a as ServSession, S as ServContext, b as ServIam, R as RefreshCookieConfig, C as CreateServContext, c as ServRequestMetadata, d as CreateServContextInput } from './serv-context-DSsS_ksL.js';
|
|
7
|
+
export { N as NativeRefreshTokenTransportConfig, e as RefreshTokenPair } from './serv-context-DSsS_ksL.js';
|
|
8
8
|
import { MiddlewareHandler } from 'hono';
|
|
9
9
|
import { z, ZodType } from 'zod';
|
|
10
10
|
import { TransportServerKeyRing, CryptoFunctions, TransportKeyStore } from '@h-ai/crypto';
|
|
11
11
|
import { ServerType } from '@hono/node-server';
|
|
12
12
|
import { AddressInfo } from 'node:net';
|
|
13
|
-
import {
|
|
14
|
-
export { A as AuthenticatedServContext,
|
|
13
|
+
import { S as ServImplementer } from './serv-router-DWjYC0zD.js';
|
|
14
|
+
export { A as AuthenticatedServContext, a as ServRouteHandler, b as ServRoutePath, c as ServRouterBuilder } from './serv-router-DWjYC0zD.js';
|
|
15
15
|
import { StorageFunctions } from '@h-ai/storage';
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -138,7 +138,7 @@ type ServProcedureHandler<TInput, TOutput, TContext extends ServContext = ServCo
|
|
|
138
138
|
/**
|
|
139
139
|
* @h-ai/serv — HTTP 配置
|
|
140
140
|
*
|
|
141
|
-
* 提供用于控制 API 前缀、OpenAPI、docs
|
|
141
|
+
* 提供用于控制 API 前缀、OpenAPI、docs、健康检查与传输加密策略的配置结构,
|
|
142
142
|
* 并由 zod 负责默认值填充与边界校验。
|
|
143
143
|
* @module serv-config
|
|
144
144
|
*/
|
|
@@ -217,24 +217,6 @@ interface ServHealthHttpConfig {
|
|
|
217
217
|
readonly path: `/${string}`;
|
|
218
218
|
readonly readyPath?: `/${string}`;
|
|
219
219
|
}
|
|
220
|
-
/**
|
|
221
|
-
* 内部 RPC endpoint 配置。
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* ```ts
|
|
225
|
-
* import type { ServRpcHttpConfig } from '@h-ai/serv'
|
|
226
|
-
* import { serv } from '@h-ai/serv'
|
|
227
|
-
*
|
|
228
|
-
* const rpc: ServRpcHttpConfig = { prefix: '/rpc', access: 'loopback' }
|
|
229
|
-
* // 缺少可信连接信息时拒绝;跨节点来源通过明确网关/网络策略控制。
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
interface ServRpcHttpConfig {
|
|
233
|
-
readonly prefix: `/${string}`;
|
|
234
|
-
readonly access: 'loopback' | 'private-network' | 'gateway-only';
|
|
235
|
-
readonly gatewayHeader?: string;
|
|
236
|
-
readonly gatewaySecret?: string;
|
|
237
|
-
}
|
|
238
220
|
/**
|
|
239
221
|
* 传输加密运行时配置(对应 `config/_serv.yml`)。
|
|
240
222
|
*
|
|
@@ -250,6 +232,10 @@ interface ServRpcHttpConfig {
|
|
|
250
232
|
interface ServTransportRuntimeConfig {
|
|
251
233
|
/** 双向明文 UTF-8 字节上限;省略使用 1 MiB,范围 1 KiB~64 MiB。 */
|
|
252
234
|
readonly maxPlaintextBytes?: number;
|
|
235
|
+
/** 请求时间允许领先服务器的秒数,默认 30,整数范围 0~300。 */
|
|
236
|
+
readonly maxFutureSkewSeconds?: number;
|
|
237
|
+
/** 请求从签发起的有效秒数,默认 300,整数范围 1~600。 */
|
|
238
|
+
readonly maxRequestAgeSeconds?: number;
|
|
253
239
|
/** 按完整路径段匹配的明文容量;* 匹配单段。 */
|
|
254
240
|
readonly routePlaintextBytes?: Readonly<Record<string, number>>;
|
|
255
241
|
readonly keyExchangePath: `/${string}`;
|
|
@@ -281,7 +267,7 @@ interface ServCorsRuntimeConfig {
|
|
|
281
267
|
* import type { ServHttpConfig } from '@h-ai/serv'
|
|
282
268
|
* import { serv } from '@h-ai/serv'
|
|
283
269
|
*
|
|
284
|
-
* const http: ServHttpConfig = { trustedProxies: 'auto', access: false, apiPrefix: '/api/v1', openapi: false, docs: false, health: { path: '/health' }
|
|
270
|
+
* const http: ServHttpConfig = { trustedProxies: 'auto', access: false, apiPrefix: '/api/v1', openapi: false, docs: false, health: { path: '/health' } }
|
|
285
271
|
* ```
|
|
286
272
|
*/
|
|
287
273
|
interface ServHttpConfig {
|
|
@@ -289,11 +275,10 @@ interface ServHttpConfig {
|
|
|
289
275
|
readonly trustedProxies: TrustedProxies;
|
|
290
276
|
/** 每次请求的 IP/时间策略;默认 false,内联与独立文件二选一。 */
|
|
291
277
|
readonly access: RequestAccessConfigInput;
|
|
292
|
-
readonly apiPrefix:
|
|
278
|
+
readonly apiPrefix: `/${string}`;
|
|
293
279
|
readonly openapi: false | ServOpenAPIHttpConfig;
|
|
294
280
|
readonly docs: false | ServDocsHttpConfig;
|
|
295
281
|
readonly health: false | ServHealthHttpConfig;
|
|
296
|
-
readonly rpc: false | ServRpcHttpConfig;
|
|
297
282
|
}
|
|
298
283
|
/**
|
|
299
284
|
* `config/_serv.yml` 的顶层配置结构。
|
|
@@ -341,6 +326,8 @@ type ServCorsRuntimeConfigInput = Partial<ServCorsRuntimeConfig>;
|
|
|
341
326
|
*/
|
|
342
327
|
type ServTransportRuntimeConfigInput = Partial<{
|
|
343
328
|
readonly maxPlaintextBytes: number | 'auto';
|
|
329
|
+
readonly maxFutureSkewSeconds: number;
|
|
330
|
+
readonly maxRequestAgeSeconds: number;
|
|
344
331
|
readonly routePlaintextBytes: Readonly<Record<string, number>>;
|
|
345
332
|
readonly keyExchangePath: `/${string}`;
|
|
346
333
|
readonly excludePaths: readonly `/${string}`[];
|
|
@@ -359,11 +346,10 @@ type ServTransportRuntimeConfigInput = Partial<{
|
|
|
359
346
|
type ServHttpConfigInput = Partial<{
|
|
360
347
|
readonly trustedProxies: TrustedProxies;
|
|
361
348
|
readonly access: RequestAccessConfigInput;
|
|
362
|
-
readonly apiPrefix:
|
|
349
|
+
readonly apiPrefix: `/${string}`;
|
|
363
350
|
readonly openapi: false | Partial<ServOpenAPIHttpConfig>;
|
|
364
351
|
readonly docs: false | Partial<ServDocsHttpConfig>;
|
|
365
352
|
readonly health: false | Partial<ServHealthHttpConfig>;
|
|
366
|
-
readonly rpc: false | Partial<ServRpcHttpConfig>;
|
|
367
353
|
}>;
|
|
368
354
|
/**
|
|
369
355
|
* `config/_serv.yml` 的顶层输入类型。
|
|
@@ -447,7 +433,7 @@ declare const ServConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
447
433
|
}>>;
|
|
448
434
|
}, z.core.$strict>>>;
|
|
449
435
|
}, z.core.$strict>]>>;
|
|
450
|
-
apiPrefix: z.ZodDefault<z.ZodCustom
|
|
436
|
+
apiPrefix: z.ZodDefault<z.ZodCustom<`/${string}`, `/${string}`>>;
|
|
451
437
|
openapi: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObject<{
|
|
452
438
|
path: z.ZodDefault<z.ZodCustom<`/${string}`, `/${string}`>>;
|
|
453
439
|
}, z.core.$strip>]>>;
|
|
@@ -459,16 +445,6 @@ declare const ServConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
459
445
|
path: z.ZodDefault<z.ZodCustom<`/${string}`, `/${string}`>>;
|
|
460
446
|
readyPath: z.ZodDefault<z.ZodOptional<z.ZodCustom<`/${string}`, `/${string}`>>>;
|
|
461
447
|
}, z.core.$strip>]>>;
|
|
462
|
-
rpc: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObject<{
|
|
463
|
-
prefix: z.ZodDefault<z.ZodCustom<`/${string}`, `/${string}`>>;
|
|
464
|
-
access: z.ZodDefault<z.ZodEnum<{
|
|
465
|
-
loopback: "loopback";
|
|
466
|
-
"private-network": "private-network";
|
|
467
|
-
"gateway-only": "gateway-only";
|
|
468
|
-
}>>;
|
|
469
|
-
gatewayHeader: z.ZodOptional<z.ZodString>;
|
|
470
|
-
gatewaySecret: z.ZodOptional<z.ZodString>;
|
|
471
|
-
}, z.core.$strip>]>>;
|
|
472
448
|
}, z.core.$strip>>;
|
|
473
449
|
cors: z.ZodOptional<z.ZodObject<{
|
|
474
450
|
origin: z.ZodOptional<z.ZodString>;
|
|
@@ -479,6 +455,8 @@ declare const ServConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
479
455
|
}, z.core.$strip>>;
|
|
480
456
|
transport: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObject<{
|
|
481
457
|
maxPlaintextBytes: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"auto">]>, z.ZodTransform<number | undefined, number | "auto">>>;
|
|
458
|
+
maxFutureSkewSeconds: z.ZodOptional<z.ZodNumber>;
|
|
459
|
+
maxRequestAgeSeconds: z.ZodOptional<z.ZodNumber>;
|
|
482
460
|
routePlaintextBytes: z.ZodOptional<z.ZodRecord<z.ZodCustom<`/${string}`, `/${string}`>, z.ZodNumber>>;
|
|
483
461
|
keyExchangePath: z.ZodDefault<z.ZodCustom<`/${string}`, `/${string}`>>;
|
|
484
462
|
excludePaths: z.ZodDefault<z.ZodArray<z.ZodCustom<`/${string}`, `/${string}`>>>;
|
|
@@ -494,7 +472,7 @@ declare const ServConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
494
472
|
port: number;
|
|
495
473
|
} | undefined;
|
|
496
474
|
http?: {
|
|
497
|
-
trustedProxies: string[]
|
|
475
|
+
trustedProxies: "auto" | string[];
|
|
498
476
|
access: false | {
|
|
499
477
|
file: string;
|
|
500
478
|
} | {
|
|
@@ -509,7 +487,7 @@ declare const ServConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
509
487
|
}[];
|
|
510
488
|
id: string;
|
|
511
489
|
paths: string[];
|
|
512
|
-
methods: ("GET" | "HEAD" | "
|
|
490
|
+
methods: ("GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "CONNECT" | "TRACE")[];
|
|
513
491
|
encryption?: "required" | "disabled" | undefined;
|
|
514
492
|
}[];
|
|
515
493
|
global?: {
|
|
@@ -523,7 +501,7 @@ declare const ServConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
523
501
|
}[];
|
|
524
502
|
} | undefined;
|
|
525
503
|
};
|
|
526
|
-
apiPrefix:
|
|
504
|
+
apiPrefix: `/${string}`;
|
|
527
505
|
openapi: false | {
|
|
528
506
|
path: `/${string}`;
|
|
529
507
|
};
|
|
@@ -535,12 +513,6 @@ declare const ServConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
535
513
|
path: `/${string}`;
|
|
536
514
|
readyPath: `/${string}`;
|
|
537
515
|
};
|
|
538
|
-
rpc: false | {
|
|
539
|
-
prefix: `/${string}`;
|
|
540
|
-
access: "loopback" | "private-network" | "gateway-only";
|
|
541
|
-
gatewayHeader?: string | undefined;
|
|
542
|
-
gatewaySecret?: string | undefined;
|
|
543
|
-
};
|
|
544
516
|
} | undefined;
|
|
545
517
|
cors?: {
|
|
546
518
|
allowedHeaders: string[];
|
|
@@ -553,6 +525,8 @@ declare const ServConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
553
525
|
keyExchangePath: `/${string}`;
|
|
554
526
|
excludePaths: `/${string}`[];
|
|
555
527
|
maxPlaintextBytes?: number | undefined;
|
|
528
|
+
maxFutureSkewSeconds?: number | undefined;
|
|
529
|
+
maxRequestAgeSeconds?: number | undefined;
|
|
556
530
|
routePlaintextBytes?: Record<`/${string}`, number> | undefined;
|
|
557
531
|
} | undefined;
|
|
558
532
|
}>>;
|
|
@@ -577,6 +551,10 @@ interface ServTransportConfig {
|
|
|
577
551
|
/** 受管服务端密钥环,仅运行时从私有 Secret 注入。 */
|
|
578
552
|
/** 双向业务明文 UTF-8 字节上限;默认 1 MiB,整数范围 1 KiB~64 MiB。 */
|
|
579
553
|
readonly maxPlaintextBytes?: number;
|
|
554
|
+
/** 请求时间允许领先服务器的秒数,默认 30,整数范围 0~300。 */
|
|
555
|
+
readonly maxFutureSkewSeconds?: number;
|
|
556
|
+
/** 请求从签发起的有效秒数,默认 300,整数范围 1~600。 */
|
|
557
|
+
readonly maxRequestAgeSeconds?: number;
|
|
580
558
|
/** 路由明文容量;* 匹配一个完整路径段。 */
|
|
581
559
|
routePlaintextBytes?: Readonly<Record<string, number>>;
|
|
582
560
|
readonly serverKeyRing: TransportServerKeyRing;
|
|
@@ -954,8 +932,8 @@ interface ServListenOptions {
|
|
|
954
932
|
* 优雅关闭回调(释放业务模块资源)。
|
|
955
933
|
*
|
|
956
934
|
* 传入后 `serv.listen` 自动监听 `SIGINT` / `SIGTERM`,按以下顺序关闭:
|
|
957
|
-
* 1. 停止接受新 HTTP
|
|
958
|
-
* 2.
|
|
935
|
+
* 1. 停止接受新 HTTP 连接,关闭 Audio WebSocket(未配合者最多等待一秒)
|
|
936
|
+
* 2. 等待监听句柄关闭,再调用此回调释放业务资源
|
|
959
937
|
*
|
|
960
938
|
* 应用层无需手动注册 `process.once('SIGINT', ...)` 或维护 `shuttingDown` 标志。
|
|
961
939
|
*/
|
|
@@ -983,7 +961,7 @@ interface ServNodeServer {
|
|
|
983
961
|
readonly host: string;
|
|
984
962
|
readonly port: number;
|
|
985
963
|
};
|
|
986
|
-
/**
|
|
964
|
+
/** 停止接入或取消待完成绑定;关闭语音连接最多等待一秒。并发关闭复用结果,真实监听失败仍会拒绝。 */
|
|
987
965
|
readonly close: () => Promise<void>;
|
|
988
966
|
}
|
|
989
967
|
/**
|
|
@@ -1059,6 +1037,23 @@ interface ServCorsConfig {
|
|
|
1059
1037
|
*/
|
|
1060
1038
|
declare function cors(config?: ServCorsConfig): ServMiddleware;
|
|
1061
1039
|
|
|
1040
|
+
/**
|
|
1041
|
+
* 获取 Serv 模块的 i18n 消息。
|
|
1042
|
+
*
|
|
1043
|
+
* 单次调用可通过 `options.locale` 指定该次调用使用的语言,
|
|
1044
|
+
* 用于在请求处理过程中根据 `Accept-Language` 头本地化错误消息,
|
|
1045
|
+
* 而不污染全局 locale(多并发请求安全)。
|
|
1046
|
+
*
|
|
1047
|
+
* @example
|
|
1048
|
+
* ```ts
|
|
1049
|
+
* import { serv } from '@h-ai/serv'
|
|
1050
|
+
*
|
|
1051
|
+
* const message = serv.m('serv_validationStringMin', { locale: 'en-US', params: { min: 3 } })
|
|
1052
|
+
* // 单次 locale 不修改并发请求的全局语言。
|
|
1053
|
+
* ```
|
|
1054
|
+
*/
|
|
1055
|
+
declare const servM: (key: "serv_transportPlaintextRequired" | "$schema" | "serv_validationFailed" | "serv_validationRequired" | "serv_validationInvalid" | "serv_validationInvalidType" | "serv_validationUnexpectedFields" | "serv_validationStringMin" | "serv_validationStringMax" | "serv_validationNumberMin" | "serv_validationNumberMax" | "serv_validationArrayMin" | "serv_validationArrayMax" | "serv_validationTooSmall" | "serv_validationTooBig" | "serv_validationEmail" | "serv_validationUrl" | "serv_validationUuid" | "serv_validationEnum" | "serv_errorUnauthorized" | "serv_errorForbidden" | "serv_errorInternal" | "serv_storageKeyRequired" | "serv_storageKeyTooLong" | "serv_storageKeyIllegalChars" | "serv_storageKeyDotSegments" | "serv_iamCannotDeleteCurrentUser" | "serv_transportInvalidPayload" | "serv_transportUnknownClient" | "serv_transportClientIdRequired" | "serv_transportClientKeyNotFound" | "serv_transportDecryptFailed" | "serv_transportEncryptFailed" | "serv_transportKeyExchangeFailed" | "serv_transportBusy" | "serv_feedbackUnavailable" | "serv_invalidApiPrefix", options?: _h_ai_core.MessageOptions) => string;
|
|
1056
|
+
|
|
1062
1057
|
/**
|
|
1063
1058
|
* @h-ai/serv — OpenAPI 文档
|
|
1064
1059
|
*
|
|
@@ -1142,11 +1137,13 @@ interface ServRuntimeSecurityPolicyInput {
|
|
|
1142
1137
|
interface ServRuntimeSecurityPolicy {
|
|
1143
1138
|
readonly allowOrigin: (origin: string) => boolean;
|
|
1144
1139
|
readonly isNativeOrigin: (origin: string) => boolean;
|
|
1140
|
+
/** 刷新 Cookie 是否启用 Secure,默认在生产开启。 */
|
|
1145
1141
|
readonly secureRefreshCookie: boolean;
|
|
1146
1142
|
readonly exposeApiDocs: boolean;
|
|
1147
1143
|
}
|
|
1148
1144
|
/**
|
|
1149
1145
|
* 校验部署 Origin 并生成 Cookie、文档与跨端 CORS 安全策略。
|
|
1146
|
+
* `HAI_SERV_REFRESH_COOKIE_SECURE` 可覆盖刷新 Cookie 的 Secure 默认值。
|
|
1150
1147
|
*
|
|
1151
1148
|
* @param input - 部署环境与显式允许的 Web/原生 Origin
|
|
1152
1149
|
* @returns 可用于 HTTP 装配的策略
|
|
@@ -1337,26 +1334,28 @@ declare function resolveRequestLocale(headers: Headers | Record<string, string |
|
|
|
1337
1334
|
declare function validateInputOrFail<TOutput>(schema: ZodType<TOutput>, input: unknown, locale?: string): HaiResult<TOutput>;
|
|
1338
1335
|
|
|
1339
1336
|
/**
|
|
1340
|
-
*
|
|
1337
|
+
* @h-ai/serv — 公开类型聚合
|
|
1341
1338
|
*
|
|
1339
|
+
* 将各模块对外暴露的类型集中在此重导出,方便消费方按需 `import type`。
|
|
1340
|
+
* @module serv-types
|
|
1341
|
+
*/
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* Serv 公开命名空间;显式函数签名避免消费者声明引用内部共享构建块。
|
|
1342
1345
|
* @example
|
|
1343
1346
|
* ```ts
|
|
1344
|
-
* import type {
|
|
1345
|
-
* import { apiContract } from '@h-ai/api-contract'
|
|
1347
|
+
* import type { ServFunctions } from '@h-ai/serv'
|
|
1346
1348
|
* import { serv } from '@h-ai/serv'
|
|
1347
1349
|
*
|
|
1348
|
-
* const
|
|
1349
|
-
* const
|
|
1350
|
-
*
|
|
1351
|
-
*
|
|
1352
|
-
* const response = await app.request('/health')
|
|
1353
|
-
* if (!response.ok) throw new Error('Health request failed')
|
|
1350
|
+
* const runtime: ServFunctions = serv
|
|
1351
|
+
* const context = runtime.parseRequestContext({ request: new Request('https://example.com') })
|
|
1352
|
+
* void context.requestId
|
|
1354
1353
|
* ```
|
|
1355
1354
|
*/
|
|
1356
|
-
|
|
1355
|
+
interface ServFunctions {
|
|
1357
1356
|
createApp: typeof createApp;
|
|
1358
|
-
parseRequestContext:
|
|
1359
|
-
buildAuthContextFactory:
|
|
1357
|
+
parseRequestContext: (input: CreateServContextInput) => ServContext;
|
|
1358
|
+
buildAuthContextFactory: (verifyToken: (accessToken: string) => Promise<HaiResult<ServSession>>) => CreateServContext;
|
|
1360
1359
|
resolveRequestLocale: typeof resolveRequestLocale;
|
|
1361
1360
|
listen: typeof listen;
|
|
1362
1361
|
toFetch: typeof toFetch;
|
|
@@ -1364,11 +1363,41 @@ declare const serv: {
|
|
|
1364
1363
|
storageAssets: typeof storageAssets;
|
|
1365
1364
|
createRuntimeSecurityPolicy: typeof createRuntimeSecurityPolicy;
|
|
1366
1365
|
generateSpec: typeof generateSpec;
|
|
1367
|
-
implement:
|
|
1366
|
+
implement: <TContract extends ContractRouter<Meta>>(contract: TContract) => ServImplementer<TContract>;
|
|
1368
1367
|
validateInputOrFail: typeof validateInputOrFail;
|
|
1369
1368
|
WILDCARD_PERMISSION: string;
|
|
1370
1369
|
WILDCARD_ROLE: string;
|
|
1371
|
-
m:
|
|
1372
|
-
}
|
|
1370
|
+
m: typeof servM;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* @h-ai/serv — API service runtime 统一入口
|
|
1375
|
+
*
|
|
1376
|
+
* 将 createApp、parseRequestContext、buildAuthContextFactory、listen、toFetch、openapi、pipeline 工具集合为扁平
|
|
1377
|
+
* 的 `serv` 命名空间,应用层通过这个模块访问所有 runtime 能力而无需直接导入内部文件。
|
|
1378
|
+
*
|
|
1379
|
+
* @module serv-main
|
|
1380
|
+
*
|
|
1381
|
+
*/
|
|
1382
|
+
|
|
1383
|
+
/**
|
|
1384
|
+
* hai-framework API service runtime 统一入口(扁平 API)。
|
|
1385
|
+
*
|
|
1386
|
+
* @example
|
|
1387
|
+
* ```ts
|
|
1388
|
+
* import type { ServContext } from '@h-ai/serv'
|
|
1389
|
+
* import { apiContract } from '@h-ai/api-contract'
|
|
1390
|
+
* import { serv } from '@h-ai/serv'
|
|
1391
|
+
*
|
|
1392
|
+
* const contract = apiContract.create({})
|
|
1393
|
+
* const procedures = serv.implement(contract).context<ServContext>().build()
|
|
1394
|
+
* const app = serv.createApp({ contract, procedures })
|
|
1395
|
+
*
|
|
1396
|
+
* const response = await app.request('/health')
|
|
1397
|
+
* if (!response.ok) throw new Error('Health request failed')
|
|
1398
|
+
* ```
|
|
1399
|
+
*/
|
|
1400
|
+
declare const serv: ServFunctions;
|
|
1373
1401
|
|
|
1374
|
-
export {
|
|
1402
|
+
export { CreateServContext, CreateServContextInput, RefreshCookieConfig, ServConfigSchema, ServContext, ServIam, ServImplementer, ServRequestMetadata, ServSession, serv };
|
|
1403
|
+
export type { AudioTicketGrant, AudioTicketVerification, AuthorizedAudioRequest, CreateServAppOptions, GenerateOpenAPISpecOptions, ServAudioConfig, ServConfig, ServConfigInput, ServCorsConfig, ServCorsRuntimeConfig, ServCorsRuntimeConfigInput, ServDocsHttpConfig, ServFetchHandler, ServFunctions, ServHealthHttpConfig, ServHttpApp, ServHttpConfig, ServHttpConfigInput, ServListenOptions, ServMiddleware, ServMiddlewareFactory, ServMiddlewareMount, ServNodeServer, ServOpenAPIHttpConfig, ServProcedureHandler, ServProcedureOptions, ServRuntimeSecurityPolicy, ServRuntimeSecurityPolicyInput, ServServerConfig, ServServerConfigInput, ServStorageAssetsConfig, ServTransportConfig, ServTransportRuntimeConfig, ServTransportRuntimeConfigInput, ServValidationFailureBody };
|