@lark-apaas/fullstack-nestjs-core 1.1.1-alpha.13 → 1.1.1-alpha.14
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 -12
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +44 -12
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -52,7 +52,6 @@ var import_nestjs_observable = require("@lark-apaas/nestjs-observable");
|
|
|
52
52
|
var import_nestjs_logger = require("@lark-apaas/nestjs-logger");
|
|
53
53
|
var import_nestjs_datapaas = require("@lark-apaas/nestjs-datapaas");
|
|
54
54
|
var import_nestjs_authnpaas = require("@lark-apaas/nestjs-authnpaas");
|
|
55
|
-
var import_nestjs_trigger = require("@lark-apaas/nestjs-trigger");
|
|
56
55
|
|
|
57
56
|
// src/middlewares/user-context/index.ts
|
|
58
57
|
var import_common = require("@nestjs/common");
|
|
@@ -94,7 +93,12 @@ var UserContextMiddleware = class {
|
|
|
94
93
|
userId: webUser?.user_id,
|
|
95
94
|
tenantId: webUser?.tenant_id,
|
|
96
95
|
appId: webUser?.app_id ?? "",
|
|
97
|
-
loginUrl: webUser?.login_url ?? ""
|
|
96
|
+
loginUrl: webUser?.login_url ?? "",
|
|
97
|
+
userType: webUser?.user_type ?? "",
|
|
98
|
+
env: webUser?.env ?? "runtime",
|
|
99
|
+
userName: webUser?.user_name?.zh_cn ?? "",
|
|
100
|
+
userNameEn: webUser?.user_name?.en_us ?? "",
|
|
101
|
+
userNameI18n: webUser?.user_name ?? {}
|
|
98
102
|
};
|
|
99
103
|
next();
|
|
100
104
|
}
|
|
@@ -247,7 +251,7 @@ var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
|
247
251
|
res.cookie(cookieKey, token, {
|
|
248
252
|
maxAge: cookieMaxAge,
|
|
249
253
|
path: cookiePath,
|
|
250
|
-
httpOnly:
|
|
254
|
+
httpOnly: false,
|
|
251
255
|
secure: true,
|
|
252
256
|
sameSite: "none",
|
|
253
257
|
partitioned: true
|
|
@@ -260,6 +264,38 @@ CsrfTokenMiddleware = _ts_decorate4([
|
|
|
260
264
|
(0, import_common4.Injectable)()
|
|
261
265
|
], CsrfTokenMiddleware);
|
|
262
266
|
|
|
267
|
+
// src/middlewares/api-fallback/index.ts
|
|
268
|
+
function createApiNotFoundResponse(req) {
|
|
269
|
+
return {
|
|
270
|
+
code: 404,
|
|
271
|
+
message: `Cannot ${req.method} ${req.path}`,
|
|
272
|
+
error: "Not Found",
|
|
273
|
+
path: req.path,
|
|
274
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
__name(createApiNotFoundResponse, "createApiNotFoundResponse");
|
|
278
|
+
function getApiPathPrefix() {
|
|
279
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
280
|
+
if (!globalPrefix) {
|
|
281
|
+
return "/api/";
|
|
282
|
+
}
|
|
283
|
+
const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
|
|
284
|
+
return `${normalizedPrefix}/api/`;
|
|
285
|
+
}
|
|
286
|
+
__name(getApiPathPrefix, "getApiPathPrefix");
|
|
287
|
+
function apiResponseInterceptor(req, res, next) {
|
|
288
|
+
const apiPrefix = getApiPathPrefix();
|
|
289
|
+
if (!req.baseUrl.startsWith(apiPrefix)) {
|
|
290
|
+
return next();
|
|
291
|
+
}
|
|
292
|
+
res.render = function() {
|
|
293
|
+
return res.status(404).json(createApiNotFoundResponse(req));
|
|
294
|
+
};
|
|
295
|
+
next();
|
|
296
|
+
}
|
|
297
|
+
__name(apiResponseInterceptor, "apiResponseInterceptor");
|
|
298
|
+
|
|
263
299
|
// src/modules/platform/config/app.config.ts
|
|
264
300
|
var import_config = require("@nestjs/config");
|
|
265
301
|
var NAMESPACE = "app";
|
|
@@ -330,12 +366,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
330
366
|
};
|
|
331
367
|
}, "useFactory")
|
|
332
368
|
}),
|
|
333
|
-
import_nestjs_authnpaas.AuthNPaasModule.forRoot()
|
|
334
|
-
import_nestjs_trigger.AutomationModule.forRoot({
|
|
335
|
-
imports: [
|
|
336
|
-
import_nestjs_logger.LoggerModule
|
|
337
|
-
]
|
|
338
|
-
})
|
|
369
|
+
import_nestjs_authnpaas.AuthNPaasModule.forRoot()
|
|
339
370
|
],
|
|
340
371
|
providers: [
|
|
341
372
|
{
|
|
@@ -363,7 +394,8 @@ var PlatformModule = class _PlatformModule {
|
|
|
363
394
|
*/
|
|
364
395
|
configure(consumer) {
|
|
365
396
|
const options = _PlatformModule.moduleOptions;
|
|
366
|
-
consumer.apply(
|
|
397
|
+
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
398
|
+
consumer.apply(UserContextMiddleware, import_nestjs_logger.LoggerContextMiddleware, import_nestjs_observable.ObservableTraceMiddleware, import_nestjs_datapaas.SqlExecutionContextMiddleware).forRoutes("/*");
|
|
367
399
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
368
400
|
if (options.enableCsrf !== false) {
|
|
369
401
|
const csrfRoutes = options.csrfRoutes || "/api/*";
|
|
@@ -412,7 +444,7 @@ __name(configureApp, "configureApp");
|
|
|
412
444
|
var import_nestjs_openapi_devtools2 = require("@lark-apaas/nestjs-openapi-devtools");
|
|
413
445
|
__reExport(index_exports, require("@lark-apaas/nestjs-authnpaas"), module.exports);
|
|
414
446
|
__reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports);
|
|
415
|
-
__reExport(index_exports, require("@lark-apaas/nestjs-
|
|
447
|
+
__reExport(index_exports, require("@lark-apaas/nestjs-observable"), module.exports);
|
|
416
448
|
// Annotate the CommonJS export names for ESM import in node:
|
|
417
449
|
0 && (module.exports = {
|
|
418
450
|
CsrfMiddleware,
|
|
@@ -425,5 +457,5 @@ __reExport(index_exports, require("@lark-apaas/nestjs-trigger"), module.exports)
|
|
|
425
457
|
configureApp,
|
|
426
458
|
...require("@lark-apaas/nestjs-authnpaas"),
|
|
427
459
|
...require("@lark-apaas/nestjs-datapaas"),
|
|
428
|
-
...require("@lark-apaas/nestjs-
|
|
460
|
+
...require("@lark-apaas/nestjs-observable")
|
|
429
461
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options }
|
|
|
4
4
|
import { Request, Response, NextFunction } from 'express';
|
|
5
5
|
export * from '@lark-apaas/nestjs-authnpaas';
|
|
6
6
|
export * from '@lark-apaas/nestjs-datapaas';
|
|
7
|
-
export * from '@lark-apaas/nestjs-
|
|
7
|
+
export * from '@lark-apaas/nestjs-observable';
|
|
8
8
|
|
|
9
9
|
declare global {
|
|
10
10
|
namespace Express {
|
|
@@ -20,6 +20,11 @@ declare global {
|
|
|
20
20
|
tenantId?: number;
|
|
21
21
|
appId?: string;
|
|
22
22
|
loginUrl?: string;
|
|
23
|
+
userType?: string;
|
|
24
|
+
env?: 'preview' | 'runtime';
|
|
25
|
+
userName?: string; // 默认中文名
|
|
26
|
+
userNameEn?: string; // 冗余一份英文名
|
|
27
|
+
userNameI18n?: Record<string, string>; // 带多语的用户名
|
|
23
28
|
},
|
|
24
29
|
csrfToken?: string;
|
|
25
30
|
}
|
|
@@ -93,4 +98,15 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
93
98
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
|
|
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
|
@@ -4,7 +4,7 @@ export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options }
|
|
|
4
4
|
import { Request, Response, NextFunction } from 'express';
|
|
5
5
|
export * from '@lark-apaas/nestjs-authnpaas';
|
|
6
6
|
export * from '@lark-apaas/nestjs-datapaas';
|
|
7
|
-
export * from '@lark-apaas/nestjs-
|
|
7
|
+
export * from '@lark-apaas/nestjs-observable';
|
|
8
8
|
|
|
9
9
|
declare global {
|
|
10
10
|
namespace Express {
|
|
@@ -20,6 +20,11 @@ declare global {
|
|
|
20
20
|
tenantId?: number;
|
|
21
21
|
appId?: string;
|
|
22
22
|
loginUrl?: string;
|
|
23
|
+
userType?: string;
|
|
24
|
+
env?: 'preview' | 'runtime';
|
|
25
|
+
userName?: string; // 默认中文名
|
|
26
|
+
userNameEn?: string; // 冗余一份英文名
|
|
27
|
+
userNameI18n?: Record<string, string>; // 带多语的用户名
|
|
23
28
|
},
|
|
24
29
|
csrfToken?: string;
|
|
25
30
|
}
|
|
@@ -93,4 +98,15 @@ declare class ViewContextMiddleware implements NestMiddleware {
|
|
|
93
98
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
|
|
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
|
@@ -6,11 +6,10 @@ import { Global, Module, ValidationPipe } from "@nestjs/common";
|
|
|
6
6
|
import { APP_PIPE } from "@nestjs/core";
|
|
7
7
|
import { CommonModule } from "@lark-apaas/nestjs-common";
|
|
8
8
|
import { ConfigModule, ConfigService } from "@nestjs/config";
|
|
9
|
-
import { NestjsObservableModule as ObservableModule } from "@lark-apaas/nestjs-observable";
|
|
9
|
+
import { NestjsObservableModule as ObservableModule, ObservableTraceMiddleware } from "@lark-apaas/nestjs-observable";
|
|
10
10
|
import { LoggerModule, AppLogger, LoggerContextMiddleware } from "@lark-apaas/nestjs-logger";
|
|
11
11
|
import { DataPaasModule, SqlExecutionContextMiddleware } from "@lark-apaas/nestjs-datapaas";
|
|
12
12
|
import { AuthNPaasModule } from "@lark-apaas/nestjs-authnpaas";
|
|
13
|
-
import { AutomationModule } from "@lark-apaas/nestjs-trigger";
|
|
14
13
|
|
|
15
14
|
// src/middlewares/user-context/index.ts
|
|
16
15
|
import { Injectable } from "@nestjs/common";
|
|
@@ -52,7 +51,12 @@ var UserContextMiddleware = class {
|
|
|
52
51
|
userId: webUser?.user_id,
|
|
53
52
|
tenantId: webUser?.tenant_id,
|
|
54
53
|
appId: webUser?.app_id ?? "",
|
|
55
|
-
loginUrl: webUser?.login_url ?? ""
|
|
54
|
+
loginUrl: webUser?.login_url ?? "",
|
|
55
|
+
userType: webUser?.user_type ?? "",
|
|
56
|
+
env: webUser?.env ?? "runtime",
|
|
57
|
+
userName: webUser?.user_name?.zh_cn ?? "",
|
|
58
|
+
userNameEn: webUser?.user_name?.en_us ?? "",
|
|
59
|
+
userNameI18n: webUser?.user_name ?? {}
|
|
56
60
|
};
|
|
57
61
|
next();
|
|
58
62
|
}
|
|
@@ -205,7 +209,7 @@ var CsrfTokenMiddleware = class _CsrfTokenMiddleware {
|
|
|
205
209
|
res.cookie(cookieKey, token, {
|
|
206
210
|
maxAge: cookieMaxAge,
|
|
207
211
|
path: cookiePath,
|
|
208
|
-
httpOnly:
|
|
212
|
+
httpOnly: false,
|
|
209
213
|
secure: true,
|
|
210
214
|
sameSite: "none",
|
|
211
215
|
partitioned: true
|
|
@@ -218,6 +222,38 @@ CsrfTokenMiddleware = _ts_decorate4([
|
|
|
218
222
|
Injectable4()
|
|
219
223
|
], CsrfTokenMiddleware);
|
|
220
224
|
|
|
225
|
+
// src/middlewares/api-fallback/index.ts
|
|
226
|
+
function createApiNotFoundResponse(req) {
|
|
227
|
+
return {
|
|
228
|
+
code: 404,
|
|
229
|
+
message: `Cannot ${req.method} ${req.path}`,
|
|
230
|
+
error: "Not Found",
|
|
231
|
+
path: req.path,
|
|
232
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
__name(createApiNotFoundResponse, "createApiNotFoundResponse");
|
|
236
|
+
function getApiPathPrefix() {
|
|
237
|
+
const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
|
|
238
|
+
if (!globalPrefix) {
|
|
239
|
+
return "/api/";
|
|
240
|
+
}
|
|
241
|
+
const normalizedPrefix = globalPrefix.replace(/\/+$/, "");
|
|
242
|
+
return `${normalizedPrefix}/api/`;
|
|
243
|
+
}
|
|
244
|
+
__name(getApiPathPrefix, "getApiPathPrefix");
|
|
245
|
+
function apiResponseInterceptor(req, res, next) {
|
|
246
|
+
const apiPrefix = getApiPathPrefix();
|
|
247
|
+
if (!req.baseUrl.startsWith(apiPrefix)) {
|
|
248
|
+
return next();
|
|
249
|
+
}
|
|
250
|
+
res.render = function() {
|
|
251
|
+
return res.status(404).json(createApiNotFoundResponse(req));
|
|
252
|
+
};
|
|
253
|
+
next();
|
|
254
|
+
}
|
|
255
|
+
__name(apiResponseInterceptor, "apiResponseInterceptor");
|
|
256
|
+
|
|
221
257
|
// src/modules/platform/config/app.config.ts
|
|
222
258
|
import { registerAs } from "@nestjs/config";
|
|
223
259
|
var NAMESPACE = "app";
|
|
@@ -288,12 +324,7 @@ var PlatformModule = class _PlatformModule {
|
|
|
288
324
|
};
|
|
289
325
|
}, "useFactory")
|
|
290
326
|
}),
|
|
291
|
-
AuthNPaasModule.forRoot()
|
|
292
|
-
AutomationModule.forRoot({
|
|
293
|
-
imports: [
|
|
294
|
-
LoggerModule
|
|
295
|
-
]
|
|
296
|
-
})
|
|
327
|
+
AuthNPaasModule.forRoot()
|
|
297
328
|
],
|
|
298
329
|
providers: [
|
|
299
330
|
{
|
|
@@ -321,7 +352,8 @@ var PlatformModule = class _PlatformModule {
|
|
|
321
352
|
*/
|
|
322
353
|
configure(consumer) {
|
|
323
354
|
const options = _PlatformModule.moduleOptions;
|
|
324
|
-
consumer.apply(
|
|
355
|
+
consumer.apply(apiResponseInterceptor).forRoutes("/api/*");
|
|
356
|
+
consumer.apply(UserContextMiddleware, LoggerContextMiddleware, ObservableTraceMiddleware, SqlExecutionContextMiddleware).forRoutes("/*");
|
|
325
357
|
consumer.apply(CsrfTokenMiddleware, ViewContextMiddleware).exclude("/api/(.*)").forRoutes("*");
|
|
326
358
|
if (options.enableCsrf !== false) {
|
|
327
359
|
const csrfRoutes = options.csrfRoutes || "/api/*";
|
|
@@ -370,7 +402,7 @@ __name(configureApp, "configureApp");
|
|
|
370
402
|
import { DevToolsModule, DevToolsV2Module as DevToolsV2Module2 } from "@lark-apaas/nestjs-openapi-devtools";
|
|
371
403
|
export * from "@lark-apaas/nestjs-authnpaas";
|
|
372
404
|
export * from "@lark-apaas/nestjs-datapaas";
|
|
373
|
-
export * from "@lark-apaas/nestjs-
|
|
405
|
+
export * from "@lark-apaas/nestjs-observable";
|
|
374
406
|
export {
|
|
375
407
|
CsrfMiddleware,
|
|
376
408
|
CsrfTokenMiddleware,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-nestjs-core",
|
|
3
|
-
"version": "1.1.1-alpha.
|
|
3
|
+
"version": "1.1.1-alpha.14",
|
|
4
4
|
"description": "FullStack Nestjs Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,16 +35,16 @@
|
|
|
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.1",
|
|
42
43
|
"@lark-apaas/nestjs-common": "0.0.1-alpha.1",
|
|
43
44
|
"@lark-apaas/nestjs-datapaas": "^1.0.5",
|
|
44
|
-
"@lark-apaas/nestjs-logger": "1.0.2-alpha.
|
|
45
|
-
"@lark-apaas/nestjs-observable": "0.0.1-alpha.
|
|
46
|
-
"@lark-apaas/nestjs-openapi-devtools": "^1.0.
|
|
47
|
-
"@lark-apaas/nestjs-trigger": "0.0.1-alpha.0",
|
|
45
|
+
"@lark-apaas/nestjs-logger": "1.0.2-alpha.15",
|
|
46
|
+
"@lark-apaas/nestjs-observable": "0.0.1-alpha.10",
|
|
47
|
+
"@lark-apaas/nestjs-openapi-devtools": "^1.0.9",
|
|
48
48
|
"cookie-parser": "^1.4.7"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|