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

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
@@ -34946,7 +34946,8 @@ var app_config_default = (0, import_config.registerAs)(NAMESPACE, () => {
34946
34946
  return {
34947
34947
  host: process.env.SERVER_HOST ?? "localhost",
34948
34948
  port: Number(process.env.SERVER_PORT ?? 3e3),
34949
- clientBasePath: process.env.CLIENT_BASE_PATH ?? "/"
34949
+ clientBasePath: process.env.CLIENT_BASE_PATH ?? "/",
34950
+ databaseUrl: process.env.SUDA_DATABASE_URL ?? ""
34950
34951
  };
34951
34952
  });
34952
34953
 
@@ -35072,6 +35073,9 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35072
35073
  client;
35073
35074
  protectedClient;
35074
35075
  logger = new import_common8.Logger(_PlatformHttpClientService.name);
35076
+ defaultPlatformConfig = {
35077
+ enabled: true
35078
+ };
35075
35079
  constructor(requestContext) {
35076
35080
  this.requestContext = requestContext;
35077
35081
  const baseConfig = {
@@ -35079,12 +35083,11 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35079
35083
  };
35080
35084
  this.client = new import_http_client.HttpClient({
35081
35085
  ...baseConfig,
35082
- platform: {
35083
- enabled: true
35084
- }
35086
+ baseURL: (0, import_http_client.resolvePlatformBaseURL)(this.defaultPlatformConfig)
35085
35087
  });
35086
35088
  this.protectedClient = new ProtectedHttpClient(this.client);
35087
35089
  this.registerGlobalInterceptors();
35090
+ this.registerPlatformPluginForClient(this.client, this.defaultPlatformConfig);
35088
35091
  }
35089
35092
  /**
35090
35093
  * 获取受保护的 HttpClient 实例(推荐)
@@ -35150,13 +35153,10 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35150
35153
  ...options?.config
35151
35154
  };
35152
35155
  const mergedPlatform = {
35153
- enabled: true,
35156
+ ...this.defaultPlatformConfig,
35154
35157
  ...options?.platform
35155
35158
  };
35156
- return new import_http_client.HttpClient({
35157
- ...mergedConfig,
35158
- platform: mergedPlatform
35159
- });
35159
+ return this.createClientWithPlatform(mergedConfig, mergedPlatform);
35160
35160
  }
35161
35161
  /**
35162
35162
  * 创建一个带全局拦截器的独立 HttpClient 实例
@@ -35189,6 +35189,17 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35189
35189
  registerGlobalInterceptors() {
35190
35190
  this.registerInterceptorsForClient(this.client);
35191
35191
  }
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
+ }
35192
35203
  /**
35193
35204
  * 为指定的 HttpClient 实例注册标准拦截器
35194
35205
  *
@@ -35208,6 +35219,30 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35208
35219
  "x-tt-env": ttEnv
35209
35220
  };
35210
35221
  }
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
+ }
35211
35246
  return config;
35212
35247
  }, (error) => {
35213
35248
  this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
@@ -36337,13 +36372,16 @@ var PlatformModule = class _PlatformModule {
36337
36372
  ...DISABLE_DATAPASS ? [] : [
36338
36373
  import_nestjs_datapaas.DataPaasModule.forRootAsync({
36339
36374
  imports: [
36375
+ import_config2.ConfigModule,
36340
36376
  import_nestjs_logger2.LoggerModule
36341
36377
  ],
36342
36378
  inject: [
36379
+ import_config2.ConfigService,
36343
36380
  import_nestjs_logger2.AppLogger
36344
36381
  ],
36345
36382
  useFactory: /* @__PURE__ */ __name(async (...args) => {
36346
- const appLogger = args[0];
36383
+ const configService = args[0];
36384
+ const appLogger = args[1];
36347
36385
  const drizzleLogger = {
36348
36386
  logQuery(query, params) {
36349
36387
  if (process.env.NODE_ENV === "development") {
@@ -36355,7 +36393,7 @@ var PlatformModule = class _PlatformModule {
36355
36393
  }
36356
36394
  };
36357
36395
  return {
36358
- connectionString: process.env.SUDA_DATABASE_URL ?? "",
36396
+ connectionString: configService.get("app.databaseUrl") ?? "",
36359
36397
  logger: drizzleLogger,
36360
36398
  connectionTokenFilePath: "/var/run/secrets/zti/credential"
36361
36399
  };
package/dist/index.d.cts CHANGED
@@ -308,6 +308,7 @@ declare class PlatformHttpClientService {
308
308
  private readonly client;
309
309
  private readonly protectedClient;
310
310
  private readonly logger;
311
+ private readonly defaultPlatformConfig;
311
312
  constructor(requestContext: RequestContextService);
312
313
  /**
313
314
  * 获取受保护的 HttpClient 实例(推荐)
@@ -389,6 +390,8 @@ declare class PlatformHttpClientService {
389
390
  * 注册全局拦截器(用于单例实例)
390
391
  */
391
392
  private registerGlobalInterceptors;
393
+ private createClientWithPlatform;
394
+ private registerPlatformPluginForClient;
392
395
  /**
393
396
  * 为指定的 HttpClient 实例注册标准拦截器
394
397
  *
package/dist/index.d.ts CHANGED
@@ -308,6 +308,7 @@ declare class PlatformHttpClientService {
308
308
  private readonly client;
309
309
  private readonly protectedClient;
310
310
  private readonly logger;
311
+ private readonly defaultPlatformConfig;
311
312
  constructor(requestContext: RequestContextService);
312
313
  /**
313
314
  * 获取受保护的 HttpClient 实例(推荐)
@@ -389,6 +390,8 @@ declare class PlatformHttpClientService {
389
390
  * 注册全局拦截器(用于单例实例)
390
391
  */
391
392
  private registerGlobalInterceptors;
393
+ private createClientWithPlatform;
394
+ private registerPlatformPluginForClient;
392
395
  /**
393
396
  * 为指定的 HttpClient 实例注册标准拦截器
394
397
  *
package/dist/index.js CHANGED
@@ -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 } from "@nestjs/config";
34407
+ import { ConfigModule, ConfigService } 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";
@@ -34919,7 +34919,8 @@ var app_config_default = registerAs(NAMESPACE, () => {
34919
34919
  return {
34920
34920
  host: process.env.SERVER_HOST ?? "localhost",
34921
34921
  port: Number(process.env.SERVER_PORT ?? 3e3),
34922
- clientBasePath: process.env.CLIENT_BASE_PATH ?? "/"
34922
+ clientBasePath: process.env.CLIENT_BASE_PATH ?? "/",
34923
+ databaseUrl: process.env.SUDA_DATABASE_URL ?? ""
34923
34924
  };
34924
34925
  });
34925
34926
 
@@ -34997,7 +34998,7 @@ FrameworkDebugMiddleware = _ts_decorate7([
34997
34998
 
34998
34999
  // src/services/platform-http-client.service.ts
34999
35000
  import { Injectable as Injectable8, Logger as Logger2 } from "@nestjs/common";
35000
- import { HttpClient } from "@lark-apaas/http-client";
35001
+ import { HttpClient, registerPlatformPlugin, resolvePlatformBaseURL } from "@lark-apaas/http-client";
35001
35002
  import { RequestContextService as RequestContextService2 } from "@lark-apaas/nestjs-common";
35002
35003
  function _ts_decorate8(decorators, target, key, desc) {
35003
35004
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -35045,6 +35046,9 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35045
35046
  client;
35046
35047
  protectedClient;
35047
35048
  logger = new Logger2(_PlatformHttpClientService.name);
35049
+ defaultPlatformConfig = {
35050
+ enabled: true
35051
+ };
35048
35052
  constructor(requestContext) {
35049
35053
  this.requestContext = requestContext;
35050
35054
  const baseConfig = {
@@ -35052,12 +35056,11 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35052
35056
  };
35053
35057
  this.client = new HttpClient({
35054
35058
  ...baseConfig,
35055
- platform: {
35056
- enabled: true
35057
- }
35059
+ baseURL: resolvePlatformBaseURL(this.defaultPlatformConfig)
35058
35060
  });
35059
35061
  this.protectedClient = new ProtectedHttpClient(this.client);
35060
35062
  this.registerGlobalInterceptors();
35063
+ this.registerPlatformPluginForClient(this.client, this.defaultPlatformConfig);
35061
35064
  }
35062
35065
  /**
35063
35066
  * 获取受保护的 HttpClient 实例(推荐)
@@ -35123,13 +35126,10 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35123
35126
  ...options?.config
35124
35127
  };
35125
35128
  const mergedPlatform = {
35126
- enabled: true,
35129
+ ...this.defaultPlatformConfig,
35127
35130
  ...options?.platform
35128
35131
  };
35129
- return new HttpClient({
35130
- ...mergedConfig,
35131
- platform: mergedPlatform
35132
- });
35132
+ return this.createClientWithPlatform(mergedConfig, mergedPlatform);
35133
35133
  }
35134
35134
  /**
35135
35135
  * 创建一个带全局拦截器的独立 HttpClient 实例
@@ -35162,6 +35162,17 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35162
35162
  registerGlobalInterceptors() {
35163
35163
  this.registerInterceptorsForClient(this.client);
35164
35164
  }
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
+ }
35165
35176
  /**
35166
35177
  * 为指定的 HttpClient 实例注册标准拦截器
35167
35178
  *
@@ -35181,6 +35192,30 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
35181
35192
  "x-tt-env": ttEnv
35182
35193
  };
35183
35194
  }
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
+ }
35184
35219
  return config;
35185
35220
  }, (error) => {
35186
35221
  this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
@@ -36310,13 +36345,16 @@ var PlatformModule = class _PlatformModule {
36310
36345
  ...DISABLE_DATAPASS ? [] : [
36311
36346
  DataPaasModule.forRootAsync({
36312
36347
  imports: [
36348
+ ConfigModule,
36313
36349
  LoggerModule
36314
36350
  ],
36315
36351
  inject: [
36352
+ ConfigService,
36316
36353
  AppLogger2
36317
36354
  ],
36318
36355
  useFactory: /* @__PURE__ */ __name(async (...args) => {
36319
- const appLogger = args[0];
36356
+ const configService = args[0];
36357
+ const appLogger = args[1];
36320
36358
  const drizzleLogger = {
36321
36359
  logQuery(query, params) {
36322
36360
  if (process.env.NODE_ENV === "development") {
@@ -36328,7 +36366,7 @@ var PlatformModule = class _PlatformModule {
36328
36366
  }
36329
36367
  };
36330
36368
  return {
36331
- connectionString: process.env.SUDA_DATABASE_URL ?? "",
36369
+ connectionString: configService.get("app.databaseUrl") ?? "",
36332
36370
  logger: drizzleLogger,
36333
36371
  connectionTokenFilePath: "/var/run/secrets/zti/credential"
36334
36372
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.1.47",
3
+ "version": "1.1.48-alpha.1",
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.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",