@lark-apaas/fullstack-nestjs-core 1.1.50 → 1.1.51-alpha.0

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
@@ -34423,10 +34423,24 @@ __export(index_exports, {
34423
34423
  UserContextMiddleware: () => UserContextMiddleware,
34424
34424
  ViewContextMiddleware: () => ViewContextMiddleware,
34425
34425
  configureApp: () => configureApp,
34426
- createLegacyPathRedirectMiddleware: () => createLegacyPathRedirectMiddleware
34426
+ createLegacyPathRedirectMiddleware: () => createLegacyPathRedirectMiddleware,
34427
+ createLocalDevMiddleware: () => createLocalDevMiddleware,
34428
+ isLocalDev: () => isLocalDev
34427
34429
  });
34428
34430
  module.exports = __toCommonJS(index_exports);
34429
34431
 
34432
+ // src/load-env.ts
34433
+ try {
34434
+ const dotenv = require("dotenv");
34435
+ dotenv.config({
34436
+ path: ".env.local"
34437
+ });
34438
+ dotenv.config({
34439
+ path: ".env"
34440
+ });
34441
+ } catch {
34442
+ }
34443
+
34430
34444
  // src/modules/platform/module.ts
34431
34445
  var import_common16 = require("@nestjs/common");
34432
34446
  var import_core2 = require("@nestjs/core");
@@ -34553,7 +34567,7 @@ CsrfMiddleware = _ts_decorate2([
34553
34567
  (0, import_common2.Injectable)()
34554
34568
  ], CsrfMiddleware);
34555
34569
 
34556
- // src/middlewares/view-context/middleware.ts
34570
+ // src/middlewares/view-context/index.ts
34557
34571
  var import_common3 = require("@nestjs/common");
34558
34572
  var import_nestjs_common = require("@lark-apaas/nestjs-common");
34559
34573
 
@@ -34600,7 +34614,7 @@ function safeEscape(s) {
34600
34614
  }
34601
34615
  __name(safeEscape, "safeEscape");
34602
34616
 
34603
- // src/middlewares/view-context/middleware.ts
34617
+ // src/middlewares/view-context/index.ts
34604
34618
  function _ts_decorate3(decorators, target, key, desc) {
34605
34619
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
34606
34620
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -34651,7 +34665,6 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34651
34665
  const { userId, tenantId, appId, loginUrl, userType } = req.userContext;
34652
34666
  const csrfToken = req.csrfToken;
34653
34667
  const environment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
34654
- const basename = safeEscape(req.headers["x-miaoda-custom-host"] !== void 0 ? "/" : `/app/${appId || ""}`);
34655
34668
  const appPublishedData = await this.getAppPublished(appId);
34656
34669
  const appInfo = appPublishedData?.app_info ?? null;
34657
34670
  req.__platform_data__ = {
@@ -34666,8 +34679,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34666
34679
  tenantId,
34667
34680
  environment,
34668
34681
  showBadge: appInfo?.show_badge !== false,
34669
- appPublished: appPublishedData ?? null,
34670
- basename
34682
+ appPublished: appPublishedData ?? null
34671
34683
  };
34672
34684
  res.locals = {
34673
34685
  ...res.locals ?? {},
@@ -34680,8 +34692,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34680
34692
  appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
34681
34693
  appAvatar: appInfo?.app_avatar ?? "",
34682
34694
  appDescription: safeEscape(appInfo?.app_description ?? ""),
34683
- environment,
34684
- basename
34695
+ environment
34685
34696
  };
34686
34697
  next();
34687
34698
  }
@@ -36549,6 +36560,45 @@ function createLegacyPathRedirectMiddleware() {
36549
36560
  }
36550
36561
  __name(createLegacyPathRedirectMiddleware, "createLegacyPathRedirectMiddleware");
36551
36562
 
36563
+ // src/middlewares/local-dev/index.ts
36564
+ var CSRF_COOKIE_KEY = "suda-csrf-token";
36565
+ var CSRF_HEADER_KEY = "x-suda-csrf-token";
36566
+ var WEBUSER_HEADER_KEY = "x-larkgw-suda-webuser";
36567
+ function isLocalDev() {
36568
+ if (process.env.NODE_ENV === "production") return false;
36569
+ const flag = process.env.MIAODA_LOCAL_DEV;
36570
+ return flag === "1" || flag === "true";
36571
+ }
36572
+ __name(isLocalDev, "isLocalDev");
36573
+ function extractCsrfFromCookie(cookieHeader) {
36574
+ if (!cookieHeader) return void 0;
36575
+ const re = new RegExp(`(?:^|;\\s*)${CSRF_COOKIE_KEY}=([^;]+)`);
36576
+ const m = cookieHeader.match(re);
36577
+ return m?.[1];
36578
+ }
36579
+ __name(extractCsrfFromCookie, "extractCsrfFromCookie");
36580
+ function createLocalDevMiddleware() {
36581
+ let webUserHeader = "";
36582
+ if (process.env.SUDA_WEBUSER) {
36583
+ try {
36584
+ webUserHeader = encodeURIComponent(JSON.stringify(JSON.parse(process.env.SUDA_WEBUSER)));
36585
+ } catch {
36586
+ }
36587
+ }
36588
+ return /* @__PURE__ */ __name(function localDevMiddleware(req, _res, next) {
36589
+ const headers = req.headers;
36590
+ if (!headers[CSRF_HEADER_KEY]) {
36591
+ const token = extractCsrfFromCookie(req.headers.cookie);
36592
+ if (token) headers[CSRF_HEADER_KEY] = token;
36593
+ }
36594
+ if (webUserHeader && !headers[WEBUSER_HEADER_KEY]) {
36595
+ headers[WEBUSER_HEADER_KEY] = webUserHeader;
36596
+ }
36597
+ next();
36598
+ }, "localDevMiddleware");
36599
+ }
36600
+ __name(createLocalDevMiddleware, "createLocalDevMiddleware");
36601
+
36552
36602
  // src/setup.ts
36553
36603
  var DEFAULT_BODY_LIMIT = "1mb";
36554
36604
  var defaultPerms = {
@@ -36566,6 +36616,9 @@ async function configureApp(app, perms = defaultPerms) {
36566
36616
  extended: true
36567
36617
  }));
36568
36618
  app.use((0, import_cookie_parser.default)());
36619
+ if (isLocalDev()) {
36620
+ app.use(createLocalDevMiddleware());
36621
+ }
36569
36622
  app.use(createLegacyPathRedirectMiddleware());
36570
36623
  const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
36571
36624
  app.setGlobalPrefix(globalPrefix);
@@ -36617,6 +36670,8 @@ var import_nestjs_authzpaas2 = require("@lark-apaas/nestjs-authzpaas");
36617
36670
  ViewContextMiddleware,
36618
36671
  configureApp,
36619
36672
  createLegacyPathRedirectMiddleware,
36673
+ createLocalDevMiddleware,
36674
+ isLocalDev,
36620
36675
  ...require("@lark-apaas/nestjs-authnpaas"),
36621
36676
  ...require("@lark-apaas/nestjs-capability"),
36622
36677
  ...require("@lark-apaas/nestjs-datapaas"),
package/dist/index.d.cts CHANGED
@@ -6,7 +6,7 @@ import { NestExpressApplication } from '@nestjs/platform-express';
6
6
  import { PlatformHttpClient, RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
7
7
  export { AutoTrace } from '@lark-apaas/nestjs-common';
8
8
  export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
9
- import { Request, Response, NextFunction } from 'express';
9
+ import { Request, Response, NextFunction, RequestHandler } from 'express';
10
10
  import * as _lark_apaas_file_service from '@lark-apaas/file-service';
11
11
  import { FileBody, UploadOptions, FileDownloadBuilder, SearchOptions } from '@lark-apaas/file-service';
12
12
  export * from '@lark-apaas/file-service';
@@ -23,8 +23,6 @@ declare global {
23
23
  userId?: string;
24
24
  tenantId?: number;
25
25
  csrfToken?: string;
26
- /** React Router basename,由 ViewContextMiddleware 注入;自定义域名场景下 = / 或 /<alias>,默认域名 = /app/<appId> */
27
- basename?: string;
28
26
  [key: string]: unknown;
29
27
  };
30
28
  userContext: {
@@ -223,6 +221,9 @@ declare class ViewContextMiddleware implements NestMiddleware {
223
221
  */
224
222
  declare function createLegacyPathRedirectMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
225
223
 
224
+ declare function isLocalDev(): boolean;
225
+ declare function createLocalDevMiddleware(): RequestHandler;
226
+
226
227
  /**
227
228
  * API 404 响应格式
228
229
  */
@@ -404,4 +405,4 @@ declare class PlatformHttpClientService {
404
405
  private registerInterceptorsForClient;
405
406
  }
406
407
 
407
- export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware };
408
+ export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware, createLocalDevMiddleware, isLocalDev };
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import { NestExpressApplication } from '@nestjs/platform-express';
6
6
  import { PlatformHttpClient, RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
7
7
  export { AutoTrace } from '@lark-apaas/nestjs-common';
8
8
  export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
9
- import { Request, Response, NextFunction } from 'express';
9
+ import { Request, Response, NextFunction, RequestHandler } from 'express';
10
10
  import * as _lark_apaas_file_service from '@lark-apaas/file-service';
11
11
  import { FileBody, UploadOptions, FileDownloadBuilder, SearchOptions } from '@lark-apaas/file-service';
12
12
  export * from '@lark-apaas/file-service';
@@ -23,8 +23,6 @@ declare global {
23
23
  userId?: string;
24
24
  tenantId?: number;
25
25
  csrfToken?: string;
26
- /** React Router basename,由 ViewContextMiddleware 注入;自定义域名场景下 = / 或 /<alias>,默认域名 = /app/<appId> */
27
- basename?: string;
28
26
  [key: string]: unknown;
29
27
  };
30
28
  userContext: {
@@ -223,6 +221,9 @@ declare class ViewContextMiddleware implements NestMiddleware {
223
221
  */
224
222
  declare function createLegacyPathRedirectMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
225
223
 
224
+ declare function isLocalDev(): boolean;
225
+ declare function createLocalDevMiddleware(): RequestHandler;
226
+
226
227
  /**
227
228
  * API 404 响应格式
228
229
  */
@@ -404,4 +405,4 @@ declare class PlatformHttpClientService {
404
405
  private registerInterceptorsForClient;
405
406
  }
406
407
 
407
- export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware };
408
+ export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware, createLocalDevMiddleware, isLocalDev };
package/dist/index.js CHANGED
@@ -34400,6 +34400,18 @@ var require_express2 = __commonJS({
34400
34400
  }
34401
34401
  });
34402
34402
 
34403
+ // src/load-env.ts
34404
+ try {
34405
+ const dotenv = __require("dotenv");
34406
+ dotenv.config({
34407
+ path: ".env.local"
34408
+ });
34409
+ dotenv.config({
34410
+ path: ".env"
34411
+ });
34412
+ } catch {
34413
+ }
34414
+
34403
34415
  // src/modules/platform/module.ts
34404
34416
  import { Global, Module as Module3, ValidationPipe } from "@nestjs/common";
34405
34417
  import { APP_INTERCEPTOR, APP_PIPE } from "@nestjs/core";
@@ -34526,7 +34538,7 @@ CsrfMiddleware = _ts_decorate2([
34526
34538
  Injectable2()
34527
34539
  ], CsrfMiddleware);
34528
34540
 
34529
- // src/middlewares/view-context/middleware.ts
34541
+ // src/middlewares/view-context/index.ts
34530
34542
  import { Inject, Injectable as Injectable3, Logger } from "@nestjs/common";
34531
34543
  import { PLATFORM_HTTP_CLIENT } from "@lark-apaas/nestjs-common";
34532
34544
 
@@ -34573,7 +34585,7 @@ function safeEscape(s) {
34573
34585
  }
34574
34586
  __name(safeEscape, "safeEscape");
34575
34587
 
34576
- // src/middlewares/view-context/middleware.ts
34588
+ // src/middlewares/view-context/index.ts
34577
34589
  function _ts_decorate3(decorators, target, key, desc) {
34578
34590
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
34579
34591
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -34624,7 +34636,6 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34624
34636
  const { userId, tenantId, appId, loginUrl, userType } = req.userContext;
34625
34637
  const csrfToken = req.csrfToken;
34626
34638
  const environment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
34627
- const basename = safeEscape(req.headers["x-miaoda-custom-host"] !== void 0 ? "/" : `/app/${appId || ""}`);
34628
34639
  const appPublishedData = await this.getAppPublished(appId);
34629
34640
  const appInfo = appPublishedData?.app_info ?? null;
34630
34641
  req.__platform_data__ = {
@@ -34639,8 +34650,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34639
34650
  tenantId,
34640
34651
  environment,
34641
34652
  showBadge: appInfo?.show_badge !== false,
34642
- appPublished: appPublishedData ?? null,
34643
- basename
34653
+ appPublished: appPublishedData ?? null
34644
34654
  };
34645
34655
  res.locals = {
34646
34656
  ...res.locals ?? {},
@@ -34653,8 +34663,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34653
34663
  appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
34654
34664
  appAvatar: appInfo?.app_avatar ?? "",
34655
34665
  appDescription: safeEscape(appInfo?.app_description ?? ""),
34656
- environment,
34657
- basename
34666
+ environment
34658
34667
  };
34659
34668
  next();
34660
34669
  }
@@ -36522,6 +36531,45 @@ function createLegacyPathRedirectMiddleware() {
36522
36531
  }
36523
36532
  __name(createLegacyPathRedirectMiddleware, "createLegacyPathRedirectMiddleware");
36524
36533
 
36534
+ // src/middlewares/local-dev/index.ts
36535
+ var CSRF_COOKIE_KEY = "suda-csrf-token";
36536
+ var CSRF_HEADER_KEY = "x-suda-csrf-token";
36537
+ var WEBUSER_HEADER_KEY = "x-larkgw-suda-webuser";
36538
+ function isLocalDev() {
36539
+ if (process.env.NODE_ENV === "production") return false;
36540
+ const flag = process.env.MIAODA_LOCAL_DEV;
36541
+ return flag === "1" || flag === "true";
36542
+ }
36543
+ __name(isLocalDev, "isLocalDev");
36544
+ function extractCsrfFromCookie(cookieHeader) {
36545
+ if (!cookieHeader) return void 0;
36546
+ const re = new RegExp(`(?:^|;\\s*)${CSRF_COOKIE_KEY}=([^;]+)`);
36547
+ const m = cookieHeader.match(re);
36548
+ return m?.[1];
36549
+ }
36550
+ __name(extractCsrfFromCookie, "extractCsrfFromCookie");
36551
+ function createLocalDevMiddleware() {
36552
+ let webUserHeader = "";
36553
+ if (process.env.SUDA_WEBUSER) {
36554
+ try {
36555
+ webUserHeader = encodeURIComponent(JSON.stringify(JSON.parse(process.env.SUDA_WEBUSER)));
36556
+ } catch {
36557
+ }
36558
+ }
36559
+ return /* @__PURE__ */ __name(function localDevMiddleware(req, _res, next) {
36560
+ const headers = req.headers;
36561
+ if (!headers[CSRF_HEADER_KEY]) {
36562
+ const token = extractCsrfFromCookie(req.headers.cookie);
36563
+ if (token) headers[CSRF_HEADER_KEY] = token;
36564
+ }
36565
+ if (webUserHeader && !headers[WEBUSER_HEADER_KEY]) {
36566
+ headers[WEBUSER_HEADER_KEY] = webUserHeader;
36567
+ }
36568
+ next();
36569
+ }, "localDevMiddleware");
36570
+ }
36571
+ __name(createLocalDevMiddleware, "createLocalDevMiddleware");
36572
+
36525
36573
  // src/setup.ts
36526
36574
  var DEFAULT_BODY_LIMIT = "1mb";
36527
36575
  var defaultPerms = {
@@ -36539,6 +36587,9 @@ async function configureApp(app, perms = defaultPerms) {
36539
36587
  extended: true
36540
36588
  }));
36541
36589
  app.use(cookieParser());
36590
+ if (isLocalDev()) {
36591
+ app.use(createLocalDevMiddleware());
36592
+ }
36542
36593
  app.use(createLegacyPathRedirectMiddleware());
36543
36594
  const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
36544
36595
  app.setGlobalPrefix(globalPrefix);
@@ -36588,7 +36639,9 @@ export {
36588
36639
  UserContextMiddleware,
36589
36640
  ViewContextMiddleware,
36590
36641
  configureApp,
36591
- createLegacyPathRedirectMiddleware
36642
+ createLegacyPathRedirectMiddleware,
36643
+ createLocalDevMiddleware,
36644
+ isLocalDev
36592
36645
  };
36593
36646
  /*! Bundled license information:
36594
36647
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.1.50",
3
+ "version": "1.1.51-alpha.0",
4
4
  "description": "FullStack Nestjs Core",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@lark-apaas/file-service": "^0.1.2",
43
- "@lark-apaas/http-client": "^0.1.6",
43
+ "@lark-apaas/http-client": "0.1.7-alpha.0",
44
44
  "@lark-apaas/nestjs-authnpaas": "^1.0.3",
45
45
  "@lark-apaas/nestjs-authzpaas": "^0.1.8",
46
46
  "@lark-apaas/nestjs-capability": "^0.1.13",
@@ -52,7 +52,8 @@
52
52
  "@lark-apaas/nestjs-trigger": "^0.0.3",
53
53
  "@nestjs/axios": "^4.0.1",
54
54
  "axios": "^1.13.2",
55
- "cookie-parser": "^1.4.7"
55
+ "cookie-parser": "^1.4.7",
56
+ "dotenv": "^16.4.5"
56
57
  },
57
58
  "devDependencies": {
58
59
  "@nestjs/common": "^10.4.20",