@furkanogutcu/nest-common 0.0.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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +187 -0
  3. package/dist/exceptions/app.exception.d.ts +13 -0
  4. package/dist/exceptions/app.exception.js +22 -0
  5. package/dist/exceptions/app.exception.js.map +1 -0
  6. package/dist/exceptions/bad-request.exception.d.ts +8 -0
  7. package/dist/exceptions/bad-request.exception.js +16 -0
  8. package/dist/exceptions/bad-request.exception.js.map +1 -0
  9. package/dist/exceptions/conflict.exception.d.ts +8 -0
  10. package/dist/exceptions/conflict.exception.js +29 -0
  11. package/dist/exceptions/conflict.exception.js.map +1 -0
  12. package/dist/exceptions/filters/global.exception-filter.d.ts +5 -0
  13. package/dist/exceptions/filters/global.exception-filter.js +60 -0
  14. package/dist/exceptions/filters/global.exception-filter.js.map +1 -0
  15. package/dist/exceptions/filters/index.d.ts +1 -0
  16. package/dist/exceptions/filters/index.js +18 -0
  17. package/dist/exceptions/filters/index.js.map +1 -0
  18. package/dist/exceptions/forbidden.exception.d.ts +8 -0
  19. package/dist/exceptions/forbidden.exception.js +17 -0
  20. package/dist/exceptions/forbidden.exception.js.map +1 -0
  21. package/dist/exceptions/index.d.ts +14 -0
  22. package/dist/exceptions/index.js +31 -0
  23. package/dist/exceptions/index.js.map +1 -0
  24. package/dist/exceptions/interfaces/error-response.interface.d.ts +9 -0
  25. package/dist/exceptions/interfaces/error-response.interface.js +3 -0
  26. package/dist/exceptions/interfaces/error-response.interface.js.map +1 -0
  27. package/dist/exceptions/interfaces/index.d.ts +2 -0
  28. package/dist/exceptions/interfaces/index.js +19 -0
  29. package/dist/exceptions/interfaces/index.js.map +1 -0
  30. package/dist/exceptions/interfaces/validation-error-detail.interface.d.ts +6 -0
  31. package/dist/exceptions/interfaces/validation-error-detail.interface.js +3 -0
  32. package/dist/exceptions/interfaces/validation-error-detail.interface.js.map +1 -0
  33. package/dist/exceptions/internal.exception.d.ts +10 -0
  34. package/dist/exceptions/internal.exception.js +18 -0
  35. package/dist/exceptions/internal.exception.js.map +1 -0
  36. package/dist/exceptions/not-found.exception.d.ts +8 -0
  37. package/dist/exceptions/not-found.exception.js +18 -0
  38. package/dist/exceptions/not-found.exception.js.map +1 -0
  39. package/dist/exceptions/reference/exception-code.reference.d.ts +25 -0
  40. package/dist/exceptions/reference/exception-code.reference.js +30 -0
  41. package/dist/exceptions/reference/exception-code.reference.js.map +1 -0
  42. package/dist/exceptions/reference/index.d.ts +2 -0
  43. package/dist/exceptions/reference/index.js +19 -0
  44. package/dist/exceptions/reference/index.js.map +1 -0
  45. package/dist/exceptions/reference/validation-error-type.reference.d.ts +6 -0
  46. package/dist/exceptions/reference/validation-error-type.reference.js +11 -0
  47. package/dist/exceptions/reference/validation-error-type.reference.js.map +1 -0
  48. package/dist/exceptions/too-many-request.exception.d.ts +4 -0
  49. package/dist/exceptions/too-many-request.exception.js +17 -0
  50. package/dist/exceptions/too-many-request.exception.js.map +1 -0
  51. package/dist/exceptions/transformers/index.d.ts +2 -0
  52. package/dist/exceptions/transformers/index.js +19 -0
  53. package/dist/exceptions/transformers/index.js.map +1 -0
  54. package/dist/exceptions/transformers/nestjs.exception-transformer.d.ts +5 -0
  55. package/dist/exceptions/transformers/nestjs.exception-transformer.js +33 -0
  56. package/dist/exceptions/transformers/nestjs.exception-transformer.js.map +1 -0
  57. package/dist/exceptions/transformers/typeorm.exception-transformer.d.ts +12 -0
  58. package/dist/exceptions/transformers/typeorm.exception-transformer.js +54 -0
  59. package/dist/exceptions/transformers/typeorm.exception-transformer.js.map +1 -0
  60. package/dist/exceptions/unauthorized.exception.d.ts +8 -0
  61. package/dist/exceptions/unauthorized.exception.js +17 -0
  62. package/dist/exceptions/unauthorized.exception.js.map +1 -0
  63. package/dist/exceptions/unprocessable-entity.exception.d.ts +8 -0
  64. package/dist/exceptions/unprocessable-entity.exception.js +17 -0
  65. package/dist/exceptions/unprocessable-entity.exception.js.map +1 -0
  66. package/dist/exceptions/validation.exception.d.ts +8 -0
  67. package/dist/exceptions/validation.exception.js +54 -0
  68. package/dist/exceptions/validation.exception.js.map +1 -0
  69. package/dist/index.d.ts +1 -0
  70. package/dist/index.js +18 -0
  71. package/dist/index.js.map +1 -0
  72. package/package.json +103 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Furkan Ogutcu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # NestJS Common
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@furkanogutcu/nest-common.svg)](https://www.npmjs.com/package/@furkanogutcu/nest-common)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ A module containing common structures and utilities for NestJS projects.
7
+
8
+ ## Contents
9
+
10
+ This package is designed to standardize structures you repeatedly use in your NestJS projects and to accelerate the development process.
11
+
12
+ - [Installation](#installation)
13
+ - [Features](#features)
14
+ - [Exceptions](#1-exceptions)
15
+ - [Development](#development)
16
+ - [License](#license)
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @furkanogutcu/nest-common
22
+ ```
23
+
24
+ or
25
+
26
+ ```bash
27
+ yarn add @furkanogutcu/nest-common
28
+ ```
29
+
30
+ ## Features
31
+
32
+ ### 1. Exceptions
33
+
34
+ #### Installation
35
+
36
+ No additional installation steps are needed beyond installing the package.
37
+
38
+ #### Features
39
+
40
+ - **Custom Exception Classes**: Comprehensive set of HTTP-based exception classes for consistent error responses.
41
+
42
+ | Exception Class | HTTP Status | Description |
43
+ |-----------------|-------------|-------------|
44
+ | `AppException` | - | Base exception class for all custom exceptions |
45
+ | `AppBadRequestException` | 400 | For invalid input, malformed requests |
46
+ | `AppUnauthorizedException` | 401 | For authentication failures |
47
+ | `AppForbiddenException` | 403 | For authorization failures |
48
+ | `AppNotFoundException` | 404 | For resources that couldn't be found |
49
+ | `AppConflictException` | 409 | For conflicting requests (e.g., duplicate entries) |
50
+ | `AppUnprocessableEntityException` | 422 | For semantically incorrect requests |
51
+ | `AppInternalException` | 500 | For server-side errors |
52
+ | `AppTooManyRequestException` | 429 | For rate limiting scenarios |
53
+ | `AppValidationException` | 400 | Specifically for input validation errors |
54
+
55
+ - **Global Exception Filter**: Automatically catches and transforms exceptions throughout your application.
56
+ - Centralized error handling logic
57
+ - Consistent error response format
58
+ - Easy to configure through NestJS's dependency injection
59
+
60
+ - **Exception Transformers**: Converts various error types to standardized app exceptions.
61
+ - NestJS built-in exception transformer
62
+ - TypeORM exception transformer
63
+
64
+ - **Structured Error Responses**: All exceptions follow a consistent JSON structure for frontend consumption.
65
+ - Consistent error format across your entire API
66
+ - Detailed validation error information
67
+ - Type-safe error codes for easy client-side handling
68
+
69
+ #### Usage
70
+
71
+ ##### Setup
72
+
73
+ To use the exception handling system globally in your NestJS application, you need to configure the `GlobalExceptionFilter` in your main module (e.g., `app.module.ts`):
74
+
75
+ ```typescript
76
+ import { Module } from '@nestjs/common';
77
+ import { APP_FILTER } from '@nestjs/core';
78
+ import { GlobalExceptionFilter } from '@furkanogutcu/nest-common';
79
+
80
+ @Module({
81
+ imports: [
82
+ // Your other modules
83
+ ],
84
+ controllers: [
85
+ // Your controllers
86
+ ],
87
+ providers: [
88
+ // Your other providers
89
+ {
90
+ provide: APP_FILTER,
91
+ useClass: GlobalExceptionFilter,
92
+ },
93
+ ],
94
+ })
95
+ export class AppModule {}
96
+ ```
97
+
98
+ ##### Exception Example
99
+
100
+ ```typescript
101
+ import { AppBadRequestException } from '@furkanogutcu/nest-common';
102
+
103
+ throw new AppBadRequestException({
104
+ message: 'Invalid request parameter',
105
+ code: 'BAD_REQUEST',
106
+ });
107
+ ```
108
+
109
+ ##### JSON Error Response Example
110
+
111
+ When an exception is thrown, the NestJS global exception filter can convert it to a JSON response using the `toJSON()` method. Here's an example of the JSON structure returned:
112
+
113
+ ```json
114
+ {
115
+ "error": {
116
+ "code": "invalid_request",
117
+ "message": "Invalid request parameter"
118
+ }
119
+ }
120
+ ```
121
+
122
+ For validation errors, additional details are provided:
123
+
124
+ ```json
125
+ {
126
+ "error": {
127
+ "code": "validation_failed",
128
+ "message": "Validation failed",
129
+ "details": [
130
+ {
131
+ "type": "invalid",
132
+ "path": "email",
133
+ "message": "Email must be a valid email address"
134
+ },
135
+ {
136
+ "type": "missing_field",
137
+ "path": "password",
138
+ "message": "Password is required"
139
+ }
140
+ ]
141
+ }
142
+ }
143
+ ```
144
+
145
+ The `type` field in validation error details can have the following values:
146
+
147
+ | Type Value | Description |
148
+ | ---------------- | ------------------------------------------------------------- |
149
+ | `already_exists` | When a field value already exists (e.g., duplicate email) |
150
+ | `invalid` | When a field value is not valid according to validation rules |
151
+ | `missing_field` | When a required field is missing |
152
+ | `unrecognized` | When a field is not recognized or not allowed |
153
+
154
+ ##### Additional Components
155
+
156
+ For more detailed information about the filters, transformers, and interfaces included in the exceptions package, please check the source code.
157
+
158
+ ## Development
159
+
160
+ ### Requirements
161
+
162
+ - Node.js 18+
163
+ - npm or yarn
164
+
165
+ ### Getting Started
166
+
167
+ ```bash
168
+ # Clone the repository
169
+ git clone https://github.com/furkanogutcu/nest-common.git
170
+
171
+ # Install dependencies
172
+ npm install
173
+
174
+ # Start in development mode
175
+ npm run start:dev
176
+ ```
177
+
178
+ ### Commands
179
+
180
+ - `npm run build`: Compiles the project
181
+ - `npm run format`: Formats the code
182
+ - `npm run lint`: Checks code quality
183
+ - `npm run test`: Runs tests
184
+
185
+ ## License
186
+
187
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,13 @@
1
+ import { HttpStatus } from '@nestjs/common';
2
+ import { IErrorResponse } from './interfaces/error-response.interface';
3
+ import { IValidationErrorDetails } from './interfaces/validation-error-detail.interface';
4
+ import { ExceptionCode } from './reference/exception-code.reference';
5
+ export declare class AppException extends Error {
6
+ readonly code: ExceptionCode;
7
+ readonly httpCode: HttpStatus;
8
+ readonly details?: IValidationErrorDetails[];
9
+ constructor({ message, httpCode, code, details }: IErrorResponse['error'] & {
10
+ httpCode: HttpStatus;
11
+ });
12
+ toJSON(): IErrorResponse;
13
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppException = void 0;
4
+ class AppException extends Error {
5
+ constructor({ message, httpCode, code, details }) {
6
+ super(message);
7
+ this.httpCode = httpCode;
8
+ this.code = code;
9
+ this.details = details;
10
+ }
11
+ toJSON() {
12
+ return {
13
+ error: {
14
+ code: this.code,
15
+ message: this.message,
16
+ details: this.details,
17
+ },
18
+ };
19
+ }
20
+ }
21
+ exports.AppException = AppException;
22
+ //# sourceMappingURL=app.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.exception.js","sourceRoot":"","sources":["../../src/exceptions/app.exception.ts"],"names":[],"mappings":";;;AAMA,MAAa,YAAa,SAAQ,KAAK;IAKrC,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAsD;QAClG,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,MAAM;QACJ,OAAO;YACL,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB;SACF,CAAC;IACJ,CAAC;CACF;AAtBD,oCAsBC"}
@@ -0,0 +1,8 @@
1
+ import { AppException } from './app.exception';
2
+ import { ExceptionCode } from './reference/exception-code.reference';
3
+ export declare class AppBadRequestException extends AppException {
4
+ constructor({ message, code }: {
5
+ message: string;
6
+ code: ExceptionCode;
7
+ });
8
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppBadRequestException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const app_exception_1 = require("./app.exception");
6
+ class AppBadRequestException extends app_exception_1.AppException {
7
+ constructor({ message, code }) {
8
+ super({
9
+ message,
10
+ code,
11
+ httpCode: common_1.HttpStatus.BAD_REQUEST,
12
+ });
13
+ }
14
+ }
15
+ exports.AppBadRequestException = AppBadRequestException;
16
+ //# sourceMappingURL=bad-request.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bad-request.exception.js","sourceRoot":"","sources":["../../src/exceptions/bad-request.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,mDAA+C;AAG/C,MAAa,sBAAuB,SAAQ,4BAAY;IACtD,YAAY,EAAE,OAAO,EAAE,IAAI,EAA4C;QACrE,KAAK,CAAC;YACJ,OAAO;YACP,IAAI;YACJ,QAAQ,EAAE,mBAAU,CAAC,WAAW;SACjC,CAAC,CAAC;IACL,CAAC;CACF;AARD,wDAQC"}
@@ -0,0 +1,8 @@
1
+ import { AppException } from './app.exception';
2
+ export declare class AppConflictException extends AppException {
3
+ readonly conflictedFields: string[];
4
+ constructor({ conflictedFields }: {
5
+ conflictedFields: string[];
6
+ });
7
+ private static buildDetails;
8
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppConflictException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const app_exception_1 = require("./app.exception");
6
+ const exception_code_reference_1 = require("./reference/exception-code.reference");
7
+ const validation_error_type_reference_1 = require("./reference/validation-error-type.reference");
8
+ class AppConflictException extends app_exception_1.AppException {
9
+ constructor({ conflictedFields }) {
10
+ super({
11
+ message: 'Some fields already exists.',
12
+ code: exception_code_reference_1.ExceptionCode.SomeFieldsAlreadyExists,
13
+ httpCode: common_1.HttpStatus.CONFLICT,
14
+ details: AppConflictException.buildDetails(conflictedFields),
15
+ });
16
+ this.conflictedFields = conflictedFields;
17
+ }
18
+ static buildDetails(conflictedFields) {
19
+ return conflictedFields.map((field) => {
20
+ return {
21
+ type: validation_error_type_reference_1.ValidationErrorType.AlreadyExists,
22
+ path: field,
23
+ message: `${field} already exists`,
24
+ };
25
+ });
26
+ }
27
+ }
28
+ exports.AppConflictException = AppConflictException;
29
+ //# sourceMappingURL=conflict.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conflict.exception.js","sourceRoot":"","sources":["../../src/exceptions/conflict.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,mDAA+C;AAE/C,mFAAqE;AACrE,iGAAkF;AAElF,MAAa,oBAAqB,SAAQ,4BAAY;IAGpD,YAAY,EAAE,gBAAgB,EAAkC;QAC9D,KAAK,CAAC;YACJ,OAAO,EAAE,6BAA6B;YACtC,IAAI,EAAE,wCAAa,CAAC,uBAAuB;YAC3C,QAAQ,EAAE,mBAAU,CAAC,QAAQ;YAC7B,OAAO,EAAE,oBAAoB,CAAC,YAAY,CAAC,gBAAgB,CAAC;SAC7D,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,gBAA0B;QACpD,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC,KAAK,EAA2B,EAAE;YAC7D,OAAO;gBACL,IAAI,EAAE,qDAAmB,CAAC,aAAa;gBACvC,IAAI,EAAE,KAAK;gBACX,OAAO,EAAE,GAAG,KAAK,iBAAiB;aACnC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvBD,oDAuBC"}
@@ -0,0 +1,5 @@
1
+ import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
+ export declare class GlobalExceptionFilter implements ExceptionFilter {
3
+ private readonly logger;
4
+ catch(exception: any, host: ArgumentsHost): any;
5
+ }
@@ -0,0 +1,60 @@
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 GlobalExceptionFilter_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.GlobalExceptionFilter = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const typeorm_1 = require("typeorm");
13
+ const zod_1 = require("zod");
14
+ const app_exception_1 = require("../app.exception");
15
+ const internal_exception_1 = require("../internal.exception");
16
+ const nestjs_exception_transformer_1 = require("../transformers/nestjs.exception-transformer");
17
+ const typeorm_exception_transformer_1 = require("../transformers/typeorm.exception-transformer");
18
+ const validation_exception_1 = require("../validation.exception");
19
+ let GlobalExceptionFilter = GlobalExceptionFilter_1 = class GlobalExceptionFilter {
20
+ constructor() {
21
+ this.logger = new common_1.Logger(GlobalExceptionFilter_1.name);
22
+ }
23
+ catch(exception, host) {
24
+ const ctx = host.switchToHttp();
25
+ const response = ctx.getResponse();
26
+ try {
27
+ if (exception instanceof app_exception_1.AppException) {
28
+ if (exception instanceof internal_exception_1.AppInternalException)
29
+ this.logger.error(exception);
30
+ return response.status(exception.httpCode).json(exception.toJSON());
31
+ }
32
+ let appException;
33
+ if (exception instanceof zod_1.ZodError) {
34
+ appException = new validation_exception_1.AppValidationException(exception);
35
+ }
36
+ else if (exception instanceof typeorm_1.TypeORMError) {
37
+ appException = typeorm_exception_transformer_1.TypeORMExceptionTransformer.transform(exception);
38
+ }
39
+ else if (exception instanceof common_1.HttpException) {
40
+ appException = nestjs_exception_transformer_1.NestJSExceptionTransformer.transform(exception);
41
+ }
42
+ if (!appException) {
43
+ appException = new internal_exception_1.AppInternalException({ error: exception });
44
+ }
45
+ if (appException instanceof internal_exception_1.AppInternalException)
46
+ this.logger.error(appException);
47
+ return response.status(appException.httpCode).json(appException.toJSON());
48
+ }
49
+ catch (error) {
50
+ const err = new internal_exception_1.AppInternalException({ error });
51
+ this.logger.error(err);
52
+ return response.status(err.httpCode).json(err.toJSON());
53
+ }
54
+ }
55
+ };
56
+ exports.GlobalExceptionFilter = GlobalExceptionFilter;
57
+ exports.GlobalExceptionFilter = GlobalExceptionFilter = GlobalExceptionFilter_1 = __decorate([
58
+ (0, common_1.Catch)()
59
+ ], GlobalExceptionFilter);
60
+ //# sourceMappingURL=global.exception-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.exception-filter.js","sourceRoot":"","sources":["../../../src/exceptions/filters/global.exception-filter.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA8F;AAC9F,qCAAuC;AACvC,6BAA+B;AAE/B,oDAAgD;AAChD,8DAA6D;AAC7D,+FAA0F;AAC1F,iGAA4F;AAC5F,kEAAiE;AAG1D,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAA3B;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;IAsCnE,CAAC;IApCC,KAAK,CAAC,SAAc,EAAE,IAAmB;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAEnC,IAAI,CAAC;YACH,IAAI,SAAS,YAAY,4BAAY,EAAE,CAAC;gBACtC,IAAI,SAAS,YAAY,yCAAoB;oBAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBAE5E,OAAO,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;YACtE,CAAC;YAED,IAAI,YAAsC,CAAC;YAE3C,IAAI,SAAS,YAAY,cAAQ,EAAE,CAAC;gBAClC,YAAY,GAAG,IAAI,6CAAsB,CAAC,SAAS,CAAC,CAAC;YACvD,CAAC;iBAAM,IAAI,SAAS,YAAY,sBAAY,EAAE,CAAC;gBAC7C,YAAY,GAAG,2DAA2B,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YAClE,CAAC;iBAAM,IAAI,SAAS,YAAY,sBAAa,EAAE,CAAC;gBAC9C,YAAY,GAAG,yDAA0B,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YACjE,CAAC;YAED,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,YAAY,GAAG,IAAI,yCAAoB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;YAChE,CAAC;YAED,IAAI,YAAY,YAAY,yCAAoB;gBAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAElF,OAAO,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5E,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,GAAG,GAAG,IAAI,yCAAoB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAEhD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAEvB,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF,CAAA;AAvCY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,cAAK,GAAE;GACK,qBAAqB,CAuCjC"}
@@ -0,0 +1 @@
1
+ export * from './global.exception-filter';
@@ -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("./global.exception-filter"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exceptions/filters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C"}
@@ -0,0 +1,8 @@
1
+ import { AppException } from './app.exception';
2
+ import { ExceptionCode } from './reference/exception-code.reference';
3
+ export declare class AppForbiddenException extends AppException {
4
+ constructor({ message, code, }?: {
5
+ message?: string;
6
+ code?: ExceptionCode;
7
+ });
8
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppForbiddenException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const app_exception_1 = require("./app.exception");
6
+ const exception_code_reference_1 = require("./reference/exception-code.reference");
7
+ class AppForbiddenException extends app_exception_1.AppException {
8
+ constructor({ message = 'You do not have permission to access this resource.', code = exception_code_reference_1.ExceptionCode.InsufficientPermissions, } = {}) {
9
+ super({
10
+ message,
11
+ code,
12
+ httpCode: common_1.HttpStatus.FORBIDDEN,
13
+ });
14
+ }
15
+ }
16
+ exports.AppForbiddenException = AppForbiddenException;
17
+ //# sourceMappingURL=forbidden.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forbidden.exception.js","sourceRoot":"","sources":["../../src/exceptions/forbidden.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,mDAA+C;AAC/C,mFAAqE;AAErE,MAAa,qBAAsB,SAAQ,4BAAY;IACrD,YAAY,EACV,OAAO,GAAG,qDAAqD,EAC/D,IAAI,GAAG,wCAAa,CAAC,uBAAuB,MACE,EAAE;QAChD,KAAK,CAAC;YACJ,OAAO;YACP,IAAI;YACJ,QAAQ,EAAE,mBAAU,CAAC,SAAS;SAC/B,CAAC,CAAC;IACL,CAAC;CACF;AAXD,sDAWC"}
@@ -0,0 +1,14 @@
1
+ export * from './app.exception';
2
+ export * from './bad-request.exception';
3
+ export * from './conflict.exception';
4
+ export * from './forbidden.exception';
5
+ export * from './internal.exception';
6
+ export * from './not-found.exception';
7
+ export * from './too-many-request.exception';
8
+ export * from './unauthorized.exception';
9
+ export * from './unprocessable-entity.exception';
10
+ export * from './validation.exception';
11
+ export * from './filters';
12
+ export * from './interfaces';
13
+ export * from './reference';
14
+ export * from './transformers';
@@ -0,0 +1,31 @@
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("./app.exception"), exports);
18
+ __exportStar(require("./bad-request.exception"), exports);
19
+ __exportStar(require("./conflict.exception"), exports);
20
+ __exportStar(require("./forbidden.exception"), exports);
21
+ __exportStar(require("./internal.exception"), exports);
22
+ __exportStar(require("./not-found.exception"), exports);
23
+ __exportStar(require("./too-many-request.exception"), exports);
24
+ __exportStar(require("./unauthorized.exception"), exports);
25
+ __exportStar(require("./unprocessable-entity.exception"), exports);
26
+ __exportStar(require("./validation.exception"), exports);
27
+ __exportStar(require("./filters"), exports);
28
+ __exportStar(require("./interfaces"), exports);
29
+ __exportStar(require("./reference"), exports);
30
+ __exportStar(require("./transformers"), exports);
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,kDAAgC;AAChC,0DAAwC;AACxC,uDAAqC;AACrC,wDAAsC;AACtC,uDAAqC;AACrC,wDAAsC;AACtC,+DAA6C;AAC7C,2DAAyC;AACzC,mEAAiD;AACjD,yDAAuC;AAGvC,4CAA0B;AAC1B,+CAA6B;AAC7B,8CAA4B;AAC5B,iDAA+B"}
@@ -0,0 +1,9 @@
1
+ import { ExceptionCode } from '../reference/exception-code.reference';
2
+ import { IValidationErrorDetails } from './validation-error-detail.interface';
3
+ export interface IErrorResponse {
4
+ error: {
5
+ code: ExceptionCode;
6
+ message: string;
7
+ details?: IValidationErrorDetails[];
8
+ };
9
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=error-response.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-response.interface.js","sourceRoot":"","sources":["../../../src/exceptions/interfaces/error-response.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from './error-response.interface';
2
+ export * from './validation-error-detail.interface';
@@ -0,0 +1,19 @@
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("./error-response.interface"), exports);
18
+ __exportStar(require("./validation-error-detail.interface"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exceptions/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,sEAAoD"}
@@ -0,0 +1,6 @@
1
+ import { ValidationErrorType } from '../reference/validation-error-type.reference';
2
+ export interface IValidationErrorDetails {
3
+ type: ValidationErrorType;
4
+ path: string;
5
+ message: string;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=validation-error-detail.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation-error-detail.interface.js","sourceRoot":"","sources":["../../../src/exceptions/interfaces/validation-error-detail.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { AppException } from './app.exception';
2
+ import { ExceptionCode } from './reference/exception-code.reference';
3
+ export declare class AppInternalException extends AppException {
4
+ readonly originalError?: Error;
5
+ constructor({ message, code, error, }?: {
6
+ message?: string;
7
+ code?: ExceptionCode;
8
+ error?: Error;
9
+ });
10
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppInternalException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const app_exception_1 = require("./app.exception");
6
+ const exception_code_reference_1 = require("./reference/exception-code.reference");
7
+ class AppInternalException extends app_exception_1.AppException {
8
+ constructor({ message = 'An unexpected error occurred.', code, error, } = {}) {
9
+ super({
10
+ message,
11
+ code: code || exception_code_reference_1.ExceptionCode.UnexpectedError,
12
+ httpCode: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
13
+ });
14
+ this.originalError = error;
15
+ }
16
+ }
17
+ exports.AppInternalException = AppInternalException;
18
+ //# sourceMappingURL=internal.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.exception.js","sourceRoot":"","sources":["../../src/exceptions/internal.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,mDAA+C;AAC/C,mFAAqE;AAErE,MAAa,oBAAqB,SAAQ,4BAAY;IAGpD,YAAY,EACV,OAAO,GAAG,+BAA+B,EACzC,IAAI,EACJ,KAAK,MACwD,EAAE;QAC/D,KAAK,CAAC;YACJ,OAAO;YACP,IAAI,EAAE,IAAI,IAAI,wCAAa,CAAC,eAAe;YAC3C,QAAQ,EAAE,mBAAU,CAAC,qBAAqB;SAC3C,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;IAC7B,CAAC;CACF;AAhBD,oDAgBC"}
@@ -0,0 +1,8 @@
1
+ import { AppException } from './app.exception';
2
+ export declare class AppNotFoundException extends AppException {
3
+ readonly resourceName: string;
4
+ constructor({ resourceName, message }?: {
5
+ resourceName?: string;
6
+ message?: string;
7
+ });
8
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppNotFoundException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const app_exception_1 = require("./app.exception");
6
+ const exception_code_reference_1 = require("./reference/exception-code.reference");
7
+ class AppNotFoundException extends app_exception_1.AppException {
8
+ constructor({ resourceName = 'Resource', message } = {}) {
9
+ super({
10
+ message: message || `${resourceName} not found.`,
11
+ code: exception_code_reference_1.ExceptionCode.ResourceNotFound,
12
+ httpCode: common_1.HttpStatus.NOT_FOUND,
13
+ });
14
+ this.resourceName = resourceName;
15
+ }
16
+ }
17
+ exports.AppNotFoundException = AppNotFoundException;
18
+ //# sourceMappingURL=not-found.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-found.exception.js","sourceRoot":"","sources":["../../src/exceptions/not-found.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,mDAA+C;AAC/C,mFAAqE;AAErE,MAAa,oBAAqB,SAAQ,4BAAY;IAGpD,YAAY,EAAE,YAAY,GAAG,UAAU,EAAE,OAAO,KAAkD,EAAE;QAClG,KAAK,CAAC;YACJ,OAAO,EAAE,OAAO,IAAI,GAAG,YAAY,aAAa;YAChD,IAAI,EAAE,wCAAa,CAAC,gBAAgB;YACpC,QAAQ,EAAE,mBAAU,CAAC,SAAS;SAC/B,CAAC,CAAC;QAEH,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AAZD,oDAYC"}