@lark-apaas/fullstack-nestjs-core 1.1.22-beta.5 → 1.1.22-beta.6
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.cjs +33859 -17
- package/dist/index.d.cts +144 -2
- package/dist/index.d.ts +144 -2
- package/dist/index.js +33875 -7
- package/package.json +7 -7
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,9 +89,11 @@ 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
|
|
|
97
99
|
interface CsrfTokenOptions {
|
|
@@ -169,4 +171,144 @@ declare class FileService {
|
|
|
169
171
|
private _getFileMetadata;
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
|
|
174
|
+
/**
|
|
175
|
+
* 平台 HttpClient 服务
|
|
176
|
+
*
|
|
177
|
+
* 提供两种使用方式:
|
|
178
|
+
* 1. 全局实例:通过 `instance` 或 `PLATFORM_HTTP_CLIENT` 注入,适用于 95% 的场景
|
|
179
|
+
* 2. 独立实例:通过 `create()` 创建,适用于需要自定义拦截器或配置的场景
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* 基本使用(推荐)
|
|
183
|
+
* ```typescript
|
|
184
|
+
* @Injectable()
|
|
185
|
+
* export class UserService {
|
|
186
|
+
* constructor(
|
|
187
|
+
* @Inject(PLATFORM_HTTP_CLIENT) private http: SafeHttpClient
|
|
188
|
+
* ) {}
|
|
189
|
+
*
|
|
190
|
+
* async getUser() {
|
|
191
|
+
* return this.http.get('/user');
|
|
192
|
+
* }
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* 需要自定义拦截器(高级场景)
|
|
198
|
+
* ```typescript
|
|
199
|
+
* @Injectable()
|
|
200
|
+
* export class FileService {
|
|
201
|
+
* private fileClient: HttpClient;
|
|
202
|
+
*
|
|
203
|
+
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
204
|
+
* this.fileClient = this.platformHttp.create({
|
|
205
|
+
* config: { timeout: 60000 }
|
|
206
|
+
* });
|
|
207
|
+
*
|
|
208
|
+
* this.fileClient.interceptors.request.use((config) => {
|
|
209
|
+
* console.log('File upload starting...');
|
|
210
|
+
* return config;
|
|
211
|
+
* });
|
|
212
|
+
* }
|
|
213
|
+
* }
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare class PlatformHttpClientService {
|
|
217
|
+
private readonly requestContext;
|
|
218
|
+
private readonly client;
|
|
219
|
+
private readonly protectedClient;
|
|
220
|
+
private readonly logger;
|
|
221
|
+
constructor(requestContext: RequestContextService);
|
|
222
|
+
/**
|
|
223
|
+
* 获取受保护的 HttpClient 实例(推荐)
|
|
224
|
+
*
|
|
225
|
+
* 该实例不暴露 interceptors,防止业务代码修改全局拦截器
|
|
226
|
+
*
|
|
227
|
+
* @returns 受保护的 HttpClient 实例
|
|
228
|
+
*/
|
|
229
|
+
get instance(): PlatformHttpClient;
|
|
230
|
+
/**
|
|
231
|
+
* 获取原始 HttpClient 实例(危险)
|
|
232
|
+
*
|
|
233
|
+
* ⚠️ 警告:该实例允许修改拦截器,会影响所有使用全局实例的地方
|
|
234
|
+
*
|
|
235
|
+
* 仅用于特殊场景,不应该暴露给业务代码
|
|
236
|
+
* 如果需要自定义拦截器,请使用 `create()` 方法创建独立实例
|
|
237
|
+
*
|
|
238
|
+
* @internal
|
|
239
|
+
* @returns 原始 HttpClient 实例
|
|
240
|
+
*/
|
|
241
|
+
get rawInstance(): HttpClient;
|
|
242
|
+
/**
|
|
243
|
+
* 创建一个新的独立 HttpClient 实例
|
|
244
|
+
*
|
|
245
|
+
* 适用于需要自定义拦截器或配置的场景
|
|
246
|
+
* 创建的实例完全独立,不会影响全局实例
|
|
247
|
+
*
|
|
248
|
+
* @param options - 配置选项(会与全局配置合并)
|
|
249
|
+
* @returns 完整的 HttpClient 实例(允许修改拦截器)
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* @Injectable()
|
|
254
|
+
* export class FileService {
|
|
255
|
+
* private fileClient: HttpClient;
|
|
256
|
+
*
|
|
257
|
+
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
258
|
+
* // 创建超时 60 秒的独立实例
|
|
259
|
+
* this.fileClient = this.platformHttp.create({
|
|
260
|
+
* config: { timeout: 60000 }
|
|
261
|
+
* });
|
|
262
|
+
*
|
|
263
|
+
* // 为这个实例注册拦截器(不影响全局实例)
|
|
264
|
+
* this.fileClient.interceptors.request.use((config) => {
|
|
265
|
+
* console.log('File upload starting...');
|
|
266
|
+
* return config;
|
|
267
|
+
* });
|
|
268
|
+
* }
|
|
269
|
+
*
|
|
270
|
+
* async uploadFile(file: Buffer) {
|
|
271
|
+
* return this.fileClient.post('/file/upload', file);
|
|
272
|
+
* }
|
|
273
|
+
* }
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
create(options?: PlatformHttpClientOptions): HttpClient;
|
|
277
|
+
/**
|
|
278
|
+
* 创建一个带全局拦截器的独立 HttpClient 实例
|
|
279
|
+
*
|
|
280
|
+
* 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
|
|
281
|
+
* 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
|
|
282
|
+
*
|
|
283
|
+
* @param options - 配置选项(会与全局配置合并)
|
|
284
|
+
* @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* const client = this.platformHttp.createWithGlobalInterceptors();
|
|
289
|
+
* // 客户端已包含日志和 x-tt-env 拦截器
|
|
290
|
+
* // 可以继续添加自定义拦截器
|
|
291
|
+
* client.interceptors.request.use((config) => {
|
|
292
|
+
* config.headers['x-custom'] = 'value';
|
|
293
|
+
* return config;
|
|
294
|
+
* });
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
|
|
298
|
+
/**
|
|
299
|
+
* 注册全局拦截器(用于单例实例)
|
|
300
|
+
*/
|
|
301
|
+
private registerGlobalInterceptors;
|
|
302
|
+
/**
|
|
303
|
+
* 为指定的 HttpClient 实例注册标准拦截器
|
|
304
|
+
*
|
|
305
|
+
* 包含:
|
|
306
|
+
* - 请求日志记录
|
|
307
|
+
* - x-tt-env header 透传
|
|
308
|
+
* - 响应日志记录
|
|
309
|
+
* - 错误日志记录
|
|
310
|
+
*/
|
|
311
|
+
private registerInterceptorsForClient;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, 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,9 +89,11 @@ 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
|
|
|
97
99
|
interface CsrfTokenOptions {
|
|
@@ -169,4 +171,144 @@ declare class FileService {
|
|
|
169
171
|
private _getFileMetadata;
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
|
|
174
|
+
/**
|
|
175
|
+
* 平台 HttpClient 服务
|
|
176
|
+
*
|
|
177
|
+
* 提供两种使用方式:
|
|
178
|
+
* 1. 全局实例:通过 `instance` 或 `PLATFORM_HTTP_CLIENT` 注入,适用于 95% 的场景
|
|
179
|
+
* 2. 独立实例:通过 `create()` 创建,适用于需要自定义拦截器或配置的场景
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* 基本使用(推荐)
|
|
183
|
+
* ```typescript
|
|
184
|
+
* @Injectable()
|
|
185
|
+
* export class UserService {
|
|
186
|
+
* constructor(
|
|
187
|
+
* @Inject(PLATFORM_HTTP_CLIENT) private http: SafeHttpClient
|
|
188
|
+
* ) {}
|
|
189
|
+
*
|
|
190
|
+
* async getUser() {
|
|
191
|
+
* return this.http.get('/user');
|
|
192
|
+
* }
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* 需要自定义拦截器(高级场景)
|
|
198
|
+
* ```typescript
|
|
199
|
+
* @Injectable()
|
|
200
|
+
* export class FileService {
|
|
201
|
+
* private fileClient: HttpClient;
|
|
202
|
+
*
|
|
203
|
+
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
204
|
+
* this.fileClient = this.platformHttp.create({
|
|
205
|
+
* config: { timeout: 60000 }
|
|
206
|
+
* });
|
|
207
|
+
*
|
|
208
|
+
* this.fileClient.interceptors.request.use((config) => {
|
|
209
|
+
* console.log('File upload starting...');
|
|
210
|
+
* return config;
|
|
211
|
+
* });
|
|
212
|
+
* }
|
|
213
|
+
* }
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare class PlatformHttpClientService {
|
|
217
|
+
private readonly requestContext;
|
|
218
|
+
private readonly client;
|
|
219
|
+
private readonly protectedClient;
|
|
220
|
+
private readonly logger;
|
|
221
|
+
constructor(requestContext: RequestContextService);
|
|
222
|
+
/**
|
|
223
|
+
* 获取受保护的 HttpClient 实例(推荐)
|
|
224
|
+
*
|
|
225
|
+
* 该实例不暴露 interceptors,防止业务代码修改全局拦截器
|
|
226
|
+
*
|
|
227
|
+
* @returns 受保护的 HttpClient 实例
|
|
228
|
+
*/
|
|
229
|
+
get instance(): PlatformHttpClient;
|
|
230
|
+
/**
|
|
231
|
+
* 获取原始 HttpClient 实例(危险)
|
|
232
|
+
*
|
|
233
|
+
* ⚠️ 警告:该实例允许修改拦截器,会影响所有使用全局实例的地方
|
|
234
|
+
*
|
|
235
|
+
* 仅用于特殊场景,不应该暴露给业务代码
|
|
236
|
+
* 如果需要自定义拦截器,请使用 `create()` 方法创建独立实例
|
|
237
|
+
*
|
|
238
|
+
* @internal
|
|
239
|
+
* @returns 原始 HttpClient 实例
|
|
240
|
+
*/
|
|
241
|
+
get rawInstance(): HttpClient;
|
|
242
|
+
/**
|
|
243
|
+
* 创建一个新的独立 HttpClient 实例
|
|
244
|
+
*
|
|
245
|
+
* 适用于需要自定义拦截器或配置的场景
|
|
246
|
+
* 创建的实例完全独立,不会影响全局实例
|
|
247
|
+
*
|
|
248
|
+
* @param options - 配置选项(会与全局配置合并)
|
|
249
|
+
* @returns 完整的 HttpClient 实例(允许修改拦截器)
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* @Injectable()
|
|
254
|
+
* export class FileService {
|
|
255
|
+
* private fileClient: HttpClient;
|
|
256
|
+
*
|
|
257
|
+
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
258
|
+
* // 创建超时 60 秒的独立实例
|
|
259
|
+
* this.fileClient = this.platformHttp.create({
|
|
260
|
+
* config: { timeout: 60000 }
|
|
261
|
+
* });
|
|
262
|
+
*
|
|
263
|
+
* // 为这个实例注册拦截器(不影响全局实例)
|
|
264
|
+
* this.fileClient.interceptors.request.use((config) => {
|
|
265
|
+
* console.log('File upload starting...');
|
|
266
|
+
* return config;
|
|
267
|
+
* });
|
|
268
|
+
* }
|
|
269
|
+
*
|
|
270
|
+
* async uploadFile(file: Buffer) {
|
|
271
|
+
* return this.fileClient.post('/file/upload', file);
|
|
272
|
+
* }
|
|
273
|
+
* }
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
create(options?: PlatformHttpClientOptions): HttpClient;
|
|
277
|
+
/**
|
|
278
|
+
* 创建一个带全局拦截器的独立 HttpClient 实例
|
|
279
|
+
*
|
|
280
|
+
* 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
|
|
281
|
+
* 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
|
|
282
|
+
*
|
|
283
|
+
* @param options - 配置选项(会与全局配置合并)
|
|
284
|
+
* @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* const client = this.platformHttp.createWithGlobalInterceptors();
|
|
289
|
+
* // 客户端已包含日志和 x-tt-env 拦截器
|
|
290
|
+
* // 可以继续添加自定义拦截器
|
|
291
|
+
* client.interceptors.request.use((config) => {
|
|
292
|
+
* config.headers['x-custom'] = 'value';
|
|
293
|
+
* return config;
|
|
294
|
+
* });
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
|
|
298
|
+
/**
|
|
299
|
+
* 注册全局拦截器(用于单例实例)
|
|
300
|
+
*/
|
|
301
|
+
private registerGlobalInterceptors;
|
|
302
|
+
/**
|
|
303
|
+
* 为指定的 HttpClient 实例注册标准拦截器
|
|
304
|
+
*
|
|
305
|
+
* 包含:
|
|
306
|
+
* - 请求日志记录
|
|
307
|
+
* - x-tt-env header 透传
|
|
308
|
+
* - 响应日志记录
|
|
309
|
+
* - 错误日志记录
|
|
310
|
+
*/
|
|
311
|
+
private registerInterceptorsForClient;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|