fiscalia_bo-nest-helpers 0.1.11 → 0.1.13
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/custom-validators/validator.sms.d.ts +3 -1
- package/dist/custom-validators/validator.sms.js +24 -6
- package/dist/custom-validators/validator.sms.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/request-block/index.d.ts +1 -0
- package/dist/request-block/index.js +7 -0
- package/dist/request-block/index.js.map +1 -0
- package/dist/request-block/request-block.module.d.ts +11 -0
- package/dist/request-block/request-block.module.js +55 -0
- package/dist/request-block/request-block.module.js.map +1 -0
- package/dist/request-block/throttle.decorator.d.ts +10 -0
- package/dist/request-block/throttle.decorator.js +57 -0
- package/dist/request-block/throttle.decorator.js.map +1 -0
- package/package.json +3 -1
@@ -7,10 +7,12 @@ export declare const smsBase64: (args: ValidationArguments, fieldName?: string)
|
|
7
7
|
export declare const smsArrayNotSelect: (field: string) => string;
|
8
8
|
export declare const smsArrayNotEmpty: (field: string) => string;
|
9
9
|
export declare const smsEnum: (args: ValidationArguments) => string;
|
10
|
+
export declare const smsIsString: (args: ValidationArguments, fieldName?: string) => string;
|
10
11
|
export declare const smsIsStringM: (args: ValidationArguments, fieldName?: string) => string;
|
11
12
|
export declare const smsIsStringF: (args: ValidationArguments, fieldName?: string) => string;
|
12
13
|
export declare const smsIsDate: (args: ValidationArguments, fieldName?: string) => string;
|
13
14
|
export declare const smsIsBoolean: (args: ValidationArguments, fieldName?: string) => string;
|
15
|
+
export declare const smsNotEmpty: () => string;
|
14
16
|
export declare const smsNotEmptyM: (args: ValidationArguments, fieldName?: string) => string;
|
15
17
|
export declare const smsNotEmptyF: (args: ValidationArguments, fieldName?: string) => string;
|
16
18
|
export declare const smsMinLength: (args: ValidationArguments, fieldName?: string) => string;
|
@@ -20,5 +22,5 @@ export declare const smsMaxInt: (args: ValidationArguments) => string;
|
|
20
22
|
export declare const smsLength: (args: ValidationArguments, fieldName?: string) => string;
|
21
23
|
export declare const smsInteger: (args: ValidationArguments, fieldName?: string) => string;
|
22
24
|
export declare const smsDateString: (args: ValidationArguments, fieldName?: string) => string;
|
23
|
-
export declare const smsDate: (args: ValidationArguments
|
25
|
+
export declare const smsDate: (args: ValidationArguments) => string;
|
24
26
|
export declare const formatValidationErrorsToResponseDto: <T>(errors: ValidationError[]) => ResponseDTO<T>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.formatValidationErrorsToResponseDto = exports.smsDate = exports.smsDateString = exports.smsInteger = exports.smsLength = exports.smsMaxInt = exports.smsMinInt = exports.smsMaxLength = exports.smsMinLength = exports.smsNotEmptyF = exports.smsNotEmptyM = exports.smsIsBoolean = exports.smsIsDate = exports.smsIsStringF = exports.smsIsStringM = exports.smsEnum = exports.smsArrayNotEmpty = exports.smsArrayNotSelect = exports.smsBase64 = exports.requiredFile = exports.smsMinStr = exports.smsMin = void 0;
|
3
|
+
exports.formatValidationErrorsToResponseDto = exports.smsDate = exports.smsDateString = exports.smsInteger = exports.smsLength = exports.smsMaxInt = exports.smsMinInt = exports.smsMaxLength = exports.smsMinLength = exports.smsNotEmptyF = exports.smsNotEmptyM = exports.smsNotEmpty = exports.smsIsBoolean = exports.smsIsDate = exports.smsIsStringF = exports.smsIsStringM = exports.smsIsString = exports.smsEnum = exports.smsArrayNotEmpty = exports.smsArrayNotSelect = exports.smsBase64 = exports.requiredFile = exports.smsMinStr = exports.smsMin = void 0;
|
4
4
|
const smsMin = (field) => `valor de ${field} no válido`;
|
5
5
|
exports.smsMin = smsMin;
|
6
6
|
const smsMinStr = (field) => `valor de ${field} no válido`;
|
@@ -14,13 +14,18 @@ exports.smsArrayNotSelect = smsArrayNotSelect;
|
|
14
14
|
const smsArrayNotEmpty = (field) => `Debe contener al menos ${field}`;
|
15
15
|
exports.smsArrayNotEmpty = smsArrayNotEmpty;
|
16
16
|
const smsEnum = (args) => {
|
17
|
+
var _a;
|
17
18
|
if (Array.isArray(args.constraints)) {
|
18
|
-
const arrayData = args.constraints
|
19
|
+
const arrayData = (_a = args.constraints[1]) === null || _a === void 0 ? void 0 : _a.join(', ');
|
19
20
|
return `'$value' no válido para $property, admite solo '${arrayData}'`;
|
20
21
|
}
|
21
22
|
return `$property no admite el valor '$value'`;
|
22
23
|
};
|
23
24
|
exports.smsEnum = smsEnum;
|
25
|
+
const smsIsString = (args, fieldName = null) => {
|
26
|
+
return `El ${fieldName !== null && fieldName !== void 0 ? fieldName : '$property'} ingresado no es válido. Por favor, ingrese solo texto.`;
|
27
|
+
};
|
28
|
+
exports.smsIsString = smsIsString;
|
24
29
|
const smsIsStringM = (args, fieldName = null) => {
|
25
30
|
return `El ${fieldName !== null && fieldName !== void 0 ? fieldName : '$property'} ingresado no es válido. Por favor, ingrese solo texto.`;
|
26
31
|
};
|
@@ -37,6 +42,10 @@ const smsIsBoolean = (args, fieldName = null) => {
|
|
37
42
|
return `El ${fieldName !== null && fieldName !== void 0 ? fieldName : '$property'} ingresado no es válido. Por favor, ingrese un valor binario.`;
|
38
43
|
};
|
39
44
|
exports.smsIsBoolean = smsIsBoolean;
|
45
|
+
const smsNotEmpty = () => {
|
46
|
+
return `Este campo no puede estar vacío`;
|
47
|
+
};
|
48
|
+
exports.smsNotEmpty = smsNotEmpty;
|
40
49
|
const smsNotEmptyM = (args, fieldName = null) => {
|
41
50
|
return `El ${fieldName !== null && fieldName !== void 0 ? fieldName : '$property'} no puede estar vacío`;
|
42
51
|
};
|
@@ -55,7 +64,9 @@ const smsMinInt = (args, fieldName = null) => `${fieldName !== null && fieldName
|
|
55
64
|
exports.smsMinInt = smsMinInt;
|
56
65
|
const smsMaxInt = (args) => `$property debe ser menor o igual a ${args.constraints[0]}`;
|
57
66
|
exports.smsMaxInt = smsMaxInt;
|
58
|
-
const smsLength = (args, fieldName = null) =>
|
67
|
+
const smsLength = (args, fieldName = null) => {
|
68
|
+
return `${fieldName !== null && fieldName !== void 0 ? fieldName : '$property'} debe tener entre ${args.constraints[0]} y ${args.constraints[1]} caracteres.`;
|
69
|
+
};
|
59
70
|
exports.smsLength = smsLength;
|
60
71
|
const smsInteger = (args, fieldName = null) => {
|
61
72
|
return `${fieldName !== null && fieldName !== void 0 ? fieldName : '$property'} debe ser un numero`;
|
@@ -65,13 +76,20 @@ const smsDateString = (args, fieldName = null) => {
|
|
65
76
|
return `La fecha de ${fieldName !== null && fieldName !== void 0 ? fieldName : '$property'} no esta formato ISO 8601`;
|
66
77
|
};
|
67
78
|
exports.smsDateString = smsDateString;
|
68
|
-
const smsDate = (args
|
69
|
-
|
79
|
+
const smsDate = (args) => {
|
80
|
+
var _a;
|
81
|
+
return `La propiedad '${(_a = args.constraints[1]) !== null && _a !== void 0 ? _a : '$property'} debe estar en formato ISO (ej. 2001-12-25T04:00:00.000Z ó 2001-12-25T00:00:00.000Z). Por favor, verifique que haya ingresado correctamente.`;
|
70
82
|
};
|
71
83
|
exports.smsDate = smsDate;
|
72
84
|
const formatValidationErrorsToResponseDto = (errors) => {
|
73
85
|
const errorSms = errors.reduce((objErrors, err) => {
|
74
|
-
|
86
|
+
if (!!err.children.length) {
|
87
|
+
const tempDAta = (0, exports.formatValidationErrorsToResponseDto)(err.children);
|
88
|
+
objErrors[err.property] = tempDAta.response.validationErrors;
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
objErrors[err.property] = Object.values(err.constraints);
|
92
|
+
}
|
75
93
|
return Object.assign({}, objErrors);
|
76
94
|
}, {});
|
77
95
|
return {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validator.sms.js","sourceRoot":"","sources":["../../src/custom-validators/validator.sms.ts"],"names":[],"mappings":";;;AAGO,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,KAAK,YAAY,CAAC;AAAnD,QAAA,MAAM,UAA6C;AAEzD,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,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,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE;YACzB,MAAM,QAAQ,GAAG,IAAA,2CAAmC,EAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACnE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC;SAC9D;aAAM;YACL,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;SAC1D;QACD,yBAAY,SAAS,EAAG;IAC1B,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,sEAAsE;QAC/E,QAAQ,EAAE;YACR,gBAAgB,EAAE,QAAmC;SACtD;QACD,MAAM,EAAE,GAAG;KACZ,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,mCAAmC,uCAqB9C"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.Dtos = exports.Decorators = exports.CustomValidators = exports.MsSkylogs = exports.MsFiles = exports.MsPdf = exports.MsPersonas = exports.PermissionsGuard = exports.MsSeguridadHttpError = void 0;
|
17
|
+
exports.RequestRestrict = exports.Dtos = exports.Decorators = exports.CustomValidators = exports.MsSkylogs = exports.MsFiles = exports.MsPdf = exports.MsPersonas = exports.PermissionsGuard = exports.MsSeguridadHttpError = void 0;
|
18
18
|
__exportStar(require("./ms-redis/ms-redis.module"), exports);
|
19
19
|
__exportStar(require("./ms-redis/ms-redis.service"), exports);
|
20
20
|
__exportStar(require("./ms-redis/datapass.interceptor"), exports);
|
@@ -39,4 +39,5 @@ exports.MsSkylogs = require("./ms-skylogs");
|
|
39
39
|
exports.CustomValidators = require("./custom-validators");
|
40
40
|
exports.Decorators = require("./decorators");
|
41
41
|
exports.Dtos = require("./dto");
|
42
|
+
exports.RequestRestrict = require("./request-block");
|
42
43
|
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
export { BlockModuleOptions, RequestRestrictModule } from './request-block.module';
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.RequestRestrictModule = exports.BlockModuleOptions = void 0;
|
4
|
+
var request_block_module_1 = require("./request-block.module");
|
5
|
+
Object.defineProperty(exports, "BlockModuleOptions", { enumerable: true, get: function () { return request_block_module_1.BlockModuleOptions; } });
|
6
|
+
Object.defineProperty(exports, "RequestRestrictModule", { enumerable: true, get: function () { return request_block_module_1.RequestRestrictModule; } });
|
7
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request-block/index.ts"],"names":[],"mappings":";;;AAAA,+DAAmF;AAA1E,0HAAA,kBAAkB,OAAA;AAAE,6HAAA,qBAAqB,OAAA"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
2
|
+
export declare class BlockModuleOptions {
|
3
|
+
global?: boolean;
|
4
|
+
limit: number;
|
5
|
+
limitById: number;
|
6
|
+
ttl: number;
|
7
|
+
}
|
8
|
+
export declare class RequestRestrictModule {
|
9
|
+
static register(options: BlockModuleOptions): DynamicModule;
|
10
|
+
static registerAsync(options: BlockModuleOptions): Promise<DynamicModule>;
|
11
|
+
}
|
@@ -0,0 +1,55 @@
|
|
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 RequestRestrictModule_1;
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
10
|
+
exports.RequestRestrictModule = exports.BlockModuleOptions = void 0;
|
11
|
+
const common_1 = require("@nestjs/common");
|
12
|
+
const core_1 = require("@nestjs/core");
|
13
|
+
const throttler_1 = require("@nestjs/throttler");
|
14
|
+
class BlockModuleOptions {
|
15
|
+
}
|
16
|
+
exports.BlockModuleOptions = BlockModuleOptions;
|
17
|
+
let RequestRestrictModule = RequestRestrictModule_1 = class RequestRestrictModule {
|
18
|
+
static register(options) {
|
19
|
+
const ttl = (options === null || options === void 0 ? void 0 : options.ttl) || 60;
|
20
|
+
const limit = (options === null || options === void 0 ? void 0 : options.limit) || 10;
|
21
|
+
const limitById = (options === null || options === void 0 ? void 0 : options.limitById) || 15;
|
22
|
+
return {
|
23
|
+
global: options.global,
|
24
|
+
module: RequestRestrictModule_1,
|
25
|
+
imports: [throttler_1.ThrottlerModule.forRoot({ limit, ttl })],
|
26
|
+
providers: [
|
27
|
+
throttler_1.ThrottlerStorageService,
|
28
|
+
{ provide: core_1.APP_GUARD, useClass: throttler_1.ThrottlerGuard },
|
29
|
+
{ provide: 'REQUEST_BLOCK_OPTIONS', useValue: { limit, ttl, limitById } },
|
30
|
+
],
|
31
|
+
exports: [throttler_1.ThrottlerStorageService, 'REQUEST_BLOCK_OPTIONS'],
|
32
|
+
};
|
33
|
+
}
|
34
|
+
static async registerAsync(options) {
|
35
|
+
const ttl = (options === null || options === void 0 ? void 0 : options.ttl) || 60;
|
36
|
+
const limit = (options === null || options === void 0 ? void 0 : options.limit) || 10;
|
37
|
+
const limitById = (options === null || options === void 0 ? void 0 : options.limitById) || 15;
|
38
|
+
return {
|
39
|
+
global: options.global,
|
40
|
+
module: RequestRestrictModule_1,
|
41
|
+
imports: [throttler_1.ThrottlerModule.forRoot({ limit, ttl })],
|
42
|
+
providers: [
|
43
|
+
throttler_1.ThrottlerStorageService,
|
44
|
+
{ provide: core_1.APP_GUARD, useClass: throttler_1.ThrottlerGuard },
|
45
|
+
{ provide: 'REQUEST_BLOCK_OPTIONS', useValue: { limit, ttl, limitById } },
|
46
|
+
],
|
47
|
+
exports: [throttler_1.ThrottlerStorageService, 'REQUEST_BLOCK_OPTIONS'],
|
48
|
+
};
|
49
|
+
}
|
50
|
+
};
|
51
|
+
RequestRestrictModule = RequestRestrictModule_1 = __decorate([
|
52
|
+
(0, common_1.Module)({})
|
53
|
+
], RequestRestrictModule);
|
54
|
+
exports.RequestRestrictModule = RequestRestrictModule;
|
55
|
+
//# sourceMappingURL=request-block.module.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"request-block.module.js","sourceRoot":"","sources":["../../src/request-block/request-block.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,uCAAyC;AACzC,iDAA6F;AAE7F,MAAa,kBAAkB;CAK9B;AALD,gDAKC;AAGM,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAIhC,MAAM,CAAC,QAAQ,CAAC,OAA2B;QACzC,MAAM,GAAG,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,KAAI,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,KAAI,EAAE,CAAC;QACnC,MAAM,SAAS,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,KAAI,EAAE,CAAC;QAC3C,OAAO;YACL,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,uBAAqB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jC;AAxCY,sDAAqB"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
2
|
+
import { ThrottlerStorageService } from '@nestjs/throttler';
|
3
|
+
import { BlockModuleOptions } from './request-block.module';
|
4
|
+
export declare class ThrottleIdGuard implements CanActivate {
|
5
|
+
private blockOptions;
|
6
|
+
private throttlerStorageService;
|
7
|
+
constructor(blockOptions: BlockModuleOptions, throttlerStorageService: ThrottlerStorageService);
|
8
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
9
|
+
}
|
10
|
+
export declare function ThrottleId(): MethodDecorator;
|
@@ -0,0 +1,57 @@
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.ThrottleId = exports.ThrottleIdGuard = void 0;
|
16
|
+
const common_1 = require("@nestjs/common");
|
17
|
+
const throttler_1 = require("@nestjs/throttler");
|
18
|
+
const request_block_module_1 = require("./request-block.module");
|
19
|
+
let ThrottleIdGuard = class ThrottleIdGuard {
|
20
|
+
constructor(blockOptions, throttlerStorageService) {
|
21
|
+
this.blockOptions = blockOptions;
|
22
|
+
this.throttlerStorageService = throttlerStorageService;
|
23
|
+
}
|
24
|
+
async canActivate(context) {
|
25
|
+
const ttl = this.blockOptions.ttl;
|
26
|
+
const limitById = this.blockOptions.limitById;
|
27
|
+
const req = context.switchToHttp().getRequest();
|
28
|
+
const key = req.method + '-' + req.ip + '-' + context.getHandler().name;
|
29
|
+
const storage = this.throttlerStorageService.storage;
|
30
|
+
const record = storage[key];
|
31
|
+
let totalHits = 0;
|
32
|
+
if (record && Date.now() < record.expiresAt) {
|
33
|
+
totalHits = record.totalHits;
|
34
|
+
}
|
35
|
+
const remainingPoints = Math.max(limitById - totalHits, 0);
|
36
|
+
if (remainingPoints <= 0) {
|
37
|
+
throw new throttler_1.ThrottlerException('You are being rate limited');
|
38
|
+
}
|
39
|
+
storage[key] = {
|
40
|
+
totalHits: totalHits + 1,
|
41
|
+
expiresAt: Date.now() + ttl * 1000,
|
42
|
+
};
|
43
|
+
return true;
|
44
|
+
}
|
45
|
+
};
|
46
|
+
ThrottleIdGuard = __decorate([
|
47
|
+
(0, common_1.Injectable)(),
|
48
|
+
__param(0, (0, common_1.Inject)('REQUEST_BLOCK_OPTIONS')),
|
49
|
+
__metadata("design:paramtypes", [request_block_module_1.BlockModuleOptions,
|
50
|
+
throttler_1.ThrottlerStorageService])
|
51
|
+
], ThrottleIdGuard);
|
52
|
+
exports.ThrottleIdGuard = ThrottleIdGuard;
|
53
|
+
function ThrottleId() {
|
54
|
+
return (0, common_1.applyDecorators)((0, throttler_1.SkipThrottle)(), (0, common_1.UseGuards)(ThrottleIdGuard));
|
55
|
+
}
|
56
|
+
exports.ThrottleId = ThrottleId;
|
57
|
+
//# sourceMappingURL=throttle.decorator.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"throttle.decorator.js","sourceRoot":"","sources":["../../src/request-block/throttle.decorator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAOwB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IAD3B,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,uBAAuB,CAAC,CAAA;qCAAuB,yCAAkB;QACxC,mCAAuB;GAH/C,eAAe,CAmC3B;AAnCY,0CAAe;AAqC5B,SAAgB,UAAU;IACxB,OAAO,IAAA,wBAAe,EAAC,IAAA,wBAAY,GAAE,EAAE,IAAA,kBAAS,EAAC,eAAe,CAAC,CAAC,CAAC;AACrE,CAAC;AAFD,gCAEC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "fiscalia_bo-nest-helpers",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.13",
|
4
4
|
"author": "UTIC",
|
5
5
|
"contact": {
|
6
6
|
"name": "Unidad de Tecnologías de la Información y Comunicación - Ministerio Público",
|
@@ -21,6 +21,7 @@
|
|
21
21
|
"dist/services/*",
|
22
22
|
"dist/ms-geojson/*",
|
23
23
|
"dist/helpers/*",
|
24
|
+
"dist/request-block/*",
|
24
25
|
"dist/types/*",
|
25
26
|
"dist/index.d.ts",
|
26
27
|
"*.md"
|
@@ -64,6 +65,7 @@
|
|
64
65
|
},
|
65
66
|
"dependencies": {
|
66
67
|
"@nestjs/common": "^9.0.0",
|
68
|
+
"@nestjs/throttler": "^4.0.0",
|
67
69
|
"@turf/turf": "^6.5.0",
|
68
70
|
"dotenv": "^16.0.3",
|
69
71
|
"ua-parser-js": "^1.0.35"
|