@lark-apaas/fullstack-nestjs-core 1.0.3-alpha.1 → 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);
@@ -13685,15 +13688,25 @@ var PlatformModule = class _PlatformModule {
13685
13688
  logger: drizzleLogger
13686
13689
  };
13687
13690
  }, "useFactory")
13691
+ }),
13692
+ import_nestjs_authnpaas.AuthNPaasModule.forRoot({
13693
+ alwaysNeedLogin: options.alwaysNeedLogin ?? true
13688
13694
  })
13689
13695
  ],
13690
13696
  providers: [
13691
13697
  {
13692
13698
  provide: PLATFORM_MODULE_OPTIONS,
13693
13699
  useValue: options
13700
+ },
13701
+ {
13702
+ provide: import_core.APP_PIPE,
13703
+ useClass: import_common3.ValidationPipe
13694
13704
  }
13695
13705
  ],
13696
- exports: []
13706
+ exports: [
13707
+ import_config2.ConfigModule,
13708
+ import_nestjs_logger.LoggerModule
13709
+ ]
13697
13710
  };
13698
13711
  }
13699
13712
  /**
@@ -13719,6 +13732,12 @@ PlatformModule = _ts_decorate3([
13719
13732
  (0, import_common3.Module)({})
13720
13733
  ], PlatformModule);
13721
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
+
13722
13741
  // src/modules/devtool/index.ts
13723
13742
  var import_swagger = require("@nestjs/swagger");
13724
13743
  var import_node_fs2 = require("fs");
@@ -13803,6 +13822,25 @@ var DevToolsModule = class {
13803
13822
  }
13804
13823
  };
13805
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
+
13806
13844
  // src/middlewares/csrf_token/index.ts
13807
13845
  var import_common4 = require("@nestjs/common");
13808
13846
 
@@ -13873,6 +13911,6 @@ CsrfTokenMiddleware = _ts_decorate4([
13873
13911
  CsrfTokenMiddleware,
13874
13912
  DevToolsModule,
13875
13913
  PlatformModule,
13876
- UserContextMiddleware
13914
+ UserContextMiddleware,
13915
+ configureApp
13877
13916
  });
13878
- //# 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,6 +29,11 @@ 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 {
@@ -39,6 +45,10 @@ declare class PlatformModule implements NestModule {
39
45
  configure(consumer: MiddlewareConsumer): void;
40
46
  }
41
47
 
48
+ declare function configureApp(app: NestExpressApplication, options?: {
49
+ viewsDir?: string;
50
+ }): Promise<void>;
51
+
42
52
  interface DevToolsOptions {
43
53
  basePath?: string;
44
54
  docsPath?: string;
@@ -85,4 +95,4 @@ declare class UserContextMiddleware implements NestMiddleware {
85
95
  use(req: Request, _res: Response, next: NextFunction): void;
86
96
  }
87
97
 
88
- 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,6 +29,11 @@ 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 {
@@ -39,6 +45,10 @@ declare class PlatformModule implements NestModule {
39
45
  configure(consumer: MiddlewareConsumer): void;
40
46
  }
41
47
 
48
+ declare function configureApp(app: NestExpressApplication, options?: {
49
+ viewsDir?: string;
50
+ }): Promise<void>;
51
+
42
52
  interface DevToolsOptions {
43
53
  basePath?: string;
44
54
  docsPath?: string;
@@ -85,4 +95,4 @@ declare class UserContextMiddleware implements NestMiddleware {
85
95
  use(req: Request, _res: Response, next: NextFunction): void;
86
96
  }
87
97
 
88
- 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);
@@ -13674,15 +13676,25 @@ var PlatformModule = class _PlatformModule {
13674
13676
  logger: drizzleLogger
13675
13677
  };
13676
13678
  }, "useFactory")
13679
+ }),
13680
+ AuthNPaasModule.forRoot({
13681
+ alwaysNeedLogin: options.alwaysNeedLogin ?? true
13677
13682
  })
13678
13683
  ],
13679
13684
  providers: [
13680
13685
  {
13681
13686
  provide: PLATFORM_MODULE_OPTIONS,
13682
13687
  useValue: options
13688
+ },
13689
+ {
13690
+ provide: APP_PIPE,
13691
+ useClass: ValidationPipe
13683
13692
  }
13684
13693
  ],
13685
- exports: []
13694
+ exports: [
13695
+ import_config2.ConfigModule,
13696
+ LoggerModule
13697
+ ]
13686
13698
  };
13687
13699
  }
13688
13700
  /**
@@ -13708,6 +13720,12 @@ PlatformModule = _ts_decorate3([
13708
13720
  Module({})
13709
13721
  ], PlatformModule);
13710
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
+
13711
13729
  // src/modules/devtool/index.ts
13712
13730
  import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
13713
13731
  import { mkdirSync as mkdirSync2 } from "fs";
@@ -13792,6 +13810,25 @@ var DevToolsModule = class {
13792
13810
  }
13793
13811
  };
13794
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
+
13795
13832
  // src/middlewares/csrf_token/index.ts
13796
13833
  import { Injectable as Injectable3 } from "@nestjs/common";
13797
13834
 
@@ -13861,6 +13898,6 @@ export {
13861
13898
  CsrfTokenMiddleware,
13862
13899
  DevToolsModule,
13863
13900
  PlatformModule,
13864
- UserContextMiddleware
13901
+ UserContextMiddleware,
13902
+ configureApp
13865
13903
  };
13866
- //# 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.1",
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"