@ajayjbtickets/common 1.0.2 → 1.0.3
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/config.d.ts +10 -0
- package/dist/config/config.js +25 -0
- package/dist/config/config.js.map +1 -0
- package/dist/constants/environments.d.ts +6 -0
- package/dist/constants/environments.js +9 -0
- package/dist/constants/environments.js.map +1 -0
- package/dist/core/ApiError.d.ts +54 -0
- package/dist/core/ApiError.js +136 -0
- package/dist/core/ApiError.js.map +1 -0
- package/dist/core/ApiResponse.d.ts +83 -0
- package/dist/core/ApiResponse.js +140 -0
- package/dist/core/ApiResponse.js.map +1 -0
- package/dist/core/Logger.d.ts +3 -0
- package/dist/core/Logger.js +74 -0
- package/dist/core/Logger.js.map +1 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.js +25 -6
- package/dist/index.js.map +1 -0
- package/dist/middlewares/schemaValidator.d.ts +5 -0
- package/dist/middlewares/schemaValidator.js +20 -0
- package/dist/middlewares/schemaValidator.js.map +1 -0
- package/dist/middlewares/verifyToken.d.ts +3 -0
- package/dist/middlewares/verifyToken.js +32 -0
- package/dist/middlewares/verifyToken.js.map +1 -0
- package/dist/services/jwt.service.d.ts +11 -0
- package/dist/services/jwt.service.js +25 -0
- package/dist/services/jwt.service.js.map +1 -0
- package/dist/services/password.service.d.ts +5 -0
- package/dist/services/password.service.js +30 -0
- package/dist/services/password.service.js.map +1 -0
- package/dist/types/validation.d.ts +6 -0
- package/dist/types/validation.js +11 -0
- package/dist/types/validation.js.map +1 -0
- package/dist/utils/asyncHandler.d.ts +4 -0
- package/dist/utils/asyncHandler.js +12 -0
- package/dist/utils/asyncHandler.js.map +1 -0
- package/package.json +15 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizedConfig = void 0;
|
|
4
|
+
require("dotenv/config");
|
|
5
|
+
const getConfig = () => {
|
|
6
|
+
return {
|
|
7
|
+
ENVIRONMENT: process.env.ENVIRONMENT,
|
|
8
|
+
LOG_DIR: process.env.LOG_DIR,
|
|
9
|
+
LOG_LEVEL: process.env.LOG_LEVEL,
|
|
10
|
+
SALT_ROUNDS: parseInt(process.env.SALT_ROUNDS),
|
|
11
|
+
JWT_KEY: process.env.JWT_KEY,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const getSanitizedConfig = (config) => {
|
|
15
|
+
for (const [key, value] of Object.entries(config)) {
|
|
16
|
+
if (!value) {
|
|
17
|
+
throw new Error(`Missing key ${key} in config.env`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return config;
|
|
21
|
+
};
|
|
22
|
+
const config = getConfig();
|
|
23
|
+
const sanitizedConfig = getSanitizedConfig(config);
|
|
24
|
+
exports.sanitizedConfig = sanitizedConfig;
|
|
25
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":";;;AAAA,yBAAuB;AAUvB,MAAM,SAAS,GAAG,GAAQ,EAAE;IAC1B,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;QACpC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;QAC5B,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;QAChC,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QAC9C,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;KAC7B,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,MAAW,EAAO,EAAE;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,eAAe,GAAG,gBAAgB,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAC3B,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAE1C,0CAAe"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ENVIRONMENTS = {
|
|
4
|
+
production: "production",
|
|
5
|
+
development: "development",
|
|
6
|
+
testing: "testing",
|
|
7
|
+
};
|
|
8
|
+
exports.default = ENVIRONMENTS;
|
|
9
|
+
//# sourceMappingURL=environments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environments.js","sourceRoot":"","sources":["../../src/constants/environments.ts"],"names":[],"mappings":";;AAAC,MAAM,YAAY,GAAG;IAClB,UAAU,EAAE,YAAY;IACxB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF,kBAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Response } from "express";
|
|
2
|
+
export declare enum ErrorType {
|
|
3
|
+
BAD_TOKEN = "BadTokenError",
|
|
4
|
+
TOKEN_EXPIRED = "TokenExpiredError",
|
|
5
|
+
UNAUTHORIZED = "AuthFailureError",
|
|
6
|
+
ACCESS_TOKEN = "AccessTokenError",
|
|
7
|
+
INTERNAL = "InternalError",
|
|
8
|
+
NOT_FOUND = "NotFoundError",
|
|
9
|
+
NO_ENTRY = "NoEntryError",
|
|
10
|
+
NO_DATA = "NoDataError",
|
|
11
|
+
BAD_REQUEST = "BadRequestError",
|
|
12
|
+
FORBIDDEN = "ForbiddenError"
|
|
13
|
+
}
|
|
14
|
+
export type ErrorDetailType = {
|
|
15
|
+
field: string | number;
|
|
16
|
+
message?: (string | number)[];
|
|
17
|
+
};
|
|
18
|
+
export declare abstract class ApiError extends Error {
|
|
19
|
+
type: ErrorType;
|
|
20
|
+
message: string;
|
|
21
|
+
errors: ErrorDetailType[];
|
|
22
|
+
constructor(type: ErrorType, message: string | undefined, errors: ErrorDetailType[]);
|
|
23
|
+
static handle(err: ApiError, res: Response): void;
|
|
24
|
+
}
|
|
25
|
+
export declare class BadTokenError extends ApiError {
|
|
26
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
27
|
+
}
|
|
28
|
+
export declare class TokenExpiredError extends ApiError {
|
|
29
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
30
|
+
}
|
|
31
|
+
export declare class AuthFailureError extends ApiError {
|
|
32
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
33
|
+
}
|
|
34
|
+
export declare class AccessTokenError extends ApiError {
|
|
35
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
36
|
+
}
|
|
37
|
+
export declare class InternalError extends ApiError {
|
|
38
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
39
|
+
}
|
|
40
|
+
export declare class NotFoundError extends ApiError {
|
|
41
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
42
|
+
}
|
|
43
|
+
export declare class NoEntryError extends ApiError {
|
|
44
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
45
|
+
}
|
|
46
|
+
export declare class NoDataError extends ApiError {
|
|
47
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
48
|
+
}
|
|
49
|
+
export declare class BadRequestError extends ApiError {
|
|
50
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
51
|
+
}
|
|
52
|
+
export declare class ForbiddenError extends ApiError {
|
|
53
|
+
constructor(message?: string, errors?: ErrorDetailType[]);
|
|
54
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ForbiddenError = exports.BadRequestError = exports.NoDataError = exports.NoEntryError = exports.NotFoundError = exports.InternalError = exports.AccessTokenError = exports.AuthFailureError = exports.TokenExpiredError = exports.BadTokenError = exports.ApiError = exports.ErrorType = void 0;
|
|
7
|
+
const ApiResponse_1 = require("@/core/ApiResponse");
|
|
8
|
+
const config_1 = require("@/config/config");
|
|
9
|
+
const environments_1 = __importDefault(require("@/constants/environments"));
|
|
10
|
+
var ErrorType;
|
|
11
|
+
(function (ErrorType) {
|
|
12
|
+
ErrorType["BAD_TOKEN"] = "BadTokenError";
|
|
13
|
+
ErrorType["TOKEN_EXPIRED"] = "TokenExpiredError";
|
|
14
|
+
ErrorType["UNAUTHORIZED"] = "AuthFailureError";
|
|
15
|
+
ErrorType["ACCESS_TOKEN"] = "AccessTokenError";
|
|
16
|
+
ErrorType["INTERNAL"] = "InternalError";
|
|
17
|
+
ErrorType["NOT_FOUND"] = "NotFoundError";
|
|
18
|
+
ErrorType["NO_ENTRY"] = "NoEntryError";
|
|
19
|
+
ErrorType["NO_DATA"] = "NoDataError";
|
|
20
|
+
ErrorType["BAD_REQUEST"] = "BadRequestError";
|
|
21
|
+
ErrorType["FORBIDDEN"] = "ForbiddenError";
|
|
22
|
+
})(ErrorType || (exports.ErrorType = ErrorType = {}));
|
|
23
|
+
class ApiError extends Error {
|
|
24
|
+
type;
|
|
25
|
+
message;
|
|
26
|
+
errors;
|
|
27
|
+
constructor(type, message = "Error", errors) {
|
|
28
|
+
super(type);
|
|
29
|
+
this.type = type;
|
|
30
|
+
this.message = message;
|
|
31
|
+
this.errors = errors;
|
|
32
|
+
this.type = type;
|
|
33
|
+
this.message = message;
|
|
34
|
+
this.errors = errors;
|
|
35
|
+
}
|
|
36
|
+
static handle(err, res) {
|
|
37
|
+
switch (err.type) {
|
|
38
|
+
case ErrorType.BAD_TOKEN:
|
|
39
|
+
case ErrorType.TOKEN_EXPIRED:
|
|
40
|
+
case ErrorType.UNAUTHORIZED:
|
|
41
|
+
new ApiResponse_1.BadTokenResponse(err.message, err.errors).send(res);
|
|
42
|
+
break;
|
|
43
|
+
case ErrorType.ACCESS_TOKEN:
|
|
44
|
+
new ApiResponse_1.AccessTokenErrorResponse(err.message, err.errors).send(res);
|
|
45
|
+
break;
|
|
46
|
+
case ErrorType.INTERNAL:
|
|
47
|
+
new ApiResponse_1.InternalErrorResponse(err.message, err.errors).send(res);
|
|
48
|
+
break;
|
|
49
|
+
case ErrorType.NOT_FOUND:
|
|
50
|
+
case ErrorType.NO_ENTRY:
|
|
51
|
+
case ErrorType.NO_DATA:
|
|
52
|
+
new ApiResponse_1.NoFoundResponse(err.message, err.errors).send(res);
|
|
53
|
+
break;
|
|
54
|
+
case ErrorType.BAD_REQUEST:
|
|
55
|
+
new ApiResponse_1.BadRequestResponse(err.message, err.errors).send(res);
|
|
56
|
+
break;
|
|
57
|
+
case ErrorType.FORBIDDEN:
|
|
58
|
+
new ApiResponse_1.ForbiddenResponse(err.message, err.errors).send(res);
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
let messsage = err.message;
|
|
62
|
+
messsage =
|
|
63
|
+
config_1.sanitizedConfig.ENVIRONMENT !== environments_1.default.production
|
|
64
|
+
? messsage
|
|
65
|
+
: "Something went wrong!";
|
|
66
|
+
new ApiResponse_1.InternalErrorResponse(messsage, err.errors).send(res);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.ApiError = ApiError;
|
|
72
|
+
class BadTokenError extends ApiError {
|
|
73
|
+
constructor(message = "Invalid token", errors = []) {
|
|
74
|
+
super(ErrorType.BAD_TOKEN, message, errors);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.BadTokenError = BadTokenError;
|
|
78
|
+
class TokenExpiredError extends ApiError {
|
|
79
|
+
constructor(message = "Token expired", errors = []) {
|
|
80
|
+
super(ErrorType.TOKEN_EXPIRED, message, errors);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.TokenExpiredError = TokenExpiredError;
|
|
84
|
+
class AuthFailureError extends ApiError {
|
|
85
|
+
constructor(message = "Invalid Credentials", errors = []) {
|
|
86
|
+
super(ErrorType.UNAUTHORIZED, message, errors);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.AuthFailureError = AuthFailureError;
|
|
90
|
+
class AccessTokenError extends ApiError {
|
|
91
|
+
constructor(message = "Invalid access token", errors = []) {
|
|
92
|
+
super(ErrorType.ACCESS_TOKEN, message, errors);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.AccessTokenError = AccessTokenError;
|
|
96
|
+
class InternalError extends ApiError {
|
|
97
|
+
constructor(message = "Internal error", errors = []) {
|
|
98
|
+
message =
|
|
99
|
+
config_1.sanitizedConfig.ENVIRONMENT !== environments_1.default.production
|
|
100
|
+
? message
|
|
101
|
+
: "Something went wrong!";
|
|
102
|
+
super(ErrorType.INTERNAL, message, errors);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.InternalError = InternalError;
|
|
106
|
+
class NotFoundError extends ApiError {
|
|
107
|
+
constructor(message = "Not found", errors = []) {
|
|
108
|
+
super(ErrorType.NOT_FOUND, message, errors);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.NotFoundError = NotFoundError;
|
|
112
|
+
class NoEntryError extends ApiError {
|
|
113
|
+
constructor(message = "Entry don't exists", errors = []) {
|
|
114
|
+
super(ErrorType.NO_ENTRY, message, errors);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.NoEntryError = NoEntryError;
|
|
118
|
+
class NoDataError extends ApiError {
|
|
119
|
+
constructor(message = "No data", errors = []) {
|
|
120
|
+
super(ErrorType.NO_DATA, message, errors);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.NoDataError = NoDataError;
|
|
124
|
+
class BadRequestError extends ApiError {
|
|
125
|
+
constructor(message = "Bad request", errors = []) {
|
|
126
|
+
super(ErrorType.BAD_REQUEST, message, errors);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.BadRequestError = BadRequestError;
|
|
130
|
+
class ForbiddenError extends ApiError {
|
|
131
|
+
constructor(message = "Permission denied", errors = []) {
|
|
132
|
+
super(ErrorType.FORBIDDEN, message, errors);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.ForbiddenError = ForbiddenError;
|
|
136
|
+
//# sourceMappingURL=ApiError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiError.js","sourceRoot":"","sources":["../../src/core/ApiError.ts"],"names":[],"mappings":";;;;;;AAEA,oDAO4B;AAC5B,4CAAkD;AAClD,4EAAoD;AAEpD,IAAY,SAWX;AAXD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,gDAAmC,CAAA;IACnC,8CAAiC,CAAA;IACjC,8CAAiC,CAAA;IACjC,uCAA0B,CAAA;IAC1B,wCAA2B,CAAA;IAC3B,sCAAyB,CAAA;IACzB,oCAAuB,CAAA;IACvB,4CAA+B,CAAA;IAC/B,yCAA4B,CAAA;AAC9B,CAAC,EAXW,SAAS,yBAAT,SAAS,QAWpB;AAOD,MAAsB,QAAS,SAAQ,KAAK;IAEjC;IACA;IACA;IAHT,YACS,IAAe,EACf,UAAkB,OAAO,EACzB,MAAyB;QAEhC,KAAK,CAAC,IAAI,CAAC,CAAC;QAJL,SAAI,GAAJ,IAAI,CAAW;QACf,YAAO,GAAP,OAAO,CAAkB;QACzB,WAAM,GAAN,MAAM,CAAmB;QAGhC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,MAAM,CA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AO,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;CACF;AAXD,sCAWC;AAED,MAAa,aAAc,SAAQ,QAAQ;IACzC,YAAY,UAAkB,WAAW,EAAE,SAA4B,EAAE;QACvE,KAAK,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;CACF;AAJD,sCAIC;AAED,MAAa,YAAa,SAAQ,QAAQ;IACxC,YACE,UAAkB,oBAAoB,EACtC,SAA4B,EAAE;QAE9B,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;CACF;AAPD,oCAOC;AAED,MAAa,WAAY,SAAQ,QAAQ;IACvC,YAAY,UAAkB,SAAS,EAAE,SAA4B,EAAE;QACrE,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF;AAJD,kCAIC;AAED,MAAa,eAAgB,SAAQ,QAAQ;IAC3C,YAAY,UAAkB,aAAa,EAAE,SAA4B,EAAE;QACzE,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;CACF;AAJD,0CAIC;AAED,MAAa,cAAe,SAAQ,QAAQ;IAC1C,YACE,UAAkB,mBAAmB,EACrC,SAA4B,EAAE;QAE9B,KAAK,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;CACF;AAPD,wCAOC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Response } from "express";
|
|
2
|
+
import { ErrorDetailType } from "@/core/ApiError";
|
|
3
|
+
export declare enum StatusCode {
|
|
4
|
+
SUCCESS = "10000",
|
|
5
|
+
FAILURE = "10001",
|
|
6
|
+
RETRY = "10002",
|
|
7
|
+
IN_VALID_ACCESS_TOKEN = "10003"
|
|
8
|
+
}
|
|
9
|
+
export declare enum ResponseStatusCode {
|
|
10
|
+
SUCCESS = 200,
|
|
11
|
+
CREATED = 201,
|
|
12
|
+
ACCEPTED = 202,
|
|
13
|
+
NO_CONTENT = 204,
|
|
14
|
+
MOVED_PERMANENTLY = 301,
|
|
15
|
+
FOUND = 302,
|
|
16
|
+
NOT_MODIFIED = 304,
|
|
17
|
+
TEMPORARY_REDIRECT = 307,
|
|
18
|
+
PERMANENT_REDIRECT = 308,
|
|
19
|
+
BAD_REQUEST = 400,
|
|
20
|
+
UNAUTHORIZED = 401,
|
|
21
|
+
PAYMENT_REQUIRED = 402,
|
|
22
|
+
FORBIDDEN = 403,
|
|
23
|
+
NOT_FOUND = 404,
|
|
24
|
+
METHOD_NOT_ALLOWED = 405,
|
|
25
|
+
NOT_ACCEPTABLE = 406,
|
|
26
|
+
CONFLICT = 409,
|
|
27
|
+
GONE = 410,
|
|
28
|
+
PAYLOAD_TOO_LARGE = 413,
|
|
29
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
30
|
+
UNPROCESSABLE_ENTITY = 422,
|
|
31
|
+
TOO_MANY_REQUESTS = 429,
|
|
32
|
+
INTERNAL_ERROR = 500,
|
|
33
|
+
NOT_IMPLEMENTED = 501,
|
|
34
|
+
BAD_GATEWAY = 502,
|
|
35
|
+
SERVICE_UNAVAILABLE = 503,
|
|
36
|
+
GATEWAY_TIMEOUT = 504
|
|
37
|
+
}
|
|
38
|
+
export declare abstract class ApiResponse {
|
|
39
|
+
message: string;
|
|
40
|
+
statusCode: string | undefined;
|
|
41
|
+
status: number;
|
|
42
|
+
constructor(status: number, message: string, statusCode?: string);
|
|
43
|
+
prepare<T extends ApiResponse>(res: Response, response: T, headers?: {
|
|
44
|
+
[key: string]: string;
|
|
45
|
+
}): void;
|
|
46
|
+
send(res: Response, headers?: {
|
|
47
|
+
[key: string]: string;
|
|
48
|
+
}): void;
|
|
49
|
+
private sanitize;
|
|
50
|
+
}
|
|
51
|
+
export declare class SuccessResponse<T> extends ApiResponse {
|
|
52
|
+
data: T;
|
|
53
|
+
constructor(responseStatusCode: ResponseStatusCode.SUCCESS | ResponseStatusCode.CREATED | ResponseStatusCode.ACCEPTED | ResponseStatusCode.NO_CONTENT, message: string, data: T);
|
|
54
|
+
send(res: Response): void;
|
|
55
|
+
}
|
|
56
|
+
export declare class AccessTokenErrorResponse extends ApiResponse {
|
|
57
|
+
protected instruction: string;
|
|
58
|
+
errors: ErrorDetailType[];
|
|
59
|
+
constructor(message: string, errors: ErrorDetailType[]);
|
|
60
|
+
send(res: Response, headers?: {
|
|
61
|
+
[key: string]: string;
|
|
62
|
+
}): void;
|
|
63
|
+
}
|
|
64
|
+
export declare class BadTokenResponse extends ApiResponse {
|
|
65
|
+
errors: ErrorDetailType[];
|
|
66
|
+
constructor(message: string, errors: ErrorDetailType[]);
|
|
67
|
+
}
|
|
68
|
+
export declare class BadRequestResponse extends ApiResponse {
|
|
69
|
+
errors: ErrorDetailType[];
|
|
70
|
+
constructor(message: string, errors: ErrorDetailType[]);
|
|
71
|
+
}
|
|
72
|
+
export declare class InternalErrorResponse extends ApiResponse {
|
|
73
|
+
errors: ErrorDetailType[];
|
|
74
|
+
constructor(message: string, errors: ErrorDetailType[]);
|
|
75
|
+
}
|
|
76
|
+
export declare class NoFoundResponse extends ApiResponse {
|
|
77
|
+
errors: ErrorDetailType[];
|
|
78
|
+
constructor(message: string, errors: ErrorDetailType[]);
|
|
79
|
+
}
|
|
80
|
+
export declare class ForbiddenResponse extends ApiResponse {
|
|
81
|
+
errors: ErrorDetailType[];
|
|
82
|
+
constructor(message: string, errors: ErrorDetailType[]);
|
|
83
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ForbiddenResponse = exports.NoFoundResponse = exports.InternalErrorResponse = exports.BadRequestResponse = exports.BadTokenResponse = exports.AccessTokenErrorResponse = exports.SuccessResponse = exports.ApiResponse = exports.ResponseStatusCode = exports.StatusCode = void 0;
|
|
4
|
+
var StatusCode;
|
|
5
|
+
(function (StatusCode) {
|
|
6
|
+
StatusCode["SUCCESS"] = "10000";
|
|
7
|
+
StatusCode["FAILURE"] = "10001";
|
|
8
|
+
StatusCode["RETRY"] = "10002";
|
|
9
|
+
StatusCode["IN_VALID_ACCESS_TOKEN"] = "10003";
|
|
10
|
+
})(StatusCode || (exports.StatusCode = StatusCode = {}));
|
|
11
|
+
var ResponseStatusCode;
|
|
12
|
+
(function (ResponseStatusCode) {
|
|
13
|
+
ResponseStatusCode[ResponseStatusCode["SUCCESS"] = 200] = "SUCCESS";
|
|
14
|
+
ResponseStatusCode[ResponseStatusCode["CREATED"] = 201] = "CREATED";
|
|
15
|
+
ResponseStatusCode[ResponseStatusCode["ACCEPTED"] = 202] = "ACCEPTED";
|
|
16
|
+
ResponseStatusCode[ResponseStatusCode["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
17
|
+
ResponseStatusCode[ResponseStatusCode["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
18
|
+
ResponseStatusCode[ResponseStatusCode["FOUND"] = 302] = "FOUND";
|
|
19
|
+
ResponseStatusCode[ResponseStatusCode["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
20
|
+
ResponseStatusCode[ResponseStatusCode["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
21
|
+
ResponseStatusCode[ResponseStatusCode["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
22
|
+
ResponseStatusCode[ResponseStatusCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
23
|
+
ResponseStatusCode[ResponseStatusCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
24
|
+
ResponseStatusCode[ResponseStatusCode["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
25
|
+
ResponseStatusCode[ResponseStatusCode["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
26
|
+
ResponseStatusCode[ResponseStatusCode["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
27
|
+
ResponseStatusCode[ResponseStatusCode["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
28
|
+
ResponseStatusCode[ResponseStatusCode["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
29
|
+
ResponseStatusCode[ResponseStatusCode["CONFLICT"] = 409] = "CONFLICT";
|
|
30
|
+
ResponseStatusCode[ResponseStatusCode["GONE"] = 410] = "GONE";
|
|
31
|
+
ResponseStatusCode[ResponseStatusCode["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
32
|
+
ResponseStatusCode[ResponseStatusCode["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
33
|
+
ResponseStatusCode[ResponseStatusCode["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
34
|
+
ResponseStatusCode[ResponseStatusCode["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
35
|
+
ResponseStatusCode[ResponseStatusCode["INTERNAL_ERROR"] = 500] = "INTERNAL_ERROR";
|
|
36
|
+
ResponseStatusCode[ResponseStatusCode["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
37
|
+
ResponseStatusCode[ResponseStatusCode["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
38
|
+
ResponseStatusCode[ResponseStatusCode["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
39
|
+
ResponseStatusCode[ResponseStatusCode["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
40
|
+
})(ResponseStatusCode || (exports.ResponseStatusCode = ResponseStatusCode = {}));
|
|
41
|
+
class ApiResponse {
|
|
42
|
+
message;
|
|
43
|
+
statusCode;
|
|
44
|
+
status;
|
|
45
|
+
constructor(status, message, statusCode) {
|
|
46
|
+
this.message = message;
|
|
47
|
+
this.status = status;
|
|
48
|
+
if (statusCode) {
|
|
49
|
+
this.statusCode = statusCode;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
prepare(res, response, headers = {}) {
|
|
53
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
54
|
+
res.append(key, value);
|
|
55
|
+
}
|
|
56
|
+
res.status(this.status).send(this.sanitize(response));
|
|
57
|
+
}
|
|
58
|
+
send(res, headers = {}) {
|
|
59
|
+
this.prepare(res, this, headers);
|
|
60
|
+
}
|
|
61
|
+
sanitize(response) {
|
|
62
|
+
const clone = {};
|
|
63
|
+
Object.assign(clone, response);
|
|
64
|
+
delete clone["statusCode"];
|
|
65
|
+
for (const key in clone) {
|
|
66
|
+
const typedKey = key;
|
|
67
|
+
if (clone[typedKey] === undefined) {
|
|
68
|
+
delete clone[typedKey];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return clone;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.ApiResponse = ApiResponse;
|
|
75
|
+
class SuccessResponse extends ApiResponse {
|
|
76
|
+
data;
|
|
77
|
+
constructor(responseStatusCode, message, data) {
|
|
78
|
+
super(responseStatusCode, message, StatusCode.SUCCESS);
|
|
79
|
+
this.data = data;
|
|
80
|
+
this.data = data;
|
|
81
|
+
}
|
|
82
|
+
send(res) {
|
|
83
|
+
this.prepare(res, this, {});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.SuccessResponse = SuccessResponse;
|
|
87
|
+
class AccessTokenErrorResponse extends ApiResponse {
|
|
88
|
+
instruction = "refresh_token";
|
|
89
|
+
errors;
|
|
90
|
+
constructor(message, errors) {
|
|
91
|
+
super(ResponseStatusCode.UNAUTHORIZED, message, StatusCode.IN_VALID_ACCESS_TOKEN);
|
|
92
|
+
this.errors = errors || [];
|
|
93
|
+
}
|
|
94
|
+
send(res, headers = {}) {
|
|
95
|
+
headers.instruction = this.instruction;
|
|
96
|
+
this.prepare(res, this, headers);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.AccessTokenErrorResponse = AccessTokenErrorResponse;
|
|
100
|
+
class BadTokenResponse extends ApiResponse {
|
|
101
|
+
errors;
|
|
102
|
+
constructor(message, errors) {
|
|
103
|
+
super(ResponseStatusCode.UNAUTHORIZED, message, StatusCode.FAILURE);
|
|
104
|
+
this.errors = errors || [];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.BadTokenResponse = BadTokenResponse;
|
|
108
|
+
class BadRequestResponse extends ApiResponse {
|
|
109
|
+
errors;
|
|
110
|
+
constructor(message, errors) {
|
|
111
|
+
super(ResponseStatusCode.BAD_REQUEST, message, StatusCode.FAILURE);
|
|
112
|
+
this.errors = errors || [];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.BadRequestResponse = BadRequestResponse;
|
|
116
|
+
class InternalErrorResponse extends ApiResponse {
|
|
117
|
+
errors;
|
|
118
|
+
constructor(message, errors) {
|
|
119
|
+
super(ResponseStatusCode.INTERNAL_ERROR, message, StatusCode.FAILURE);
|
|
120
|
+
this.errors = errors || [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.InternalErrorResponse = InternalErrorResponse;
|
|
124
|
+
class NoFoundResponse extends ApiResponse {
|
|
125
|
+
errors;
|
|
126
|
+
constructor(message, errors) {
|
|
127
|
+
super(ResponseStatusCode.NOT_FOUND, message, StatusCode.FAILURE);
|
|
128
|
+
this.errors = errors || [];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.NoFoundResponse = NoFoundResponse;
|
|
132
|
+
class ForbiddenResponse extends ApiResponse {
|
|
133
|
+
errors;
|
|
134
|
+
constructor(message, errors) {
|
|
135
|
+
super(ResponseStatusCode.FORBIDDEN, message, StatusCode.FAILURE);
|
|
136
|
+
this.errors = errors || [];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.ForbiddenResponse = ForbiddenResponse;
|
|
140
|
+
//# sourceMappingURL=ApiResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiResponse.js","sourceRoot":"","sources":["../../src/core/ApiResponse.ts"],"names":[],"mappings":";;;AAGA,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,+BAAiB,CAAA;IACjB,+BAAiB,CAAA;IACjB,6BAAe,CAAA;IACf,6CAA+B,CAAA;AACjC,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAED,IAAY,kBA+BX;AA/BD,WAAY,kBAAkB;IAC5B,mEAAa,CAAA;IACb,mEAAa,CAAA;IACb,qEAAc,CAAA;IACd,yEAAgB,CAAA;IAEhB,uFAAuB,CAAA;IACvB,+DAAW,CAAA;IACX,6EAAkB,CAAA;IAClB,yFAAwB,CAAA;IACxB,yFAAwB,CAAA;IAExB,2EAAiB,CAAA;IACjB,6EAAkB,CAAA;IAClB,qFAAsB,CAAA;IACtB,uEAAe,CAAA;IACf,uEAAe,CAAA;IACf,yFAAwB,CAAA;IACxB,iFAAoB,CAAA;IACpB,qEAAc,CAAA;IACd,6DAAU,CAAA;IACV,uFAAuB,CAAA;IACvB,iGAA4B,CAAA;IAC5B,6FAA0B,CAAA;IAC1B,uFAAuB,CAAA;IAEvB,iFAAoB,CAAA;IACpB,mFAAqB,CAAA;IACrB,2EAAiB,CAAA;IACjB,2FAAyB,CAAA;IACzB,mFAAqB,CAAA;AACvB,CAAC,EA/BW,kBAAkB,kCAAlB,kBAAkB,QA+B7B;AAED,MAAsB,WAAW;IACxB,OAAO,CAAS;IAChB,UAAU,CAAqB;IAC/B,MAAM,CAAS;IAEtB,YAAY,MAAc,EAAE,OAAe,EAAE,UAAmB;QAC9D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,UAA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EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IAC7B,CAAC;CACF;AAPD,sDAOC;AAED,MAAa,eAAgB,SAAQ,WAAW;IACvC,MAAM,CAAoB;IAEjC,YAAY,OAAe,EAAE,MAAyB;QACpD,KAAK,CAAC,kBAAkB,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IAC7B,CAAC;CACF;AAPD,0CAOC;AAED,MAAa,iBAAkB,SAAQ,WAAW;IACzC,MAAM,CAAoB;IAEjC,YAAY,OAAe,EAAE,MAAyB;QACpD,KAAK,CAAC,kBAAkB,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IAC7B,CAAC;CACF;AAPD,8CAOC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const winston_1 = __importStar(require("winston"));
|
|
40
|
+
const fs_1 = __importDefault(require("fs"));
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
43
|
+
const config_1 = require("@/config/config");
|
|
44
|
+
let dir = config_1.sanitizedConfig.LOG_DIR;
|
|
45
|
+
if (!dir) {
|
|
46
|
+
dir = path_1.default.resolve("logs");
|
|
47
|
+
}
|
|
48
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
49
|
+
fs_1.default.mkdirSync(dir);
|
|
50
|
+
}
|
|
51
|
+
const logfileRotateTransport = new winston_daily_rotate_file_1.default({
|
|
52
|
+
level: config_1.sanitizedConfig.LOG_LEVEL,
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
filename: dir + "/%DATE%.log",
|
|
55
|
+
datePattern: "YYYY-MM-DD",
|
|
56
|
+
zippedArchive: true,
|
|
57
|
+
handleExceptions: true,
|
|
58
|
+
maxSize: "20m",
|
|
59
|
+
maxFiles: "14d",
|
|
60
|
+
format: winston_1.format.combine(winston_1.format.errors({ stack: true }), winston_1.format.timestamp(), winston_1.format.json()),
|
|
61
|
+
});
|
|
62
|
+
const consoleTransport = new winston_1.default.transports.Console({
|
|
63
|
+
level: process.env.LOG_LEVEL,
|
|
64
|
+
format: winston_1.format.combine(winston_1.format.colorize({ all: true }), winston_1.format.timestamp({
|
|
65
|
+
format: "YYYY-MM-DD hh:mm:ss.SSS A",
|
|
66
|
+
}), winston_1.format.align(), winston_1.format.printf((info) => `[${info.timestamp}] ${info.level}: ${info.message}`)),
|
|
67
|
+
});
|
|
68
|
+
const logger = winston_1.default.createLogger({
|
|
69
|
+
transports: [consoleTransport, logfileRotateTransport],
|
|
70
|
+
exceptionHandlers: [logfileRotateTransport],
|
|
71
|
+
exitOnError: false,
|
|
72
|
+
});
|
|
73
|
+
exports.default = logger;
|
|
74
|
+
//# sourceMappingURL=Logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/core/Logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAA0C;AAC1C,4CAAoB;AACpB,gDAAwB;AACxB,0FAAwD;AAExD,4CAAkD;AAElD,IAAI,GAAG,GAAG,wBAAe,CAAC,OAAO,CAAC;AAClC,IAAI,CAAC,GAAG,EAAE,CAAC;IACT,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IACxB,YAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AACpB,CAAC;AAED,MAAM,sBAAsB,GAAG,IAAI,mCAAe,CAAC;IACjD,KAAK,EAAE,wBAAe,CAAC,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";
|
|
2
|
+
export * from "@/core/ApiError";
|
|
3
|
+
export * from "@/core/ApiResponse";
|
|
4
|
+
export * from "@/core/Logger";
|
|
5
|
+
export * from "@/middlewares/schemaValidator";
|
|
6
|
+
export * from "@/middlewares/verifyToken";
|
|
7
|
+
export * from "@/services/jwt.service";
|
|
8
|
+
export * from "@/services/password.service";
|
|
9
|
+
export * from "@/types/validation";
|
|
10
|
+
export * from "@/utils/asyncHandler";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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);
|
|
7
15
|
};
|
|
8
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@/constants/environments"), exports);
|
|
18
|
+
__exportStar(require("@/core/ApiError"), exports);
|
|
19
|
+
__exportStar(require("@/core/ApiResponse"), exports);
|
|
20
|
+
__exportStar(require("@/core/Logger"), exports);
|
|
21
|
+
__exportStar(require("@/middlewares/schemaValidator"), exports);
|
|
22
|
+
__exportStar(require("@/middlewares/verifyToken"), exports);
|
|
23
|
+
__exportStar(require("@/services/jwt.service"), exports);
|
|
24
|
+
__exportStar(require("@/services/password.service"), exports);
|
|
25
|
+
__exportStar(require("@/types/validation"), exports);
|
|
26
|
+
__exportStar(require("@/utils/asyncHandler"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAwC;AACxC,kDAA+B;AAC/B,qDAAkC;AAClC,gDAA6B;AAC7B,gEAA6C;AAC7C,4DAAyC;AACzC,yDAAsC;AACtC,8DAA2C;AAC3C,qDAAkC;AAClC,uDAAoC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { ZodSchema } from "zod";
|
|
3
|
+
import { ValidationSource } from "@/types/validation";
|
|
4
|
+
declare const schemaValidator: (type: ValidationSource, schema: ZodSchema) => (req: Request, res: Response, next: NextFunction) => void;
|
|
5
|
+
export default schemaValidator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ApiError_1 = require("@/core/ApiError");
|
|
4
|
+
const schemaValidator = (type, schema) => {
|
|
5
|
+
return (req, res, next) => {
|
|
6
|
+
const result = schema.safeParse(req[type]);
|
|
7
|
+
if (!result.success) {
|
|
8
|
+
const errors = Object.entries(result.error.flatten().fieldErrors).map(([key, value]) => ({
|
|
9
|
+
field: key,
|
|
10
|
+
message: value,
|
|
11
|
+
}));
|
|
12
|
+
next(new ApiError_1.BadRequestError("Bad request", errors));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
next();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.default = schemaValidator;
|
|
20
|
+
//# sourceMappingURL=schemaValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaValidator.js","sourceRoot":"","sources":["../../src/middlewares/schemaValidator.ts"],"names":[],"mappings":";;AAGA,8CAAkD;AAGlD,MAAM,eAAe,GAAG,CAAC,IAAsB,EAAE,MAAiB,EAAE,EAAE;IACpE,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QACzD,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAC,GAAG,CACnE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;gBACjB,KAAK,EAAE,GAAG;gBACV,OAAO,EAAE,KAAK;aACf,CAAC,CACH,CAAC;YACF,IAAI,CAAC,IAAI,0BAAe,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACN,IAAI,EAAE,CAAC;QACT,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
7
|
+
const ApiError_1 = require("@/core/ApiError");
|
|
8
|
+
const jwt_service_1 = __importDefault(require("@/services/jwt.service"));
|
|
9
|
+
const verifyToken = async (req, res, next) => {
|
|
10
|
+
try {
|
|
11
|
+
const { token } = req?.session;
|
|
12
|
+
if (!token) {
|
|
13
|
+
next(new ApiError_1.BadTokenError("Authentication token is missing"));
|
|
14
|
+
}
|
|
15
|
+
const decoded = jwt_service_1.default.verify(token);
|
|
16
|
+
req.user = decoded;
|
|
17
|
+
next();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof jsonwebtoken_1.default.TokenExpiredError) {
|
|
21
|
+
next(new ApiError_1.TokenExpiredError());
|
|
22
|
+
}
|
|
23
|
+
else if (error instanceof jsonwebtoken_1.default.JsonWebTokenError) {
|
|
24
|
+
next(new ApiError_1.BadTokenError());
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
next(new ApiError_1.BadTokenError());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.default = verifyToken;
|
|
32
|
+
//# sourceMappingURL=verifyToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifyToken.js","sourceRoot":"","sources":["../../src/middlewares/verifyToken.ts"],"names":[],"mappings":";;;;;AAAA,gEAAwC;AAGxC,8CAAmE;AACnE,yEAAgE;AAE/D,MAAM,WAAW,GAAG,KAAK,EACxB,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,EAAE;IACF,IAAI,CAAC;QACH,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,EAAE,OAAO,CAAC;QAC/B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,IAAI,wBAAa,CAAC,iCAAiC,CAAC,CAAC,CAAC;QAC7D,CAAC;QAED,MAAM,OAAO,GAAG,qBAAU,CAAC,MAAM,CAAC,KAAK,CAAe,CAAC;QAEvD,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC;QACnB,IAAI,EAAE,CAAC;IACT,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,sBAAY,CAAC,iBAAiB,EAAE,CAAC;YACpD,IAAI,CAAC,IAAI,4BAAiB,EAAE,CAAC,CAAC;QAChC,CAAC;aAAM,IAAI,KAAK,YAAY,sBAAY,CAAC,iBAAiB,EAAE,CAAC;YAC3D,IAAI,CAAC,IAAI,wBAAa,EAAE,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,wBAAa,EAAE,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,kBAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import jsonwebtoken, { SignOptions, VerifyOptions } from "jsonwebtoken";
|
|
2
|
+
export interface JwtPayload {
|
|
3
|
+
_id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
}
|
|
6
|
+
declare class JwtService {
|
|
7
|
+
static sign(payload: string | Buffer | object, signOptions?: SignOptions): string;
|
|
8
|
+
static verify(token: string, verifyOptions?: VerifyOptions): string | jsonwebtoken.Jwt | jsonwebtoken.JwtPayload;
|
|
9
|
+
static generatePayload<T extends JwtPayload>(user: T): T;
|
|
10
|
+
}
|
|
11
|
+
export default JwtService;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const config_1 = require("@/config/config");
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
class JwtService {
|
|
9
|
+
static sign(payload, signOptions = {}) {
|
|
10
|
+
const token = jsonwebtoken_1.default.sign(payload, config_1.sanitizedConfig.JWT_KEY, signOptions);
|
|
11
|
+
return token;
|
|
12
|
+
}
|
|
13
|
+
static verify(token, verifyOptions) {
|
|
14
|
+
const decoded = jsonwebtoken_1.default.verify(token, config_1.sanitizedConfig.JWT_KEY, verifyOptions);
|
|
15
|
+
return decoded;
|
|
16
|
+
}
|
|
17
|
+
static generatePayload(user) {
|
|
18
|
+
return {
|
|
19
|
+
_id: user._id.toString(),
|
|
20
|
+
email: user.email,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = JwtService;
|
|
25
|
+
//# sourceMappingURL=jwt.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.service.js","sourceRoot":"","sources":["../../src/services/jwt.service.ts"],"names":[],"mappings":";;;;;AAAA,4CAAkD;AAClD,gEAAwE;AAOxE,MAAM,UAAU;IACd,MAAM,CAAC,IAAI,CACT,OAAiC,EACjC,cAA2B,EAAE;QAE7B,MAAM,KAAK,GAAG,sBAAY,CAAC,IAAI,CAC7B,OAAO,EACP,wBAAe,CAAC,OAAO,EACvB,WAAW,CACZ,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAa,EAAE,aAA6B;QACxD,MAAM,OAAO,GAAG,sBAAY,CAAC,MAAM,CACjC,KAAK,EACL,wBAAe,CAAC,OAAO,EACvB,aAAa,CACd,CAAC;QACF,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,eAAe,CAAuB,IAAO;QAClD,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE;YACxB,KAAK,EAAE,IAAI,CAAC,KAAK;SACb,CAAC;IACT,CAAC;CACF;AAED,kBAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const bcrypt_1 = __importDefault(require("bcrypt"));
|
|
7
|
+
class Password {
|
|
8
|
+
static hashPassword(password, salesRounds) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
bcrypt_1.default.hash(password, salesRounds, function (err, hash) {
|
|
11
|
+
if (err) {
|
|
12
|
+
reject(err.message);
|
|
13
|
+
}
|
|
14
|
+
resolve(hash);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
static comparePassword(password, hashedPassword) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
bcrypt_1.default.compare(password, hashedPassword, function (err, result) {
|
|
21
|
+
if (err) {
|
|
22
|
+
reject(err.message);
|
|
23
|
+
}
|
|
24
|
+
resolve(result);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = Password;
|
|
30
|
+
//# sourceMappingURL=password.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password.service.js","sourceRoot":"","sources":["../../src/services/password.service.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,MAAM,QAAQ;IACZ,MAAM,CAAC,YAAY,CAAC,QAAgB,EAAE,WAAmB;QACvD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,gBAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,GAAG,EAAE,IAAI;gBACpD,IAAI,GAAG,EAAE,CAAC;oBACR,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACtB,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,eAAe,CACpB,QAAgB,EAChB,cAAsB;QAEtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,gBAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,GAAG,EAAE,MAAM;gBAC5D,IAAI,GAAG,EAAE,CAAC;oBACR,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACtB,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationSource = void 0;
|
|
4
|
+
var ValidationSource;
|
|
5
|
+
(function (ValidationSource) {
|
|
6
|
+
ValidationSource["BODY"] = "body";
|
|
7
|
+
ValidationSource["HEADER"] = "headers";
|
|
8
|
+
ValidationSource["QUERY"] = "query";
|
|
9
|
+
ValidationSource["PARAM"] = "params";
|
|
10
|
+
})(ValidationSource || (exports.ValidationSource = ValidationSource = {}));
|
|
11
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/types/validation.ts"],"names":[],"mappings":";;;AAAA,IAAY,gBAKT;AALH,WAAY,gBAAgB;IACxB,iCAAa,CAAA;IACb,sCAAkB,CAAA;IAClB,mCAAe,CAAA;IACf,oCAAgB,CAAA;AAClB,CAAC,EALS,gBAAgB,gCAAhB,gBAAgB,QAKzB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
type AsyncFunction = (req: Request, res: Response, next: NextFunction) => Promise<any>;
|
|
3
|
+
declare const asyncHandler: (execution: AsyncFunction) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
4
|
+
export default asyncHandler;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const asyncHandler = (execution) => async (req, res, next) => {
|
|
4
|
+
try {
|
|
5
|
+
await execution(req, res, next);
|
|
6
|
+
}
|
|
7
|
+
catch (err) {
|
|
8
|
+
next(err);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
exports.default = asyncHandler;
|
|
12
|
+
//# sourceMappingURL=asyncHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncHandler.js","sourceRoot":"","sources":["../../src/utils/asyncHandler.ts"],"names":[],"mappings":";;AAQA,MAAM,YAAY,GAChB,CAAC,SAAwB,EAAE,EAAE,CAC7B,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,IAAI,CAAC;QACH,MAAM,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAEJ,kBAAe,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ajayjbtickets/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,7 +17,21 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"@types/bcrypt": "^5.0.2",
|
|
21
|
+
"@types/cookie-session": "^2.0.49",
|
|
22
|
+
"@types/express": "^5.0.1",
|
|
23
|
+
"@types/jsonwebtoken": "^9.0.9",
|
|
20
24
|
"del-cli": "^6.0.0",
|
|
21
25
|
"typescript": "^5.8.3"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"bcrypt": "^5.1.1",
|
|
29
|
+
"cookie-session": "^2.1.0",
|
|
30
|
+
"dotenv": "^16.5.0",
|
|
31
|
+
"express": "^5.1.0",
|
|
32
|
+
"jsonwebtoken": "^9.0.2",
|
|
33
|
+
"winston": "^3.17.0",
|
|
34
|
+
"winston-daily-rotate-file": "^5.0.0",
|
|
35
|
+
"zod": "^3.24.4"
|
|
22
36
|
}
|
|
23
37
|
}
|