@nathapp/nestjs-common 1.0.1-rc.0 → 1.0.1-rc.10
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/dist/config/index.d.ts +2 -6
- package/dist/config/index.js +2 -10
- package/dist/config/{joi-util.d.ts → utils/joi-util.d.ts} +1 -1
- package/dist/decorator/index.d.ts +1 -3
- package/dist/decorator/index.js +1 -5
- package/dist/exception/app-exception-code.enum.d.ts +11 -0
- package/dist/exception/app-exception-code.enum.js +15 -0
- package/dist/exception/global-exception.filter.d.ts +46 -0
- package/dist/exception/global-exception.filter.js +140 -0
- package/dist/exception/index.d.ts +5 -2
- package/dist/exception/index.js +9 -3
- package/dist/exception/micro-service.exception.d.ts +8 -0
- package/dist/exception/micro-service.exception.js +18 -0
- package/dist/exception/user-not-found.exception.d.ts +4 -0
- package/dist/exception/user-not-found.exception.js +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/middleware/index.d.ts +3 -0
- package/dist/middleware/index.js +7 -0
- package/dist/middleware/json-body.middleware.d.ts +4 -0
- package/dist/middleware/json-body.middleware.js +20 -0
- package/dist/middleware/raw-body.middleware.d.ts +6 -0
- package/dist/middleware/raw-body.middleware.js +25 -0
- package/dist/serialize/json-response.d.ts +10 -0
- package/dist/serialize/json-response.js +30 -0
- package/dist/validation/index.d.ts +0 -0
- package/dist/validation/index.js +0 -0
- package/lib/config/README.md +7 -0
- package/package.json +4 -6
- package/dist/config/db.config.d.ts +0 -14
- package/dist/config/db.config.js +0 -17
- package/dist/config/mongodb.config.d.ts +0 -10
- package/dist/config/mongodb.config.js +0 -14
- package/dist/config/rabbitmq.config.d.ts +0 -10
- package/dist/config/rabbitmq.config.js +0 -14
- package/dist/config/redis.config.d.ts +0 -10
- package/dist/config/redis.config.js +0 -14
- package/dist/decorator/is-public.decorator.d.ts +0 -2
- package/dist/decorator/is-public.decorator.js +0 -7
- package/dist/decorator/permission.decorator.d.ts +0 -2
- package/dist/decorator/permission.decorator.js +0 -7
- package/dist/exception/app-exception-filter.provider.d.ts +0 -2
- package/dist/exception/app-exception-filter.provider.js +0 -9
- package/dist/exception/translator.d.ts +0 -12
- package/dist/exception/translator.js +0 -9
- /package/dist/config/{joi-util.js → utils/joi-util.js} +0 -0
- /package/dist/config/{validate-util.d.ts → utils/validate-util.d.ts} +0 -0
- /package/dist/config/{validate-util.js → utils/validate-util.js} +0 -0
package/dist/config/index.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import RedisConfig from "./redis.config";
|
|
4
|
-
import RabbitMQConfig from "./rabbitmq.config";
|
|
5
|
-
import JoiUtil, { JoiConfig } from "./joi-util";
|
|
6
|
-
export { DbConfig, MongoConfig, RedisConfig, RabbitMQConfig, JoiUtil, JoiConfig, };
|
|
1
|
+
import JoiUtil, { JoiConfig } from "./utils/joi-util";
|
|
2
|
+
export { JoiUtil, JoiConfig, };
|
package/dist/config/index.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JoiUtil =
|
|
4
|
-
const
|
|
5
|
-
exports.DbConfig = db_config_1.default;
|
|
6
|
-
const mongodb_config_1 = require("./mongodb.config");
|
|
7
|
-
exports.MongoConfig = mongodb_config_1.default;
|
|
8
|
-
const redis_config_1 = require("./redis.config");
|
|
9
|
-
exports.RedisConfig = redis_config_1.default;
|
|
10
|
-
const rabbitmq_config_1 = require("./rabbitmq.config");
|
|
11
|
-
exports.RabbitMQConfig = rabbitmq_config_1.default;
|
|
12
|
-
const joi_util_1 = require("./joi-util");
|
|
3
|
+
exports.JoiUtil = void 0;
|
|
4
|
+
const joi_util_1 = require("./utils/joi-util");
|
|
13
5
|
exports.JoiUtil = joi_util_1.default;
|
|
@@ -3,7 +3,7 @@ interface ConfigProps {
|
|
|
3
3
|
value: unknown;
|
|
4
4
|
joi: Schema;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
6
|
+
export type JoiConfig<T> = Record<keyof T, ConfigProps>;
|
|
7
7
|
export default class JoiUtil {
|
|
8
8
|
static validate<T>(config: JoiConfig<T>): T;
|
|
9
9
|
static extractByPropName<T>(config: JoiConfig<T>, propName: keyof ConfigProps): T | SchemaMap<T>;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { ClientInfo } from "./client-info.decorator";
|
|
2
2
|
import { RealIP } from "./real-ip.decorator";
|
|
3
|
-
|
|
4
|
-
import { RequiredPermission } from "./permission.decorator";
|
|
5
|
-
export { ClientInfo, RealIP, Public, RequiredPermission };
|
|
3
|
+
export { ClientInfo, RealIP };
|
package/dist/decorator/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RealIP = exports.ClientInfo = void 0;
|
|
4
4
|
const client_info_decorator_1 = require("./client-info.decorator");
|
|
5
5
|
Object.defineProperty(exports, "ClientInfo", { enumerable: true, get: function () { return client_info_decorator_1.ClientInfo; } });
|
|
6
6
|
const real_ip_decorator_1 = require("./real-ip.decorator");
|
|
7
7
|
Object.defineProperty(exports, "RealIP", { enumerable: true, get: function () { return real_ip_decorator_1.RealIP; } });
|
|
8
|
-
const is_public_decorator_1 = require("./is-public.decorator");
|
|
9
|
-
Object.defineProperty(exports, "Public", { enumerable: true, get: function () { return is_public_decorator_1.Public; } });
|
|
10
|
-
const permission_decorator_1 = require("./permission.decorator");
|
|
11
|
-
Object.defineProperty(exports, "RequiredPermission", { enumerable: true, get: function () { return permission_decorator_1.RequiredPermission; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare enum CommonExceptionCode {
|
|
2
|
+
UNKNOWN_ERROR = -1,
|
|
3
|
+
REQUEST_PARAMETER_ERROR = -2,
|
|
4
|
+
NOT_FOUND = 404,
|
|
5
|
+
INTERNAL_ERROR = 501,
|
|
6
|
+
USER_NOT_FOUND = 20000,
|
|
7
|
+
UNAUTHORIZED = 40000,
|
|
8
|
+
FORBIDDEN_IP_NOT_MATCH = 40001,
|
|
9
|
+
FORBIDDEN_BLACKLISTED = 40002,
|
|
10
|
+
FORBIDDEN = 40003
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonExceptionCode = void 0;
|
|
4
|
+
var CommonExceptionCode;
|
|
5
|
+
(function (CommonExceptionCode) {
|
|
6
|
+
CommonExceptionCode[CommonExceptionCode["UNKNOWN_ERROR"] = -1] = "UNKNOWN_ERROR";
|
|
7
|
+
CommonExceptionCode[CommonExceptionCode["REQUEST_PARAMETER_ERROR"] = -2] = "REQUEST_PARAMETER_ERROR";
|
|
8
|
+
CommonExceptionCode[CommonExceptionCode["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
9
|
+
CommonExceptionCode[CommonExceptionCode["INTERNAL_ERROR"] = 501] = "INTERNAL_ERROR";
|
|
10
|
+
CommonExceptionCode[CommonExceptionCode["USER_NOT_FOUND"] = 20000] = "USER_NOT_FOUND";
|
|
11
|
+
CommonExceptionCode[CommonExceptionCode["UNAUTHORIZED"] = 40000] = "UNAUTHORIZED";
|
|
12
|
+
CommonExceptionCode[CommonExceptionCode["FORBIDDEN_IP_NOT_MATCH"] = 40001] = "FORBIDDEN_IP_NOT_MATCH";
|
|
13
|
+
CommonExceptionCode[CommonExceptionCode["FORBIDDEN_BLACKLISTED"] = 40002] = "FORBIDDEN_BLACKLISTED";
|
|
14
|
+
CommonExceptionCode[CommonExceptionCode["FORBIDDEN"] = 40003] = "FORBIDDEN";
|
|
15
|
+
})(CommonExceptionCode = exports.CommonExceptionCode || (exports.CommonExceptionCode = {}));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ExceptionFilter, ArgumentsHost, ForbiddenException, NotFoundException } from "@nestjs/common";
|
|
2
|
+
import { HttpAdapterHost } from "@nestjs/core";
|
|
3
|
+
import { I18nService } from "nestjs-i18n";
|
|
4
|
+
import { CommonExceptionCode } from "./app-exception-code.enum";
|
|
5
|
+
import { AppException } from "./app.exception";
|
|
6
|
+
import { UsernameNotFoundException } from "./user-not-found.exception";
|
|
7
|
+
import { HttpMicroServiceException } from "./micro-service.exception";
|
|
8
|
+
export declare class GlobalExceptionsFilter implements ExceptionFilter {
|
|
9
|
+
private readonly httpAdapterHost;
|
|
10
|
+
private readonly i18nService;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private readonly exceptionPrefix;
|
|
13
|
+
constructor(httpAdapterHost: HttpAdapterHost, i18nService: I18nService);
|
|
14
|
+
catch(exception: unknown, host: ArgumentsHost): Promise<void>;
|
|
15
|
+
handleAppException(exception: AppException, lang: string): Promise<{
|
|
16
|
+
httpStatus: number;
|
|
17
|
+
errorCode: number;
|
|
18
|
+
errMessage: string;
|
|
19
|
+
}>;
|
|
20
|
+
handleForbiddenException(exception: ForbiddenException, lang: string): Promise<{
|
|
21
|
+
httpStatus: number;
|
|
22
|
+
errorCode: CommonExceptionCode;
|
|
23
|
+
errMessage: string;
|
|
24
|
+
}>;
|
|
25
|
+
handleUserNotFoundException(exception: UsernameNotFoundException, lang: string): Promise<{
|
|
26
|
+
httpStatus: number;
|
|
27
|
+
errorCode: CommonExceptionCode;
|
|
28
|
+
errMessage: string;
|
|
29
|
+
}>;
|
|
30
|
+
handleNotFoundException(exception: NotFoundException, request: any): Promise<{
|
|
31
|
+
httpStatus: number;
|
|
32
|
+
errorCode: CommonExceptionCode;
|
|
33
|
+
errMessage: string;
|
|
34
|
+
}>;
|
|
35
|
+
handleHttpMicroServiceException(exception: HttpMicroServiceException): Promise<{
|
|
36
|
+
httpStatus: number;
|
|
37
|
+
errorCode: number;
|
|
38
|
+
errMessage: string;
|
|
39
|
+
}>;
|
|
40
|
+
handleUnknownException(exception: any, lang: string, responseBody?: any): Promise<{
|
|
41
|
+
httpStatus: number;
|
|
42
|
+
errorCode: CommonExceptionCode;
|
|
43
|
+
errMessage: string;
|
|
44
|
+
}>;
|
|
45
|
+
translate(code: number, lang: string, args?: any, prefix?: string): Promise<string>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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 GlobalExceptionsFilter_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.GlobalExceptionsFilter = void 0;
|
|
14
|
+
const common_1 = require("@nathapp/common");
|
|
15
|
+
const common_2 = require("@nestjs/common");
|
|
16
|
+
const core_1 = require("@nestjs/core");
|
|
17
|
+
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
18
|
+
const app_exception_code_enum_1 = require("./app-exception-code.enum");
|
|
19
|
+
const app_exception_1 = require("./app.exception");
|
|
20
|
+
const user_not_found_exception_1 = require("./user-not-found.exception");
|
|
21
|
+
const micro_service_exception_1 = require("./micro-service.exception");
|
|
22
|
+
let GlobalExceptionsFilter = GlobalExceptionsFilter_1 = class GlobalExceptionsFilter {
|
|
23
|
+
constructor(httpAdapterHost, i18nService) {
|
|
24
|
+
this.httpAdapterHost = httpAdapterHost;
|
|
25
|
+
this.i18nService = i18nService;
|
|
26
|
+
this.logger = new common_2.Logger(GlobalExceptionsFilter_1.name);
|
|
27
|
+
this.exceptionPrefix = "exception";
|
|
28
|
+
}
|
|
29
|
+
async catch(exception, host) {
|
|
30
|
+
const { httpAdapter } = this.httpAdapterHost;
|
|
31
|
+
const ctx = host.switchToHttp();
|
|
32
|
+
const response = ctx.getResponse();
|
|
33
|
+
const request = ctx.getRequest();
|
|
34
|
+
const lang = ctx.getRequest().i18nLang;
|
|
35
|
+
let es;
|
|
36
|
+
if (exception instanceof app_exception_1.AppException) {
|
|
37
|
+
es = await this.handleAppException(exception, lang);
|
|
38
|
+
}
|
|
39
|
+
else if (exception instanceof common_2.ForbiddenException) {
|
|
40
|
+
es = await this.handleForbiddenException(exception, lang);
|
|
41
|
+
}
|
|
42
|
+
else if (exception instanceof common_2.NotFoundException) {
|
|
43
|
+
es = await this.handleNotFoundException(exception, request);
|
|
44
|
+
}
|
|
45
|
+
else if (exception instanceof user_not_found_exception_1.UsernameNotFoundException) {
|
|
46
|
+
es = await this.handleUserNotFoundException(exception, lang);
|
|
47
|
+
}
|
|
48
|
+
else if (exception instanceof micro_service_exception_1.HttpMicroServiceException) {
|
|
49
|
+
es = await this.handleHttpMicroServiceException(exception);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const httpStatus = exception instanceof common_2.HttpException
|
|
53
|
+
? exception.getStatus()
|
|
54
|
+
: common_2.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
55
|
+
const responseBody = {
|
|
56
|
+
statusCode: httpStatus,
|
|
57
|
+
timestamp: new Date().toISOString(),
|
|
58
|
+
path: httpAdapter.getRequestUrl(ctx.getRequest()),
|
|
59
|
+
};
|
|
60
|
+
es = await this.handleUnknownException(exception, lang, responseBody);
|
|
61
|
+
}
|
|
62
|
+
httpAdapter.reply(response, common_1.JsonResponse.Error(es.errorCode, es.errMessage), es.httpStatus);
|
|
63
|
+
}
|
|
64
|
+
async handleAppException(exception, lang) {
|
|
65
|
+
const httpStatus = 200;
|
|
66
|
+
const errorCode = exception.code;
|
|
67
|
+
const errMessage = await this.translate(errorCode, lang, exception.args, exception.prefix);
|
|
68
|
+
return {
|
|
69
|
+
httpStatus,
|
|
70
|
+
errorCode,
|
|
71
|
+
errMessage,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async handleForbiddenException(exception, lang) {
|
|
75
|
+
const httpStatus = 200;
|
|
76
|
+
const errorCode = app_exception_code_enum_1.CommonExceptionCode.FORBIDDEN;
|
|
77
|
+
const errMessage = await this.translate(errorCode, lang);
|
|
78
|
+
return {
|
|
79
|
+
httpStatus,
|
|
80
|
+
errorCode,
|
|
81
|
+
errMessage,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async handleUserNotFoundException(exception, lang) {
|
|
85
|
+
const httpStatus = 200;
|
|
86
|
+
const errorCode = app_exception_code_enum_1.CommonExceptionCode.USER_NOT_FOUND;
|
|
87
|
+
this.logger.warn(exception.message, user_not_found_exception_1.UsernameNotFoundException.name);
|
|
88
|
+
const errMessage = await this.translate(errorCode, lang);
|
|
89
|
+
return {
|
|
90
|
+
httpStatus,
|
|
91
|
+
errorCode,
|
|
92
|
+
errMessage,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async handleNotFoundException(exception, request) {
|
|
96
|
+
const httpStatus = exception.getStatus();
|
|
97
|
+
const errorCode = app_exception_code_enum_1.CommonExceptionCode.NOT_FOUND;
|
|
98
|
+
this.logger.warn(`Method: ${request.method}, url: ${request.url}`, exception.name);
|
|
99
|
+
const errMessage = exception.message;
|
|
100
|
+
return {
|
|
101
|
+
httpStatus,
|
|
102
|
+
errorCode,
|
|
103
|
+
errMessage,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async handleHttpMicroServiceException(exception) {
|
|
107
|
+
const httpStatus = 200;
|
|
108
|
+
const errorCode = exception.ret;
|
|
109
|
+
const errMessage = exception.message;
|
|
110
|
+
return {
|
|
111
|
+
httpStatus,
|
|
112
|
+
errorCode,
|
|
113
|
+
errMessage,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async handleUnknownException(exception, lang, responseBody) {
|
|
117
|
+
const httpStatus = 500;
|
|
118
|
+
const errorCode = app_exception_code_enum_1.CommonExceptionCode.UNKNOWN_ERROR;
|
|
119
|
+
const { message } = (0, common_1.describeError)(exception);
|
|
120
|
+
this.logger.error(`Unknown Error occur. msg: ${message}, data: ${JSON.stringify(responseBody)}`, exception.stack);
|
|
121
|
+
const errMessage = await this.translate(errorCode, lang);
|
|
122
|
+
return {
|
|
123
|
+
httpStatus,
|
|
124
|
+
errorCode,
|
|
125
|
+
errMessage,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async translate(code, lang, args, prefix) {
|
|
129
|
+
return this.i18nService.translate(`${prefix || this.exceptionPrefix}.${code}`, {
|
|
130
|
+
lang,
|
|
131
|
+
args,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
GlobalExceptionsFilter = GlobalExceptionsFilter_1 = __decorate([
|
|
136
|
+
(0, common_2.Catch)(),
|
|
137
|
+
__metadata("design:paramtypes", [core_1.HttpAdapterHost,
|
|
138
|
+
nestjs_i18n_1.I18nService])
|
|
139
|
+
], GlobalExceptionsFilter);
|
|
140
|
+
exports.GlobalExceptionsFilter = GlobalExceptionsFilter;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonExceptionCode } from "./app-exception-code.enum";
|
|
2
2
|
import { AppExceptionFilter } from "./app-exception.filter";
|
|
3
3
|
import { AppException } from "./app.exception";
|
|
4
|
-
|
|
4
|
+
import { GlobalExceptionsFilter } from "./global-exception.filter";
|
|
5
|
+
import { HttpMicroServiceException } from "./micro-service.exception";
|
|
6
|
+
import { UsernameNotFoundException } from "./user-not-found.exception";
|
|
7
|
+
export { AppException, AppExceptionFilter, GlobalExceptionsFilter, UsernameNotFoundException, CommonExceptionCode, HttpMicroServiceException };
|
package/dist/exception/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.HttpMicroServiceException = exports.CommonExceptionCode = exports.UsernameNotFoundException = exports.GlobalExceptionsFilter = exports.AppExceptionFilter = exports.AppException = void 0;
|
|
4
|
+
const app_exception_code_enum_1 = require("./app-exception-code.enum");
|
|
5
|
+
Object.defineProperty(exports, "CommonExceptionCode", { enumerable: true, get: function () { return app_exception_code_enum_1.CommonExceptionCode; } });
|
|
6
6
|
const app_exception_filter_1 = require("./app-exception.filter");
|
|
7
7
|
Object.defineProperty(exports, "AppExceptionFilter", { enumerable: true, get: function () { return app_exception_filter_1.AppExceptionFilter; } });
|
|
8
8
|
const app_exception_1 = require("./app.exception");
|
|
9
9
|
Object.defineProperty(exports, "AppException", { enumerable: true, get: function () { return app_exception_1.AppException; } });
|
|
10
|
+
const global_exception_filter_1 = require("./global-exception.filter");
|
|
11
|
+
Object.defineProperty(exports, "GlobalExceptionsFilter", { enumerable: true, get: function () { return global_exception_filter_1.GlobalExceptionsFilter; } });
|
|
12
|
+
const micro_service_exception_1 = require("./micro-service.exception");
|
|
13
|
+
Object.defineProperty(exports, "HttpMicroServiceException", { enumerable: true, get: function () { return micro_service_exception_1.HttpMicroServiceException; } });
|
|
14
|
+
const user_not_found_exception_1 = require("./user-not-found.exception");
|
|
15
|
+
Object.defineProperty(exports, "UsernameNotFoundException", { enumerable: true, get: function () { return user_not_found_exception_1.UsernameNotFoundException; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMicroServiceException = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class HttpMicroServiceException extends common_1.HttpException {
|
|
6
|
+
constructor(ret, message) {
|
|
7
|
+
super({ ret, message }, 200);
|
|
8
|
+
this._ret = ret;
|
|
9
|
+
this._message = message;
|
|
10
|
+
}
|
|
11
|
+
get ret() {
|
|
12
|
+
return this._ret;
|
|
13
|
+
}
|
|
14
|
+
get message() {
|
|
15
|
+
return this._message;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.HttpMicroServiceException = HttpMicroServiceException;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UsernameNotFoundException = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class UsernameNotFoundException extends common_1.HttpException {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message, 500);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.UsernameNotFoundException = UsernameNotFoundException;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RawBodyMiddleware = exports.JsonBodyMiddleware = void 0;
|
|
4
|
+
const json_body_middleware_1 = require("./json-body.middleware");
|
|
5
|
+
Object.defineProperty(exports, "JsonBodyMiddleware", { enumerable: true, get: function () { return json_body_middleware_1.JsonBodyMiddleware; } });
|
|
6
|
+
const raw_body_middleware_1 = require("./raw-body.middleware");
|
|
7
|
+
Object.defineProperty(exports, "RawBodyMiddleware", { enumerable: true, get: function () { return raw_body_middleware_1.RawBodyMiddleware; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
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.JsonBodyMiddleware = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const body_parser_1 = require("body-parser");
|
|
12
|
+
let JsonBodyMiddleware = class JsonBodyMiddleware {
|
|
13
|
+
use(req, res, next) {
|
|
14
|
+
(0, body_parser_1.json)()(req, res, next);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
JsonBodyMiddleware = __decorate([
|
|
18
|
+
(0, common_1.Injectable)()
|
|
19
|
+
], JsonBodyMiddleware);
|
|
20
|
+
exports.JsonBodyMiddleware = JsonBodyMiddleware;
|
|
@@ -0,0 +1,25 @@
|
|
|
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.RawBodyMiddleware = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const bodyParser = require("body-parser");
|
|
15
|
+
let RawBodyMiddleware = class RawBodyMiddleware {
|
|
16
|
+
constructor() { }
|
|
17
|
+
use(req, res, next) {
|
|
18
|
+
bodyParser.raw({ type: "*/*" })(req, res, next);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
RawBodyMiddleware = __decorate([
|
|
22
|
+
(0, common_1.Injectable)(),
|
|
23
|
+
__metadata("design:paramtypes", [])
|
|
24
|
+
], RawBodyMiddleware);
|
|
25
|
+
exports.RawBodyMiddleware = RawBodyMiddleware;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ClassConstructor } from "class-transformer";
|
|
2
|
+
import { JsonResponse as JResponse } from "@nathapp/common";
|
|
3
|
+
export declare class JsonResponse<T> extends JResponse {
|
|
4
|
+
ret: number;
|
|
5
|
+
data: T;
|
|
6
|
+
message?: string;
|
|
7
|
+
constructor(ret: number, data: any, message?: string);
|
|
8
|
+
static Ok<T>(data?: T, cls?: ClassConstructor<T>): JsonResponse<T>;
|
|
9
|
+
static Error<T>(errcode: number, message: string): JsonResponse<T>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonResponse = void 0;
|
|
4
|
+
const class_transformer_1 = require("class-transformer");
|
|
5
|
+
const common_1 = require("@nathapp/common");
|
|
6
|
+
class JsonResponse extends common_1.JsonResponse {
|
|
7
|
+
constructor(ret, data, message) {
|
|
8
|
+
super(ret, data, message);
|
|
9
|
+
this.ret = ret;
|
|
10
|
+
this.data = data;
|
|
11
|
+
this.message = message;
|
|
12
|
+
}
|
|
13
|
+
static Ok(data, cls) {
|
|
14
|
+
let responseData;
|
|
15
|
+
if (data && cls) {
|
|
16
|
+
responseData = (0, class_transformer_1.plainToInstance)(cls, data);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
responseData = data;
|
|
20
|
+
}
|
|
21
|
+
const response = new JsonResponse(0, responseData, "ok");
|
|
22
|
+
return response;
|
|
23
|
+
}
|
|
24
|
+
static Error(errcode, message) {
|
|
25
|
+
const response = new JsonResponse(errcode, null, message);
|
|
26
|
+
delete response.data;
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.JsonResponse = JsonResponse;
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-common",
|
|
3
|
-
"version": "1.0.1-rc.
|
|
3
|
+
"version": "1.0.1-rc.10",
|
|
4
4
|
"description": "NestJs Common Library",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist && tsc -p tsconfig.json",
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@nestjs/platform-express": "^9.0.0",
|
|
18
18
|
"@nestjs/platform-fastify": "^9.0.0",
|
|
19
|
-
"@types/js-yaml": "^4.0.5",
|
|
20
19
|
"@types/node": "^17.0.22",
|
|
21
20
|
"@typescript-eslint/eslint-plugin": "^4",
|
|
22
21
|
"@typescript-eslint/parser": "^4",
|
|
@@ -34,14 +33,13 @@
|
|
|
34
33
|
"dependencies": {
|
|
35
34
|
"@nathapp/common": "^0.1.10",
|
|
36
35
|
"joi": "^17.6.0",
|
|
37
|
-
"js-yaml": "^4.1.0",
|
|
38
36
|
"nestjs-i18n": "^10.0.0",
|
|
39
37
|
"request-ip": "^3.2.0"
|
|
40
38
|
},
|
|
41
39
|
"peerDependencies": {
|
|
42
|
-
"@nestjs/common": "
|
|
43
|
-
"@nestjs/config": "
|
|
44
|
-
"@nestjs/core": "
|
|
40
|
+
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
41
|
+
"@nestjs/config": "^1.0.0 || ^2.0.0 || ^3.0.0",
|
|
42
|
+
"@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
45
43
|
"class-transformer": "*",
|
|
46
44
|
"class-validator": "*",
|
|
47
45
|
"rxjs": "*"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare const _default: (() => {
|
|
2
|
-
isPresent: boolean;
|
|
3
|
-
name: string;
|
|
4
|
-
url: string;
|
|
5
|
-
type: "mysql" | "mariadb" | "postgres" | "mssql" | "oracle" | "sqlite";
|
|
6
|
-
entityPath: string;
|
|
7
|
-
}) & import("@nestjs/config").ConfigFactoryKeyHost<{
|
|
8
|
-
isPresent: boolean;
|
|
9
|
-
name: string;
|
|
10
|
-
url: string;
|
|
11
|
-
type: "mysql" | "mariadb" | "postgres" | "mssql" | "oracle" | "sqlite";
|
|
12
|
-
entityPath: string;
|
|
13
|
-
}>;
|
|
14
|
-
export default _default;
|
package/dist/config/db.config.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const common_1 = require("@nathapp/common");
|
|
4
|
-
const config_1 = require("@nestjs/config");
|
|
5
|
-
exports.default = (0, config_1.registerAs)("db", () => {
|
|
6
|
-
const isPresent = !(0, common_1.isUndefinedOrNullOrEmpty)(process.env.DB_URL);
|
|
7
|
-
const name = process.env.DB_NAME || "default";
|
|
8
|
-
const url = process.env.DB_URL;
|
|
9
|
-
const type = (isPresent ? url.split(":").shift() : null);
|
|
10
|
-
return {
|
|
11
|
-
isPresent,
|
|
12
|
-
name,
|
|
13
|
-
url,
|
|
14
|
-
type,
|
|
15
|
-
entityPath: process.env.DB_ENTITY_PATH || "/**/*.entity.ts",
|
|
16
|
-
};
|
|
17
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const common_1 = require("@nathapp/common");
|
|
4
|
-
const config_1 = require("@nestjs/config");
|
|
5
|
-
exports.default = (0, config_1.registerAs)("mongodb", () => {
|
|
6
|
-
const isPresent = !(0, common_1.isUndefinedOrNullOrEmpty)(process.env.MONGO_URL);
|
|
7
|
-
const name = process.env.MONGO_NAME || "default";
|
|
8
|
-
const url = process.env.MONGO_URL;
|
|
9
|
-
return {
|
|
10
|
-
isPresent,
|
|
11
|
-
name,
|
|
12
|
-
url,
|
|
13
|
-
};
|
|
14
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const common_1 = require("@nathapp/common");
|
|
4
|
-
const config_1 = require("@nestjs/config");
|
|
5
|
-
exports.default = (0, config_1.registerAs)("rabbitmq", () => {
|
|
6
|
-
const isPresent = !(0, common_1.isUndefinedOrNullOrEmpty)(process.env.RABBITMQ_URL);
|
|
7
|
-
const name = process.env.RABBITMQ_NAME || "default";
|
|
8
|
-
const url = process.env.RABBITMQ_URL;
|
|
9
|
-
return {
|
|
10
|
-
isPresent,
|
|
11
|
-
name,
|
|
12
|
-
url,
|
|
13
|
-
};
|
|
14
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const common_1 = require("@nathapp/common");
|
|
4
|
-
const config_1 = require("@nestjs/config");
|
|
5
|
-
exports.default = (0, config_1.registerAs)("redis", () => {
|
|
6
|
-
const isPresent = !(0, common_1.isUndefinedOrNullOrEmpty)(process.env.REDIS_URL);
|
|
7
|
-
const name = process.env.REDIS_NAME || "default";
|
|
8
|
-
const url = process.env.REDIS_URL;
|
|
9
|
-
return {
|
|
10
|
-
isPresent,
|
|
11
|
-
name,
|
|
12
|
-
url,
|
|
13
|
-
};
|
|
14
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
exports.IS_PUBLIC_KEY = "isPublic";
|
|
6
|
-
const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true);
|
|
7
|
-
exports.Public = Public;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequiredPermission = exports.PERMISSION_KEY = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
exports.PERMISSION_KEY = "PERMISSION";
|
|
6
|
-
const RequiredPermission = (permission) => (0, common_1.SetMetadata)(exports.PERMISSION_KEY, permission);
|
|
7
|
-
exports.RequiredPermission = RequiredPermission;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAppExceptionFilterProvider = void 0;
|
|
4
|
-
const core_1 = require("@nestjs/core");
|
|
5
|
-
const app_exception_filter_1 = require("./app-exception.filter");
|
|
6
|
-
exports.createAppExceptionFilterProvider = {
|
|
7
|
-
provide: core_1.APP_FILTER,
|
|
8
|
-
useClass: app_exception_filter_1.AppExceptionFilter,
|
|
9
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface Translator {
|
|
2
|
-
translate(key: string, params: {
|
|
3
|
-
lang: string;
|
|
4
|
-
args?: any;
|
|
5
|
-
}): string | Promise<string>;
|
|
6
|
-
}
|
|
7
|
-
export declare class NullTranslator implements Translator {
|
|
8
|
-
translate(key: string, params: {
|
|
9
|
-
lang: string;
|
|
10
|
-
args?: any;
|
|
11
|
-
}): string | Promise<string>;
|
|
12
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|