@lark-apaas/fullstack-nestjs-core 1.1.48-alpha.13 → 1.1.48-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 CHANGED
@@ -34651,7 +34651,6 @@ 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);
34655
34654
  const appPublishedData = await this.getAppPublished(appId);
34656
34655
  const appInfo = appPublishedData?.app_info ?? null;
34657
34656
  req.__platform_data__ = {
@@ -34666,8 +34665,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34666
34665
  tenantId,
34667
34666
  environment,
34668
34667
  showBadge: appInfo?.show_badge !== false,
34669
- appPublished: appPublishedData ?? null,
34670
- basename
34668
+ appPublished: appPublishedData ?? null
34671
34669
  };
34672
34670
  res.locals = {
34673
34671
  ...res.locals ?? {},
@@ -34701,16 +34699,6 @@ function mapToWindowEnvironment(input) {
34701
34699
  return "online";
34702
34700
  }
34703
34701
  __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");
34714
34702
 
34715
34703
  // src/middlewares/csrf_token/index.ts
34716
34704
  var import_common4 = require("@nestjs/common");
@@ -35093,6 +35081,9 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35093
35081
  ...baseConfig,
35094
35082
  platform: {
35095
35083
  enabled: true
35084
+ },
35085
+ preInterceptors: {
35086
+ request: this.createClaimsPreInterceptors()
35096
35087
  }
35097
35088
  });
35098
35089
  this.protectedClient = new ProtectedHttpClient(this.client);
@@ -35167,7 +35158,10 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35167
35158
  };
35168
35159
  return new import_http_client.HttpClient({
35169
35160
  ...mergedConfig,
35170
- platform: mergedPlatform
35161
+ platform: mergedPlatform,
35162
+ preInterceptors: {
35163
+ request: this.createClaimsPreInterceptors()
35164
+ }
35171
35165
  });
35172
35166
  }
35173
35167
  /**
@@ -35195,6 +35189,36 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35195
35189
  this.registerInterceptorsForClient(client);
35196
35190
  return client;
35197
35191
  }
35192
+ createClaimsPreInterceptors() {
35193
+ return [
35194
+ {
35195
+ onFulfilled: /* @__PURE__ */ __name((config) => {
35196
+ const userId = this.requestContext.get("userId");
35197
+ const tenantId = this.requestContext.get("tenantId");
35198
+ const contextClaims = {};
35199
+ if (userId) {
35200
+ contextClaims.user_id = userId;
35201
+ }
35202
+ if (tenantId) {
35203
+ contextClaims.tenant_id = tenantId;
35204
+ }
35205
+ if (contextClaims.user_id === void 0 && contextClaims.tenant_id === void 0) {
35206
+ return config;
35207
+ }
35208
+ return {
35209
+ ...config,
35210
+ platformAuth: {
35211
+ ...config.platformAuth,
35212
+ customClaims: {
35213
+ ...contextClaims,
35214
+ ...config.platformAuth?.customClaims || {}
35215
+ }
35216
+ }
35217
+ };
35218
+ }, "onFulfilled")
35219
+ }
35220
+ ];
35221
+ }
35198
35222
  /**
35199
35223
  * 注册全局拦截器(用于单例实例)
35200
35224
  */
package/dist/index.d.cts CHANGED
@@ -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: {
@@ -387,6 +385,7 @@ declare class PlatformHttpClientService {
387
385
  * ```
388
386
  */
389
387
  createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
388
+ private createClaimsPreInterceptors;
390
389
  /**
391
390
  * 注册全局拦截器(用于单例实例)
392
391
  */
package/dist/index.d.ts CHANGED
@@ -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: {
@@ -387,6 +385,7 @@ declare class PlatformHttpClientService {
387
385
  * ```
388
386
  */
389
387
  createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
388
+ private createClaimsPreInterceptors;
390
389
  /**
391
390
  * 注册全局拦截器(用于单例实例)
392
391
  */
package/dist/index.js CHANGED
@@ -34624,7 +34624,6 @@ 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);
34628
34627
  const appPublishedData = await this.getAppPublished(appId);
34629
34628
  const appInfo = appPublishedData?.app_info ?? null;
34630
34629
  req.__platform_data__ = {
@@ -34639,8 +34638,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
34639
34638
  tenantId,
34640
34639
  environment,
34641
34640
  showBadge: appInfo?.show_badge !== false,
34642
- appPublished: appPublishedData ?? null,
34643
- basename
34641
+ appPublished: appPublishedData ?? null
34644
34642
  };
34645
34643
  res.locals = {
34646
34644
  ...res.locals ?? {},
@@ -34674,16 +34672,6 @@ function mapToWindowEnvironment(input) {
34674
34672
  return "online";
34675
34673
  }
34676
34674
  __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");
34687
34675
 
34688
34676
  // src/middlewares/csrf_token/index.ts
34689
34677
  import { Injectable as Injectable4 } from "@nestjs/common";
@@ -35066,6 +35054,9 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35066
35054
  ...baseConfig,
35067
35055
  platform: {
35068
35056
  enabled: true
35057
+ },
35058
+ preInterceptors: {
35059
+ request: this.createClaimsPreInterceptors()
35069
35060
  }
35070
35061
  });
35071
35062
  this.protectedClient = new ProtectedHttpClient(this.client);
@@ -35140,7 +35131,10 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35140
35131
  };
35141
35132
  return new HttpClient({
35142
35133
  ...mergedConfig,
35143
- platform: mergedPlatform
35134
+ platform: mergedPlatform,
35135
+ preInterceptors: {
35136
+ request: this.createClaimsPreInterceptors()
35137
+ }
35144
35138
  });
35145
35139
  }
35146
35140
  /**
@@ -35168,6 +35162,36 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35168
35162
  this.registerInterceptorsForClient(client);
35169
35163
  return client;
35170
35164
  }
35165
+ createClaimsPreInterceptors() {
35166
+ return [
35167
+ {
35168
+ onFulfilled: /* @__PURE__ */ __name((config) => {
35169
+ const userId = this.requestContext.get("userId");
35170
+ const tenantId = this.requestContext.get("tenantId");
35171
+ const contextClaims = {};
35172
+ if (userId) {
35173
+ contextClaims.user_id = userId;
35174
+ }
35175
+ if (tenantId) {
35176
+ contextClaims.tenant_id = tenantId;
35177
+ }
35178
+ if (contextClaims.user_id === void 0 && contextClaims.tenant_id === void 0) {
35179
+ return config;
35180
+ }
35181
+ return {
35182
+ ...config,
35183
+ platformAuth: {
35184
+ ...config.platformAuth,
35185
+ customClaims: {
35186
+ ...contextClaims,
35187
+ ...config.platformAuth?.customClaims || {}
35188
+ }
35189
+ }
35190
+ };
35191
+ }, "onFulfilled")
35192
+ }
35193
+ ];
35194
+ }
35171
35195
  /**
35172
35196
  * 注册全局拦截器(用于单例实例)
35173
35197
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.1.48-alpha.13",
3
+ "version": "1.1.48-alpha.15",
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.5",
43
+ "@lark-apaas/http-client": "0.1.6-alpha.2",
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",