@lark-apaas/fullstack-nestjs-core 1.1.23-alpha.2 → 1.1.23-alpha.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/dist/index.cjs +10 -55
- package/dist/index.d.cts +2 -142
- package/dist/index.d.ts +2 -142
- package/dist/index.js +11 -55
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,6 @@ __export(index_exports, {
|
|
|
39
39
|
DevToolsModule: () => import_nestjs_openapi_devtools2.DevToolsModule,
|
|
40
40
|
DevToolsV2Module: () => import_nestjs_openapi_devtools2.DevToolsV2Module,
|
|
41
41
|
FileService: () => FileService,
|
|
42
|
-
PlatformHttpClientService: () => PlatformHttpClientService,
|
|
43
42
|
PlatformModule: () => PlatformModule,
|
|
44
43
|
UserContextMiddleware: () => UserContextMiddleware,
|
|
45
44
|
ViewContextMiddleware: () => ViewContextMiddleware,
|
|
@@ -440,13 +439,15 @@ var RequestContextMiddleware = class {
|
|
|
440
439
|
const path = req.originalUrl ?? req.url;
|
|
441
440
|
const userContext = req.userContext ?? {};
|
|
442
441
|
const ttEnv = req.headers["x-tt-env"];
|
|
442
|
+
const referer = req.get("Referer") ?? req.get("Referrer") ?? req.headers?.referer ?? req.headers?.referrer;
|
|
443
443
|
this.requestContext.run({
|
|
444
444
|
path,
|
|
445
445
|
method: req.method,
|
|
446
446
|
userId: userContext.userId,
|
|
447
447
|
tenantId: userContext.tenantId,
|
|
448
448
|
appId: userContext.appId,
|
|
449
|
-
ttEnv
|
|
449
|
+
ttEnv,
|
|
450
|
+
referer
|
|
450
451
|
}, () => next());
|
|
451
452
|
}
|
|
452
453
|
};
|
|
@@ -601,10 +602,13 @@ var FrameworkDebugMiddleware = class {
|
|
|
601
602
|
const routes = [];
|
|
602
603
|
router.stack.forEach((middleware, index) => {
|
|
603
604
|
if (middleware.route) {
|
|
605
|
+
const methods = middleware.route.methods;
|
|
606
|
+
const methodList = methods ? Object.keys(methods).filter((m) => methods[m]).map((m) => m.toUpperCase()) : [];
|
|
607
|
+
const method = methodList.length > 0 ? methodList.join(",") : "ALL";
|
|
604
608
|
routes.push({
|
|
605
609
|
order: String(index),
|
|
606
610
|
path: middleware.route.path,
|
|
607
|
-
method
|
|
611
|
+
method,
|
|
608
612
|
regexp: middleware.regexp?.toString()
|
|
609
613
|
});
|
|
610
614
|
}
|
|
@@ -760,47 +764,10 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
760
764
|
});
|
|
761
765
|
}
|
|
762
766
|
/**
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
* 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
|
|
766
|
-
* 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
|
|
767
|
-
*
|
|
768
|
-
* @param options - 配置选项(会与全局配置合并)
|
|
769
|
-
* @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
|
|
770
|
-
*
|
|
771
|
-
* @example
|
|
772
|
-
* ```typescript
|
|
773
|
-
* const client = this.platformHttp.createWithGlobalInterceptors();
|
|
774
|
-
* // 客户端已包含日志和 x-tt-env 拦截器
|
|
775
|
-
* // 可以继续添加自定义拦截器
|
|
776
|
-
* client.interceptors.request.use((config) => {
|
|
777
|
-
* config.headers['x-custom'] = 'value';
|
|
778
|
-
* return config;
|
|
779
|
-
* });
|
|
780
|
-
* ```
|
|
781
|
-
*/
|
|
782
|
-
createWithGlobalInterceptors(options) {
|
|
783
|
-
const client = this.create(options);
|
|
784
|
-
this.registerInterceptorsForClient(client);
|
|
785
|
-
return client;
|
|
786
|
-
}
|
|
787
|
-
/**
|
|
788
|
-
* 注册全局拦截器(用于单例实例)
|
|
767
|
+
* 注册全局拦截器
|
|
789
768
|
*/
|
|
790
769
|
registerGlobalInterceptors() {
|
|
791
|
-
this.
|
|
792
|
-
}
|
|
793
|
-
/**
|
|
794
|
-
* 为指定的 HttpClient 实例注册标准拦截器
|
|
795
|
-
*
|
|
796
|
-
* 包含:
|
|
797
|
-
* - 请求日志记录
|
|
798
|
-
* - x-tt-env header 透传
|
|
799
|
-
* - 响应日志记录
|
|
800
|
-
* - 错误日志记录
|
|
801
|
-
*/
|
|
802
|
-
registerInterceptorsForClient(client) {
|
|
803
|
-
client.interceptors.request.use((config) => {
|
|
770
|
+
this.client.interceptors.request.use((config) => {
|
|
804
771
|
this.logger.debug(`Server SDK HTTP Request: ${config.method?.toUpperCase()} ${config.url}`);
|
|
805
772
|
const ttEnv = this.requestContext.get("ttEnv");
|
|
806
773
|
if (ttEnv) {
|
|
@@ -814,7 +781,7 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
814
781
|
this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
|
|
815
782
|
return Promise.reject(error);
|
|
816
783
|
});
|
|
817
|
-
client.interceptors.response.use((response) => {
|
|
784
|
+
this.client.interceptors.response.use((response) => {
|
|
818
785
|
this.logger.debug(`Server SDK HTTP Response: ${response.status} ${response.url}`);
|
|
819
786
|
return response;
|
|
820
787
|
}, (error) => {
|
|
@@ -1328,15 +1295,6 @@ var PlatformModule = class _PlatformModule {
|
|
|
1328
1295
|
PlatformHttpClientService
|
|
1329
1296
|
]
|
|
1330
1297
|
},
|
|
1331
|
-
{
|
|
1332
|
-
provide: import_nestjs_common5.HTTP_CLIENT_FACTORY,
|
|
1333
|
-
useFactory: /* @__PURE__ */ __name((svc) => ({
|
|
1334
|
-
create: /* @__PURE__ */ __name((options2) => svc.createWithGlobalInterceptors(options2), "create")
|
|
1335
|
-
}), "useFactory"),
|
|
1336
|
-
inject: [
|
|
1337
|
-
PlatformHttpClientService
|
|
1338
|
-
]
|
|
1339
|
-
},
|
|
1340
1298
|
HttpInterceptorService,
|
|
1341
1299
|
{
|
|
1342
1300
|
provide: import_core2.APP_INTERCEPTOR,
|
|
@@ -1350,8 +1308,6 @@ var PlatformModule = class _PlatformModule {
|
|
|
1350
1308
|
import_nestjs_common5.CommonModule,
|
|
1351
1309
|
import_nestjs_common5.OBSERVABLE_SERVICE,
|
|
1352
1310
|
import_nestjs_common6.PLATFORM_HTTP_CLIENT,
|
|
1353
|
-
import_nestjs_common5.HTTP_CLIENT_FACTORY,
|
|
1354
|
-
PlatformHttpClientService,
|
|
1355
1311
|
import_nestjs_capability.CapabilityModule,
|
|
1356
1312
|
FileService
|
|
1357
1313
|
]
|
|
@@ -1435,7 +1391,6 @@ var import_nestjs_authzpaas2 = require("@lark-apaas/nestjs-authzpaas");
|
|
|
1435
1391
|
DevToolsModule,
|
|
1436
1392
|
DevToolsV2Module,
|
|
1437
1393
|
FileService,
|
|
1438
|
-
PlatformHttpClientService,
|
|
1439
1394
|
PlatformModule,
|
|
1440
1395
|
UserContextMiddleware,
|
|
1441
1396
|
ViewContextMiddleware,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NestModule, DynamicModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
|
|
2
|
-
import { HttpClientConfig, PlatformPluginOptions
|
|
2
|
+
import { HttpClientConfig, PlatformPluginOptions } 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';
|
|
@@ -169,144 +169,4 @@ declare class FileService {
|
|
|
169
169
|
private _getFileMetadata;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
* 平台 HttpClient 服务
|
|
174
|
-
*
|
|
175
|
-
* 提供两种使用方式:
|
|
176
|
-
* 1. 全局实例:通过 `instance` 或 `PLATFORM_HTTP_CLIENT` 注入,适用于 95% 的场景
|
|
177
|
-
* 2. 独立实例:通过 `create()` 创建,适用于需要自定义拦截器或配置的场景
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* 基本使用(推荐)
|
|
181
|
-
* ```typescript
|
|
182
|
-
* @Injectable()
|
|
183
|
-
* export class UserService {
|
|
184
|
-
* constructor(
|
|
185
|
-
* @Inject(PLATFORM_HTTP_CLIENT) private http: SafeHttpClient
|
|
186
|
-
* ) {}
|
|
187
|
-
*
|
|
188
|
-
* async getUser() {
|
|
189
|
-
* return this.http.get('/user');
|
|
190
|
-
* }
|
|
191
|
-
* }
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* 需要自定义拦截器(高级场景)
|
|
196
|
-
* ```typescript
|
|
197
|
-
* @Injectable()
|
|
198
|
-
* export class FileService {
|
|
199
|
-
* private fileClient: HttpClient;
|
|
200
|
-
*
|
|
201
|
-
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
202
|
-
* this.fileClient = this.platformHttp.create({
|
|
203
|
-
* config: { timeout: 60000 }
|
|
204
|
-
* });
|
|
205
|
-
*
|
|
206
|
-
* this.fileClient.interceptors.request.use((config) => {
|
|
207
|
-
* console.log('File upload starting...');
|
|
208
|
-
* return config;
|
|
209
|
-
* });
|
|
210
|
-
* }
|
|
211
|
-
* }
|
|
212
|
-
* ```
|
|
213
|
-
*/
|
|
214
|
-
declare class PlatformHttpClientService {
|
|
215
|
-
private readonly requestContext;
|
|
216
|
-
private readonly client;
|
|
217
|
-
private readonly protectedClient;
|
|
218
|
-
private readonly logger;
|
|
219
|
-
constructor(requestContext: RequestContextService);
|
|
220
|
-
/**
|
|
221
|
-
* 获取受保护的 HttpClient 实例(推荐)
|
|
222
|
-
*
|
|
223
|
-
* 该实例不暴露 interceptors,防止业务代码修改全局拦截器
|
|
224
|
-
*
|
|
225
|
-
* @returns 受保护的 HttpClient 实例
|
|
226
|
-
*/
|
|
227
|
-
get instance(): PlatformHttpClient;
|
|
228
|
-
/**
|
|
229
|
-
* 获取原始 HttpClient 实例(危险)
|
|
230
|
-
*
|
|
231
|
-
* ⚠️ 警告:该实例允许修改拦截器,会影响所有使用全局实例的地方
|
|
232
|
-
*
|
|
233
|
-
* 仅用于特殊场景,不应该暴露给业务代码
|
|
234
|
-
* 如果需要自定义拦截器,请使用 `create()` 方法创建独立实例
|
|
235
|
-
*
|
|
236
|
-
* @internal
|
|
237
|
-
* @returns 原始 HttpClient 实例
|
|
238
|
-
*/
|
|
239
|
-
get rawInstance(): HttpClient;
|
|
240
|
-
/**
|
|
241
|
-
* 创建一个新的独立 HttpClient 实例
|
|
242
|
-
*
|
|
243
|
-
* 适用于需要自定义拦截器或配置的场景
|
|
244
|
-
* 创建的实例完全独立,不会影响全局实例
|
|
245
|
-
*
|
|
246
|
-
* @param options - 配置选项(会与全局配置合并)
|
|
247
|
-
* @returns 完整的 HttpClient 实例(允许修改拦截器)
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
* ```typescript
|
|
251
|
-
* @Injectable()
|
|
252
|
-
* export class FileService {
|
|
253
|
-
* private fileClient: HttpClient;
|
|
254
|
-
*
|
|
255
|
-
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
256
|
-
* // 创建超时 60 秒的独立实例
|
|
257
|
-
* this.fileClient = this.platformHttp.create({
|
|
258
|
-
* config: { timeout: 60000 }
|
|
259
|
-
* });
|
|
260
|
-
*
|
|
261
|
-
* // 为这个实例注册拦截器(不影响全局实例)
|
|
262
|
-
* this.fileClient.interceptors.request.use((config) => {
|
|
263
|
-
* console.log('File upload starting...');
|
|
264
|
-
* return config;
|
|
265
|
-
* });
|
|
266
|
-
* }
|
|
267
|
-
*
|
|
268
|
-
* async uploadFile(file: Buffer) {
|
|
269
|
-
* return this.fileClient.post('/file/upload', file);
|
|
270
|
-
* }
|
|
271
|
-
* }
|
|
272
|
-
* ```
|
|
273
|
-
*/
|
|
274
|
-
create(options?: PlatformHttpClientOptions): HttpClient;
|
|
275
|
-
/**
|
|
276
|
-
* 创建一个带全局拦截器的独立 HttpClient 实例
|
|
277
|
-
*
|
|
278
|
-
* 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
|
|
279
|
-
* 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
|
|
280
|
-
*
|
|
281
|
-
* @param options - 配置选项(会与全局配置合并)
|
|
282
|
-
* @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
|
|
283
|
-
*
|
|
284
|
-
* @example
|
|
285
|
-
* ```typescript
|
|
286
|
-
* const client = this.platformHttp.createWithGlobalInterceptors();
|
|
287
|
-
* // 客户端已包含日志和 x-tt-env 拦截器
|
|
288
|
-
* // 可以继续添加自定义拦截器
|
|
289
|
-
* client.interceptors.request.use((config) => {
|
|
290
|
-
* config.headers['x-custom'] = 'value';
|
|
291
|
-
* return config;
|
|
292
|
-
* });
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
295
|
-
createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
|
|
296
|
-
/**
|
|
297
|
-
* 注册全局拦截器(用于单例实例)
|
|
298
|
-
*/
|
|
299
|
-
private registerGlobalInterceptors;
|
|
300
|
-
/**
|
|
301
|
-
* 为指定的 HttpClient 实例注册标准拦截器
|
|
302
|
-
*
|
|
303
|
-
* 包含:
|
|
304
|
-
* - 请求日志记录
|
|
305
|
-
* - x-tt-env header 透传
|
|
306
|
-
* - 响应日志记录
|
|
307
|
-
* - 错误日志记录
|
|
308
|
-
*/
|
|
309
|
-
private registerInterceptorsForClient;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|
|
172
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, 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
|
|
2
|
+
import { HttpClientConfig, PlatformPluginOptions } 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';
|
|
@@ -169,144 +169,4 @@ declare class FileService {
|
|
|
169
169
|
private _getFileMetadata;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
* 平台 HttpClient 服务
|
|
174
|
-
*
|
|
175
|
-
* 提供两种使用方式:
|
|
176
|
-
* 1. 全局实例:通过 `instance` 或 `PLATFORM_HTTP_CLIENT` 注入,适用于 95% 的场景
|
|
177
|
-
* 2. 独立实例:通过 `create()` 创建,适用于需要自定义拦截器或配置的场景
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* 基本使用(推荐)
|
|
181
|
-
* ```typescript
|
|
182
|
-
* @Injectable()
|
|
183
|
-
* export class UserService {
|
|
184
|
-
* constructor(
|
|
185
|
-
* @Inject(PLATFORM_HTTP_CLIENT) private http: SafeHttpClient
|
|
186
|
-
* ) {}
|
|
187
|
-
*
|
|
188
|
-
* async getUser() {
|
|
189
|
-
* return this.http.get('/user');
|
|
190
|
-
* }
|
|
191
|
-
* }
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* 需要自定义拦截器(高级场景)
|
|
196
|
-
* ```typescript
|
|
197
|
-
* @Injectable()
|
|
198
|
-
* export class FileService {
|
|
199
|
-
* private fileClient: HttpClient;
|
|
200
|
-
*
|
|
201
|
-
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
202
|
-
* this.fileClient = this.platformHttp.create({
|
|
203
|
-
* config: { timeout: 60000 }
|
|
204
|
-
* });
|
|
205
|
-
*
|
|
206
|
-
* this.fileClient.interceptors.request.use((config) => {
|
|
207
|
-
* console.log('File upload starting...');
|
|
208
|
-
* return config;
|
|
209
|
-
* });
|
|
210
|
-
* }
|
|
211
|
-
* }
|
|
212
|
-
* ```
|
|
213
|
-
*/
|
|
214
|
-
declare class PlatformHttpClientService {
|
|
215
|
-
private readonly requestContext;
|
|
216
|
-
private readonly client;
|
|
217
|
-
private readonly protectedClient;
|
|
218
|
-
private readonly logger;
|
|
219
|
-
constructor(requestContext: RequestContextService);
|
|
220
|
-
/**
|
|
221
|
-
* 获取受保护的 HttpClient 实例(推荐)
|
|
222
|
-
*
|
|
223
|
-
* 该实例不暴露 interceptors,防止业务代码修改全局拦截器
|
|
224
|
-
*
|
|
225
|
-
* @returns 受保护的 HttpClient 实例
|
|
226
|
-
*/
|
|
227
|
-
get instance(): PlatformHttpClient;
|
|
228
|
-
/**
|
|
229
|
-
* 获取原始 HttpClient 实例(危险)
|
|
230
|
-
*
|
|
231
|
-
* ⚠️ 警告:该实例允许修改拦截器,会影响所有使用全局实例的地方
|
|
232
|
-
*
|
|
233
|
-
* 仅用于特殊场景,不应该暴露给业务代码
|
|
234
|
-
* 如果需要自定义拦截器,请使用 `create()` 方法创建独立实例
|
|
235
|
-
*
|
|
236
|
-
* @internal
|
|
237
|
-
* @returns 原始 HttpClient 实例
|
|
238
|
-
*/
|
|
239
|
-
get rawInstance(): HttpClient;
|
|
240
|
-
/**
|
|
241
|
-
* 创建一个新的独立 HttpClient 实例
|
|
242
|
-
*
|
|
243
|
-
* 适用于需要自定义拦截器或配置的场景
|
|
244
|
-
* 创建的实例完全独立,不会影响全局实例
|
|
245
|
-
*
|
|
246
|
-
* @param options - 配置选项(会与全局配置合并)
|
|
247
|
-
* @returns 完整的 HttpClient 实例(允许修改拦截器)
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
* ```typescript
|
|
251
|
-
* @Injectable()
|
|
252
|
-
* export class FileService {
|
|
253
|
-
* private fileClient: HttpClient;
|
|
254
|
-
*
|
|
255
|
-
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
256
|
-
* // 创建超时 60 秒的独立实例
|
|
257
|
-
* this.fileClient = this.platformHttp.create({
|
|
258
|
-
* config: { timeout: 60000 }
|
|
259
|
-
* });
|
|
260
|
-
*
|
|
261
|
-
* // 为这个实例注册拦截器(不影响全局实例)
|
|
262
|
-
* this.fileClient.interceptors.request.use((config) => {
|
|
263
|
-
* console.log('File upload starting...');
|
|
264
|
-
* return config;
|
|
265
|
-
* });
|
|
266
|
-
* }
|
|
267
|
-
*
|
|
268
|
-
* async uploadFile(file: Buffer) {
|
|
269
|
-
* return this.fileClient.post('/file/upload', file);
|
|
270
|
-
* }
|
|
271
|
-
* }
|
|
272
|
-
* ```
|
|
273
|
-
*/
|
|
274
|
-
create(options?: PlatformHttpClientOptions): HttpClient;
|
|
275
|
-
/**
|
|
276
|
-
* 创建一个带全局拦截器的独立 HttpClient 实例
|
|
277
|
-
*
|
|
278
|
-
* 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
|
|
279
|
-
* 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
|
|
280
|
-
*
|
|
281
|
-
* @param options - 配置选项(会与全局配置合并)
|
|
282
|
-
* @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
|
|
283
|
-
*
|
|
284
|
-
* @example
|
|
285
|
-
* ```typescript
|
|
286
|
-
* const client = this.platformHttp.createWithGlobalInterceptors();
|
|
287
|
-
* // 客户端已包含日志和 x-tt-env 拦截器
|
|
288
|
-
* // 可以继续添加自定义拦截器
|
|
289
|
-
* client.interceptors.request.use((config) => {
|
|
290
|
-
* config.headers['x-custom'] = 'value';
|
|
291
|
-
* return config;
|
|
292
|
-
* });
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
295
|
-
createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
|
|
296
|
-
/**
|
|
297
|
-
* 注册全局拦截器(用于单例实例)
|
|
298
|
-
*/
|
|
299
|
-
private registerGlobalInterceptors;
|
|
300
|
-
/**
|
|
301
|
-
* 为指定的 HttpClient 实例注册标准拦截器
|
|
302
|
-
*
|
|
303
|
-
* 包含:
|
|
304
|
-
* - 请求日志记录
|
|
305
|
-
* - x-tt-env header 透传
|
|
306
|
-
* - 响应日志记录
|
|
307
|
-
* - 错误日志记录
|
|
308
|
-
*/
|
|
309
|
-
private registerInterceptorsForClient;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|
|
172
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, type PlatformHttpClientOptions, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/modules/platform/module.ts
|
|
5
5
|
import { Global, Module, ValidationPipe } from "@nestjs/common";
|
|
6
6
|
import { APP_INTERCEPTOR, APP_PIPE } from "@nestjs/core";
|
|
7
|
-
import { CommonModule, OBSERVABLE_SERVICE as OBSERVABLE_SERVICE2
|
|
7
|
+
import { CommonModule, OBSERVABLE_SERVICE as OBSERVABLE_SERVICE2 } from "@lark-apaas/nestjs-common";
|
|
8
8
|
import { ConfigModule, ConfigService } from "@nestjs/config";
|
|
9
9
|
import { NestjsObservableModule as ObservableModule, Observable, ObservableTraceMiddleware, TraceInterceptor } from "@lark-apaas/nestjs-observable";
|
|
10
10
|
import { HttpModule } from "@nestjs/axios";
|
|
@@ -394,13 +394,15 @@ var RequestContextMiddleware = class {
|
|
|
394
394
|
const path = req.originalUrl ?? req.url;
|
|
395
395
|
const userContext = req.userContext ?? {};
|
|
396
396
|
const ttEnv = req.headers["x-tt-env"];
|
|
397
|
+
const referer = req.get("Referer") ?? req.get("Referrer") ?? req.headers?.referer ?? req.headers?.referrer;
|
|
397
398
|
this.requestContext.run({
|
|
398
399
|
path,
|
|
399
400
|
method: req.method,
|
|
400
401
|
userId: userContext.userId,
|
|
401
402
|
tenantId: userContext.tenantId,
|
|
402
403
|
appId: userContext.appId,
|
|
403
|
-
ttEnv
|
|
404
|
+
ttEnv,
|
|
405
|
+
referer
|
|
404
406
|
}, () => next());
|
|
405
407
|
}
|
|
406
408
|
};
|
|
@@ -555,10 +557,13 @@ var FrameworkDebugMiddleware = class {
|
|
|
555
557
|
const routes = [];
|
|
556
558
|
router.stack.forEach((middleware, index) => {
|
|
557
559
|
if (middleware.route) {
|
|
560
|
+
const methods = middleware.route.methods;
|
|
561
|
+
const methodList = methods ? Object.keys(methods).filter((m) => methods[m]).map((m) => m.toUpperCase()) : [];
|
|
562
|
+
const method = methodList.length > 0 ? methodList.join(",") : "ALL";
|
|
558
563
|
routes.push({
|
|
559
564
|
order: String(index),
|
|
560
565
|
path: middleware.route.path,
|
|
561
|
-
method
|
|
566
|
+
method,
|
|
562
567
|
regexp: middleware.regexp?.toString()
|
|
563
568
|
});
|
|
564
569
|
}
|
|
@@ -714,47 +719,10 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
714
719
|
});
|
|
715
720
|
}
|
|
716
721
|
/**
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
* 与 `create()` 类似,但会自动注册全局拦截器(日志、x-tt-env 透传等)
|
|
720
|
-
* 适用于需要保留平台标准行为,同时又需要添加自定义拦截器的场景
|
|
721
|
-
*
|
|
722
|
-
* @param options - 配置选项(会与全局配置合并)
|
|
723
|
-
* @returns 完整的 HttpClient 实例(带全局拦截器,允许添加更多拦截器)
|
|
724
|
-
*
|
|
725
|
-
* @example
|
|
726
|
-
* ```typescript
|
|
727
|
-
* const client = this.platformHttp.createWithGlobalInterceptors();
|
|
728
|
-
* // 客户端已包含日志和 x-tt-env 拦截器
|
|
729
|
-
* // 可以继续添加自定义拦截器
|
|
730
|
-
* client.interceptors.request.use((config) => {
|
|
731
|
-
* config.headers['x-custom'] = 'value';
|
|
732
|
-
* return config;
|
|
733
|
-
* });
|
|
734
|
-
* ```
|
|
735
|
-
*/
|
|
736
|
-
createWithGlobalInterceptors(options) {
|
|
737
|
-
const client = this.create(options);
|
|
738
|
-
this.registerInterceptorsForClient(client);
|
|
739
|
-
return client;
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* 注册全局拦截器(用于单例实例)
|
|
722
|
+
* 注册全局拦截器
|
|
743
723
|
*/
|
|
744
724
|
registerGlobalInterceptors() {
|
|
745
|
-
this.
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* 为指定的 HttpClient 实例注册标准拦截器
|
|
749
|
-
*
|
|
750
|
-
* 包含:
|
|
751
|
-
* - 请求日志记录
|
|
752
|
-
* - x-tt-env header 透传
|
|
753
|
-
* - 响应日志记录
|
|
754
|
-
* - 错误日志记录
|
|
755
|
-
*/
|
|
756
|
-
registerInterceptorsForClient(client) {
|
|
757
|
-
client.interceptors.request.use((config) => {
|
|
725
|
+
this.client.interceptors.request.use((config) => {
|
|
758
726
|
this.logger.debug(`Server SDK HTTP Request: ${config.method?.toUpperCase()} ${config.url}`);
|
|
759
727
|
const ttEnv = this.requestContext.get("ttEnv");
|
|
760
728
|
if (ttEnv) {
|
|
@@ -768,7 +736,7 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
768
736
|
this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
|
|
769
737
|
return Promise.reject(error);
|
|
770
738
|
});
|
|
771
|
-
client.interceptors.response.use((response) => {
|
|
739
|
+
this.client.interceptors.response.use((response) => {
|
|
772
740
|
this.logger.debug(`Server SDK HTTP Response: ${response.status} ${response.url}`);
|
|
773
741
|
return response;
|
|
774
742
|
}, (error) => {
|
|
@@ -1282,15 +1250,6 @@ var PlatformModule = class _PlatformModule {
|
|
|
1282
1250
|
PlatformHttpClientService
|
|
1283
1251
|
]
|
|
1284
1252
|
},
|
|
1285
|
-
{
|
|
1286
|
-
provide: HTTP_CLIENT_FACTORY,
|
|
1287
|
-
useFactory: /* @__PURE__ */ __name((svc) => ({
|
|
1288
|
-
create: /* @__PURE__ */ __name((options2) => svc.createWithGlobalInterceptors(options2), "create")
|
|
1289
|
-
}), "useFactory"),
|
|
1290
|
-
inject: [
|
|
1291
|
-
PlatformHttpClientService
|
|
1292
|
-
]
|
|
1293
|
-
},
|
|
1294
1253
|
HttpInterceptorService,
|
|
1295
1254
|
{
|
|
1296
1255
|
provide: APP_INTERCEPTOR,
|
|
@@ -1304,8 +1263,6 @@ var PlatformModule = class _PlatformModule {
|
|
|
1304
1263
|
CommonModule,
|
|
1305
1264
|
OBSERVABLE_SERVICE2,
|
|
1306
1265
|
PLATFORM_HTTP_CLIENT3,
|
|
1307
|
-
HTTP_CLIENT_FACTORY,
|
|
1308
|
-
PlatformHttpClientService,
|
|
1309
1266
|
CapabilityModule,
|
|
1310
1267
|
FileService
|
|
1311
1268
|
]
|
|
@@ -1388,7 +1345,6 @@ export {
|
|
|
1388
1345
|
DevToolsModule,
|
|
1389
1346
|
DevToolsV2Module2 as DevToolsV2Module,
|
|
1390
1347
|
FileService,
|
|
1391
|
-
PlatformHttpClientService,
|
|
1392
1348
|
PlatformModule,
|
|
1393
1349
|
UserContextMiddleware,
|
|
1394
1350
|
ViewContextMiddleware,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-nestjs-core",
|
|
3
|
-
"version": "1.1.23-alpha.
|
|
3
|
+
"version": "1.1.23-alpha.20",
|
|
4
4
|
"description": "FullStack Nestjs Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"@lark-apaas/file-service": "^0.1.1",
|
|
43
43
|
"@lark-apaas/http-client": "^0.1.2",
|
|
44
44
|
"@lark-apaas/nestjs-authnpaas": "^1.0.2",
|
|
45
|
-
"@lark-apaas/nestjs-authzpaas": "0.1.2-alpha.
|
|
46
|
-
"@lark-apaas/nestjs-capability": "0.1.5-alpha.
|
|
47
|
-
"@lark-apaas/nestjs-common": "0.1.4-alpha.
|
|
48
|
-
"@lark-apaas/nestjs-datapaas": "1.0.10-alpha.
|
|
49
|
-
"@lark-apaas/nestjs-logger": "1.0.10-alpha.
|
|
50
|
-
"@lark-apaas/nestjs-observable": "0.0.5-alpha.
|
|
45
|
+
"@lark-apaas/nestjs-authzpaas": "0.1.2-alpha.5",
|
|
46
|
+
"@lark-apaas/nestjs-capability": "0.1.5-alpha.5",
|
|
47
|
+
"@lark-apaas/nestjs-common": "0.1.4-alpha.5",
|
|
48
|
+
"@lark-apaas/nestjs-datapaas": "1.0.10-alpha.5",
|
|
49
|
+
"@lark-apaas/nestjs-logger": "1.0.10-alpha.19",
|
|
50
|
+
"@lark-apaas/nestjs-observable": "0.0.5-alpha.5",
|
|
51
51
|
"@lark-apaas/nestjs-openapi-devtools": "^1.0.9",
|
|
52
52
|
"@lark-apaas/nestjs-trigger": "^0.0.2",
|
|
53
53
|
"@nestjs/axios": "^4.0.1",
|