microservice-common-nestjs 1.0.0
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/README.md +452 -0
- package/dist/cache/cache.module.d.ts +5 -0
- package/dist/cache/cache.module.js +32 -0
- package/dist/cache/cache.module.js.map +1 -0
- package/dist/cache/cache.service.d.ts +18 -0
- package/dist/cache/cache.service.js +68 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/client/client.interface.d.ts +14 -0
- package/dist/client/client.interface.js +3 -0
- package/dist/client/client.interface.js.map +1 -0
- package/dist/client/http-client.module.d.ts +2 -0
- package/dist/client/http-client.module.js +22 -0
- package/dist/client/http-client.module.js.map +1 -0
- package/dist/client/http-client.service.d.ts +12 -0
- package/dist/client/http-client.service.js +100 -0
- package/dist/client/http-client.service.js.map +1 -0
- package/dist/config/config.interface.d.ts +42 -0
- package/dist/config/config.interface.js +3 -0
- package/dist/config/config.interface.js.map +1 -0
- package/dist/config/config.module.d.ts +2 -0
- package/dist/config/config.module.js +28 -0
- package/dist/config/config.module.js.map +1 -0
- package/dist/config/config.service.d.ts +10 -0
- package/dist/config/config.service.js +85 -0
- package/dist/config/config.service.js.map +1 -0
- package/dist/database/prisma.module.d.ts +21 -0
- package/dist/database/prisma.module.js +121 -0
- package/dist/database/prisma.module.js.map +1 -0
- package/dist/health/health.controller.d.ts +10 -0
- package/dist/health/health.controller.js +75 -0
- package/dist/health/health.controller.js.map +1 -0
- package/dist/health/health.interface.d.ts +14 -0
- package/dist/health/health.interface.js +3 -0
- package/dist/health/health.interface.js.map +1 -0
- package/dist/health/health.module.d.ts +2 -0
- package/dist/health/health.module.js +23 -0
- package/dist/health/health.module.js.map +1 -0
- package/dist/health/health.service.d.ts +10 -0
- package/dist/health/health.service.js +25 -0
- package/dist/health/health.service.js.map +1 -0
- package/dist/http/http-response.decorator.d.ts +6 -0
- package/dist/http/http-response.decorator.js +8 -0
- package/dist/http/http-response.decorator.js.map +1 -0
- package/dist/http/http-response.module.d.ts +2 -0
- package/dist/http/http-response.module.js +22 -0
- package/dist/http/http-response.module.js.map +1 -0
- package/dist/http/http-response.service.d.ts +17 -0
- package/dist/http/http-response.service.js +73 -0
- package/dist/http/http-response.service.js.map +1 -0
- package/dist/http/response.interface.d.ts +10 -0
- package/dist/http/response.interface.js +3 -0
- package/dist/http/response.interface.js.map +1 -0
- package/dist/i18n/i18n.module.d.ts +5 -0
- package/dist/i18n/i18n.module.js +32 -0
- package/dist/i18n/i18n.module.js.map +1 -0
- package/dist/i18n/i18n.service.d.ts +16 -0
- package/dist/i18n/i18n.service.js +58 -0
- package/dist/i18n/i18n.service.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/microservice-common.module.d.ts +17 -0
- package/dist/microservice-common.module.js +76 -0
- package/dist/microservice-common.module.js.map +1 -0
- package/dist/middleware/correlation-id.middleware.d.ts +9 -0
- package/dist/middleware/correlation-id.middleware.js +34 -0
- package/dist/middleware/correlation-id.middleware.js.map +1 -0
- package/dist/middleware/cors.middleware.d.ts +9 -0
- package/dist/middleware/cors.middleware.js +71 -0
- package/dist/middleware/cors.middleware.js.map +1 -0
- package/dist/middleware/logging.middleware.d.ts +10 -0
- package/dist/middleware/logging.middleware.js +75 -0
- package/dist/middleware/logging.middleware.js.map +1 -0
- package/dist/middleware/middleware.interface.d.ts +18 -0
- package/dist/middleware/middleware.interface.js +3 -0
- package/dist/middleware/middleware.interface.js.map +1 -0
- package/dist/middleware/middleware.module.d.ts +9 -0
- package/dist/middleware/middleware.module.js +61 -0
- package/dist/middleware/middleware.module.js.map +1 -0
- package/dist/prometheus/prometheus.module.d.ts +8 -0
- package/dist/prometheus/prometheus.module.js +44 -0
- package/dist/prometheus/prometheus.module.js.map +1 -0
- package/dist/prometheus/prometheus.service.d.ts +14 -0
- package/dist/prometheus/prometheus.service.js +56 -0
- package/dist/prometheus/prometheus.service.js.map +1 -0
- package/dist/rate-limit/rate-limit.module.d.ts +4 -0
- package/dist/rate-limit/rate-limit.module.js +47 -0
- package/dist/rate-limit/rate-limit.module.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpResponse = exports.HTTP_RESPONSE_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.HTTP_RESPONSE_KEY = 'http_response';
|
|
6
|
+
const HttpResponse = (options) => (0, common_1.SetMetadata)(exports.HTTP_RESPONSE_KEY, options || {});
|
|
7
|
+
exports.HttpResponse = HttpResponse;
|
|
8
|
+
//# sourceMappingURL=http-response.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response.decorator.js","sourceRoot":"","sources":["../../src/http/http-response.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAEhC,QAAA,iBAAiB,GAAG,eAAe,CAAC;AAO1C,MAAM,YAAY,GAAG,CAAC,OAA6B,EAAE,EAAE,CAC5D,IAAA,oBAAW,EAAC,yBAAiB,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;AADnC,QAAA,YAAY,gBACuB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpResponseModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const http_response_service_1 = require("../http/http-response.service");
|
|
12
|
+
let HttpResponseModule = class HttpResponseModule {
|
|
13
|
+
};
|
|
14
|
+
exports.HttpResponseModule = HttpResponseModule;
|
|
15
|
+
exports.HttpResponseModule = HttpResponseModule = __decorate([
|
|
16
|
+
(0, common_1.Global)(),
|
|
17
|
+
(0, common_1.Module)({
|
|
18
|
+
providers: [http_response_service_1.HttpResponseService],
|
|
19
|
+
exports: [http_response_service_1.HttpResponseService],
|
|
20
|
+
})
|
|
21
|
+
], HttpResponseModule);
|
|
22
|
+
//# sourceMappingURL=http-response.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response.module.js","sourceRoot":"","sources":["../../src/http/http-response.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,wEAAmE;AAO5D,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAAG,CAAA;AAArB,gDAAkB;6BAAlB,kBAAkB;IAL9B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,2CAAmB,CAAC;QAChC,OAAO,EAAE,CAAC,2CAAmB,CAAC;KAC/B,CAAC;GACW,kBAAkB,CAAG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ApiResponse } from '../http/response.interface';
|
|
2
|
+
export declare class HttpResponseService {
|
|
3
|
+
success<T>(code?: string, description?: string, data?: T, httpCode?: number): ApiResponse<T>;
|
|
4
|
+
error(httpCode: number, code?: string, description?: string, details?: unknown): ApiResponse;
|
|
5
|
+
badRequest(description?: string, details?: unknown): ApiResponse;
|
|
6
|
+
notFound(description?: string): ApiResponse;
|
|
7
|
+
internalServerError(description?: string, details?: unknown): ApiResponse;
|
|
8
|
+
unauthorized(description?: string, details?: unknown): ApiResponse;
|
|
9
|
+
forbidden(description?: string, details?: unknown): ApiResponse;
|
|
10
|
+
throwSuccess<T>(code?: string, description?: string, data?: T, httpCode?: number): never;
|
|
11
|
+
throwError(httpCode: number, code?: string, description?: string, details?: unknown): never;
|
|
12
|
+
throwBadRequest(description?: string, details?: unknown): never;
|
|
13
|
+
throwNotFound(description?: string): never;
|
|
14
|
+
throwInternalServerError(description?: string, details?: unknown): never;
|
|
15
|
+
throwUnauthorized(description?: string, details?: unknown): never;
|
|
16
|
+
throwForbidden(description?: string, details?: unknown): never;
|
|
17
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpResponseService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let HttpResponseService = class HttpResponseService {
|
|
12
|
+
success(code = '1000', description = 'Success', data, httpCode = common_1.HttpStatus.OK) {
|
|
13
|
+
return {
|
|
14
|
+
status: {
|
|
15
|
+
code,
|
|
16
|
+
description,
|
|
17
|
+
http_code: httpCode,
|
|
18
|
+
},
|
|
19
|
+
data,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
error(httpCode, code = '1999', description = 'Generic server side error', details) {
|
|
23
|
+
return {
|
|
24
|
+
status: {
|
|
25
|
+
code,
|
|
26
|
+
description,
|
|
27
|
+
http_code: httpCode,
|
|
28
|
+
details,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
badRequest(description = 'Invalid parameters entered', details) {
|
|
33
|
+
return this.error(common_1.HttpStatus.BAD_REQUEST, '1999', description, details);
|
|
34
|
+
}
|
|
35
|
+
notFound(description = 'Resource not found') {
|
|
36
|
+
return this.error(common_1.HttpStatus.NOT_FOUND, '1999', description);
|
|
37
|
+
}
|
|
38
|
+
internalServerError(description = 'Generic server side error', details) {
|
|
39
|
+
return this.error(common_1.HttpStatus.INTERNAL_SERVER_ERROR, '1999', description, details);
|
|
40
|
+
}
|
|
41
|
+
unauthorized(description = 'Unauthorized', details) {
|
|
42
|
+
return this.error(common_1.HttpStatus.UNAUTHORIZED, '1999', description, details);
|
|
43
|
+
}
|
|
44
|
+
forbidden(description = 'Forbidden', details) {
|
|
45
|
+
return this.error(common_1.HttpStatus.FORBIDDEN, '1999', description, details);
|
|
46
|
+
}
|
|
47
|
+
throwSuccess(code = '1000', description = 'Success', data, httpCode = common_1.HttpStatus.OK) {
|
|
48
|
+
throw new common_1.HttpException(this.success(code, description, data, httpCode), httpCode);
|
|
49
|
+
}
|
|
50
|
+
throwError(httpCode, code = '1999', description = 'Generic server side error', details) {
|
|
51
|
+
throw new common_1.HttpException(this.error(httpCode, code, description, details), httpCode);
|
|
52
|
+
}
|
|
53
|
+
throwBadRequest(description = 'Invalid parameters entered', details) {
|
|
54
|
+
throw new common_1.HttpException(this.badRequest(description, details), common_1.HttpStatus.BAD_REQUEST);
|
|
55
|
+
}
|
|
56
|
+
throwNotFound(description = 'Resource not found') {
|
|
57
|
+
throw new common_1.HttpException(this.notFound(description), common_1.HttpStatus.NOT_FOUND);
|
|
58
|
+
}
|
|
59
|
+
throwInternalServerError(description = 'Generic server side error', details) {
|
|
60
|
+
throw new common_1.HttpException(this.internalServerError(description, details), common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
61
|
+
}
|
|
62
|
+
throwUnauthorized(description = 'Unauthorized', details) {
|
|
63
|
+
throw new common_1.HttpException(this.unauthorized(description, details), common_1.HttpStatus.UNAUTHORIZED);
|
|
64
|
+
}
|
|
65
|
+
throwForbidden(description = 'Forbidden', details) {
|
|
66
|
+
throw new common_1.HttpException(this.forbidden(description, details), common_1.HttpStatus.FORBIDDEN);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.HttpResponseService = HttpResponseService;
|
|
70
|
+
exports.HttpResponseService = HttpResponseService = __decorate([
|
|
71
|
+
(0, common_1.Injectable)()
|
|
72
|
+
], HttpResponseService);
|
|
73
|
+
//# sourceMappingURL=http-response.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response.service.js","sourceRoot":"","sources":["../../src/http/http-response.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.interface.js","sourceRoot":"","sources":["../../src/http/response.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 I18nModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.I18nModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const i18n_service_1 = require("../i18n/i18n.service");
|
|
13
|
+
let I18nModule = I18nModule_1 = class I18nModule {
|
|
14
|
+
static forRoot(options) {
|
|
15
|
+
return {
|
|
16
|
+
module: I18nModule_1,
|
|
17
|
+
providers: [
|
|
18
|
+
{
|
|
19
|
+
provide: i18n_service_1.I18nService,
|
|
20
|
+
useValue: new i18n_service_1.I18nService(options),
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
exports: [i18n_service_1.I18nService],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.I18nModule = I18nModule;
|
|
28
|
+
exports.I18nModule = I18nModule = I18nModule_1 = __decorate([
|
|
29
|
+
(0, common_1.Global)(),
|
|
30
|
+
(0, common_1.Module)({})
|
|
31
|
+
], I18nModule);
|
|
32
|
+
//# sourceMappingURL=i18n.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.module.js","sourceRoot":"","sources":["../../src/i18n/i18n.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA+D;AAC/D,sDAA+D;AAIxD,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,MAAM,CAAC,OAAO,CAAC,OAAqB;QAClC,OAAO;YACL,MAAM,EAAE,YAAU;YAClB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,0BAAW;oBACpB,QAAQ,EAAE,IAAI,0BAAW,CAAC,OAAO,CAAC;iBACnC;aACF;YACD,OAAO,EAAE,CAAC,0BAAW,CAAC;SACvB,CAAC;IACJ,CAAC;CACF,CAAA;AAbY,gCAAU;qBAAV,UAAU;IAFtB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CAatB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
export interface I18nOptions {
|
|
3
|
+
defaultLanguage?: string;
|
|
4
|
+
fallbackLanguage?: string;
|
|
5
|
+
resources?: Record<string, Record<string, string>>;
|
|
6
|
+
}
|
|
7
|
+
export declare class I18nService {
|
|
8
|
+
private readonly logger;
|
|
9
|
+
private readonly i18n;
|
|
10
|
+
constructor(options?: I18nOptions);
|
|
11
|
+
translate(key: string, language?: string, options?: Record<string, unknown>): string;
|
|
12
|
+
translateFromRequest(req: Request, key: string, options?: Record<string, unknown>): string;
|
|
13
|
+
getLanguage(req: Request): string;
|
|
14
|
+
changeLanguage(language: string): void;
|
|
15
|
+
getCurrentLanguage(): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
var I18nService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.I18nService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const i18next_1 = __importDefault(require("i18next"));
|
|
19
|
+
let I18nService = I18nService_1 = class I18nService {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.logger = new common_1.Logger(I18nService_1.name);
|
|
22
|
+
const defaultLanguage = options?.defaultLanguage || 'en';
|
|
23
|
+
const fallbackLanguage = options?.fallbackLanguage || 'en';
|
|
24
|
+
const resources = options?.resources || {};
|
|
25
|
+
this.i18n = i18next_1.default.createInstance();
|
|
26
|
+
this.i18n.init({
|
|
27
|
+
lng: defaultLanguage,
|
|
28
|
+
fallbackLng: fallbackLanguage,
|
|
29
|
+
resources,
|
|
30
|
+
interpolation: {
|
|
31
|
+
escapeValue: false,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
this.logger.log(`I18n initialized with default language: ${defaultLanguage}`);
|
|
35
|
+
}
|
|
36
|
+
translate(key, language, options) {
|
|
37
|
+
return this.i18n.t(key, { lng: language, ...options });
|
|
38
|
+
}
|
|
39
|
+
translateFromRequest(req, key, options) {
|
|
40
|
+
const language = req.headers['accept-language'] || 'en';
|
|
41
|
+
return this.translate(key, language, options);
|
|
42
|
+
}
|
|
43
|
+
getLanguage(req) {
|
|
44
|
+
return req.headers['accept-language'] || 'en';
|
|
45
|
+
}
|
|
46
|
+
changeLanguage(language) {
|
|
47
|
+
this.i18n.changeLanguage(language);
|
|
48
|
+
}
|
|
49
|
+
getCurrentLanguage() {
|
|
50
|
+
return this.i18n.language;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.I18nService = I18nService;
|
|
54
|
+
exports.I18nService = I18nService = I18nService_1 = __decorate([
|
|
55
|
+
(0, common_1.Injectable)(),
|
|
56
|
+
__metadata("design:paramtypes", [Object])
|
|
57
|
+
], I18nService);
|
|
58
|
+
//# sourceMappingURL=i18n.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.service.js","sourceRoot":"","sources":["../../src/i18n/i18n.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,sDAAgD;AAUzC,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAItB,YAAY,OAAqB;QAHhB,WAAM,GAAG,IAAI,eAAM,CAAC,aAAW,CAAC,IAAI,CAAC,CAAC;QAIrD,MAAM,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,IAAI,CAAC;QACzD,MAAM,gBAAgB,GAAG,OAAO,EAAE,gBAAgB,IAAI,IAAI,CAAC;QAC3D,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,EAAE,CAAC;QAE3C,IAAI,CAAC,IAAI,GAAG,iBAAO,CAAC,cAAc,EAAE,CAAC;QAErC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACb,GAAG,EAAE,eAAe;YACpB,WAAW,EAAE,gBAAgB;YAC7B,SAAS;YACT,aAAa,EAAE;gBACb,WAAW,EAAE,KAAK;aACnB;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,2CAA2C,eAAe,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,SAAS,CAAC,GAAW,EAAE,QAAiB,EAAE,OAAiC;QACzE,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,oBAAoB,CAAC,GAAY,EAAE,GAAW,EAAE,OAAiC;QAC/E,MAAM,QAAQ,GAAI,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAY,IAAI,IAAI,CAAC;QACpE,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,WAAW,CAAC,GAAY;QACtB,OAAQ,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAY,IAAI,IAAI,CAAC;IAC5D,CAAC;IAED,cAAc,CAAC,QAAgB;QAC7B,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC5B,CAAC;CACF,CAAA;AA3CY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;;GACA,WAAW,CA2CvB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { MicroserviceCommonModule } from './microservice-common.module';
|
|
2
|
+
export type { MicroserviceCommonModuleOptions } from './microservice-common.module';
|
|
3
|
+
export { ConfigModule } from './config/config.module';
|
|
4
|
+
export { ConfigService } from './config/config.service';
|
|
5
|
+
export type { MicroserviceCommonConfig, DatabaseConfig, HttpConfig, LogConfig, } from './config/config.interface';
|
|
6
|
+
export { HealthModule } from './health/health.module';
|
|
7
|
+
export { HealthController } from './health/health.controller';
|
|
8
|
+
export { HealthService } from './health/health.service';
|
|
9
|
+
export type { HealthCheckResult, HealthCheckDetail } from './health/health.interface';
|
|
10
|
+
export { HttpResponseModule } from './http/http-response.module';
|
|
11
|
+
export { HttpResponseService } from './http/http-response.service';
|
|
12
|
+
export type { ApiResponse, StatusInfo } from './http/response.interface';
|
|
13
|
+
export { HttpResponse } from './http/http-response.decorator';
|
|
14
|
+
export { PrismaModule } from './database/prisma.module';
|
|
15
|
+
export type { PrismaModuleOptions, PrismaModuleAsyncOptions } from './database/prisma.module';
|
|
16
|
+
export { MiddlewareModule } from './middleware/middleware.module';
|
|
17
|
+
export { CorrelationIdMiddleware } from './middleware/correlation-id.middleware';
|
|
18
|
+
export { LoggingMiddleware } from './middleware/logging.middleware';
|
|
19
|
+
export { CorsMiddleware } from './middleware/cors.middleware';
|
|
20
|
+
export type { CorrelationIdOptions, LoggingOptions, JwtOptions, } from './middleware/middleware.interface';
|
|
21
|
+
export { HttpClientModule } from './client/http-client.module';
|
|
22
|
+
export { HttpClientService } from './client/http-client.service';
|
|
23
|
+
export type { HttpClientConfig, RetryOptions, RestApiConfig } from './client/client.interface';
|
|
24
|
+
export { CacheModule } from './cache/cache.module';
|
|
25
|
+
export { CacheService } from './cache/cache.service';
|
|
26
|
+
export type { CacheOptions } from './cache/cache.service';
|
|
27
|
+
export { RateLimitModule } from './rate-limit/rate-limit.module';
|
|
28
|
+
export { PrometheusModule } from './prometheus/prometheus.module';
|
|
29
|
+
export { PrometheusService } from './prometheus/prometheus.service';
|
|
30
|
+
export { I18nModule } from './i18n/i18n.module';
|
|
31
|
+
export { I18nService } from './i18n/i18n.service';
|
|
32
|
+
export type { I18nOptions } from './i18n/i18n.service';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.I18nService = exports.I18nModule = exports.PrometheusService = exports.PrometheusModule = exports.RateLimitModule = exports.CacheService = exports.CacheModule = exports.HttpClientService = exports.HttpClientModule = exports.CorsMiddleware = exports.LoggingMiddleware = exports.CorrelationIdMiddleware = exports.MiddlewareModule = exports.PrismaModule = exports.HttpResponse = exports.HttpResponseService = exports.HttpResponseModule = exports.HealthService = exports.HealthController = exports.HealthModule = exports.ConfigService = exports.ConfigModule = exports.MicroserviceCommonModule = void 0;
|
|
4
|
+
var microservice_common_module_1 = require("./microservice-common.module");
|
|
5
|
+
Object.defineProperty(exports, "MicroserviceCommonModule", { enumerable: true, get: function () { return microservice_common_module_1.MicroserviceCommonModule; } });
|
|
6
|
+
var config_module_1 = require("./config/config.module");
|
|
7
|
+
Object.defineProperty(exports, "ConfigModule", { enumerable: true, get: function () { return config_module_1.ConfigModule; } });
|
|
8
|
+
var config_service_1 = require("./config/config.service");
|
|
9
|
+
Object.defineProperty(exports, "ConfigService", { enumerable: true, get: function () { return config_service_1.ConfigService; } });
|
|
10
|
+
var health_module_1 = require("./health/health.module");
|
|
11
|
+
Object.defineProperty(exports, "HealthModule", { enumerable: true, get: function () { return health_module_1.HealthModule; } });
|
|
12
|
+
var health_controller_1 = require("./health/health.controller");
|
|
13
|
+
Object.defineProperty(exports, "HealthController", { enumerable: true, get: function () { return health_controller_1.HealthController; } });
|
|
14
|
+
var health_service_1 = require("./health/health.service");
|
|
15
|
+
Object.defineProperty(exports, "HealthService", { enumerable: true, get: function () { return health_service_1.HealthService; } });
|
|
16
|
+
var http_response_module_1 = require("./http/http-response.module");
|
|
17
|
+
Object.defineProperty(exports, "HttpResponseModule", { enumerable: true, get: function () { return http_response_module_1.HttpResponseModule; } });
|
|
18
|
+
var http_response_service_1 = require("./http/http-response.service");
|
|
19
|
+
Object.defineProperty(exports, "HttpResponseService", { enumerable: true, get: function () { return http_response_service_1.HttpResponseService; } });
|
|
20
|
+
var http_response_decorator_1 = require("./http/http-response.decorator");
|
|
21
|
+
Object.defineProperty(exports, "HttpResponse", { enumerable: true, get: function () { return http_response_decorator_1.HttpResponse; } });
|
|
22
|
+
var prisma_module_1 = require("./database/prisma.module");
|
|
23
|
+
Object.defineProperty(exports, "PrismaModule", { enumerable: true, get: function () { return prisma_module_1.PrismaModule; } });
|
|
24
|
+
var middleware_module_1 = require("./middleware/middleware.module");
|
|
25
|
+
Object.defineProperty(exports, "MiddlewareModule", { enumerable: true, get: function () { return middleware_module_1.MiddlewareModule; } });
|
|
26
|
+
var correlation_id_middleware_1 = require("./middleware/correlation-id.middleware");
|
|
27
|
+
Object.defineProperty(exports, "CorrelationIdMiddleware", { enumerable: true, get: function () { return correlation_id_middleware_1.CorrelationIdMiddleware; } });
|
|
28
|
+
var logging_middleware_1 = require("./middleware/logging.middleware");
|
|
29
|
+
Object.defineProperty(exports, "LoggingMiddleware", { enumerable: true, get: function () { return logging_middleware_1.LoggingMiddleware; } });
|
|
30
|
+
var cors_middleware_1 = require("./middleware/cors.middleware");
|
|
31
|
+
Object.defineProperty(exports, "CorsMiddleware", { enumerable: true, get: function () { return cors_middleware_1.CorsMiddleware; } });
|
|
32
|
+
var http_client_module_1 = require("./client/http-client.module");
|
|
33
|
+
Object.defineProperty(exports, "HttpClientModule", { enumerable: true, get: function () { return http_client_module_1.HttpClientModule; } });
|
|
34
|
+
var http_client_service_1 = require("./client/http-client.service");
|
|
35
|
+
Object.defineProperty(exports, "HttpClientService", { enumerable: true, get: function () { return http_client_service_1.HttpClientService; } });
|
|
36
|
+
var cache_module_1 = require("./cache/cache.module");
|
|
37
|
+
Object.defineProperty(exports, "CacheModule", { enumerable: true, get: function () { return cache_module_1.CacheModule; } });
|
|
38
|
+
var cache_service_1 = require("./cache/cache.service");
|
|
39
|
+
Object.defineProperty(exports, "CacheService", { enumerable: true, get: function () { return cache_service_1.CacheService; } });
|
|
40
|
+
var rate_limit_module_1 = require("./rate-limit/rate-limit.module");
|
|
41
|
+
Object.defineProperty(exports, "RateLimitModule", { enumerable: true, get: function () { return rate_limit_module_1.RateLimitModule; } });
|
|
42
|
+
var prometheus_module_1 = require("./prometheus/prometheus.module");
|
|
43
|
+
Object.defineProperty(exports, "PrometheusModule", { enumerable: true, get: function () { return prometheus_module_1.PrometheusModule; } });
|
|
44
|
+
var prometheus_service_1 = require("./prometheus/prometheus.service");
|
|
45
|
+
Object.defineProperty(exports, "PrometheusService", { enumerable: true, get: function () { return prometheus_service_1.PrometheusService; } });
|
|
46
|
+
var i18n_module_1 = require("./i18n/i18n.module");
|
|
47
|
+
Object.defineProperty(exports, "I18nModule", { enumerable: true, get: function () { return i18n_module_1.I18nModule; } });
|
|
48
|
+
var i18n_service_1 = require("./i18n/i18n.service");
|
|
49
|
+
Object.defineProperty(exports, "I18nService", { enumerable: true, get: function () { return i18n_service_1.I18nService; } });
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AAIjC,wDAAsD;AAA7C,6GAAA,YAAY,OAAA;AACrB,0DAAwD;AAA/C,+GAAA,aAAa,OAAA;AAStB,wDAAsD;AAA7C,6GAAA,YAAY,OAAA;AACrB,gEAA8D;AAArD,qHAAA,gBAAgB,OAAA;AACzB,0DAAwD;AAA/C,+GAAA,aAAa,OAAA;AAItB,oEAAiE;AAAxD,0HAAA,kBAAkB,OAAA;AAC3B,sEAAmE;AAA1D,4HAAA,mBAAmB,OAAA;AAE5B,0EAA8D;AAArD,uHAAA,YAAY,OAAA;AAGrB,0DAAwD;AAA/C,6GAAA,YAAY,OAAA;AAIrB,oEAAkE;AAAzD,qHAAA,gBAAgB,OAAA;AACzB,oFAAiF;AAAxE,oIAAA,uBAAuB,OAAA;AAChC,sEAAoE;AAA3D,uHAAA,iBAAiB,OAAA;AAC1B,gEAA8D;AAArD,iHAAA,cAAc,OAAA;AAQvB,kEAA+D;AAAtD,sHAAA,gBAAgB,OAAA;AACzB,oEAAiE;AAAxD,wHAAA,iBAAiB,OAAA;AAI1B,qDAAmD;AAA1C,2GAAA,WAAW,OAAA;AACpB,uDAAqD;AAA5C,6GAAA,YAAY,OAAA;AAIrB,oEAAiE;AAAxD,oHAAA,eAAe,OAAA;AAGxB,oEAAkE;AAAzD,qHAAA,gBAAgB,OAAA;AACzB,sEAAoE;AAA3D,uHAAA,iBAAiB,OAAA;AAG1B,kDAAgD;AAAvC,yGAAA,UAAU,OAAA;AACnB,oDAAkD;AAAzC,2GAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { CacheOptions } from './cache/cache.service';
|
|
3
|
+
import { I18nOptions } from './i18n/i18n.service';
|
|
4
|
+
import { CorrelationIdOptions, LoggingOptions } from './middleware/middleware.interface';
|
|
5
|
+
export interface MicroserviceCommonModuleOptions {
|
|
6
|
+
enableCache?: boolean;
|
|
7
|
+
cacheOptions?: CacheOptions;
|
|
8
|
+
enableRateLimit?: boolean;
|
|
9
|
+
enablePrometheus?: boolean;
|
|
10
|
+
enableI18n?: boolean;
|
|
11
|
+
i18nOptions?: I18nOptions;
|
|
12
|
+
correlationIdOptions?: CorrelationIdOptions;
|
|
13
|
+
loggingOptions?: LoggingOptions;
|
|
14
|
+
}
|
|
15
|
+
export declare class MicroserviceCommonModule {
|
|
16
|
+
static forRoot(options?: MicroserviceCommonModuleOptions): DynamicModule;
|
|
17
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 MicroserviceCommonModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.MicroserviceCommonModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const config_module_1 = require("./config/config.module");
|
|
13
|
+
const health_module_1 = require("./health/health.module");
|
|
14
|
+
const http_response_module_1 = require("./http/http-response.module");
|
|
15
|
+
const http_client_module_1 = require("./client/http-client.module");
|
|
16
|
+
const cache_module_1 = require("./cache/cache.module");
|
|
17
|
+
const middleware_module_1 = require("./middleware/middleware.module");
|
|
18
|
+
const rate_limit_module_1 = require("./rate-limit/rate-limit.module");
|
|
19
|
+
const prometheus_module_1 = require("./prometheus/prometheus.module");
|
|
20
|
+
const i18n_module_1 = require("./i18n/i18n.module");
|
|
21
|
+
const config_service_1 = require("./config/config.service");
|
|
22
|
+
let MicroserviceCommonModule = MicroserviceCommonModule_1 = class MicroserviceCommonModule {
|
|
23
|
+
static forRoot(options) {
|
|
24
|
+
const { enableCache = true, cacheOptions, enableRateLimit = true, enablePrometheus = true, enableI18n = false, i18nOptions, correlationIdOptions, loggingOptions, } = options || {};
|
|
25
|
+
const imports = [
|
|
26
|
+
config_module_1.ConfigModule,
|
|
27
|
+
health_module_1.HealthModule,
|
|
28
|
+
http_response_module_1.HttpResponseModule,
|
|
29
|
+
http_client_module_1.HttpClientModule,
|
|
30
|
+
];
|
|
31
|
+
if (enableCache) {
|
|
32
|
+
imports.push(cache_module_1.CacheModule.forRoot(cacheOptions));
|
|
33
|
+
}
|
|
34
|
+
if (enableRateLimit) {
|
|
35
|
+
imports.push(rate_limit_module_1.RateLimitModule.forRoot());
|
|
36
|
+
}
|
|
37
|
+
if (enablePrometheus) {
|
|
38
|
+
imports.push(prometheus_module_1.PrometheusModule);
|
|
39
|
+
}
|
|
40
|
+
if (enableI18n) {
|
|
41
|
+
imports.push(i18n_module_1.I18nModule.forRoot(i18nOptions));
|
|
42
|
+
}
|
|
43
|
+
imports.push(middleware_module_1.MiddlewareModule.forRoot(correlationIdOptions, loggingOptions));
|
|
44
|
+
const exports = [
|
|
45
|
+
config_module_1.ConfigModule,
|
|
46
|
+
health_module_1.HealthModule,
|
|
47
|
+
http_response_module_1.HttpResponseModule,
|
|
48
|
+
http_client_module_1.HttpClientModule,
|
|
49
|
+
middleware_module_1.MiddlewareModule,
|
|
50
|
+
config_service_1.ConfigService,
|
|
51
|
+
];
|
|
52
|
+
if (enableCache) {
|
|
53
|
+
exports.push(cache_module_1.CacheModule);
|
|
54
|
+
}
|
|
55
|
+
if (enableRateLimit) {
|
|
56
|
+
exports.push(rate_limit_module_1.RateLimitModule);
|
|
57
|
+
}
|
|
58
|
+
if (enablePrometheus) {
|
|
59
|
+
exports.push(prometheus_module_1.PrometheusModule);
|
|
60
|
+
}
|
|
61
|
+
if (enableI18n) {
|
|
62
|
+
exports.push(i18n_module_1.I18nModule);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
module: MicroserviceCommonModule_1,
|
|
66
|
+
imports,
|
|
67
|
+
providers: [config_service_1.ConfigService],
|
|
68
|
+
exports,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
exports.MicroserviceCommonModule = MicroserviceCommonModule;
|
|
73
|
+
exports.MicroserviceCommonModule = MicroserviceCommonModule = MicroserviceCommonModule_1 = __decorate([
|
|
74
|
+
(0, common_1.Module)({})
|
|
75
|
+
], MicroserviceCommonModule);
|
|
76
|
+
//# sourceMappingURL=microservice-common.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"microservice-common.module.js","sourceRoot":"","sources":["../src/microservice-common.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA6D;AAC7D,0DAAsD;AACtD,0DAAsD;AACtD,sEAAiE;AACjE,oEAA+D;AAC/D,uDAAmD;AAEnD,sEAAkE;AAClE,sEAAiE;AACjE,sEAAkE;AAClE,oDAAgD;AAEhD,4DAAwD;AAejD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IACnC,MAAM,CAAC,OAAO,CAAC,OAAyC;QACtD,MAAM,EACJ,WAAW,GAAG,IAAI,EAClB,YAAY,EACZ,eAAe,GAAG,IAAI,EACtB,gBAAgB,GAAG,IAAI,EACvB,UAAU,GAAG,KAAK,EAClB,WAAW,EACX,oBAAoB,EACpB,cAAc,GACf,GAAG,OAAO,IAAI,EAAE,CAAC;QAElB,MAAM,OAAO,GAAyC;YACpD,4BAAY;YACZ,4BAAY;YACZ,yCAAkB;YAClB,qCAAgB;SACjB,CAAC;QAEF,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,IAAI,CAAC,0BAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,mCAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,gBAAgB,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,oCAAgB,CAAC,CAAC;QACjC,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,wBAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;QAChD,CAAC;QAGD,OAAO,CAAC,IAAI,CAAC,oCAAgB,CAAC,OAAO,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAAC,CAAC;QAG7E,MAAM,OAAO,GAAyC;YACpD,4BAAY;YACZ,4BAAY;YACZ,yCAAkB;YAClB,qCAAgB;YAChB,oCAAgB;YAChB,8BAAa;SACd,CAAC;QAEF,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,IAAI,CAAC,0BAAW,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,mCAAe,CAAC,CAAC;QAChC,CAAC;QAED,IAAI,gBAAgB,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,oCAAgB,CAAC,CAAC;QACjC,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,wBAAU,CAAC,CAAC;QAC3B,CAAC;QAED,OAAO;YACL,MAAM,EAAE,0BAAwB;YAChC,OAAO;YACP,SAAS,EAAE,CAAC,8BAAa,CAAC;YAC1B,OAAO;SACR,CAAC;IACJ,CAAC;CACF,CAAA;AAxEY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,wBAAwB,CAwEpC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
import { CorrelationIdOptions } from '../middleware/middleware.interface';
|
|
4
|
+
export declare class CorrelationIdMiddleware implements NestMiddleware {
|
|
5
|
+
private readonly headerName;
|
|
6
|
+
private readonly generateIfMissing;
|
|
7
|
+
constructor(options?: CorrelationIdOptions);
|
|
8
|
+
use(req: Request, res: Response, next: NextFunction): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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.CorrelationIdMiddleware = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const uuid_1 = require("uuid");
|
|
15
|
+
let CorrelationIdMiddleware = class CorrelationIdMiddleware {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.headerName = options?.headerName || 'x-correlation-id';
|
|
18
|
+
this.generateIfMissing = options?.generateIfMissing ?? true;
|
|
19
|
+
}
|
|
20
|
+
use(req, res, next) {
|
|
21
|
+
const correlationId = req.headers[this.headerName];
|
|
22
|
+
if (!correlationId && this.generateIfMissing) {
|
|
23
|
+
req.headers[this.headerName] = (0, uuid_1.v4)();
|
|
24
|
+
}
|
|
25
|
+
res.setHeader(this.headerName, req.headers[this.headerName]);
|
|
26
|
+
next();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.CorrelationIdMiddleware = CorrelationIdMiddleware;
|
|
30
|
+
exports.CorrelationIdMiddleware = CorrelationIdMiddleware = __decorate([
|
|
31
|
+
(0, common_1.Injectable)(),
|
|
32
|
+
__metadata("design:paramtypes", [Object])
|
|
33
|
+
], CorrelationIdMiddleware);
|
|
34
|
+
//# sourceMappingURL=correlation-id.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlation-id.middleware.js","sourceRoot":"","sources":["../../src/middleware/correlation-id.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4D;AAE5D,+BAAoC;AAI7B,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAIlC,YAAY,OAA8B;QACxC,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,kBAAkB,CAAC;QAC5D,IAAI,CAAC,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI,IAAI,CAAC;IAC9D,CAAC;IAED,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;QACjD,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAW,CAAC;QAE7D,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC7C,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,IAAA,SAAM,GAAE,CAAC;QAC1C,CAAC;QAED,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAW,CAAC,CAAC;QACvE,IAAI,EAAE,CAAC;IACT,CAAC;CACF,CAAA;AAnBY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;;GACA,uBAAuB,CAmBnC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
import { MicroserviceCommonConfig } from '../config/config.interface';
|
|
4
|
+
export declare class CorsMiddleware implements NestMiddleware {
|
|
5
|
+
private readonly corsConfig;
|
|
6
|
+
constructor(corsConfig?: MicroserviceCommonConfig['cors']);
|
|
7
|
+
use(req: Request, res: Response, next: NextFunction): void;
|
|
8
|
+
private isOriginAllowed;
|
|
9
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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.CorsMiddleware = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
let CorsMiddleware = class CorsMiddleware {
|
|
15
|
+
constructor(corsConfig) {
|
|
16
|
+
this.corsConfig = corsConfig || {
|
|
17
|
+
origin: '*',
|
|
18
|
+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH', 'HEAD'],
|
|
19
|
+
allowedHeaders: [
|
|
20
|
+
'Content-Type',
|
|
21
|
+
'Authorization',
|
|
22
|
+
'X-Request-ID',
|
|
23
|
+
'X-Correlation-UID',
|
|
24
|
+
'X-Consumer-Custom-ID',
|
|
25
|
+
],
|
|
26
|
+
exposedHeaders: ['Content-Length', 'Content-Type'],
|
|
27
|
+
credentials: false,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
use(req, res, next) {
|
|
31
|
+
const origin = req.headers.origin;
|
|
32
|
+
if (this.corsConfig && (this.corsConfig.origin === '*' || this.isOriginAllowed(origin))) {
|
|
33
|
+
res.setHeader('Access-Control-Allow-Origin', origin || '*');
|
|
34
|
+
}
|
|
35
|
+
if (this.corsConfig?.methods) {
|
|
36
|
+
res.setHeader('Access-Control-Allow-Methods', this.corsConfig.methods.join(','));
|
|
37
|
+
}
|
|
38
|
+
if (this.corsConfig?.allowedHeaders) {
|
|
39
|
+
res.setHeader('Access-Control-Allow-Headers', this.corsConfig.allowedHeaders.join(','));
|
|
40
|
+
}
|
|
41
|
+
if (this.corsConfig?.exposedHeaders) {
|
|
42
|
+
res.setHeader('Access-Control-Expose-Headers', this.corsConfig.exposedHeaders.join(','));
|
|
43
|
+
}
|
|
44
|
+
if (this.corsConfig?.credentials) {
|
|
45
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
46
|
+
}
|
|
47
|
+
if (req.method === 'OPTIONS') {
|
|
48
|
+
res.status(200).end();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
next();
|
|
52
|
+
}
|
|
53
|
+
isOriginAllowed(origin) {
|
|
54
|
+
if (!origin || !this.corsConfig) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (typeof this.corsConfig.origin === 'string') {
|
|
58
|
+
return this.corsConfig.origin === '*' || this.corsConfig.origin === origin;
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(this.corsConfig.origin)) {
|
|
61
|
+
return this.corsConfig.origin.includes(origin);
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.CorsMiddleware = CorsMiddleware;
|
|
67
|
+
exports.CorsMiddleware = CorsMiddleware = __decorate([
|
|
68
|
+
(0, common_1.Injectable)(),
|
|
69
|
+
__metadata("design:paramtypes", [Object])
|
|
70
|
+
], CorsMiddleware);
|
|
71
|
+
//# sourceMappingURL=cors.middleware.js.map
|