@lark-apaas/fullstack-nestjs-core 1.1.2-alpha.11 → 1.1.3

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
@@ -39,7 +39,6 @@ __export(index_exports, {
39
39
  PlatformModule: () => PlatformModule,
40
40
  UserContextMiddleware: () => UserContextMiddleware,
41
41
  ViewContextMiddleware: () => ViewContextMiddleware,
42
- apiResponseInterceptor: () => apiResponseInterceptor,
43
42
  configureApp: () => configureApp
44
43
  });
45
44
  module.exports = __toCommonJS(index_exports);
@@ -93,6 +92,7 @@ var UserContextMiddleware = class {
93
92
  tenantId: webUser?.tenant_id,
94
93
  appId: webUser?.app_id ?? "",
95
94
  loginUrl: webUser?.login_url ?? "",
95
+ userType: webUser?.user_type ?? "",
96
96
  env: webUser?.env ?? "runtime",
97
97
  userName: webUser?.user_name?.zh_cn ?? "",
98
98
  userNameEn: webUser?.user_name?.en_us ?? "",
@@ -265,7 +265,7 @@ CsrfTokenMiddleware = _ts_decorate4([
265
265
  // src/middlewares/api-fallback/index.ts
266
266
  function createApiNotFoundResponse(req) {
267
267
  return {
268
- statusCode: 404,
268
+ code: 404,
269
269
  message: `Cannot ${req.method} ${req.path}`,
270
270
  error: "Not Found",
271
271
  path: req.path,
@@ -273,8 +273,18 @@ function createApiNotFoundResponse(req) {
273
273
  };
274
274
  }
275
275
  __name(createApiNotFoundResponse, "createApiNotFoundResponse");
276
+ function getApiPathPrefix() {
277
+ const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
278
+ if (!globalPrefix) {
279
+ return "/api/";
280
+ }
281
+ const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
282
+ return `${normalizedPrefix}/api/`;
283
+ }
284
+ __name(getApiPathPrefix, "getApiPathPrefix");
276
285
  function apiResponseInterceptor(req, res, next) {
277
- if (!req.path.startsWith("/api/")) {
286
+ const apiPrefix = getApiPathPrefix();
287
+ if (!req.baseUrl.startsWith(apiPrefix)) {
278
288
  return next();
279
289
  }
280
290
  res.render = function() {
@@ -439,7 +449,6 @@ __reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports
439
449
  PlatformModule,
440
450
  UserContextMiddleware,
441
451
  ViewContextMiddleware,
442
- apiResponseInterceptor,
443
452
  configureApp,
444
453
  ...require("@lark-apaas/nestjs-authnpaas"),
445
454
  ...require("@lark-apaas/nestjs-datapaas")
package/dist/index.d.cts CHANGED
@@ -19,6 +19,7 @@ declare global {
19
19
  tenantId?: number;
20
20
  appId?: string;
21
21
  loginUrl?: string;
22
+ userType?: string;
22
23
  env?: 'preview' | 'runtime';
23
24
  userName?: string; // 默认中文名
24
25
  userNameEn?: string; // 冗余一份英文名
@@ -100,23 +101,11 @@ declare class ViewContextMiddleware implements NestMiddleware {
100
101
  * API 404 响应格式
101
102
  */
102
103
  interface ApiNotFoundResponse {
103
- statusCode: number;
104
+ code: number;
104
105
  message: string;
105
106
  error: string;
106
107
  path: string;
107
108
  timestamp: string;
108
109
  }
109
- /**
110
- * API 响应拦截中间件
111
- *
112
- * 拦截 ViewModule 的 /* 路由,当其尝试返回 HTML 时
113
- * 如果请求路径是 /api/*,改为返回 JSON 404
114
- *
115
- * 工作原理:
116
- * 1. 包装 res.render() 和 res.send()
117
- * 2. render() 直接返回 JSON(肯定是要渲染 HTML)
118
- * 3. send() 检查 Content-Type 判断是否是 HTML
119
- */
120
- declare function apiResponseInterceptor(req: Request, res: Response, next: NextFunction): void;
121
110
 
122
- export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, apiResponseInterceptor, configureApp };
111
+ export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ declare global {
19
19
  tenantId?: number;
20
20
  appId?: string;
21
21
  loginUrl?: string;
22
+ userType?: string;
22
23
  env?: 'preview' | 'runtime';
23
24
  userName?: string; // 默认中文名
24
25
  userNameEn?: string; // 冗余一份英文名
@@ -100,23 +101,11 @@ declare class ViewContextMiddleware implements NestMiddleware {
100
101
  * API 404 响应格式
101
102
  */
102
103
  interface ApiNotFoundResponse {
103
- statusCode: number;
104
+ code: number;
104
105
  message: string;
105
106
  error: string;
106
107
  path: string;
107
108
  timestamp: string;
108
109
  }
109
- /**
110
- * API 响应拦截中间件
111
- *
112
- * 拦截 ViewModule 的 /* 路由,当其尝试返回 HTML 时
113
- * 如果请求路径是 /api/*,改为返回 JSON 404
114
- *
115
- * 工作原理:
116
- * 1. 包装 res.render() 和 res.send()
117
- * 2. render() 直接返回 JSON(肯定是要渲染 HTML)
118
- * 3. send() 检查 Content-Type 判断是否是 HTML
119
- */
120
- declare function apiResponseInterceptor(req: Request, res: Response, next: NextFunction): void;
121
110
 
122
- export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, apiResponseInterceptor, configureApp };
111
+ export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
package/dist/index.js CHANGED
@@ -50,6 +50,7 @@ var UserContextMiddleware = class {
50
50
  tenantId: webUser?.tenant_id,
51
51
  appId: webUser?.app_id ?? "",
52
52
  loginUrl: webUser?.login_url ?? "",
53
+ userType: webUser?.user_type ?? "",
53
54
  env: webUser?.env ?? "runtime",
54
55
  userName: webUser?.user_name?.zh_cn ?? "",
55
56
  userNameEn: webUser?.user_name?.en_us ?? "",
@@ -222,7 +223,7 @@ CsrfTokenMiddleware = _ts_decorate4([
222
223
  // src/middlewares/api-fallback/index.ts
223
224
  function createApiNotFoundResponse(req) {
224
225
  return {
225
- statusCode: 404,
226
+ code: 404,
226
227
  message: `Cannot ${req.method} ${req.path}`,
227
228
  error: "Not Found",
228
229
  path: req.path,
@@ -230,8 +231,18 @@ function createApiNotFoundResponse(req) {
230
231
  };
231
232
  }
232
233
  __name(createApiNotFoundResponse, "createApiNotFoundResponse");
234
+ function getApiPathPrefix() {
235
+ const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
236
+ if (!globalPrefix) {
237
+ return "/api/";
238
+ }
239
+ const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
240
+ return `${normalizedPrefix}/api/`;
241
+ }
242
+ __name(getApiPathPrefix, "getApiPathPrefix");
233
243
  function apiResponseInterceptor(req, res, next) {
234
- if (!req.path.startsWith("/api/")) {
244
+ const apiPrefix = getApiPathPrefix();
245
+ if (!req.baseUrl.startsWith(apiPrefix)) {
235
246
  return next();
236
247
  }
237
248
  res.render = function() {
@@ -395,6 +406,5 @@ export {
395
406
  PlatformModule,
396
407
  UserContextMiddleware,
397
408
  ViewContextMiddleware,
398
- apiResponseInterceptor,
399
409
  configureApp
400
410
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.1.2-alpha.11",
3
+ "version": "1.1.3",
4
4
  "description": "FullStack Nestjs Core",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",