@lark-apaas/fullstack-nestjs-core 1.1.47 → 1.1.48-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 +46 -11
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +48 -13
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
35156
|
+
...this.defaultPlatformConfig,
|
|
35154
35157
|
...options?.platform
|
|
35155
35158
|
};
|
|
35156
|
-
return
|
|
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,27 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
35208
35219
|
"x-tt-env": ttEnv
|
|
35209
35220
|
};
|
|
35210
35221
|
}
|
|
35222
|
+
const userId = this.requestContext.get("userId");
|
|
35223
|
+
const tenantIdRaw = this.requestContext.get("tenantId");
|
|
35224
|
+
const contextClaims = {};
|
|
35225
|
+
if (userId) {
|
|
35226
|
+
contextClaims.user_id = userId;
|
|
35227
|
+
}
|
|
35228
|
+
if (tenantIdRaw !== void 0 && tenantIdRaw !== "") {
|
|
35229
|
+
const tenantIdNum = typeof tenantIdRaw === "number" ? tenantIdRaw : Number(tenantIdRaw);
|
|
35230
|
+
if (Number.isFinite(tenantIdNum)) {
|
|
35231
|
+
contextClaims.tenant_id = tenantIdNum;
|
|
35232
|
+
}
|
|
35233
|
+
}
|
|
35234
|
+
if (contextClaims.user_id !== void 0 || contextClaims.tenant_id !== void 0) {
|
|
35235
|
+
config.platformAuth = {
|
|
35236
|
+
...config.platformAuth,
|
|
35237
|
+
customClaims: {
|
|
35238
|
+
...contextClaims,
|
|
35239
|
+
...config.platformAuth?.customClaims || {}
|
|
35240
|
+
}
|
|
35241
|
+
};
|
|
35242
|
+
}
|
|
35211
35243
|
return config;
|
|
35212
35244
|
}, (error) => {
|
|
35213
35245
|
this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
|
|
@@ -36337,13 +36369,16 @@ var PlatformModule = class _PlatformModule {
|
|
|
36337
36369
|
...DISABLE_DATAPASS ? [] : [
|
|
36338
36370
|
import_nestjs_datapaas.DataPaasModule.forRootAsync({
|
|
36339
36371
|
imports: [
|
|
36372
|
+
import_config2.ConfigModule,
|
|
36340
36373
|
import_nestjs_logger2.LoggerModule
|
|
36341
36374
|
],
|
|
36342
36375
|
inject: [
|
|
36376
|
+
import_config2.ConfigService,
|
|
36343
36377
|
import_nestjs_logger2.AppLogger
|
|
36344
36378
|
],
|
|
36345
36379
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
36346
|
-
const
|
|
36380
|
+
const configService = args[0];
|
|
36381
|
+
const appLogger = args[1];
|
|
36347
36382
|
const drizzleLogger = {
|
|
36348
36383
|
logQuery(query, params) {
|
|
36349
36384
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -36355,7 +36390,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
36355
36390
|
}
|
|
36356
36391
|
};
|
|
36357
36392
|
return {
|
|
36358
|
-
connectionString:
|
|
36393
|
+
connectionString: configService.get("app.databaseUrl") ?? "",
|
|
36359
36394
|
logger: drizzleLogger,
|
|
36360
36395
|
connectionTokenFilePath: "/var/run/secrets/zti/credential"
|
|
36361
36396
|
};
|
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
|
-
|
|
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
|
-
|
|
35129
|
+
...this.defaultPlatformConfig,
|
|
35127
35130
|
...options?.platform
|
|
35128
35131
|
};
|
|
35129
|
-
return
|
|
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,27 @@ var PlatformHttpClientService = class _PlatformHttpClientService {
|
|
|
35181
35192
|
"x-tt-env": ttEnv
|
|
35182
35193
|
};
|
|
35183
35194
|
}
|
|
35195
|
+
const userId = this.requestContext.get("userId");
|
|
35196
|
+
const tenantIdRaw = this.requestContext.get("tenantId");
|
|
35197
|
+
const contextClaims = {};
|
|
35198
|
+
if (userId) {
|
|
35199
|
+
contextClaims.user_id = userId;
|
|
35200
|
+
}
|
|
35201
|
+
if (tenantIdRaw !== void 0 && tenantIdRaw !== "") {
|
|
35202
|
+
const tenantIdNum = typeof tenantIdRaw === "number" ? tenantIdRaw : Number(tenantIdRaw);
|
|
35203
|
+
if (Number.isFinite(tenantIdNum)) {
|
|
35204
|
+
contextClaims.tenant_id = tenantIdNum;
|
|
35205
|
+
}
|
|
35206
|
+
}
|
|
35207
|
+
if (contextClaims.user_id !== void 0 || contextClaims.tenant_id !== void 0) {
|
|
35208
|
+
config.platformAuth = {
|
|
35209
|
+
...config.platformAuth,
|
|
35210
|
+
customClaims: {
|
|
35211
|
+
...contextClaims,
|
|
35212
|
+
...config.platformAuth?.customClaims || {}
|
|
35213
|
+
}
|
|
35214
|
+
};
|
|
35215
|
+
}
|
|
35184
35216
|
return config;
|
|
35185
35217
|
}, (error) => {
|
|
35186
35218
|
this.logger.error("Server SDK HTTP Request Error", error, "HttpService");
|
|
@@ -36310,13 +36342,16 @@ var PlatformModule = class _PlatformModule {
|
|
|
36310
36342
|
...DISABLE_DATAPASS ? [] : [
|
|
36311
36343
|
DataPaasModule.forRootAsync({
|
|
36312
36344
|
imports: [
|
|
36345
|
+
ConfigModule,
|
|
36313
36346
|
LoggerModule
|
|
36314
36347
|
],
|
|
36315
36348
|
inject: [
|
|
36349
|
+
ConfigService,
|
|
36316
36350
|
AppLogger2
|
|
36317
36351
|
],
|
|
36318
36352
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
36319
|
-
const
|
|
36353
|
+
const configService = args[0];
|
|
36354
|
+
const appLogger = args[1];
|
|
36320
36355
|
const drizzleLogger = {
|
|
36321
36356
|
logQuery(query, params) {
|
|
36322
36357
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -36328,7 +36363,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
36328
36363
|
}
|
|
36329
36364
|
};
|
|
36330
36365
|
return {
|
|
36331
|
-
connectionString:
|
|
36366
|
+
connectionString: configService.get("app.databaseUrl") ?? "",
|
|
36332
36367
|
logger: drizzleLogger,
|
|
36333
36368
|
connectionTokenFilePath: "/var/run/secrets/zti/credential"
|
|
36334
36369
|
};
|