@lark-apaas/fullstack-nestjs-core 1.1.1-alpha.3 → 1.1.1-alpha.31
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 +179 -26
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +171 -18
- package/package.json +9 -7
package/dist/index.cjs
CHANGED
|
@@ -44,14 +44,14 @@ __export(index_exports, {
|
|
|
44
44
|
module.exports = __toCommonJS(index_exports);
|
|
45
45
|
|
|
46
46
|
// src/modules/platform/module.ts
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var
|
|
47
|
+
var import_common7 = require("@nestjs/common");
|
|
48
|
+
var import_core2 = require("@nestjs/core");
|
|
49
|
+
var import_nestjs_common2 = require("@lark-apaas/nestjs-common");
|
|
50
50
|
var import_config2 = require("@nestjs/config");
|
|
51
|
+
var import_nestjs_observable = require("@lark-apaas/nestjs-observable");
|
|
51
52
|
var import_nestjs_logger = require("@lark-apaas/nestjs-logger");
|
|
52
53
|
var import_nestjs_datapaas = require("@lark-apaas/nestjs-datapaas");
|
|
53
54
|
var import_nestjs_authnpaas = require("@lark-apaas/nestjs-authnpaas");
|
|
54
|
-
var import_nestjs_automation = require("@lark-apaas/nestjs-automation");
|
|
55
55
|
|
|
56
56
|
// src/middlewares/user-context/index.ts
|
|
57
57
|
var import_common = require("@nestjs/common");
|
|
@@ -93,7 +93,12 @@ var UserContextMiddleware = class {
|
|
|
93
93
|
userId: webUser?.user_id,
|
|
94
94
|
tenantId: webUser?.tenant_id,
|
|
95
95
|
appId: webUser?.app_id ?? "",
|
|
96
|
-
loginUrl: webUser?.login_url ?? ""
|
|
96
|
+
loginUrl: webUser?.login_url ?? "",
|
|
97
|
+
userType: webUser?.user_type ?? "",
|
|
98
|
+
env: webUser?.env ?? "runtime",
|
|
99
|
+
userName: webUser?.user_name?.zh_cn ?? "",
|
|
100
|
+
userNameEn: webUser?.user_name?.en_us ?? "",
|
|
101
|
+
userNameI18n: webUser?.user_name ?? {}
|
|
97
102
|
};
|
|
98
103
|
next();
|
|
99
104
|
}
|
|
@@ -246,7 +251,7 @@ var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
|
246
251
|
res.cookie(cookieKey, token, {
|
|
247
252
|
maxAge: cookieMaxAge,
|
|
248
253
|
path: cookiePath,
|
|
249
|
-
httpOnly:
|
|
254
|
+
httpOnly: false,
|
|
250
255
|
secure: true,
|
|
251
256
|
sameSite: "none",
|
|
252
257
|
partitioned: true
|
|
@@ -259,6 +264,80 @@ CsrfTokenMiddleware = _ts_decorate4([
|
|
|
259
264
|
(0, import_common4.Injectable)()
|
|
260
265
|
], CsrfTokenMiddleware);
|
|
261
266
|
|
|
267
|
+
// src/middlewares/api-fallback/index.ts
|
|
268
|
+
function createApiNotFoundResponse(req) {
|
|
269
|
+
return {
|
|
270
|
+
code: 404,
|
|
271
|
+
message: `Cannot ${req.method} ${req.path}`,
|
|
272
|
+
error: "Not Found",
|
|
273
|
+
path: req.path,
|
|
274
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
__name(createApiNotFoundResponse, "createApiNotFoundResponse");
|
|
278
|
+
function getApiPathPrefix() {
|
|
279
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
280
|
+
if (!globalPrefix) {
|
|
281
|
+
return "/api/";
|
|
282
|
+
}
|
|
283
|
+
const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
|
|
284
|
+
return `${normalizedPrefix}/api/`;
|
|
285
|
+
}
|
|
286
|
+
__name(getApiPathPrefix, "getApiPathPrefix");
|
|
287
|
+
function apiResponseInterceptor(req, res, next) {
|
|
288
|
+
const apiPrefix = getApiPathPrefix();
|
|
289
|
+
if (!req.baseUrl.startsWith(apiPrefix)) {
|
|
290
|
+
return next();
|
|
291
|
+
}
|
|
292
|
+
res.render = function() {
|
|
293
|
+
return res.status(404).json(createApiNotFoundResponse(req));
|
|
294
|
+
};
|
|
295
|
+
next();
|
|
296
|
+
}
|
|
297
|
+
__name(apiResponseInterceptor, "apiResponseInterceptor");
|
|
298
|
+
|
|
299
|
+
// src/middlewares/request-context/index.ts
|
|
300
|
+
var import_common5 = require("@nestjs/common");
|
|
301
|
+
var import_nestjs_common = require("@lark-apaas/nestjs-common");
|
|
302
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
303
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
304
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
305
|
+
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;
|
|
306
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
307
|
+
}
|
|
308
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
309
|
+
function _ts_metadata(k, v) {
|
|
310
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
311
|
+
}
|
|
312
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
313
|
+
var RequestContextMiddleware = class {
|
|
314
|
+
static {
|
|
315
|
+
__name(this, "RequestContextMiddleware");
|
|
316
|
+
}
|
|
317
|
+
requestContext;
|
|
318
|
+
constructor(requestContext) {
|
|
319
|
+
this.requestContext = requestContext;
|
|
320
|
+
}
|
|
321
|
+
use(req, _res, next) {
|
|
322
|
+
const path = req.originalUrl ?? req.url;
|
|
323
|
+
const userContext = req.userContext ?? {};
|
|
324
|
+
this.requestContext.run({
|
|
325
|
+
path,
|
|
326
|
+
method: req.method,
|
|
327
|
+
userId: userContext.userId,
|
|
328
|
+
tenantId: userContext.tenantId,
|
|
329
|
+
appId: userContext.appId
|
|
330
|
+
}, () => next());
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
RequestContextMiddleware = _ts_decorate5([
|
|
334
|
+
(0, import_common5.Injectable)(),
|
|
335
|
+
_ts_metadata("design:type", Function),
|
|
336
|
+
_ts_metadata("design:paramtypes", [
|
|
337
|
+
typeof import_nestjs_common.RequestContextService === "undefined" ? Object : import_nestjs_common.RequestContextService
|
|
338
|
+
])
|
|
339
|
+
], RequestContextMiddleware);
|
|
340
|
+
|
|
262
341
|
// src/modules/platform/config/app.config.ts
|
|
263
342
|
var import_config = require("@nestjs/config");
|
|
264
343
|
var NAMESPACE = "app";
|
|
@@ -271,14 +350,83 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
|
|
|
271
350
|
};
|
|
272
351
|
});
|
|
273
352
|
|
|
353
|
+
// src/middlewares/debug/index.ts
|
|
354
|
+
var import_common6 = require("@nestjs/common");
|
|
355
|
+
var import_core = require("@nestjs/core");
|
|
356
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
357
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
358
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
359
|
+
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;
|
|
360
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
361
|
+
}
|
|
362
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
363
|
+
function _ts_metadata2(k, v) {
|
|
364
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
365
|
+
}
|
|
366
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
367
|
+
var processStartTimestamp = Date.now();
|
|
368
|
+
var FrameworkDebugMiddleware = class {
|
|
369
|
+
static {
|
|
370
|
+
__name(this, "FrameworkDebugMiddleware");
|
|
371
|
+
}
|
|
372
|
+
httpAdapterHost;
|
|
373
|
+
constructor(httpAdapterHost) {
|
|
374
|
+
this.httpAdapterHost = httpAdapterHost;
|
|
375
|
+
}
|
|
376
|
+
use(_req, res) {
|
|
377
|
+
res.json(this.getDebugInfo());
|
|
378
|
+
}
|
|
379
|
+
getDebugInfo() {
|
|
380
|
+
const routes = this.getRoutes();
|
|
381
|
+
const uptimeSeconds = Math.floor(process.uptime());
|
|
382
|
+
return {
|
|
383
|
+
["\u8DEF\u7531\u914D\u7F6E"]: routes,
|
|
384
|
+
["\u8FDB\u7A0B\u5B58\u6D3B\u65F6\u95F4\uFF08\u79D2\uFF09"]: uptimeSeconds,
|
|
385
|
+
["\u8FDB\u7A0B\u542F\u52A8\u65F6\u95F4\uFF08\u79D2\uFF09"]: new Date(processStartTimestamp).toISOString(),
|
|
386
|
+
["\u8FD0\u884C\u65F6\u7248\u672C"]: process.versions
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
getRoutes() {
|
|
390
|
+
const server = this.httpAdapterHost.httpAdapter;
|
|
391
|
+
const router = server.getInstance()._router;
|
|
392
|
+
if (!router) {
|
|
393
|
+
return {
|
|
394
|
+
error: "Router \u4E0D\u53EF\u7528"
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
const routes = [];
|
|
398
|
+
router.stack.forEach((middleware, index) => {
|
|
399
|
+
if (middleware.route) {
|
|
400
|
+
routes.push({
|
|
401
|
+
order: String(index),
|
|
402
|
+
path: middleware.route.path,
|
|
403
|
+
method: middleware.method,
|
|
404
|
+
regexp: middleware.regexp?.toString()
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
return {
|
|
409
|
+
total: routes.length,
|
|
410
|
+
routes
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
FrameworkDebugMiddleware = _ts_decorate6([
|
|
415
|
+
(0, import_common6.Injectable)(),
|
|
416
|
+
_ts_metadata2("design:type", Function),
|
|
417
|
+
_ts_metadata2("design:paramtypes", [
|
|
418
|
+
typeof import_core.HttpAdapterHost === "undefined" ? Object : import_core.HttpAdapterHost
|
|
419
|
+
])
|
|
420
|
+
], FrameworkDebugMiddleware);
|
|
421
|
+
|
|
274
422
|
// src/modules/platform/module.ts
|
|
275
|
-
function
|
|
423
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
276
424
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
277
425
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
278
426
|
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;
|
|
279
427
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
280
428
|
}
|
|
281
|
-
__name(
|
|
429
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
282
430
|
var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
|
|
283
431
|
var PlatformModule = class _PlatformModule {
|
|
284
432
|
static {
|
|
@@ -300,7 +448,8 @@ var PlatformModule = class _PlatformModule {
|
|
|
300
448
|
app_config_default
|
|
301
449
|
]
|
|
302
450
|
}),
|
|
303
|
-
|
|
451
|
+
import_nestjs_common2.CommonModule,
|
|
452
|
+
import_nestjs_observable.NestjsObservableModule,
|
|
304
453
|
import_nestjs_logger.LoggerModule,
|
|
305
454
|
import_nestjs_datapaas.DataPaasModule.forRootAsync({
|
|
306
455
|
imports: [
|
|
@@ -316,10 +465,10 @@ var PlatformModule = class _PlatformModule {
|
|
|
316
465
|
const appLogger = args[1];
|
|
317
466
|
const drizzleLogger = {
|
|
318
467
|
logQuery(query, params) {
|
|
319
|
-
appLogger.log?.("SQL Query"
|
|
468
|
+
appLogger.log?.("SQL Query " + JSON.stringify({
|
|
320
469
|
query,
|
|
321
470
|
params
|
|
322
|
-
}, "Database");
|
|
471
|
+
}), "Database");
|
|
323
472
|
}
|
|
324
473
|
};
|
|
325
474
|
return {
|
|
@@ -328,12 +477,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
328
477
|
};
|
|
329
478
|
}, "useFactory")
|
|
330
479
|
}),
|
|
331
|
-
import_nestjs_authnpaas.AuthNPaasModule.forRoot()
|
|
332
|
-
import_nestjs_automation.AutomationModule.forRoot({
|
|
333
|
-
imports: [
|
|
334
|
-
import_nestjs_logger.LoggerModule
|
|
335
|
-
]
|
|
336
|
-
})
|
|
480
|
+
import_nestjs_authnpaas.AuthNPaasModule.forRoot()
|
|
337
481
|
],
|
|
338
482
|
providers: [
|
|
339
483
|
{
|
|
@@ -341,18 +485,23 @@ var PlatformModule = class _PlatformModule {
|
|
|
341
485
|
useValue: options
|
|
342
486
|
},
|
|
343
487
|
{
|
|
344
|
-
provide:
|
|
345
|
-
useValue: new
|
|
488
|
+
provide: import_core2.APP_PIPE,
|
|
489
|
+
useValue: new import_common7.ValidationPipe({
|
|
346
490
|
transform: true,
|
|
347
491
|
transformOptions: {
|
|
348
492
|
enableImplicitConversion: true
|
|
349
493
|
}
|
|
350
494
|
})
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
provide: import_nestjs_common2.OBSERVABLE_SERVICE_TOKEN,
|
|
498
|
+
useClass: import_nestjs_observable.Observable
|
|
351
499
|
}
|
|
352
500
|
],
|
|
353
501
|
exports: [
|
|
354
502
|
import_config2.ConfigModule,
|
|
355
|
-
import_nestjs_logger.LoggerModule
|
|
503
|
+
import_nestjs_logger.LoggerModule,
|
|
504
|
+
import_nestjs_common2.OBSERVABLE_SERVICE_TOKEN
|
|
356
505
|
]
|
|
357
506
|
};
|
|
358
507
|
}
|
|
@@ -361,7 +510,11 @@ var PlatformModule = class _PlatformModule {
|
|
|
361
510
|
*/
|
|
362
511
|
configure(consumer) {
|
|
363
512
|
const options = _PlatformModule.moduleOptions;
|
|
364
|
-
consumer.apply(
|
|
513
|
+
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
514
|
+
if (process.env.NODE_ENV === "development") {
|
|
515
|
+
consumer.apply(FrameworkDebugMiddleware).forRoutes("/api/__framework__/debug");
|
|
516
|
+
}
|
|
517
|
+
consumer.apply(UserContextMiddleware, RequestContextMiddleware, import_nestjs_logger.LoggerContextMiddleware, import_nestjs_datapaas.SqlExecutionContextMiddleware).forRoutes("/*");
|
|
365
518
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
366
519
|
if (options.enableCsrf !== false) {
|
|
367
520
|
const csrfRoutes = options.csrfRoutes || "/api/*";
|
|
@@ -375,9 +528,9 @@ var PlatformModule = class _PlatformModule {
|
|
|
375
528
|
}
|
|
376
529
|
}
|
|
377
530
|
};
|
|
378
|
-
PlatformModule =
|
|
379
|
-
(0,
|
|
380
|
-
(0,
|
|
531
|
+
PlatformModule = _ts_decorate7([
|
|
532
|
+
(0, import_common7.Global)(),
|
|
533
|
+
(0, import_common7.Module)({})
|
|
381
534
|
], PlatformModule);
|
|
382
535
|
|
|
383
536
|
// src/setup.ts
|
|
@@ -410,7 +563,7 @@ __name(configureApp, "configureApp");
|
|
|
410
563
|
var import_nestjs_openapi_devtools2 = require("@lark-apaas/nestjs-openapi-devtools");
|
|
411
564
|
__reExport(index_exports, require("@lark-apaas/nestjs-authnpaas"), module.exports);
|
|
412
565
|
__reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports);
|
|
413
|
-
__reExport(index_exports, require("@lark-apaas/nestjs-
|
|
566
|
+
__reExport(index_exports, require("@lark-apaas/nestjs-observable"), module.exports);
|
|
414
567
|
// Annotate the CommonJS export names for ESM import in node:
|
|
415
568
|
0 && (module.exports = {
|
|
416
569
|
CsrfMiddleware,
|
|
@@ -423,5 +576,5 @@ __reExport(index_exports, require("@lark-apaas/nestjs-automation"), module.expor
|
|
|
423
576
|
configureApp,
|
|
424
577
|
...require("@lark-apaas/nestjs-authnpaas"),
|
|
425
578
|
...require("@lark-apaas/nestjs-datapaas"),
|
|
426
|
-
...require("@lark-apaas/nestjs-
|
|
579
|
+
...require("@lark-apaas/nestjs-observable")
|
|
427
580
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options }
|
|
|
4
4
|
import { Request, Response, NextFunction } from 'express';
|
|
5
5
|
export * from '@lark-apaas/nestjs-authnpaas';
|
|
6
6
|
export * from '@lark-apaas/nestjs-datapaas';
|
|
7
|
-
export * from '@lark-apaas/nestjs-
|
|
7
|
+
export * from '@lark-apaas/nestjs-observable';
|
|
8
8
|
|
|
9
9
|
declare global {
|
|
10
10
|
namespace Express {
|
|
@@ -20,6 +20,11 @@ declare global {
|
|
|
20
20
|
tenantId?: number;
|
|
21
21
|
appId?: string;
|
|
22
22
|
loginUrl?: string;
|
|
23
|
+
userType?: string;
|
|
24
|
+
env?: 'preview' | 'runtime';
|
|
25
|
+
userName?: string; // 默认中文名
|
|
26
|
+
userNameEn?: string; // 冗余一份英文名
|
|
27
|
+
userNameI18n?: Record<string, string>; // 带多语的用户名
|
|
23
28
|
},
|
|
24
29
|
csrfToken?: string;
|
|
25
30
|
}
|
|
@@ -93,4 +98,15 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
93
98
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
|
|
101
|
+
/**
|
|
102
|
+
* API 404 响应格式
|
|
103
|
+
*/
|
|
104
|
+
interface ApiNotFoundResponse {
|
|
105
|
+
code: number;
|
|
106
|
+
message: string;
|
|
107
|
+
error: string;
|
|
108
|
+
path: string;
|
|
109
|
+
timestamp: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options }
|
|
|
4
4
|
import { Request, Response, NextFunction } from 'express';
|
|
5
5
|
export * from '@lark-apaas/nestjs-authnpaas';
|
|
6
6
|
export * from '@lark-apaas/nestjs-datapaas';
|
|
7
|
-
export * from '@lark-apaas/nestjs-
|
|
7
|
+
export * from '@lark-apaas/nestjs-observable';
|
|
8
8
|
|
|
9
9
|
declare global {
|
|
10
10
|
namespace Express {
|
|
@@ -20,6 +20,11 @@ declare global {
|
|
|
20
20
|
tenantId?: number;
|
|
21
21
|
appId?: string;
|
|
22
22
|
loginUrl?: string;
|
|
23
|
+
userType?: string;
|
|
24
|
+
env?: 'preview' | 'runtime';
|
|
25
|
+
userName?: string; // 默认中文名
|
|
26
|
+
userNameEn?: string; // 冗余一份英文名
|
|
27
|
+
userNameI18n?: Record<string, string>; // 带多语的用户名
|
|
23
28
|
},
|
|
24
29
|
csrfToken?: string;
|
|
25
30
|
}
|
|
@@ -93,4 +98,15 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
93
98
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
|
|
101
|
+
/**
|
|
102
|
+
* API 404 响应格式
|
|
103
|
+
*/
|
|
104
|
+
interface ApiNotFoundResponse {
|
|
105
|
+
code: number;
|
|
106
|
+
message: string;
|
|
107
|
+
error: string;
|
|
108
|
+
path: string;
|
|
109
|
+
timestamp: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,12 @@ 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_PIPE } from "@nestjs/core";
|
|
7
|
-
import { CommonModule } from "@lark-apaas/nestjs-common";
|
|
7
|
+
import { CommonModule, OBSERVABLE_SERVICE_TOKEN } from "@lark-apaas/nestjs-common";
|
|
8
8
|
import { ConfigModule, ConfigService } from "@nestjs/config";
|
|
9
|
+
import { NestjsObservableModule as ObservableModule, Observable } from "@lark-apaas/nestjs-observable";
|
|
9
10
|
import { LoggerModule, AppLogger, LoggerContextMiddleware } from "@lark-apaas/nestjs-logger";
|
|
10
11
|
import { DataPaasModule, SqlExecutionContextMiddleware } from "@lark-apaas/nestjs-datapaas";
|
|
11
12
|
import { AuthNPaasModule } from "@lark-apaas/nestjs-authnpaas";
|
|
12
|
-
import { AutomationModule } from "@lark-apaas/nestjs-automation";
|
|
13
13
|
|
|
14
14
|
// src/middlewares/user-context/index.ts
|
|
15
15
|
import { Injectable } from "@nestjs/common";
|
|
@@ -51,7 +51,12 @@ var UserContextMiddleware = class {
|
|
|
51
51
|
userId: webUser?.user_id,
|
|
52
52
|
tenantId: webUser?.tenant_id,
|
|
53
53
|
appId: webUser?.app_id ?? "",
|
|
54
|
-
loginUrl: webUser?.login_url ?? ""
|
|
54
|
+
loginUrl: webUser?.login_url ?? "",
|
|
55
|
+
userType: webUser?.user_type ?? "",
|
|
56
|
+
env: webUser?.env ?? "runtime",
|
|
57
|
+
userName: webUser?.user_name?.zh_cn ?? "",
|
|
58
|
+
userNameEn: webUser?.user_name?.en_us ?? "",
|
|
59
|
+
userNameI18n: webUser?.user_name ?? {}
|
|
55
60
|
};
|
|
56
61
|
next();
|
|
57
62
|
}
|
|
@@ -204,7 +209,7 @@ var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
|
204
209
|
res.cookie(cookieKey, token, {
|
|
205
210
|
maxAge: cookieMaxAge,
|
|
206
211
|
path: cookiePath,
|
|
207
|
-
httpOnly:
|
|
212
|
+
httpOnly: false,
|
|
208
213
|
secure: true,
|
|
209
214
|
sameSite: "none",
|
|
210
215
|
partitioned: true
|
|
@@ -217,6 +222,80 @@ CsrfTokenMiddleware = _ts_decorate4([
|
|
|
217
222
|
Injectable4()
|
|
218
223
|
], CsrfTokenMiddleware);
|
|
219
224
|
|
|
225
|
+
// src/middlewares/api-fallback/index.ts
|
|
226
|
+
function createApiNotFoundResponse(req) {
|
|
227
|
+
return {
|
|
228
|
+
code: 404,
|
|
229
|
+
message: `Cannot ${req.method} ${req.path}`,
|
|
230
|
+
error: "Not Found",
|
|
231
|
+
path: req.path,
|
|
232
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
__name(createApiNotFoundResponse, "createApiNotFoundResponse");
|
|
236
|
+
function getApiPathPrefix() {
|
|
237
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
238
|
+
if (!globalPrefix) {
|
|
239
|
+
return "/api/";
|
|
240
|
+
}
|
|
241
|
+
const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
|
|
242
|
+
return `${normalizedPrefix}/api/`;
|
|
243
|
+
}
|
|
244
|
+
__name(getApiPathPrefix, "getApiPathPrefix");
|
|
245
|
+
function apiResponseInterceptor(req, res, next) {
|
|
246
|
+
const apiPrefix = getApiPathPrefix();
|
|
247
|
+
if (!req.baseUrl.startsWith(apiPrefix)) {
|
|
248
|
+
return next();
|
|
249
|
+
}
|
|
250
|
+
res.render = function() {
|
|
251
|
+
return res.status(404).json(createApiNotFoundResponse(req));
|
|
252
|
+
};
|
|
253
|
+
next();
|
|
254
|
+
}
|
|
255
|
+
__name(apiResponseInterceptor, "apiResponseInterceptor");
|
|
256
|
+
|
|
257
|
+
// src/middlewares/request-context/index.ts
|
|
258
|
+
import { Injectable as Injectable5 } from "@nestjs/common";
|
|
259
|
+
import { RequestContextService } from "@lark-apaas/nestjs-common";
|
|
260
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
261
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
262
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
263
|
+
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;
|
|
264
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
265
|
+
}
|
|
266
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
267
|
+
function _ts_metadata(k, v) {
|
|
268
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
269
|
+
}
|
|
270
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
271
|
+
var RequestContextMiddleware = class {
|
|
272
|
+
static {
|
|
273
|
+
__name(this, "RequestContextMiddleware");
|
|
274
|
+
}
|
|
275
|
+
requestContext;
|
|
276
|
+
constructor(requestContext) {
|
|
277
|
+
this.requestContext = requestContext;
|
|
278
|
+
}
|
|
279
|
+
use(req, _res, next) {
|
|
280
|
+
const path = req.originalUrl ?? req.url;
|
|
281
|
+
const userContext = req.userContext ?? {};
|
|
282
|
+
this.requestContext.run({
|
|
283
|
+
path,
|
|
284
|
+
method: req.method,
|
|
285
|
+
userId: userContext.userId,
|
|
286
|
+
tenantId: userContext.tenantId,
|
|
287
|
+
appId: userContext.appId
|
|
288
|
+
}, () => next());
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
RequestContextMiddleware = _ts_decorate5([
|
|
292
|
+
Injectable5(),
|
|
293
|
+
_ts_metadata("design:type", Function),
|
|
294
|
+
_ts_metadata("design:paramtypes", [
|
|
295
|
+
typeof RequestContextService === "undefined" ? Object : RequestContextService
|
|
296
|
+
])
|
|
297
|
+
], RequestContextMiddleware);
|
|
298
|
+
|
|
220
299
|
// src/modules/platform/config/app.config.ts
|
|
221
300
|
import { registerAs } from "@nestjs/config";
|
|
222
301
|
var NAMESPACE = "app";
|
|
@@ -229,14 +308,83 @@ var app_config_default = registerAs(NAMESPACE, () => {
|
|
|
229
308
|
};
|
|
230
309
|
});
|
|
231
310
|
|
|
311
|
+
// src/middlewares/debug/index.ts
|
|
312
|
+
import { Injectable as Injectable6 } from "@nestjs/common";
|
|
313
|
+
import { HttpAdapterHost } from "@nestjs/core";
|
|
314
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
315
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
316
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
317
|
+
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;
|
|
318
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
319
|
+
}
|
|
320
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
321
|
+
function _ts_metadata2(k, v) {
|
|
322
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
323
|
+
}
|
|
324
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
325
|
+
var processStartTimestamp = Date.now();
|
|
326
|
+
var FrameworkDebugMiddleware = class {
|
|
327
|
+
static {
|
|
328
|
+
__name(this, "FrameworkDebugMiddleware");
|
|
329
|
+
}
|
|
330
|
+
httpAdapterHost;
|
|
331
|
+
constructor(httpAdapterHost) {
|
|
332
|
+
this.httpAdapterHost = httpAdapterHost;
|
|
333
|
+
}
|
|
334
|
+
use(_req, res) {
|
|
335
|
+
res.json(this.getDebugInfo());
|
|
336
|
+
}
|
|
337
|
+
getDebugInfo() {
|
|
338
|
+
const routes = this.getRoutes();
|
|
339
|
+
const uptimeSeconds = Math.floor(process.uptime());
|
|
340
|
+
return {
|
|
341
|
+
["\u8DEF\u7531\u914D\u7F6E"]: routes,
|
|
342
|
+
["\u8FDB\u7A0B\u5B58\u6D3B\u65F6\u95F4\uFF08\u79D2\uFF09"]: uptimeSeconds,
|
|
343
|
+
["\u8FDB\u7A0B\u542F\u52A8\u65F6\u95F4\uFF08\u79D2\uFF09"]: new Date(processStartTimestamp).toISOString(),
|
|
344
|
+
["\u8FD0\u884C\u65F6\u7248\u672C"]: process.versions
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
getRoutes() {
|
|
348
|
+
const server = this.httpAdapterHost.httpAdapter;
|
|
349
|
+
const router = server.getInstance()._router;
|
|
350
|
+
if (!router) {
|
|
351
|
+
return {
|
|
352
|
+
error: "Router \u4E0D\u53EF\u7528"
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
const routes = [];
|
|
356
|
+
router.stack.forEach((middleware, index) => {
|
|
357
|
+
if (middleware.route) {
|
|
358
|
+
routes.push({
|
|
359
|
+
order: String(index),
|
|
360
|
+
path: middleware.route.path,
|
|
361
|
+
method: middleware.method,
|
|
362
|
+
regexp: middleware.regexp?.toString()
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
total: routes.length,
|
|
368
|
+
routes
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
FrameworkDebugMiddleware = _ts_decorate6([
|
|
373
|
+
Injectable6(),
|
|
374
|
+
_ts_metadata2("design:type", Function),
|
|
375
|
+
_ts_metadata2("design:paramtypes", [
|
|
376
|
+
typeof HttpAdapterHost === "undefined" ? Object : HttpAdapterHost
|
|
377
|
+
])
|
|
378
|
+
], FrameworkDebugMiddleware);
|
|
379
|
+
|
|
232
380
|
// src/modules/platform/module.ts
|
|
233
|
-
function
|
|
381
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
234
382
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
235
383
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
236
384
|
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;
|
|
237
385
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
238
386
|
}
|
|
239
|
-
__name(
|
|
387
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
240
388
|
var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
|
|
241
389
|
var PlatformModule = class _PlatformModule {
|
|
242
390
|
static {
|
|
@@ -259,6 +407,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
259
407
|
]
|
|
260
408
|
}),
|
|
261
409
|
CommonModule,
|
|
410
|
+
ObservableModule,
|
|
262
411
|
LoggerModule,
|
|
263
412
|
DataPaasModule.forRootAsync({
|
|
264
413
|
imports: [
|
|
@@ -274,10 +423,10 @@ var PlatformModule = class _PlatformModule {
|
|
|
274
423
|
const appLogger = args[1];
|
|
275
424
|
const drizzleLogger = {
|
|
276
425
|
logQuery(query, params) {
|
|
277
|
-
appLogger.log?.("SQL Query"
|
|
426
|
+
appLogger.log?.("SQL Query " + JSON.stringify({
|
|
278
427
|
query,
|
|
279
428
|
params
|
|
280
|
-
}, "Database");
|
|
429
|
+
}), "Database");
|
|
281
430
|
}
|
|
282
431
|
};
|
|
283
432
|
return {
|
|
@@ -286,12 +435,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
286
435
|
};
|
|
287
436
|
}, "useFactory")
|
|
288
437
|
}),
|
|
289
|
-
AuthNPaasModule.forRoot()
|
|
290
|
-
AutomationModule.forRoot({
|
|
291
|
-
imports: [
|
|
292
|
-
LoggerModule
|
|
293
|
-
]
|
|
294
|
-
})
|
|
438
|
+
AuthNPaasModule.forRoot()
|
|
295
439
|
],
|
|
296
440
|
providers: [
|
|
297
441
|
{
|
|
@@ -306,11 +450,16 @@ var PlatformModule = class _PlatformModule {
|
|
|
306
450
|
enableImplicitConversion: true
|
|
307
451
|
}
|
|
308
452
|
})
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
provide: OBSERVABLE_SERVICE_TOKEN,
|
|
456
|
+
useClass: Observable
|
|
309
457
|
}
|
|
310
458
|
],
|
|
311
459
|
exports: [
|
|
312
460
|
ConfigModule,
|
|
313
|
-
LoggerModule
|
|
461
|
+
LoggerModule,
|
|
462
|
+
OBSERVABLE_SERVICE_TOKEN
|
|
314
463
|
]
|
|
315
464
|
};
|
|
316
465
|
}
|
|
@@ -319,7 +468,11 @@ var PlatformModule = class _PlatformModule {
|
|
|
319
468
|
*/
|
|
320
469
|
configure(consumer) {
|
|
321
470
|
const options = _PlatformModule.moduleOptions;
|
|
322
|
-
consumer.apply(
|
|
471
|
+
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
472
|
+
if (process.env.NODE_ENV === "development") {
|
|
473
|
+
consumer.apply(FrameworkDebugMiddleware).forRoutes("/api/__framework__/debug");
|
|
474
|
+
}
|
|
475
|
+
consumer.apply(UserContextMiddleware, RequestContextMiddleware, LoggerContextMiddleware, SqlExecutionContextMiddleware).forRoutes("/*");
|
|
323
476
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
324
477
|
if (options.enableCsrf !== false) {
|
|
325
478
|
const csrfRoutes = options.csrfRoutes || "/api/*";
|
|
@@ -333,7 +486,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
333
486
|
}
|
|
334
487
|
}
|
|
335
488
|
};
|
|
336
|
-
PlatformModule =
|
|
489
|
+
PlatformModule = _ts_decorate7([
|
|
337
490
|
Global(),
|
|
338
491
|
Module({})
|
|
339
492
|
], PlatformModule);
|
|
@@ -368,7 +521,7 @@ __name(configureApp, "configureApp");
|
|
|
368
521
|
import { DevToolsModule, DevToolsV2Module as DevToolsV2Module2 } from "@lark-apaas/nestjs-openapi-devtools";
|
|
369
522
|
export * from "@lark-apaas/nestjs-authnpaas";
|
|
370
523
|
export * from "@lark-apaas/nestjs-datapaas";
|
|
371
|
-
export * from "@lark-apaas/nestjs-
|
|
524
|
+
export * from "@lark-apaas/nestjs-observable";
|
|
372
525
|
export {
|
|
373
526
|
CsrfMiddleware,
|
|
374
527
|
CsrfTokenMiddleware,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-nestjs-core",
|
|
3
|
-
"version": "1.1.1-alpha.
|
|
3
|
+
"version": "1.1.1-alpha.31",
|
|
4
4
|
"description": "FullStack Nestjs Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,15 +35,16 @@
|
|
|
35
35
|
"test": "vitest run",
|
|
36
36
|
"test:watch": "vitest",
|
|
37
37
|
"lint": "echo 'ESLint skipped for TypeScript files'",
|
|
38
|
-
"lint:fix": "eslint src --ext .ts --fix"
|
|
38
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
39
|
+
"prepublishOnly": "npm run build"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@lark-apaas/nestjs-authnpaas": "^1.0.
|
|
42
|
-
"@lark-apaas/nestjs-
|
|
43
|
-
"@lark-apaas/nestjs-common": "0.0.1-alpha.1",
|
|
42
|
+
"@lark-apaas/nestjs-authnpaas": "^1.0.2",
|
|
43
|
+
"@lark-apaas/nestjs-common": "0.0.1-alpha.4",
|
|
44
44
|
"@lark-apaas/nestjs-datapaas": "^1.0.5",
|
|
45
|
-
"@lark-apaas/nestjs-logger": "1.0.2-alpha.
|
|
46
|
-
"@lark-apaas/nestjs-
|
|
45
|
+
"@lark-apaas/nestjs-logger": "1.0.2-alpha.25",
|
|
46
|
+
"@lark-apaas/nestjs-observable": "0.0.1-alpha.25",
|
|
47
|
+
"@lark-apaas/nestjs-openapi-devtools": "^1.0.9",
|
|
47
48
|
"cookie-parser": "^1.4.7"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|
|
62
63
|
"@nestjs/common": "^10.4.20",
|
|
64
|
+
"@nestjs/core": "^10.4.20",
|
|
63
65
|
"@nestjs/platform-express": "^10.4.20",
|
|
64
66
|
"@nestjs/swagger": "^7.4.2",
|
|
65
67
|
"class-transformer": "^0.5.1",
|