grm-shared-library 1.0.11 → 1.0.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.
Files changed (28) hide show
  1. package/dist/decorators/case-decorators.d.ts +3 -0
  2. package/dist/decorators/case-decorators.js +28 -0
  3. package/dist/exceptions/custom-exception/custom-rpc.exception.d.ts +10 -0
  4. package/dist/exceptions/custom-exception/custom-rpc.exception.js +30 -0
  5. package/dist/exceptions/enums/error-codes.enum.d.ts +5 -0
  6. package/dist/exceptions/enums/error-codes.enum.js +8 -0
  7. package/dist/exceptions/error-logger/error-logger.d.ts +2 -0
  8. package/dist/exceptions/error-logger/error-logger.js +24 -0
  9. package/dist/exceptions/filters/all-exceptions.filter.d.ts +6 -0
  10. package/dist/exceptions/filters/all-exceptions.filter.js +63 -0
  11. package/dist/exceptions/index.d.ts +6 -0
  12. package/dist/exceptions/index.js +22 -0
  13. package/dist/exceptions/interfaces/error-context.d.ts +7 -0
  14. package/dist/exceptions/interfaces/error-context.js +2 -0
  15. package/dist/exceptions/interfaces/error-response.d.ts +8 -0
  16. package/dist/exceptions/interfaces/error-response.js +2 -0
  17. package/dist/index.d.ts +11 -11
  18. package/dist/index.js +11 -11
  19. package/dist/modules/common/index.d.ts +2 -0
  20. package/dist/modules/common/index.js +18 -0
  21. package/dist/modules/organization/dtos/contact-person.dto.js +2 -2
  22. package/dist/modules/organization/index.d.ts +5 -0
  23. package/dist/modules/organization/index.js +21 -0
  24. package/dist/modules/organization/interfaces/organization.d.ts +1 -1
  25. package/dist/modules/user/dtos/create-user.dto.js +2 -0
  26. package/dist/modules/user/index.d.ts +0 -0
  27. package/dist/modules/user/index.js +1 -0
  28. package/package.json +20 -3
@@ -0,0 +1,3 @@
1
+ export declare function SentenceCase(): PropertyDecorator;
2
+ export declare function UpperCase(): PropertyDecorator;
3
+ export declare function LowerCase(): PropertyDecorator;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SentenceCase = SentenceCase;
4
+ exports.UpperCase = UpperCase;
5
+ exports.LowerCase = LowerCase;
6
+ const class_transformer_1 = require("class-transformer");
7
+ function SentenceCase() {
8
+ return (0, class_transformer_1.Transform)(({ value }) => {
9
+ if (typeof value !== 'string') {
10
+ return value;
11
+ }
12
+ return value
13
+ .split(' ')
14
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
15
+ .join(' ');
16
+ });
17
+ }
18
+ function UpperCase() {
19
+ return (0, class_transformer_1.Transform)(({ value }) => {
20
+ if (typeof value !== 'string') {
21
+ return value;
22
+ }
23
+ return value.toUpperCase();
24
+ });
25
+ }
26
+ function LowerCase() {
27
+ return (0, class_transformer_1.Transform)(({ value }) => typeof value === "string" ? value.toLowerCase() : value);
28
+ }
@@ -0,0 +1,10 @@
1
+ import { RpcException } from "@nestjs/microservices";
2
+ import { ErrorContext } from "../interfaces/error-context";
3
+ import { ErrorResponse } from "../interfaces/error-response";
4
+ export declare class CustomRpcException extends RpcException {
5
+ constructor(message: string, code: string, details?: string, context?: ErrorContext);
6
+ static fromError(message: string, error: Error, context: ErrorContext): CustomRpcException;
7
+ static fromDBError(message: string, error: Error, context: ErrorContext): CustomRpcException;
8
+ getErrorResponse(): ErrorResponse;
9
+ getContext(): ErrorContext | undefined;
10
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomRpcException = void 0;
4
+ const microservices_1 = require("@nestjs/microservices");
5
+ const error_codes_enum_1 = require("../enums/error-codes.enum");
6
+ class CustomRpcException extends microservices_1.RpcException {
7
+ constructor(message, code, details, context) {
8
+ const errorResponse = {
9
+ message,
10
+ code,
11
+ timestamp: new Date().toISOString(),
12
+ details,
13
+ context
14
+ };
15
+ super(errorResponse);
16
+ }
17
+ static fromError(message, error, context) {
18
+ return new CustomRpcException(message, error_codes_enum_1.ErrorCodes.INTERNAL_SERVER_ERROR, error.message, context);
19
+ }
20
+ static fromDBError(message, error, context) {
21
+ return new CustomRpcException(message, error_codes_enum_1.ErrorCodes.DATABASE_ERROR, error.message, context);
22
+ }
23
+ getErrorResponse() {
24
+ return this.getError();
25
+ }
26
+ getContext() {
27
+ return this.getErrorResponse().context;
28
+ }
29
+ }
30
+ exports.CustomRpcException = CustomRpcException;
@@ -0,0 +1,5 @@
1
+ export declare const ErrorCodes: {
2
+ INTERNAL_SERVER_ERROR: string;
3
+ DATABASE_ERROR: string;
4
+ UNKNOWN_ERROR: string;
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorCodes = void 0;
4
+ exports.ErrorCodes = {
5
+ INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
6
+ DATABASE_ERROR: 'DATABASE_ERROR',
7
+ UNKNOWN_ERROR: 'UNKNOWN_ERROR',
8
+ };
@@ -0,0 +1,2 @@
1
+ import { ErrorContext } from '../interfaces/error-context';
2
+ export declare const logError: (error: Error, context?: ErrorContext) => Promise<void>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logError = void 0;
4
+ const Sentry = require("@sentry/node");
5
+ const logError = async (error, context) => {
6
+ Sentry.withScope(scope => {
7
+ if (context) {
8
+ scope.setTag('service', context.service);
9
+ scope.setTag('method', context.method);
10
+ if (context.userId) {
11
+ scope.setUser({ id: context.userId });
12
+ }
13
+ if (context.payload) {
14
+ scope.setExtra('payload', context.payload);
15
+ }
16
+ if (context.additionalContext) {
17
+ scope.setExtras(context.additionalContext);
18
+ }
19
+ }
20
+ Sentry.captureException(error);
21
+ });
22
+ await Sentry.flush(2000);
23
+ };
24
+ exports.logError = logError;
@@ -0,0 +1,6 @@
1
+ import { RpcExceptionFilter, ArgumentsHost } from '@nestjs/common';
2
+ import { Observable } from 'rxjs';
3
+ export declare class AllExceptionsFilter implements RpcExceptionFilter<any> {
4
+ private readonly logger;
5
+ catch(exception: any, host: ArgumentsHost): Observable<any>;
6
+ }
@@ -0,0 +1,63 @@
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 AllExceptionsFilter_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.AllExceptionsFilter = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const rxjs_1 = require("rxjs");
13
+ const microservices_1 = require("@nestjs/microservices");
14
+ const custom_rpc_exception_1 = require("../custom-exception/custom-rpc.exception");
15
+ const error_codes_enum_1 = require("../enums/error-codes.enum");
16
+ const error_logger_1 = require("../error-logger/error-logger");
17
+ let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
18
+ constructor() {
19
+ this.logger = new common_1.Logger(AllExceptionsFilter_1.name);
20
+ }
21
+ catch(exception, host) {
22
+ var _a, _b, _c, _d, _e, _f;
23
+ let customException;
24
+ if (exception instanceof custom_rpc_exception_1.CustomRpcException) {
25
+ customException = exception;
26
+ }
27
+ else if (exception instanceof microservices_1.RpcException) {
28
+ const errorResponse = exception.getError();
29
+ if (typeof errorResponse === 'string') {
30
+ customException = new custom_rpc_exception_1.CustomRpcException(errorResponse, error_codes_enum_1.ErrorCodes.UNKNOWN_ERROR, 'An unexpected error occurred', {
31
+ service: 'Unknown in Organization-Microservice',
32
+ method: (_a = host.getArgByIndex(1)) === null || _a === void 0 ? void 0 : _a.pattern,
33
+ payload: (_b = host.getArgByIndex(1)) === null || _b === void 0 ? void 0 : _b.data
34
+ });
35
+ }
36
+ else {
37
+ const error = errorResponse;
38
+ customException = new custom_rpc_exception_1.CustomRpcException(error.message || 'Unknown error', error.code || error_codes_enum_1.ErrorCodes.UNKNOWN_ERROR, error.details || undefined, error.context || {
39
+ service: 'Unknown in Organization-Microservice',
40
+ method: (_c = host.getArgByIndex(1)) === null || _c === void 0 ? void 0 : _c.pattern,
41
+ payload: (_d = host.getArgByIndex(1)) === null || _d === void 0 ? void 0 : _d.data
42
+ });
43
+ }
44
+ }
45
+ else {
46
+ const context = {
47
+ service: 'Unknown in Organization-Microservice',
48
+ method: (_e = host.getArgByIndex(1)) === null || _e === void 0 ? void 0 : _e.pattern,
49
+ payload: (_f = host.getArgByIndex(1)) === null || _f === void 0 ? void 0 : _f.data
50
+ };
51
+ customException = custom_rpc_exception_1.CustomRpcException.fromError('An unknown Error occured', exception, context);
52
+ }
53
+ this.logger.error(customException.getErrorResponse().message, customException.getErrorResponse().details);
54
+ (0, error_logger_1.logError)(exception, customException.getContext()); // Log to Sentry
55
+ const responseError = { ...customException.getErrorResponse() }; // Remove context before sending response
56
+ delete responseError.context;
57
+ return (0, rxjs_1.throwError)(() => responseError);
58
+ }
59
+ };
60
+ exports.AllExceptionsFilter = AllExceptionsFilter;
61
+ exports.AllExceptionsFilter = AllExceptionsFilter = AllExceptionsFilter_1 = __decorate([
62
+ (0, common_1.Catch)()
63
+ ], AllExceptionsFilter);
@@ -0,0 +1,6 @@
1
+ export * from './custom-exception/custom-rpc.exception';
2
+ export * from './enums/error-codes.enum';
3
+ export * from './error-logger/error-logger';
4
+ export * from './filters/all-exceptions.filter';
5
+ export * from './interfaces/error-context';
6
+ export * from './interfaces/error-response';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./custom-exception/custom-rpc.exception"), exports);
18
+ __exportStar(require("./enums/error-codes.enum"), exports);
19
+ __exportStar(require("./error-logger/error-logger"), exports);
20
+ __exportStar(require("./filters/all-exceptions.filter"), exports);
21
+ __exportStar(require("./interfaces/error-context"), exports);
22
+ __exportStar(require("./interfaces/error-response"), exports);
@@ -0,0 +1,7 @@
1
+ export interface ErrorContext {
2
+ service?: string;
3
+ method?: string;
4
+ payload?: any;
5
+ userId?: string;
6
+ additionalContext?: Record<string, any>;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { ErrorContext } from "./error-context";
2
+ export interface ErrorResponse {
3
+ message: string;
4
+ code: string;
5
+ timestamp: string;
6
+ details?: string;
7
+ context?: ErrorContext;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  /**
2
- * Organization
2
+ * Modules
3
3
  */
4
- export * from './modules/organization/dtos/create-organization.dto';
5
- export * from './modules/organization/dtos/update-organization.dto';
6
- export * from './modules/organization/dtos/contact-person.dto';
7
- export * from './modules/organization/interfaces/organization';
8
- export * from './modules/organization/enums/org-status.enum';
9
- /**
10
- * Common
11
- */
12
- export * from './modules/common/dtos/map-location.dto';
13
- export * from './modules/common/dtos/map-address.dto';
4
+ export * from './modules/organization/index';
5
+ export * from './modules/common/index';
14
6
  /**
15
7
  * Kafka
16
8
  */
17
9
  export * from './kafka/topics';
10
+ /**
11
+ * Utilities
12
+ */
13
+ export * from './decorators/case-decorators';
14
+ /**
15
+ * Exceptions
16
+ */
17
+ export * from './exceptions/index';
package/dist/index.js CHANGED
@@ -15,19 +15,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  /**
18
- * Organization
18
+ * Modules
19
19
  */
20
- __exportStar(require("./modules/organization/dtos/create-organization.dto"), exports);
21
- __exportStar(require("./modules/organization/dtos/update-organization.dto"), exports);
22
- __exportStar(require("./modules/organization/dtos/contact-person.dto"), exports);
23
- __exportStar(require("./modules/organization/interfaces/organization"), exports);
24
- __exportStar(require("./modules/organization/enums/org-status.enum"), exports);
25
- /**
26
- * Common
27
- */
28
- __exportStar(require("./modules/common/dtos/map-location.dto"), exports);
29
- __exportStar(require("./modules/common/dtos/map-address.dto"), exports);
20
+ __exportStar(require("./modules/organization/index"), exports);
21
+ __exportStar(require("./modules/common/index"), exports);
30
22
  /**
31
23
  * Kafka
32
24
  */
33
25
  __exportStar(require("./kafka/topics"), exports);
26
+ /**
27
+ * Utilities
28
+ */
29
+ __exportStar(require("./decorators/case-decorators"), exports);
30
+ /**
31
+ * Exceptions
32
+ */
33
+ __exportStar(require("./exceptions/index"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './dtos/map-location.dto';
2
+ export * from './dtos/map-address.dto';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./dtos/map-location.dto"), exports);
18
+ __exportStar(require("./dtos/map-address.dto"), exports);
@@ -11,13 +11,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ContactPersonDto = void 0;
13
13
  const class_validator_1 = require("class-validator");
14
- const decorators_1 = require("../../utilities/decorators");
14
+ const case_decorators_1 = require("../../../decorators/case-decorators");
15
15
  class ContactPersonDto {
16
16
  }
17
17
  exports.ContactPersonDto = ContactPersonDto;
18
18
  __decorate([
19
19
  (0, class_validator_1.IsString)(),
20
- (0, decorators_1.SentenceCase)(),
20
+ (0, case_decorators_1.SentenceCase)(),
21
21
  (0, class_validator_1.IsNotEmpty)(),
22
22
  __metadata("design:type", String)
23
23
  ], ContactPersonDto.prototype, "name", void 0);
@@ -0,0 +1,5 @@
1
+ export * from './dtos/create-organization.dto';
2
+ export * from './dtos/update-organization.dto';
3
+ export * from './dtos/contact-person.dto';
4
+ export * from './interfaces/organization';
5
+ export * from './enums/org-status.enum';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./dtos/create-organization.dto"), exports);
18
+ __exportStar(require("./dtos/update-organization.dto"), exports);
19
+ __exportStar(require("./dtos/contact-person.dto"), exports);
20
+ __exportStar(require("./interfaces/organization"), exports);
21
+ __exportStar(require("./enums/org-status.enum"), exports);
@@ -1,4 +1,4 @@
1
- import { MapAddressDto } from "../modules/common/dtos/map-address.dto";
1
+ import { MapAddressDto } from "../../common/dtos/map-address.dto";
2
2
  export interface Organization {
3
3
  id: number;
4
4
  name: string;
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CreateUserDto = void 0;
13
13
  const class_validator_1 = require("class-validator");
14
14
  const user_role_enum_1 = require("../enums/user-role.enum");
15
+ const case_decorators_1 = require("../../../decorators/case-decorators");
15
16
  class CreateUserDto {
16
17
  constructor() {
17
18
  this.role = user_role_enum_1.UserRole.USER;
@@ -22,6 +23,7 @@ __decorate([
22
23
  (0, class_validator_1.IsString)(),
23
24
  (0, class_validator_1.IsNotEmpty)(),
24
25
  (0, class_validator_1.MinLength)(2),
26
+ (0, case_decorators_1.SentenceCase)(),
25
27
  __metadata("design:type", String)
26
28
  ], CreateUserDto.prototype, "name", void 0);
27
29
  __decorate([
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grm-shared-library",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -8,7 +8,10 @@
8
8
  ],
9
9
  "scripts": {
10
10
  "build": "tsc",
11
- "test": "echo \"Error: no test specified\" && exit 1"
11
+ "build:watch": "tsc -w",
12
+ "prepare": "npm run build",
13
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
14
+ "type-check": "tsc --noEmit"
12
15
  },
13
16
  "keywords": [],
14
17
  "author": "",
@@ -22,9 +25,23 @@
22
25
  "typescript": "^5.7.3"
23
26
  },
24
27
  "dependencies": {
28
+ "@nestjs/common": "^11.0.6",
29
+ "@nestjs/core": "^11.0.6",
25
30
  "@nestjs/mapped-types": "^2.0.6",
31
+ "@nestjs/microservices": "^11.0.6",
26
32
  "@nestjs/swagger": "^8.1.1",
33
+ "@sentry/node": "^8.52.0",
27
34
  "class-transformer": "^0.5.1",
28
- "class-validator": "^0.14.1"
35
+ "class-validator": "^0.14.1",
36
+ "rxjs": "^7.8.1"
37
+ },
38
+ "peerDependencies": {
39
+ "@nestjs/common": "^11.0.0",
40
+ "@nestjs/core": "^11.0.0",
41
+ "@nestjs/microservices": "^11.0.0",
42
+ "@sentry/node": "^8.0.0",
43
+ "rxjs": "^7.8.0",
44
+ "class-transformer": "^0.5.0",
45
+ "class-validator": "^0.14.0"
29
46
  }
30
47
  }