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

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
@@ -35073,9 +35073,6 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35073
35073
  client;
35074
35074
  protectedClient;
35075
35075
  logger = new import_common8.Logger(_PlatformHttpClientService.name);
35076
- defaultPlatformConfig = {
35077
- enabled: true
35078
- };
35079
35076
  constructor(requestContext) {
35080
35077
  this.requestContext = requestContext;
35081
35078
  const baseConfig = {
@@ -35083,11 +35080,15 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35083
35080
  };
35084
35081
  this.client = new import_http_client.HttpClient({
35085
35082
  ...baseConfig,
35086
- baseURL: (0, import_http_client.resolvePlatformBaseURL)(this.defaultPlatformConfig)
35083
+ platform: {
35084
+ enabled: true
35085
+ },
35086
+ preInterceptors: {
35087
+ request: this.createClaimsPreInterceptors()
35088
+ }
35087
35089
  });
35088
35090
  this.protectedClient = new ProtectedHttpClient(this.client);
35089
35091
  this.registerGlobalInterceptors();
35090
- this.registerPlatformPluginForClient(this.client, this.defaultPlatformConfig);
35091
35092
  }
35092
35093
  /**
35093
35094
  * 获取受保护的 HttpClient 实例(推荐)
@@ -35153,10 +35154,16 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35153
35154
  ...options?.config
35154
35155
  };
35155
35156
  const mergedPlatform = {
35156
- ...this.defaultPlatformConfig,
35157
+ enabled: true,
35157
35158
  ...options?.platform
35158
35159
  };
35159
- return this.createClientWithPlatform(mergedConfig, mergedPlatform);
35160
+ return new import_http_client.HttpClient({
35161
+ ...mergedConfig,
35162
+ platform: mergedPlatform,
35163
+ preInterceptors: {
35164
+ request: this.createClaimsPreInterceptors()
35165
+ }
35166
+ });
35160
35167
  }
35161
35168
  /**
35162
35169
  * 创建一个带全局拦截器的独立 HttpClient 实例
@@ -35183,23 +35190,42 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35183
35190
  this.registerInterceptorsForClient(client);
35184
35191
  return client;
35185
35192
  }
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
+ }
35186
35223
  /**
35187
35224
  * 注册全局拦截器(用于单例实例)
35188
35225
  */
35189
35226
  registerGlobalInterceptors() {
35190
35227
  this.registerInterceptorsForClient(this.client);
35191
35228
  }
35192
- createClientWithPlatform(config, platform) {
35193
- const client = new import_http_client.HttpClient({
35194
- ...config,
35195
- baseURL: (0, import_http_client.resolvePlatformBaseURL)(platform)
35196
- });
35197
- this.registerPlatformPluginForClient(client, platform);
35198
- return client;
35199
- }
35200
- registerPlatformPluginForClient(client, platform) {
35201
- (0, import_http_client.registerPlatformPlugin)(client.interceptors, platform);
35202
- }
35203
35229
  /**
35204
35230
  * 为指定的 HttpClient 实例注册标准拦截器
35205
35231
  *
@@ -35219,30 +35245,6 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35219
35245
  "x-tt-env": ttEnv
35220
35246
  };
35221
35247
  }
35222
- const userIdRaw = this.requestContext.get("userId");
35223
- const tenantIdRaw = this.requestContext.get("tenantId");
35224
- const contextClaims = {};
35225
- if (userIdRaw !== void 0 && userIdRaw !== "") {
35226
- const userIdNum = typeof userIdRaw === "number" ? userIdRaw : Number(userIdRaw);
35227
- if (Number.isFinite(userIdNum)) {
35228
- contextClaims.user_id = userIdNum;
35229
- }
35230
- }
35231
- if (tenantIdRaw !== void 0 && tenantIdRaw !== "") {
35232
- const tenantIdNum = typeof tenantIdRaw === "number" ? tenantIdRaw : Number(tenantIdRaw);
35233
- if (Number.isFinite(tenantIdNum)) {
35234
- contextClaims.tenant_id = tenantIdNum;
35235
- }
35236
- }
35237
- if (contextClaims.user_id !== void 0 || contextClaims.tenant_id !== void 0) {
35238
- config.platformAuth = {
35239
- ...config.platformAuth,
35240
- customClaims: {
35241
- ...contextClaims,
35242
- ...config.platformAuth?.customClaims || {}
35243
- }
35244
- };
35245
- }
35246
35248
  return config;
35247
35249
  }, (error) => {
35248
35250
  this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
package/dist/index.d.cts CHANGED
@@ -308,7 +308,6 @@ declare class PlatformHttpClientService {
308
308
  private readonly client;
309
309
  private readonly protectedClient;
310
310
  private readonly logger;
311
- private readonly defaultPlatformConfig;
312
311
  constructor(requestContext: RequestContextService);
313
312
  /**
314
313
  * 获取受保护的 HttpClient 实例(推荐)
@@ -386,12 +385,11 @@ declare class PlatformHttpClientService {
386
385
  * ```
387
386
  */
388
387
  createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
388
+ private createClaimsPreInterceptors;
389
389
  /**
390
390
  * 注册全局拦截器(用于单例实例)
391
391
  */
392
392
  private registerGlobalInterceptors;
393
- private createClientWithPlatform;
394
- private registerPlatformPluginForClient;
395
393
  /**
396
394
  * 为指定的 HttpClient 实例注册标准拦截器
397
395
  *
package/dist/index.d.ts CHANGED
@@ -308,7 +308,6 @@ declare class PlatformHttpClientService {
308
308
  private readonly client;
309
309
  private readonly protectedClient;
310
310
  private readonly logger;
311
- private readonly defaultPlatformConfig;
312
311
  constructor(requestContext: RequestContextService);
313
312
  /**
314
313
  * 获取受保护的 HttpClient 实例(推荐)
@@ -386,12 +385,11 @@ declare class PlatformHttpClientService {
386
385
  * ```
387
386
  */
388
387
  createWithGlobalInterceptors(options?: PlatformHttpClientOptions): HttpClient;
388
+ private createClaimsPreInterceptors;
389
389
  /**
390
390
  * 注册全局拦截器(用于单例实例)
391
391
  */
392
392
  private registerGlobalInterceptors;
393
- private createClientWithPlatform;
394
- private registerPlatformPluginForClient;
395
393
  /**
396
394
  * 为指定的 HttpClient 实例注册标准拦截器
397
395
  *
package/dist/index.js CHANGED
@@ -34998,7 +34998,7 @@ FrameworkDebugMiddleware = _ts_decorate7([
34998
34998
 
34999
34999
  // src/services/platform-http-client.service.ts
35000
35000
  import { Injectable as Injectable8, Logger as Logger2 } from "@nestjs/common";
35001
- import { HttpClient, registerPlatformPlugin, resolvePlatformBaseURL } from "@lark-apaas/http-client";
35001
+ import { HttpClient } from "@lark-apaas/http-client";
35002
35002
  import { RequestContextService as RequestContextService2 } from "@lark-apaas/nestjs-common";
35003
35003
  function _ts_decorate8(decorators, target, key, desc) {
35004
35004
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -35046,9 +35046,6 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35046
35046
  client;
35047
35047
  protectedClient;
35048
35048
  logger = new Logger2(_PlatformHttpClientService.name);
35049
- defaultPlatformConfig = {
35050
- enabled: true
35051
- };
35052
35049
  constructor(requestContext) {
35053
35050
  this.requestContext = requestContext;
35054
35051
  const baseConfig = {
@@ -35056,11 +35053,15 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35056
35053
  };
35057
35054
  this.client = new HttpClient({
35058
35055
  ...baseConfig,
35059
- baseURL: resolvePlatformBaseURL(this.defaultPlatformConfig)
35056
+ platform: {
35057
+ enabled: true
35058
+ },
35059
+ preInterceptors: {
35060
+ request: this.createClaimsPreInterceptors()
35061
+ }
35060
35062
  });
35061
35063
  this.protectedClient = new ProtectedHttpClient(this.client);
35062
35064
  this.registerGlobalInterceptors();
35063
- this.registerPlatformPluginForClient(this.client, this.defaultPlatformConfig);
35064
35065
  }
35065
35066
  /**
35066
35067
  * 获取受保护的 HttpClient 实例(推荐)
@@ -35126,10 +35127,16 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35126
35127
  ...options?.config
35127
35128
  };
35128
35129
  const mergedPlatform = {
35129
- ...this.defaultPlatformConfig,
35130
+ enabled: true,
35130
35131
  ...options?.platform
35131
35132
  };
35132
- return this.createClientWithPlatform(mergedConfig, mergedPlatform);
35133
+ return new HttpClient({
35134
+ ...mergedConfig,
35135
+ platform: mergedPlatform,
35136
+ preInterceptors: {
35137
+ request: this.createClaimsPreInterceptors()
35138
+ }
35139
+ });
35133
35140
  }
35134
35141
  /**
35135
35142
  * 创建一个带全局拦截器的独立 HttpClient 实例
@@ -35156,23 +35163,42 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35156
35163
  this.registerInterceptorsForClient(client);
35157
35164
  return client;
35158
35165
  }
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
+ }
35159
35196
  /**
35160
35197
  * 注册全局拦截器(用于单例实例)
35161
35198
  */
35162
35199
  registerGlobalInterceptors() {
35163
35200
  this.registerInterceptorsForClient(this.client);
35164
35201
  }
35165
- createClientWithPlatform(config, platform) {
35166
- const client = new HttpClient({
35167
- ...config,
35168
- baseURL: resolvePlatformBaseURL(platform)
35169
- });
35170
- this.registerPlatformPluginForClient(client, platform);
35171
- return client;
35172
- }
35173
- registerPlatformPluginForClient(client, platform) {
35174
- registerPlatformPlugin(client.interceptors, platform);
35175
- }
35176
35202
  /**
35177
35203
  * 为指定的 HttpClient 实例注册标准拦截器
35178
35204
  *
@@ -35192,30 +35218,6 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35192
35218
  "x-tt-env": ttEnv
35193
35219
  };
35194
35220
  }
35195
- const userIdRaw = this.requestContext.get("userId");
35196
- const tenantIdRaw = this.requestContext.get("tenantId");
35197
- const contextClaims = {};
35198
- if (userIdRaw !== void 0 && userIdRaw !== "") {
35199
- const userIdNum = typeof userIdRaw === "number" ? userIdRaw : Number(userIdRaw);
35200
- if (Number.isFinite(userIdNum)) {
35201
- contextClaims.user_id = userIdNum;
35202
- }
35203
- }
35204
- if (tenantIdRaw !== void 0 && tenantIdRaw !== "") {
35205
- const tenantIdNum = typeof tenantIdRaw === "number" ? tenantIdRaw : Number(tenantIdRaw);
35206
- if (Number.isFinite(tenantIdNum)) {
35207
- contextClaims.tenant_id = tenantIdNum;
35208
- }
35209
- }
35210
- if (contextClaims.user_id !== void 0 || contextClaims.tenant_id !== void 0) {
35211
- config.platformAuth = {
35212
- ...config.platformAuth,
35213
- customClaims: {
35214
- ...contextClaims,
35215
- ...config.platformAuth?.customClaims || {}
35216
- }
35217
- };
35218
- }
35219
35221
  return config;
35220
35222
  }, (error) => {
35221
35223
  this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.1.48-alpha.1",
3
+ "version": "1.1.48-alpha.11",
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.0",
43
+ "@lark-apaas/http-client": "0.1.6-alpha.1",
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",