@lark-apaas/fullstack-nestjs-core 1.1.22 → 1.1.38
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.md +39 -0
- package/dist/index.cjs +35659 -171
- package/dist/index.d.cts +239 -7
- package/dist/index.d.ts +239 -7
- package/dist/index.js +35656 -150
- package/package.json +11 -11
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { NestModule, DynamicModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
|
|
2
|
-
import { HttpClientConfig, PlatformPluginOptions } from '@lark-apaas/http-client';
|
|
1
|
+
import { NestModule, DynamicModule, MiddlewareConsumer, OnModuleInit, NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import { HttpClientConfig, PlatformPluginOptions, HttpClient } from '@lark-apaas/http-client';
|
|
3
|
+
import { AuthZPaasModuleOptions } from '@lark-apaas/nestjs-authzpaas';
|
|
4
|
+
export { AddMembersParams, AuthZPaasModule, AuthorizationSDK, Can, CanRole, ChatSimpleDTO, CommonParam, CreateRoleParams, CreateRoleResponse, DepartmentDTO, DepartmentEntity, DepartmentSimpleDTO, FilterParams, ForceRoleDTO, I18nText, IPermissionResolver, ListMembersParams, ListMembersResponse, ListRolesParams, MemberMutationData, MemberType, PERMISSION_RESOLVER_TOKEN, PermissionPoint, PermissionRequirement, PresetGroupDTO, RemoveMembersParams, RoleMemberDTO, SearchChatEntity, SearchParams, SearchResponse, SearchResult, SearchUserEntity, UpdateRoleParams, UserSimpleDTO } from '@lark-apaas/nestjs-authzpaas';
|
|
3
5
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
4
|
-
export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
|
|
5
|
-
import { Request, Response, NextFunction } from 'express';
|
|
6
6
|
import { PlatformHttpClient, RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
|
|
7
7
|
export { AutoTrace } from '@lark-apaas/nestjs-common';
|
|
8
|
+
export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
|
|
9
|
+
import { Request, Response, NextFunction } from 'express';
|
|
8
10
|
import * as _lark_apaas_file_service from '@lark-apaas/file-service';
|
|
9
11
|
import { FileBody, UploadOptions, FileDownloadBuilder, SearchOptions } from '@lark-apaas/file-service';
|
|
10
12
|
export * from '@lark-apaas/file-service';
|
|
@@ -13,7 +15,6 @@ export * from '@lark-apaas/nestjs-capability';
|
|
|
13
15
|
export * from '@lark-apaas/nestjs-datapaas';
|
|
14
16
|
export * from '@lark-apaas/nestjs-observable';
|
|
15
17
|
export * from '@lark-apaas/nestjs-trigger';
|
|
16
|
-
export { CanRole } from '@lark-apaas/nestjs-authzpaas';
|
|
17
18
|
|
|
18
19
|
declare global {
|
|
19
20
|
namespace Express {
|
|
@@ -34,7 +35,7 @@ declare global {
|
|
|
34
35
|
userName?: string; // 默认中文名
|
|
35
36
|
userNameEn?: string; // 冗余一份英文名
|
|
36
37
|
userNameI18n?: Record<string, string>; // 带多语的用户名
|
|
37
|
-
isSystemAccount?: boolean; // trigger
|
|
38
|
+
isSystemAccount?: boolean; // 是否为系统账号,trigger 场景下为 true
|
|
38
39
|
roles?: string[]; // 用户角色 id 列表
|
|
39
40
|
};
|
|
40
41
|
csrfToken?: string;
|
|
@@ -72,6 +73,11 @@ interface PlatformModuleOptions {
|
|
|
72
73
|
* 默认: server/capabilities
|
|
73
74
|
*/
|
|
74
75
|
capabilitiesDir?: string;
|
|
76
|
+
/**
|
|
77
|
+
* AuthZPaas 模块配置
|
|
78
|
+
* 可传入 permissionResolver 等选项,透传给 AuthZPaasModule.forRoot()
|
|
79
|
+
*/
|
|
80
|
+
authz?: AuthZPaasModuleOptions;
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
declare class PlatformModule implements NestModule {
|
|
@@ -89,11 +95,81 @@ declare class PlatformModule implements NestModule {
|
|
|
89
95
|
* @param app NestExpressApplication 实例
|
|
90
96
|
* @param perms 配置项
|
|
91
97
|
* @param perms.disableSwagger 是否禁用 Swagger(默认:false)
|
|
98
|
+
* @param perms.bodyLimit 请求体大小限制,优先级:perms.bodyLimit > env.BODY_LIMIT > '1mb'
|
|
92
99
|
*/
|
|
93
100
|
declare function configureApp(app: NestExpressApplication, perms?: {
|
|
94
101
|
disableSwagger?: boolean;
|
|
102
|
+
bodyLimit?: string;
|
|
95
103
|
}): Promise<void>;
|
|
96
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Static Module
|
|
107
|
+
*
|
|
108
|
+
* Provides serving of static files from the shared/static directory.
|
|
109
|
+
* This module is automatically imported by PlatformModule in PRODUCTION mode only.
|
|
110
|
+
*
|
|
111
|
+
* Architecture:
|
|
112
|
+
* - Development: Vite/Rspack dev server middleware handles /static/* requests
|
|
113
|
+
* (faster response, HMR support)
|
|
114
|
+
* - Production: NestJS StaticController handles /static/* requests
|
|
115
|
+
* (proper caching, ETag support)
|
|
116
|
+
*
|
|
117
|
+
* Features:
|
|
118
|
+
* - Serves files at GET /static/* route
|
|
119
|
+
* - Security protection against path traversal
|
|
120
|
+
* - Proper MIME type detection
|
|
121
|
+
* - ETag-based cache validation
|
|
122
|
+
* - Streaming response for efficient file delivery
|
|
123
|
+
*
|
|
124
|
+
* Usage:
|
|
125
|
+
* 1. Place static files in shared/static/ directory
|
|
126
|
+
* 2. Import files in frontend: import x from '@shared/static/path'
|
|
127
|
+
* 3. Access files at {basePath}/static/{path}
|
|
128
|
+
*/
|
|
129
|
+
declare class StaticModule {
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* HTML 热更新模块
|
|
134
|
+
*
|
|
135
|
+
* 提供两个能力:
|
|
136
|
+
* 1. 冷启动时主动拉取最新 HTML 文件列表并替换本地文件(任务一)
|
|
137
|
+
* 2. 对外暴露 innerapi 接口,供 tce 服务主动触发热更新(任务二)
|
|
138
|
+
*
|
|
139
|
+
* 仅在生产环境加载(PlatformModule 中控制),两个能力默认都启用。
|
|
140
|
+
*/
|
|
141
|
+
declare class HtmlHotUpdateModule {
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface HtmlHotUpdateResult {
|
|
145
|
+
updatedFiles: string[];
|
|
146
|
+
failedFiles: {
|
|
147
|
+
filePath: string;
|
|
148
|
+
reason: string;
|
|
149
|
+
}[];
|
|
150
|
+
}
|
|
151
|
+
declare class HtmlHotUpdateService implements OnModuleInit {
|
|
152
|
+
private readonly httpClient;
|
|
153
|
+
private readonly logger;
|
|
154
|
+
private readonly fileLock;
|
|
155
|
+
private readonly hotUpdateDir;
|
|
156
|
+
private readonly hotUpdateVersionsDir;
|
|
157
|
+
private readonly originalHtmlDir;
|
|
158
|
+
constructor(httpClient: PlatformHttpClient);
|
|
159
|
+
onModuleInit(): Promise<void>;
|
|
160
|
+
resolveHtmlPath(fileName: string): string;
|
|
161
|
+
getViewsDirs(): string[];
|
|
162
|
+
getActiveVersion(): string;
|
|
163
|
+
computeVersion(fileMap: Record<string, string>): string;
|
|
164
|
+
normalizeFilePath(filePath: string): string;
|
|
165
|
+
updateFromRemote(appID: string, commitID?: string): Promise<HtmlHotUpdateResult>;
|
|
166
|
+
writeHtmlFiles(fileMap: Record<string, string>): Promise<HtmlHotUpdateResult>;
|
|
167
|
+
private promoteVersionDirectory;
|
|
168
|
+
private cleanupOldVersions;
|
|
169
|
+
private fetchLatestHtmlFiles;
|
|
170
|
+
private getAppID;
|
|
171
|
+
}
|
|
172
|
+
|
|
97
173
|
interface CsrfTokenOptions {
|
|
98
174
|
cookieKey?: string;
|
|
99
175
|
cookieMaxAge?: number;
|
|
@@ -129,6 +205,22 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
129
205
|
use(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
130
206
|
}
|
|
131
207
|
|
|
208
|
+
/**
|
|
209
|
+
* 创建旧路径兼容中间件(纯 Express 中间件)。
|
|
210
|
+
*
|
|
211
|
+
* 当 CLIENT_BASE_PATH 为新的 /app/:appId 格式时,
|
|
212
|
+
* 将旧路径请求映射到新路径:
|
|
213
|
+
* 预览态:/af/p/:appId/... → /app/:appId/...
|
|
214
|
+
* 运行态:/spark/faas/:appId/... → /app/:appId/...
|
|
215
|
+
*
|
|
216
|
+
* 处理策略:
|
|
217
|
+
* - API 路由(/api/)及内部路由(/__innerapi__/):URL rewrite,保留 HTTP 方法和请求体
|
|
218
|
+
* - 页面导航(GET 其他路径):302 重定向,更新浏览器地址栏
|
|
219
|
+
*
|
|
220
|
+
* 不依赖 req.userContext,直接通过正则从 URL 解析 appId。
|
|
221
|
+
*/
|
|
222
|
+
declare function createLegacyPathRedirectMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
|
|
223
|
+
|
|
132
224
|
/**
|
|
133
225
|
* API 404 响应格式
|
|
134
226
|
*/
|
|
@@ -169,4 +261,144 @@ declare class FileService {
|
|
|
169
261
|
private _getFileMetadata;
|
|
170
262
|
}
|
|
171
263
|
|
|
172
|
-
|
|
264
|
+
/**
|
|
265
|
+
* 平台 HttpClient 服务
|
|
266
|
+
*
|
|
267
|
+
* 提供两种使用方式:
|
|
268
|
+
* 1. 全局实例:通过 `instance` 或 `PLATFORM_HTTP_CLIENT` 注入,适用于 95% 的场景
|
|
269
|
+
* 2. 独立实例:通过 `create()` 创建,适用于需要自定义拦截器或配置的场景
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* 基本使用(推荐)
|
|
273
|
+
* ```typescript
|
|
274
|
+
* @Injectable()
|
|
275
|
+
* export class UserService {
|
|
276
|
+
* constructor(
|
|
277
|
+
* @Inject(PLATFORM_HTTP_CLIENT) private http: SafeHttpClient
|
|
278
|
+
* ) {}
|
|
279
|
+
*
|
|
280
|
+
* async getUser() {
|
|
281
|
+
* return this.http.get('/user');
|
|
282
|
+
* }
|
|
283
|
+
* }
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* 需要自定义拦截器(高级场景)
|
|
288
|
+
* ```typescript
|
|
289
|
+
* @Injectable()
|
|
290
|
+
* export class FileService {
|
|
291
|
+
* private fileClient: HttpClient;
|
|
292
|
+
*
|
|
293
|
+
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
294
|
+
* this.fileClient = this.platformHttp.create({
|
|
295
|
+
* config: { timeout: 60000 }
|
|
296
|
+
* });
|
|
297
|
+
*
|
|
298
|
+
* this.fileClient.interceptors.request.use((config) => {
|
|
299
|
+
* console.log('File upload starting...');
|
|
300
|
+
* return config;
|
|
301
|
+
* });
|
|
302
|
+
* }
|
|
303
|
+
* }
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
declare class PlatformHttpClientService {
|
|
307
|
+
private readonly requestContext;
|
|
308
|
+
private readonly client;
|
|
309
|
+
private readonly protectedClient;
|
|
310
|
+
private readonly logger;
|
|
311
|
+
constructor(requestContext: RequestContextService);
|
|
312
|
+
/**
|
|
313
|
+
* 获取受保护的 HttpClient 实例(推荐)
|
|
314
|
+
*
|
|
315
|
+
* 该实例不暴露 interceptors,防止业务代码修改全局拦截器
|
|
316
|
+
*
|
|
317
|
+
* @returns 受保护的 HttpClient 实例
|
|
318
|
+
*/
|
|
319
|
+
get instance(): PlatformHttpClient;
|
|
320
|
+
/**
|
|
321
|
+
* 获取原始 HttpClient 实例(危险)
|
|
322
|
+
*
|
|
323
|
+
* ⚠️ 警告:该实例允许修改拦截器,会影响所有使用全局实例的地方
|
|
324
|
+
*
|
|
325
|
+
* 仅用于特殊场景,不应该暴露给业务代码
|
|
326
|
+
* 如果需要自定义拦截器,请使用 `create()` 方法创建独立实例
|
|
327
|
+
*
|
|
328
|
+
* @internal
|
|
329
|
+
* @returns 原始 HttpClient 实例
|
|
330
|
+
*/
|
|
331
|
+
get rawInstance(): HttpClient;
|
|
332
|
+
/**
|
|
333
|
+
* 创建一个新的独立 HttpClient 实例
|
|
334
|
+
*
|
|
335
|
+
* 适用于需要自定义拦截器或配置的场景
|
|
336
|
+
* 创建的实例完全独立,不会影响全局实例
|
|
337
|
+
*
|
|
338
|
+
* @param options - 配置选项(会与全局配置合并)
|
|
339
|
+
* @returns 完整的 HttpClient 实例(允许修改拦截器)
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* @Injectable()
|
|
344
|
+
* export class FileService {
|
|
345
|
+
* private fileClient: HttpClient;
|
|
346
|
+
*
|
|
347
|
+
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
348
|
+
* // 创建超时 60 秒的独立实例
|
|
349
|
+
* this.fileClient = this.platformHttp.create({
|
|
350
|
+
* config: { timeout: 60000 }
|
|
351
|
+
* });
|
|
352
|
+
*
|
|
353
|
+
* // 为这个实例注册拦截器(不影响全局实例)
|
|
354
|
+
* this.fileClient.interceptors.request.use((config) => {
|
|
355
|
+
* console.log('File upload starting...');
|
|
356
|
+
* return config;
|
|
357
|
+
* });
|
|
358
|
+
* }
|
|
359
|
+
*
|
|
360
|
+
* async uploadFile(file: Buffer) {
|
|
361
|
+
* return this.fileClient.post('/file/upload', file);
|
|
362
|
+
* }
|
|
363
|
+
* }
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
create(options?: PlatformHttpClientOptions): HttpClient;
|
|
367
|
+
/**
|
|
368
|
+
* 创建一个带全局拦截器的独立 HttpClient 实例
|
|
369
|
+
*
|
|
370
|
+
* 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
|
|
371
|
+
* 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
|
|
372
|
+
*
|
|
373
|
+
* @param options - 配置选项(会与全局配置合并)
|
|
374
|
+
* @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const client = this.platformHttp.createWithGlobalInterceptors();
|
|
379
|
+
* // 客户端已包含日志和 x-tt-env 拦截器
|
|
380
|
+
* // 可以继续添加自定义拦截器
|
|
381
|
+
* client.interceptors.request.use((config) => {
|
|
382
|
+
* config.headers['x-custom'] = 'value';
|
|
383
|
+
* return config;
|
|
384
|
+
* });
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
|
|
388
|
+
/**
|
|
389
|
+
* 注册全局拦截器(用于单例实例)
|
|
390
|
+
*/
|
|
391
|
+
private registerGlobalInterceptors;
|
|
392
|
+
/**
|
|
393
|
+
* 为指定的 HttpClient 实例注册标准拦截器
|
|
394
|
+
*
|
|
395
|
+
* 包含:
|
|
396
|
+
* - 请求日志记录
|
|
397
|
+
* - x-tt-env header 透传
|
|
398
|
+
* - 响应日志记录
|
|
399
|
+
* - 错误日志记录
|
|
400
|
+
*/
|
|
401
|
+
private registerInterceptorsForClient;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { NestModule, DynamicModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
|
|
2
|
-
import { HttpClientConfig, PlatformPluginOptions } from '@lark-apaas/http-client';
|
|
1
|
+
import { NestModule, DynamicModule, MiddlewareConsumer, OnModuleInit, NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import { HttpClientConfig, PlatformPluginOptions, HttpClient } from '@lark-apaas/http-client';
|
|
3
|
+
import { AuthZPaasModuleOptions } from '@lark-apaas/nestjs-authzpaas';
|
|
4
|
+
export { AddMembersParams, AuthZPaasModule, AuthorizationSDK, Can, CanRole, ChatSimpleDTO, CommonParam, CreateRoleParams, CreateRoleResponse, DepartmentDTO, DepartmentEntity, DepartmentSimpleDTO, FilterParams, ForceRoleDTO, I18nText, IPermissionResolver, ListMembersParams, ListMembersResponse, ListRolesParams, MemberMutationData, MemberType, PERMISSION_RESOLVER_TOKEN, PermissionPoint, PermissionRequirement, PresetGroupDTO, RemoveMembersParams, RoleMemberDTO, SearchChatEntity, SearchParams, SearchResponse, SearchResult, SearchUserEntity, UpdateRoleParams, UserSimpleDTO } from '@lark-apaas/nestjs-authzpaas';
|
|
3
5
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
4
|
-
export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
|
|
5
|
-
import { Request, Response, NextFunction } from 'express';
|
|
6
6
|
import { PlatformHttpClient, RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
|
|
7
7
|
export { AutoTrace } from '@lark-apaas/nestjs-common';
|
|
8
|
+
export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
|
|
9
|
+
import { Request, Response, NextFunction } from 'express';
|
|
8
10
|
import * as _lark_apaas_file_service from '@lark-apaas/file-service';
|
|
9
11
|
import { FileBody, UploadOptions, FileDownloadBuilder, SearchOptions } from '@lark-apaas/file-service';
|
|
10
12
|
export * from '@lark-apaas/file-service';
|
|
@@ -13,7 +15,6 @@ export * from '@lark-apaas/nestjs-capability';
|
|
|
13
15
|
export * from '@lark-apaas/nestjs-datapaas';
|
|
14
16
|
export * from '@lark-apaas/nestjs-observable';
|
|
15
17
|
export * from '@lark-apaas/nestjs-trigger';
|
|
16
|
-
export { CanRole } from '@lark-apaas/nestjs-authzpaas';
|
|
17
18
|
|
|
18
19
|
declare global {
|
|
19
20
|
namespace Express {
|
|
@@ -34,7 +35,7 @@ declare global {
|
|
|
34
35
|
userName?: string; // 默认中文名
|
|
35
36
|
userNameEn?: string; // 冗余一份英文名
|
|
36
37
|
userNameI18n?: Record<string, string>; // 带多语的用户名
|
|
37
|
-
isSystemAccount?: boolean; // trigger
|
|
38
|
+
isSystemAccount?: boolean; // 是否为系统账号,trigger 场景下为 true
|
|
38
39
|
roles?: string[]; // 用户角色 id 列表
|
|
39
40
|
};
|
|
40
41
|
csrfToken?: string;
|
|
@@ -72,6 +73,11 @@ interface PlatformModuleOptions {
|
|
|
72
73
|
* 默认: server/capabilities
|
|
73
74
|
*/
|
|
74
75
|
capabilitiesDir?: string;
|
|
76
|
+
/**
|
|
77
|
+
* AuthZPaas 模块配置
|
|
78
|
+
* 可传入 permissionResolver 等选项,透传给 AuthZPaasModule.forRoot()
|
|
79
|
+
*/
|
|
80
|
+
authz?: AuthZPaasModuleOptions;
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
declare class PlatformModule implements NestModule {
|
|
@@ -89,11 +95,81 @@ declare class PlatformModule implements NestModule {
|
|
|
89
95
|
* @param app NestExpressApplication 实例
|
|
90
96
|
* @param perms 配置项
|
|
91
97
|
* @param perms.disableSwagger 是否禁用 Swagger(默认:false)
|
|
98
|
+
* @param perms.bodyLimit 请求体大小限制,优先级:perms.bodyLimit > env.BODY_LIMIT > '1mb'
|
|
92
99
|
*/
|
|
93
100
|
declare function configureApp(app: NestExpressApplication, perms?: {
|
|
94
101
|
disableSwagger?: boolean;
|
|
102
|
+
bodyLimit?: string;
|
|
95
103
|
}): Promise<void>;
|
|
96
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Static Module
|
|
107
|
+
*
|
|
108
|
+
* Provides serving of static files from the shared/static directory.
|
|
109
|
+
* This module is automatically imported by PlatformModule in PRODUCTION mode only.
|
|
110
|
+
*
|
|
111
|
+
* Architecture:
|
|
112
|
+
* - Development: Vite/Rspack dev server middleware handles /static/* requests
|
|
113
|
+
* (faster response, HMR support)
|
|
114
|
+
* - Production: NestJS StaticController handles /static/* requests
|
|
115
|
+
* (proper caching, ETag support)
|
|
116
|
+
*
|
|
117
|
+
* Features:
|
|
118
|
+
* - Serves files at GET /static/* route
|
|
119
|
+
* - Security protection against path traversal
|
|
120
|
+
* - Proper MIME type detection
|
|
121
|
+
* - ETag-based cache validation
|
|
122
|
+
* - Streaming response for efficient file delivery
|
|
123
|
+
*
|
|
124
|
+
* Usage:
|
|
125
|
+
* 1. Place static files in shared/static/ directory
|
|
126
|
+
* 2. Import files in frontend: import x from '@shared/static/path'
|
|
127
|
+
* 3. Access files at {basePath}/static/{path}
|
|
128
|
+
*/
|
|
129
|
+
declare class StaticModule {
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* HTML 热更新模块
|
|
134
|
+
*
|
|
135
|
+
* 提供两个能力:
|
|
136
|
+
* 1. 冷启动时主动拉取最新 HTML 文件列表并替换本地文件(任务一)
|
|
137
|
+
* 2. 对外暴露 innerapi 接口,供 tce 服务主动触发热更新(任务二)
|
|
138
|
+
*
|
|
139
|
+
* 仅在生产环境加载(PlatformModule 中控制),两个能力默认都启用。
|
|
140
|
+
*/
|
|
141
|
+
declare class HtmlHotUpdateModule {
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface HtmlHotUpdateResult {
|
|
145
|
+
updatedFiles: string[];
|
|
146
|
+
failedFiles: {
|
|
147
|
+
filePath: string;
|
|
148
|
+
reason: string;
|
|
149
|
+
}[];
|
|
150
|
+
}
|
|
151
|
+
declare class HtmlHotUpdateService implements OnModuleInit {
|
|
152
|
+
private readonly httpClient;
|
|
153
|
+
private readonly logger;
|
|
154
|
+
private readonly fileLock;
|
|
155
|
+
private readonly hotUpdateDir;
|
|
156
|
+
private readonly hotUpdateVersionsDir;
|
|
157
|
+
private readonly originalHtmlDir;
|
|
158
|
+
constructor(httpClient: PlatformHttpClient);
|
|
159
|
+
onModuleInit(): Promise<void>;
|
|
160
|
+
resolveHtmlPath(fileName: string): string;
|
|
161
|
+
getViewsDirs(): string[];
|
|
162
|
+
getActiveVersion(): string;
|
|
163
|
+
computeVersion(fileMap: Record<string, string>): string;
|
|
164
|
+
normalizeFilePath(filePath: string): string;
|
|
165
|
+
updateFromRemote(appID: string, commitID?: string): Promise<HtmlHotUpdateResult>;
|
|
166
|
+
writeHtmlFiles(fileMap: Record<string, string>): Promise<HtmlHotUpdateResult>;
|
|
167
|
+
private promoteVersionDirectory;
|
|
168
|
+
private cleanupOldVersions;
|
|
169
|
+
private fetchLatestHtmlFiles;
|
|
170
|
+
private getAppID;
|
|
171
|
+
}
|
|
172
|
+
|
|
97
173
|
interface CsrfTokenOptions {
|
|
98
174
|
cookieKey?: string;
|
|
99
175
|
cookieMaxAge?: number;
|
|
@@ -129,6 +205,22 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
129
205
|
use(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
130
206
|
}
|
|
131
207
|
|
|
208
|
+
/**
|
|
209
|
+
* 创建旧路径兼容中间件(纯 Express 中间件)。
|
|
210
|
+
*
|
|
211
|
+
* 当 CLIENT_BASE_PATH 为新的 /app/:appId 格式时,
|
|
212
|
+
* 将旧路径请求映射到新路径:
|
|
213
|
+
* 预览态:/af/p/:appId/... → /app/:appId/...
|
|
214
|
+
* 运行态:/spark/faas/:appId/... → /app/:appId/...
|
|
215
|
+
*
|
|
216
|
+
* 处理策略:
|
|
217
|
+
* - API 路由(/api/)及内部路由(/__innerapi__/):URL rewrite,保留 HTTP 方法和请求体
|
|
218
|
+
* - 页面导航(GET 其他路径):302 重定向,更新浏览器地址栏
|
|
219
|
+
*
|
|
220
|
+
* 不依赖 req.userContext,直接通过正则从 URL 解析 appId。
|
|
221
|
+
*/
|
|
222
|
+
declare function createLegacyPathRedirectMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
|
|
223
|
+
|
|
132
224
|
/**
|
|
133
225
|
* API 404 响应格式
|
|
134
226
|
*/
|
|
@@ -169,4 +261,144 @@ declare class FileService {
|
|
|
169
261
|
private _getFileMetadata;
|
|
170
262
|
}
|
|
171
263
|
|
|
172
|
-
|
|
264
|
+
/**
|
|
265
|
+
* 平台 HttpClient 服务
|
|
266
|
+
*
|
|
267
|
+
* 提供两种使用方式:
|
|
268
|
+
* 1. 全局实例:通过 `instance` 或 `PLATFORM_HTTP_CLIENT` 注入,适用于 95% 的场景
|
|
269
|
+
* 2. 独立实例:通过 `create()` 创建,适用于需要自定义拦截器或配置的场景
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* 基本使用(推荐)
|
|
273
|
+
* ```typescript
|
|
274
|
+
* @Injectable()
|
|
275
|
+
* export class UserService {
|
|
276
|
+
* constructor(
|
|
277
|
+
* @Inject(PLATFORM_HTTP_CLIENT) private http: SafeHttpClient
|
|
278
|
+
* ) {}
|
|
279
|
+
*
|
|
280
|
+
* async getUser() {
|
|
281
|
+
* return this.http.get('/user');
|
|
282
|
+
* }
|
|
283
|
+
* }
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* 需要自定义拦截器(高级场景)
|
|
288
|
+
* ```typescript
|
|
289
|
+
* @Injectable()
|
|
290
|
+
* export class FileService {
|
|
291
|
+
* private fileClient: HttpClient;
|
|
292
|
+
*
|
|
293
|
+
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
294
|
+
* this.fileClient = this.platformHttp.create({
|
|
295
|
+
* config: { timeout: 60000 }
|
|
296
|
+
* });
|
|
297
|
+
*
|
|
298
|
+
* this.fileClient.interceptors.request.use((config) => {
|
|
299
|
+
* console.log('File upload starting...');
|
|
300
|
+
* return config;
|
|
301
|
+
* });
|
|
302
|
+
* }
|
|
303
|
+
* }
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
declare class PlatformHttpClientService {
|
|
307
|
+
private readonly requestContext;
|
|
308
|
+
private readonly client;
|
|
309
|
+
private readonly protectedClient;
|
|
310
|
+
private readonly logger;
|
|
311
|
+
constructor(requestContext: RequestContextService);
|
|
312
|
+
/**
|
|
313
|
+
* 获取受保护的 HttpClient 实例(推荐)
|
|
314
|
+
*
|
|
315
|
+
* 该实例不暴露 interceptors,防止业务代码修改全局拦截器
|
|
316
|
+
*
|
|
317
|
+
* @returns 受保护的 HttpClient 实例
|
|
318
|
+
*/
|
|
319
|
+
get instance(): PlatformHttpClient;
|
|
320
|
+
/**
|
|
321
|
+
* 获取原始 HttpClient 实例(危险)
|
|
322
|
+
*
|
|
323
|
+
* ⚠️ 警告:该实例允许修改拦截器,会影响所有使用全局实例的地方
|
|
324
|
+
*
|
|
325
|
+
* 仅用于特殊场景,不应该暴露给业务代码
|
|
326
|
+
* 如果需要自定义拦截器,请使用 `create()` 方法创建独立实例
|
|
327
|
+
*
|
|
328
|
+
* @internal
|
|
329
|
+
* @returns 原始 HttpClient 实例
|
|
330
|
+
*/
|
|
331
|
+
get rawInstance(): HttpClient;
|
|
332
|
+
/**
|
|
333
|
+
* 创建一个新的独立 HttpClient 实例
|
|
334
|
+
*
|
|
335
|
+
* 适用于需要自定义拦截器或配置的场景
|
|
336
|
+
* 创建的实例完全独立,不会影响全局实例
|
|
337
|
+
*
|
|
338
|
+
* @param options - 配置选项(会与全局配置合并)
|
|
339
|
+
* @returns 完整的 HttpClient 实例(允许修改拦截器)
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* @Injectable()
|
|
344
|
+
* export class FileService {
|
|
345
|
+
* private fileClient: HttpClient;
|
|
346
|
+
*
|
|
347
|
+
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
348
|
+
* // 创建超时 60 秒的独立实例
|
|
349
|
+
* this.fileClient = this.platformHttp.create({
|
|
350
|
+
* config: { timeout: 60000 }
|
|
351
|
+
* });
|
|
352
|
+
*
|
|
353
|
+
* // 为这个实例注册拦截器(不影响全局实例)
|
|
354
|
+
* this.fileClient.interceptors.request.use((config) => {
|
|
355
|
+
* console.log('File upload starting...');
|
|
356
|
+
* return config;
|
|
357
|
+
* });
|
|
358
|
+
* }
|
|
359
|
+
*
|
|
360
|
+
* async uploadFile(file: Buffer) {
|
|
361
|
+
* return this.fileClient.post('/file/upload', file);
|
|
362
|
+
* }
|
|
363
|
+
* }
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
create(options?: PlatformHttpClientOptions): HttpClient;
|
|
367
|
+
/**
|
|
368
|
+
* 创建一个带全局拦截器的独立 HttpClient 实例
|
|
369
|
+
*
|
|
370
|
+
* 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
|
|
371
|
+
* 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
|
|
372
|
+
*
|
|
373
|
+
* @param options - 配置选项(会与全局配置合并)
|
|
374
|
+
* @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const client = this.platformHttp.createWithGlobalInterceptors();
|
|
379
|
+
* // 客户端已包含日志和 x-tt-env 拦截器
|
|
380
|
+
* // 可以继续添加自定义拦截器
|
|
381
|
+
* client.interceptors.request.use((config) => {
|
|
382
|
+
* config.headers['x-custom'] = 'value';
|
|
383
|
+
* return config;
|
|
384
|
+
* });
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
|
|
388
|
+
/**
|
|
389
|
+
* 注册全局拦截器(用于单例实例)
|
|
390
|
+
*/
|
|
391
|
+
private registerGlobalInterceptors;
|
|
392
|
+
/**
|
|
393
|
+
* 为指定的 HttpClient 实例注册标准拦截器
|
|
394
|
+
*
|
|
395
|
+
* 包含:
|
|
396
|
+
* - 请求日志记录
|
|
397
|
+
* - x-tt-env header 透传
|
|
398
|
+
* - 响应日志记录
|
|
399
|
+
* - 错误日志记录
|
|
400
|
+
*/
|
|
401
|
+
private registerInterceptorsForClient;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware };
|