@lark-apaas/fullstack-nestjs-core 1.1.48-alpha.11 → 1.1.48-alpha.13

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
@@ -5492,9 +5492,9 @@ var require_read = __commonJS({
5492
5492
  }
5493
5493
  });
5494
5494
 
5495
- // ../../../node_modules/type-is/node_modules/media-typer/index.js
5495
+ // ../../../node_modules/media-typer/index.js
5496
5496
  var require_media_typer = __commonJS({
5497
- "../../../node_modules/type-is/node_modules/media-typer/index.js"(exports2) {
5497
+ "../../../node_modules/media-typer/index.js"(exports2) {
5498
5498
  "use strict";
5499
5499
  var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u0020-\u007e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g;
5500
5500
  var textRegExp = /^[\u0020-\u007e\u0080-\u00ff]+$/;
@@ -34651,6 +34651,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34651
34651
  const { userId, tenantId, appId, loginUrl, userType } = req.userContext;
34652
34652
  const csrfToken = req.csrfToken;
34653
34653
  const environment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
34654
+ const basename = resolveBasename(req, appId);
34654
34655
  const appPublishedData = await this.getAppPublished(appId);
34655
34656
  const appInfo = appPublishedData?.app_info ?? null;
34656
34657
  req.__platform_data__ = {
@@ -34665,7 +34666,8 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34665
34666
  tenantId,
34666
34667
  environment,
34667
34668
  showBadge: appInfo?.show_badge !== false,
34668
- appPublished: appPublishedData ?? null
34669
+ appPublished: appPublishedData ?? null,
34670
+ basename
34669
34671
  };
34670
34672
  res.locals = {
34671
34673
  ...res.locals ?? {},
@@ -34699,6 +34701,16 @@ function mapToWindowEnvironment(input) {
34699
34701
  return "online";
34700
34702
  }
34701
34703
  __name(mapToWindowEnvironment, "mapToWindowEnvironment");
34704
+ var CUSTOM_DOMAINS = new Set((process.env.CUSTOM_DOMAINS || "").split(",").map((d) => d.trim()).filter(Boolean));
34705
+ function resolveBasename(req, appId) {
34706
+ const headerValue = req.headers["x-app-basename"];
34707
+ if (typeof headerValue === "string" && headerValue) return headerValue;
34708
+ if (CUSTOM_DOMAINS.size > 0 && CUSTOM_DOMAINS.has(req.hostname)) {
34709
+ return "/";
34710
+ }
34711
+ return appId ? `/app/${appId}` : "/";
34712
+ }
34713
+ __name(resolveBasename, "resolveBasename");
34702
34714
 
34703
34715
  // src/middlewares/csrf_token/index.ts
34704
34716
  var import_common4 = require("@nestjs/common");
@@ -34946,8 +34958,7 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
34946
34958
  return {
34947
34959
  host: process.env.SERVER_HOST ?? "localhost",
34948
34960
  port: Number(process.env.SERVER_PORT ?? 3e3),
34949
- clientBasePath: process.env.CLIENT_BASE_PATH ?? "/",
34950
- databaseUrl: process.env.SUDA_DATABASE_URL ?? ""
34961
+ clientBasePath: process.env.CLIENT_BASE_PATH ?? "/"
34951
34962
  };
34952
34963
  });
34953
34964
 
@@ -35082,9 +35093,6 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35082
35093
  ...baseConfig,
35083
35094
  platform: {
35084
35095
  enabled: true
35085
- },
35086
- preInterceptors: {
35087
- request: this.createClaimsPreInterceptors()
35088
35096
  }
35089
35097
  });
35090
35098
  this.protectedClient = new ProtectedHttpClient(this.client);
@@ -35159,10 +35167,7 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35159
35167
  };
35160
35168
  return new import_http_client.HttpClient({
35161
35169
  ...mergedConfig,
35162
- platform: mergedPlatform,
35163
- preInterceptors: {
35164
- request: this.createClaimsPreInterceptors()
35165
- }
35170
+ platform: mergedPlatform
35166
35171
  });
35167
35172
  }
35168
35173
  /**
@@ -35190,36 +35195,6 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35190
35195
  this.registerInterceptorsForClient(client);
35191
35196
  return client;
35192
35197
  }
35193
- createClaimsPreInterceptors() {
35194
- return [
35195
- {
35196
- onFulfilled: /* @__PURE__ */ __name((config) => {
35197
- const userId = this.requestContext.get("userId");
35198
- const tenantId = this.requestContext.get("tenantId");
35199
- const contextClaims = {};
35200
- if (userId) {
35201
- contextClaims.user_id = userId;
35202
- }
35203
- if (tenantId) {
35204
- contextClaims.tenant_id = tenantId;
35205
- }
35206
- if (contextClaims.user_id === void 0 && contextClaims.tenant_id === void 0) {
35207
- return config;
35208
- }
35209
- return {
35210
- ...config,
35211
- platformAuth: {
35212
- ...config.platformAuth,
35213
- customClaims: {
35214
- ...contextClaims,
35215
- ...config.platformAuth?.customClaims || {}
35216
- }
35217
- }
35218
- };
35219
- }, "onFulfilled")
35220
- }
35221
- ];
35222
- }
35223
35198
  /**
35224
35199
  * 注册全局拦截器(用于单例实例)
35225
35200
  */
@@ -36374,16 +36349,13 @@ var PlatformModule = class _PlatformModule {
36374
36349
  ...DISABLE_DATAPASS ? [] : [
36375
36350
  import_nestjs_datapaas.DataPaasModule.forRootAsync({
36376
36351
  imports: [
36377
- import_config2.ConfigModule,
36378
36352
  import_nestjs_logger2.LoggerModule
36379
36353
  ],
36380
36354
  inject: [
36381
- import_config2.ConfigService,
36382
36355
  import_nestjs_logger2.AppLogger
36383
36356
  ],
36384
36357
  useFactory: /* @__PURE__ */ __name(async (...args) => {
36385
- const configService = args[0];
36386
- const appLogger = args[1];
36358
+ const appLogger = args[0];
36387
36359
  const drizzleLogger = {
36388
36360
  logQuery(query, params) {
36389
36361
  if (process.env.NODE_ENV === "development") {
@@ -36395,7 +36367,7 @@ var PlatformModule = class _PlatformModule {
36395
36367
  }
36396
36368
  };
36397
36369
  return {
36398
- connectionString: configService.get("app.databaseUrl") ?? "",
36370
+ connectionString: process.env.SUDA_DATABASE_URL ?? "",
36399
36371
  logger: drizzleLogger,
36400
36372
  connectionTokenFilePath: "/var/run/secrets/zti/credential"
36401
36373
  };
package/dist/index.d.cts CHANGED
@@ -23,6 +23,8 @@ 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;
26
28
  [key: string]: unknown;
27
29
  };
28
30
  userContext: {
@@ -385,7 +387,6 @@ declare class PlatformHttpClientService {
385
387
  * ```
386
388
  */
387
389
  createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
388
- private createClaimsPreInterceptors;
389
390
  /**
390
391
  * 注册全局拦截器(用于单例实例)
391
392
  */
package/dist/index.d.ts CHANGED
@@ -23,6 +23,8 @@ 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;
26
28
  [key: string]: unknown;
27
29
  };
28
30
  userContext: {
@@ -385,7 +387,6 @@ declare class PlatformHttpClientService {
385
387
  * ```
386
388
  */
387
389
  createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
388
- private createClaimsPreInterceptors;
389
390
  /**
390
391
  * 注册全局拦截器(用于单例实例)
391
392
  */
package/dist/index.js CHANGED
@@ -5491,9 +5491,9 @@ var require_read = __commonJS({
5491
5491
  }
5492
5492
  });
5493
5493
 
5494
- // ../../../node_modules/type-is/node_modules/media-typer/index.js
5494
+ // ../../../node_modules/media-typer/index.js
5495
5495
  var require_media_typer = __commonJS({
5496
- "../../../node_modules/type-is/node_modules/media-typer/index.js"(exports) {
5496
+ "../../../node_modules/media-typer/index.js"(exports) {
5497
5497
  "use strict";
5498
5498
  var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u0020-\u007e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g;
5499
5499
  var textRegExp = /^[\u0020-\u007e\u0080-\u00ff]+$/;
@@ -34404,7 +34404,7 @@ var require_express2 = __commonJS({
34404
34404
  import { Global, Module as Module3, ValidationPipe } from "@nestjs/common";
34405
34405
  import { APP_INTERCEPTOR, APP_PIPE } from "@nestjs/core";
34406
34406
  import { CommonModule, OBSERVABLE_SERVICE as OBSERVABLE_SERVICE2, HTTP_CLIENT_FACTORY } from "@lark-apaas/nestjs-common";
34407
- import { ConfigModule, ConfigService } from "@nestjs/config";
34407
+ import { ConfigModule } from "@nestjs/config";
34408
34408
  import { NestjsObservableModule as ObservableModule, Observable, ObservableTraceMiddleware, TraceInterceptor } from "@lark-apaas/nestjs-observable";
34409
34409
  import { HttpModule } from "@nestjs/axios";
34410
34410
  import { LoggerModule, AppLogger as AppLogger2, LoggerContextMiddleware } from "@lark-apaas/nestjs-logger";
@@ -34624,6 +34624,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34624
34624
  const { userId, tenantId, appId, loginUrl, userType } = req.userContext;
34625
34625
  const csrfToken = req.csrfToken;
34626
34626
  const environment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
34627
+ const basename = resolveBasename(req, appId);
34627
34628
  const appPublishedData = await this.getAppPublished(appId);
34628
34629
  const appInfo = appPublishedData?.app_info ?? null;
34629
34630
  req.__platform_data__ = {
@@ -34638,7 +34639,8 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34638
34639
  tenantId,
34639
34640
  environment,
34640
34641
  showBadge: appInfo?.show_badge !== false,
34641
- appPublished: appPublishedData ?? null
34642
+ appPublished: appPublishedData ?? null,
34643
+ basename
34642
34644
  };
34643
34645
  res.locals = {
34644
34646
  ...res.locals ?? {},
@@ -34672,6 +34674,16 @@ function mapToWindowEnvironment(input) {
34672
34674
  return "online";
34673
34675
  }
34674
34676
  __name(mapToWindowEnvironment, "mapToWindowEnvironment");
34677
+ var CUSTOM_DOMAINS = new Set((process.env.CUSTOM_DOMAINS || "").split(",").map((d) => d.trim()).filter(Boolean));
34678
+ function resolveBasename(req, appId) {
34679
+ const headerValue = req.headers["x-app-basename"];
34680
+ if (typeof headerValue === "string" && headerValue) return headerValue;
34681
+ if (CUSTOM_DOMAINS.size > 0 && CUSTOM_DOMAINS.has(req.hostname)) {
34682
+ return "/";
34683
+ }
34684
+ return appId ? `/app/${appId}` : "/";
34685
+ }
34686
+ __name(resolveBasename, "resolveBasename");
34675
34687
 
34676
34688
  // src/middlewares/csrf_token/index.ts
34677
34689
  import { Injectable as Injectable4 } from "@nestjs/common";
@@ -34919,8 +34931,7 @@ var app_config_default = registerAs(NAMESPACE, () => {
34919
34931
  return {
34920
34932
  host: process.env.SERVER_HOST ?? "localhost",
34921
34933
  port: Number(process.env.SERVER_PORT ?? 3e3),
34922
- clientBasePath: process.env.CLIENT_BASE_PATH ?? "/",
34923
- databaseUrl: process.env.SUDA_DATABASE_URL ?? ""
34934
+ clientBasePath: process.env.CLIENT_BASE_PATH ?? "/"
34924
34935
  };
34925
34936
  });
34926
34937
 
@@ -35055,9 +35066,6 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35055
35066
  ...baseConfig,
35056
35067
  platform: {
35057
35068
  enabled: true
35058
- },
35059
- preInterceptors: {
35060
- request: this.createClaimsPreInterceptors()
35061
35069
  }
35062
35070
  });
35063
35071
  this.protectedClient = new ProtectedHttpClient(this.client);
@@ -35132,10 +35140,7 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35132
35140
  };
35133
35141
  return new HttpClient({
35134
35142
  ...mergedConfig,
35135
- platform: mergedPlatform,
35136
- preInterceptors: {
35137
- request: this.createClaimsPreInterceptors()
35138
- }
35143
+ platform: mergedPlatform
35139
35144
  });
35140
35145
  }
35141
35146
  /**
@@ -35163,36 +35168,6 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35163
35168
  this.registerInterceptorsForClient(client);
35164
35169
  return client;
35165
35170
  }
35166
- createClaimsPreInterceptors() {
35167
- return [
35168
- {
35169
- onFulfilled: /* @__PURE__ */ __name((config) => {
35170
- const userId = this.requestContext.get("userId");
35171
- const tenantId = this.requestContext.get("tenantId");
35172
- const contextClaims = {};
35173
- if (userId) {
35174
- contextClaims.user_id = userId;
35175
- }
35176
- if (tenantId) {
35177
- contextClaims.tenant_id = tenantId;
35178
- }
35179
- if (contextClaims.user_id === void 0 && contextClaims.tenant_id === void 0) {
35180
- return config;
35181
- }
35182
- return {
35183
- ...config,
35184
- platformAuth: {
35185
- ...config.platformAuth,
35186
- customClaims: {
35187
- ...contextClaims,
35188
- ...config.platformAuth?.customClaims || {}
35189
- }
35190
- }
35191
- };
35192
- }, "onFulfilled")
35193
- }
35194
- ];
35195
- }
35196
35171
  /**
35197
35172
  * 注册全局拦截器(用于单例实例)
35198
35173
  */
@@ -36347,16 +36322,13 @@ var PlatformModule = class _PlatformModule {
36347
36322
  ...DISABLE_DATAPASS ? [] : [
36348
36323
  DataPaasModule.forRootAsync({
36349
36324
  imports: [
36350
- ConfigModule,
36351
36325
  LoggerModule
36352
36326
  ],
36353
36327
  inject: [
36354
- ConfigService,
36355
36328
  AppLogger2
36356
36329
  ],
36357
36330
  useFactory: /* @__PURE__ */ __name(async (...args) => {
36358
- const configService = args[0];
36359
- const appLogger = args[1];
36331
+ const appLogger = args[0];
36360
36332
  const drizzleLogger = {
36361
36333
  logQuery(query, params) {
36362
36334
  if (process.env.NODE_ENV === "development") {
@@ -36368,7 +36340,7 @@ var PlatformModule = class _PlatformModule {
36368
36340
  }
36369
36341
  };
36370
36342
  return {
36371
- connectionString: configService.get("app.databaseUrl") ?? "",
36343
+ connectionString: process.env.SUDA_DATABASE_URL ?? "",
36372
36344
  logger: drizzleLogger,
36373
36345
  connectionTokenFilePath: "/var/run/secrets/zti/credential"
36374
36346
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.1.48-alpha.11",
3
+ "version": "1.1.48-alpha.13",
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-alpha.1",
43
+ "@lark-apaas/http-client": "^0.1.5",
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",