listpage-next-nest 0.0.26 → 0.0.129

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.
@@ -25,17 +25,20 @@ var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  RequestContextMiddleware: ()=>RequestContextMiddleware,
28
+ AdminAuthGuard: ()=>AdminAuthGuard,
28
29
  StaticRouteMiddleware: ()=>StaticRouteMiddleware,
29
30
  PaginationData: ()=>PaginationData,
30
31
  StaticRouteMiddlewareFactory: ()=>StaticRouteMiddlewareFactory,
31
32
  RequestIdMiddleware: ()=>RequestIdMiddleware,
32
33
  LoggingInterceptor: ()=>LoggingInterceptor,
33
- StaticRouteModule: ()=>StaticRouteModule,
34
34
  ResponseInterceptor: ()=>ResponseInterceptor,
35
+ StaticRouteModule: ()=>StaticRouteModule,
35
36
  CorsInterceptor: ()=>CorsInterceptor,
36
37
  BaseQueryDto: ()=>BaseQueryDto,
37
38
  ApiResponse: ()=>ApiResponse,
38
39
  HttpExceptionFilter: ()=>HttpExceptionFilter,
40
+ User: ()=>User,
41
+ Public: ()=>Public,
39
42
  PaginatedResponse: ()=>PaginatedResponse,
40
43
  RequestContextService: ()=>RequestContextService,
41
44
  setup: ()=>setup
@@ -316,6 +319,44 @@ class ResponseInterceptor {
316
319
  ResponseInterceptor = response_interceptor_ts_decorate([
317
320
  (0, common_namespaceObject.Injectable)()
318
321
  ], ResponseInterceptor);
322
+ const external_lodash_namespaceObject = require("lodash");
323
+ const User = (0, common_namespaceObject.createParamDecorator)((path, context)=>{
324
+ const request = context.switchToHttp().getRequest();
325
+ if (path) return (0, external_lodash_namespaceObject.get)(request.user, path);
326
+ return request.user;
327
+ });
328
+ const IS_PUBLIC_KEY = 'isPublic';
329
+ const Public = ()=>(0, common_namespaceObject.SetMetadata)(IS_PUBLIC_KEY, true);
330
+ function auth_guard_ts_decorate(decorators, target, key, desc) {
331
+ var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
332
+ if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
333
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
334
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
335
+ }
336
+ class AdminAuthGuard {
337
+ async canActivate(context) {
338
+ const isPublic = Reflect.getMetadata(IS_PUBLIC_KEY, context.getClass()) || Reflect.getMetadata(IS_PUBLIC_KEY, context.getHandler());
339
+ if (isPublic) return true;
340
+ const request = context.switchToHttp().getRequest();
341
+ const payload = await this.validateToken(request);
342
+ if (!payload) throw new common_namespaceObject.UnauthorizedException();
343
+ (0, external_lodash_namespaceObject.set)(request, 'user', payload);
344
+ return true;
345
+ }
346
+ constructor(){
347
+ this.validateToken = async (request)=>{
348
+ const [, token] = request.headers.authorization?.split(' ') ?? [];
349
+ if ('admin' !== token) return null;
350
+ return {
351
+ id: 'admin',
352
+ name: '系统管理员'
353
+ };
354
+ };
355
+ }
356
+ }
357
+ AdminAuthGuard = auth_guard_ts_decorate([
358
+ (0, common_namespaceObject.Injectable)()
359
+ ], AdminAuthGuard);
319
360
  const external_class_validator_namespaceObject = require("class-validator");
320
361
  const external_class_transformer_namespaceObject = require("class-transformer");
321
362
  function query_dto_ts_decorate(decorators, target, key, desc) {
@@ -401,8 +442,8 @@ function StaticRouteMiddlewareFactory(options) {
401
442
  return function(req, res, next) {
402
443
  const { rootDir, routeMappings } = options;
403
444
  if (external_path_namespaceObject.extname(req.path)) {
404
- const filePath = external_path_namespaceObject.join(this.options.rootDir, req.path);
405
- if (!(0, external_fs_namespaceObject.existsSync)(filePath)) next(new common_namespaceObject.NotFoundException(`File not found: ${req.path}`));
445
+ const filePath = external_path_namespaceObject.join(rootDir, req.path);
446
+ if (!(0, external_fs_namespaceObject.existsSync)(filePath)) next(new common_namespaceObject.NotFoundException(`找不到对应文件: ${req.path}`));
406
447
  res.sendFile(filePath, (err)=>{
407
448
  if (err) next(err);
408
449
  });
@@ -471,6 +512,7 @@ StaticRouteModule = static_route_module_ts_decorate([
471
512
  (0, common_namespaceObject.Global)(),
472
513
  (0, common_namespaceObject.Module)({})
473
514
  ], StaticRouteModule);
515
+ exports.AdminAuthGuard = __webpack_exports__.AdminAuthGuard;
474
516
  exports.ApiResponse = __webpack_exports__.ApiResponse;
475
517
  exports.BaseQueryDto = __webpack_exports__.BaseQueryDto;
476
518
  exports.CorsInterceptor = __webpack_exports__.CorsInterceptor;
@@ -478,6 +520,7 @@ exports.HttpExceptionFilter = __webpack_exports__.HttpExceptionFilter;
478
520
  exports.LoggingInterceptor = __webpack_exports__.LoggingInterceptor;
479
521
  exports.PaginatedResponse = __webpack_exports__.PaginatedResponse;
480
522
  exports.PaginationData = __webpack_exports__.PaginationData;
523
+ exports.Public = __webpack_exports__.Public;
481
524
  exports.RequestContextMiddleware = __webpack_exports__.RequestContextMiddleware;
482
525
  exports.RequestContextService = __webpack_exports__.RequestContextService;
483
526
  exports.RequestIdMiddleware = __webpack_exports__.RequestIdMiddleware;
@@ -485,8 +528,10 @@ exports.ResponseInterceptor = __webpack_exports__.ResponseInterceptor;
485
528
  exports.StaticRouteMiddleware = __webpack_exports__.StaticRouteMiddleware;
486
529
  exports.StaticRouteMiddlewareFactory = __webpack_exports__.StaticRouteMiddlewareFactory;
487
530
  exports.StaticRouteModule = __webpack_exports__.StaticRouteModule;
531
+ exports.User = __webpack_exports__.User;
488
532
  exports.setup = __webpack_exports__.setup;
489
533
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
534
+ "AdminAuthGuard",
490
535
  "ApiResponse",
491
536
  "BaseQueryDto",
492
537
  "CorsInterceptor",
@@ -494,6 +539,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
494
539
  "LoggingInterceptor",
495
540
  "PaginatedResponse",
496
541
  "PaginationData",
542
+ "Public",
497
543
  "RequestContextMiddleware",
498
544
  "RequestContextService",
499
545
  "RequestIdMiddleware",
@@ -501,6 +547,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
501
547
  "StaticRouteMiddleware",
502
548
  "StaticRouteMiddlewareFactory",
503
549
  "StaticRouteModule",
550
+ "User",
504
551
  "setup"
505
552
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
506
553
  Object.defineProperty(exports, '__esModule', {
@@ -1,5 +1,7 @@
1
1
  import { ArgumentsHost } from '@nestjs/common';
2
2
  import { CallHandler } from '@nestjs/common';
3
+ import { CanActivate } from '@nestjs/common';
4
+ import { CustomDecorator } from '@nestjs/common';
3
5
  import { DynamicModule } from '@nestjs/common';
4
6
  import { ExceptionFilter } from '@nestjs/common';
5
7
  import { ExecutionContext } from '@nestjs/common';
@@ -9,8 +11,18 @@ import { NestInterceptor } from '@nestjs/common';
9
11
  import { NestMiddleware } from '@nestjs/common';
10
12
  import { NextFunction } from 'express';
11
13
  import { Observable } from 'rxjs';
14
+ import { PipeTransform } from '@nestjs/common';
12
15
  import { Request as Request_2 } from 'express';
13
16
  import { Response as Response_2 } from 'express';
17
+ import { Type } from '@nestjs/common';
18
+
19
+ export declare class AdminAuthGuard implements CanActivate {
20
+ canActivate(context: ExecutionContext): Promise<boolean>;
21
+ validateToken: (request: Request_2) => Promise<{
22
+ id: string;
23
+ name: string;
24
+ }>;
25
+ }
14
26
 
15
27
  export declare class ApiResponse<T = any> {
16
28
  code: number;
@@ -66,6 +78,8 @@ export declare class PaginationData<T> {
66
78
  constructor(list: T[], current: number, pageSize: number, total: number);
67
79
  }
68
80
 
81
+ export declare const Public: () => CustomDecorator<string>;
82
+
69
83
  declare interface RequestContext {
70
84
  requestId: string;
71
85
  startTime: number;
@@ -132,4 +146,6 @@ export declare interface StaticRouteOptions {
132
146
  routeMappings: RouteMapping[];
133
147
  }
134
148
 
149
+ export declare const User: (...dataOrPipes: (string | PipeTransform<any, any> | Type<PipeTransform<any, any>>)[]) => ParameterDecorator;
150
+
135
151
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next-nest",
3
- "version": "0.0.26",
3
+ "version": "0.0.129",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",
@@ -36,9 +36,10 @@
36
36
  "@rslib/core": "^0.13.3",
37
37
  "prettier": "^3.6.2",
38
38
  "typescript": "^5.9.2",
39
- "@microsoft/api-extractor": "~7.52.13"
39
+ "@microsoft/api-extractor": "~7.52.13",
40
+ "@types/lodash": "~4.17.20",
41
+ "reflect-metadata": "~0.2.2"
40
42
  },
41
- "peerDependencies": {},
42
43
  "dependencies": {
43
44
  "class-transformer": "~0.5.1",
44
45
  "class-validator": "~0.14.2",
@@ -46,6 +47,7 @@
46
47
  "uuid": "9.0.1",
47
48
  "express": "~5.1.0",
48
49
  "@types/express": "~5.0.3",
49
- "rxjs": "~7.8.2"
50
+ "rxjs": "~7.8.2",
51
+ "lodash": "~4.17.21"
50
52
  }
51
- }
53
+ }