@lark-apaas/fullstack-nestjs-core 1.1.23-alpha.4 → 1.1.23-alpha.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 +14 -54
- package/dist/index.d.cts +2 -142
- package/dist/index.d.ts +2 -142
- package/dist/index.js +15 -54
- 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,
|
|
@@ -577,7 +576,17 @@ var FrameworkDebugMiddleware = class {
|
|
|
577
576
|
constructor(httpAdapterHost) {
|
|
578
577
|
this.httpAdapterHost = httpAdapterHost;
|
|
579
578
|
}
|
|
580
|
-
use(
|
|
579
|
+
use(req, res) {
|
|
580
|
+
const origin = req.headers.origin;
|
|
581
|
+
if (origin) {
|
|
582
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
583
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
584
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
585
|
+
}
|
|
586
|
+
if (req.method === "OPTIONS") {
|
|
587
|
+
res.status(204).end();
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
581
590
|
res.json(this.getDebugInfo());
|
|
582
591
|
}
|
|
583
592
|
getDebugInfo() {
|
|
@@ -760,47 +769,10 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
760
769
|
});
|
|
761
770
|
}
|
|
762
771
|
/**
|
|
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
|
-
* 注册全局拦截器(用于单例实例)
|
|
772
|
+
* 注册全局拦截器
|
|
789
773
|
*/
|
|
790
774
|
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) => {
|
|
775
|
+
this.client.interceptors.request.use((config) => {
|
|
804
776
|
this.logger.debug(`Server SDK HTTP Request: ${config.method?.toUpperCase()} ${config.url}`);
|
|
805
777
|
const ttEnv = this.requestContext.get("ttEnv");
|
|
806
778
|
if (ttEnv) {
|
|
@@ -814,7 +786,7 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
814
786
|
this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
|
|
815
787
|
return Promise.reject(error);
|
|
816
788
|
});
|
|
817
|
-
client.interceptors.response.use((response) => {
|
|
789
|
+
this.client.interceptors.response.use((response) => {
|
|
818
790
|
this.logger.debug(`Server SDK HTTP Response: ${response.status} ${response.url}`);
|
|
819
791
|
return response;
|
|
820
792
|
}, (error) => {
|
|
@@ -1328,15 +1300,6 @@ var PlatformModule = class _PlatformModule {
|
|
|
1328
1300
|
PlatformHttpClientService
|
|
1329
1301
|
]
|
|
1330
1302
|
},
|
|
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
1303
|
HttpInterceptorService,
|
|
1341
1304
|
{
|
|
1342
1305
|
provide: import_core2.APP_INTERCEPTOR,
|
|
@@ -1350,8 +1313,6 @@ var PlatformModule = class _PlatformModule {
|
|
|
1350
1313
|
import_nestjs_common5.CommonModule,
|
|
1351
1314
|
import_nestjs_common5.OBSERVABLE_SERVICE,
|
|
1352
1315
|
import_nestjs_common6.PLATFORM_HTTP_CLIENT,
|
|
1353
|
-
import_nestjs_common5.HTTP_CLIENT_FACTORY,
|
|
1354
|
-
PlatformHttpClientService,
|
|
1355
1316
|
import_nestjs_capability.CapabilityModule,
|
|
1356
1317
|
FileService
|
|
1357
1318
|
]
|
|
@@ -1435,7 +1396,6 @@ var import_nestjs_authzpaas2 = require("@lark-apaas/nestjs-authzpaas");
|
|
|
1435
1396
|
DevToolsModule,
|
|
1436
1397
|
DevToolsV2Module,
|
|
1437
1398
|
FileService,
|
|
1438
|
-
PlatformHttpClientService,
|
|
1439
1399
|
PlatformModule,
|
|
1440
1400
|
UserContextMiddleware,
|
|
1441
1401
|
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";
|
|
@@ -531,7 +531,17 @@ var FrameworkDebugMiddleware = class {
|
|
|
531
531
|
constructor(httpAdapterHost) {
|
|
532
532
|
this.httpAdapterHost = httpAdapterHost;
|
|
533
533
|
}
|
|
534
|
-
use(
|
|
534
|
+
use(req, res) {
|
|
535
|
+
const origin = req.headers.origin;
|
|
536
|
+
if (origin) {
|
|
537
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
538
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
539
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
540
|
+
}
|
|
541
|
+
if (req.method === "OPTIONS") {
|
|
542
|
+
res.status(204).end();
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
535
545
|
res.json(this.getDebugInfo());
|
|
536
546
|
}
|
|
537
547
|
getDebugInfo() {
|
|
@@ -714,47 +724,10 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
714
724
|
});
|
|
715
725
|
}
|
|
716
726
|
/**
|
|
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
|
-
* 注册全局拦截器(用于单例实例)
|
|
727
|
+
* 注册全局拦截器
|
|
743
728
|
*/
|
|
744
729
|
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) => {
|
|
730
|
+
this.client.interceptors.request.use((config) => {
|
|
758
731
|
this.logger.debug(`Server SDK HTTP Request: ${config.method?.toUpperCase()} ${config.url}`);
|
|
759
732
|
const ttEnv = this.requestContext.get("ttEnv");
|
|
760
733
|
if (ttEnv) {
|
|
@@ -768,7 +741,7 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
768
741
|
this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
|
|
769
742
|
return Promise.reject(error);
|
|
770
743
|
});
|
|
771
|
-
client.interceptors.response.use((response) => {
|
|
744
|
+
this.client.interceptors.response.use((response) => {
|
|
772
745
|
this.logger.debug(`Server SDK HTTP Response: ${response.status} ${response.url}`);
|
|
773
746
|
return response;
|
|
774
747
|
}, (error) => {
|
|
@@ -1282,15 +1255,6 @@ var PlatformModule = class _PlatformModule {
|
|
|
1282
1255
|
PlatformHttpClientService
|
|
1283
1256
|
]
|
|
1284
1257
|
},
|
|
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
1258
|
HttpInterceptorService,
|
|
1295
1259
|
{
|
|
1296
1260
|
provide: APP_INTERCEPTOR,
|
|
@@ -1304,8 +1268,6 @@ var PlatformModule = class _PlatformModule {
|
|
|
1304
1268
|
CommonModule,
|
|
1305
1269
|
OBSERVABLE_SERVICE2,
|
|
1306
1270
|
PLATFORM_HTTP_CLIENT3,
|
|
1307
|
-
HTTP_CLIENT_FACTORY,
|
|
1308
|
-
PlatformHttpClientService,
|
|
1309
1271
|
CapabilityModule,
|
|
1310
1272
|
FileService
|
|
1311
1273
|
]
|
|
@@ -1388,7 +1350,6 @@ export {
|
|
|
1388
1350
|
DevToolsModule,
|
|
1389
1351
|
DevToolsV2Module2 as DevToolsV2Module,
|
|
1390
1352
|
FileService,
|
|
1391
|
-
PlatformHttpClientService,
|
|
1392
1353
|
PlatformModule,
|
|
1393
1354
|
UserContextMiddleware,
|
|
1394
1355
|
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.6",
|
|
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.
|
|
46
|
-
"@lark-apaas/nestjs-capability": "0.1.
|
|
47
|
-
"@lark-apaas/nestjs-common": "0.1.
|
|
48
|
-
"@lark-apaas/nestjs-datapaas": "1.0.
|
|
49
|
-
"@lark-apaas/nestjs-logger": "1.0.10-alpha.
|
|
50
|
-
"@lark-apaas/nestjs-observable": "0.0.
|
|
45
|
+
"@lark-apaas/nestjs-authzpaas": "^0.1.1",
|
|
46
|
+
"@lark-apaas/nestjs-capability": "^0.1.3",
|
|
47
|
+
"@lark-apaas/nestjs-common": "^0.1.3",
|
|
48
|
+
"@lark-apaas/nestjs-datapaas": "^1.0.9",
|
|
49
|
+
"@lark-apaas/nestjs-logger": "1.0.10-alpha.5",
|
|
50
|
+
"@lark-apaas/nestjs-observable": "^0.0.4",
|
|
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",
|