@lark-apaas/fullstack-nestjs-core 1.1.1-alpha.2 → 1.1.1-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 +105 -24
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +99 -18
- package/package.json +7 -6
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
|
|
47
|
+
var import_common6 = require("@nestjs/common");
|
|
48
48
|
var import_core = require("@nestjs/core");
|
|
49
|
-
var
|
|
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";
|
|
@@ -272,13 +351,13 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
|
|
|
272
351
|
});
|
|
273
352
|
|
|
274
353
|
// src/modules/platform/module.ts
|
|
275
|
-
function
|
|
354
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
276
355
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
277
356
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
278
357
|
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
358
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
280
359
|
}
|
|
281
|
-
__name(
|
|
360
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
282
361
|
var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
|
|
283
362
|
var PlatformModule = class _PlatformModule {
|
|
284
363
|
static {
|
|
@@ -300,7 +379,8 @@ var PlatformModule = class _PlatformModule {
|
|
|
300
379
|
app_config_default
|
|
301
380
|
]
|
|
302
381
|
}),
|
|
303
|
-
|
|
382
|
+
import_nestjs_common2.CommonModule,
|
|
383
|
+
import_nestjs_observable.NestjsObservableModule.forRoot(),
|
|
304
384
|
import_nestjs_logger.LoggerModule,
|
|
305
385
|
import_nestjs_datapaas.DataPaasModule.forRootAsync({
|
|
306
386
|
imports: [
|
|
@@ -316,10 +396,10 @@ var PlatformModule = class _PlatformModule {
|
|
|
316
396
|
const appLogger = args[1];
|
|
317
397
|
const drizzleLogger = {
|
|
318
398
|
logQuery(query, params) {
|
|
319
|
-
appLogger.log?.("SQL Query"
|
|
399
|
+
appLogger.log?.("SQL Query " + JSON.stringify({
|
|
320
400
|
query,
|
|
321
401
|
params
|
|
322
|
-
}, "Database");
|
|
402
|
+
}), "Database");
|
|
323
403
|
}
|
|
324
404
|
};
|
|
325
405
|
return {
|
|
@@ -328,12 +408,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
328
408
|
};
|
|
329
409
|
}, "useFactory")
|
|
330
410
|
}),
|
|
331
|
-
import_nestjs_authnpaas.AuthNPaasModule.forRoot()
|
|
332
|
-
import_nestjs_automation.AutomationModule.forRoot({
|
|
333
|
-
imports: [
|
|
334
|
-
import_nestjs_logger.LoggerModule
|
|
335
|
-
]
|
|
336
|
-
})
|
|
411
|
+
import_nestjs_authnpaas.AuthNPaasModule.forRoot()
|
|
337
412
|
],
|
|
338
413
|
providers: [
|
|
339
414
|
{
|
|
@@ -342,17 +417,22 @@ var PlatformModule = class _PlatformModule {
|
|
|
342
417
|
},
|
|
343
418
|
{
|
|
344
419
|
provide: import_core.APP_PIPE,
|
|
345
|
-
useValue: new
|
|
420
|
+
useValue: new import_common6.ValidationPipe({
|
|
346
421
|
transform: true,
|
|
347
422
|
transformOptions: {
|
|
348
423
|
enableImplicitConversion: true
|
|
349
424
|
}
|
|
350
425
|
})
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
provide: import_nestjs_common2.OBSERVABLE_SERVICE_TOKEN,
|
|
429
|
+
useClass: import_nestjs_observable.ObservableService
|
|
351
430
|
}
|
|
352
431
|
],
|
|
353
432
|
exports: [
|
|
354
433
|
import_config2.ConfigModule,
|
|
355
|
-
import_nestjs_logger.LoggerModule
|
|
434
|
+
import_nestjs_logger.LoggerModule,
|
|
435
|
+
import_nestjs_common2.OBSERVABLE_SERVICE_TOKEN
|
|
356
436
|
]
|
|
357
437
|
};
|
|
358
438
|
}
|
|
@@ -361,7 +441,8 @@ var PlatformModule = class _PlatformModule {
|
|
|
361
441
|
*/
|
|
362
442
|
configure(consumer) {
|
|
363
443
|
const options = _PlatformModule.moduleOptions;
|
|
364
|
-
consumer.apply(
|
|
444
|
+
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
445
|
+
consumer.apply(UserContextMiddleware, RequestContextMiddleware, import_nestjs_logger.LoggerContextMiddleware, import_nestjs_observable.ObservableTraceMiddleware, import_nestjs_datapaas.SqlExecutionContextMiddleware).forRoutes("/*");
|
|
365
446
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
366
447
|
if (options.enableCsrf !== false) {
|
|
367
448
|
const csrfRoutes = options.csrfRoutes || "/api/*";
|
|
@@ -375,9 +456,9 @@ var PlatformModule = class _PlatformModule {
|
|
|
375
456
|
}
|
|
376
457
|
}
|
|
377
458
|
};
|
|
378
|
-
PlatformModule =
|
|
379
|
-
(0,
|
|
380
|
-
(0,
|
|
459
|
+
PlatformModule = _ts_decorate6([
|
|
460
|
+
(0, import_common6.Global)(),
|
|
461
|
+
(0, import_common6.Module)({})
|
|
381
462
|
], PlatformModule);
|
|
382
463
|
|
|
383
464
|
// src/setup.ts
|
|
@@ -410,7 +491,7 @@ __name(configureApp, "configureApp");
|
|
|
410
491
|
var import_nestjs_openapi_devtools2 = require("@lark-apaas/nestjs-openapi-devtools");
|
|
411
492
|
__reExport(index_exports, require("@lark-apaas/nestjs-authnpaas"), module.exports);
|
|
412
493
|
__reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports);
|
|
413
|
-
__reExport(index_exports, require("@lark-apaas/nestjs-
|
|
494
|
+
__reExport(index_exports, require("@lark-apaas/nestjs-observable"), module.exports);
|
|
414
495
|
// Annotate the CommonJS export names for ESM import in node:
|
|
415
496
|
0 && (module.exports = {
|
|
416
497
|
CsrfMiddleware,
|
|
@@ -423,5 +504,5 @@ __reExport(index_exports, require("@lark-apaas/nestjs-automation"), module.expor
|
|
|
423
504
|
configureApp,
|
|
424
505
|
...require("@lark-apaas/nestjs-authnpaas"),
|
|
425
506
|
...require("@lark-apaas/nestjs-datapaas"),
|
|
426
|
-
...require("@lark-apaas/nestjs-
|
|
507
|
+
...require("@lark-apaas/nestjs-observable")
|
|
427
508
|
});
|
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, ObservableTraceMiddleware, ObservableService } 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";
|
|
@@ -230,13 +309,13 @@ var app_config_default = registerAs(NAMESPACE, () => {
|
|
|
230
309
|
});
|
|
231
310
|
|
|
232
311
|
// src/modules/platform/module.ts
|
|
233
|
-
function
|
|
312
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
234
313
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
235
314
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
236
315
|
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
316
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
238
317
|
}
|
|
239
|
-
__name(
|
|
318
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
240
319
|
var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
|
|
241
320
|
var PlatformModule = class _PlatformModule {
|
|
242
321
|
static {
|
|
@@ -259,6 +338,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
259
338
|
]
|
|
260
339
|
}),
|
|
261
340
|
CommonModule,
|
|
341
|
+
ObservableModule.forRoot(),
|
|
262
342
|
LoggerModule,
|
|
263
343
|
DataPaasModule.forRootAsync({
|
|
264
344
|
imports: [
|
|
@@ -274,10 +354,10 @@ var PlatformModule = class _PlatformModule {
|
|
|
274
354
|
const appLogger = args[1];
|
|
275
355
|
const drizzleLogger = {
|
|
276
356
|
logQuery(query, params) {
|
|
277
|
-
appLogger.log?.("SQL Query"
|
|
357
|
+
appLogger.log?.("SQL Query " + JSON.stringify({
|
|
278
358
|
query,
|
|
279
359
|
params
|
|
280
|
-
}, "Database");
|
|
360
|
+
}), "Database");
|
|
281
361
|
}
|
|
282
362
|
};
|
|
283
363
|
return {
|
|
@@ -286,12 +366,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
286
366
|
};
|
|
287
367
|
}, "useFactory")
|
|
288
368
|
}),
|
|
289
|
-
AuthNPaasModule.forRoot()
|
|
290
|
-
AutomationModule.forRoot({
|
|
291
|
-
imports: [
|
|
292
|
-
LoggerModule
|
|
293
|
-
]
|
|
294
|
-
})
|
|
369
|
+
AuthNPaasModule.forRoot()
|
|
295
370
|
],
|
|
296
371
|
providers: [
|
|
297
372
|
{
|
|
@@ -306,11 +381,16 @@ var PlatformModule = class _PlatformModule {
|
|
|
306
381
|
enableImplicitConversion: true
|
|
307
382
|
}
|
|
308
383
|
})
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
provide: OBSERVABLE_SERVICE_TOKEN,
|
|
387
|
+
useClass: ObservableService
|
|
309
388
|
}
|
|
310
389
|
],
|
|
311
390
|
exports: [
|
|
312
391
|
ConfigModule,
|
|
313
|
-
LoggerModule
|
|
392
|
+
LoggerModule,
|
|
393
|
+
OBSERVABLE_SERVICE_TOKEN
|
|
314
394
|
]
|
|
315
395
|
};
|
|
316
396
|
}
|
|
@@ -319,7 +399,8 @@ var PlatformModule = class _PlatformModule {
|
|
|
319
399
|
*/
|
|
320
400
|
configure(consumer) {
|
|
321
401
|
const options = _PlatformModule.moduleOptions;
|
|
322
|
-
consumer.apply(
|
|
402
|
+
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
403
|
+
consumer.apply(UserContextMiddleware, RequestContextMiddleware, LoggerContextMiddleware, ObservableTraceMiddleware, SqlExecutionContextMiddleware).forRoutes("/*");
|
|
323
404
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
324
405
|
if (options.enableCsrf !== false) {
|
|
325
406
|
const csrfRoutes = options.csrfRoutes || "/api/*";
|
|
@@ -333,7 +414,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
333
414
|
}
|
|
334
415
|
}
|
|
335
416
|
};
|
|
336
|
-
PlatformModule =
|
|
417
|
+
PlatformModule = _ts_decorate6([
|
|
337
418
|
Global(),
|
|
338
419
|
Module({})
|
|
339
420
|
], PlatformModule);
|
|
@@ -368,7 +449,7 @@ __name(configureApp, "configureApp");
|
|
|
368
449
|
import { DevToolsModule, DevToolsV2Module as DevToolsV2Module2 } from "@lark-apaas/nestjs-openapi-devtools";
|
|
369
450
|
export * from "@lark-apaas/nestjs-authnpaas";
|
|
370
451
|
export * from "@lark-apaas/nestjs-datapaas";
|
|
371
|
-
export * from "@lark-apaas/nestjs-
|
|
452
|
+
export * from "@lark-apaas/nestjs-observable";
|
|
372
453
|
export {
|
|
373
454
|
CsrfMiddleware,
|
|
374
455
|
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.20",
|
|
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
42
|
"@lark-apaas/nestjs-authnpaas": "^1.0.1",
|
|
42
|
-
"@lark-apaas/nestjs-
|
|
43
|
-
"@lark-apaas/nestjs-common": "^0.0.1-alpha.1",
|
|
43
|
+
"@lark-apaas/nestjs-common": "0.0.1-alpha.3",
|
|
44
44
|
"@lark-apaas/nestjs-datapaas": "^1.0.5",
|
|
45
|
-
"@lark-apaas/nestjs-logger": "
|
|
46
|
-
"@lark-apaas/nestjs-
|
|
45
|
+
"@lark-apaas/nestjs-logger": "1.0.2-alpha.20",
|
|
46
|
+
"@lark-apaas/nestjs-observable": "0.0.1-alpha.14",
|
|
47
|
+
"@lark-apaas/nestjs-openapi-devtools": "^1.0.9",
|
|
47
48
|
"cookie-parser": "^1.4.7"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|