@lark-apaas/fullstack-nestjs-core 1.1.2 → 1.1.4-alpha.0
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 +92 -9
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +86 -3
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -44,8 +44,8 @@ __export(index_exports, {
|
|
|
44
44
|
module.exports = __toCommonJS(index_exports);
|
|
45
45
|
|
|
46
46
|
// src/modules/platform/module.ts
|
|
47
|
-
var
|
|
48
|
-
var
|
|
47
|
+
var import_common6 = require("@nestjs/common");
|
|
48
|
+
var import_core2 = require("@nestjs/core");
|
|
49
49
|
var import_config2 = require("@nestjs/config");
|
|
50
50
|
var import_nestjs_logger = require("@lark-apaas/nestjs-logger");
|
|
51
51
|
var import_nestjs_datapaas = require("@lark-apaas/nestjs-datapaas");
|
|
@@ -92,6 +92,7 @@ var UserContextMiddleware = class {
|
|
|
92
92
|
tenantId: webUser?.tenant_id,
|
|
93
93
|
appId: webUser?.app_id ?? "",
|
|
94
94
|
loginUrl: webUser?.login_url ?? "",
|
|
95
|
+
userType: webUser?.user_type ?? "",
|
|
95
96
|
env: webUser?.env ?? "runtime",
|
|
96
97
|
userName: webUser?.user_name?.zh_cn ?? "",
|
|
97
98
|
userNameEn: webUser?.user_name?.en_us ?? "",
|
|
@@ -272,8 +273,18 @@ function createApiNotFoundResponse(req) {
|
|
|
272
273
|
};
|
|
273
274
|
}
|
|
274
275
|
__name(createApiNotFoundResponse, "createApiNotFoundResponse");
|
|
276
|
+
function getApiPathPrefix() {
|
|
277
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
278
|
+
if (!globalPrefix) {
|
|
279
|
+
return "/api/";
|
|
280
|
+
}
|
|
281
|
+
const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
|
|
282
|
+
return `${normalizedPrefix}/api/`;
|
|
283
|
+
}
|
|
284
|
+
__name(getApiPathPrefix, "getApiPathPrefix");
|
|
275
285
|
function apiResponseInterceptor(req, res, next) {
|
|
276
|
-
|
|
286
|
+
const apiPrefix = getApiPathPrefix();
|
|
287
|
+
if (!req.baseUrl.startsWith(apiPrefix)) {
|
|
277
288
|
return next();
|
|
278
289
|
}
|
|
279
290
|
res.render = function() {
|
|
@@ -295,7 +306,9 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
|
|
|
295
306
|
};
|
|
296
307
|
});
|
|
297
308
|
|
|
298
|
-
// src/
|
|
309
|
+
// src/middlewares/debug/index.ts
|
|
310
|
+
var import_common5 = require("@nestjs/common");
|
|
311
|
+
var import_core = require("@nestjs/core");
|
|
299
312
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
300
313
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
301
314
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -303,6 +316,73 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
303
316
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
304
317
|
}
|
|
305
318
|
__name(_ts_decorate5, "_ts_decorate");
|
|
319
|
+
function _ts_metadata(k, v) {
|
|
320
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
321
|
+
}
|
|
322
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
323
|
+
var processStartTimestamp = Date.now();
|
|
324
|
+
var FrameworkDebugMiddleware = class {
|
|
325
|
+
static {
|
|
326
|
+
__name(this, "FrameworkDebugMiddleware");
|
|
327
|
+
}
|
|
328
|
+
httpAdapterHost;
|
|
329
|
+
constructor(httpAdapterHost) {
|
|
330
|
+
this.httpAdapterHost = httpAdapterHost;
|
|
331
|
+
}
|
|
332
|
+
use(_req, res) {
|
|
333
|
+
res.json(this.getDebugInfo());
|
|
334
|
+
}
|
|
335
|
+
getDebugInfo() {
|
|
336
|
+
const routes = this.getRoutes();
|
|
337
|
+
const uptimeSeconds = Math.floor(process.uptime());
|
|
338
|
+
return {
|
|
339
|
+
["\u8DEF\u7531\u914D\u7F6E"]: routes,
|
|
340
|
+
["\u8FDB\u7A0B\u5B58\u6D3B\u65F6\u95F4\uFF08\u79D2\uFF09"]: uptimeSeconds,
|
|
341
|
+
["\u8FDB\u7A0B\u542F\u52A8\u65F6\u95F4\uFF08\u79D2\uFF09"]: new Date(processStartTimestamp).toISOString(),
|
|
342
|
+
["\u8FD0\u884C\u65F6\u7248\u672C"]: process.versions
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
getRoutes() {
|
|
346
|
+
const server = this.httpAdapterHost.httpAdapter;
|
|
347
|
+
const router = server.getInstance()._router;
|
|
348
|
+
if (!router) {
|
|
349
|
+
return {
|
|
350
|
+
error: "Router \u4E0D\u53EF\u7528"
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
const routes = [];
|
|
354
|
+
router.stack.forEach((middleware, index) => {
|
|
355
|
+
if (middleware.route) {
|
|
356
|
+
routes.push({
|
|
357
|
+
order: String(index),
|
|
358
|
+
path: middleware.route.path,
|
|
359
|
+
method: middleware.method,
|
|
360
|
+
regexp: middleware.regexp?.toString()
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
return {
|
|
365
|
+
total: routes.length,
|
|
366
|
+
routes
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
FrameworkDebugMiddleware = _ts_decorate5([
|
|
371
|
+
(0, import_common5.Injectable)(),
|
|
372
|
+
_ts_metadata("design:type", Function),
|
|
373
|
+
_ts_metadata("design:paramtypes", [
|
|
374
|
+
typeof import_core.HttpAdapterHost === "undefined" ? Object : import_core.HttpAdapterHost
|
|
375
|
+
])
|
|
376
|
+
], FrameworkDebugMiddleware);
|
|
377
|
+
|
|
378
|
+
// src/modules/platform/module.ts
|
|
379
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
380
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
381
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
382
|
+
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
384
|
+
}
|
|
385
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
306
386
|
var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
|
|
307
387
|
var PlatformModule = class _PlatformModule {
|
|
308
388
|
static {
|
|
@@ -359,8 +439,8 @@ var PlatformModule = class _PlatformModule {
|
|
|
359
439
|
useValue: options
|
|
360
440
|
},
|
|
361
441
|
{
|
|
362
|
-
provide:
|
|
363
|
-
useValue: new
|
|
442
|
+
provide: import_core2.APP_PIPE,
|
|
443
|
+
useValue: new import_common6.ValidationPipe({
|
|
364
444
|
transform: true,
|
|
365
445
|
transformOptions: {
|
|
366
446
|
enableImplicitConversion: true
|
|
@@ -380,6 +460,9 @@ var PlatformModule = class _PlatformModule {
|
|
|
380
460
|
configure(consumer) {
|
|
381
461
|
const options = _PlatformModule.moduleOptions;
|
|
382
462
|
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
463
|
+
if (process.env.NODE_ENV === "development") {
|
|
464
|
+
consumer.apply(FrameworkDebugMiddleware).forRoutes("/api/__framework__/debug");
|
|
465
|
+
}
|
|
383
466
|
consumer.apply(UserContextMiddleware, import_nestjs_logger.LoggerContextMiddleware, import_nestjs_datapaas.SqlExecutionContextMiddleware).forRoutes("/*");
|
|
384
467
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
385
468
|
if (options.enableCsrf !== false) {
|
|
@@ -394,9 +477,9 @@ var PlatformModule = class _PlatformModule {
|
|
|
394
477
|
}
|
|
395
478
|
}
|
|
396
479
|
};
|
|
397
|
-
PlatformModule =
|
|
398
|
-
(0,
|
|
399
|
-
(0,
|
|
480
|
+
PlatformModule = _ts_decorate6([
|
|
481
|
+
(0, import_common6.Global)(),
|
|
482
|
+
(0, import_common6.Module)({})
|
|
400
483
|
], PlatformModule);
|
|
401
484
|
|
|
402
485
|
// src/setup.ts
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ var UserContextMiddleware = class {
|
|
|
50
50
|
tenantId: webUser?.tenant_id,
|
|
51
51
|
appId: webUser?.app_id ?? "",
|
|
52
52
|
loginUrl: webUser?.login_url ?? "",
|
|
53
|
+
userType: webUser?.user_type ?? "",
|
|
53
54
|
env: webUser?.env ?? "runtime",
|
|
54
55
|
userName: webUser?.user_name?.zh_cn ?? "",
|
|
55
56
|
userNameEn: webUser?.user_name?.en_us ?? "",
|
|
@@ -230,8 +231,18 @@ function createApiNotFoundResponse(req) {
|
|
|
230
231
|
};
|
|
231
232
|
}
|
|
232
233
|
__name(createApiNotFoundResponse, "createApiNotFoundResponse");
|
|
234
|
+
function getApiPathPrefix() {
|
|
235
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
236
|
+
if (!globalPrefix) {
|
|
237
|
+
return "/api/";
|
|
238
|
+
}
|
|
239
|
+
const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
|
|
240
|
+
return `${normalizedPrefix}/api/`;
|
|
241
|
+
}
|
|
242
|
+
__name(getApiPathPrefix, "getApiPathPrefix");
|
|
233
243
|
function apiResponseInterceptor(req, res, next) {
|
|
234
|
-
|
|
244
|
+
const apiPrefix = getApiPathPrefix();
|
|
245
|
+
if (!req.baseUrl.startsWith(apiPrefix)) {
|
|
235
246
|
return next();
|
|
236
247
|
}
|
|
237
248
|
res.render = function() {
|
|
@@ -253,7 +264,9 @@ var app_config_default = registerAs(NAMESPACE, () => {
|
|
|
253
264
|
};
|
|
254
265
|
});
|
|
255
266
|
|
|
256
|
-
// src/
|
|
267
|
+
// src/middlewares/debug/index.ts
|
|
268
|
+
import { Injectable as Injectable5 } from "@nestjs/common";
|
|
269
|
+
import { HttpAdapterHost } from "@nestjs/core";
|
|
257
270
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
258
271
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
259
272
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -261,6 +274,73 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
261
274
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
262
275
|
}
|
|
263
276
|
__name(_ts_decorate5, "_ts_decorate");
|
|
277
|
+
function _ts_metadata(k, v) {
|
|
278
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
279
|
+
}
|
|
280
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
281
|
+
var processStartTimestamp = Date.now();
|
|
282
|
+
var FrameworkDebugMiddleware = class {
|
|
283
|
+
static {
|
|
284
|
+
__name(this, "FrameworkDebugMiddleware");
|
|
285
|
+
}
|
|
286
|
+
httpAdapterHost;
|
|
287
|
+
constructor(httpAdapterHost) {
|
|
288
|
+
this.httpAdapterHost = httpAdapterHost;
|
|
289
|
+
}
|
|
290
|
+
use(_req, res) {
|
|
291
|
+
res.json(this.getDebugInfo());
|
|
292
|
+
}
|
|
293
|
+
getDebugInfo() {
|
|
294
|
+
const routes = this.getRoutes();
|
|
295
|
+
const uptimeSeconds = Math.floor(process.uptime());
|
|
296
|
+
return {
|
|
297
|
+
["\u8DEF\u7531\u914D\u7F6E"]: routes,
|
|
298
|
+
["\u8FDB\u7A0B\u5B58\u6D3B\u65F6\u95F4\uFF08\u79D2\uFF09"]: uptimeSeconds,
|
|
299
|
+
["\u8FDB\u7A0B\u542F\u52A8\u65F6\u95F4\uFF08\u79D2\uFF09"]: new Date(processStartTimestamp).toISOString(),
|
|
300
|
+
["\u8FD0\u884C\u65F6\u7248\u672C"]: process.versions
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
getRoutes() {
|
|
304
|
+
const server = this.httpAdapterHost.httpAdapter;
|
|
305
|
+
const router = server.getInstance()._router;
|
|
306
|
+
if (!router) {
|
|
307
|
+
return {
|
|
308
|
+
error: "Router \u4E0D\u53EF\u7528"
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
const routes = [];
|
|
312
|
+
router.stack.forEach((middleware, index) => {
|
|
313
|
+
if (middleware.route) {
|
|
314
|
+
routes.push({
|
|
315
|
+
order: String(index),
|
|
316
|
+
path: middleware.route.path,
|
|
317
|
+
method: middleware.method,
|
|
318
|
+
regexp: middleware.regexp?.toString()
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
return {
|
|
323
|
+
total: routes.length,
|
|
324
|
+
routes
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
FrameworkDebugMiddleware = _ts_decorate5([
|
|
329
|
+
Injectable5(),
|
|
330
|
+
_ts_metadata("design:type", Function),
|
|
331
|
+
_ts_metadata("design:paramtypes", [
|
|
332
|
+
typeof HttpAdapterHost === "undefined" ? Object : HttpAdapterHost
|
|
333
|
+
])
|
|
334
|
+
], FrameworkDebugMiddleware);
|
|
335
|
+
|
|
336
|
+
// src/modules/platform/module.ts
|
|
337
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
338
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
339
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
340
|
+
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;
|
|
341
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
342
|
+
}
|
|
343
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
264
344
|
var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
|
|
265
345
|
var PlatformModule = class _PlatformModule {
|
|
266
346
|
static {
|
|
@@ -338,6 +418,9 @@ var PlatformModule = class _PlatformModule {
|
|
|
338
418
|
configure(consumer) {
|
|
339
419
|
const options = _PlatformModule.moduleOptions;
|
|
340
420
|
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
421
|
+
if (process.env.NODE_ENV === "development") {
|
|
422
|
+
consumer.apply(FrameworkDebugMiddleware).forRoutes("/api/__framework__/debug");
|
|
423
|
+
}
|
|
341
424
|
consumer.apply(UserContextMiddleware, LoggerContextMiddleware, SqlExecutionContextMiddleware).forRoutes("/*");
|
|
342
425
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
343
426
|
if (options.enableCsrf !== false) {
|
|
@@ -352,7 +435,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
352
435
|
}
|
|
353
436
|
}
|
|
354
437
|
};
|
|
355
|
-
PlatformModule =
|
|
438
|
+
PlatformModule = _ts_decorate6([
|
|
356
439
|
Global(),
|
|
357
440
|
Module({})
|
|
358
441
|
], PlatformModule);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-nestjs-core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4-alpha.0",
|
|
4
4
|
"description": "FullStack Nestjs Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@nestjs/common": "^10.4.20",
|
|
62
|
+
"@nestjs/core": "^10.4.20",
|
|
62
63
|
"@nestjs/platform-express": "^10.4.20",
|
|
63
64
|
"@nestjs/swagger": "^7.4.2",
|
|
64
65
|
"class-transformer": "^0.5.1",
|