@lark-apaas/fullstack-nestjs-core 1.1.5 → 1.1.6-alpha.1
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 +165 -0
- package/dist/index.cjs +408 -33
- package/dist/index.d.cts +21 -2
- package/dist/index.d.ts +21 -2
- package/dist/index.js +400 -27
- package/package.json +7 -1
package/dist/index.cjs
CHANGED
|
@@ -44,12 +44,17 @@ __export(index_exports, {
|
|
|
44
44
|
module.exports = __toCommonJS(index_exports);
|
|
45
45
|
|
|
46
46
|
// src/modules/platform/module.ts
|
|
47
|
-
var
|
|
47
|
+
var import_common9 = require("@nestjs/common");
|
|
48
48
|
var import_core2 = require("@nestjs/core");
|
|
49
|
+
var import_nestjs_common3 = require("@lark-apaas/nestjs-common");
|
|
49
50
|
var import_config2 = require("@nestjs/config");
|
|
50
|
-
var
|
|
51
|
+
var import_nestjs_observable = require("@lark-apaas/nestjs-observable");
|
|
52
|
+
var import_axios2 = require("@nestjs/axios");
|
|
53
|
+
var import_nestjs_logger2 = require("@lark-apaas/nestjs-logger");
|
|
51
54
|
var import_nestjs_datapaas = require("@lark-apaas/nestjs-datapaas");
|
|
52
55
|
var import_nestjs_authnpaas = require("@lark-apaas/nestjs-authnpaas");
|
|
56
|
+
var import_nestjs_trigger = require("@lark-apaas/nestjs-trigger");
|
|
57
|
+
var import_nestjs_common4 = require("@lark-apaas/nestjs-common");
|
|
53
58
|
|
|
54
59
|
// src/middlewares/user-context/index.ts
|
|
55
60
|
var import_common = require("@nestjs/common");
|
|
@@ -163,6 +168,7 @@ CsrfMiddleware = _ts_decorate2([
|
|
|
163
168
|
|
|
164
169
|
// src/middlewares/view-context/index.ts
|
|
165
170
|
var import_common3 = require("@nestjs/common");
|
|
171
|
+
var import_nestjs_common = require("@lark-apaas/nestjs-common");
|
|
166
172
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
167
173
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
168
174
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -170,13 +176,50 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
170
176
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
171
177
|
}
|
|
172
178
|
__name(_ts_decorate3, "_ts_decorate");
|
|
173
|
-
|
|
179
|
+
function _ts_metadata(k, v) {
|
|
180
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
181
|
+
}
|
|
182
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
183
|
+
function _ts_param(paramIndex, decorator) {
|
|
184
|
+
return function(target, key) {
|
|
185
|
+
decorator(target, key, paramIndex);
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
__name(_ts_param, "_ts_param");
|
|
189
|
+
var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
174
190
|
static {
|
|
175
191
|
__name(this, "ViewContextMiddleware");
|
|
176
192
|
}
|
|
177
|
-
|
|
193
|
+
client;
|
|
194
|
+
logger = new import_common3.Logger(_ViewContextMiddleware.name);
|
|
195
|
+
constructor(client) {
|
|
196
|
+
this.client = client;
|
|
197
|
+
}
|
|
198
|
+
async getAppInfo(appId) {
|
|
199
|
+
if (!appId) {
|
|
200
|
+
this.logger.warn(`appId is empty, skip get app info`);
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const resp = await this.client.get(`b/${appId}/get_published_v2`);
|
|
205
|
+
if (resp.status !== 200) {
|
|
206
|
+
throw new Error(`Failed to get app info, status: ${resp.status}`);
|
|
207
|
+
}
|
|
208
|
+
const data = await resp.json();
|
|
209
|
+
if (data.status_code !== "0") {
|
|
210
|
+
throw new Error(`Failed to get app info, status_code: ${data.status_code}`);
|
|
211
|
+
}
|
|
212
|
+
return data.data.app_info ?? {};
|
|
213
|
+
} catch (err) {
|
|
214
|
+
this.logger.error(err, "Failed to get app info");
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async use(req, res, next) {
|
|
178
219
|
const { userId, tenantId, appId } = req.userContext;
|
|
179
220
|
const csrfToken = req.csrfToken;
|
|
221
|
+
const appInfo = await this.getAppInfo(appId);
|
|
222
|
+
this.logger.debug(`appInfo: ${JSON.stringify(appInfo)}`);
|
|
180
223
|
req.__platform_data__ = {
|
|
181
224
|
csrfToken: csrfToken ?? "",
|
|
182
225
|
userId: userId ?? "",
|
|
@@ -194,7 +237,12 @@ var ViewContextMiddleware = class {
|
|
|
194
237
|
}
|
|
195
238
|
};
|
|
196
239
|
ViewContextMiddleware = _ts_decorate3([
|
|
197
|
-
(0, import_common3.Injectable)()
|
|
240
|
+
(0, import_common3.Injectable)(),
|
|
241
|
+
_ts_param(0, (0, import_common3.Inject)(import_nestjs_common.PLATFORM_HTTP_CLIENT)),
|
|
242
|
+
_ts_metadata("design:type", Function),
|
|
243
|
+
_ts_metadata("design:paramtypes", [
|
|
244
|
+
typeof PlatformHttpClient === "undefined" ? Object : PlatformHttpClient
|
|
245
|
+
])
|
|
198
246
|
], ViewContextMiddleware);
|
|
199
247
|
|
|
200
248
|
// src/middlewares/csrf_token/index.ts
|
|
@@ -294,6 +342,128 @@ function apiResponseInterceptor(req, res, next) {
|
|
|
294
342
|
}
|
|
295
343
|
__name(apiResponseInterceptor, "apiResponseInterceptor");
|
|
296
344
|
|
|
345
|
+
// src/middlewares/request-context/index.ts
|
|
346
|
+
var import_common5 = require("@nestjs/common");
|
|
347
|
+
var import_nestjs_common2 = require("@lark-apaas/nestjs-common");
|
|
348
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
349
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
350
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
351
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
352
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
353
|
+
}
|
|
354
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
355
|
+
function _ts_metadata2(k, v) {
|
|
356
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
357
|
+
}
|
|
358
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
359
|
+
var RequestContextMiddleware = class {
|
|
360
|
+
static {
|
|
361
|
+
__name(this, "RequestContextMiddleware");
|
|
362
|
+
}
|
|
363
|
+
requestContext;
|
|
364
|
+
constructor(requestContext) {
|
|
365
|
+
this.requestContext = requestContext;
|
|
366
|
+
}
|
|
367
|
+
use(req, _res, next) {
|
|
368
|
+
const path = req.originalUrl ?? req.url;
|
|
369
|
+
const userContext = req.userContext ?? {};
|
|
370
|
+
this.requestContext.run({
|
|
371
|
+
path,
|
|
372
|
+
method: req.method,
|
|
373
|
+
userId: userContext.userId,
|
|
374
|
+
tenantId: userContext.tenantId,
|
|
375
|
+
appId: userContext.appId
|
|
376
|
+
}, () => next());
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
RequestContextMiddleware = _ts_decorate5([
|
|
380
|
+
(0, import_common5.Injectable)(),
|
|
381
|
+
_ts_metadata2("design:type", Function),
|
|
382
|
+
_ts_metadata2("design:paramtypes", [
|
|
383
|
+
typeof import_nestjs_common2.RequestContextService === "undefined" ? Object : import_nestjs_common2.RequestContextService
|
|
384
|
+
])
|
|
385
|
+
], RequestContextMiddleware);
|
|
386
|
+
|
|
387
|
+
// src/services/http-interceptor.service.ts
|
|
388
|
+
var import_common6 = require("@nestjs/common");
|
|
389
|
+
var import_axios = require("@nestjs/axios");
|
|
390
|
+
var import_nestjs_logger = require("@lark-apaas/nestjs-logger");
|
|
391
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
392
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
393
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
394
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
395
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
396
|
+
}
|
|
397
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
398
|
+
function _ts_metadata3(k, v) {
|
|
399
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
400
|
+
}
|
|
401
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
402
|
+
var HttpInterceptorService = class {
|
|
403
|
+
static {
|
|
404
|
+
__name(this, "HttpInterceptorService");
|
|
405
|
+
}
|
|
406
|
+
httpService;
|
|
407
|
+
logger;
|
|
408
|
+
constructor(httpService, logger) {
|
|
409
|
+
this.httpService = httpService;
|
|
410
|
+
this.logger = logger;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* 模块初始化时配置拦截器
|
|
414
|
+
*/
|
|
415
|
+
onModuleInit() {
|
|
416
|
+
this.setupInterceptors();
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* 配置 axios 请求/响应拦截器
|
|
420
|
+
*/
|
|
421
|
+
setupInterceptors() {
|
|
422
|
+
const axiosInstance = this.httpService.axiosRef;
|
|
423
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
424
|
+
this.logger.log("HTTP Request", {
|
|
425
|
+
method: config.method?.toUpperCase(),
|
|
426
|
+
url: config.url,
|
|
427
|
+
headers: config.headers,
|
|
428
|
+
params: config.params,
|
|
429
|
+
data: config.data
|
|
430
|
+
}, "HttpService");
|
|
431
|
+
return config;
|
|
432
|
+
}, (error) => {
|
|
433
|
+
this.logger.error("HTTP Request Error", error, "HttpService");
|
|
434
|
+
return Promise.reject(error);
|
|
435
|
+
});
|
|
436
|
+
axiosInstance.interceptors.response.use((response) => {
|
|
437
|
+
this.logger.log("HTTP Response", {
|
|
438
|
+
method: response.config.method?.toUpperCase(),
|
|
439
|
+
url: response.config.url,
|
|
440
|
+
status: response.status,
|
|
441
|
+
statusText: response.statusText,
|
|
442
|
+
data: response.data
|
|
443
|
+
}, "HttpService");
|
|
444
|
+
return response;
|
|
445
|
+
}, (error) => {
|
|
446
|
+
this.logger.error("HTTP Response Error", {
|
|
447
|
+
method: error.config?.method?.toUpperCase(),
|
|
448
|
+
url: error.config?.url,
|
|
449
|
+
status: error.response?.status,
|
|
450
|
+
statusText: error.response?.statusText,
|
|
451
|
+
data: error.response?.data,
|
|
452
|
+
message: error.message
|
|
453
|
+
}, "HttpService");
|
|
454
|
+
return Promise.reject(error);
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
HttpInterceptorService = _ts_decorate6([
|
|
459
|
+
(0, import_common6.Injectable)(),
|
|
460
|
+
_ts_metadata3("design:type", Function),
|
|
461
|
+
_ts_metadata3("design:paramtypes", [
|
|
462
|
+
typeof import_axios.HttpService === "undefined" ? Object : import_axios.HttpService,
|
|
463
|
+
typeof import_nestjs_logger.AppLogger === "undefined" ? Object : import_nestjs_logger.AppLogger
|
|
464
|
+
])
|
|
465
|
+
], HttpInterceptorService);
|
|
466
|
+
|
|
297
467
|
// src/modules/platform/config/app.config.ts
|
|
298
468
|
var import_config = require("@nestjs/config");
|
|
299
469
|
var NAMESPACE = "app";
|
|
@@ -307,19 +477,19 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
|
|
|
307
477
|
});
|
|
308
478
|
|
|
309
479
|
// src/middlewares/debug/index.ts
|
|
310
|
-
var
|
|
480
|
+
var import_common7 = require("@nestjs/common");
|
|
311
481
|
var import_core = require("@nestjs/core");
|
|
312
|
-
function
|
|
482
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
313
483
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
314
484
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
315
485
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
316
486
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
317
487
|
}
|
|
318
|
-
__name(
|
|
319
|
-
function
|
|
488
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
489
|
+
function _ts_metadata4(k, v) {
|
|
320
490
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
321
491
|
}
|
|
322
|
-
__name(
|
|
492
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
323
493
|
var processStartTimestamp = Date.now();
|
|
324
494
|
var FrameworkDebugMiddleware = class {
|
|
325
495
|
static {
|
|
@@ -367,23 +537,201 @@ var FrameworkDebugMiddleware = class {
|
|
|
367
537
|
};
|
|
368
538
|
}
|
|
369
539
|
};
|
|
370
|
-
FrameworkDebugMiddleware =
|
|
371
|
-
(0,
|
|
372
|
-
|
|
373
|
-
|
|
540
|
+
FrameworkDebugMiddleware = _ts_decorate7([
|
|
541
|
+
(0, import_common7.Injectable)(),
|
|
542
|
+
_ts_metadata4("design:type", Function),
|
|
543
|
+
_ts_metadata4("design:paramtypes", [
|
|
374
544
|
typeof import_core.HttpAdapterHost === "undefined" ? Object : import_core.HttpAdapterHost
|
|
375
545
|
])
|
|
376
546
|
], FrameworkDebugMiddleware);
|
|
377
547
|
|
|
548
|
+
// src/services/platform-http-client.service.ts
|
|
549
|
+
var import_common8 = require("@nestjs/common");
|
|
550
|
+
var import_http_client = require("@lark-apaas/http-client");
|
|
551
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
552
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
553
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
554
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
555
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
556
|
+
}
|
|
557
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
558
|
+
function _ts_metadata5(k, v) {
|
|
559
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
560
|
+
}
|
|
561
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
562
|
+
var ProtectedHttpClient = class ProtectedHttpClient2 {
|
|
563
|
+
static {
|
|
564
|
+
__name(this, "ProtectedHttpClient");
|
|
565
|
+
}
|
|
566
|
+
client;
|
|
567
|
+
constructor(client) {
|
|
568
|
+
this.client = client;
|
|
569
|
+
}
|
|
570
|
+
request(config) {
|
|
571
|
+
return this.client.request(config);
|
|
572
|
+
}
|
|
573
|
+
get(url, config) {
|
|
574
|
+
return this.client.get(url, config);
|
|
575
|
+
}
|
|
576
|
+
post(url, data, config) {
|
|
577
|
+
return this.client.post(url, data, config);
|
|
578
|
+
}
|
|
579
|
+
put(url, data, config) {
|
|
580
|
+
return this.client.put(url, data, config);
|
|
581
|
+
}
|
|
582
|
+
patch(url, data, config) {
|
|
583
|
+
return this.client.patch(url, data, config);
|
|
584
|
+
}
|
|
585
|
+
delete(url, config) {
|
|
586
|
+
return this.client.delete(url, config);
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
590
|
+
static {
|
|
591
|
+
__name(this, "PlatformHttpClientService");
|
|
592
|
+
}
|
|
593
|
+
client;
|
|
594
|
+
protectedClient;
|
|
595
|
+
logger = new import_common8.Logger(_PlatformHttpClientService.name);
|
|
596
|
+
constructor() {
|
|
597
|
+
const baseConfig = {
|
|
598
|
+
timeout: 5e3
|
|
599
|
+
};
|
|
600
|
+
this.client = new import_http_client.HttpClient({
|
|
601
|
+
...baseConfig,
|
|
602
|
+
platform: {
|
|
603
|
+
enabled: true
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
this.protectedClient = new ProtectedHttpClient(this.client);
|
|
607
|
+
this.registerGlobalInterceptors();
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* 获取受保护的 HttpClient 实例(推荐)
|
|
611
|
+
*
|
|
612
|
+
* 该实例不暴露 interceptors,防止业务代码修改全局拦截器
|
|
613
|
+
*
|
|
614
|
+
* @returns 受保护的 HttpClient 实例
|
|
615
|
+
*/
|
|
616
|
+
get instance() {
|
|
617
|
+
return this.protectedClient;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* 获取原始 HttpClient 实例(危险)
|
|
621
|
+
*
|
|
622
|
+
* ⚠️ 警告:该实例允许修改拦截器,会影响所有使用全局实例的地方
|
|
623
|
+
*
|
|
624
|
+
* 仅用于特殊场景,不应该暴露给业务代码
|
|
625
|
+
* 如果需要自定义拦截器,请使用 `create()` 方法创建独立实例
|
|
626
|
+
*
|
|
627
|
+
* @internal
|
|
628
|
+
* @returns 原始 HttpClient 实例
|
|
629
|
+
*/
|
|
630
|
+
get rawInstance() {
|
|
631
|
+
return this.client;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* 创建一个新的独立 HttpClient 实例
|
|
635
|
+
*
|
|
636
|
+
* 适用于需要自定义拦截器或配置的场景
|
|
637
|
+
* 创建的实例完全独立,不会影响全局实例
|
|
638
|
+
*
|
|
639
|
+
* @param options - 配置选项(会与全局配置合并)
|
|
640
|
+
* @returns 完整的 HttpClient 实例(允许修改拦截器)
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```typescript
|
|
644
|
+
* @Injectable()
|
|
645
|
+
* export class FileService {
|
|
646
|
+
* private fileClient: HttpClient;
|
|
647
|
+
*
|
|
648
|
+
* constructor(private platformHttp: PlatformHttpClientService) {
|
|
649
|
+
* // 创建超时 60 秒的独立实例
|
|
650
|
+
* this.fileClient = this.platformHttp.create({
|
|
651
|
+
* config: { timeout: 60000 }
|
|
652
|
+
* });
|
|
653
|
+
*
|
|
654
|
+
* // 为这个实例注册拦截器(不影响全局实例)
|
|
655
|
+
* this.fileClient.interceptors.request.use((config) => {
|
|
656
|
+
* console.log('File upload starting...');
|
|
657
|
+
* return config;
|
|
658
|
+
* });
|
|
659
|
+
* }
|
|
660
|
+
*
|
|
661
|
+
* async uploadFile(file: Buffer) {
|
|
662
|
+
* return this.fileClient.post('/file/upload', file);
|
|
663
|
+
* }
|
|
664
|
+
* }
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
create(options) {
|
|
668
|
+
const mergedConfig = {
|
|
669
|
+
timeout: 5e3,
|
|
670
|
+
...options?.config
|
|
671
|
+
};
|
|
672
|
+
const mergedPlatform = {
|
|
673
|
+
enabled: true,
|
|
674
|
+
...options?.platform
|
|
675
|
+
};
|
|
676
|
+
return new import_http_client.HttpClient({
|
|
677
|
+
...mergedConfig,
|
|
678
|
+
platform: mergedPlatform
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* 注册全局拦截器
|
|
683
|
+
*/
|
|
684
|
+
registerGlobalInterceptors() {
|
|
685
|
+
this.client.interceptors.request.use((config) => {
|
|
686
|
+
this.logger.log("Internal HTTP Request", {
|
|
687
|
+
method: config.method?.toUpperCase(),
|
|
688
|
+
url: config.url,
|
|
689
|
+
headers: config.headers,
|
|
690
|
+
params: config.params,
|
|
691
|
+
data: config.data
|
|
692
|
+
}, "HttpService");
|
|
693
|
+
return config;
|
|
694
|
+
}, (error) => {
|
|
695
|
+
this.logger.error("HTTP Request Error", error, "HttpService");
|
|
696
|
+
return Promise.reject(error);
|
|
697
|
+
});
|
|
698
|
+
this.client.interceptors.response.use((response) => {
|
|
699
|
+
this.logger.log("InternalHTTP Response", {
|
|
700
|
+
method: response.config.method?.toUpperCase(),
|
|
701
|
+
url: response.config.url,
|
|
702
|
+
status: response.status,
|
|
703
|
+
statusText: response.statusText,
|
|
704
|
+
data: response.data
|
|
705
|
+
}, "HttpService");
|
|
706
|
+
return response;
|
|
707
|
+
}, (error) => {
|
|
708
|
+
this.logger.error("Internal HTTP Response Error", {
|
|
709
|
+
method: error.config?.method?.toUpperCase(),
|
|
710
|
+
url: error.config?.url,
|
|
711
|
+
status: error.response?.status,
|
|
712
|
+
statusText: error.response?.statusText,
|
|
713
|
+
data: error.response?.data,
|
|
714
|
+
message: error.message
|
|
715
|
+
}, "HttpService");
|
|
716
|
+
return Promise.reject(error);
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
PlatformHttpClientService = _ts_decorate8([
|
|
721
|
+
(0, import_common8.Injectable)(),
|
|
722
|
+
_ts_metadata5("design:type", Function),
|
|
723
|
+
_ts_metadata5("design:paramtypes", [])
|
|
724
|
+
], PlatformHttpClientService);
|
|
725
|
+
|
|
378
726
|
// src/modules/platform/module.ts
|
|
379
|
-
function
|
|
727
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
380
728
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
381
729
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
382
730
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
383
731
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
384
732
|
}
|
|
385
|
-
__name(
|
|
386
|
-
var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
|
|
733
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
734
|
+
var PLATFORM_MODULE_OPTIONS = /* @__PURE__ */ Symbol("PLATFORM_MODULE_OPTIONS");
|
|
387
735
|
var PlatformModule = class _PlatformModule {
|
|
388
736
|
static {
|
|
389
737
|
__name(this, "PlatformModule");
|
|
@@ -404,25 +752,31 @@ var PlatformModule = class _PlatformModule {
|
|
|
404
752
|
app_config_default
|
|
405
753
|
]
|
|
406
754
|
}),
|
|
407
|
-
|
|
755
|
+
import_nestjs_common3.CommonModule,
|
|
756
|
+
import_nestjs_observable.NestjsObservableModule,
|
|
757
|
+
import_nestjs_logger2.LoggerModule,
|
|
758
|
+
import_axios2.HttpModule.register({
|
|
759
|
+
timeout: 5e3,
|
|
760
|
+
maxRedirects: 5
|
|
761
|
+
}),
|
|
408
762
|
import_nestjs_datapaas.DataPaasModule.forRootAsync({
|
|
409
763
|
imports: [
|
|
410
764
|
import_config2.ConfigModule,
|
|
411
|
-
|
|
765
|
+
import_nestjs_logger2.LoggerModule
|
|
412
766
|
],
|
|
413
767
|
inject: [
|
|
414
768
|
import_config2.ConfigService,
|
|
415
|
-
|
|
769
|
+
import_nestjs_logger2.AppLogger
|
|
416
770
|
],
|
|
417
771
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
418
772
|
const configService = args[0];
|
|
419
773
|
const appLogger = args[1];
|
|
420
774
|
const drizzleLogger = {
|
|
421
775
|
logQuery(query, params) {
|
|
422
|
-
appLogger.log?.("SQL Query"
|
|
776
|
+
appLogger.log?.("SQL Query " + JSON.stringify({
|
|
423
777
|
query,
|
|
424
778
|
params
|
|
425
|
-
}, "Database");
|
|
779
|
+
}), "Database");
|
|
426
780
|
}
|
|
427
781
|
};
|
|
428
782
|
return {
|
|
@@ -431,7 +785,8 @@ var PlatformModule = class _PlatformModule {
|
|
|
431
785
|
};
|
|
432
786
|
}, "useFactory")
|
|
433
787
|
}),
|
|
434
|
-
import_nestjs_authnpaas.AuthNPaasModule.forRoot()
|
|
788
|
+
import_nestjs_authnpaas.AuthNPaasModule.forRoot(),
|
|
789
|
+
import_nestjs_trigger.AutomationModule.forRoot()
|
|
435
790
|
],
|
|
436
791
|
providers: [
|
|
437
792
|
{
|
|
@@ -440,17 +795,33 @@ var PlatformModule = class _PlatformModule {
|
|
|
440
795
|
},
|
|
441
796
|
{
|
|
442
797
|
provide: import_core2.APP_PIPE,
|
|
443
|
-
useValue: new
|
|
798
|
+
useValue: new import_common9.ValidationPipe({
|
|
444
799
|
transform: true,
|
|
445
800
|
transformOptions: {
|
|
446
801
|
enableImplicitConversion: true
|
|
447
802
|
}
|
|
448
803
|
})
|
|
449
|
-
}
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
provide: import_nestjs_common3.OBSERVABLE_SERVICE,
|
|
807
|
+
useClass: import_nestjs_observable.Observable
|
|
808
|
+
},
|
|
809
|
+
PlatformHttpClientService,
|
|
810
|
+
{
|
|
811
|
+
provide: import_nestjs_common4.PLATFORM_HTTP_CLIENT,
|
|
812
|
+
useFactory: /* @__PURE__ */ __name((svc) => svc.instance, "useFactory"),
|
|
813
|
+
inject: [
|
|
814
|
+
PlatformHttpClientService
|
|
815
|
+
]
|
|
816
|
+
},
|
|
817
|
+
HttpInterceptorService
|
|
450
818
|
],
|
|
451
819
|
exports: [
|
|
452
820
|
import_config2.ConfigModule,
|
|
453
|
-
|
|
821
|
+
import_nestjs_logger2.LoggerModule,
|
|
822
|
+
import_nestjs_common3.CommonModule,
|
|
823
|
+
import_nestjs_common3.OBSERVABLE_SERVICE,
|
|
824
|
+
import_nestjs_common4.PLATFORM_HTTP_CLIENT
|
|
454
825
|
]
|
|
455
826
|
};
|
|
456
827
|
}
|
|
@@ -463,7 +834,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
463
834
|
if (process.env.NODE_ENV === "development") {
|
|
464
835
|
consumer.apply(FrameworkDebugMiddleware).forRoutes("/api/__framework__/debug");
|
|
465
836
|
}
|
|
466
|
-
consumer.apply(UserContextMiddleware,
|
|
837
|
+
consumer.apply(UserContextMiddleware, RequestContextMiddleware, import_nestjs_logger2.LoggerContextMiddleware, import_nestjs_datapaas.SqlExecutionContextMiddleware).forRoutes("/*");
|
|
467
838
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
468
839
|
if (options.enableCsrf !== false) {
|
|
469
840
|
const csrfRoutes = options.csrfRoutes || "/api/*";
|
|
@@ -477,20 +848,20 @@ var PlatformModule = class _PlatformModule {
|
|
|
477
848
|
}
|
|
478
849
|
}
|
|
479
850
|
};
|
|
480
|
-
PlatformModule =
|
|
481
|
-
(0,
|
|
482
|
-
(0,
|
|
851
|
+
PlatformModule = _ts_decorate9([
|
|
852
|
+
(0, import_common9.Global)(),
|
|
853
|
+
(0, import_common9.Module)({})
|
|
483
854
|
], PlatformModule);
|
|
484
855
|
|
|
485
856
|
// src/setup.ts
|
|
486
|
-
var
|
|
857
|
+
var import_nestjs_logger3 = require("@lark-apaas/nestjs-logger");
|
|
487
858
|
var import_cookie_parser = __toESM(require("cookie-parser"), 1);
|
|
488
859
|
var import_nestjs_openapi_devtools = require("@lark-apaas/nestjs-openapi-devtools");
|
|
489
860
|
var defaultPerms = {
|
|
490
861
|
disableSwagger: false
|
|
491
862
|
};
|
|
492
863
|
async function configureApp(app, perms = defaultPerms) {
|
|
493
|
-
app.useLogger(app.get(
|
|
864
|
+
app.useLogger(app.get(import_nestjs_logger3.AppLogger));
|
|
494
865
|
app.flushLogs();
|
|
495
866
|
app.use((0, import_cookie_parser.default)());
|
|
496
867
|
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
@@ -512,6 +883,8 @@ __name(configureApp, "configureApp");
|
|
|
512
883
|
var import_nestjs_openapi_devtools2 = require("@lark-apaas/nestjs-openapi-devtools");
|
|
513
884
|
__reExport(index_exports, require("@lark-apaas/nestjs-authnpaas"), module.exports);
|
|
514
885
|
__reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports);
|
|
886
|
+
__reExport(index_exports, require("@lark-apaas/nestjs-observable"), module.exports);
|
|
887
|
+
__reExport(index_exports, require("@lark-apaas/nestjs-trigger"), module.exports);
|
|
515
888
|
// Annotate the CommonJS export names for ESM import in node:
|
|
516
889
|
0 && (module.exports = {
|
|
517
890
|
CsrfMiddleware,
|
|
@@ -523,5 +896,7 @@ __reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports
|
|
|
523
896
|
ViewContextMiddleware,
|
|
524
897
|
configureApp,
|
|
525
898
|
...require("@lark-apaas/nestjs-authnpaas"),
|
|
526
|
-
...require("@lark-apaas/nestjs-datapaas")
|
|
899
|
+
...require("@lark-apaas/nestjs-datapaas"),
|
|
900
|
+
...require("@lark-apaas/nestjs-observable"),
|
|
901
|
+
...require("@lark-apaas/nestjs-trigger")
|
|
527
902
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { NestModule, DynamicModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import { HttpClientConfig, PlatformPluginOptions } from '@lark-apaas/http-client';
|
|
2
3
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
3
4
|
export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
|
|
4
5
|
import { Request, Response, NextFunction } from 'express';
|
|
6
|
+
import { PlatformHttpClient } from '@lark-apaas/nestjs-common';
|
|
5
7
|
export * from '@lark-apaas/nestjs-authnpaas';
|
|
6
8
|
export * from '@lark-apaas/nestjs-datapaas';
|
|
9
|
+
export * from '@lark-apaas/nestjs-observable';
|
|
10
|
+
export * from '@lark-apaas/nestjs-trigger';
|
|
7
11
|
|
|
8
12
|
declare global {
|
|
9
13
|
namespace Express {
|
|
@@ -33,6 +37,13 @@ declare global {
|
|
|
33
37
|
/**
|
|
34
38
|
* PlatformModule 配置选项
|
|
35
39
|
*/
|
|
40
|
+
|
|
41
|
+
interface PlatformHttpClientOptions {
|
|
42
|
+
/** HttpClient 基础配置(超时、headers 等) */
|
|
43
|
+
config?: Omit<HttpClientConfig, 'platform'>;
|
|
44
|
+
/** 平台插件配置(默认启用) */
|
|
45
|
+
platform?: PlatformPluginOptions;
|
|
46
|
+
}
|
|
36
47
|
interface PlatformModuleOptions {
|
|
37
48
|
/**
|
|
38
49
|
* 是否启用 CSRF 保护
|
|
@@ -44,6 +55,10 @@ interface PlatformModuleOptions {
|
|
|
44
55
|
* 默认: '/api/*'
|
|
45
56
|
*/
|
|
46
57
|
csrfRoutes?: string | string[];
|
|
58
|
+
/**
|
|
59
|
+
* 平台 HttpClient 配置
|
|
60
|
+
*/
|
|
61
|
+
httpClient?: PlatformHttpClientOptions;
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
declare class PlatformModule implements NestModule {
|
|
@@ -94,7 +109,11 @@ declare class UserContextMiddleware implements NestMiddleware {
|
|
|
94
109
|
}
|
|
95
110
|
|
|
96
111
|
declare class ViewContextMiddleware implements NestMiddleware {
|
|
97
|
-
|
|
112
|
+
private readonly client;
|
|
113
|
+
private readonly logger;
|
|
114
|
+
constructor(client: PlatformHttpClient);
|
|
115
|
+
private getAppInfo;
|
|
116
|
+
use(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
98
117
|
}
|
|
99
118
|
|
|
100
119
|
/**
|
|
@@ -108,4 +127,4 @@ interface ApiNotFoundResponse {
|
|
|
108
127
|
timestamp: string;
|
|
109
128
|
}
|
|
110
129
|
|
|
111
|
-
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|
|
130
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, type PlatformHttpClientOptions, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|