@lark-apaas/fullstack-nestjs-core 1.0.15-alpha.14 → 1.0.15-alpha.15
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 +44 -4
- package/dist/index.d.cts +27 -3
- package/dist/index.d.ts +27 -3
- package/dist/index.js +44 -4
- package/package.json +6 -5
package/dist/index.cjs
CHANGED
|
@@ -92,7 +92,11 @@ var UserContextMiddleware = class {
|
|
|
92
92
|
tenantId: webUser?.tenant_id,
|
|
93
93
|
appId: webUser?.app_id ?? "",
|
|
94
94
|
loginUrl: webUser?.login_url ?? "",
|
|
95
|
-
userType: webUser?.user_type ?? ""
|
|
95
|
+
userType: webUser?.user_type ?? "",
|
|
96
|
+
env: webUser?.env ?? "runtime",
|
|
97
|
+
userName: webUser?.user_name?.zh_cn ?? "",
|
|
98
|
+
userNameEn: webUser?.user_name?.en_us ?? "",
|
|
99
|
+
userNameI18n: webUser?.user_name ?? {}
|
|
96
100
|
};
|
|
97
101
|
next();
|
|
98
102
|
}
|
|
@@ -249,7 +253,7 @@ var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
|
249
253
|
res.cookie(cookieKey, token, {
|
|
250
254
|
maxAge: cookieMaxAge,
|
|
251
255
|
path: cookiePath,
|
|
252
|
-
httpOnly:
|
|
256
|
+
httpOnly: false,
|
|
253
257
|
secure: true,
|
|
254
258
|
sameSite: "none",
|
|
255
259
|
partitioned: true
|
|
@@ -262,6 +266,38 @@ CsrfTokenMiddleware = _ts_decorate4([
|
|
|
262
266
|
(0, import_common4.Injectable)()
|
|
263
267
|
], CsrfTokenMiddleware);
|
|
264
268
|
|
|
269
|
+
// src/middlewares/api-fallback/index.ts
|
|
270
|
+
function createApiNotFoundResponse(req) {
|
|
271
|
+
return {
|
|
272
|
+
code: 404,
|
|
273
|
+
message: `Cannot ${req.method} ${req.path}`,
|
|
274
|
+
error: "Not Found",
|
|
275
|
+
path: req.path,
|
|
276
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
__name(createApiNotFoundResponse, "createApiNotFoundResponse");
|
|
280
|
+
function getApiPathPrefix() {
|
|
281
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
282
|
+
if (!globalPrefix) {
|
|
283
|
+
return "/api/";
|
|
284
|
+
}
|
|
285
|
+
const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
|
|
286
|
+
return `${normalizedPrefix}/api/`;
|
|
287
|
+
}
|
|
288
|
+
__name(getApiPathPrefix, "getApiPathPrefix");
|
|
289
|
+
function apiResponseInterceptor(req, res, next) {
|
|
290
|
+
const apiPrefix = getApiPathPrefix();
|
|
291
|
+
if (!req.baseUrl.startsWith(apiPrefix)) {
|
|
292
|
+
return next();
|
|
293
|
+
}
|
|
294
|
+
res.render = function() {
|
|
295
|
+
return res.status(404).json(createApiNotFoundResponse(req));
|
|
296
|
+
};
|
|
297
|
+
next();
|
|
298
|
+
}
|
|
299
|
+
__name(apiResponseInterceptor, "apiResponseInterceptor");
|
|
300
|
+
|
|
265
301
|
// src/modules/platform/config/app.config.ts
|
|
266
302
|
var import_config = require("@nestjs/config");
|
|
267
303
|
var NAMESPACE = "app";
|
|
@@ -360,6 +396,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
360
396
|
*/
|
|
361
397
|
configure(consumer) {
|
|
362
398
|
const options = _PlatformModule.moduleOptions;
|
|
399
|
+
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
363
400
|
consumer.apply(UserContextMiddleware, import_nestjs_logger.LoggerContextMiddleware, import_nestjs_datapaas.SqlExecutionContextMiddleware).forRoutes("/*");
|
|
364
401
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
365
402
|
if (options.enableCsrf !== false) {
|
|
@@ -383,13 +420,16 @@ PlatformModule = _ts_decorate5([
|
|
|
383
420
|
var import_nestjs_logger2 = require("@lark-apaas/nestjs-logger");
|
|
384
421
|
var import_cookie_parser = __toESM(require("cookie-parser"), 1);
|
|
385
422
|
var import_nestjs_openapi_devtools = require("@lark-apaas/nestjs-openapi-devtools");
|
|
386
|
-
|
|
423
|
+
var defaultPerms = {
|
|
424
|
+
disableSwagger: false
|
|
425
|
+
};
|
|
426
|
+
async function configureApp(app, perms = defaultPerms) {
|
|
387
427
|
app.useLogger(app.get(import_nestjs_logger2.AppLogger));
|
|
388
428
|
app.flushLogs();
|
|
389
429
|
app.use((0, import_cookie_parser.default)());
|
|
390
430
|
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
391
431
|
app.setGlobalPrefix(globalPrefix);
|
|
392
|
-
if (process.env.NODE_ENV !== "production") {
|
|
432
|
+
if (process.env.NODE_ENV !== "production" && perms.disableSwagger !== true) {
|
|
393
433
|
try {
|
|
394
434
|
await import_nestjs_openapi_devtools.DevToolsV2Module.mount(app, {
|
|
395
435
|
basePath: process.env.CLIENT_BASE_PATH,
|
package/dist/index.d.cts
CHANGED
|
@@ -21,7 +21,11 @@ declare global {
|
|
|
21
21
|
appId?: string;
|
|
22
22
|
loginUrl?: string;
|
|
23
23
|
userType?: string;
|
|
24
|
-
|
|
24
|
+
env?: 'preview' | 'runtime';
|
|
25
|
+
userName?: string; // 默认中文名
|
|
26
|
+
userNameEn?: string; // 冗余一份英文名
|
|
27
|
+
userNameI18n?: Record<string, string>; // 带多语的用户名
|
|
28
|
+
},
|
|
25
29
|
csrfToken?: string;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
@@ -52,7 +56,16 @@ declare class PlatformModule implements NestModule {
|
|
|
52
56
|
configure(consumer: MiddlewareConsumer): void;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
/**
|
|
60
|
+
* 初始化应用的基础能力(中间件、过滤器、Swagger 等)。
|
|
61
|
+
*
|
|
62
|
+
* @param app NestExpressApplication 实例
|
|
63
|
+
* @param perms 配置项
|
|
64
|
+
* @param perms.disableSwagger 是否禁用 Swagger(默认:false)
|
|
65
|
+
*/
|
|
66
|
+
declare function configureApp(app: NestExpressApplication, perms?: {
|
|
67
|
+
disableSwagger?: boolean;
|
|
68
|
+
}): Promise<void>;
|
|
56
69
|
|
|
57
70
|
interface CsrfTokenOptions {
|
|
58
71
|
cookieKey?: string;
|
|
@@ -85,4 +98,15 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
85
98
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
86
99
|
}
|
|
87
100
|
|
|
88
|
-
|
|
101
|
+
/**
|
|
102
|
+
* API 404 响应格式
|
|
103
|
+
*/
|
|
104
|
+
interface ApiNotFoundResponse {
|
|
105
|
+
code: number;
|
|
106
|
+
message: string;
|
|
107
|
+
error: string;
|
|
108
|
+
path: string;
|
|
109
|
+
timestamp: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,11 @@ declare global {
|
|
|
21
21
|
appId?: string;
|
|
22
22
|
loginUrl?: string;
|
|
23
23
|
userType?: string;
|
|
24
|
-
|
|
24
|
+
env?: 'preview' | 'runtime';
|
|
25
|
+
userName?: string; // 默认中文名
|
|
26
|
+
userNameEn?: string; // 冗余一份英文名
|
|
27
|
+
userNameI18n?: Record<string, string>; // 带多语的用户名
|
|
28
|
+
},
|
|
25
29
|
csrfToken?: string;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
@@ -52,7 +56,16 @@ declare class PlatformModule implements NestModule {
|
|
|
52
56
|
configure(consumer: MiddlewareConsumer): void;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
/**
|
|
60
|
+
* 初始化应用的基础能力(中间件、过滤器、Swagger 等)。
|
|
61
|
+
*
|
|
62
|
+
* @param app NestExpressApplication 实例
|
|
63
|
+
* @param perms 配置项
|
|
64
|
+
* @param perms.disableSwagger 是否禁用 Swagger(默认:false)
|
|
65
|
+
*/
|
|
66
|
+
declare function configureApp(app: NestExpressApplication, perms?: {
|
|
67
|
+
disableSwagger?: boolean;
|
|
68
|
+
}): Promise<void>;
|
|
56
69
|
|
|
57
70
|
interface CsrfTokenOptions {
|
|
58
71
|
cookieKey?: string;
|
|
@@ -85,4 +98,15 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
85
98
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
86
99
|
}
|
|
87
100
|
|
|
88
|
-
|
|
101
|
+
/**
|
|
102
|
+
* API 404 响应格式
|
|
103
|
+
*/
|
|
104
|
+
interface ApiNotFoundResponse {
|
|
105
|
+
code: number;
|
|
106
|
+
message: string;
|
|
107
|
+
error: string;
|
|
108
|
+
path: string;
|
|
109
|
+
timestamp: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { type ApiNotFoundResponse, CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
|
package/dist/index.js
CHANGED
|
@@ -50,7 +50,11 @@ 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
|
+
userType: webUser?.user_type ?? "",
|
|
54
|
+
env: webUser?.env ?? "runtime",
|
|
55
|
+
userName: webUser?.user_name?.zh_cn ?? "",
|
|
56
|
+
userNameEn: webUser?.user_name?.en_us ?? "",
|
|
57
|
+
userNameI18n: webUser?.user_name ?? {}
|
|
54
58
|
};
|
|
55
59
|
next();
|
|
56
60
|
}
|
|
@@ -207,7 +211,7 @@ var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
|
207
211
|
res.cookie(cookieKey, token, {
|
|
208
212
|
maxAge: cookieMaxAge,
|
|
209
213
|
path: cookiePath,
|
|
210
|
-
httpOnly:
|
|
214
|
+
httpOnly: false,
|
|
211
215
|
secure: true,
|
|
212
216
|
sameSite: "none",
|
|
213
217
|
partitioned: true
|
|
@@ -220,6 +224,38 @@ CsrfTokenMiddleware = _ts_decorate4([
|
|
|
220
224
|
Injectable4()
|
|
221
225
|
], CsrfTokenMiddleware);
|
|
222
226
|
|
|
227
|
+
// src/middlewares/api-fallback/index.ts
|
|
228
|
+
function createApiNotFoundResponse(req) {
|
|
229
|
+
return {
|
|
230
|
+
code: 404,
|
|
231
|
+
message: `Cannot ${req.method} ${req.path}`,
|
|
232
|
+
error: "Not Found",
|
|
233
|
+
path: req.path,
|
|
234
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
__name(createApiNotFoundResponse, "createApiNotFoundResponse");
|
|
238
|
+
function getApiPathPrefix() {
|
|
239
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
240
|
+
if (!globalPrefix) {
|
|
241
|
+
return "/api/";
|
|
242
|
+
}
|
|
243
|
+
const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
|
|
244
|
+
return `${normalizedPrefix}/api/`;
|
|
245
|
+
}
|
|
246
|
+
__name(getApiPathPrefix, "getApiPathPrefix");
|
|
247
|
+
function apiResponseInterceptor(req, res, next) {
|
|
248
|
+
const apiPrefix = getApiPathPrefix();
|
|
249
|
+
if (!req.baseUrl.startsWith(apiPrefix)) {
|
|
250
|
+
return next();
|
|
251
|
+
}
|
|
252
|
+
res.render = function() {
|
|
253
|
+
return res.status(404).json(createApiNotFoundResponse(req));
|
|
254
|
+
};
|
|
255
|
+
next();
|
|
256
|
+
}
|
|
257
|
+
__name(apiResponseInterceptor, "apiResponseInterceptor");
|
|
258
|
+
|
|
223
259
|
// src/modules/platform/config/app.config.ts
|
|
224
260
|
import { registerAs } from "@nestjs/config";
|
|
225
261
|
var NAMESPACE = "app";
|
|
@@ -318,6 +354,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
318
354
|
*/
|
|
319
355
|
configure(consumer) {
|
|
320
356
|
const options = _PlatformModule.moduleOptions;
|
|
357
|
+
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
321
358
|
consumer.apply(UserContextMiddleware, LoggerContextMiddleware, SqlExecutionContextMiddleware).forRoutes("/*");
|
|
322
359
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
323
360
|
if (options.enableCsrf !== false) {
|
|
@@ -341,13 +378,16 @@ PlatformModule = _ts_decorate5([
|
|
|
341
378
|
import { AppLogger as AppLogger2 } from "@lark-apaas/nestjs-logger";
|
|
342
379
|
import cookieParser from "cookie-parser";
|
|
343
380
|
import { DevToolsV2Module } from "@lark-apaas/nestjs-openapi-devtools";
|
|
344
|
-
|
|
381
|
+
var defaultPerms = {
|
|
382
|
+
disableSwagger: false
|
|
383
|
+
};
|
|
384
|
+
async function configureApp(app, perms = defaultPerms) {
|
|
345
385
|
app.useLogger(app.get(AppLogger2));
|
|
346
386
|
app.flushLogs();
|
|
347
387
|
app.use(cookieParser());
|
|
348
388
|
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
349
389
|
app.setGlobalPrefix(globalPrefix);
|
|
350
|
-
if (process.env.NODE_ENV !== "production") {
|
|
390
|
+
if (process.env.NODE_ENV !== "production" && perms.disableSwagger !== true) {
|
|
351
391
|
try {
|
|
352
392
|
await DevToolsV2Module.mount(app, {
|
|
353
393
|
basePath: process.env.CLIENT_BASE_PATH,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-nestjs-core",
|
|
3
|
-
"version": "1.0.15-alpha.
|
|
3
|
+
"version": "1.0.15-alpha.15",
|
|
4
4
|
"description": "FullStack Nestjs Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,14 +35,15 @@
|
|
|
35
35
|
"test": "vitest run",
|
|
36
36
|
"test:watch": "vitest",
|
|
37
37
|
"lint": "echo 'ESLint skipped for TypeScript files'",
|
|
38
|
-
"lint:fix": "eslint src --ext .ts --fix"
|
|
38
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
39
|
+
"prepublishOnly": "npm run build"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@lark-apaas/nestjs-authnpaas": "^1.0.0",
|
|
42
|
-
"@lark-apaas/nestjs-authzpaas": "0.1.0-alpha.
|
|
43
|
-
"@lark-apaas/nestjs-datapaas": "1.0.6-alpha.
|
|
43
|
+
"@lark-apaas/nestjs-authzpaas": "0.1.0-alpha.13",
|
|
44
|
+
"@lark-apaas/nestjs-datapaas": "1.0.6-alpha.13",
|
|
44
45
|
"@lark-apaas/nestjs-logger": "^1.0.2",
|
|
45
|
-
"@lark-apaas/nestjs-openapi-devtools": "^1.0.
|
|
46
|
+
"@lark-apaas/nestjs-openapi-devtools": "^1.0.9",
|
|
46
47
|
"cookie-parser": "^1.4.7"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|