@edirect/rate-limit-module 11.0.59 → 11.0.61

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 (82) hide show
  1. package/package.json +6 -23
  2. package/dist/README.md +0 -584
  3. package/dist/package.json +0 -41
  4. package/dist/src/decorators/rate-limiting-rule.decorator.d.ts +0 -10
  5. package/dist/src/decorators/rate-limiting-rule.decorator.d.ts.map +0 -1
  6. package/dist/src/decorators/rate-limiting-rule.decorator.js +0 -7
  7. package/dist/src/guards/rate-limiting.guard.d.ts +0 -21
  8. package/dist/src/guards/rate-limiting.guard.d.ts.map +0 -1
  9. package/dist/src/guards/rate-limiting.guard.js +0 -248
  10. package/dist/src/index.d.ts +0 -11
  11. package/dist/src/index.d.ts.map +0 -1
  12. package/dist/src/index.js +0 -14
  13. package/dist/src/main.d.ts +0 -2
  14. package/dist/src/main.d.ts.map +0 -1
  15. package/dist/src/main.js +0 -9
  16. package/dist/src/object.utils.d.ts +0 -3
  17. package/dist/src/object.utils.d.ts.map +0 -1
  18. package/dist/src/object.utils.js +0 -38
  19. package/dist/src/rate-limiting.module.d.ts +0 -6
  20. package/dist/src/rate-limiting.module.d.ts.map +0 -1
  21. package/dist/src/rate-limiting.module.js +0 -26
  22. package/dist/src/rules/dto/pagination.dto.d.ts +0 -6
  23. package/dist/src/rules/dto/pagination.dto.d.ts.map +0 -1
  24. package/dist/src/rules/dto/pagination.dto.js +0 -42
  25. package/dist/src/rules/dto/rule.dto.d.ts +0 -24
  26. package/dist/src/rules/dto/rule.dto.d.ts.map +0 -1
  27. package/dist/src/rules/dto/rule.dto.js +0 -198
  28. package/dist/src/rules/interface/pagination.interface.d.ts +0 -7
  29. package/dist/src/rules/interface/pagination.interface.d.ts.map +0 -1
  30. package/dist/src/rules/interface/pagination.interface.js +0 -2
  31. package/dist/src/rules/interface/rule.interface.d.ts +0 -29
  32. package/dist/src/rules/interface/rule.interface.d.ts.map +0 -1
  33. package/dist/src/rules/interface/rule.interface.js +0 -2
  34. package/dist/src/rules/rule.controller.d.ts +0 -14
  35. package/dist/src/rules/rule.controller.d.ts.map +0 -1
  36. package/dist/src/rules/rule.controller.js +0 -87
  37. package/dist/src/rules/rule.module.d.ts +0 -5
  38. package/dist/src/rules/rule.module.d.ts.map +0 -1
  39. package/dist/src/rules/rule.module.js +0 -36
  40. package/dist/src/rules/rule.repository.d.ts +0 -15
  41. package/dist/src/rules/rule.repository.d.ts.map +0 -1
  42. package/dist/src/rules/rule.repository.js +0 -79
  43. package/dist/src/rules/rule.schema.d.ts +0 -166
  44. package/dist/src/rules/rule.schema.d.ts.map +0 -1
  45. package/dist/src/rules/rule.schema.js +0 -150
  46. package/dist/src/rules/rule.service.d.ts +0 -26
  47. package/dist/src/rules/rule.service.d.ts.map +0 -1
  48. package/dist/src/rules/rule.service.js +0 -204
  49. package/dist/src/shared/cache/cache.service.d.ts +0 -10
  50. package/dist/src/shared/cache/cache.service.d.ts.map +0 -1
  51. package/dist/src/shared/cache/cache.service.js +0 -29
  52. package/dist/src/shared/dsl/dsl.interface.d.ts +0 -43
  53. package/dist/src/shared/dsl/dsl.interface.d.ts.map +0 -1
  54. package/dist/src/shared/dsl/dsl.interface.js +0 -9
  55. package/dist/src/shared/dsl/dsl.service.d.ts +0 -8
  56. package/dist/src/shared/dsl/dsl.service.d.ts.map +0 -1
  57. package/dist/src/shared/dsl/dsl.service.js +0 -87
  58. package/dist/src/shared/redis/redis.module.d.ts +0 -3
  59. package/dist/src/shared/redis/redis.module.d.ts.map +0 -1
  60. package/dist/src/shared/redis/redis.module.js +0 -32
  61. package/dist/src/shared/redis/redis.service.d.ts +0 -13
  62. package/dist/src/shared/redis/redis.service.d.ts.map +0 -1
  63. package/dist/src/shared/redis/redis.service.js +0 -53
  64. package/dist/src/shared/rule-engine/interface/rule-engine.interface.d.ts +0 -14
  65. package/dist/src/shared/rule-engine/interface/rule-engine.interface.d.ts.map +0 -1
  66. package/dist/src/shared/rule-engine/interface/rule-engine.interface.js +0 -2
  67. package/dist/src/shared/rule-engine/rule-engine.module.d.ts +0 -11
  68. package/dist/src/shared/rule-engine/rule-engine.module.d.ts.map +0 -1
  69. package/dist/src/shared/rule-engine/rule-engine.module.js +0 -51
  70. package/dist/src/shared/rule-engine/rule-engine.service.d.ts +0 -18
  71. package/dist/src/shared/rule-engine/rule-engine.service.d.ts.map +0 -1
  72. package/dist/src/shared/rule-engine/rule-engine.service.js +0 -134
  73. package/dist/src/shared/shared.module.d.ts +0 -3
  74. package/dist/src/shared/shared.module.d.ts.map +0 -1
  75. package/dist/src/shared/shared.module.js +0 -29
  76. package/dist/src/validators/rule.constraint.d.ts +0 -10
  77. package/dist/src/validators/rule.constraint.d.ts.map +0 -1
  78. package/dist/src/validators/rule.constraint.js +0 -49
  79. package/dist/src/validators/rule.validator.d.ts +0 -3
  80. package/dist/src/validators/rule.validator.d.ts.map +0 -1
  81. package/dist/src/validators/rule.validator.js +0 -16
  82. package/dist/tsconfig.lib.tsbuildinfo +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule.schema.d.ts","sourceRoot":"","sources":["../../../src/rules/rule.schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG,QAAQ,CAAC;AAEvD,qBACa,gBAAiB,YAAW,KAAK;IAU5C,MAAM,EAAG,MAAM,CAAC;IAMhB,IAAI,EAAG,MAAM,CAAC;IAMd,YAAY,CAAC,EAAE,MAAM,CAAC;IAMtB,UAAU,EAAG,MAAM,CAAC;IAOpB,OAAO,EAAG,OAAO,CAAC;IAMlB,MAAM,EAAG,MAAM,CAAC;IAMhB,YAAY,CAAC,EAAE,MAAM,CAAC;IAMtB,OAAO,EAAG,MAAM,CAAC;IAMjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAMlB,WAAW,CAAC,EAAE,MAAM,CAAC;IAMrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAMnC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAM5B,SAAS,CAAC,EAAE,IAAI,CAAC;IAMjB,SAAS,CAAC,EAAE,IAAI,CAAC;IAMjB,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB;AAED,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBACa,CAAC"}
@@ -1,150 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RateLimitingRuleSchema = exports.RateLimitingRule = void 0;
4
- const tslib_1 = require("tslib");
5
- const mongoose_1 = require("@nestjs/mongoose");
6
- let RateLimitingRule = class RateLimitingRule {
7
- ruleId;
8
- name;
9
- targetAction;
10
- expression;
11
- enabled;
12
- market;
13
- errorMessage;
14
- partner;
15
- provider;
16
- productType;
17
- variables;
18
- variablesRequired;
19
- deletedAt;
20
- createdAt;
21
- updatedAt;
22
- };
23
- exports.RateLimitingRule = RateLimitingRule;
24
- tslib_1.__decorate([
25
- (0, mongoose_1.Prop)({
26
- required: true,
27
- unique: true,
28
- default: async () => {
29
- const { v4: uuidv4 } = await import('uuid');
30
- return uuidv4();
31
- },
32
- type: String,
33
- }),
34
- tslib_1.__metadata("design:type", String)
35
- ], RateLimitingRule.prototype, "ruleId", void 0);
36
- tslib_1.__decorate([
37
- (0, mongoose_1.Prop)({
38
- required: true,
39
- type: String,
40
- }),
41
- tslib_1.__metadata("design:type", String)
42
- ], RateLimitingRule.prototype, "name", void 0);
43
- tslib_1.__decorate([
44
- (0, mongoose_1.Prop)({
45
- required: true,
46
- type: String,
47
- }),
48
- tslib_1.__metadata("design:type", String)
49
- ], RateLimitingRule.prototype, "targetAction", void 0);
50
- tslib_1.__decorate([
51
- (0, mongoose_1.Prop)({
52
- required: true,
53
- type: String,
54
- }),
55
- tslib_1.__metadata("design:type", String)
56
- ], RateLimitingRule.prototype, "expression", void 0);
57
- tslib_1.__decorate([
58
- (0, mongoose_1.Prop)({
59
- required: true,
60
- default: true,
61
- type: Boolean,
62
- }),
63
- tslib_1.__metadata("design:type", Boolean)
64
- ], RateLimitingRule.prototype, "enabled", void 0);
65
- tslib_1.__decorate([
66
- (0, mongoose_1.Prop)({
67
- required: false,
68
- type: String,
69
- }),
70
- tslib_1.__metadata("design:type", String)
71
- ], RateLimitingRule.prototype, "market", void 0);
72
- tslib_1.__decorate([
73
- (0, mongoose_1.Prop)({
74
- required: false,
75
- type: String,
76
- }),
77
- tslib_1.__metadata("design:type", String)
78
- ], RateLimitingRule.prototype, "errorMessage", void 0);
79
- tslib_1.__decorate([
80
- (0, mongoose_1.Prop)({
81
- required: true,
82
- type: String,
83
- }),
84
- tslib_1.__metadata("design:type", String)
85
- ], RateLimitingRule.prototype, "partner", void 0);
86
- tslib_1.__decorate([
87
- (0, mongoose_1.Prop)({
88
- required: false,
89
- type: String,
90
- }),
91
- tslib_1.__metadata("design:type", String)
92
- ], RateLimitingRule.prototype, "provider", void 0);
93
- tslib_1.__decorate([
94
- (0, mongoose_1.Prop)({
95
- required: false,
96
- type: String,
97
- }),
98
- tslib_1.__metadata("design:type", String)
99
- ], RateLimitingRule.prototype, "productType", void 0);
100
- tslib_1.__decorate([
101
- (0, mongoose_1.Prop)({
102
- required: false,
103
- type: Object,
104
- }),
105
- tslib_1.__metadata("design:type", Object)
106
- ], RateLimitingRule.prototype, "variables", void 0);
107
- tslib_1.__decorate([
108
- (0, mongoose_1.Prop)({
109
- required: false,
110
- type: Boolean,
111
- }),
112
- tslib_1.__metadata("design:type", Boolean)
113
- ], RateLimitingRule.prototype, "variablesRequired", void 0);
114
- tslib_1.__decorate([
115
- (0, mongoose_1.Prop)({
116
- required: false,
117
- type: Date,
118
- }),
119
- tslib_1.__metadata("design:type", Date)
120
- ], RateLimitingRule.prototype, "deletedAt", void 0);
121
- tslib_1.__decorate([
122
- (0, mongoose_1.Prop)({
123
- required: false,
124
- type: Date,
125
- }),
126
- tslib_1.__metadata("design:type", Date)
127
- ], RateLimitingRule.prototype, "createdAt", void 0);
128
- tslib_1.__decorate([
129
- (0, mongoose_1.Prop)({
130
- required: false,
131
- type: Date,
132
- }),
133
- tslib_1.__metadata("design:type", Date)
134
- ], RateLimitingRule.prototype, "updatedAt", void 0);
135
- exports.RateLimitingRule = RateLimitingRule = tslib_1.__decorate([
136
- (0, mongoose_1.Schema)({ timestamps: true })
137
- ], RateLimitingRule);
138
- exports.RateLimitingRuleSchema = mongoose_1.SchemaFactory.createForClass(RateLimitingRule);
139
- exports.RateLimitingRuleSchema.index({
140
- partner: 1,
141
- provider: 1,
142
- productType: 1,
143
- });
144
- exports.RateLimitingRuleSchema.index({
145
- partner: 1,
146
- provider: 1,
147
- });
148
- exports.RateLimitingRuleSchema.index({
149
- partner: 1,
150
- });
@@ -1,26 +0,0 @@
1
- import { LoggerService } from '@edirect/logger';
2
- import { CacheService } from '../shared/cache/cache.service';
3
- import { CreateRuleDTO } from './dto/rule.dto';
4
- import { IPagination } from './interface/pagination.interface';
5
- import { IFindRule, IRule } from './interface/rule.interface';
6
- import { RuleRepository } from './rule.repository';
7
- export declare class RuleService {
8
- private readonly logger;
9
- private readonly repository;
10
- private readonly cacheService;
11
- private readonly MAX_EXPRESSION_LENGTH;
12
- private readonly MAX_EXPRESSION_DEPTH;
13
- private readonly FORBIDDEN_PATTERNS;
14
- constructor(logger: LoggerService, repository: RuleRepository, cacheService: CacheService);
15
- create(input?: CreateRuleDTO): Promise<IRule>;
16
- findAll(queryParameters: IFindRule): Promise<IPagination<IRule[]>>;
17
- findAllWithoutPagination(queryParameters: IFindRule): Promise<IRule[]>;
18
- findById(id: string): Promise<IRule>;
19
- updateOne(id: string, fieldsToUpdate: Partial<IRule>): Promise<IRule | null>;
20
- delete(id: string): Promise<void>;
21
- private logError;
22
- validateRuleExpression(expression: string): string | null;
23
- private getFromCache;
24
- private generateRateLimitingCountCacheKey;
25
- }
26
- //# sourceMappingURL=rule.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule.service.d.ts","sourceRoot":"","sources":["../../../src/rules/rule.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAShD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAe,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBACa,WAAW;IAqBpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAtB/B,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAO;IAC7C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAK;IAC1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAejC;gBAGiB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,cAAc,EAC1B,YAAY,EAAE,YAAY;IAGvC,MAAM,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC;IA0B7C,OAAO,CAAC,eAAe,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;IASlE,wBAAwB,CAAC,eAAe,EAAE,SAAS,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IA0BtE,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAapC,SAAS,CACb,EAAE,EAAE,MAAM,EACV,cAAc,EAAE,OAAO,CAAC,KAAK,CAAC,GAC7B,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAgClB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBvC,OAAO,CAAC,QAAQ;IAOhB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;YAoB3C,YAAY;IAiB1B,OAAO,CAAC,iCAAiC;CAuB1C"}
@@ -1,204 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RuleService = void 0;
4
- const tslib_1 = require("tslib");
5
- const logger_1 = require("@edirect/logger");
6
- const common_1 = require("@nestjs/common");
7
- const object_utils_1 = require("../object.utils");
8
- const cache_service_1 = require("../shared/cache/cache.service");
9
- const rule_repository_1 = require("./rule.repository");
10
- let RuleService = class RuleService {
11
- logger;
12
- repository;
13
- cacheService;
14
- MAX_EXPRESSION_LENGTH = 500;
15
- MAX_EXPRESSION_DEPTH = 8;
16
- FORBIDDEN_PATTERNS = [
17
- /constructor/i,
18
- /__proto__/i,
19
- /prototype/i,
20
- /process/i,
21
- /global/i,
22
- /require/i,
23
- /import/i,
24
- /eval/i,
25
- /Function/i,
26
- /setTimeout/i,
27
- /setInterval/i,
28
- /api/i,
29
- /request/i,
30
- /\[".*"\s*\+\s*".*"\]/,
31
- ];
32
- constructor(logger, repository, cacheService) {
33
- this.logger = logger;
34
- this.repository = repository;
35
- this.cacheService = cacheService;
36
- }
37
- async create(input) {
38
- try {
39
- if (!input)
40
- throw new common_1.BadRequestException('[ERROR] payload invalid!');
41
- const cacheKey = this.generateRateLimitingCountCacheKey({
42
- partner: input?.partner,
43
- provider: input?.provider,
44
- productType: input?.productType,
45
- market: input?.market,
46
- });
47
- if (cacheKey || cacheKey === '') {
48
- const isDeleted = await this.cacheService.delete([cacheKey]);
49
- if (!isDeleted) {
50
- await this.cacheService.deleteByPattern('rate-limit-config');
51
- }
52
- }
53
- return this.repository.save(input);
54
- }
55
- catch (error) {
56
- this.logError(`[ERROR] error to create rate limiting `, error);
57
- throw error;
58
- }
59
- }
60
- async findAll(queryParameters) {
61
- try {
62
- return this.repository.findAll(queryParameters);
63
- }
64
- catch (error) {
65
- this.logError('[ERROR] error to find rate limiting', error);
66
- throw new common_1.InternalServerErrorException();
67
- }
68
- }
69
- async findAllWithoutPagination(queryParameters) {
70
- try {
71
- const cachedData = await this.getFromCache(queryParameters);
72
- if (cachedData && cachedData.length)
73
- return cachedData;
74
- const { data } = await this.repository.findAll(queryParameters);
75
- const cacheKey = this.generateRateLimitingCountCacheKey({
76
- partner: queryParameters?.partner || '',
77
- provider: queryParameters?.provider || '',
78
- productType: queryParameters?.productType || '',
79
- market: queryParameters?.market || '',
80
- });
81
- if (data && data.length) {
82
- await this.cacheService.set(cacheKey, data, 3600);
83
- }
84
- return data;
85
- }
86
- catch (error) {
87
- this.logError('[ERROR] error to fnd rate limiting', error);
88
- throw new common_1.InternalServerErrorException();
89
- }
90
- }
91
- async findById(id) {
92
- try {
93
- const rate = await this.repository.findOneByRateId(id);
94
- if (!rate)
95
- throw new common_1.NotFoundException('Rate Limiting rule');
96
- return rate;
97
- }
98
- catch (error) {
99
- this.logError('[ERROR] error to find quote by ID', error);
100
- throw error;
101
- }
102
- }
103
- async updateOne(id, fieldsToUpdate) {
104
- try {
105
- if (!id)
106
- throw new common_1.NotFoundException('Rate Limiting rule');
107
- const current = await this.repository.findOneByRateId(id);
108
- if (!current)
109
- throw new common_1.NotFoundException('Rate Limiting rule');
110
- if (current.deletedAt) {
111
- throw new common_1.GoneException(`Already Deleted at ${current.deletedAt}`);
112
- }
113
- const cacheKey = this.generateRateLimitingCountCacheKey({
114
- partner: current?.partner || '',
115
- provider: current?.provider || '',
116
- productType: current?.productType || '',
117
- market: current?.market || '',
118
- });
119
- if (cacheKey || cacheKey === '') {
120
- const isDeleted = await this.cacheService.delete([cacheKey]);
121
- if (!isDeleted) {
122
- await this.cacheService.deleteByPattern('rate-limit-config');
123
- }
124
- }
125
- return this.repository.update(id, fieldsToUpdate);
126
- }
127
- catch (error) {
128
- this.logError(`[ERROR] error to update ${id}`, error);
129
- throw error;
130
- }
131
- }
132
- async delete(id) {
133
- try {
134
- if (!id)
135
- throw new common_1.NotFoundException('Rate limiting rule');
136
- const rule = await this.repository.findOneByRateId(id);
137
- if (rule?.deletedAt) {
138
- throw new common_1.GoneException(`Already Deleted at ${rule.deletedAt}`);
139
- }
140
- await this.repository.update(id, {
141
- deletedAt: new Date(),
142
- });
143
- }
144
- catch (error) {
145
- this.logError(`[ERROR] Error to delete rule`, error);
146
- throw error;
147
- }
148
- }
149
- logError(message, error) {
150
- this.logger.error(message, error instanceof Error ? error.stack || error.message : String(error));
151
- }
152
- validateRuleExpression(expression) {
153
- if (expression && expression.length > this.MAX_EXPRESSION_LENGTH) {
154
- return `Expression too long: ${expression.length} chars`;
155
- }
156
- for (const pattern of this.FORBIDDEN_PATTERNS) {
157
- if (pattern.test(expression)) {
158
- return `Expression contains forbidden pattern: ${pattern}`;
159
- }
160
- }
161
- const depth = (0, object_utils_1.calculateDepth)(expression);
162
- if (depth && depth > this.MAX_EXPRESSION_DEPTH) {
163
- return `Expression too complex`;
164
- }
165
- return null;
166
- }
167
- async getFromCache(queryParameters) {
168
- const cacheKey = this.generateRateLimitingCountCacheKey({
169
- partner: queryParameters?.partner || '',
170
- provider: queryParameters?.provider || '',
171
- productType: queryParameters?.productType || '',
172
- market: queryParameters?.market || '',
173
- });
174
- const cachedData = await this.cacheService.get(cacheKey);
175
- if (cachedData && cachedData.length) {
176
- this.logger.info(`[INFO] Cache hit for: ${JSON.stringify(cachedData)}`);
177
- return cachedData;
178
- }
179
- return [];
180
- }
181
- generateRateLimitingCountCacheKey(params) {
182
- if (!params.partner && !params.provider)
183
- return '';
184
- const parameters = {
185
- ...params,
186
- enabled: 'true',
187
- };
188
- const orderedParams = Object.keys(parameters)
189
- .sort()
190
- .reduce((obj, key) => {
191
- // Ensure all values are stringified for cache key
192
- obj[key] = String(parameters[key]);
193
- return obj;
194
- }, {});
195
- return `rate-limit-config:${JSON.stringify(orderedParams)}`;
196
- }
197
- };
198
- exports.RuleService = RuleService;
199
- exports.RuleService = RuleService = tslib_1.__decorate([
200
- (0, common_1.Injectable)(),
201
- tslib_1.__metadata("design:paramtypes", [logger_1.LoggerService,
202
- rule_repository_1.RuleRepository,
203
- cache_service_1.CacheService])
204
- ], RuleService);
@@ -1,10 +0,0 @@
1
- import { RedisService } from '../redis/redis.service';
2
- export declare class CacheService {
3
- private readonly redis;
4
- constructor(redis: RedisService);
5
- get<T>(key: string): Promise<T | null>;
6
- set<T>(key: string, value: T, ttl?: number): Promise<void>;
7
- delete(keys: string[]): Promise<number>;
8
- deleteByPattern(pattern: string): Promise<number>;
9
- }
10
- //# sourceMappingURL=cache.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.service.d.ts","sourceRoot":"","sources":["../../../../src/shared/cache/cache.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,qBACa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,YAAY;IAE1C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAI5C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1D,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAIvC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGlD"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CacheService = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const redis_service_1 = require("../redis/redis.service");
7
- let CacheService = class CacheService {
8
- redis;
9
- constructor(redis) {
10
- this.redis = redis;
11
- }
12
- async get(key) {
13
- return await this.redis.get(key);
14
- }
15
- set(key, value, ttl) {
16
- return this.redis.set(key, value, ttl);
17
- }
18
- delete(keys) {
19
- return this.redis.delKeys(keys);
20
- }
21
- deleteByPattern(pattern) {
22
- return this.redis.deleteByPattern(pattern);
23
- }
24
- };
25
- exports.CacheService = CacheService;
26
- exports.CacheService = CacheService = tslib_1.__decorate([
27
- (0, common_1.Injectable)(),
28
- tslib_1.__metadata("design:paramtypes", [redis_service_1.RedisService])
29
- ], CacheService);
@@ -1,43 +0,0 @@
1
- type Primitive = string | number | boolean | Date;
2
- interface EqFilter<T = Primitive> {
3
- eq: T;
4
- }
5
- interface InFilter<T = Primitive> {
6
- in: T[];
7
- }
8
- interface RangeFilter<T = Date | number> {
9
- range: {
10
- from?: T;
11
- to?: T;
12
- };
13
- }
14
- interface GteFilter<T = Date | number> {
15
- gte: T;
16
- }
17
- interface LteFilter<T = Date | number> {
18
- lte: T;
19
- }
20
- interface ElemMatchFilter {
21
- elemMatch: FilterDsl;
22
- }
23
- type FieldFilter = EqFilter | InFilter | RangeFilter | ElemMatchFilter | LteFilter | GteFilter;
24
- export interface FilterDsl {
25
- or?: FilterDsl[];
26
- [field: string]: FieldFilter | FilterDsl[] | undefined;
27
- }
28
- export interface IDslQuery {
29
- fnContext: string;
30
- query: IDslQueryItem[];
31
- }
32
- export interface IDslQueryItem {
33
- label: string;
34
- value: unknown;
35
- op: OperationDslEnum;
36
- }
37
- export declare enum OperationDslEnum {
38
- EQ = "eq",
39
- RANGE = "range",
40
- GTE = "gte"
41
- }
42
- export {};
43
- //# sourceMappingURL=dsl.interface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dsl.interface.d.ts","sourceRoot":"","sources":["../../../../src/shared/dsl/dsl.interface.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAElD,UAAU,QAAQ,CAAC,CAAC,GAAG,SAAS;IAC9B,EAAE,EAAE,CAAC,CAAC;CACP;AAED,UAAU,QAAQ,CAAC,CAAC,GAAG,SAAS;IAC9B,EAAE,EAAE,CAAC,EAAE,CAAC;CACT;AAED,UAAU,WAAW,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM;IACrC,KAAK,EAAE;QACL,IAAI,CAAC,EAAE,CAAC,CAAC;QACT,EAAE,CAAC,EAAE,CAAC,CAAC;KACR,CAAC;CACH;AAED,UAAU,SAAS,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM;IACnC,GAAG,EAAE,CAAC,CAAC;CACR;AAED,UAAU,SAAS,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM;IACnC,GAAG,EAAE,CAAC,CAAC;CACR;AAED,UAAU,eAAe;IACvB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,KAAK,WAAW,GACZ,QAAQ,GACR,QAAQ,GACR,WAAW,GACX,eAAe,GACf,SAAS,GACT,SAAS,CAAC;AAEd,MAAM,WAAW,SAAS;IACxB,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC;IACjB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,EAAE,GAAG,SAAS,CAAC;CACxD;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,EAAE,EAAE,gBAAgB,CAAC;CACtB;AAED,oBAAY,gBAAgB;IAC1B,EAAE,OAAO;IACT,KAAK,UAAU;IACf,GAAG,QAAQ;CACZ"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OperationDslEnum = void 0;
4
- var OperationDslEnum;
5
- (function (OperationDslEnum) {
6
- OperationDslEnum["EQ"] = "eq";
7
- OperationDslEnum["RANGE"] = "range";
8
- OperationDslEnum["GTE"] = "gte";
9
- })(OperationDslEnum || (exports.OperationDslEnum = OperationDslEnum = {}));
@@ -1,8 +0,0 @@
1
- import { QueryFilter } from 'mongoose';
2
- import { FilterDsl, IDslQueryItem } from './dsl.interface';
3
- export declare class DslService {
4
- #private;
5
- static buildFilter: (query: IDslQueryItem[]) => FilterDsl;
6
- static toMongoQuery: (filter: FilterDsl) => QueryFilter<IDslQueryItem>;
7
- }
8
- //# sourceMappingURL=dsl.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dsl.service.d.ts","sourceRoot":"","sources":["../../../../src/shared/dsl/dsl.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3D,qBAAa,UAAU;;IACrB,MAAM,CAAC,WAAW,GAAI,OAAO,aAAa,EAAE,KAAG,SAAS,CAWtD;IAEF,MAAM,CAAC,YAAY,GAAI,QAAQ,SAAS,KAAG,WAAW,CAAC,aAAa,CAAC,CAqDnE;CAuBH"}
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DslService = void 0;
4
- const tslib_1 = require("tslib");
5
- const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
- class DslService {
7
- static buildFilter = (query) => {
8
- return query.reduce((acc, cur) => {
9
- if (!cur || !cur.label)
10
- return acc;
11
- const value = cur.value ?? '';
12
- return {
13
- ...acc,
14
- [cur.label]: this.#buildOp(cur.op, value),
15
- };
16
- }, {});
17
- };
18
- static toMongoQuery = (filter) => {
19
- const query = {};
20
- for (const key in filter) {
21
- const condition = filter[key];
22
- if (!condition)
23
- continue;
24
- if (key === 'or' && Array.isArray(condition)) {
25
- query['$or'] = condition.map(subCond => this.toMongoQuery(subCond));
26
- continue;
27
- }
28
- if ('eq' in condition && condition.eq !== undefined) {
29
- query[key] = condition.eq;
30
- }
31
- if ('in' in condition && condition.in !== undefined) {
32
- query[key] = { $in: condition.in };
33
- }
34
- if ('range' in condition && condition.range !== undefined) {
35
- const rangeQuery = {};
36
- const conditionRange = condition.range;
37
- if (conditionRange.from)
38
- rangeQuery['$gte'] = conditionRange.from;
39
- if (conditionRange.to)
40
- rangeQuery['$lte'] = conditionRange.to;
41
- query[key] = rangeQuery;
42
- }
43
- if ('gte' in condition) {
44
- const gteQuery = {};
45
- if (condition.gte !== undefined)
46
- gteQuery['$gte'] = condition.gte;
47
- query[key] = gteQuery;
48
- }
49
- if ('lte' in condition) {
50
- const lteQuery = {};
51
- if (condition.lte !== undefined)
52
- lteQuery['$lte'] = condition.lte;
53
- query[key] = lteQuery;
54
- }
55
- if ('elemMatch' in condition) {
56
- const elemMatchQuery = {};
57
- if (condition.elemMatch) {
58
- elemMatchQuery['$elemMatch'] = this.toMongoQuery(condition.elemMatch);
59
- query[key] = elemMatchQuery;
60
- }
61
- }
62
- }
63
- return query;
64
- };
65
- static #buildOp = (op, value) => {
66
- if (op === 'rangeDate') {
67
- const data = value;
68
- return {
69
- range: {
70
- from: data?.from || (0, dayjs_1.default)().subtract(1, 'month').toDate(),
71
- to: data?.to || new Date(),
72
- },
73
- };
74
- }
75
- if (op === 'range') {
76
- const data = value;
77
- return {
78
- range: {
79
- from: data?.from,
80
- to: data?.to,
81
- },
82
- };
83
- }
84
- return { [op || 'eq']: value };
85
- };
86
- }
87
- exports.DslService = DslService;
@@ -1,3 +0,0 @@
1
- export declare class RedisModule {
2
- }
3
- //# sourceMappingURL=redis.module.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redis.module.d.ts","sourceRoot":"","sources":["../../../../src/shared/redis/redis.module.ts"],"names":[],"mappings":"AAKA,qBAmBa,WAAW;CAAG"}
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisModule = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const config_1 = require("@nestjs/config");
7
- const ioredis_1 = tslib_1.__importDefault(require("ioredis"));
8
- const redis_service_1 = require("./redis.service");
9
- let RedisModule = class RedisModule {
10
- };
11
- exports.RedisModule = RedisModule;
12
- exports.RedisModule = RedisModule = tslib_1.__decorate([
13
- (0, common_1.Global)(),
14
- (0, common_1.Module)({
15
- imports: [config_1.ConfigModule],
16
- providers: [
17
- {
18
- provide: 'REDIS_CLIENT',
19
- useFactory: (config) => {
20
- return new ioredis_1.default({
21
- host: config.get('REDIS_HOST'),
22
- port: config.get('REDIS_PORT'),
23
- password: config.get('REDIS_PASSWORD'),
24
- });
25
- },
26
- inject: [config_1.ConfigService],
27
- },
28
- redis_service_1.RedisService,
29
- ],
30
- exports: ['REDIS_CLIENT', redis_service_1.RedisService],
31
- })
32
- ], RedisModule);
@@ -1,13 +0,0 @@
1
- import { OnModuleDestroy } from '@nestjs/common';
2
- import Redis from 'ioredis';
3
- export declare class RedisService implements OnModuleDestroy {
4
- private readonly client;
5
- constructor(client: Redis);
6
- get<T>(key: string): Promise<T | null>;
7
- set<T>(key: string, value: T, ttlSeconds?: number): Promise<void>;
8
- delKeys(keys: string[]): Promise<number>;
9
- scan(pattern: string, count?: number): Promise<string[]>;
10
- deleteByPattern(pattern: string): Promise<number>;
11
- onModuleDestroy(): void;
12
- }
13
- //# sourceMappingURL=redis.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redis.service.d.ts","sourceRoot":"","sources":["../../../../src/shared/redis/redis.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,qBACa,YAAa,YAAW,eAAe;IAGhD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,KAAK;IAG1B,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAKtC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASjE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAKxC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAmBrD,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvD,eAAe;CAGhB"}