@biorate/nestjs-tools 1.24.0 → 1.24.1
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/.nyc_output/{dd6ef4c9-1ffd-446e-8e09-13aa0f3ce477.json → dd20662e-b42a-4eac-b521-e71c885587a7.json} +1 -1
- package/.nyc_output/processinfo/dd20662e-b42a-4eac-b521-e71c885587a7.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/CHANGELOG.md +11 -0
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/src/decorators/auth.ts.html +1 -1
- package/coverage/lcov-report/src/decorators/index.html +1 -1
- package/coverage/lcov-report/src/decorators/index.ts.html +1 -1
- package/coverage/lcov-report/src/decorators/roles.ts.html +1 -1
- package/coverage/lcov-report/src/enums/index.html +1 -1
- package/coverage/lcov-report/src/enums/index.ts.html +1 -1
- package/coverage/lcov-report/src/enums/user.ts.html +1 -1
- package/coverage/lcov-report/src/filters/all-exception-filter.ts.html +1 -1
- package/coverage/lcov-report/src/filters/index.html +1 -1
- package/coverage/lcov-report/src/filters/index.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +1 -1
- package/coverage/lcov-report/src/interceptors/index.html +1 -1
- package/coverage/lcov-report/src/interceptors/index.ts.html +1 -1
- package/coverage/lcov-report/src/interceptors/routes-interceptor.ts.html +6 -3
- package/coverage/lcov-report/src/middlewares/index.html +4 -4
- package/coverage/lcov-report/src/middlewares/index.ts.html +4 -4
- package/coverage/lcov-report/src/middlewares/proxy-middleware.ts.html +292 -0
- package/coverage/lcov-report/src/middlewares/request-count-middleware.ts.html +172 -0
- package/coverage/lcov-report/src/middlewares/response-time-middleware.ts.html +244 -0
- package/coverage/lcov-report/src/providers/auth.ts.html +1 -1
- package/coverage/lcov-report/src/providers/index.html +1 -1
- package/coverage/lcov-report/src/providers/index.ts.html +1 -1
- package/coverage/lcov-report/src/providers/roles.ts.html +1 -1
- package/coverage/lcov.info +10 -10
- package/dist/src/interceptors/routes-interceptor.js.map +1 -1
- package/dist/src/middlewares/index.js +3 -3
- package/dist/src/middlewares/index.js.map +1 -1
- package/dist/src/middlewares/proxy-middleware.js +70 -0
- package/dist/src/middlewares/proxy-middleware.js.map +1 -0
- package/dist/src/middlewares/request-count-middleware.js +45 -0
- package/dist/src/middlewares/request-count-middleware.js.map +1 -0
- package/dist/src/middlewares/response-time-middleware.js +61 -0
- package/dist/src/middlewares/response-time-middleware.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.d.ts +62 -1
- package/package.json +2 -2
- package/.nyc_output/processinfo/dd6ef4c9-1ffd-446e-8e09-13aa0f3ce477.json +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RequestCountMiddleware = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const prometheus_1 = require("@biorate/prometheus");
|
|
15
|
+
const on_headers_1 = require("on-headers");
|
|
16
|
+
const interceptors_1 = require("../interceptors");
|
|
17
|
+
let RequestCountMiddleware = class RequestCountMiddleware {
|
|
18
|
+
use(req, res, next) {
|
|
19
|
+
(0, on_headers_1.default)(res, () => {
|
|
20
|
+
var _a;
|
|
21
|
+
const route = interceptors_1.RoutesInterceptor.map.get(req);
|
|
22
|
+
this.counter
|
|
23
|
+
.labels({
|
|
24
|
+
method: req.method,
|
|
25
|
+
url: (_a = route === null || route === void 0 ? void 0 : route.path) !== null && _a !== void 0 ? _a : (req.baseUrl || req.originalUrl),
|
|
26
|
+
status: res.statusCode,
|
|
27
|
+
})
|
|
28
|
+
.inc();
|
|
29
|
+
});
|
|
30
|
+
next();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, prometheus_1.counter)({
|
|
35
|
+
name: 'http_server_requests_seconds_count',
|
|
36
|
+
help: 'Http server requests count',
|
|
37
|
+
labelNames: ['method', 'url', 'status'],
|
|
38
|
+
}),
|
|
39
|
+
__metadata("design:type", Object)
|
|
40
|
+
], RequestCountMiddleware.prototype, "counter", void 0);
|
|
41
|
+
RequestCountMiddleware = __decorate([
|
|
42
|
+
(0, common_1.Injectable)()
|
|
43
|
+
], RequestCountMiddleware);
|
|
44
|
+
exports.RequestCountMiddleware = RequestCountMiddleware;
|
|
45
|
+
//# sourceMappingURL=request-count-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-count-middleware.js","sourceRoot":"","sources":["../../../src/middlewares/request-count-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4D;AAC5D,oDAAuD;AAEvD,2CAAmC;AACnC,kDAAoD;AAGpD,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAQ1B,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;QACxD,IAAA,oBAAS,EAAC,GAAG,EAAE,GAAG,EAAE;;YAClB,MAAM,KAAK,GAAG,gCAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7C,IAAI,CAAC,OAAO;iBACT,MAAM,CAAC;gBACN,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,GAAG,EAAE,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,mCAAI,CAAC,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,WAAW,CAAC;gBACpD,MAAM,EAAE,GAAG,CAAC,UAAU;aACvB,CAAC;iBACD,GAAG,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;QACH,IAAI,EAAE,CAAC;IACT,CAAC;CACF,CAAA;AAfC;IALC,IAAA,oBAAO,EAAC;QACP,IAAI,EAAE,oCAAoC;QAC1C,IAAI,EAAE,4BAA4B;QAClC,UAAU,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC;KACxC,CAAC;;uDACuB;AANd,sBAAsB;IADlC,IAAA,mBAAU,GAAE;GACA,sBAAsB,CAqBlC;AArBY,wDAAsB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ResponseTimeMiddleware = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const inversion_1 = require("@biorate/inversion");
|
|
15
|
+
const prometheus_1 = require("@biorate/prometheus");
|
|
16
|
+
const on_headers_1 = require("on-headers");
|
|
17
|
+
const interceptors_1 = require("../interceptors");
|
|
18
|
+
const tools_1 = require("@biorate/tools");
|
|
19
|
+
let ResponseTimeMiddleware = class ResponseTimeMiddleware {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.suffix = this.config.get('app.middleware.ResponseTime.suffix', true);
|
|
22
|
+
this.header = this.config.get('app.middleware.ResponseTime.header', 'x-response-time');
|
|
23
|
+
this.digits = this.config.get('app.middleware.ResponseTime.digits', 3);
|
|
24
|
+
}
|
|
25
|
+
use(req, res, next) {
|
|
26
|
+
const diff = tools_1.time.diff();
|
|
27
|
+
(0, on_headers_1.default)(res, () => {
|
|
28
|
+
var _a;
|
|
29
|
+
const time = diff();
|
|
30
|
+
const route = interceptors_1.RoutesInterceptor.map.get(req);
|
|
31
|
+
this.histogram
|
|
32
|
+
.labels({
|
|
33
|
+
method: req.method,
|
|
34
|
+
url: (_a = route === null || route === void 0 ? void 0 : route.path) !== null && _a !== void 0 ? _a : (req.baseUrl || req.originalUrl),
|
|
35
|
+
status: res.statusCode,
|
|
36
|
+
})
|
|
37
|
+
.observe(time);
|
|
38
|
+
res.setHeader(this.header, time.toFixed(this.digits) + (this.suffix ? 'ms' : ''));
|
|
39
|
+
});
|
|
40
|
+
next();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, inversion_1.inject)(inversion_1.Types.Config),
|
|
45
|
+
__metadata("design:type", Object)
|
|
46
|
+
], ResponseTimeMiddleware.prototype, "config", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, prometheus_1.histogram)({
|
|
49
|
+
name: 'http_server_requests_seconds',
|
|
50
|
+
help: 'Http server requests seconds bucket',
|
|
51
|
+
labelNames: ['method', 'url', 'status'],
|
|
52
|
+
buckets: [5, 10, 20, 50, 100, 300, 500, 1000, 2000, 3000, 5000, 10000],
|
|
53
|
+
}),
|
|
54
|
+
__metadata("design:type", Object)
|
|
55
|
+
], ResponseTimeMiddleware.prototype, "histogram", void 0);
|
|
56
|
+
ResponseTimeMiddleware = __decorate([
|
|
57
|
+
(0, common_1.Injectable)(),
|
|
58
|
+
__metadata("design:paramtypes", [])
|
|
59
|
+
], ResponseTimeMiddleware);
|
|
60
|
+
exports.ResponseTimeMiddleware = ResponseTimeMiddleware;
|
|
61
|
+
//# sourceMappingURL=response-time-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-time-middleware.js","sourceRoot":"","sources":["../../../src/middlewares/response-time-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4D;AAC5D,kDAAmD;AAEnD,oDAA2D;AAE3D,2CAAmC;AACnC,kDAAoD;AACpD,0CAAsC;AAGtC,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAiBjC;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAU,oCAAoC,EAAE,IAAI,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAC3B,oCAAoC,EACpC,iBAAiB,CAClB,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAS,oCAAoC,EAAE,CAAC,CAAC,CAAC;IACjF,CAAC;IAEM,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;QACxD,MAAM,IAAI,GAAG,YAAI,CAAC,IAAI,EAAE,CAAC;QACzB,IAAA,oBAAS,EAAC,GAAG,EAAE,GAAG,EAAE;;YAClB,MAAM,IAAI,GAAG,IAAI,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,gCAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7C,IAAI,CAAC,SAAS;iBACX,MAAM,CAAC;gBACN,MAAM,EAAE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