@lark-apaas/fullstack-nestjs-core 1.0.3-alpha.1 → 1.0.3-alpha.3
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 +145 -76
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +141 -73
- package/package.json +8 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
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/
|
|
13512
|
-
var
|
|
13512
|
+
// src/modules/platform/module.ts
|
|
13513
|
+
var import_common5 = 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,102 @@ CsrfMiddleware = _ts_decorate2([
|
|
|
13618
13621
|
(0, import_common2.Injectable)()
|
|
13619
13622
|
], CsrfMiddleware);
|
|
13620
13623
|
|
|
13621
|
-
// src/
|
|
13624
|
+
// src/middlewares/view-context/index.ts
|
|
13625
|
+
var import_common3 = require("@nestjs/common");
|
|
13626
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
13627
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13628
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13629
|
+
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;
|
|
13630
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13631
|
+
}
|
|
13632
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
13633
|
+
var ViewContextMiddleware = class {
|
|
13634
|
+
static {
|
|
13635
|
+
__name(this, "ViewContextMiddleware");
|
|
13636
|
+
}
|
|
13637
|
+
use(req, res, next) {
|
|
13638
|
+
const { userId, tenantId, appId } = req.userContext;
|
|
13639
|
+
const csrfToken = req.csrfToken;
|
|
13640
|
+
res.locals = {
|
|
13641
|
+
csrfToken: csrfToken ?? "",
|
|
13642
|
+
userId: userId ?? "",
|
|
13643
|
+
tenantId: tenantId ?? "",
|
|
13644
|
+
appId: appId ?? "",
|
|
13645
|
+
...res.locals
|
|
13646
|
+
};
|
|
13647
|
+
next();
|
|
13648
|
+
}
|
|
13649
|
+
};
|
|
13650
|
+
ViewContextMiddleware = _ts_decorate3([
|
|
13651
|
+
(0, import_common3.Injectable)()
|
|
13652
|
+
], ViewContextMiddleware);
|
|
13653
|
+
|
|
13654
|
+
// src/middlewares/csrf_token/index.ts
|
|
13655
|
+
var import_common4 = require("@nestjs/common");
|
|
13656
|
+
|
|
13657
|
+
// src/middlewares/csrf_token/helper.ts
|
|
13658
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
13659
|
+
function resolveCsrfTokenOptions(options) {
|
|
13660
|
+
return {
|
|
13661
|
+
...options,
|
|
13662
|
+
cookieKey: options.cookieKey ?? "suda-csrf-token",
|
|
13663
|
+
cookieMaxAge: options.cookieMaxAge ?? 1e3 * 60 * 60 * 24 * 30,
|
|
13664
|
+
cookiePath: options.cookiePath ?? "/"
|
|
13665
|
+
};
|
|
13666
|
+
}
|
|
13667
|
+
__name(resolveCsrfTokenOptions, "resolveCsrfTokenOptions");
|
|
13668
|
+
function genToken() {
|
|
13669
|
+
const ts = Math.floor(Date.now() / 1e3);
|
|
13670
|
+
const randInt64 = BigInt("0x" + import_crypto.default.randomBytes(8).toString("hex")).toString();
|
|
13671
|
+
const s = `${randInt64}.${ts}`;
|
|
13672
|
+
const sha1 = import_crypto.default.createHash("sha1");
|
|
13673
|
+
sha1.update(s);
|
|
13674
|
+
return `${sha1.digest("hex")}-${ts}`;
|
|
13675
|
+
}
|
|
13676
|
+
__name(genToken, "genToken");
|
|
13677
|
+
|
|
13678
|
+
// src/middlewares/csrf_token/index.ts
|
|
13679
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
13680
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13681
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13682
|
+
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;
|
|
13683
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13684
|
+
}
|
|
13685
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
13686
|
+
var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
13687
|
+
static {
|
|
13688
|
+
__name(this, "CsrfTokenMiddleware");
|
|
13689
|
+
}
|
|
13690
|
+
static options = resolveCsrfTokenOptions({});
|
|
13691
|
+
static configure(opts) {
|
|
13692
|
+
this.options = resolveCsrfTokenOptions(opts);
|
|
13693
|
+
}
|
|
13694
|
+
use(req, res, next) {
|
|
13695
|
+
const { cookieKey, cookieMaxAge, cookiePath } = _CsrfTokenMiddleware.options;
|
|
13696
|
+
const originToken = req.cookies[cookieKey.toLowerCase()];
|
|
13697
|
+
if (originToken) {
|
|
13698
|
+
req.csrfToken = originToken;
|
|
13699
|
+
next();
|
|
13700
|
+
} else {
|
|
13701
|
+
const token = genToken();
|
|
13702
|
+
req.csrfToken = token;
|
|
13703
|
+
res.cookie(cookieKey, token, {
|
|
13704
|
+
maxAge: cookieMaxAge,
|
|
13705
|
+
path: cookiePath,
|
|
13706
|
+
httpOnly: true,
|
|
13707
|
+
secure: true,
|
|
13708
|
+
sameSite: "none",
|
|
13709
|
+
partitioned: true
|
|
13710
|
+
});
|
|
13711
|
+
next();
|
|
13712
|
+
}
|
|
13713
|
+
}
|
|
13714
|
+
};
|
|
13715
|
+
CsrfTokenMiddleware = _ts_decorate4([
|
|
13716
|
+
(0, import_common4.Injectable)()
|
|
13717
|
+
], CsrfTokenMiddleware);
|
|
13718
|
+
|
|
13719
|
+
// src/modules/platform/config/app.config.ts
|
|
13622
13720
|
var import_config = __toESM(require_config2(), 1);
|
|
13623
13721
|
var NAMESPACE = "app";
|
|
13624
13722
|
var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
|
|
@@ -13630,14 +13728,14 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
|
|
|
13630
13728
|
};
|
|
13631
13729
|
});
|
|
13632
13730
|
|
|
13633
|
-
// src/
|
|
13634
|
-
function
|
|
13731
|
+
// src/modules/platform/module.ts
|
|
13732
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
13635
13733
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13636
13734
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13637
13735
|
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;
|
|
13638
13736
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13639
13737
|
}
|
|
13640
|
-
__name(
|
|
13738
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
13641
13739
|
var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
|
|
13642
13740
|
var PlatformModule = class _PlatformModule {
|
|
13643
13741
|
static {
|
|
@@ -13685,15 +13783,25 @@ var PlatformModule = class _PlatformModule {
|
|
|
13685
13783
|
logger: drizzleLogger
|
|
13686
13784
|
};
|
|
13687
13785
|
}, "useFactory")
|
|
13786
|
+
}),
|
|
13787
|
+
import_nestjs_authnpaas.AuthNPaasModule.forRoot({
|
|
13788
|
+
alwaysNeedLogin: options.alwaysNeedLogin ?? true
|
|
13688
13789
|
})
|
|
13689
13790
|
],
|
|
13690
13791
|
providers: [
|
|
13691
13792
|
{
|
|
13692
13793
|
provide: PLATFORM_MODULE_OPTIONS,
|
|
13693
13794
|
useValue: options
|
|
13795
|
+
},
|
|
13796
|
+
{
|
|
13797
|
+
provide: import_core.APP_PIPE,
|
|
13798
|
+
useClass: import_common5.ValidationPipe
|
|
13694
13799
|
}
|
|
13695
13800
|
],
|
|
13696
|
-
exports: [
|
|
13801
|
+
exports: [
|
|
13802
|
+
import_config2.ConfigModule,
|
|
13803
|
+
import_nestjs_logger.LoggerModule
|
|
13804
|
+
]
|
|
13697
13805
|
};
|
|
13698
13806
|
}
|
|
13699
13807
|
/**
|
|
@@ -13702,6 +13810,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
13702
13810
|
configure(consumer) {
|
|
13703
13811
|
const options = _PlatformModule.moduleOptions;
|
|
13704
13812
|
consumer.apply(UserContextMiddleware, import_nestjs_logger.LoggerContextMiddleware, import_nestjs_datapaas.SqlExecutionContextMiddleware).forRoutes("/*");
|
|
13813
|
+
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/*");
|
|
13705
13814
|
if (options.enableCsrf !== false) {
|
|
13706
13815
|
const csrfRoutes = options.csrfRoutes || "/api/*";
|
|
13707
13816
|
if (Array.isArray(csrfRoutes)) {
|
|
@@ -13714,11 +13823,17 @@ var PlatformModule = class _PlatformModule {
|
|
|
13714
13823
|
}
|
|
13715
13824
|
}
|
|
13716
13825
|
};
|
|
13717
|
-
PlatformModule =
|
|
13718
|
-
(0,
|
|
13719
|
-
(0,
|
|
13826
|
+
PlatformModule = _ts_decorate5([
|
|
13827
|
+
(0, import_common5.Global)(),
|
|
13828
|
+
(0, import_common5.Module)({})
|
|
13720
13829
|
], PlatformModule);
|
|
13721
13830
|
|
|
13831
|
+
// src/setup.ts
|
|
13832
|
+
var import_nestjs_logger2 = require("@lark-apaas/nestjs-logger");
|
|
13833
|
+
var import_path = require("path");
|
|
13834
|
+
var import_hbs = require("hbs");
|
|
13835
|
+
var import_cookie_parser = __toESM(require("cookie-parser"), 1);
|
|
13836
|
+
|
|
13722
13837
|
// src/modules/devtool/index.ts
|
|
13723
13838
|
var import_swagger = require("@nestjs/swagger");
|
|
13724
13839
|
var import_node_fs2 = require("fs");
|
|
@@ -13803,76 +13918,30 @@ var DevToolsModule = class {
|
|
|
13803
13918
|
}
|
|
13804
13919
|
};
|
|
13805
13920
|
|
|
13806
|
-
// src/
|
|
13807
|
-
|
|
13808
|
-
|
|
13809
|
-
|
|
13810
|
-
|
|
13811
|
-
|
|
13812
|
-
|
|
13813
|
-
|
|
13814
|
-
|
|
13815
|
-
|
|
13816
|
-
|
|
13817
|
-
|
|
13818
|
-
|
|
13819
|
-
|
|
13820
|
-
|
|
13821
|
-
const ts = Math.floor(Date.now() / 1e3);
|
|
13822
|
-
const randInt64 = BigInt("0x" + import_crypto.default.randomBytes(8).toString("hex")).toString();
|
|
13823
|
-
const s = `${randInt64}.${ts}`;
|
|
13824
|
-
const sha1 = import_crypto.default.createHash("sha1");
|
|
13825
|
-
sha1.update(s);
|
|
13826
|
-
return `${sha1.digest("hex")}-${ts}`;
|
|
13827
|
-
}
|
|
13828
|
-
__name(genToken, "genToken");
|
|
13829
|
-
|
|
13830
|
-
// src/middlewares/csrf_token/index.ts
|
|
13831
|
-
function _ts_decorate4(decorators, target, key, desc) {
|
|
13832
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13833
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13834
|
-
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;
|
|
13835
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13836
|
-
}
|
|
13837
|
-
__name(_ts_decorate4, "_ts_decorate");
|
|
13838
|
-
var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
13839
|
-
static {
|
|
13840
|
-
__name(this, "CsrfTokenMiddleware");
|
|
13841
|
-
}
|
|
13842
|
-
static options = resolveCsrfTokenOptions({});
|
|
13843
|
-
static configure(opts) {
|
|
13844
|
-
this.options = resolveCsrfTokenOptions(opts);
|
|
13845
|
-
}
|
|
13846
|
-
use(req, res, next) {
|
|
13847
|
-
const { cookieKey, cookieMaxAge, cookiePath } = _CsrfTokenMiddleware.options;
|
|
13848
|
-
const originToken = req.cookies[cookieKey.toLowerCase()];
|
|
13849
|
-
if (originToken) {
|
|
13850
|
-
req.csrfToken = originToken;
|
|
13851
|
-
next();
|
|
13852
|
-
} else {
|
|
13853
|
-
const token = genToken();
|
|
13854
|
-
req.csrfToken = token;
|
|
13855
|
-
res.cookie(cookieKey, token, {
|
|
13856
|
-
maxAge: cookieMaxAge,
|
|
13857
|
-
path: cookiePath,
|
|
13858
|
-
httpOnly: true,
|
|
13859
|
-
secure: true,
|
|
13860
|
-
sameSite: "none",
|
|
13861
|
-
partitioned: true
|
|
13862
|
-
});
|
|
13863
|
-
next();
|
|
13864
|
-
}
|
|
13921
|
+
// src/setup.ts
|
|
13922
|
+
async function configureApp(app, options) {
|
|
13923
|
+
app.useLogger(app.get(import_nestjs_logger2.AppLogger));
|
|
13924
|
+
app.flushLogs();
|
|
13925
|
+
app.use((0, import_cookie_parser.default)());
|
|
13926
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
13927
|
+
app.setGlobalPrefix(globalPrefix);
|
|
13928
|
+
app.setBaseViewsDir((0, import_path.join)(process.cwd(), options?.viewsDir ?? "dist/client"));
|
|
13929
|
+
app.setViewEngine("html");
|
|
13930
|
+
app.engine("html", import_hbs.__express);
|
|
13931
|
+
if (process.env.NODE_ENV !== "production") {
|
|
13932
|
+
await DevToolsModule.mount(app, {
|
|
13933
|
+
basePath: process.env.CLIENT_BASE_PATH,
|
|
13934
|
+
docsPath: "/api_docs"
|
|
13935
|
+
});
|
|
13865
13936
|
}
|
|
13866
|
-
}
|
|
13867
|
-
|
|
13868
|
-
(0, import_common4.Injectable)()
|
|
13869
|
-
], CsrfTokenMiddleware);
|
|
13937
|
+
}
|
|
13938
|
+
__name(configureApp, "configureApp");
|
|
13870
13939
|
// Annotate the CommonJS export names for ESM import in node:
|
|
13871
13940
|
0 && (module.exports = {
|
|
13872
13941
|
CsrfMiddleware,
|
|
13873
13942
|
CsrfTokenMiddleware,
|
|
13874
13943
|
DevToolsModule,
|
|
13875
13944
|
PlatformModule,
|
|
13876
|
-
UserContextMiddleware
|
|
13945
|
+
UserContextMiddleware,
|
|
13946
|
+
configureApp
|
|
13877
13947
|
});
|
|
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/
|
|
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,102 @@ CsrfMiddleware = _ts_decorate2([
|
|
|
13607
13609
|
Injectable2()
|
|
13608
13610
|
], CsrfMiddleware);
|
|
13609
13611
|
|
|
13610
|
-
// src/
|
|
13612
|
+
// src/middlewares/view-context/index.ts
|
|
13613
|
+
import { Injectable as Injectable3 } from "@nestjs/common";
|
|
13614
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
13615
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13616
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13617
|
+
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;
|
|
13618
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13619
|
+
}
|
|
13620
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
13621
|
+
var ViewContextMiddleware = class {
|
|
13622
|
+
static {
|
|
13623
|
+
__name(this, "ViewContextMiddleware");
|
|
13624
|
+
}
|
|
13625
|
+
use(req, res, next) {
|
|
13626
|
+
const { userId, tenantId, appId } = req.userContext;
|
|
13627
|
+
const csrfToken = req.csrfToken;
|
|
13628
|
+
res.locals = {
|
|
13629
|
+
csrfToken: csrfToken ?? "",
|
|
13630
|
+
userId: userId ?? "",
|
|
13631
|
+
tenantId: tenantId ?? "",
|
|
13632
|
+
appId: appId ?? "",
|
|
13633
|
+
...res.locals
|
|
13634
|
+
};
|
|
13635
|
+
next();
|
|
13636
|
+
}
|
|
13637
|
+
};
|
|
13638
|
+
ViewContextMiddleware = _ts_decorate3([
|
|
13639
|
+
Injectable3()
|
|
13640
|
+
], ViewContextMiddleware);
|
|
13641
|
+
|
|
13642
|
+
// src/middlewares/csrf_token/index.ts
|
|
13643
|
+
import { Injectable as Injectable4 } from "@nestjs/common";
|
|
13644
|
+
|
|
13645
|
+
// src/middlewares/csrf_token/helper.ts
|
|
13646
|
+
import crypto from "crypto";
|
|
13647
|
+
function resolveCsrfTokenOptions(options) {
|
|
13648
|
+
return {
|
|
13649
|
+
...options,
|
|
13650
|
+
cookieKey: options.cookieKey ?? "suda-csrf-token",
|
|
13651
|
+
cookieMaxAge: options.cookieMaxAge ?? 1e3 * 60 * 60 * 24 * 30,
|
|
13652
|
+
cookiePath: options.cookiePath ?? "/"
|
|
13653
|
+
};
|
|
13654
|
+
}
|
|
13655
|
+
__name(resolveCsrfTokenOptions, "resolveCsrfTokenOptions");
|
|
13656
|
+
function genToken() {
|
|
13657
|
+
const ts = Math.floor(Date.now() / 1e3);
|
|
13658
|
+
const randInt64 = BigInt("0x" + crypto.randomBytes(8).toString("hex")).toString();
|
|
13659
|
+
const s = `${randInt64}.${ts}`;
|
|
13660
|
+
const sha1 = crypto.createHash("sha1");
|
|
13661
|
+
sha1.update(s);
|
|
13662
|
+
return `${sha1.digest("hex")}-${ts}`;
|
|
13663
|
+
}
|
|
13664
|
+
__name(genToken, "genToken");
|
|
13665
|
+
|
|
13666
|
+
// src/middlewares/csrf_token/index.ts
|
|
13667
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
13668
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13669
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13670
|
+
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;
|
|
13671
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13672
|
+
}
|
|
13673
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
13674
|
+
var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
13675
|
+
static {
|
|
13676
|
+
__name(this, "CsrfTokenMiddleware");
|
|
13677
|
+
}
|
|
13678
|
+
static options = resolveCsrfTokenOptions({});
|
|
13679
|
+
static configure(opts) {
|
|
13680
|
+
this.options = resolveCsrfTokenOptions(opts);
|
|
13681
|
+
}
|
|
13682
|
+
use(req, res, next) {
|
|
13683
|
+
const { cookieKey, cookieMaxAge, cookiePath } = _CsrfTokenMiddleware.options;
|
|
13684
|
+
const originToken = req.cookies[cookieKey.toLowerCase()];
|
|
13685
|
+
if (originToken) {
|
|
13686
|
+
req.csrfToken = originToken;
|
|
13687
|
+
next();
|
|
13688
|
+
} else {
|
|
13689
|
+
const token = genToken();
|
|
13690
|
+
req.csrfToken = token;
|
|
13691
|
+
res.cookie(cookieKey, token, {
|
|
13692
|
+
maxAge: cookieMaxAge,
|
|
13693
|
+
path: cookiePath,
|
|
13694
|
+
httpOnly: true,
|
|
13695
|
+
secure: true,
|
|
13696
|
+
sameSite: "none",
|
|
13697
|
+
partitioned: true
|
|
13698
|
+
});
|
|
13699
|
+
next();
|
|
13700
|
+
}
|
|
13701
|
+
}
|
|
13702
|
+
};
|
|
13703
|
+
CsrfTokenMiddleware = _ts_decorate4([
|
|
13704
|
+
Injectable4()
|
|
13705
|
+
], CsrfTokenMiddleware);
|
|
13706
|
+
|
|
13707
|
+
// src/modules/platform/config/app.config.ts
|
|
13611
13708
|
var import_config = __toESM(require_config2(), 1);
|
|
13612
13709
|
var NAMESPACE = "app";
|
|
13613
13710
|
var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
|
|
@@ -13619,14 +13716,14 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
|
|
|
13619
13716
|
};
|
|
13620
13717
|
});
|
|
13621
13718
|
|
|
13622
|
-
// src/
|
|
13623
|
-
function
|
|
13719
|
+
// src/modules/platform/module.ts
|
|
13720
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
13624
13721
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13625
13722
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13626
13723
|
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;
|
|
13627
13724
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13628
13725
|
}
|
|
13629
|
-
__name(
|
|
13726
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
13630
13727
|
var PLATFORM_MODULE_OPTIONS = "PLATFORM_MODULE_OPTIONS";
|
|
13631
13728
|
var PlatformModule = class _PlatformModule {
|
|
13632
13729
|
static {
|
|
@@ -13674,15 +13771,25 @@ var PlatformModule = class _PlatformModule {
|
|
|
13674
13771
|
logger: drizzleLogger
|
|
13675
13772
|
};
|
|
13676
13773
|
}, "useFactory")
|
|
13774
|
+
}),
|
|
13775
|
+
AuthNPaasModule.forRoot({
|
|
13776
|
+
alwaysNeedLogin: options.alwaysNeedLogin ?? true
|
|
13677
13777
|
})
|
|
13678
13778
|
],
|
|
13679
13779
|
providers: [
|
|
13680
13780
|
{
|
|
13681
13781
|
provide: PLATFORM_MODULE_OPTIONS,
|
|
13682
13782
|
useValue: options
|
|
13783
|
+
},
|
|
13784
|
+
{
|
|
13785
|
+
provide: APP_PIPE,
|
|
13786
|
+
useClass: ValidationPipe
|
|
13683
13787
|
}
|
|
13684
13788
|
],
|
|
13685
|
-
exports: [
|
|
13789
|
+
exports: [
|
|
13790
|
+
import_config2.ConfigModule,
|
|
13791
|
+
LoggerModule
|
|
13792
|
+
]
|
|
13686
13793
|
};
|
|
13687
13794
|
}
|
|
13688
13795
|
/**
|
|
@@ -13691,6 +13798,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
13691
13798
|
configure(consumer) {
|
|
13692
13799
|
const options = _PlatformModule.moduleOptions;
|
|
13693
13800
|
consumer.apply(UserContextMiddleware, LoggerContextMiddleware, SqlExecutionContextMiddleware).forRoutes("/*");
|
|
13801
|
+
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/*");
|
|
13694
13802
|
if (options.enableCsrf !== false) {
|
|
13695
13803
|
const csrfRoutes = options.csrfRoutes || "/api/*";
|
|
13696
13804
|
if (Array.isArray(csrfRoutes)) {
|
|
@@ -13703,11 +13811,17 @@ var PlatformModule = class _PlatformModule {
|
|
|
13703
13811
|
}
|
|
13704
13812
|
}
|
|
13705
13813
|
};
|
|
13706
|
-
PlatformModule =
|
|
13814
|
+
PlatformModule = _ts_decorate5([
|
|
13707
13815
|
Global(),
|
|
13708
13816
|
Module({})
|
|
13709
13817
|
], PlatformModule);
|
|
13710
13818
|
|
|
13819
|
+
// src/setup.ts
|
|
13820
|
+
import { AppLogger as AppLogger2 } from "@lark-apaas/nestjs-logger";
|
|
13821
|
+
import { join } from "path";
|
|
13822
|
+
import { __express as hbsExpressEngine } from "hbs";
|
|
13823
|
+
import cookieParser from "cookie-parser";
|
|
13824
|
+
|
|
13711
13825
|
// src/modules/devtool/index.ts
|
|
13712
13826
|
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
|
|
13713
13827
|
import { mkdirSync as mkdirSync2 } from "fs";
|
|
@@ -13792,75 +13906,29 @@ var DevToolsModule = class {
|
|
|
13792
13906
|
}
|
|
13793
13907
|
};
|
|
13794
13908
|
|
|
13795
|
-
// src/
|
|
13796
|
-
|
|
13797
|
-
|
|
13798
|
-
|
|
13799
|
-
|
|
13800
|
-
|
|
13801
|
-
|
|
13802
|
-
|
|
13803
|
-
|
|
13804
|
-
|
|
13805
|
-
|
|
13806
|
-
|
|
13807
|
-
|
|
13808
|
-
|
|
13809
|
-
|
|
13810
|
-
const ts = Math.floor(Date.now() / 1e3);
|
|
13811
|
-
const randInt64 = BigInt("0x" + crypto.randomBytes(8).toString("hex")).toString();
|
|
13812
|
-
const s = `${randInt64}.${ts}`;
|
|
13813
|
-
const sha1 = crypto.createHash("sha1");
|
|
13814
|
-
sha1.update(s);
|
|
13815
|
-
return `${sha1.digest("hex")}-${ts}`;
|
|
13816
|
-
}
|
|
13817
|
-
__name(genToken, "genToken");
|
|
13818
|
-
|
|
13819
|
-
// src/middlewares/csrf_token/index.ts
|
|
13820
|
-
function _ts_decorate4(decorators, target, key, desc) {
|
|
13821
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13822
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13823
|
-
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;
|
|
13824
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13825
|
-
}
|
|
13826
|
-
__name(_ts_decorate4, "_ts_decorate");
|
|
13827
|
-
var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
13828
|
-
static {
|
|
13829
|
-
__name(this, "CsrfTokenMiddleware");
|
|
13830
|
-
}
|
|
13831
|
-
static options = resolveCsrfTokenOptions({});
|
|
13832
|
-
static configure(opts) {
|
|
13833
|
-
this.options = resolveCsrfTokenOptions(opts);
|
|
13834
|
-
}
|
|
13835
|
-
use(req, res, next) {
|
|
13836
|
-
const { cookieKey, cookieMaxAge, cookiePath } = _CsrfTokenMiddleware.options;
|
|
13837
|
-
const originToken = req.cookies[cookieKey.toLowerCase()];
|
|
13838
|
-
if (originToken) {
|
|
13839
|
-
req.csrfToken = originToken;
|
|
13840
|
-
next();
|
|
13841
|
-
} else {
|
|
13842
|
-
const token = genToken();
|
|
13843
|
-
req.csrfToken = token;
|
|
13844
|
-
res.cookie(cookieKey, token, {
|
|
13845
|
-
maxAge: cookieMaxAge,
|
|
13846
|
-
path: cookiePath,
|
|
13847
|
-
httpOnly: true,
|
|
13848
|
-
secure: true,
|
|
13849
|
-
sameSite: "none",
|
|
13850
|
-
partitioned: true
|
|
13851
|
-
});
|
|
13852
|
-
next();
|
|
13853
|
-
}
|
|
13909
|
+
// src/setup.ts
|
|
13910
|
+
async function configureApp(app, options) {
|
|
13911
|
+
app.useLogger(app.get(AppLogger2));
|
|
13912
|
+
app.flushLogs();
|
|
13913
|
+
app.use(cookieParser());
|
|
13914
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
13915
|
+
app.setGlobalPrefix(globalPrefix);
|
|
13916
|
+
app.setBaseViewsDir(join(process.cwd(), options?.viewsDir ?? "dist/client"));
|
|
13917
|
+
app.setViewEngine("html");
|
|
13918
|
+
app.engine("html", hbsExpressEngine);
|
|
13919
|
+
if (process.env.NODE_ENV !== "production") {
|
|
13920
|
+
await DevToolsModule.mount(app, {
|
|
13921
|
+
basePath: process.env.CLIENT_BASE_PATH,
|
|
13922
|
+
docsPath: "/api_docs"
|
|
13923
|
+
});
|
|
13854
13924
|
}
|
|
13855
|
-
}
|
|
13856
|
-
|
|
13857
|
-
Injectable3()
|
|
13858
|
-
], CsrfTokenMiddleware);
|
|
13925
|
+
}
|
|
13926
|
+
__name(configureApp, "configureApp");
|
|
13859
13927
|
export {
|
|
13860
13928
|
CsrfMiddleware,
|
|
13861
13929
|
CsrfTokenMiddleware,
|
|
13862
13930
|
DevToolsModule,
|
|
13863
13931
|
PlatformModule,
|
|
13864
|
-
UserContextMiddleware
|
|
13932
|
+
UserContextMiddleware,
|
|
13933
|
+
configureApp
|
|
13865
13934
|
};
|
|
13866
|
-
//# sourceMappingURL=index.js.map
|