@lark-apaas/fullstack-nestjs-core 1.0.3-alpha.0 → 1.0.3-alpha.2

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 CHANGED
@@ -13504,15 +13504,18 @@ __export(index_exports, {
13504
13504
  CsrfTokenMiddleware: () => CsrfTokenMiddleware,
13505
13505
  DevToolsModule: () => DevToolsModule,
13506
13506
  PlatformModule: () => PlatformModule,
13507
- UserContextMiddleware: () => UserContextMiddleware
13507
+ UserContextMiddleware: () => UserContextMiddleware,
13508
+ configureApp: () => configureApp
13508
13509
  });
13509
13510
  module.exports = __toCommonJS(index_exports);
13510
13511
 
13511
- // src/core/module.ts
13512
+ // src/modules/platform/module.ts
13512
13513
  var import_common3 = require("@nestjs/common");
13514
+ var import_core = require("@nestjs/core");
13513
13515
  var import_config2 = __toESM(require_config2(), 1);
13514
13516
  var import_nestjs_logger = require("@lark-apaas/nestjs-logger");
13515
13517
  var import_nestjs_datapaas = require("@lark-apaas/nestjs-datapaas");
13518
+ var import_nestjs_authnpaas = require("@lark-apaas/nestjs-authnpaas");
13516
13519
 
13517
13520
  // src/middlewares/user-context/index.ts
13518
13521
  var import_common = require("@nestjs/common");
@@ -13618,7 +13621,7 @@ CsrfMiddleware = _ts_decorate2([
13618
13621
  (0, import_common2.Injectable)()
13619
13622
  ], CsrfMiddleware);
13620
13623
 
13621
- // src/core/config/app.config.ts
13624
+ // src/modules/platform/config/app.config.ts
13622
13625
  var import_config = __toESM(require_config2(), 1);
13623
13626
  var NAMESPACE = "app";
13624
13627
  var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
@@ -13630,7 +13633,7 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
13630
13633
  };
13631
13634
  });
13632
13635
 
13633
- // src/core/module.ts
13636
+ // src/modules/platform/module.ts
13634
13637
  function _ts_decorate3(decorators, target, key, desc) {
13635
13638
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13636
13639
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -13638,20 +13641,14 @@ function _ts_decorate3(decorators, target, key, desc) {
13638
13641
  return c > 3 && r && Object.defineProperty(target, key, r), r;
13639
13642
  }
13640
13643
  __name(_ts_decorate3, "_ts_decorate");
13641
- function _ts_metadata(k, v) {
13642
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
13643
- }
13644
- __name(_ts_metadata, "_ts_metadata");
13645
13644
  var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
13646
13645
  var PlatformModule = class _PlatformModule {
13647
13646
  static {
13648
13647
  __name(this, "PlatformModule");
13649
13648
  }
13650
- options;
13651
- constructor(options) {
13652
- this.options = options;
13653
- }
13649
+ static moduleOptions = {};
13654
13650
  static forRoot(options = {}) {
13651
+ _PlatformModule.moduleOptions = options;
13655
13652
  return {
13656
13653
  module: _PlatformModule,
13657
13654
  imports: [
@@ -13691,24 +13688,35 @@ var PlatformModule = class _PlatformModule {
13691
13688
  logger: drizzleLogger
13692
13689
  };
13693
13690
  }, "useFactory")
13691
+ }),
13692
+ import_nestjs_authnpaas.AuthNPaasModule.forRoot({
13693
+ alwaysNeedLogin: options.alwaysNeedLogin ?? true
13694
13694
  })
13695
13695
  ],
13696
13696
  providers: [
13697
13697
  {
13698
13698
  provide: PLATFORM_MODULE_OPTIONS,
13699
13699
  useValue: options
13700
+ },
13701
+ {
13702
+ provide: import_core.APP_PIPE,
13703
+ useClass: import_common3.ValidationPipe
13700
13704
  }
13701
13705
  ],
13702
- exports: []
13706
+ exports: [
13707
+ import_config2.ConfigModule,
13708
+ import_nestjs_logger.LoggerModule
13709
+ ]
13703
13710
  };
13704
13711
  }
13705
13712
  /**
13706
13713
  * 配置中间件
13707
13714
  */
13708
13715
  configure(consumer) {
13716
+ const options = _PlatformModule.moduleOptions;
13709
13717
  consumer.apply(UserContextMiddleware, import_nestjs_logger.LoggerContextMiddleware, import_nestjs_datapaas.SqlExecutionContextMiddleware).forRoutes("/*");
13710
- if (this.options.enableCsrf !== false) {
13711
- const csrfRoutes = this.options.csrfRoutes || "/api/*";
13718
+ if (options.enableCsrf !== false) {
13719
+ const csrfRoutes = options.csrfRoutes || "/api/*";
13712
13720
  if (Array.isArray(csrfRoutes)) {
13713
13721
  csrfRoutes.forEach((route) => {
13714
13722
  consumer.apply(CsrfMiddleware).forRoutes(route);
@@ -13721,13 +13729,15 @@ var PlatformModule = class _PlatformModule {
13721
13729
  };
13722
13730
  PlatformModule = _ts_decorate3([
13723
13731
  (0, import_common3.Global)(),
13724
- (0, import_common3.Module)({}),
13725
- _ts_metadata("design:type", Function),
13726
- _ts_metadata("design:paramtypes", [
13727
- typeof PlatformModuleOptions === "undefined" ? Object : PlatformModuleOptions
13728
- ])
13732
+ (0, import_common3.Module)({})
13729
13733
  ], PlatformModule);
13730
13734
 
13735
+ // src/setup.ts
13736
+ var import_nestjs_logger2 = require("@lark-apaas/nestjs-logger");
13737
+ var import_path = require("path");
13738
+ var import_hbs = require("hbs");
13739
+ var import_cookie_parser = __toESM(require("cookie-parser"), 1);
13740
+
13731
13741
  // src/modules/devtool/index.ts
13732
13742
  var import_swagger = require("@nestjs/swagger");
13733
13743
  var import_node_fs2 = require("fs");
@@ -13812,6 +13822,25 @@ var DevToolsModule = class {
13812
13822
  }
13813
13823
  };
13814
13824
 
13825
+ // src/setup.ts
13826
+ async function configureApp(app, options) {
13827
+ app.useLogger(app.get(import_nestjs_logger2.AppLogger));
13828
+ app.flushLogs();
13829
+ app.use((0, import_cookie_parser.default)());
13830
+ const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
13831
+ app.setGlobalPrefix(globalPrefix);
13832
+ app.setBaseViewsDir((0, import_path.join)(process.cwd(), options?.viewsDir ?? "dist/client"));
13833
+ app.setViewEngine("html");
13834
+ app.engine("html", import_hbs.__express);
13835
+ if (process.env.NODE_ENV !== "production") {
13836
+ await DevToolsModule.mount(app, {
13837
+ basePath: process.env.CLIENT_BASE_PATH,
13838
+ docsPath: "/api_docs"
13839
+ });
13840
+ }
13841
+ }
13842
+ __name(configureApp, "configureApp");
13843
+
13815
13844
  // src/middlewares/csrf_token/index.ts
13816
13845
  var import_common4 = require("@nestjs/common");
13817
13846
 
@@ -13882,6 +13911,6 @@ CsrfTokenMiddleware = _ts_decorate4([
13882
13911
  CsrfTokenMiddleware,
13883
13912
  DevToolsModule,
13884
13913
  PlatformModule,
13885
- UserContextMiddleware
13914
+ UserContextMiddleware,
13915
+ configureApp
13886
13916
  });
13887
- //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { NestModule, DynamicModule, MiddlewareConsumer, INestApplication, NestMiddleware } from '@nestjs/common';
2
+ import { NestExpressApplication } from '@nestjs/platform-express';
2
3
  import { Request, Response, NextFunction } from 'express';
3
4
 
4
5
  declare global {
@@ -28,11 +29,15 @@ interface PlatformModuleOptions {
28
29
  * 默认: '/api/*'
29
30
  */
30
31
  csrfRoutes?: string | string[];
32
+ /**
33
+ * AuthN 能力,是否全部依赖登录
34
+ * 默认:true
35
+ */
36
+ alwaysNeedLogin?: boolean;
31
37
  }
32
38
 
33
39
  declare class PlatformModule implements NestModule {
34
- private readonly options;
35
- constructor(options: PlatformModuleOptions);
40
+ private static moduleOptions;
36
41
  static forRoot(options?: PlatformModuleOptions): DynamicModule;
37
42
  /**
38
43
  * 配置中间件
@@ -40,6 +45,10 @@ declare class PlatformModule implements NestModule {
40
45
  configure(consumer: MiddlewareConsumer): void;
41
46
  }
42
47
 
48
+ declare function configureApp(app: NestExpressApplication, options?: {
49
+ viewsDir?: string;
50
+ }): Promise<void>;
51
+
43
52
  interface DevToolsOptions {
44
53
  basePath?: string;
45
54
  docsPath?: string;
@@ -86,4 +95,4 @@ declare class UserContextMiddleware implements NestMiddleware {
86
95
  use(req: Request, _res: Response, next: NextFunction): void;
87
96
  }
88
97
 
89
- export { CsrfMiddleware, CsrfTokenMiddleware, DevToolsModule, PlatformModule, type PlatformModuleOptions, UserContextMiddleware };
98
+ export { CsrfMiddleware, CsrfTokenMiddleware, DevToolsModule, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, configureApp };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { NestModule, DynamicModule, MiddlewareConsumer, INestApplication, NestMiddleware } from '@nestjs/common';
2
+ import { NestExpressApplication } from '@nestjs/platform-express';
2
3
  import { Request, Response, NextFunction } from 'express';
3
4
 
4
5
  declare global {
@@ -28,11 +29,15 @@ interface PlatformModuleOptions {
28
29
  * 默认: '/api/*'
29
30
  */
30
31
  csrfRoutes?: string | string[];
32
+ /**
33
+ * AuthN 能力,是否全部依赖登录
34
+ * 默认:true
35
+ */
36
+ alwaysNeedLogin?: boolean;
31
37
  }
32
38
 
33
39
  declare class PlatformModule implements NestModule {
34
- private readonly options;
35
- constructor(options: PlatformModuleOptions);
40
+ private static moduleOptions;
36
41
  static forRoot(options?: PlatformModuleOptions): DynamicModule;
37
42
  /**
38
43
  * 配置中间件
@@ -40,6 +45,10 @@ declare class PlatformModule implements NestModule {
40
45
  configure(consumer: MiddlewareConsumer): void;
41
46
  }
42
47
 
48
+ declare function configureApp(app: NestExpressApplication, options?: {
49
+ viewsDir?: string;
50
+ }): Promise<void>;
51
+
43
52
  interface DevToolsOptions {
44
53
  basePath?: string;
45
54
  docsPath?: string;
@@ -86,4 +95,4 @@ declare class UserContextMiddleware implements NestMiddleware {
86
95
  use(req: Request, _res: Response, next: NextFunction): void;
87
96
  }
88
97
 
89
- export { CsrfMiddleware, CsrfTokenMiddleware, DevToolsModule, PlatformModule, type PlatformModuleOptions, UserContextMiddleware };
98
+ export { CsrfMiddleware, CsrfTokenMiddleware, DevToolsModule, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, configureApp };
package/dist/index.js CHANGED
@@ -13497,11 +13497,13 @@ var require_config2 = __commonJS({
13497
13497
  }
13498
13498
  });
13499
13499
 
13500
- // src/core/module.ts
13500
+ // src/modules/platform/module.ts
13501
13501
  var import_config2 = __toESM(require_config2(), 1);
13502
- import { Global, Module } from "@nestjs/common";
13502
+ import { Global, Module, ValidationPipe } from "@nestjs/common";
13503
+ import { APP_PIPE } from "@nestjs/core";
13503
13504
  import { LoggerModule, AppLogger, LoggerContextMiddleware } from "@lark-apaas/nestjs-logger";
13504
13505
  import { DataPaasModule, SqlExecutionContextMiddleware } from "@lark-apaas/nestjs-datapaas";
13506
+ import { AuthNPaasModule } from "@lark-apaas/nestjs-authnpaas";
13505
13507
 
13506
13508
  // src/middlewares/user-context/index.ts
13507
13509
  import { Injectable } from "@nestjs/common";
@@ -13607,7 +13609,7 @@ CsrfMiddleware = _ts_decorate2([
13607
13609
  Injectable2()
13608
13610
  ], CsrfMiddleware);
13609
13611
 
13610
- // src/core/config/app.config.ts
13612
+ // src/modules/platform/config/app.config.ts
13611
13613
  var import_config = __toESM(require_config2(), 1);
13612
13614
  var NAMESPACE = "app";
13613
13615
  var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
@@ -13619,7 +13621,7 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
13619
13621
  };
13620
13622
  });
13621
13623
 
13622
- // src/core/module.ts
13624
+ // src/modules/platform/module.ts
13623
13625
  function _ts_decorate3(decorators, target, key, desc) {
13624
13626
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13625
13627
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -13627,20 +13629,14 @@ function _ts_decorate3(decorators, target, key, desc) {
13627
13629
  return c > 3 && r && Object.defineProperty(target, key, r), r;
13628
13630
  }
13629
13631
  __name(_ts_decorate3, "_ts_decorate");
13630
- function _ts_metadata(k, v) {
13631
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
13632
- }
13633
- __name(_ts_metadata, "_ts_metadata");
13634
13632
  var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
13635
13633
  var PlatformModule = class _PlatformModule {
13636
13634
  static {
13637
13635
  __name(this, "PlatformModule");
13638
13636
  }
13639
- options;
13640
- constructor(options) {
13641
- this.options = options;
13642
- }
13637
+ static moduleOptions = {};
13643
13638
  static forRoot(options = {}) {
13639
+ _PlatformModule.moduleOptions = options;
13644
13640
  return {
13645
13641
  module: _PlatformModule,
13646
13642
  imports: [
@@ -13680,24 +13676,35 @@ var PlatformModule = class _PlatformModule {
13680
13676
  logger: drizzleLogger
13681
13677
  };
13682
13678
  }, "useFactory")
13679
+ }),
13680
+ AuthNPaasModule.forRoot({
13681
+ alwaysNeedLogin: options.alwaysNeedLogin ?? true
13683
13682
  })
13684
13683
  ],
13685
13684
  providers: [
13686
13685
  {
13687
13686
  provide: PLATFORM_MODULE_OPTIONS,
13688
13687
  useValue: options
13688
+ },
13689
+ {
13690
+ provide: APP_PIPE,
13691
+ useClass: ValidationPipe
13689
13692
  }
13690
13693
  ],
13691
- exports: []
13694
+ exports: [
13695
+ import_config2.ConfigModule,
13696
+ LoggerModule
13697
+ ]
13692
13698
  };
13693
13699
  }
13694
13700
  /**
13695
13701
  * 配置中间件
13696
13702
  */
13697
13703
  configure(consumer) {
13704
+ const options = _PlatformModule.moduleOptions;
13698
13705
  consumer.apply(UserContextMiddleware, LoggerContextMiddleware, SqlExecutionContextMiddleware).forRoutes("/*");
13699
- if (this.options.enableCsrf !== false) {
13700
- const csrfRoutes = this.options.csrfRoutes || "/api/*";
13706
+ if (options.enableCsrf !== false) {
13707
+ const csrfRoutes = options.csrfRoutes || "/api/*";
13701
13708
  if (Array.isArray(csrfRoutes)) {
13702
13709
  csrfRoutes.forEach((route) => {
13703
13710
  consumer.apply(CsrfMiddleware).forRoutes(route);
@@ -13710,13 +13717,15 @@ var PlatformModule = class _PlatformModule {
13710
13717
  };
13711
13718
  PlatformModule = _ts_decorate3([
13712
13719
  Global(),
13713
- Module({}),
13714
- _ts_metadata("design:type", Function),
13715
- _ts_metadata("design:paramtypes", [
13716
- typeof PlatformModuleOptions === "undefined" ? Object : PlatformModuleOptions
13717
- ])
13720
+ Module({})
13718
13721
  ], PlatformModule);
13719
13722
 
13723
+ // src/setup.ts
13724
+ import { AppLogger as AppLogger2 } from "@lark-apaas/nestjs-logger";
13725
+ import { join } from "path";
13726
+ import { __express as hbsExpressEngine } from "hbs";
13727
+ import cookieParser from "cookie-parser";
13728
+
13720
13729
  // src/modules/devtool/index.ts
13721
13730
  import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
13722
13731
  import { mkdirSync as mkdirSync2 } from "fs";
@@ -13801,6 +13810,25 @@ var DevToolsModule = class {
13801
13810
  }
13802
13811
  };
13803
13812
 
13813
+ // src/setup.ts
13814
+ async function configureApp(app, options) {
13815
+ app.useLogger(app.get(AppLogger2));
13816
+ app.flushLogs();
13817
+ app.use(cookieParser());
13818
+ const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
13819
+ app.setGlobalPrefix(globalPrefix);
13820
+ app.setBaseViewsDir(join(process.cwd(), options?.viewsDir ?? "dist/client"));
13821
+ app.setViewEngine("html");
13822
+ app.engine("html", hbsExpressEngine);
13823
+ if (process.env.NODE_ENV !== "production") {
13824
+ await DevToolsModule.mount(app, {
13825
+ basePath: process.env.CLIENT_BASE_PATH,
13826
+ docsPath: "/api_docs"
13827
+ });
13828
+ }
13829
+ }
13830
+ __name(configureApp, "configureApp");
13831
+
13804
13832
  // src/middlewares/csrf_token/index.ts
13805
13833
  import { Injectable as Injectable3 } from "@nestjs/common";
13806
13834
 
@@ -13870,6 +13898,6 @@ export {
13870
13898
  CsrfTokenMiddleware,
13871
13899
  DevToolsModule,
13872
13900
  PlatformModule,
13873
- UserContextMiddleware
13901
+ UserContextMiddleware,
13902
+ configureApp
13874
13903
  };
13875
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.0.3-alpha.0",
3
+ "version": "1.0.3-alpha.2",
4
4
  "description": "FullStack Nestjs Core",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -41,6 +41,8 @@
41
41
  "@lark-apaas/nestjs-authnpaas": "^1.0.0",
42
42
  "@lark-apaas/nestjs-datapaas": "^1.0.1",
43
43
  "@lark-apaas/nestjs-logger": "^1.0.0",
44
+ "cookie-parser": "^1.4.7",
45
+ "hbs": "^4.2.0",
44
46
  "openapi-typescript-codegen": "^0.29.0"
45
47
  },
46
48
  "devDependencies": {
@@ -49,6 +51,7 @@
49
51
  "@nestjs/swagger": "^7.4.2",
50
52
  "@types/cookie-parser": "^1.4.9",
51
53
  "@types/express": "^5.0.3",
54
+ "@types/hbs": "^4.0.5",
52
55
  "drizzle-orm": "0.44.6",
53
56
  "tsup": "^8.0.0",
54
57
  "typescript": "^5.0.0"