@nest-omni/core 4.1.3-20 → 4.1.3-23

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.
Files changed (107) hide show
  1. package/audit/audit.module.d.ts +1 -0
  2. package/audit/audit.module.js +5 -3
  3. package/audit/controllers/audit.controller.d.ts +3 -11
  4. package/audit/controllers/audit.controller.js +12 -19
  5. package/audit/decorators/audit-operation.decorator.d.ts +0 -7
  6. package/audit/decorators/audit-operation.decorator.js +0 -7
  7. package/audit/dto/audit-action-query.dto.d.ts +13 -0
  8. package/audit/dto/audit-action-query.dto.js +77 -0
  9. package/audit/dto/index.d.ts +1 -0
  10. package/audit/dto/index.js +1 -0
  11. package/audit/entities/entity-audit-log.entity.d.ts +1 -4
  12. package/audit/entities/entity-audit-log.entity.js +1 -17
  13. package/audit/entities/manual-operation-log.entity.d.ts +0 -2
  14. package/audit/entities/manual-operation-log.entity.js +0 -8
  15. package/audit/enums/audit.enums.d.ts +0 -8
  16. package/audit/enums/audit.enums.js +1 -10
  17. package/audit/examples/decorator-value-mapping.example.d.ts +70 -0
  18. package/audit/examples/decorator-value-mapping.example.js +414 -0
  19. package/audit/index.d.ts +1 -0
  20. package/audit/index.js +5 -1
  21. package/audit/interceptors/audit.interceptor.d.ts +1 -0
  22. package/audit/interceptors/audit.interceptor.js +19 -11
  23. package/audit/interfaces/audit.interfaces.d.ts +2 -17
  24. package/audit/services/audit-context.service.d.ts +9 -0
  25. package/audit/services/entity-audit.service.d.ts +65 -24
  26. package/audit/services/entity-audit.service.js +280 -93
  27. package/audit/services/manual-audit-log.service.d.ts +0 -1
  28. package/audit/services/manual-audit-log.service.js +1 -3
  29. package/audit/subscribers/entity-audit.subscriber.d.ts +1 -0
  30. package/audit/subscribers/entity-audit.subscriber.js +22 -5
  31. package/cache/cache.module.d.ts +7 -2
  32. package/cache/cache.module.js +9 -7
  33. package/cache/cache.service.d.ts +4 -4
  34. package/cache/cache.service.js +5 -5
  35. package/cache/entities/index.d.ts +1 -0
  36. package/cache/entities/index.js +17 -0
  37. package/cache/entities/typeorm-cache.entity.d.ts +71 -0
  38. package/cache/entities/typeorm-cache.entity.js +110 -0
  39. package/cache/index.d.ts +2 -1
  40. package/cache/index.js +19 -2
  41. package/cache/providers/index.d.ts +2 -1
  42. package/cache/providers/index.js +2 -1
  43. package/cache/providers/lrucache.provider.d.ts +76 -0
  44. package/cache/providers/lrucache.provider.js +226 -0
  45. package/cache/providers/typeorm-cache.provider.d.ts +211 -0
  46. package/cache/providers/typeorm-cache.provider.js +483 -0
  47. package/common/boilerplate.polyfill.d.ts +1 -0
  48. package/common/boilerplate.polyfill.js +17 -0
  49. package/common/helpers/validation-metadata-helper.d.ts +55 -0
  50. package/common/helpers/validation-metadata-helper.js +60 -0
  51. package/common/index.d.ts +1 -0
  52. package/common/index.js +4 -0
  53. package/decorators/field.decorators.d.ts +71 -2
  54. package/decorators/field.decorators.js +147 -18
  55. package/decorators/transform.decorators.d.ts +0 -2
  56. package/decorators/transform.decorators.js +0 -23
  57. package/filters/bad-request.filter.js +19 -4
  58. package/http-client/examples/axios-config-extended.example.d.ts +17 -0
  59. package/http-client/examples/axios-config-extended.example.js +313 -0
  60. package/http-client/examples/index.d.ts +2 -0
  61. package/http-client/examples/index.js +2 -0
  62. package/http-client/examples/ssl-certificate.example.d.ts +47 -0
  63. package/http-client/examples/ssl-certificate.example.js +431 -0
  64. package/http-client/index.d.ts +1 -1
  65. package/http-client/interfaces/http-client-config.interface.d.ts +73 -0
  66. package/http-client/services/http-client.service.js +46 -5
  67. package/http-client/utils/context-extractor.util.js +2 -0
  68. package/ip-filter/constants.d.ts +21 -0
  69. package/ip-filter/constants.js +24 -0
  70. package/ip-filter/decorators/index.d.ts +1 -0
  71. package/ip-filter/decorators/index.js +17 -0
  72. package/ip-filter/decorators/ip-filter.decorator.d.ts +58 -0
  73. package/ip-filter/decorators/ip-filter.decorator.js +79 -0
  74. package/ip-filter/guards/index.d.ts +1 -0
  75. package/ip-filter/guards/index.js +17 -0
  76. package/ip-filter/guards/ip-filter.guard.d.ts +62 -0
  77. package/ip-filter/guards/ip-filter.guard.js +174 -0
  78. package/ip-filter/index.d.ts +7 -0
  79. package/ip-filter/index.js +23 -0
  80. package/ip-filter/interfaces/index.d.ts +4 -0
  81. package/ip-filter/interfaces/index.js +20 -0
  82. package/ip-filter/interfaces/ip-filter-async-options.interface.d.ts +15 -0
  83. package/ip-filter/interfaces/ip-filter-async-options.interface.js +2 -0
  84. package/ip-filter/interfaces/ip-filter-metadata.interface.d.ts +26 -0
  85. package/ip-filter/interfaces/ip-filter-metadata.interface.js +2 -0
  86. package/ip-filter/interfaces/ip-filter-options.interface.d.ts +34 -0
  87. package/ip-filter/interfaces/ip-filter-options.interface.js +2 -0
  88. package/ip-filter/interfaces/ip-rule.interface.d.ts +36 -0
  89. package/ip-filter/interfaces/ip-rule.interface.js +2 -0
  90. package/ip-filter/ip-filter.module.d.ts +55 -0
  91. package/ip-filter/ip-filter.module.js +105 -0
  92. package/ip-filter/services/index.d.ts +1 -0
  93. package/ip-filter/services/index.js +17 -0
  94. package/ip-filter/services/ip-filter.service.d.ts +92 -0
  95. package/ip-filter/services/ip-filter.service.js +238 -0
  96. package/ip-filter/utils/index.d.ts +1 -0
  97. package/ip-filter/utils/index.js +17 -0
  98. package/ip-filter/utils/ip-utils.d.ts +61 -0
  99. package/ip-filter/utils/ip-utils.js +162 -0
  100. package/package.json +23 -24
  101. package/providers/context.provider.d.ts +9 -0
  102. package/providers/context.provider.js +13 -0
  103. package/setup/bootstrap.setup.d.ts +1 -1
  104. package/setup/bootstrap.setup.js +1 -1
  105. package/shared/service-registry.module.js +0 -1
  106. package/cache/providers/memory-cache.provider.d.ts +0 -69
  107. package/cache/providers/memory-cache.provider.js +0 -237
@@ -0,0 +1,58 @@
1
+ import { IpFilterMetadata } from '../interfaces';
2
+ /**
3
+ * IP过滤装饰器
4
+ * 用于控制器或方法级别配置IP访问控制
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // 控制器级别
9
+ * @IpFilter({
10
+ * mode: 'whitelist',
11
+ * ipRanges: ['192.168.1.0/24', '10.0.0.0/8'],
12
+ * priority: 100
13
+ * })
14
+ * @Controller('admin')
15
+ * export class AdminController {}
16
+ *
17
+ * // 方法级别
18
+ * @Get()
19
+ * @IpFilter({
20
+ * mode: 'blacklist',
21
+ * ipRanges: ['203.0.113.0/24']
22
+ * })
23
+ * getData() {}
24
+ * ```
25
+ *
26
+ * @param options IP过滤配置选项
27
+ */
28
+ export declare const IpFilter: (options: IpFilterMetadata) => import("@nestjs/common").CustomDecorator<string>;
29
+ /**
30
+ * 白名单装饰器(快捷方式)
31
+ * 仅允许指定的IP范围访问
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * @IpWhitelist(['192.168.1.0/24', '10.0.0.0/8'], 'Office network')
36
+ * @Get('admin')
37
+ * adminDashboard() {}
38
+ * ```
39
+ *
40
+ * @param ipRanges 允许的IP范围列表(CIDR格式)
41
+ * @param description 规则描述
42
+ */
43
+ export declare const IpWhitelist: (ipRanges: string[], description?: string) => import("@nestjs/common").CustomDecorator<string>;
44
+ /**
45
+ * 黑名单装饰器(快捷方式)
46
+ * 禁止指定的IP范围访问
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * @IpBlacklist(['203.0.113.0/24'], 'Blocked malicious IPs')
51
+ * @Get('sensitive')
52
+ * sensitiveData() {}
53
+ * ```
54
+ *
55
+ * @param ipRanges 禁止的IP范围列表(CIDR格式)
56
+ * @param description 规则描述
57
+ */
58
+ export declare const IpBlacklist: (ipRanges: string[], description?: string) => import("@nestjs/common").CustomDecorator<string>;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IpBlacklist = exports.IpWhitelist = exports.IpFilter = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const constants_1 = require("../constants");
6
+ /**
7
+ * IP过滤装饰器
8
+ * 用于控制器或方法级别配置IP访问控制
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // 控制器级别
13
+ * @IpFilter({
14
+ * mode: 'whitelist',
15
+ * ipRanges: ['192.168.1.0/24', '10.0.0.0/8'],
16
+ * priority: 100
17
+ * })
18
+ * @Controller('admin')
19
+ * export class AdminController {}
20
+ *
21
+ * // 方法级别
22
+ * @Get()
23
+ * @IpFilter({
24
+ * mode: 'blacklist',
25
+ * ipRanges: ['203.0.113.0/24']
26
+ * })
27
+ * getData() {}
28
+ * ```
29
+ *
30
+ * @param options IP过滤配置选项
31
+ */
32
+ const IpFilter = (options) => (0, common_1.SetMetadata)(constants_1.IP_FILTER_KEY, options);
33
+ exports.IpFilter = IpFilter;
34
+ /**
35
+ * 白名单装饰器(快捷方式)
36
+ * 仅允许指定的IP范围访问
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * @IpWhitelist(['192.168.1.0/24', '10.0.0.0/8'], 'Office network')
41
+ * @Get('admin')
42
+ * adminDashboard() {}
43
+ * ```
44
+ *
45
+ * @param ipRanges 允许的IP范围列表(CIDR格式)
46
+ * @param description 规则描述
47
+ */
48
+ const IpWhitelist = (ipRanges, description) => {
49
+ return (0, exports.IpFilter)({
50
+ mode: 'whitelist',
51
+ ipRanges,
52
+ priority: 100,
53
+ description,
54
+ });
55
+ };
56
+ exports.IpWhitelist = IpWhitelist;
57
+ /**
58
+ * 黑名单装饰器(快捷方式)
59
+ * 禁止指定的IP范围访问
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * @IpBlacklist(['203.0.113.0/24'], 'Blocked malicious IPs')
64
+ * @Get('sensitive')
65
+ * sensitiveData() {}
66
+ * ```
67
+ *
68
+ * @param ipRanges 禁止的IP范围列表(CIDR格式)
69
+ * @param description 规则描述
70
+ */
71
+ const IpBlacklist = (ipRanges, description) => {
72
+ return (0, exports.IpFilter)({
73
+ mode: 'blacklist',
74
+ ipRanges,
75
+ priority: 100,
76
+ description,
77
+ });
78
+ };
79
+ exports.IpBlacklist = IpBlacklist;
@@ -0,0 +1 @@
1
+ export * from './ip-filter.guard';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ip-filter.guard"), exports);
@@ -0,0 +1,62 @@
1
+ import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import { Reflector } from '@nestjs/core';
3
+ import { IpFilterService } from '../services/ip-filter.service';
4
+ /**
5
+ * IP过滤守卫
6
+ * 用于保护路由,只允许授权的IP访问
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // 在控制器上使用
11
+ * @UseGuards(IpFilterGuard)
12
+ * @Controller('admin')
13
+ * export class AdminController {}
14
+ *
15
+ * // 在方法上使用
16
+ * @Get()
17
+ * @UseGuards(IpFilterGuard)
18
+ * getData() {}
19
+ *
20
+ * // 全局启用(在 app.module.ts)
21
+ * providers: [
22
+ * {
23
+ * provide: APP_GUARD,
24
+ * useClass: IpFilterGuard,
25
+ * },
26
+ * ]
27
+ * ```
28
+ */
29
+ export declare class IpFilterGuard implements CanActivate {
30
+ private readonly reflector;
31
+ private readonly ipFilterService;
32
+ private readonly logger;
33
+ constructor(reflector: Reflector, ipFilterService: IpFilterService);
34
+ /**
35
+ * 判断是否允许访问
36
+ */
37
+ canActivate(context: ExecutionContext): boolean;
38
+ /**
39
+ * 从请求中提取客户端IP
40
+ * 使用 Express 的 req.ip(当启用了 trust proxy 时)
41
+ * 或回退到 socket.remoteAddress
42
+ */
43
+ private extractClientIp;
44
+ /**
45
+ * 判断是否应该记录IP(出于安全考虑,生产环境可能不记录完整IP)
46
+ */
47
+ private shouldLogIp;
48
+ /**
49
+ * 记录被拒绝的访问
50
+ */
51
+ private logBlockedAccess;
52
+ /**
53
+ * 记录允许的访问
54
+ */
55
+ private logAllowedAccess;
56
+ /**
57
+ * 掩码IP地址(用于日志记录,保护隐私)
58
+ * 192.168.1.100 -> 192.168.1.*
59
+ * 2001:db8::1 -> 2001:db8::*
60
+ */
61
+ private maskIp;
62
+ }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var IpFilterGuard_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.IpFilterGuard = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const core_1 = require("@nestjs/core");
16
+ const ip_filter_service_1 = require("../services/ip-filter.service");
17
+ const constants_1 = require("../constants");
18
+ const utils_1 = require("../utils");
19
+ /**
20
+ * IP过滤守卫
21
+ * 用于保护路由,只允许授权的IP访问
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // 在控制器上使用
26
+ * @UseGuards(IpFilterGuard)
27
+ * @Controller('admin')
28
+ * export class AdminController {}
29
+ *
30
+ * // 在方法上使用
31
+ * @Get()
32
+ * @UseGuards(IpFilterGuard)
33
+ * getData() {}
34
+ *
35
+ * // 全局启用(在 app.module.ts)
36
+ * providers: [
37
+ * {
38
+ * provide: APP_GUARD,
39
+ * useClass: IpFilterGuard,
40
+ * },
41
+ * ]
42
+ * ```
43
+ */
44
+ let IpFilterGuard = IpFilterGuard_1 = class IpFilterGuard {
45
+ constructor(reflector, ipFilterService) {
46
+ this.reflector = reflector;
47
+ this.ipFilterService = ipFilterService;
48
+ this.logger = new common_1.Logger(IpFilterGuard_1.name);
49
+ }
50
+ /**
51
+ * 判断是否允许访问
52
+ */
53
+ canActivate(context) {
54
+ const request = context.switchToHttp().getRequest();
55
+ // 1. 获取客户端IP
56
+ const ip = this.extractClientIp(request);
57
+ request.clientIp = ip; // 保存到请求对象供后续使用
58
+ // 2. 获取路由级别的IP过滤元数据
59
+ const routeMetadata = this.reflector.getAllAndOverride(constants_1.IP_FILTER_KEY, [context.getHandler(), context.getClass()]);
60
+ // 3. 检查是否在路由级别禁用了IP过滤
61
+ if ((routeMetadata === null || routeMetadata === void 0 ? void 0 : routeMetadata.enabled) === false) {
62
+ return true;
63
+ }
64
+ // 4. 执行IP检查
65
+ const result = this.ipFilterService.checkIp(ip, routeMetadata);
66
+ // 5. 根据检查结果决定是否允许访问
67
+ if (!result.allowed) {
68
+ const errorResponse = this.ipFilterService.getErrorResponse();
69
+ this.logBlockedAccess(request, ip, result);
70
+ throw new common_1.ForbiddenException({
71
+ statusCode: errorResponse.statusCode,
72
+ message: errorResponse.message,
73
+ error: result.reason,
74
+ ip: this.shouldLogIp() ? ip : undefined,
75
+ timestamp: new Date().toISOString(),
76
+ });
77
+ }
78
+ this.logAllowedAccess(request, ip, result);
79
+ return true;
80
+ }
81
+ /**
82
+ * 从请求中提取客户端IP
83
+ * 使用 Express 的 req.ip(当启用了 trust proxy 时)
84
+ * 或回退到 socket.remoteAddress
85
+ */
86
+ extractClientIp(request) {
87
+ var _a;
88
+ // 优先使用 Express 的 req.ip
89
+ // 当 app.set('trust proxy', true) 启用时,Express 会自动设置正确的 IP
90
+ if (request.ip) {
91
+ return utils_1.IpUtils.normalizeIp(request.ip);
92
+ }
93
+ // 回退到 socket.remoteAddress
94
+ if ((_a = request.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress) {
95
+ return utils_1.IpUtils.normalizeIp(request.socket.remoteAddress);
96
+ }
97
+ // 最后回退到 headers(如果有的话)
98
+ const headers = request.headers;
99
+ const ipHeaders = [
100
+ 'x-forwarded-for',
101
+ 'x-real-ip',
102
+ 'cf-connecting-ip',
103
+ 'x-client-ip',
104
+ ];
105
+ for (const header of ipHeaders) {
106
+ const value = headers[header];
107
+ if (value) {
108
+ // X-Forwarded-For 可能包含多个IP,取第一个
109
+ const ip = Array.isArray(value) ? value[0] : value.split(',')[0];
110
+ return utils_1.IpUtils.normalizeIp(ip.trim());
111
+ }
112
+ }
113
+ return '0.0.0.0';
114
+ }
115
+ /**
116
+ * 判断是否应该记录IP(出于安全考虑,生产环境可能不记录完整IP)
117
+ */
118
+ shouldLogIp() {
119
+ return process.env.NODE_ENV === 'development' || process.env.LOG_IPS === 'true';
120
+ }
121
+ /**
122
+ * 记录被拒绝的访问
123
+ */
124
+ logBlockedAccess(request, ip, result) {
125
+ const logData = {
126
+ method: request.method,
127
+ url: request.url,
128
+ ip: this.shouldLogIp() ? ip : this.maskIp(ip),
129
+ reason: result.reason,
130
+ matchedRule: result.matchedRule,
131
+ };
132
+ this.logger.warn(`Access denied: ${JSON.stringify(logData)}`);
133
+ }
134
+ /**
135
+ * 记录允许的访问
136
+ */
137
+ logAllowedAccess(request, ip, result) {
138
+ if (process.env.LOG_ALLOWED_IPS === 'true') {
139
+ const logData = {
140
+ method: request.method,
141
+ url: request.url,
142
+ ip: this.shouldLogIp() ? ip : this.maskIp(ip),
143
+ matchedRule: result.matchedRule,
144
+ };
145
+ this.logger.log(`Access allowed: ${JSON.stringify(logData)}`);
146
+ }
147
+ }
148
+ /**
149
+ * 掩码IP地址(用于日志记录,保护隐私)
150
+ * 192.168.1.100 -> 192.168.1.*
151
+ * 2001:db8::1 -> 2001:db8::*
152
+ */
153
+ maskIp(ip) {
154
+ if (!ip)
155
+ return '*';
156
+ if (ip.includes(':')) {
157
+ // IPv6: 只显示前两段
158
+ const parts = ip.split(':');
159
+ return `${parts[0]}:${parts[1]}:*`;
160
+ }
161
+ // IPv4: 只显示前三段
162
+ const parts = ip.split('.');
163
+ if (parts.length === 4) {
164
+ return `${parts[0]}.${parts[1]}.${parts[2]}.*`;
165
+ }
166
+ return '*';
167
+ }
168
+ };
169
+ exports.IpFilterGuard = IpFilterGuard;
170
+ exports.IpFilterGuard = IpFilterGuard = IpFilterGuard_1 = __decorate([
171
+ (0, common_1.Injectable)(),
172
+ __metadata("design:paramtypes", [core_1.Reflector,
173
+ ip_filter_service_1.IpFilterService])
174
+ ], IpFilterGuard);
@@ -0,0 +1,7 @@
1
+ export * from './interfaces';
2
+ export * from './decorators';
3
+ export * from './guards';
4
+ export * from './services';
5
+ export * from './utils';
6
+ export * from './constants';
7
+ export * from './ip-filter.module';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./interfaces"), exports);
18
+ __exportStar(require("./decorators"), exports);
19
+ __exportStar(require("./guards"), exports);
20
+ __exportStar(require("./services"), exports);
21
+ __exportStar(require("./utils"), exports);
22
+ __exportStar(require("./constants"), exports);
23
+ __exportStar(require("./ip-filter.module"), exports);
@@ -0,0 +1,4 @@
1
+ export * from './ip-rule.interface';
2
+ export * from './ip-filter-options.interface';
3
+ export * from './ip-filter-metadata.interface';
4
+ export * from './ip-filter-async-options.interface';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ip-rule.interface"), exports);
18
+ __exportStar(require("./ip-filter-options.interface"), exports);
19
+ __exportStar(require("./ip-filter-metadata.interface"), exports);
20
+ __exportStar(require("./ip-filter-async-options.interface"), exports);
@@ -0,0 +1,15 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ import { IpFilterModuleOptions } from './ip-filter-options.interface';
3
+ /**
4
+ * IP过滤模块异步配置选项
5
+ */
6
+ export interface IpFilterModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
7
+ /**
8
+ * 异步工厂函数
9
+ */
10
+ useFactory: (...args: any[]) => Promise<IpFilterModuleOptions> | IpFilterModuleOptions;
11
+ /**
12
+ * 依赖注入的tokens
13
+ */
14
+ inject?: any[];
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 路由级别的IP过滤元数据
3
+ * 用于装饰器配置
4
+ */
5
+ export interface IpFilterMetadata {
6
+ /**
7
+ * 是否启用IP过滤
8
+ */
9
+ enabled?: boolean;
10
+ /**
11
+ * 过滤模式
12
+ */
13
+ mode?: 'whitelist' | 'blacklist';
14
+ /**
15
+ * IP范围列表(CIDR格式)
16
+ */
17
+ ipRanges?: string[];
18
+ /**
19
+ * 优先级
20
+ */
21
+ priority?: number;
22
+ /**
23
+ * 描述
24
+ */
25
+ description?: string;
26
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,34 @@
1
+ import { IpRule } from './ip-rule.interface';
2
+ /**
3
+ * IP过滤模块配置选项
4
+ */
5
+ export interface IpFilterModuleOptions {
6
+ /**
7
+ * 过滤模式
8
+ * - whitelist: 仅白名单模式(需要配置白名单规则)
9
+ * - blacklist: 仅黑名单模式(禁止黑名单中的IP,其他全部允许)
10
+ * - mixed: 混合模式(同时使用白名单和黑名单)
11
+ */
12
+ mode: 'whitelist' | 'blacklist' | 'mixed';
13
+ /**
14
+ * 默认策略
15
+ * - allow: 默认允许访问
16
+ * - deny: 默认拒绝访问
17
+ */
18
+ defaultPolicy: 'allow' | 'deny';
19
+ /**
20
+ * IP规则列表
21
+ */
22
+ rules: IpRule[];
23
+ /**
24
+ * 拒绝访问时的错误响应
25
+ */
26
+ errorResponse?: {
27
+ message?: string;
28
+ statusCode?: number;
29
+ };
30
+ /**
31
+ * 是否启用日志记录
32
+ */
33
+ enableLogging?: boolean;
34
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * IP规则接口
3
+ */
4
+ export interface IpRule {
5
+ /**
6
+ * 规则唯一标识
7
+ */
8
+ id: string;
9
+ /**
10
+ * 规则类型
11
+ * - whitelist: 白名单(只允许这些IP)
12
+ * - blacklist: 黑名单(禁止这些IP)
13
+ */
14
+ type: 'whitelist' | 'blacklist';
15
+ /**
16
+ * IP范围列表(支持CIDR格式)
17
+ * 示例:
18
+ * - '192.168.1.0/24' (CIDR)
19
+ * - '10.0.0.1' (单个IP)
20
+ * - '2001:db8::/32' (IPv6 CIDR)
21
+ */
22
+ ipRanges: string[];
23
+ /**
24
+ * 规则描述
25
+ */
26
+ description?: string;
27
+ /**
28
+ * 是否启用
29
+ */
30
+ enabled: boolean;
31
+ /**
32
+ * 优先级(数字越大越优先)
33
+ * 默认: 50
34
+ */
35
+ priority?: number;
36
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,55 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { IpFilterModuleOptions, IpFilterModuleAsyncOptions } from './interfaces';
3
+ /**
4
+ * IP过滤模块
5
+ * 提供IP访问控制功能
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // 同步配置
10
+ * @Module({
11
+ * imports: [
12
+ * IpFilterModule.register({
13
+ * mode: 'whitelist',
14
+ * defaultPolicy: 'deny',
15
+ * rules: [
16
+ * {
17
+ * id: 'office-network',
18
+ * type: 'whitelist',
19
+ * ipRanges: ['192.168.1.0/24', '10.0.0.0/8'],
20
+ * enabled: true,
21
+ * priority: 100,
22
+ * },
23
+ * ],
24
+ * }),
25
+ * ],
26
+ * })
27
+ * export class AppModule {}
28
+ *
29
+ * // 异步配置
30
+ * @Module({
31
+ * imports: [
32
+ * IpFilterModule.registerAsync({
33
+ * imports: [ConfigModule],
34
+ * inject: [ConfigService],
35
+ * useFactory: (config: ConfigService) => ({
36
+ * mode: 'whitelist',
37
+ * defaultPolicy: 'deny',
38
+ * rules: config.get('ipFilterRules'),
39
+ * }),
40
+ * }),
41
+ * ],
42
+ * })
43
+ * export class AppModule {}
44
+ * ```
45
+ */
46
+ export declare class IpFilterModule {
47
+ /**
48
+ * 同步注册模块
49
+ */
50
+ static register(options: IpFilterModuleOptions): DynamicModule;
51
+ /**
52
+ * 异步注册模块
53
+ */
54
+ static registerAsync(options: IpFilterModuleAsyncOptions): DynamicModule;
55
+ }