@lark-apaas/fullstack-nestjs-core 1.1.22-beta.0 → 1.1.22-beta.10

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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NestModule, DynamicModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
2
- import { HttpClientConfig, PlatformPluginOptions } from '@lark-apaas/http-client';
2
+ import { HttpClientConfig, PlatformPluginOptions, HttpClient } from '@lark-apaas/http-client';
3
3
  import { NestExpressApplication } from '@nestjs/platform-express';
4
4
  export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
5
5
  import { Request, Response, NextFunction } from 'express';
@@ -89,11 +89,40 @@ declare class PlatformModule implements NestModule {
89
89
  * @param app NestExpressApplication 实例
90
90
  * @param perms 配置项
91
91
  * @param perms.disableSwagger 是否禁用 Swagger(默认:false)
92
+ * @param perms.bodyLimit 请求体大小限制,优先级:perms.bodyLimit > env.BODY_LIMIT > '1mb'
92
93
  */
93
94
  declare function configureApp(app: NestExpressApplication, perms?: {
94
95
  disableSwagger?: boolean;
96
+ bodyLimit?: string;
95
97
  }): Promise<void>;
96
98
 
99
+ /**
100
+ * Static Module
101
+ *
102
+ * Provides serving of static files from the shared/static directory.
103
+ * This module is automatically imported by PlatformModule in PRODUCTION mode only.
104
+ *
105
+ * Architecture:
106
+ * - Development: Vite/Rspack dev server middleware handles /static/* requests
107
+ * (faster response, HMR support)
108
+ * - Production: NestJS StaticController handles /static/* requests
109
+ * (proper caching, ETag support)
110
+ *
111
+ * Features:
112
+ * - Serves files at GET /static/* route
113
+ * - Security protection against path traversal
114
+ * - Proper MIME type detection
115
+ * - ETag-based cache validation
116
+ * - Streaming response for efficient file delivery
117
+ *
118
+ * Usage:
119
+ * 1. Place static files in shared/static/ directory
120
+ * 2. Import files in frontend: import x from '@shared/static/path'
121
+ * 3. Access files at {basePath}/static/{path}
122
+ */
123
+ declare class StaticModule {
124
+ }
125
+
97
126
  interface CsrfTokenOptions {
98
127
  cookieKey?: string;
99
128
  cookieMaxAge?: number;
@@ -169,4 +198,144 @@ declare class FileService {
169
198
  private _getFileMetadata;
170
199
  }
171
200
 
172
- export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
201
+ /**
202
+ * 平台 HttpClient 服务
203
+ *
204
+ * 提供两种使用方式:
205
+ * 1. 全局实例:通过 `instance` 或 `PLATFORM_HTTP_CLIENT` 注入,适用于 95% 的场景
206
+ * 2. 独立实例:通过 `create()` 创建,适用于需要自定义拦截器或配置的场景
207
+ *
208
+ * @example
209
+ * 基本使用(推荐)
210
+ * ```typescript
211
+ * @Injectable()
212
+ * export class UserService {
213
+ * constructor(
214
+ * @Inject(PLATFORM_HTTP_CLIENT) private http: SafeHttpClient
215
+ * ) {}
216
+ *
217
+ * async getUser() {
218
+ * return this.http.get('/user');
219
+ * }
220
+ * }
221
+ * ```
222
+ *
223
+ * @example
224
+ * 需要自定义拦截器(高级场景)
225
+ * ```typescript
226
+ * @Injectable()
227
+ * export class FileService {
228
+ * private fileClient: HttpClient;
229
+ *
230
+ * constructor(private platformHttp: PlatformHttpClientService) {
231
+ * this.fileClient = this.platformHttp.create({
232
+ * config: { timeout: 60000 }
233
+ * });
234
+ *
235
+ * this.fileClient.interceptors.request.use((config) => {
236
+ * console.log('File upload starting...');
237
+ * return config;
238
+ * });
239
+ * }
240
+ * }
241
+ * ```
242
+ */
243
+ declare class PlatformHttpClientService {
244
+ private readonly requestContext;
245
+ private readonly client;
246
+ private readonly protectedClient;
247
+ private readonly logger;
248
+ constructor(requestContext: RequestContextService);
249
+ /**
250
+ * 获取受保护的 HttpClient 实例(推荐)
251
+ *
252
+ * 该实例不暴露 interceptors,防止业务代码修改全局拦截器
253
+ *
254
+ * @returns 受保护的 HttpClient 实例
255
+ */
256
+ get instance(): PlatformHttpClient;
257
+ /**
258
+ * 获取原始 HttpClient 实例(危险)
259
+ *
260
+ * ⚠️ 警告:该实例允许修改拦截器,会影响所有使用全局实例的地方
261
+ *
262
+ * 仅用于特殊场景,不应该暴露给业务代码
263
+ * 如果需要自定义拦截器,请使用 `create()` 方法创建独立实例
264
+ *
265
+ * @internal
266
+ * @returns 原始 HttpClient 实例
267
+ */
268
+ get rawInstance(): HttpClient;
269
+ /**
270
+ * 创建一个新的独立 HttpClient 实例
271
+ *
272
+ * 适用于需要自定义拦截器或配置的场景
273
+ * 创建的实例完全独立,不会影响全局实例
274
+ *
275
+ * @param options - 配置选项(会与全局配置合并)
276
+ * @returns 完整的 HttpClient 实例(允许修改拦截器)
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * @Injectable()
281
+ * export class FileService {
282
+ * private fileClient: HttpClient;
283
+ *
284
+ * constructor(private platformHttp: PlatformHttpClientService) {
285
+ * // 创建超时 60 秒的独立实例
286
+ * this.fileClient = this.platformHttp.create({
287
+ * config: { timeout: 60000 }
288
+ * });
289
+ *
290
+ * // 为这个实例注册拦截器(不影响全局实例)
291
+ * this.fileClient.interceptors.request.use((config) => {
292
+ * console.log('File upload starting...');
293
+ * return config;
294
+ * });
295
+ * }
296
+ *
297
+ * async uploadFile(file: Buffer) {
298
+ * return this.fileClient.post('/file/upload', file);
299
+ * }
300
+ * }
301
+ * ```
302
+ */
303
+ create(options?: PlatformHttpClientOptions): HttpClient;
304
+ /**
305
+ * 创建一个带全局拦截器的独立 HttpClient 实例
306
+ *
307
+ * 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
308
+ * 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
309
+ *
310
+ * @param options - 配置选项(会与全局配置合并)
311
+ * @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * const client = this.platformHttp.createWithGlobalInterceptors();
316
+ * // 客户端已包含日志和 x-tt-env 拦截器
317
+ * // 可以继续添加自定义拦截器
318
+ * client.interceptors.request.use((config) => {
319
+ * config.headers['x-custom'] = 'value';
320
+ * return config;
321
+ * });
322
+ * ```
323
+ */
324
+ createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
325
+ /**
326
+ * 注册全局拦截器(用于单例实例)
327
+ */
328
+ private registerGlobalInterceptors;
329
+ /**
330
+ * 为指定的 HttpClient 实例注册标准拦截器
331
+ *
332
+ * 包含:
333
+ * - 请求日志记录
334
+ * - x-tt-env header 透传
335
+ * - 响应日志记录
336
+ * - 错误日志记录
337
+ */
338
+ private registerInterceptorsForClient;
339
+ }
340
+
341
+ export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NestModule, DynamicModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
2
- import { HttpClientConfig, PlatformPluginOptions } from '@lark-apaas/http-client';
2
+ import { HttpClientConfig, PlatformPluginOptions, HttpClient } from '@lark-apaas/http-client';
3
3
  import { NestExpressApplication } from '@nestjs/platform-express';
4
4
  export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
5
5
  import { Request, Response, NextFunction } from 'express';
@@ -89,11 +89,40 @@ declare class PlatformModule implements NestModule {
89
89
  * @param app NestExpressApplication 实例
90
90
  * @param perms 配置项
91
91
  * @param perms.disableSwagger 是否禁用 Swagger(默认:false)
92
+ * @param perms.bodyLimit 请求体大小限制,优先级:perms.bodyLimit > env.BODY_LIMIT > '1mb'
92
93
  */
93
94
  declare function configureApp(app: NestExpressApplication, perms?: {
94
95
  disableSwagger?: boolean;
96
+ bodyLimit?: string;
95
97
  }): Promise<void>;
96
98
 
99
+ /**
100
+ * Static Module
101
+ *
102
+ * Provides serving of static files from the shared/static directory.
103
+ * This module is automatically imported by PlatformModule in PRODUCTION mode only.
104
+ *
105
+ * Architecture:
106
+ * - Development: Vite/Rspack dev server middleware handles /static/* requests
107
+ * (faster response, HMR support)
108
+ * - Production: NestJS StaticController handles /static/* requests
109
+ * (proper caching, ETag support)
110
+ *
111
+ * Features:
112
+ * - Serves files at GET /static/* route
113
+ * - Security protection against path traversal
114
+ * - Proper MIME type detection
115
+ * - ETag-based cache validation
116
+ * - Streaming response for efficient file delivery
117
+ *
118
+ * Usage:
119
+ * 1. Place static files in shared/static/ directory
120
+ * 2. Import files in frontend: import x from '@shared/static/path'
121
+ * 3. Access files at {basePath}/static/{path}
122
+ */
123
+ declare class StaticModule {
124
+ }
125
+
97
126
  interface CsrfTokenOptions {
98
127
  cookieKey?: string;
99
128
  cookieMaxAge?: number;
@@ -169,4 +198,144 @@ declare class FileService {
169
198
  private _getFileMetadata;
170
199
  }
171
200
 
172
- export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
201
+ /**
202
+ * 平台 HttpClient 服务
203
+ *
204
+ * 提供两种使用方式:
205
+ * 1. 全局实例:通过 `instance` 或 `PLATFORM_HTTP_CLIENT` 注入,适用于 95% 的场景
206
+ * 2. 独立实例:通过 `create()` 创建,适用于需要自定义拦截器或配置的场景
207
+ *
208
+ * @example
209
+ * 基本使用(推荐)
210
+ * ```typescript
211
+ * @Injectable()
212
+ * export class UserService {
213
+ * constructor(
214
+ * @Inject(PLATFORM_HTTP_CLIENT) private http: SafeHttpClient
215
+ * ) {}
216
+ *
217
+ * async getUser() {
218
+ * return this.http.get('/user');
219
+ * }
220
+ * }
221
+ * ```
222
+ *
223
+ * @example
224
+ * 需要自定义拦截器(高级场景)
225
+ * ```typescript
226
+ * @Injectable()
227
+ * export class FileService {
228
+ * private fileClient: HttpClient;
229
+ *
230
+ * constructor(private platformHttp: PlatformHttpClientService) {
231
+ * this.fileClient = this.platformHttp.create({
232
+ * config: { timeout: 60000 }
233
+ * });
234
+ *
235
+ * this.fileClient.interceptors.request.use((config) => {
236
+ * console.log('File upload starting...');
237
+ * return config;
238
+ * });
239
+ * }
240
+ * }
241
+ * ```
242
+ */
243
+ declare class PlatformHttpClientService {
244
+ private readonly requestContext;
245
+ private readonly client;
246
+ private readonly protectedClient;
247
+ private readonly logger;
248
+ constructor(requestContext: RequestContextService);
249
+ /**
250
+ * 获取受保护的 HttpClient 实例(推荐)
251
+ *
252
+ * 该实例不暴露 interceptors,防止业务代码修改全局拦截器
253
+ *
254
+ * @returns 受保护的 HttpClient 实例
255
+ */
256
+ get instance(): PlatformHttpClient;
257
+ /**
258
+ * 获取原始 HttpClient 实例(危险)
259
+ *
260
+ * ⚠️ 警告:该实例允许修改拦截器,会影响所有使用全局实例的地方
261
+ *
262
+ * 仅用于特殊场景,不应该暴露给业务代码
263
+ * 如果需要自定义拦截器,请使用 `create()` 方法创建独立实例
264
+ *
265
+ * @internal
266
+ * @returns 原始 HttpClient 实例
267
+ */
268
+ get rawInstance(): HttpClient;
269
+ /**
270
+ * 创建一个新的独立 HttpClient 实例
271
+ *
272
+ * 适用于需要自定义拦截器或配置的场景
273
+ * 创建的实例完全独立,不会影响全局实例
274
+ *
275
+ * @param options - 配置选项(会与全局配置合并)
276
+ * @returns 完整的 HttpClient 实例(允许修改拦截器)
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * @Injectable()
281
+ * export class FileService {
282
+ * private fileClient: HttpClient;
283
+ *
284
+ * constructor(private platformHttp: PlatformHttpClientService) {
285
+ * // 创建超时 60 秒的独立实例
286
+ * this.fileClient = this.platformHttp.create({
287
+ * config: { timeout: 60000 }
288
+ * });
289
+ *
290
+ * // 为这个实例注册拦截器(不影响全局实例)
291
+ * this.fileClient.interceptors.request.use((config) => {
292
+ * console.log('File upload starting...');
293
+ * return config;
294
+ * });
295
+ * }
296
+ *
297
+ * async uploadFile(file: Buffer) {
298
+ * return this.fileClient.post('/file/upload', file);
299
+ * }
300
+ * }
301
+ * ```
302
+ */
303
+ create(options?: PlatformHttpClientOptions): HttpClient;
304
+ /**
305
+ * 创建一个带全局拦截器的独立 HttpClient 实例
306
+ *
307
+ * 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
308
+ * 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
309
+ *
310
+ * @param options - 配置选项(会与全局配置合并)
311
+ * @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * const client = this.platformHttp.createWithGlobalInterceptors();
316
+ * // 客户端已包含日志和 x-tt-env 拦截器
317
+ * // 可以继续添加自定义拦截器
318
+ * client.interceptors.request.use((config) => {
319
+ * config.headers['x-custom'] = 'value';
320
+ * return config;
321
+ * });
322
+ * ```
323
+ */
324
+ createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
325
+ /**
326
+ * 注册全局拦截器(用于单例实例)
327
+ */
328
+ private registerGlobalInterceptors;
329
+ /**
330
+ * 为指定的 HttpClient 实例注册标准拦截器
331
+ *
332
+ * 包含:
333
+ * - 请求日志记录
334
+ * - x-tt-env header 透传
335
+ * - 响应日志记录
336
+ * - 错误日志记录
337
+ */
338
+ private registerInterceptorsForClient;
339
+ }
340
+
341
+ export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp };