@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.
- package/LICENSE +21 -0
- package/README.md +187 -0
- package/dist/exceptions/app.exception.d.ts +13 -0
- package/dist/exceptions/app.exception.js +22 -0
- package/dist/exceptions/app.exception.js.map +1 -0
- package/dist/exceptions/bad-request.exception.d.ts +8 -0
- package/dist/exceptions/bad-request.exception.js +16 -0
- package/dist/exceptions/bad-request.exception.js.map +1 -0
- package/dist/exceptions/conflict.exception.d.ts +8 -0
- package/dist/exceptions/conflict.exception.js +29 -0
- package/dist/exceptions/conflict.exception.js.map +1 -0
- package/dist/exceptions/filters/global.exception-filter.d.ts +5 -0
- package/dist/exceptions/filters/global.exception-filter.js +60 -0
- package/dist/exceptions/filters/global.exception-filter.js.map +1 -0
- package/dist/exceptions/filters/index.d.ts +1 -0
- package/dist/exceptions/filters/index.js +18 -0
- package/dist/exceptions/filters/index.js.map +1 -0
- package/dist/exceptions/forbidden.exception.d.ts +8 -0
- package/dist/exceptions/forbidden.exception.js +17 -0
- package/dist/exceptions/forbidden.exception.js.map +1 -0
- package/dist/exceptions/index.d.ts +14 -0
- package/dist/exceptions/index.js +31 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/exceptions/interfaces/error-response.interface.d.ts +9 -0
- package/dist/exceptions/interfaces/error-response.interface.js +3 -0
- package/dist/exceptions/interfaces/error-response.interface.js.map +1 -0
- package/dist/exceptions/interfaces/index.d.ts +2 -0
- package/dist/exceptions/interfaces/index.js +19 -0
- package/dist/exceptions/interfaces/index.js.map +1 -0
- package/dist/exceptions/interfaces/validation-error-detail.interface.d.ts +6 -0
- package/dist/exceptions/interfaces/validation-error-detail.interface.js +3 -0
- package/dist/exceptions/interfaces/validation-error-detail.interface.js.map +1 -0
- package/dist/exceptions/internal.exception.d.ts +10 -0
- package/dist/exceptions/internal.exception.js +18 -0
- package/dist/exceptions/internal.exception.js.map +1 -0
- package/dist/exceptions/not-found.exception.d.ts +8 -0
- package/dist/exceptions/not-found.exception.js +18 -0
- package/dist/exceptions/not-found.exception.js.map +1 -0
- package/dist/exceptions/reference/exception-code.reference.d.ts +25 -0
- package/dist/exceptions/reference/exception-code.reference.js +30 -0
- package/dist/exceptions/reference/exception-code.reference.js.map +1 -0
- package/dist/exceptions/reference/index.d.ts +2 -0
- package/dist/exceptions/reference/index.js +19 -0
- package/dist/exceptions/reference/index.js.map +1 -0
- package/dist/exceptions/reference/validation-error-type.reference.d.ts +6 -0
- package/dist/exceptions/reference/validation-error-type.reference.js +11 -0
- package/dist/exceptions/reference/validation-error-type.reference.js.map +1 -0
- package/dist/exceptions/too-many-request.exception.d.ts +4 -0
- package/dist/exceptions/too-many-request.exception.js +17 -0
- package/dist/exceptions/too-many-request.exception.js.map +1 -0
- package/dist/exceptions/transformers/index.d.ts +2 -0
- package/dist/exceptions/transformers/index.js +19 -0
- package/dist/exceptions/transformers/index.js.map +1 -0
- package/dist/exceptions/transformers/nestjs.exception-transformer.d.ts +5 -0
- package/dist/exceptions/transformers/nestjs.exception-transformer.js +33 -0
- package/dist/exceptions/transformers/nestjs.exception-transformer.js.map +1 -0
- package/dist/exceptions/transformers/typeorm.exception-transformer.d.ts +12 -0
- package/dist/exceptions/transformers/typeorm.exception-transformer.js +54 -0
- package/dist/exceptions/transformers/typeorm.exception-transformer.js.map +1 -0
- package/dist/exceptions/unauthorized.exception.d.ts +8 -0
- package/dist/exceptions/unauthorized.exception.js +17 -0
- package/dist/exceptions/unauthorized.exception.js.map +1 -0
- package/dist/exceptions/unprocessable-entity.exception.d.ts +8 -0
- package/dist/exceptions/unprocessable-entity.exception.js +17 -0
- package/dist/exceptions/unprocessable-entity.exception.js.map +1 -0
- package/dist/exceptions/validation.exception.d.ts +8 -0
- package/dist/exceptions/validation.exception.js +54 -0
- package/dist/exceptions/validation.exception.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/package.json +103 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
export declare enum ExceptionCode {
|
2
|
+
InvalidRequest = "invalid_request",
|
3
|
+
SomeFieldsAlreadyExists = "some_fields_already_exists",
|
4
|
+
InsufficientPermissions = "insufficient_permissions",
|
5
|
+
UnexpectedError = "unexpected_error",
|
6
|
+
ResourceNotFound = "resource_not_found",
|
7
|
+
RateLimit = "rate_limit",
|
8
|
+
Unauthorized = "unauthorized",
|
9
|
+
UnprocessableEntity = "unprocessable_entity",
|
10
|
+
ValidationFailed = "validation_failed",
|
11
|
+
IncorrectCredentials = "incorrect_credentials",
|
12
|
+
InactiveUser = "inactive_user",
|
13
|
+
InvalidToken = "invalid_token",
|
14
|
+
TokenInvalidOrActivityResolved = "token_invalid_or_activity_resolved",
|
15
|
+
ResolveTokenRequired = "resolve_token_required",
|
16
|
+
TokenExpired = "token_expired",
|
17
|
+
WrongMFACode = "wrong_mfa_code",
|
18
|
+
MFARequired = "mfa_required",
|
19
|
+
MFAAlreadyCompleted = "mfa_already_completed",
|
20
|
+
SuspiciousSession = "suspicious_session",
|
21
|
+
GoogleAuthFailed = "google_auth_failed",
|
22
|
+
GoogleAuthInvalidTokenPayload = "google_auth_invalid_token_payload",
|
23
|
+
GoogleAuthRequiresVerifiedEmail = "google_auth_requires_verified_email",
|
24
|
+
GoogleAuthMismatch = "google_auth_mismatch"
|
25
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ExceptionCode = void 0;
|
4
|
+
var ExceptionCode;
|
5
|
+
(function (ExceptionCode) {
|
6
|
+
ExceptionCode["InvalidRequest"] = "invalid_request";
|
7
|
+
ExceptionCode["SomeFieldsAlreadyExists"] = "some_fields_already_exists";
|
8
|
+
ExceptionCode["InsufficientPermissions"] = "insufficient_permissions";
|
9
|
+
ExceptionCode["UnexpectedError"] = "unexpected_error";
|
10
|
+
ExceptionCode["ResourceNotFound"] = "resource_not_found";
|
11
|
+
ExceptionCode["RateLimit"] = "rate_limit";
|
12
|
+
ExceptionCode["Unauthorized"] = "unauthorized";
|
13
|
+
ExceptionCode["UnprocessableEntity"] = "unprocessable_entity";
|
14
|
+
ExceptionCode["ValidationFailed"] = "validation_failed";
|
15
|
+
ExceptionCode["IncorrectCredentials"] = "incorrect_credentials";
|
16
|
+
ExceptionCode["InactiveUser"] = "inactive_user";
|
17
|
+
ExceptionCode["InvalidToken"] = "invalid_token";
|
18
|
+
ExceptionCode["TokenInvalidOrActivityResolved"] = "token_invalid_or_activity_resolved";
|
19
|
+
ExceptionCode["ResolveTokenRequired"] = "resolve_token_required";
|
20
|
+
ExceptionCode["TokenExpired"] = "token_expired";
|
21
|
+
ExceptionCode["WrongMFACode"] = "wrong_mfa_code";
|
22
|
+
ExceptionCode["MFARequired"] = "mfa_required";
|
23
|
+
ExceptionCode["MFAAlreadyCompleted"] = "mfa_already_completed";
|
24
|
+
ExceptionCode["SuspiciousSession"] = "suspicious_session";
|
25
|
+
ExceptionCode["GoogleAuthFailed"] = "google_auth_failed";
|
26
|
+
ExceptionCode["GoogleAuthInvalidTokenPayload"] = "google_auth_invalid_token_payload";
|
27
|
+
ExceptionCode["GoogleAuthRequiresVerifiedEmail"] = "google_auth_requires_verified_email";
|
28
|
+
ExceptionCode["GoogleAuthMismatch"] = "google_auth_mismatch";
|
29
|
+
})(ExceptionCode || (exports.ExceptionCode = ExceptionCode = {}));
|
30
|
+
//# sourceMappingURL=exception-code.reference.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"exception-code.reference.js","sourceRoot":"","sources":["../../../src/exceptions/reference/exception-code.reference.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAwBX;AAxBD,WAAY,aAAa;IACvB,mDAAkC,CAAA;IAClC,uEAAsD,CAAA;IACtD,qEAAoD,CAAA;IACpD,qDAAoC,CAAA;IACpC,wDAAuC,CAAA;IACvC,yCAAwB,CAAA;IACxB,8CAA6B,CAAA;IAC7B,6DAA4C,CAAA;IAC5C,uDAAsC,CAAA;IACtC,+DAA8C,CAAA;IAC9C,+CAA8B,CAAA;IAC9B,+CAA8B,CAAA;IAC9B,sFAAqE,CAAA;IACrE,gEAA+C,CAAA;IAC/C,+CAA8B,CAAA;IAC9B,gDAA+B,CAAA;IAC/B,6CAA4B,CAAA;IAC5B,8DAA6C,CAAA;IAC7C,yDAAwC,CAAA;IACxC,wDAAuC,CAAA;IACvC,oFAAmE,CAAA;IACnE,wFAAuE,CAAA;IACvE,4DAA2C,CAAA;AAC7C,CAAC,EAxBW,aAAa,6BAAb,aAAa,QAwBxB"}
|
@@ -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("./exception-code.reference"), exports);
|
18
|
+
__exportStar(require("./validation-error-type.reference"), exports);
|
19
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exceptions/reference/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,oEAAkD"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ValidationErrorType = void 0;
|
4
|
+
var ValidationErrorType;
|
5
|
+
(function (ValidationErrorType) {
|
6
|
+
ValidationErrorType["AlreadyExists"] = "already_exists";
|
7
|
+
ValidationErrorType["Invalid"] = "invalid";
|
8
|
+
ValidationErrorType["MissingField"] = "missing_field";
|
9
|
+
ValidationErrorType["Unrecognized"] = "unrecognized";
|
10
|
+
})(ValidationErrorType || (exports.ValidationErrorType = ValidationErrorType = {}));
|
11
|
+
//# sourceMappingURL=validation-error-type.reference.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"validation-error-type.reference.js","sourceRoot":"","sources":["../../../src/exceptions/reference/validation-error-type.reference.ts"],"names":[],"mappings":";;;AAAA,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC7B,uDAAgC,CAAA;IAChC,0CAAmB,CAAA;IACnB,qDAA8B,CAAA;IAC9B,oDAA6B,CAAA;AAC/B,CAAC,EALW,mBAAmB,mCAAnB,mBAAmB,QAK9B"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AppTooManyRequestException = 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 AppTooManyRequestException extends app_exception_1.AppException {
|
8
|
+
constructor() {
|
9
|
+
super({
|
10
|
+
message: 'You have exceeded the number of allowed requests. Please try again later.',
|
11
|
+
code: exception_code_reference_1.ExceptionCode.RateLimit,
|
12
|
+
httpCode: common_1.HttpStatus.TOO_MANY_REQUESTS,
|
13
|
+
});
|
14
|
+
}
|
15
|
+
}
|
16
|
+
exports.AppTooManyRequestException = AppTooManyRequestException;
|
17
|
+
//# sourceMappingURL=too-many-request.exception.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"too-many-request.exception.js","sourceRoot":"","sources":["../../src/exceptions/too-many-request.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,mDAA+C;AAC/C,mFAAqE;AAErE,MAAa,0BAA2B,SAAQ,4BAAY;IAC1D;QACE,KAAK,CAAC;YACJ,OAAO,EAAE,2EAA2E;YACpF,IAAI,EAAE,wCAAa,CAAC,SAAS;YAC7B,QAAQ,EAAE,mBAAU,CAAC,iBAAiB;SACvC,CAAC,CAAC;IACL,CAAC;CACF;AARD,gEAQC"}
|
@@ -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("./nestjs.exception-transformer"), exports);
|
18
|
+
__exportStar(require("./typeorm.exception-transformer"), exports);
|
19
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exceptions/transformers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C;AAC/C,kEAAgD"}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.NestJSExceptionTransformer = void 0;
|
4
|
+
const common_1 = require("@nestjs/common");
|
5
|
+
const bad_request_exception_1 = require("../bad-request.exception");
|
6
|
+
const forbidden_exception_1 = require("../forbidden.exception");
|
7
|
+
const not_found_exception_1 = require("../not-found.exception");
|
8
|
+
const exception_code_reference_1 = require("../reference/exception-code.reference");
|
9
|
+
const unauthorized_exception_1 = require("../unauthorized.exception");
|
10
|
+
const unprocessable_entity_exception_1 = require("../unprocessable-entity.exception");
|
11
|
+
class NestJSExceptionTransformer {
|
12
|
+
static transform(exception) {
|
13
|
+
if (exception instanceof common_1.BadRequestException) {
|
14
|
+
return new bad_request_exception_1.AppBadRequestException({ message: exception.message, code: exception_code_reference_1.ExceptionCode.InvalidRequest });
|
15
|
+
}
|
16
|
+
if (exception instanceof common_1.ForbiddenException) {
|
17
|
+
return new forbidden_exception_1.AppForbiddenException({ message: exception.message });
|
18
|
+
}
|
19
|
+
if (exception instanceof common_1.NotFoundException) {
|
20
|
+
return new not_found_exception_1.AppNotFoundException({ message: exception.message });
|
21
|
+
}
|
22
|
+
if (exception instanceof common_1.UnauthorizedException) {
|
23
|
+
return new unauthorized_exception_1.AppUnauthorizedException({ message: exception.message });
|
24
|
+
}
|
25
|
+
if (exception instanceof common_1.UnprocessableEntityException) {
|
26
|
+
return new unprocessable_entity_exception_1.AppUnprocessableEntityException({
|
27
|
+
message: exception.message,
|
28
|
+
});
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
exports.NestJSExceptionTransformer = NestJSExceptionTransformer;
|
33
|
+
//# sourceMappingURL=nestjs.exception-transformer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"nestjs.exception-transformer.js","sourceRoot":"","sources":["../../../src/exceptions/transformers/nestjs.exception-transformer.ts"],"names":[],"mappings":";;;AAAA,2CAOwB;AAGxB,oEAAkE;AAClE,gEAA+D;AAC/D,gEAA8D;AAC9D,oFAAsE;AACtE,sEAAqE;AACrE,sFAAoF;AAEpF,MAAa,0BAA0B;IACrC,MAAM,CAAC,SAAS,CAAC,SAAwB;QACvC,IAAI,SAAS,YAAY,4BAAmB,EAAE,CAAC;YAC7C,OAAO,IAAI,8CAAsB,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,wCAAa,CAAC,cAAc,EAAE,CAAC,CAAC;QACxG,CAAC;QAED,IAAI,SAAS,YAAY,2BAAkB,EAAE,CAAC;YAC5C,OAAO,IAAI,2CAAqB,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,SAAS,YAAY,0BAAiB,EAAE,CAAC;YAC3C,OAAO,IAAI,0CAAoB,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,SAAS,YAAY,8BAAqB,EAAE,CAAC;YAC/C,OAAO,IAAI,iDAAwB,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,SAAS,YAAY,qCAA4B,EAAE,CAAC;YACtD,OAAO,IAAI,gEAA+B,CAAC;gBACzC,OAAO,EAAE,SAAS,CAAC,OAAO;aAC3B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAxBD,gEAwBC"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { TypeORMError } from 'typeorm';
|
2
|
+
import { AppException } from '../app.exception';
|
3
|
+
export declare class TypeORMExceptionTransformer {
|
4
|
+
private static joinColumnKeyValues;
|
5
|
+
static setJoinColumnKeyValues(values: string[]): void;
|
6
|
+
static getJoinColumnKeyValues(): string[];
|
7
|
+
static transform(exception: TypeORMError): AppException | undefined;
|
8
|
+
private static postgresQueryFailedExceptionMapper;
|
9
|
+
private static transformEntityNotFoundError;
|
10
|
+
private static transformConflictError;
|
11
|
+
private static transformNumericOverflowError;
|
12
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TypeORMExceptionTransformer = void 0;
|
4
|
+
const typeorm_1 = require("typeorm");
|
5
|
+
const conflict_exception_1 = require("../conflict.exception");
|
6
|
+
const not_found_exception_1 = require("../not-found.exception");
|
7
|
+
const unprocessable_entity_exception_1 = require("../unprocessable-entity.exception");
|
8
|
+
class TypeORMExceptionTransformer {
|
9
|
+
static setJoinColumnKeyValues(values) {
|
10
|
+
this.joinColumnKeyValues = values;
|
11
|
+
}
|
12
|
+
static getJoinColumnKeyValues() {
|
13
|
+
return this.joinColumnKeyValues;
|
14
|
+
}
|
15
|
+
static transform(exception) {
|
16
|
+
if (exception instanceof typeorm_1.EntityNotFoundError) {
|
17
|
+
return this.transformEntityNotFoundError(exception);
|
18
|
+
}
|
19
|
+
if (exception instanceof typeorm_1.QueryFailedError) {
|
20
|
+
const exceptionCode = exception.code;
|
21
|
+
const transformer = TypeORMExceptionTransformer.postgresQueryFailedExceptionMapper[+exceptionCode];
|
22
|
+
if (transformer)
|
23
|
+
return transformer(exception);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
static transformEntityNotFoundError(exception) {
|
27
|
+
const match = exception.message.match(/"([^"]+)"/);
|
28
|
+
return new not_found_exception_1.AppNotFoundException({ resourceName: match?.[1] });
|
29
|
+
}
|
30
|
+
static transformConflictError(exception) {
|
31
|
+
const detail = exception?.detail;
|
32
|
+
if (!detail)
|
33
|
+
return;
|
34
|
+
const matches = detail.match(/\(([^)]+)\)/);
|
35
|
+
let conflictedFields = [];
|
36
|
+
if (matches && matches[1]) {
|
37
|
+
const keys = matches[1].split(', ').map((key) => key.trim());
|
38
|
+
conflictedFields = keys.filter((key) => !TypeORMExceptionTransformer.joinColumnKeyValues.includes(key));
|
39
|
+
}
|
40
|
+
return new conflict_exception_1.AppConflictException({ conflictedFields });
|
41
|
+
}
|
42
|
+
static transformNumericOverflowError(_exception) {
|
43
|
+
return new unprocessable_entity_exception_1.AppUnprocessableEntityException({
|
44
|
+
message: 'Numeric field is outside the allowed range',
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|
48
|
+
exports.TypeORMExceptionTransformer = TypeORMExceptionTransformer;
|
49
|
+
TypeORMExceptionTransformer.joinColumnKeyValues = [];
|
50
|
+
TypeORMExceptionTransformer.postgresQueryFailedExceptionMapper = {
|
51
|
+
22003: TypeORMExceptionTransformer.transformNumericOverflowError,
|
52
|
+
23505: TypeORMExceptionTransformer.transformConflictError,
|
53
|
+
};
|
54
|
+
//# sourceMappingURL=typeorm.exception-transformer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"typeorm.exception-transformer.js","sourceRoot":"","sources":["../../../src/exceptions/transformers/typeorm.exception-transformer.ts"],"names":[],"mappings":";;;AAAA,qCAA8E;AAG9E,8DAA6D;AAC7D,gEAA8D;AAC9D,sFAAoF;AAEpF,MAAa,2BAA2B;IAGtC,MAAM,CAAC,sBAAsB,CAAC,MAAgB;QAC5C,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,sBAAsB;QAC3B,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,SAAuB;QACtC,IAAI,SAAS,YAAY,6BAAmB,EAAE,CAAC;YAC7C,OAAO,IAAI,CAAC,4BAA4B,CAAC,SAAS,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,SAAS,YAAY,0BAAgB,EAAE,CAAC;YAC1C,MAAM,aAAa,GAAI,SAAiB,CAAC,IAAI,CAAC;YAE9C,MAAM,WAAW,GAAG,2BAA2B,CAAC,kCAAkC,CAAC,CAAC,aAAa,CAAC,CAAC;YAEnG,IAAI,WAAW;gBAAE,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAWO,MAAM,CAAC,4BAA4B,CAAC,SAA8B;QACxE,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAEnD,OAAO,IAAI,0CAAoB,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;IAEO,MAAM,CAAC,sBAAsB,CAAC,SAA2B;QAC/D,MAAM,MAAM,GAAwB,SAAiB,EAAE,MAAM,CAAC;QAE9D,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAE5C,IAAI,gBAAgB,GAAa,EAAE,CAAC;QAEpC,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YAErE,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,2BAA2B,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/G,CAAC;QAED,OAAO,IAAI,yCAAoB,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACxD,CAAC;IAEO,MAAM,CAAC,6BAA6B,CAAC,UAA4B;QACvE,OAAO,IAAI,gEAA+B,CAAC;YACzC,OAAO,EAAE,4CAA4C;SACtD,CAAC,CAAC;IACL,CAAC;;AA9DH,kEA+DC;AA9DgB,+CAAmB,GAAa,EAAE,CAAC;AAwBnC,8DAAkC,GAG7C;IAEF,KAAK,EAAE,2BAA2B,CAAC,6BAA6B;IAChE,KAAK,EAAE,2BAA2B,CAAC,sBAAsB;CAC1D,CAAC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { AppException } from './app.exception';
|
2
|
+
import { ExceptionCode } from './reference/exception-code.reference';
|
3
|
+
export declare class AppUnauthorizedException 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.AppUnauthorizedException = 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 AppUnauthorizedException extends app_exception_1.AppException {
|
8
|
+
constructor({ message = 'Access denied.', code } = {}) {
|
9
|
+
super({
|
10
|
+
message,
|
11
|
+
code: code || exception_code_reference_1.ExceptionCode.Unauthorized,
|
12
|
+
httpCode: common_1.HttpStatus.UNAUTHORIZED,
|
13
|
+
});
|
14
|
+
}
|
15
|
+
}
|
16
|
+
exports.AppUnauthorizedException = AppUnauthorizedException;
|
17
|
+
//# sourceMappingURL=unauthorized.exception.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"unauthorized.exception.js","sourceRoot":"","sources":["../../src/exceptions/unauthorized.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,mDAA+C;AAC/C,mFAAqE;AAErE,MAAa,wBAAyB,SAAQ,4BAAY;IACxD,YAAY,EAAE,OAAO,GAAG,gBAAgB,EAAE,IAAI,KAAiD,EAAE;QAC/F,KAAK,CAAC;YACJ,OAAO;YACP,IAAI,EAAE,IAAI,IAAI,wCAAa,CAAC,YAAY;YACxC,QAAQ,EAAE,mBAAU,CAAC,YAAY;SAClC,CAAC,CAAC;IACL,CAAC;CACF;AARD,4DAQC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { AppException } from './app.exception';
|
2
|
+
import { ExceptionCode } from './reference/exception-code.reference';
|
3
|
+
export declare class AppUnprocessableEntityException 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.AppUnprocessableEntityException = 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 AppUnprocessableEntityException extends app_exception_1.AppException {
|
8
|
+
constructor({ message, code }) {
|
9
|
+
super({
|
10
|
+
message,
|
11
|
+
code: code || exception_code_reference_1.ExceptionCode.UnprocessableEntity,
|
12
|
+
httpCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
|
13
|
+
});
|
14
|
+
}
|
15
|
+
}
|
16
|
+
exports.AppUnprocessableEntityException = AppUnprocessableEntityException;
|
17
|
+
//# sourceMappingURL=unprocessable-entity.exception.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"unprocessable-entity.exception.js","sourceRoot":"","sources":["../../src/exceptions/unprocessable-entity.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,mDAA+C;AAC/C,mFAAqE;AAErE,MAAa,+BAAgC,SAAQ,4BAAY;IAC/D,YAAY,EAAE,OAAO,EAAE,IAAI,EAA6C;QACtE,KAAK,CAAC;YACJ,OAAO;YACP,IAAI,EAAE,IAAI,IAAI,wCAAa,CAAC,mBAAmB;YAC/C,QAAQ,EAAE,mBAAU,CAAC,oBAAoB;SAC1C,CAAC,CAAC;IACL,CAAC;CACF;AARD,0EAQC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { ZodError } from 'zod';
|
2
|
+
import { AppException } from './app.exception';
|
3
|
+
export declare class AppValidationException extends AppException {
|
4
|
+
readonly zodError: ZodError;
|
5
|
+
constructor(error: ZodError);
|
6
|
+
private static buildDetails;
|
7
|
+
private static detectDetailType;
|
8
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AppValidationException = void 0;
|
4
|
+
const common_1 = require("@nestjs/common");
|
5
|
+
const zod_1 = require("zod");
|
6
|
+
const app_exception_1 = require("./app.exception");
|
7
|
+
const exception_code_reference_1 = require("./reference/exception-code.reference");
|
8
|
+
const validation_error_type_reference_1 = require("./reference/validation-error-type.reference");
|
9
|
+
class AppValidationException extends app_exception_1.AppException {
|
10
|
+
constructor(error) {
|
11
|
+
super({
|
12
|
+
code: exception_code_reference_1.ExceptionCode.ValidationFailed,
|
13
|
+
httpCode: common_1.HttpStatus.BAD_REQUEST,
|
14
|
+
message: 'Invalid request payload.',
|
15
|
+
details: AppValidationException.buildDetails(error),
|
16
|
+
});
|
17
|
+
this.zodError = error;
|
18
|
+
}
|
19
|
+
static buildDetails(zodError) {
|
20
|
+
return zodError.errors.flatMap((error) => {
|
21
|
+
const type = this.detectDetailType(error);
|
22
|
+
const paths = error.path.map((item) => item.toString());
|
23
|
+
if (error.code === zod_1.ZodIssueCode.unrecognized_keys) {
|
24
|
+
return error.keys.map((key) => ({
|
25
|
+
type: validation_error_type_reference_1.ValidationErrorType.Unrecognized,
|
26
|
+
path: [...paths, key].join('.'),
|
27
|
+
message: 'This key is not recognized',
|
28
|
+
}));
|
29
|
+
}
|
30
|
+
return [
|
31
|
+
{
|
32
|
+
type,
|
33
|
+
path: paths.join('.'),
|
34
|
+
message: error.message,
|
35
|
+
},
|
36
|
+
];
|
37
|
+
});
|
38
|
+
}
|
39
|
+
static detectDetailType(error) {
|
40
|
+
switch (error.code) {
|
41
|
+
case zod_1.ZodIssueCode.invalid_type: {
|
42
|
+
if (error.received === 'undefined')
|
43
|
+
return validation_error_type_reference_1.ValidationErrorType.MissingField;
|
44
|
+
return validation_error_type_reference_1.ValidationErrorType.Invalid;
|
45
|
+
}
|
46
|
+
case zod_1.ZodIssueCode.unrecognized_keys:
|
47
|
+
return validation_error_type_reference_1.ValidationErrorType.Unrecognized;
|
48
|
+
default:
|
49
|
+
return validation_error_type_reference_1.ValidationErrorType.Invalid;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
exports.AppValidationException = AppValidationException;
|
54
|
+
//# sourceMappingURL=validation.exception.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"validation.exception.js","sourceRoot":"","sources":["../../src/exceptions/validation.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAC5C,6BAAuD;AAEvD,mDAA+C;AAE/C,mFAAqE;AACrE,iGAAkF;AAElF,MAAa,sBAAuB,SAAQ,4BAAY;IAGtD,YAAY,KAAe;QACzB,KAAK,CAAC;YACJ,IAAI,EAAE,wCAAa,CAAC,gBAAgB;YACpC,QAAQ,EAAE,mBAAU,CAAC,WAAW;YAChC,OAAO,EAAE,0BAA0B;YACnC,OAAO,EAAE,sBAAsB,CAAC,YAAY,CAAC,KAAK,CAAC;SACpD,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,QAAkB;QAC5C,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAA6B,EAAE;YAClE,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;YAE1C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YAExD,IAAI,KAAK,CAAC,IAAI,KAAK,kBAAY,CAAC,iBAAiB,EAAE,CAAC;gBAClD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;oBAC9B,IAAI,EAAE,qDAAmB,CAAC,YAAY;oBACtC,IAAI,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;oBAC/B,OAAO,EAAE,4BAA4B;iBACtC,CAAC,CAAC,CAAC;YACN,CAAC;YAED,OAAO;gBACL;oBACE,IAAI;oBACJ,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;oBACrB,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,gBAAgB,CAAC,KAAe;QAC7C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,kBAAY,CAAC,YAAY,CAAC,CAAC,CAAC;gBAC/B,IAAI,KAAK,CAAC,QAAQ,KAAK,WAAW;oBAAE,OAAO,qDAAmB,CAAC,YAAY,CAAC;gBAE5E,OAAO,qDAAmB,CAAC,OAAO,CAAC;YACrC,CAAC;YAED,KAAK,kBAAY,CAAC,iBAAiB;gBACjC,OAAO,qDAAmB,CAAC,YAAY,CAAC;YAE1C;gBACE,OAAO,qDAAmB,CAAC,OAAO,CAAC;QACvC,CAAC;IACH,CAAC;CACF;AArDD,wDAqDC"}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './exceptions';
|
package/dist/index.js
ADDED
@@ -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("./exceptions"), exports);
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
|
package/package.json
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
{
|
2
|
+
"name": "@furkanogutcu/nest-common",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "Package of common structures for NestJS.",
|
5
|
+
"author": "Furkan Ogutcu",
|
6
|
+
"license": "MIT",
|
7
|
+
"readme": "README.md",
|
8
|
+
"main": "dist/index.js",
|
9
|
+
"types": "dist/index.d.ts",
|
10
|
+
"files": [
|
11
|
+
"dist/**/*",
|
12
|
+
"docs/**/**",
|
13
|
+
"!**/*.spec.*",
|
14
|
+
"!**/*.json",
|
15
|
+
"!**/*.tsbuildinfo",
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
],
|
19
|
+
"scripts": {
|
20
|
+
"start:dev": "tsc -w",
|
21
|
+
"build": "tsc",
|
22
|
+
"build:check": "tsc --noEmit -p tsconfig.json",
|
23
|
+
"prepublishOnly": "npm run build",
|
24
|
+
"prepare": "npm run build",
|
25
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
26
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
|
27
|
+
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
28
|
+
"test": "jest",
|
29
|
+
"test:watch": "jest --watch",
|
30
|
+
"test:cov": "jest --coverage",
|
31
|
+
"test:e2e": "jest --config ./test/jest-e2e.json"
|
32
|
+
},
|
33
|
+
"keywords": [
|
34
|
+
"nestjs"
|
35
|
+
],
|
36
|
+
"publishConfig": {
|
37
|
+
"access": "public"
|
38
|
+
},
|
39
|
+
"repository": {
|
40
|
+
"type": "git",
|
41
|
+
"url": "git+https://github.com/furkanogutcu/nest-common.git"
|
42
|
+
},
|
43
|
+
"bugs": {
|
44
|
+
"url": "https://github.com/furkanogutcu/nest-common/issues"
|
45
|
+
},
|
46
|
+
"homepage": "https://github.com/furkanogutcu/nest-common#readme",
|
47
|
+
"peerDependencies": {
|
48
|
+
"@nestjs/common": "^11.1.0",
|
49
|
+
"@nestjs/core": "^11.1.0",
|
50
|
+
"@nestjs/typeorm": "^11.0.0",
|
51
|
+
"@nestjs/testing": "11.1.0",
|
52
|
+
"@nestjs/platform-express": "^11.1.0"
|
53
|
+
},
|
54
|
+
"dependencies": {
|
55
|
+
"zod": "^3.24.3",
|
56
|
+
"typeorm": "^0.3.22"
|
57
|
+
},
|
58
|
+
"devDependencies": {
|
59
|
+
"@nestjs/common": "^11.1.0",
|
60
|
+
"@nestjs/core": "^11.1.0",
|
61
|
+
"@nestjs/typeorm": "^11.0.0",
|
62
|
+
"@nestjs/testing": "11.1.0",
|
63
|
+
"@nestjs/platform-express": "^11.1.0",
|
64
|
+
"@types/express": "5.0.1",
|
65
|
+
"@types/jest": "29.5.14",
|
66
|
+
"@types/node": "22.15.3",
|
67
|
+
"@types/supertest": "6.0.3",
|
68
|
+
"jest": "29.7.0",
|
69
|
+
"prettier": "3.5.3",
|
70
|
+
"supertest": "7.1.0",
|
71
|
+
"ts-jest": "29.3.2",
|
72
|
+
"ts-node": "10.9.2",
|
73
|
+
"tsc-watch": "6.2.1",
|
74
|
+
"tsconfig-paths": "4.2.0",
|
75
|
+
"typescript": "5.8.3",
|
76
|
+
"@eslint/eslintrc": "^3.3.1",
|
77
|
+
"@eslint/js": "^9.25.1",
|
78
|
+
"@swc/cli": "^0.7.3",
|
79
|
+
"@swc/core": "^1.11.24",
|
80
|
+
"eslint": "^9.25.1",
|
81
|
+
"eslint-config-prettier": "^10.1.2",
|
82
|
+
"eslint-plugin-prettier": "^5.2.6",
|
83
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
84
|
+
"typescript-eslint": "^8.31.1"
|
85
|
+
},
|
86
|
+
"jest": {
|
87
|
+
"moduleFileExtensions": [
|
88
|
+
"js",
|
89
|
+
"json",
|
90
|
+
"ts"
|
91
|
+
],
|
92
|
+
"rootDir": "src",
|
93
|
+
"testRegex": ".*\\.spec\\.ts$",
|
94
|
+
"transform": {
|
95
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
96
|
+
},
|
97
|
+
"collectCoverageFrom": [
|
98
|
+
"**/*.(t|j)s"
|
99
|
+
],
|
100
|
+
"coverageDirectory": "../coverage",
|
101
|
+
"testEnvironment": "node"
|
102
|
+
}
|
103
|
+
}
|