@lark-apaas/fullstack-nestjs-core 1.1.10-alpha.33 → 1.1.10-alpha.35

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.
Files changed (3) hide show
  1. package/dist/index.cjs +107 -51
  2. package/dist/index.js +107 -51
  3. package/package.json +7 -7
package/dist/index.cjs CHANGED
@@ -172,6 +172,51 @@ CsrfMiddleware = _ts_decorate2([
172
172
  // src/middlewares/view-context/index.ts
173
173
  var import_common3 = require("@nestjs/common");
174
174
  var import_nestjs_common = require("@lark-apaas/nestjs-common");
175
+
176
+ // src/utils/safe-stringify.ts
177
+ function safeEscape(s) {
178
+ return s.replace(/[<>&='"\n\r\u2028\u2029]/g, function(c) {
179
+ switch (c.charCodeAt(0)) {
180
+ case 60:
181
+ return "\\u003c";
182
+ // <
183
+ case 62:
184
+ return "\\u003e";
185
+ // >
186
+ case 38:
187
+ return "\\u0026";
188
+ // &
189
+ case 61:
190
+ return "\\u003d";
191
+ // =
192
+ case 39:
193
+ return "\\u0027";
194
+ // '
195
+ case 34:
196
+ return "\\u0022";
197
+ // "
198
+ case 10:
199
+ return "\\u000a";
200
+ // \n
201
+ case 13:
202
+ return "\\u000d";
203
+ // \r
204
+ // 正常来说用户无法输入这几个字符, 现代浏览器也修复了这个问题
205
+ // https://zhuanlan.zhihu.com/p/29958439
206
+ case 8232:
207
+ return "\\u2028";
208
+ // 行分隔符
209
+ case 8233:
210
+ return "\\u2029";
211
+ // 段落分隔符
212
+ default:
213
+ return c;
214
+ }
215
+ });
216
+ }
217
+ __name(safeEscape, "safeEscape");
218
+
219
+ // src/middlewares/view-context/index.ts
175
220
  function _ts_decorate3(decorators, target, key, desc) {
176
221
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
177
222
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -222,14 +267,13 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
222
267
  const { userId, tenantId, appId, loginUrl, userType } = req.userContext;
223
268
  const csrfToken = req.csrfToken;
224
269
  const appInfo = await this.getAppInfo(appId);
225
- this.logger.debug(`appInfo: ${JSON.stringify(appInfo)}`);
226
270
  req.__platform_data__ = {
227
271
  csrfToken: csrfToken ?? "",
228
272
  userId: userId ?? "",
229
273
  appId: appId ?? "",
230
- appName: appInfo?.app_name ?? "",
274
+ appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
231
275
  appAvatar: appInfo?.app_avatar ?? "",
232
- appDescription: appInfo?.app_description ?? "",
276
+ appDescription: safeEscape(appInfo?.app_description ?? ""),
233
277
  loginUrl: loginUrl ?? "",
234
278
  userType: userType ?? "",
235
279
  tenantId
@@ -242,9 +286,9 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
242
286
  loginUrl: loginUrl ?? "",
243
287
  userType: userType ?? "",
244
288
  appId: appId ?? "",
245
- appName: appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528",
289
+ appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
246
290
  appAvatar: appInfo?.app_avatar ?? "",
247
- appDescription: appInfo?.app_description ?? ""
291
+ appDescription: safeEscape(appInfo?.app_description ?? "")
248
292
  };
249
293
  next();
250
294
  }
@@ -434,26 +478,30 @@ var HttpInterceptorService = class {
434
478
  setupInterceptors() {
435
479
  const axiosInstance = this.httpService.axiosRef;
436
480
  axiosInstance.interceptors.request.use((config) => {
437
- this.logger.log("HTTP Request", {
438
- method: config.method?.toUpperCase(),
439
- url: config.url,
440
- headers: config.headers,
441
- params: config.params,
442
- data: config.data
443
- }, "HttpService");
481
+ if (process.env.NODE_ENV === "development") {
482
+ this.logger.log("HTTP Request", {
483
+ method: config.method?.toUpperCase(),
484
+ url: config.url,
485
+ headers: config.headers,
486
+ params: config.params,
487
+ data: config.data
488
+ }, "HttpService");
489
+ }
444
490
  return config;
445
491
  }, (error) => {
446
492
  this.logger.error("HTTP Request Error", error, "HttpService");
447
493
  return Promise.reject(error);
448
494
  });
449
495
  axiosInstance.interceptors.response.use((response) => {
450
- this.logger.log("HTTP Response", {
451
- method: response.config.method?.toUpperCase(),
452
- url: response.config.url,
453
- status: response.status,
454
- statusText: response.statusText,
455
- data: response.data
456
- }, "HttpService");
496
+ if (process.env.NODE_ENV === "development") {
497
+ this.logger.log("HTTP Response", {
498
+ method: response.config.method?.toUpperCase(),
499
+ url: response.config.url,
500
+ status: response.status,
501
+ statusText: response.statusText,
502
+ data: response.data
503
+ }, "HttpService");
504
+ }
457
505
  return response;
458
506
  }, (error) => {
459
507
  this.logger.error("HTTP Response Error", {
@@ -696,14 +744,14 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
696
744
  */
697
745
  registerGlobalInterceptors() {
698
746
  this.client.interceptors.request.use((config) => {
699
- this.logger.log(`HTTP Request: ${config.method?.toUpperCase()} ${config.url}`);
747
+ this.logger.debug(`Server SDK HTTP Request: ${config.method?.toUpperCase()} ${config.url}`);
700
748
  return config;
701
749
  }, (error) => {
702
- this.logger.error("HTTP Request Error", error, "HttpService");
750
+ this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
703
751
  return Promise.reject(error);
704
752
  });
705
753
  this.client.interceptors.response.use((response) => {
706
- this.logger.log(`HTTP Response: ${response.status} ${response.url}`);
754
+ this.logger.debug(`Server SDK HTTP Response: ${response.status} ${response.url}`);
707
755
  return response;
708
756
  }, (error) => {
709
757
  const errorLog = {
@@ -711,7 +759,7 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
711
759
  statusText: error.response?.statusText,
712
760
  message: error.message
713
761
  };
714
- this.logger.error(`HTTP Response Error: ${error.config?.method?.toUpperCase()} ${error.config?.url} ${JSON.stringify(errorLog)}`);
762
+ this.logger.error(`Server SDK HTTP Response Error: ${error.config?.method?.toUpperCase()} ${error.config?.url} ${JSON.stringify(errorLog)}`);
715
763
  return Promise.reject(error);
716
764
  });
717
765
  }
@@ -722,6 +770,9 @@ PlatformHttpClientService = _ts_decorate8([
722
770
  _ts_metadata5("design:paramtypes", [])
723
771
  ], PlatformHttpClientService);
724
772
 
773
+ // src/modules/platform/config/feature-switch.ts
774
+ var DISABLE_DATAPASS = process.env.FORCE_FRAMEWORK_DISABLE_DATAPASS === "true";
775
+
725
776
  // src/modules/platform/module.ts
726
777
  var import_nestjs_authzpaas = require("@lark-apaas/nestjs-authzpaas");
727
778
  function _ts_decorate9(decorators, target, key, desc) {
@@ -759,34 +810,37 @@ var PlatformModule = class _PlatformModule {
759
810
  timeout: 5e3,
760
811
  maxRedirects: 5
761
812
  }),
762
- import_nestjs_datapaas.DataPaasModule.forRootAsync({
763
- imports: [
764
- import_config2.ConfigModule,
765
- import_nestjs_logger2.LoggerModule
766
- ],
767
- inject: [
768
- import_config2.ConfigService,
769
- import_nestjs_logger2.AppLogger
770
- ],
771
- useFactory: /* @__PURE__ */ __name(async (...args) => {
772
- const configService = args[0];
773
- const appLogger = args[1];
774
- const drizzleLogger = {
775
- logQuery(query, params) {
776
- appLogger.log?.("SQL Query " + JSON.stringify({
777
- query,
778
- params
779
- }), {
780
- source_type: "platform"
781
- }, "Database");
782
- }
783
- };
784
- return {
785
- connectionString: configService.get("app.databaseUrl") ?? "",
786
- logger: drizzleLogger
787
- };
788
- }, "useFactory")
789
- }),
813
+ // 读取环境变量判断是否启用 DataPaasModule
814
+ ...DISABLE_DATAPASS ? [] : [
815
+ import_nestjs_datapaas.DataPaasModule.forRootAsync({
816
+ imports: [
817
+ import_config2.ConfigModule,
818
+ import_nestjs_logger2.LoggerModule
819
+ ],
820
+ inject: [
821
+ import_config2.ConfigService,
822
+ import_nestjs_logger2.AppLogger
823
+ ],
824
+ useFactory: /* @__PURE__ */ __name(async (...args) => {
825
+ const configService = args[0];
826
+ const appLogger = args[1];
827
+ const drizzleLogger = {
828
+ logQuery(query, params) {
829
+ if (process.env.NODE_ENV === "development") {
830
+ appLogger.log?.("SQL Query " + JSON.stringify({
831
+ query,
832
+ params
833
+ }), "Database");
834
+ }
835
+ }
836
+ };
837
+ return {
838
+ connectionString: configService.get("app.databaseUrl") ?? "",
839
+ logger: drizzleLogger
840
+ };
841
+ }, "useFactory")
842
+ })
843
+ ],
790
844
  import_nestjs_authnpaas.AuthNPaasModule.forRoot(),
791
845
  import_nestjs_trigger.AutomationModule.forRoot(),
792
846
  import_nestjs_authzpaas.AuthZPaasModule.forRoot()
@@ -873,6 +927,7 @@ async function configureApp(app, perms = defaultPerms) {
873
927
  app.use((0, import_cookie_parser.default)());
874
928
  const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
875
929
  app.setGlobalPrefix(globalPrefix);
930
+ app.set("trust proxy", true);
876
931
  if (process.env.NODE_ENV !== "production" && perms.disableSwagger !== true) {
877
932
  try {
878
933
  await import_nestjs_openapi_devtools.DevToolsV2Module.mount(app, {
@@ -884,6 +939,7 @@ async function configureApp(app, perms = defaultPerms) {
884
939
  console.error("[OpenAPI] OpenAPI \u751F\u6210\u5931\u8D25:", err);
885
940
  }
886
941
  }
942
+ console.log("App Started Successfully.");
887
943
  }
888
944
  __name(configureApp, "configureApp");
889
945
 
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, loginUrl, userType } = 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
  loginUrl: loginUrl ?? "",
190
234
  userType: userType ?? "",
191
235
  tenantId
@@ -198,9 +242,9 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
198
242
  loginUrl: loginUrl ?? "",
199
243
  userType: userType ?? "",
200
244
  appId: appId ?? "",
201
- appName: appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528",
245
+ appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
202
246
  appAvatar: appInfo?.app_avatar ?? "",
203
- appDescription: appInfo?.app_description ?? ""
247
+ appDescription: safeEscape(appInfo?.app_description ?? "")
204
248
  };
205
249
  next();
206
250
  }
@@ -390,26 +434,30 @@ var HttpInterceptorService = class {
390
434
  setupInterceptors() {
391
435
  const axiosInstance = this.httpService.axiosRef;
392
436
  axiosInstance.interceptors.request.use((config) => {
393
- this.logger.log("HTTP Request", {
394
- method: config.method?.toUpperCase(),
395
- url: config.url,
396
- headers: config.headers,
397
- params: config.params,
398
- data: config.data
399
- }, "HttpService");
437
+ if (process.env.NODE_ENV === "development") {
438
+ this.logger.log("HTTP Request", {
439
+ method: config.method?.toUpperCase(),
440
+ url: config.url,
441
+ headers: config.headers,
442
+ params: config.params,
443
+ data: config.data
444
+ }, "HttpService");
445
+ }
400
446
  return config;
401
447
  }, (error) => {
402
448
  this.logger.error("HTTP Request Error", error, "HttpService");
403
449
  return Promise.reject(error);
404
450
  });
405
451
  axiosInstance.interceptors.response.use((response) => {
406
- this.logger.log("HTTP Response", {
407
- method: response.config.method?.toUpperCase(),
408
- url: response.config.url,
409
- status: response.status,
410
- statusText: response.statusText,
411
- data: response.data
412
- }, "HttpService");
452
+ if (process.env.NODE_ENV === "development") {
453
+ this.logger.log("HTTP Response", {
454
+ method: response.config.method?.toUpperCase(),
455
+ url: response.config.url,
456
+ status: response.status,
457
+ statusText: response.statusText,
458
+ data: response.data
459
+ }, "HttpService");
460
+ }
413
461
  return response;
414
462
  }, (error) => {
415
463
  this.logger.error("HTTP Response Error", {
@@ -652,14 +700,14 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
652
700
  */
653
701
  registerGlobalInterceptors() {
654
702
  this.client.interceptors.request.use((config) => {
655
- this.logger.log(`HTTP Request: ${config.method?.toUpperCase()} ${config.url}`);
703
+ this.logger.debug(`Server SDK HTTP Request: ${config.method?.toUpperCase()} ${config.url}`);
656
704
  return config;
657
705
  }, (error) => {
658
- this.logger.error("HTTP Request Error", error, "HttpService");
706
+ this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
659
707
  return Promise.reject(error);
660
708
  });
661
709
  this.client.interceptors.response.use((response) => {
662
- this.logger.log(`HTTP Response: ${response.status} ${response.url}`);
710
+ this.logger.debug(`Server SDK HTTP Response: ${response.status} ${response.url}`);
663
711
  return response;
664
712
  }, (error) => {
665
713
  const errorLog = {
@@ -667,7 +715,7 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
667
715
  statusText: error.response?.statusText,
668
716
  message: error.message
669
717
  };
670
- this.logger.error(`HTTP Response Error: ${error.config?.method?.toUpperCase()} ${error.config?.url} ${JSON.stringify(errorLog)}`);
718
+ this.logger.error(`Server SDK HTTP Response Error: ${error.config?.method?.toUpperCase()} ${error.config?.url} ${JSON.stringify(errorLog)}`);
671
719
  return Promise.reject(error);
672
720
  });
673
721
  }
@@ -678,6 +726,9 @@ PlatformHttpClientService = _ts_decorate8([
678
726
  _ts_metadata5("design:paramtypes", [])
679
727
  ], PlatformHttpClientService);
680
728
 
729
+ // src/modules/platform/config/feature-switch.ts
730
+ var DISABLE_DATAPASS = process.env.FORCE_FRAMEWORK_DISABLE_DATAPASS === "true";
731
+
681
732
  // src/modules/platform/module.ts
682
733
  import { AuthZPaasModule } from "@lark-apaas/nestjs-authzpaas";
683
734
  function _ts_decorate9(decorators, target, key, desc) {
@@ -715,34 +766,37 @@ var PlatformModule = class _PlatformModule {
715
766
  timeout: 5e3,
716
767
  maxRedirects: 5
717
768
  }),
718
- DataPaasModule.forRootAsync({
719
- imports: [
720
- ConfigModule,
721
- LoggerModule
722
- ],
723
- inject: [
724
- ConfigService,
725
- AppLogger2
726
- ],
727
- useFactory: /* @__PURE__ */ __name(async (...args) => {
728
- const configService = args[0];
729
- const appLogger = args[1];
730
- const drizzleLogger = {
731
- logQuery(query, params) {
732
- appLogger.log?.("SQL Query " + JSON.stringify({
733
- query,
734
- params
735
- }), {
736
- source_type: "platform"
737
- }, "Database");
738
- }
739
- };
740
- return {
741
- connectionString: configService.get("app.databaseUrl") ?? "",
742
- logger: drizzleLogger
743
- };
744
- }, "useFactory")
745
- }),
769
+ // 读取环境变量判断是否启用 DataPaasModule
770
+ ...DISABLE_DATAPASS ? [] : [
771
+ DataPaasModule.forRootAsync({
772
+ imports: [
773
+ ConfigModule,
774
+ LoggerModule
775
+ ],
776
+ inject: [
777
+ ConfigService,
778
+ AppLogger2
779
+ ],
780
+ useFactory: /* @__PURE__ */ __name(async (...args) => {
781
+ const configService = args[0];
782
+ const appLogger = args[1];
783
+ const drizzleLogger = {
784
+ logQuery(query, params) {
785
+ if (process.env.NODE_ENV === "development") {
786
+ appLogger.log?.("SQL Query " + JSON.stringify({
787
+ query,
788
+ params
789
+ }), "Database");
790
+ }
791
+ }
792
+ };
793
+ return {
794
+ connectionString: configService.get("app.databaseUrl") ?? "",
795
+ logger: drizzleLogger
796
+ };
797
+ }, "useFactory")
798
+ })
799
+ ],
746
800
  AuthNPaasModule.forRoot(),
747
801
  AutomationModule.forRoot(),
748
802
  AuthZPaasModule.forRoot()
@@ -829,6 +883,7 @@ async function configureApp(app, perms = defaultPerms) {
829
883
  app.use(cookieParser());
830
884
  const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
831
885
  app.setGlobalPrefix(globalPrefix);
886
+ app.set("trust proxy", true);
832
887
  if (process.env.NODE_ENV !== "production" && perms.disableSwagger !== true) {
833
888
  try {
834
889
  await DevToolsV2Module.mount(app, {
@@ -840,6 +895,7 @@ async function configureApp(app, perms = defaultPerms) {
840
895
  console.error("[OpenAPI] OpenAPI \u751F\u6210\u5931\u8D25:", err);
841
896
  }
842
897
  }
898
+ console.log("App Started Successfully.");
843
899
  }
844
900
  __name(configureApp, "configureApp");
845
901
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.1.10-alpha.33",
3
+ "version": "1.1.10-alpha.35",
4
4
  "description": "FullStack Nestjs Core",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -39,13 +39,13 @@
39
39
  "prepublishOnly": "npm run build"
40
40
  },
41
41
  "dependencies": {
42
- "@lark-apaas/http-client": "0.1.2",
42
+ "@lark-apaas/http-client": "^0.1.2",
43
43
  "@lark-apaas/nestjs-authnpaas": "^1.0.2",
44
- "@lark-apaas/nestjs-authzpaas": "0.1.0-alpha.33",
45
- "@lark-apaas/nestjs-common": "0.1.0-alpha.1",
46
- "@lark-apaas/nestjs-datapaas": "^1.0.6-alpha.5",
47
- "@lark-apaas/nestjs-logger": "1.0.2-alpha.33",
48
- "@lark-apaas/nestjs-observable": "0.0.1-alpha.35",
44
+ "@lark-apaas/nestjs-authzpaas": "0.1.0-alpha.35",
45
+ "@lark-apaas/nestjs-common": "^0.1.1",
46
+ "@lark-apaas/nestjs-datapaas": "^1.0.7",
47
+ "@lark-apaas/nestjs-logger": "^1.0.5",
48
+ "@lark-apaas/nestjs-observable": "^0.0.2",
49
49
  "@lark-apaas/nestjs-openapi-devtools": "^1.0.9",
50
50
  "@lark-apaas/nestjs-trigger": "^0.0.1",
51
51
  "@nestjs/axios": "^4.0.1",