@lark-apaas/fullstack-nestjs-core 1.1.51-alpha.6 → 1.1.51
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 +21 -91
- package/dist/index.d.cts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +21 -89
- package/package.json +11 -11
package/dist/index.cjs
CHANGED
|
@@ -34423,24 +34423,10 @@ __export(index_exports, {
|
|
|
34423
34423
|
UserContextMiddleware: () => UserContextMiddleware,
|
|
34424
34424
|
ViewContextMiddleware: () => ViewContextMiddleware,
|
|
34425
34425
|
configureApp: () => configureApp,
|
|
34426
|
-
createLegacyPathRedirectMiddleware: () => createLegacyPathRedirectMiddleware
|
|
34427
|
-
createLocalDevMiddleware: () => createLocalDevMiddleware,
|
|
34428
|
-
isLocalDev: () => isLocalDev
|
|
34426
|
+
createLegacyPathRedirectMiddleware: () => createLegacyPathRedirectMiddleware
|
|
34429
34427
|
});
|
|
34430
34428
|
module.exports = __toCommonJS(index_exports);
|
|
34431
34429
|
|
|
34432
|
-
// src/load-env.ts
|
|
34433
|
-
try {
|
|
34434
|
-
const dotenv = require("dotenv");
|
|
34435
|
-
dotenv.config({
|
|
34436
|
-
path: ".env.local"
|
|
34437
|
-
});
|
|
34438
|
-
dotenv.config({
|
|
34439
|
-
path: ".env"
|
|
34440
|
-
});
|
|
34441
|
-
} catch {
|
|
34442
|
-
}
|
|
34443
|
-
|
|
34444
34430
|
// src/modules/platform/module.ts
|
|
34445
34431
|
var import_common16 = require("@nestjs/common");
|
|
34446
34432
|
var import_core2 = require("@nestjs/core");
|
|
@@ -34451,6 +34437,7 @@ var import_axios2 = require("@nestjs/axios");
|
|
|
34451
34437
|
var import_nestjs_logger2 = require("@lark-apaas/nestjs-logger");
|
|
34452
34438
|
var import_nestjs_datapaas = require("@lark-apaas/nestjs-datapaas");
|
|
34453
34439
|
var import_nestjs_authnpaas = require("@lark-apaas/nestjs-authnpaas");
|
|
34440
|
+
var import_nestjs_http_forwarder = require("@lark-apaas/nestjs-http-forwarder");
|
|
34454
34441
|
var import_nestjs_trigger = require("@lark-apaas/nestjs-trigger");
|
|
34455
34442
|
var import_nestjs_common7 = require("@lark-apaas/nestjs-common");
|
|
34456
34443
|
var import_nestjs_capability = require("@lark-apaas/nestjs-capability");
|
|
@@ -34458,41 +34445,20 @@ var import_nestjs_capability = require("@lark-apaas/nestjs-capability");
|
|
|
34458
34445
|
// src/middlewares/user-context/index.ts
|
|
34459
34446
|
var import_common = require("@nestjs/common");
|
|
34460
34447
|
|
|
34461
|
-
// src/utils/parse-suda-webuser.ts
|
|
34462
|
-
function parseSudaWebUserEnv(raw) {
|
|
34463
|
-
if (!raw) return null;
|
|
34464
|
-
try {
|
|
34465
|
-
return JSON.parse(raw);
|
|
34466
|
-
} catch {
|
|
34467
|
-
}
|
|
34468
|
-
try {
|
|
34469
|
-
return JSON.parse(raw.replace(/\\"/g, '"'));
|
|
34470
|
-
} catch {
|
|
34471
|
-
return null;
|
|
34472
|
-
}
|
|
34473
|
-
}
|
|
34474
|
-
__name(parseSudaWebUserEnv, "parseSudaWebUserEnv");
|
|
34475
|
-
|
|
34476
34448
|
// src/middlewares/user-context/helper.ts
|
|
34477
34449
|
var sudaWebUserHeaderKey = "x-larkgw-suda-webuser";
|
|
34478
34450
|
function getWebUserFromHeader(req) {
|
|
34479
34451
|
const sudaWebUserContent = req.headers[sudaWebUserHeaderKey];
|
|
34480
|
-
if (sudaWebUserContent) {
|
|
34481
|
-
|
|
34482
|
-
const sudaWebUserJsonStr = decodeURIComponent(sudaWebUserContent);
|
|
34483
|
-
const sudaWebUserJson = JSON.parse(sudaWebUserJsonStr);
|
|
34484
|
-
return sudaWebUserJson;
|
|
34485
|
-
} catch (err) {
|
|
34486
|
-
console.error("parse suda webuser from header failed, err=%o", err);
|
|
34487
|
-
return null;
|
|
34488
|
-
}
|
|
34452
|
+
if (!sudaWebUserContent) {
|
|
34453
|
+
return null;
|
|
34489
34454
|
}
|
|
34490
|
-
|
|
34491
|
-
const
|
|
34492
|
-
|
|
34493
|
-
|
|
34494
|
-
|
|
34495
|
-
|
|
34455
|
+
try {
|
|
34456
|
+
const sudaWebUserJsonStr = decodeURIComponent(sudaWebUserContent);
|
|
34457
|
+
const sudaWebUserJson = JSON.parse(sudaWebUserJsonStr);
|
|
34458
|
+
return sudaWebUserJson;
|
|
34459
|
+
} catch (err) {
|
|
34460
|
+
console.error("parse suda webuser from header failed, err=%o", err);
|
|
34461
|
+
return null;
|
|
34496
34462
|
}
|
|
34497
34463
|
return null;
|
|
34498
34464
|
}
|
|
@@ -34588,7 +34554,7 @@ CsrfMiddleware = _ts_decorate2([
|
|
|
34588
34554
|
(0, import_common2.Injectable)()
|
|
34589
34555
|
], CsrfMiddleware);
|
|
34590
34556
|
|
|
34591
|
-
// src/middlewares/view-context/
|
|
34557
|
+
// src/middlewares/view-context/middleware.ts
|
|
34592
34558
|
var import_common3 = require("@nestjs/common");
|
|
34593
34559
|
var import_nestjs_common = require("@lark-apaas/nestjs-common");
|
|
34594
34560
|
|
|
@@ -34635,7 +34601,7 @@ function safeEscape(s) {
|
|
|
34635
34601
|
}
|
|
34636
34602
|
__name(safeEscape, "safeEscape");
|
|
34637
34603
|
|
|
34638
|
-
// src/middlewares/view-context/
|
|
34604
|
+
// src/middlewares/view-context/middleware.ts
|
|
34639
34605
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
34640
34606
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
34641
34607
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -34686,6 +34652,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
34686
34652
|
const { userId, tenantId, appId, loginUrl, userType } = req.userContext;
|
|
34687
34653
|
const csrfToken = req.csrfToken;
|
|
34688
34654
|
const environment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
|
|
34655
|
+
const basename = safeEscape(req.headers["x-miaoda-custom-host"] !== void 0 ? "/" : `/app/${appId || ""}`);
|
|
34689
34656
|
const appPublishedData = await this.getAppPublished(appId);
|
|
34690
34657
|
const appInfo = appPublishedData?.app_info ?? null;
|
|
34691
34658
|
req.__platform_data__ = {
|
|
@@ -34700,7 +34667,8 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
34700
34667
|
tenantId,
|
|
34701
34668
|
environment,
|
|
34702
34669
|
showBadge: appInfo?.show_badge !== false,
|
|
34703
|
-
appPublished: appPublishedData ?? null
|
|
34670
|
+
appPublished: appPublishedData ?? null,
|
|
34671
|
+
basename
|
|
34704
34672
|
};
|
|
34705
34673
|
res.locals = {
|
|
34706
34674
|
...res.locals ?? {},
|
|
@@ -34713,7 +34681,8 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
34713
34681
|
appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
|
|
34714
34682
|
appAvatar: appInfo?.app_avatar ?? "",
|
|
34715
34683
|
appDescription: safeEscape(appInfo?.app_description ?? ""),
|
|
34716
|
-
environment
|
|
34684
|
+
environment,
|
|
34685
|
+
basename
|
|
34717
34686
|
};
|
|
34718
34687
|
next();
|
|
34719
34688
|
}
|
|
@@ -36438,6 +36407,9 @@ var PlatformModule = class _PlatformModule {
|
|
|
36438
36407
|
...options.authz || {}
|
|
36439
36408
|
}),
|
|
36440
36409
|
import_nestjs_trigger.AutomationModule.forRoot(),
|
|
36410
|
+
// 通用内网转发:自动注册 ALL /api/__platform__/http-forward?targetUrl=...
|
|
36411
|
+
// 业务方接入 PlatformModule 后零改动获得内网代理路由
|
|
36412
|
+
import_nestjs_http_forwarder.HttpForwarderModule.forRoot(options.httpForwarder),
|
|
36441
36413
|
import_nestjs_capability.CapabilityModule.forRoot({
|
|
36442
36414
|
capabilitiesDir: options.capabilitiesDir,
|
|
36443
36415
|
enableWatching: process.env.NODE_ENV === "development"
|
|
@@ -36581,43 +36553,6 @@ function createLegacyPathRedirectMiddleware() {
|
|
|
36581
36553
|
}
|
|
36582
36554
|
__name(createLegacyPathRedirectMiddleware, "createLegacyPathRedirectMiddleware");
|
|
36583
36555
|
|
|
36584
|
-
// src/middlewares/local-dev/index.ts
|
|
36585
|
-
var CSRF_COOKIE_KEY = "suda-csrf-token";
|
|
36586
|
-
var CSRF_HEADER_KEY = "x-suda-csrf-token";
|
|
36587
|
-
var WEBUSER_HEADER_KEY = "x-larkgw-suda-webuser";
|
|
36588
|
-
function isLocalDev() {
|
|
36589
|
-
if (process.env.NODE_ENV === "production") return false;
|
|
36590
|
-
const flag = process.env.MIAODA_LOCAL_DEV;
|
|
36591
|
-
return flag === "1" || flag === "true";
|
|
36592
|
-
}
|
|
36593
|
-
__name(isLocalDev, "isLocalDev");
|
|
36594
|
-
function extractCsrfFromCookie(cookieHeader) {
|
|
36595
|
-
if (!cookieHeader) return void 0;
|
|
36596
|
-
const re = new RegExp(`(?:^|;\\s*)${CSRF_COOKIE_KEY}=([^;]+)`);
|
|
36597
|
-
const m = cookieHeader.match(re);
|
|
36598
|
-
return m?.[1];
|
|
36599
|
-
}
|
|
36600
|
-
__name(extractCsrfFromCookie, "extractCsrfFromCookie");
|
|
36601
|
-
function createLocalDevMiddleware() {
|
|
36602
|
-
let webUserHeader = "";
|
|
36603
|
-
const parsed = parseSudaWebUserEnv(process.env.SUDA_WEBUSER);
|
|
36604
|
-
if (parsed) {
|
|
36605
|
-
webUserHeader = encodeURIComponent(JSON.stringify(parsed));
|
|
36606
|
-
}
|
|
36607
|
-
return /* @__PURE__ */ __name(function localDevMiddleware(req, _res, next) {
|
|
36608
|
-
const headers = req.headers;
|
|
36609
|
-
if (!headers[CSRF_HEADER_KEY]) {
|
|
36610
|
-
const token = extractCsrfFromCookie(req.headers.cookie);
|
|
36611
|
-
if (token) headers[CSRF_HEADER_KEY] = token;
|
|
36612
|
-
}
|
|
36613
|
-
if (webUserHeader && !headers[WEBUSER_HEADER_KEY]) {
|
|
36614
|
-
headers[WEBUSER_HEADER_KEY] = webUserHeader;
|
|
36615
|
-
}
|
|
36616
|
-
next();
|
|
36617
|
-
}, "localDevMiddleware");
|
|
36618
|
-
}
|
|
36619
|
-
__name(createLocalDevMiddleware, "createLocalDevMiddleware");
|
|
36620
|
-
|
|
36621
36556
|
// src/setup.ts
|
|
36622
36557
|
var DEFAULT_BODY_LIMIT = "1mb";
|
|
36623
36558
|
var defaultPerms = {
|
|
@@ -36635,9 +36570,6 @@ async function configureApp(app, perms = defaultPerms) {
|
|
|
36635
36570
|
extended: true
|
|
36636
36571
|
}));
|
|
36637
36572
|
app.use((0, import_cookie_parser.default)());
|
|
36638
|
-
if (isLocalDev()) {
|
|
36639
|
-
app.use(createLocalDevMiddleware());
|
|
36640
|
-
}
|
|
36641
36573
|
app.use(createLegacyPathRedirectMiddleware());
|
|
36642
36574
|
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
36643
36575
|
app.setGlobalPrefix(globalPrefix);
|
|
@@ -36689,8 +36621,6 @@ var import_nestjs_authzpaas2 = require("@lark-apaas/nestjs-authzpaas");
|
|
|
36689
36621
|
ViewContextMiddleware,
|
|
36690
36622
|
configureApp,
|
|
36691
36623
|
createLegacyPathRedirectMiddleware,
|
|
36692
|
-
createLocalDevMiddleware,
|
|
36693
|
-
isLocalDev,
|
|
36694
36624
|
...require("@lark-apaas/nestjs-authnpaas"),
|
|
36695
36625
|
...require("@lark-apaas/nestjs-capability"),
|
|
36696
36626
|
...require("@lark-apaas/nestjs-datapaas"),
|
package/dist/index.d.cts
CHANGED
|
@@ -2,11 +2,12 @@ import { NestModule, DynamicModule, MiddlewareConsumer, OnModuleInit, NestMiddle
|
|
|
2
2
|
import { HttpClientConfig, PlatformPluginOptions, HttpClient } from '@lark-apaas/http-client';
|
|
3
3
|
import { AuthZPaasModuleOptions } from '@lark-apaas/nestjs-authzpaas';
|
|
4
4
|
export { AddMembersParams, AuthZPaasModule, AuthorizationSDK, Can, CanRole, ChatSimpleDTO, CommonParam, CreateRoleParams, CreateRoleResponse, DepartmentDTO, DepartmentEntity, DepartmentSimpleDTO, FilterParams, ForceRoleDTO, I18nText, IPermissionResolver, ListMembersParams, ListMembersResponse, ListRolesParams, MemberMutationData, MemberType, PERMISSION_RESOLVER_TOKEN, PermissionPoint, PermissionRequirement, PresetGroupDTO, RemoveMembersParams, RoleMemberDTO, SearchChatEntity, SearchParams, SearchResponse, SearchResult, SearchUserEntity, UpdateRoleParams, UserSimpleDTO } from '@lark-apaas/nestjs-authzpaas';
|
|
5
|
+
import { HttpForwarderModuleOptions } from '@lark-apaas/nestjs-http-forwarder';
|
|
5
6
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
6
7
|
import { PlatformHttpClient, RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
|
|
7
8
|
export { AutoTrace } from '@lark-apaas/nestjs-common';
|
|
8
9
|
export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
|
|
9
|
-
import { Request, Response, NextFunction
|
|
10
|
+
import { Request, Response, NextFunction } from 'express';
|
|
10
11
|
import * as _lark_apaas_file_service from '@lark-apaas/file-service';
|
|
11
12
|
import { FileBody, UploadOptions, FileDownloadBuilder, SearchOptions } from '@lark-apaas/file-service';
|
|
12
13
|
export * from '@lark-apaas/file-service';
|
|
@@ -23,6 +24,8 @@ declare global {
|
|
|
23
24
|
userId?: string;
|
|
24
25
|
tenantId?: number;
|
|
25
26
|
csrfToken?: string;
|
|
27
|
+
/** React Router basename,由 ViewContextMiddleware 注入;自定义域名场景下 = / 或 /<alias>,默认域名 = /app/<appId> */
|
|
28
|
+
basename?: string;
|
|
26
29
|
[key: string]: unknown;
|
|
27
30
|
};
|
|
28
31
|
userContext: {
|
|
@@ -78,6 +81,12 @@ interface PlatformModuleOptions {
|
|
|
78
81
|
* 可传入 permissionResolver 等选项,透传给 AuthZPaasModule.forRoot()
|
|
79
82
|
*/
|
|
80
83
|
authz?: AuthZPaasModuleOptions;
|
|
84
|
+
/**
|
|
85
|
+
* HttpForwarder 模块配置(默认自动启用,注册 ALL /api/__platform__/http-forward 路由)
|
|
86
|
+
* 透传给 HttpForwarderModule.forRoot();不传则使用模块默认值
|
|
87
|
+
* (requestTimeoutMs=30s, maxResponseBytes=10MB)。
|
|
88
|
+
*/
|
|
89
|
+
httpForwarder?: HttpForwarderModuleOptions;
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
declare class PlatformModule implements NestModule {
|
|
@@ -221,9 +230,6 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
221
230
|
*/
|
|
222
231
|
declare function createLegacyPathRedirectMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
|
|
223
232
|
|
|
224
|
-
declare function isLocalDev(): boolean;
|
|
225
|
-
declare function createLocalDevMiddleware(): RequestHandler;
|
|
226
|
-
|
|
227
233
|
/**
|
|
228
234
|
* API 404 响应格式
|
|
229
235
|
*/
|
|
@@ -405,4 +411,4 @@ declare class PlatformHttpClientService {
|
|
|
405
411
|
private registerInterceptorsForClient;
|
|
406
412
|
}
|
|
407
413
|
|
|
408
|
-
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware
|
|
414
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { NestModule, DynamicModule, MiddlewareConsumer, OnModuleInit, NestMiddle
|
|
|
2
2
|
import { HttpClientConfig, PlatformPluginOptions, HttpClient } from '@lark-apaas/http-client';
|
|
3
3
|
import { AuthZPaasModuleOptions } from '@lark-apaas/nestjs-authzpaas';
|
|
4
4
|
export { AddMembersParams, AuthZPaasModule, AuthorizationSDK, Can, CanRole, ChatSimpleDTO, CommonParam, CreateRoleParams, CreateRoleResponse, DepartmentDTO, DepartmentEntity, DepartmentSimpleDTO, FilterParams, ForceRoleDTO, I18nText, IPermissionResolver, ListMembersParams, ListMembersResponse, ListRolesParams, MemberMutationData, MemberType, PERMISSION_RESOLVER_TOKEN, PermissionPoint, PermissionRequirement, PresetGroupDTO, RemoveMembersParams, RoleMemberDTO, SearchChatEntity, SearchParams, SearchResponse, SearchResult, SearchUserEntity, UpdateRoleParams, UserSimpleDTO } from '@lark-apaas/nestjs-authzpaas';
|
|
5
|
+
import { HttpForwarderModuleOptions } from '@lark-apaas/nestjs-http-forwarder';
|
|
5
6
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
6
7
|
import { PlatformHttpClient, RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
|
|
7
8
|
export { AutoTrace } from '@lark-apaas/nestjs-common';
|
|
8
9
|
export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
|
|
9
|
-
import { Request, Response, NextFunction
|
|
10
|
+
import { Request, Response, NextFunction } from 'express';
|
|
10
11
|
import * as _lark_apaas_file_service from '@lark-apaas/file-service';
|
|
11
12
|
import { FileBody, UploadOptions, FileDownloadBuilder, SearchOptions } from '@lark-apaas/file-service';
|
|
12
13
|
export * from '@lark-apaas/file-service';
|
|
@@ -23,6 +24,8 @@ declare global {
|
|
|
23
24
|
userId?: string;
|
|
24
25
|
tenantId?: number;
|
|
25
26
|
csrfToken?: string;
|
|
27
|
+
/** React Router basename,由 ViewContextMiddleware 注入;自定义域名场景下 = / 或 /<alias>,默认域名 = /app/<appId> */
|
|
28
|
+
basename?: string;
|
|
26
29
|
[key: string]: unknown;
|
|
27
30
|
};
|
|
28
31
|
userContext: {
|
|
@@ -78,6 +81,12 @@ interface PlatformModuleOptions {
|
|
|
78
81
|
* 可传入 permissionResolver 等选项,透传给 AuthZPaasModule.forRoot()
|
|
79
82
|
*/
|
|
80
83
|
authz?: AuthZPaasModuleOptions;
|
|
84
|
+
/**
|
|
85
|
+
* HttpForwarder 模块配置(默认自动启用,注册 ALL /api/__platform__/http-forward 路由)
|
|
86
|
+
* 透传给 HttpForwarderModule.forRoot();不传则使用模块默认值
|
|
87
|
+
* (requestTimeoutMs=30s, maxResponseBytes=10MB)。
|
|
88
|
+
*/
|
|
89
|
+
httpForwarder?: HttpForwarderModuleOptions;
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
declare class PlatformModule implements NestModule {
|
|
@@ -221,9 +230,6 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
221
230
|
*/
|
|
222
231
|
declare function createLegacyPathRedirectMiddleware(): (req: Request, res: Response, next: NextFunction) => void;
|
|
223
232
|
|
|
224
|
-
declare function isLocalDev(): boolean;
|
|
225
|
-
declare function createLocalDevMiddleware(): RequestHandler;
|
|
226
|
-
|
|
227
233
|
/**
|
|
228
234
|
* API 404 响应格式
|
|
229
235
|
*/
|
|
@@ -405,4 +411,4 @@ declare class PlatformHttpClientService {
|
|
|
405
411
|
private registerInterceptorsForClient;
|
|
406
412
|
}
|
|
407
413
|
|
|
408
|
-
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware
|
|
414
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, FileService, HtmlHotUpdateModule, HtmlHotUpdateService, type PlatformHttpClientOptions, PlatformHttpClientService, PlatformModule, type PlatformModuleOptions, StaticModule, UserContextMiddleware, ViewContextMiddleware, configureApp, createLegacyPathRedirectMiddleware };
|
package/dist/index.js
CHANGED
|
@@ -34400,18 +34400,6 @@ var require_express2 = __commonJS({
|
|
|
34400
34400
|
}
|
|
34401
34401
|
});
|
|
34402
34402
|
|
|
34403
|
-
// src/load-env.ts
|
|
34404
|
-
try {
|
|
34405
|
-
const dotenv = __require("dotenv");
|
|
34406
|
-
dotenv.config({
|
|
34407
|
-
path: ".env.local"
|
|
34408
|
-
});
|
|
34409
|
-
dotenv.config({
|
|
34410
|
-
path: ".env"
|
|
34411
|
-
});
|
|
34412
|
-
} catch {
|
|
34413
|
-
}
|
|
34414
|
-
|
|
34415
34403
|
// src/modules/platform/module.ts
|
|
34416
34404
|
import { Global, Module as Module3, ValidationPipe } from "@nestjs/common";
|
|
34417
34405
|
import { APP_INTERCEPTOR, APP_PIPE } from "@nestjs/core";
|
|
@@ -34422,6 +34410,7 @@ import { HttpModule } from "@nestjs/axios";
|
|
|
34422
34410
|
import { LoggerModule, AppLogger as AppLogger2, LoggerContextMiddleware } from "@lark-apaas/nestjs-logger";
|
|
34423
34411
|
import { DataPaasModule, SqlExecutionContextMiddleware } from "@lark-apaas/nestjs-datapaas";
|
|
34424
34412
|
import { AuthNPaasModule } from "@lark-apaas/nestjs-authnpaas";
|
|
34413
|
+
import { HttpForwarderModule } from "@lark-apaas/nestjs-http-forwarder";
|
|
34425
34414
|
import { AutomationModule } from "@lark-apaas/nestjs-trigger";
|
|
34426
34415
|
import { PLATFORM_HTTP_CLIENT as PLATFORM_HTTP_CLIENT4 } from "@lark-apaas/nestjs-common";
|
|
34427
34416
|
import { CapabilityModule } from "@lark-apaas/nestjs-capability";
|
|
@@ -34429,41 +34418,20 @@ import { CapabilityModule } from "@lark-apaas/nestjs-capability";
|
|
|
34429
34418
|
// src/middlewares/user-context/index.ts
|
|
34430
34419
|
import { Injectable } from "@nestjs/common";
|
|
34431
34420
|
|
|
34432
|
-
// src/utils/parse-suda-webuser.ts
|
|
34433
|
-
function parseSudaWebUserEnv(raw) {
|
|
34434
|
-
if (!raw) return null;
|
|
34435
|
-
try {
|
|
34436
|
-
return JSON.parse(raw);
|
|
34437
|
-
} catch {
|
|
34438
|
-
}
|
|
34439
|
-
try {
|
|
34440
|
-
return JSON.parse(raw.replace(/\\"/g, '"'));
|
|
34441
|
-
} catch {
|
|
34442
|
-
return null;
|
|
34443
|
-
}
|
|
34444
|
-
}
|
|
34445
|
-
__name(parseSudaWebUserEnv, "parseSudaWebUserEnv");
|
|
34446
|
-
|
|
34447
34421
|
// src/middlewares/user-context/helper.ts
|
|
34448
34422
|
var sudaWebUserHeaderKey = "x-larkgw-suda-webuser";
|
|
34449
34423
|
function getWebUserFromHeader(req) {
|
|
34450
34424
|
const sudaWebUserContent = req.headers[sudaWebUserHeaderKey];
|
|
34451
|
-
if (sudaWebUserContent) {
|
|
34452
|
-
|
|
34453
|
-
const sudaWebUserJsonStr = decodeURIComponent(sudaWebUserContent);
|
|
34454
|
-
const sudaWebUserJson = JSON.parse(sudaWebUserJsonStr);
|
|
34455
|
-
return sudaWebUserJson;
|
|
34456
|
-
} catch (err) {
|
|
34457
|
-
console.error("parse suda webuser from header failed, err=%o", err);
|
|
34458
|
-
return null;
|
|
34459
|
-
}
|
|
34425
|
+
if (!sudaWebUserContent) {
|
|
34426
|
+
return null;
|
|
34460
34427
|
}
|
|
34461
|
-
|
|
34462
|
-
const
|
|
34463
|
-
|
|
34464
|
-
|
|
34465
|
-
|
|
34466
|
-
|
|
34428
|
+
try {
|
|
34429
|
+
const sudaWebUserJsonStr = decodeURIComponent(sudaWebUserContent);
|
|
34430
|
+
const sudaWebUserJson = JSON.parse(sudaWebUserJsonStr);
|
|
34431
|
+
return sudaWebUserJson;
|
|
34432
|
+
} catch (err) {
|
|
34433
|
+
console.error("parse suda webuser from header failed, err=%o", err);
|
|
34434
|
+
return null;
|
|
34467
34435
|
}
|
|
34468
34436
|
return null;
|
|
34469
34437
|
}
|
|
@@ -34559,7 +34527,7 @@ CsrfMiddleware = _ts_decorate2([
|
|
|
34559
34527
|
Injectable2()
|
|
34560
34528
|
], CsrfMiddleware);
|
|
34561
34529
|
|
|
34562
|
-
// src/middlewares/view-context/
|
|
34530
|
+
// src/middlewares/view-context/middleware.ts
|
|
34563
34531
|
import { Inject, Injectable as Injectable3, Logger } from "@nestjs/common";
|
|
34564
34532
|
import { PLATFORM_HTTP_CLIENT } from "@lark-apaas/nestjs-common";
|
|
34565
34533
|
|
|
@@ -34606,7 +34574,7 @@ function safeEscape(s) {
|
|
|
34606
34574
|
}
|
|
34607
34575
|
__name(safeEscape, "safeEscape");
|
|
34608
34576
|
|
|
34609
|
-
// src/middlewares/view-context/
|
|
34577
|
+
// src/middlewares/view-context/middleware.ts
|
|
34610
34578
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
34611
34579
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
34612
34580
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -34657,6 +34625,7 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
34657
34625
|
const { userId, tenantId, appId, loginUrl, userType } = req.userContext;
|
|
34658
34626
|
const csrfToken = req.csrfToken;
|
|
34659
34627
|
const environment = mapToWindowEnvironment(process.env.FORCE_FRAMEWORK_ENVIRONMENT);
|
|
34628
|
+
const basename = safeEscape(req.headers["x-miaoda-custom-host"] !== void 0 ? "/" : `/app/${appId || ""}`);
|
|
34660
34629
|
const appPublishedData = await this.getAppPublished(appId);
|
|
34661
34630
|
const appInfo = appPublishedData?.app_info ?? null;
|
|
34662
34631
|
req.__platform_data__ = {
|
|
@@ -34671,7 +34640,8 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
34671
34640
|
tenantId,
|
|
34672
34641
|
environment,
|
|
34673
34642
|
showBadge: appInfo?.show_badge !== false,
|
|
34674
|
-
appPublished: appPublishedData ?? null
|
|
34643
|
+
appPublished: appPublishedData ?? null,
|
|
34644
|
+
basename
|
|
34675
34645
|
};
|
|
34676
34646
|
res.locals = {
|
|
34677
34647
|
...res.locals ?? {},
|
|
@@ -34684,7 +34654,8 @@ var ViewContextMiddleware = class _ViewContextMiddleware {
|
|
|
34684
34654
|
appName: safeEscape(appInfo?.app_name ?? "\u5999\u642D\u5E94\u7528"),
|
|
34685
34655
|
appAvatar: appInfo?.app_avatar ?? "",
|
|
34686
34656
|
appDescription: safeEscape(appInfo?.app_description ?? ""),
|
|
34687
|
-
environment
|
|
34657
|
+
environment,
|
|
34658
|
+
basename
|
|
34688
34659
|
};
|
|
34689
34660
|
next();
|
|
34690
34661
|
}
|
|
@@ -36409,6 +36380,9 @@ var PlatformModule = class _PlatformModule {
|
|
|
36409
36380
|
...options.authz || {}
|
|
36410
36381
|
}),
|
|
36411
36382
|
AutomationModule.forRoot(),
|
|
36383
|
+
// 通用内网转发:自动注册 ALL /api/__platform__/http-forward?targetUrl=...
|
|
36384
|
+
// 业务方接入 PlatformModule 后零改动获得内网代理路由
|
|
36385
|
+
HttpForwarderModule.forRoot(options.httpForwarder),
|
|
36412
36386
|
CapabilityModule.forRoot({
|
|
36413
36387
|
capabilitiesDir: options.capabilitiesDir,
|
|
36414
36388
|
enableWatching: process.env.NODE_ENV === "development"
|
|
@@ -36552,43 +36526,6 @@ function createLegacyPathRedirectMiddleware() {
|
|
|
36552
36526
|
}
|
|
36553
36527
|
__name(createLegacyPathRedirectMiddleware, "createLegacyPathRedirectMiddleware");
|
|
36554
36528
|
|
|
36555
|
-
// src/middlewares/local-dev/index.ts
|
|
36556
|
-
var CSRF_COOKIE_KEY = "suda-csrf-token";
|
|
36557
|
-
var CSRF_HEADER_KEY = "x-suda-csrf-token";
|
|
36558
|
-
var WEBUSER_HEADER_KEY = "x-larkgw-suda-webuser";
|
|
36559
|
-
function isLocalDev() {
|
|
36560
|
-
if (process.env.NODE_ENV === "production") return false;
|
|
36561
|
-
const flag = process.env.MIAODA_LOCAL_DEV;
|
|
36562
|
-
return flag === "1" || flag === "true";
|
|
36563
|
-
}
|
|
36564
|
-
__name(isLocalDev, "isLocalDev");
|
|
36565
|
-
function extractCsrfFromCookie(cookieHeader) {
|
|
36566
|
-
if (!cookieHeader) return void 0;
|
|
36567
|
-
const re = new RegExp(`(?:^|;\\s*)${CSRF_COOKIE_KEY}=([^;]+)`);
|
|
36568
|
-
const m = cookieHeader.match(re);
|
|
36569
|
-
return m?.[1];
|
|
36570
|
-
}
|
|
36571
|
-
__name(extractCsrfFromCookie, "extractCsrfFromCookie");
|
|
36572
|
-
function createLocalDevMiddleware() {
|
|
36573
|
-
let webUserHeader = "";
|
|
36574
|
-
const parsed = parseSudaWebUserEnv(process.env.SUDA_WEBUSER);
|
|
36575
|
-
if (parsed) {
|
|
36576
|
-
webUserHeader = encodeURIComponent(JSON.stringify(parsed));
|
|
36577
|
-
}
|
|
36578
|
-
return /* @__PURE__ */ __name(function localDevMiddleware(req, _res, next) {
|
|
36579
|
-
const headers = req.headers;
|
|
36580
|
-
if (!headers[CSRF_HEADER_KEY]) {
|
|
36581
|
-
const token = extractCsrfFromCookie(req.headers.cookie);
|
|
36582
|
-
if (token) headers[CSRF_HEADER_KEY] = token;
|
|
36583
|
-
}
|
|
36584
|
-
if (webUserHeader && !headers[WEBUSER_HEADER_KEY]) {
|
|
36585
|
-
headers[WEBUSER_HEADER_KEY] = webUserHeader;
|
|
36586
|
-
}
|
|
36587
|
-
next();
|
|
36588
|
-
}, "localDevMiddleware");
|
|
36589
|
-
}
|
|
36590
|
-
__name(createLocalDevMiddleware, "createLocalDevMiddleware");
|
|
36591
|
-
|
|
36592
36529
|
// src/setup.ts
|
|
36593
36530
|
var DEFAULT_BODY_LIMIT = "1mb";
|
|
36594
36531
|
var defaultPerms = {
|
|
@@ -36606,9 +36543,6 @@ async function configureApp(app, perms = defaultPerms) {
|
|
|
36606
36543
|
extended: true
|
|
36607
36544
|
}));
|
|
36608
36545
|
app.use(cookieParser());
|
|
36609
|
-
if (isLocalDev()) {
|
|
36610
|
-
app.use(createLocalDevMiddleware());
|
|
36611
|
-
}
|
|
36612
36546
|
app.use(createLegacyPathRedirectMiddleware());
|
|
36613
36547
|
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
36614
36548
|
app.setGlobalPrefix(globalPrefix);
|
|
@@ -36658,9 +36592,7 @@ export {
|
|
|
36658
36592
|
UserContextMiddleware,
|
|
36659
36593
|
ViewContextMiddleware,
|
|
36660
36594
|
configureApp,
|
|
36661
|
-
createLegacyPathRedirectMiddleware
|
|
36662
|
-
createLocalDevMiddleware,
|
|
36663
|
-
isLocalDev
|
|
36595
|
+
createLegacyPathRedirectMiddleware
|
|
36664
36596
|
};
|
|
36665
36597
|
/*! Bundled license information:
|
|
36666
36598
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-nestjs-core",
|
|
3
|
-
"version": "1.1.51
|
|
3
|
+
"version": "1.1.51",
|
|
4
4
|
"description": "FullStack Nestjs Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,20 +40,20 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@lark-apaas/file-service": "^0.1.2",
|
|
43
|
-
"@lark-apaas/http-client": "0.1.
|
|
44
|
-
"@lark-apaas/nestjs-authnpaas": "^1.0.
|
|
45
|
-
"@lark-apaas/nestjs-authzpaas": "^0.1.
|
|
46
|
-
"@lark-apaas/nestjs-capability": "^0.1.
|
|
47
|
-
"@lark-apaas/nestjs-common": "^0.1.
|
|
48
|
-
"@lark-apaas/nestjs-datapaas": "^1.0.
|
|
49
|
-
"@lark-apaas/nestjs-
|
|
50
|
-
"@lark-apaas/nestjs-
|
|
43
|
+
"@lark-apaas/http-client": "^0.1.6",
|
|
44
|
+
"@lark-apaas/nestjs-authnpaas": "^1.0.4",
|
|
45
|
+
"@lark-apaas/nestjs-authzpaas": "^0.1.9",
|
|
46
|
+
"@lark-apaas/nestjs-capability": "^0.1.14",
|
|
47
|
+
"@lark-apaas/nestjs-common": "^0.1.9",
|
|
48
|
+
"@lark-apaas/nestjs-datapaas": "^1.0.21",
|
|
49
|
+
"@lark-apaas/nestjs-http-forwarder": "^0.1.3",
|
|
50
|
+
"@lark-apaas/nestjs-logger": "^1.0.17",
|
|
51
|
+
"@lark-apaas/nestjs-observable": "^0.0.12",
|
|
51
52
|
"@lark-apaas/nestjs-openapi-devtools": "^1.0.10",
|
|
52
53
|
"@lark-apaas/nestjs-trigger": "^0.0.3",
|
|
53
54
|
"@nestjs/axios": "^4.0.1",
|
|
54
55
|
"axios": "^1.13.2",
|
|
55
|
-
"cookie-parser": "^1.4.7"
|
|
56
|
-
"dotenv": "^16.4.5"
|
|
56
|
+
"cookie-parser": "^1.4.7"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@nestjs/common": "^10.4.20",
|