@lark-apaas/fullstack-nestjs-core 1.1.12-alpha.14 → 1.1.12-alpha.15
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 +84 -32
- package/dist/index.js +84 -32
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -171,6 +171,51 @@ CsrfMiddleware = _ts_decorate2([
|
|
|
171
171
|
// src/middlewares/view-context/index.ts
|
|
172
172
|
var import_common3 = require("@nestjs/common");
|
|
173
173
|
var import_nestjs_common = require("@lark-apaas/nestjs-common");
|
|
174
|
+
|
|
175
|
+
// src/utils/safe-stringify.ts
|
|
176
|
+
function safeEscape(s) {
|
|
177
|
+
return s.replace(/[<>&='"\n\r\u2028\u2029]/g, function(c) {
|
|
178
|
+
switch (c.charCodeAt(0)) {
|
|
179
|
+
case 60:
|
|
180
|
+
return "\\u003c";
|
|
181
|
+
// <
|
|
182
|
+
case 62:
|
|
183
|
+
return "\\u003e";
|
|
184
|
+
// >
|
|
185
|
+
case 38:
|
|
186
|
+
return "\\u0026";
|
|
187
|
+
// &
|
|
188
|
+
case 61:
|
|
189
|
+
return "\\u003d";
|
|
190
|
+
// =
|
|
191
|
+
case 39:
|
|
192
|
+
return "\\u0027";
|
|
193
|
+
// '
|
|
194
|
+
case 34:
|
|
195
|
+
return "\\u0022";
|
|
196
|
+
// "
|
|
197
|
+
case 10:
|
|
198
|
+
return "\\u000a";
|
|
199
|
+
// \n
|
|
200
|
+
case 13:
|
|
201
|
+
return "\\u000d";
|
|
202
|
+
// \r
|
|
203
|
+
// 正常来说用户无法输入这几个字符, 现代浏览器也修复了这个问题
|
|
204
|
+
// https://zhuanlan.zhihu.com/p/29958439
|
|
205
|
+
case 8232:
|
|
206
|
+
return "\\u2028";
|
|
207
|
+
// 行分隔符
|
|
208
|
+
case 8233:
|
|
209
|
+
return "\\u2029";
|
|
210
|
+
// 段落分隔符
|
|
211
|
+
default:
|
|
212
|
+
return c;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
__name(safeEscape, "safeEscape");
|
|
217
|
+
|
|
218
|
+
// src/middlewares/view-context/index.ts
|
|
174
219
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
175
220
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
176
221
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -221,14 +266,13 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
221
266
|
const { userId, tenantId, appId } = req.userContext;
|
|
222
267
|
const csrfToken = req.csrfToken;
|
|
223
268
|
const appInfo = await this.getAppInfo(appId);
|
|
224
|
-
this.logger.debug(`appInfo: ${JSON.stringify(appInfo)}`);
|
|
225
269
|
req.__platform_data__ = {
|
|
226
270
|
csrfToken: csrfToken ?? "",
|
|
227
271
|
userId: userId ?? "",
|
|
228
272
|
appId: appId ?? "",
|
|
229
|
-
appName: appInfo?.app_name ?? "",
|
|
273
|
+
appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
|
|
230
274
|
appAvatar: appInfo?.app_avatar ?? "",
|
|
231
|
-
appDescription: appInfo?.app_description ?? "",
|
|
275
|
+
appDescription: safeEscape(appInfo?.app_description ?? ""),
|
|
232
276
|
tenantId
|
|
233
277
|
};
|
|
234
278
|
res.locals = {
|
|
@@ -237,9 +281,9 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
237
281
|
userId: userId ?? "",
|
|
238
282
|
tenantId: tenantId ?? "",
|
|
239
283
|
appId: appId ?? "",
|
|
240
|
-
appName: appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528",
|
|
284
|
+
appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
|
|
241
285
|
appAvatar: appInfo?.app_avatar ?? "",
|
|
242
|
-
appDescription: appInfo?.app_description ?? ""
|
|
286
|
+
appDescription: safeEscape(appInfo?.app_description ?? "")
|
|
243
287
|
};
|
|
244
288
|
next();
|
|
245
289
|
}
|
|
@@ -721,6 +765,9 @@ PlatformHttpClientService = _ts_decorate8([
|
|
|
721
765
|
_ts_metadata5("design:paramtypes", [])
|
|
722
766
|
], PlatformHttpClientService);
|
|
723
767
|
|
|
768
|
+
// src/modules/platform/config/feature-switch.ts
|
|
769
|
+
var DISABLE_DATAPASS = process.env.FORCE_FRAMEWORK_DISABLE_DATAPASS === "true";
|
|
770
|
+
|
|
724
771
|
// src/modules/platform/module.ts
|
|
725
772
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
726
773
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -757,34 +804,37 @@ var PlatformModule = class _PlatformModule {
|
|
|
757
804
|
timeout: 5e3,
|
|
758
805
|
maxRedirects: 5
|
|
759
806
|
}),
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
807
|
+
// 读取环境变量判断是否启用 DataPaasModule
|
|
808
|
+
...DISABLE_DATAPASS ? [] : [
|
|
809
|
+
import_nestjs_datapaas.DataPaasModule.forRootAsync({
|
|
810
|
+
imports: [
|
|
811
|
+
import_config2.ConfigModule,
|
|
812
|
+
import_nestjs_logger2.LoggerModule
|
|
813
|
+
],
|
|
814
|
+
inject: [
|
|
815
|
+
import_config2.ConfigService,
|
|
816
|
+
import_nestjs_logger2.AppLogger
|
|
817
|
+
],
|
|
818
|
+
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
819
|
+
const configService = args[0];
|
|
820
|
+
const appLogger = args[1];
|
|
821
|
+
const drizzleLogger = {
|
|
822
|
+
logQuery(query, params) {
|
|
823
|
+
if (process.env.NODE_ENV === "development") {
|
|
824
|
+
appLogger.log?.("SQL Query " + JSON.stringify({
|
|
825
|
+
query,
|
|
826
|
+
params
|
|
827
|
+
}), "Database");
|
|
828
|
+
}
|
|
779
829
|
}
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
|
|
830
|
+
};
|
|
831
|
+
return {
|
|
832
|
+
connectionString: configService.get("app.databaseUrl") ?? "",
|
|
833
|
+
logger: drizzleLogger
|
|
834
|
+
};
|
|
835
|
+
}, "useFactory")
|
|
836
|
+
})
|
|
837
|
+
],
|
|
788
838
|
import_nestjs_authnpaas.AuthNPaasModule.forRoot(),
|
|
789
839
|
import_nestjs_trigger.AutomationModule.forRoot()
|
|
790
840
|
],
|
|
@@ -870,6 +920,7 @@ async function configureApp(app, perms = defaultPerms) {
|
|
|
870
920
|
app.use((0, import_cookie_parser.default)());
|
|
871
921
|
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
872
922
|
app.setGlobalPrefix(globalPrefix);
|
|
923
|
+
app.set("trust proxy", true);
|
|
873
924
|
if (process.env.NODE_ENV !== "production" && perms.disableSwagger !== true) {
|
|
874
925
|
try {
|
|
875
926
|
await import_nestjs_openapi_devtools.DevToolsV2Module.mount(app, {
|
|
@@ -881,6 +932,7 @@ async function configureApp(app, perms = defaultPerms) {
|
|
|
881
932
|
console.error("[OpenAPI] OpenAPI \u751F\u6210\u5931\u8D25:", err);
|
|
882
933
|
}
|
|
883
934
|
}
|
|
935
|
+
console.log("App Started Successfully.");
|
|
884
936
|
}
|
|
885
937
|
__name(configureApp, "configureApp");
|
|
886
938
|
|
package/dist/index.js
CHANGED
|
@@ -128,6 +128,51 @@ CsrfMiddleware = _ts_decorate2([
|
|
|
128
128
|
// src/middlewares/view-context/index.ts
|
|
129
129
|
import { Inject, Injectable as Injectable3, Logger } from "@nestjs/common";
|
|
130
130
|
import { PLATFORM_HTTP_CLIENT } from "@lark-apaas/nestjs-common";
|
|
131
|
+
|
|
132
|
+
// src/utils/safe-stringify.ts
|
|
133
|
+
function safeEscape(s) {
|
|
134
|
+
return s.replace(/[<>&='"\n\r\u2028\u2029]/g, function(c) {
|
|
135
|
+
switch (c.charCodeAt(0)) {
|
|
136
|
+
case 60:
|
|
137
|
+
return "\\u003c";
|
|
138
|
+
// <
|
|
139
|
+
case 62:
|
|
140
|
+
return "\\u003e";
|
|
141
|
+
// >
|
|
142
|
+
case 38:
|
|
143
|
+
return "\\u0026";
|
|
144
|
+
// &
|
|
145
|
+
case 61:
|
|
146
|
+
return "\\u003d";
|
|
147
|
+
// =
|
|
148
|
+
case 39:
|
|
149
|
+
return "\\u0027";
|
|
150
|
+
// '
|
|
151
|
+
case 34:
|
|
152
|
+
return "\\u0022";
|
|
153
|
+
// "
|
|
154
|
+
case 10:
|
|
155
|
+
return "\\u000a";
|
|
156
|
+
// \n
|
|
157
|
+
case 13:
|
|
158
|
+
return "\\u000d";
|
|
159
|
+
// \r
|
|
160
|
+
// 正常来说用户无法输入这几个字符, 现代浏览器也修复了这个问题
|
|
161
|
+
// https://zhuanlan.zhihu.com/p/29958439
|
|
162
|
+
case 8232:
|
|
163
|
+
return "\\u2028";
|
|
164
|
+
// 行分隔符
|
|
165
|
+
case 8233:
|
|
166
|
+
return "\\u2029";
|
|
167
|
+
// 段落分隔符
|
|
168
|
+
default:
|
|
169
|
+
return c;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
__name(safeEscape, "safeEscape");
|
|
174
|
+
|
|
175
|
+
// src/middlewares/view-context/index.ts
|
|
131
176
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
132
177
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
133
178
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -178,14 +223,13 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
178
223
|
const { userId, tenantId, appId } = req.userContext;
|
|
179
224
|
const csrfToken = req.csrfToken;
|
|
180
225
|
const appInfo = await this.getAppInfo(appId);
|
|
181
|
-
this.logger.debug(`appInfo: ${JSON.stringify(appInfo)}`);
|
|
182
226
|
req.__platform_data__ = {
|
|
183
227
|
csrfToken: csrfToken ?? "",
|
|
184
228
|
userId: userId ?? "",
|
|
185
229
|
appId: appId ?? "",
|
|
186
|
-
appName: appInfo?.app_name ?? "",
|
|
230
|
+
appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
|
|
187
231
|
appAvatar: appInfo?.app_avatar ?? "",
|
|
188
|
-
appDescription: appInfo?.app_description ?? "",
|
|
232
|
+
appDescription: safeEscape(appInfo?.app_description ?? ""),
|
|
189
233
|
tenantId
|
|
190
234
|
};
|
|
191
235
|
res.locals = {
|
|
@@ -194,9 +238,9 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
194
238
|
userId: userId ?? "",
|
|
195
239
|
tenantId: tenantId ?? "",
|
|
196
240
|
appId: appId ?? "",
|
|
197
|
-
appName: appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528",
|
|
241
|
+
appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
|
|
198
242
|
appAvatar: appInfo?.app_avatar ?? "",
|
|
199
|
-
appDescription: appInfo?.app_description ?? ""
|
|
243
|
+
appDescription: safeEscape(appInfo?.app_description ?? "")
|
|
200
244
|
};
|
|
201
245
|
next();
|
|
202
246
|
}
|
|
@@ -678,6 +722,9 @@ PlatformHttpClientService = _ts_decorate8([
|
|
|
678
722
|
_ts_metadata5("design:paramtypes", [])
|
|
679
723
|
], PlatformHttpClientService);
|
|
680
724
|
|
|
725
|
+
// src/modules/platform/config/feature-switch.ts
|
|
726
|
+
var DISABLE_DATAPASS = process.env.FORCE_FRAMEWORK_DISABLE_DATAPASS === "true";
|
|
727
|
+
|
|
681
728
|
// src/modules/platform/module.ts
|
|
682
729
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
683
730
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -714,34 +761,37 @@ var PlatformModule = class _PlatformModule {
|
|
|
714
761
|
timeout: 5e3,
|
|
715
762
|
maxRedirects: 5
|
|
716
763
|
}),
|
|
717
|
-
DataPaasModule
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
764
|
+
// 读取环境变量判断是否启用 DataPaasModule
|
|
765
|
+
...DISABLE_DATAPASS ? [] : [
|
|
766
|
+
DataPaasModule.forRootAsync({
|
|
767
|
+
imports: [
|
|
768
|
+
ConfigModule,
|
|
769
|
+
LoggerModule
|
|
770
|
+
],
|
|
771
|
+
inject: [
|
|
772
|
+
ConfigService,
|
|
773
|
+
AppLogger2
|
|
774
|
+
],
|
|
775
|
+
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
776
|
+
const configService = args[0];
|
|
777
|
+
const appLogger = args[1];
|
|
778
|
+
const drizzleLogger = {
|
|
779
|
+
logQuery(query, params) {
|
|
780
|
+
if (process.env.NODE_ENV === "development") {
|
|
781
|
+
appLogger.log?.("SQL Query " + JSON.stringify({
|
|
782
|
+
query,
|
|
783
|
+
params
|
|
784
|
+
}), "Database");
|
|
785
|
+
}
|
|
736
786
|
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
|
|
787
|
+
};
|
|
788
|
+
return {
|
|
789
|
+
connectionString: configService.get("app.databaseUrl") ?? "",
|
|
790
|
+
logger: drizzleLogger
|
|
791
|
+
};
|
|
792
|
+
}, "useFactory")
|
|
793
|
+
})
|
|
794
|
+
],
|
|
745
795
|
AuthNPaasModule.forRoot(),
|
|
746
796
|
AutomationModule.forRoot()
|
|
747
797
|
],
|
|
@@ -827,6 +877,7 @@ async function configureApp(app, perms = defaultPerms) {
|
|
|
827
877
|
app.use(cookieParser());
|
|
828
878
|
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
829
879
|
app.setGlobalPrefix(globalPrefix);
|
|
880
|
+
app.set("trust proxy", true);
|
|
830
881
|
if (process.env.NODE_ENV !== "production" && perms.disableSwagger !== true) {
|
|
831
882
|
try {
|
|
832
883
|
await DevToolsV2Module.mount(app, {
|
|
@@ -838,6 +889,7 @@ async function configureApp(app, perms = defaultPerms) {
|
|
|
838
889
|
console.error("[OpenAPI] OpenAPI \u751F\u6210\u5931\u8D25:", err);
|
|
839
890
|
}
|
|
840
891
|
}
|
|
892
|
+
console.log("App Started Successfully.");
|
|
841
893
|
}
|
|
842
894
|
__name(configureApp, "configureApp");
|
|
843
895
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-nestjs-core",
|
|
3
|
-
"version": "1.1.12-alpha.
|
|
3
|
+
"version": "1.1.12-alpha.15",
|
|
4
4
|
"description": "FullStack Nestjs Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@lark-apaas/nestjs-authnpaas": "^1.0.2",
|
|
44
44
|
"@lark-apaas/nestjs-common": "^0.1.1",
|
|
45
45
|
"@lark-apaas/nestjs-datapaas": "^1.0.7",
|
|
46
|
-
"@lark-apaas/nestjs-logger": "1.0.6-alpha.
|
|
46
|
+
"@lark-apaas/nestjs-logger": "1.0.6-alpha.1",
|
|
47
47
|
"@lark-apaas/nestjs-observable": "^0.0.2",
|
|
48
48
|
"@lark-apaas/nestjs-openapi-devtools": "^1.0.9",
|
|
49
49
|
"@lark-apaas/nestjs-trigger": "^0.0.1",
|