@vasrefil/api-toolkit 1.2.8 → 1.3.0
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/utilities/go-mailer.util.js +2 -2
- package/package.json +1 -1
- package/dist/middlewares/auth.midware.d.ts +0 -8
- package/dist/middlewares/auth.midware.js +0 -52
- package/dist/out-tsc/api-response/user.response.d.ts +0 -48
- package/dist/out-tsc/api-response/user.response.js +0 -33
- package/dist/out-tsc/app-middlewares/airbrake.d.ts +0 -10
- package/dist/out-tsc/app-middlewares/airbrake.js +0 -58
- package/dist/out-tsc/controllers/_root.control.d.ts +0 -53
- package/dist/out-tsc/controllers/_root.control.js +0 -127
- package/dist/out-tsc/controllers/index.d.ts +0 -1
- package/dist/out-tsc/controllers/index.js +0 -17
- package/dist/out-tsc/controllers/sample.control.d.ts +0 -6
- package/dist/out-tsc/controllers/sample.control.js +0 -13
- package/dist/out-tsc/env.d.ts +0 -12
- package/dist/out-tsc/env.js +0 -16
- package/dist/out-tsc/helpers/currency-formatter.helper.d.ts +0 -1
- package/dist/out-tsc/helpers/currency-formatter.helper.js +0 -11
- package/dist/out-tsc/helpers/query.helper.d.ts +0 -22
- package/dist/out-tsc/helpers/query.helper.js +0 -133
- package/dist/out-tsc/index.d.ts +0 -1
- package/dist/out-tsc/index.js +0 -41
- package/dist/out-tsc/interfaces/interface.d.ts +0 -27
- package/dist/out-tsc/interfaces/interface.js +0 -2
- package/dist/out-tsc/interfaces/root-controller.interface.d.ts +0 -21
- package/dist/out-tsc/interfaces/root-controller.interface.js +0 -2
- package/dist/out-tsc/interfaces/status.interface.d.ts +0 -13
- package/dist/out-tsc/interfaces/status.interface.js +0 -17
- package/dist/out-tsc/middlewares/auth.midware.d.ts +0 -8
- package/dist/out-tsc/middlewares/auth.midware.js +0 -52
- package/dist/out-tsc/middlewares/validator.midware.d.ts +0 -12
- package/dist/out-tsc/middlewares/validator.midware.js +0 -32
- package/dist/out-tsc/models/_config.d.ts +0 -1
- package/dist/out-tsc/models/_config.js +0 -27
- package/dist/out-tsc/models/sample.model.d.ts +0 -33
- package/dist/out-tsc/models/sample.model.js +0 -14
- package/dist/out-tsc/public-api.d.ts +0 -1
- package/dist/out-tsc/public-api.js +0 -17
- package/dist/out-tsc/routes/index.route.d.ts +0 -9
- package/dist/out-tsc/routes/index.route.js +0 -54
- package/dist/out-tsc/routes/sample.route.d.ts +0 -16
- package/dist/out-tsc/routes/sample.route.js +0 -53
- package/dist/out-tsc/services/_root.service.d.ts +0 -12
- package/dist/out-tsc/services/_root.service.js +0 -75
- package/dist/out-tsc/services/sample.service.d.ts +0 -16
- package/dist/out-tsc/services/sample.service.js +0 -127
- package/dist/out-tsc/utilities/date.util.d.ts +0 -42
- package/dist/out-tsc/utilities/date.util.js +0 -93
- package/dist/out-tsc/utilities/logger.util.d.ts +0 -4
- package/dist/out-tsc/utilities/logger.util.js +0 -48
- package/dist/out-tsc/utilities/token.util.d.ts +0 -6
- package/dist/out-tsc/utilities/token.util.js +0 -48
- package/dist/out-tsc/validations/sample.validator.d.ts +0 -6
- package/dist/out-tsc/validations/sample.validator.js +0 -35
- package/dist/package.json +0 -54
- package/dist/utilities/token.util.d.ts +0 -6
- package/dist/utilities/token.util.js +0 -48
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RootService = void 0;
|
|
4
|
-
const logger_util_1 = require("../utilities/logger.util");
|
|
5
|
-
const status_interface_1 = require("../interfaces/status.interface");
|
|
6
|
-
class RootService {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.sendResponse = (serviceResponse) => {
|
|
9
|
-
let { res, status, data, message, actionType, error } = serviceResponse;
|
|
10
|
-
try {
|
|
11
|
-
status = status || status_interface_1.Status.ERROR;
|
|
12
|
-
const code = error && error.code ? error.code : null;
|
|
13
|
-
const response = { status, data, message, code };
|
|
14
|
-
if (error) {
|
|
15
|
-
response.error = this.get_error_(error);
|
|
16
|
-
}
|
|
17
|
-
const status_code = this.getHttpStatus(status);
|
|
18
|
-
res.status(status_code).json(response);
|
|
19
|
-
if (status_code >= 400) {
|
|
20
|
-
const dataErr = data ? JSON.stringify(data) : data;
|
|
21
|
-
const error = `[${actionType || 'App Error'}] ${response.message} ${dataErr}`;
|
|
22
|
-
logger_util_1.winston.error(error);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
res.status(500).json({ status: 'ERROR', data: error, message: error.message });
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
this.get_error_ = (err) => {
|
|
30
|
-
const error = err && err.error ? err.error : err;
|
|
31
|
-
const { req, message, status, code, ...err_rest } = error;
|
|
32
|
-
return err_rest;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
get_error(error) {
|
|
36
|
-
let response = { status: status_interface_1.Status.ERROR, message: 'Request failed', data: null };
|
|
37
|
-
const { status, message, data } = error;
|
|
38
|
-
response.status = status ? status : response.status;
|
|
39
|
-
response.message = message ? message : response.message;
|
|
40
|
-
response.data = data ? data : response.data;
|
|
41
|
-
return response;
|
|
42
|
-
}
|
|
43
|
-
getHttpStatus(status) {
|
|
44
|
-
switch (status) {
|
|
45
|
-
case 'SUCCESS':
|
|
46
|
-
case 'PROCESSING':
|
|
47
|
-
return 200;
|
|
48
|
-
case 'CREATED':
|
|
49
|
-
return 201;
|
|
50
|
-
case 'SUCCESS_NO_CONTENT':
|
|
51
|
-
return 204;
|
|
52
|
-
case 'FAILED_VALIDATION':
|
|
53
|
-
return 400;
|
|
54
|
-
case 'UN_AUTHORIZED':
|
|
55
|
-
return 401;
|
|
56
|
-
case 'FORBIDDEN':
|
|
57
|
-
return 403;
|
|
58
|
-
case 'NOT_FOUND':
|
|
59
|
-
return 404;
|
|
60
|
-
case 'CONFLICT':
|
|
61
|
-
return 409;
|
|
62
|
-
case 'UNPROCESSABLE_ENTRY':
|
|
63
|
-
return 422;
|
|
64
|
-
case 'UNATHORIZED':
|
|
65
|
-
return 401;
|
|
66
|
-
case 'PRECONDITION_FAILED':
|
|
67
|
-
return 412;
|
|
68
|
-
case 'ERROR':
|
|
69
|
-
return 500;
|
|
70
|
-
default:
|
|
71
|
-
return 400;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.RootService = RootService;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Response, Request } from 'express';
|
|
2
|
-
import { RootService } from './_root.service';
|
|
3
|
-
declare class SampleService extends RootService {
|
|
4
|
-
create: (req: Request, res: Response) => Promise<void>;
|
|
5
|
-
getAll: (req: Request, res: Response) => Promise<void>;
|
|
6
|
-
getOne: (req: Request, res: Response) => Promise<void>;
|
|
7
|
-
getById: (req: Request, res: Response) => Promise<void>;
|
|
8
|
-
updateOne: (req: Request, res: Response) => Promise<any>;
|
|
9
|
-
updateMany: (req: Request, res: Response) => Promise<any>;
|
|
10
|
-
updateById: (req: Request, res: Response) => Promise<any>;
|
|
11
|
-
deleteOne: (req: Request, res: Response) => Promise<any>;
|
|
12
|
-
deleteMany: (req: Request, res: Response) => Promise<any>;
|
|
13
|
-
deleteById: (req: Request, res: Response) => Promise<any>;
|
|
14
|
-
}
|
|
15
|
-
declare const _default: SampleService;
|
|
16
|
-
export default _default;
|
|
@@ -1,127 +0,0 @@
|
|
|
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 sample_control_1 = __importDefault(require("../controllers/sample.control"));
|
|
7
|
-
const _root_service_1 = require("./_root.service");
|
|
8
|
-
const status_interface_1 = require("../interfaces/status.interface");
|
|
9
|
-
const { SUCCESS, ERROR, UNPROCESSABLE_ENTRY, PRECONDITION_FAILED, SUCCESS_NO_CONTENT } = status_interface_1.Status;
|
|
10
|
-
class SampleService extends _root_service_1.RootService {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.create = async (req, res) => {
|
|
14
|
-
const actionType = 'CREATE_SAMPLE';
|
|
15
|
-
try {
|
|
16
|
-
const sample = await sample_control_1.default.create(req.body);
|
|
17
|
-
this.sendResponse({ req, res, status: SUCCESS, data: sample, actionType });
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
this.getAll = async (req, res) => {
|
|
24
|
-
const actionType = 'GET_ALL_SAMPLES';
|
|
25
|
-
try {
|
|
26
|
-
const samples = await sample_control_1.default.fetchAll({}, req.query);
|
|
27
|
-
this.sendResponse({ req, res, status: SUCCESS, actionType, data: samples });
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
this.getOne = async (req, res) => {
|
|
34
|
-
const actionType = 'GET_ONE_SAMPLE';
|
|
35
|
-
try {
|
|
36
|
-
const sample = await sample_control_1.default.getOne(req.query);
|
|
37
|
-
this.sendResponse({ req, res, status: SUCCESS, actionType, data: sample });
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
this.getById = async (req, res) => {
|
|
44
|
-
const actionType = 'GET_SAMPLE_BY_ID';
|
|
45
|
-
try {
|
|
46
|
-
const sample = await sample_control_1.default.getById(req.params.id);
|
|
47
|
-
this.sendResponse({ req, res, status: SUCCESS, actionType, data: sample });
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
this.updateOne = async (req, res) => {
|
|
54
|
-
const actionType = 'UPDATE_ONE_SAMPLE';
|
|
55
|
-
try {
|
|
56
|
-
const sample = await sample_control_1.default.updateOne(req.query, req.body);
|
|
57
|
-
if (sample.acknowledged)
|
|
58
|
-
return this.sendResponse({ req, res, status: SUCCESS, actionType, data: sample });
|
|
59
|
-
this.sendResponse({ req, res, status: UNPROCESSABLE_ENTRY, actionType, data: 'data not updated' });
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
this.updateMany = async (req, res) => {
|
|
66
|
-
const actionType = 'UPDATE_MANY_SAMPLE';
|
|
67
|
-
try {
|
|
68
|
-
const sample = await sample_control_1.default.updateMany(req.query, req.body);
|
|
69
|
-
if (sample.acknowledged)
|
|
70
|
-
return this.sendResponse({ req, res, status: SUCCESS, actionType, data: sample });
|
|
71
|
-
this.sendResponse({ req, res, status: UNPROCESSABLE_ENTRY, actionType, data: 'data not updated' });
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
this.updateById = async (req, res) => {
|
|
78
|
-
const actionType = 'UPDATE_SAMPLE_BY_ID';
|
|
79
|
-
try {
|
|
80
|
-
const sample = await sample_control_1.default.updateById(req.params.id, req.body);
|
|
81
|
-
if (sample)
|
|
82
|
-
return this.sendResponse({ req, res, status: SUCCESS, actionType, data: sample });
|
|
83
|
-
this.sendResponse({ req, res, status: PRECONDITION_FAILED, actionType, data: 'data not updated' });
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
this.deleteOne = async (req, res) => {
|
|
90
|
-
const actionType = 'DELETE_ONE_SAMPLE';
|
|
91
|
-
try {
|
|
92
|
-
const sample = await sample_control_1.default.deleteOne(req.query);
|
|
93
|
-
if (sample.acknowledged)
|
|
94
|
-
return this.sendResponse({ req, res, status: SUCCESS_NO_CONTENT, actionType, data: sample });
|
|
95
|
-
this.sendResponse({ req, res, status: UNPROCESSABLE_ENTRY, actionType, data: 'data not deleted' });
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
this.deleteMany = async (req, res) => {
|
|
102
|
-
const actionType = 'DELETE_MANY_SAMPLES';
|
|
103
|
-
try {
|
|
104
|
-
const sample = await sample_control_1.default.deleteMany(req.query);
|
|
105
|
-
if (sample.acknowledged)
|
|
106
|
-
return this.sendResponse({ req, res, status: SUCCESS_NO_CONTENT, actionType, data: sample });
|
|
107
|
-
this.sendResponse({ req, res, status: UNPROCESSABLE_ENTRY, actionType, data: 'data not deleted' });
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
this.deleteById = async (req, res) => {
|
|
114
|
-
const actionType = 'DELETE_SAMPLE_BY_ID';
|
|
115
|
-
try {
|
|
116
|
-
const sample = await sample_control_1.default.deleteById(req.params.id);
|
|
117
|
-
if (sample)
|
|
118
|
-
return this.sendResponse({ req, res, status: SUCCESS_NO_CONTENT, actionType, data: sample });
|
|
119
|
-
this.sendResponse({ req, res, status: PRECONDITION_FAILED, actionType, data: 'data not deleted' });
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
this.sendResponse({ req, res, status: ERROR, actionType, data: error });
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.default = new SampleService;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
declare class DateUtil_ {
|
|
2
|
-
get_local_date: (date?: Date) => Date;
|
|
3
|
-
get_start_date(date: any): number;
|
|
4
|
-
get_end_date(date: any): number;
|
|
5
|
-
get_date_format(date: Date, format: string): Date;
|
|
6
|
-
get_today_date_range(payload?: {
|
|
7
|
-
format?: string;
|
|
8
|
-
date: Date;
|
|
9
|
-
}): {
|
|
10
|
-
start_date: any;
|
|
11
|
-
end_date: any;
|
|
12
|
-
};
|
|
13
|
-
get_date_range(payload?: {
|
|
14
|
-
format?: string;
|
|
15
|
-
date: Date;
|
|
16
|
-
number_of_days?: number;
|
|
17
|
-
}): {
|
|
18
|
-
start_date: any;
|
|
19
|
-
end_date: any;
|
|
20
|
-
};
|
|
21
|
-
get_custom_date_range({ start_date, end_date }: {
|
|
22
|
-
start_date: Date;
|
|
23
|
-
end_date: Date;
|
|
24
|
-
}): {
|
|
25
|
-
start_date: Date;
|
|
26
|
-
end_date: Date;
|
|
27
|
-
};
|
|
28
|
-
this_week_date_range(): {
|
|
29
|
-
start_date: Date;
|
|
30
|
-
end_date: Date;
|
|
31
|
-
};
|
|
32
|
-
this_month_date_range(): {
|
|
33
|
-
start_date: Date;
|
|
34
|
-
end_date: Date;
|
|
35
|
-
};
|
|
36
|
-
this_year_date_range(): {
|
|
37
|
-
start_date: Date;
|
|
38
|
-
end_date: Date;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
declare const DateUtil: DateUtil_;
|
|
42
|
-
export { DateUtil };
|
|
@@ -1,93 +0,0 @@
|
|
|
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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.DateUtil = void 0;
|
|
27
|
-
const dateFns = __importStar(require("date-fns"));
|
|
28
|
-
class DateUtil_ {
|
|
29
|
-
constructor() {
|
|
30
|
-
this.get_local_date = (date = new Date()) => {
|
|
31
|
-
const currentDate = new Date(date);
|
|
32
|
-
// const localOffset = currentDate.getTimezoneOffset() * 60000;
|
|
33
|
-
// const localDate = new Date(currentDate.getTime() - localOffset);
|
|
34
|
-
return currentDate;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
get_start_date(date) {
|
|
38
|
-
const d = this.get_local_date(date);
|
|
39
|
-
d.setHours(0, 0, 0, 0);
|
|
40
|
-
return d.getTime();
|
|
41
|
-
}
|
|
42
|
-
get_end_date(date) {
|
|
43
|
-
const d = this.get_local_date(date);
|
|
44
|
-
d.setHours(23, 0, 0, 0);
|
|
45
|
-
return d.getTime();
|
|
46
|
-
}
|
|
47
|
-
get_date_format(date, format) {
|
|
48
|
-
return this.get_local_date(date);
|
|
49
|
-
}
|
|
50
|
-
get_today_date_range(payload) {
|
|
51
|
-
const main_date = payload && payload.date ? this.get_local_date(payload.date) : this.get_local_date();
|
|
52
|
-
return {
|
|
53
|
-
start_date: dateFns.startOfDay(main_date),
|
|
54
|
-
end_date: dateFns.endOfDay(main_date)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
get_date_range(payload) {
|
|
58
|
-
const main_date = payload && payload.date ? this.get_local_date(payload.date) : this.get_local_date();
|
|
59
|
-
const number_of_days = payload?.number_of_days ? payload.number_of_days : 0;
|
|
60
|
-
const start_date = dateFns.subDays(main_date, number_of_days);
|
|
61
|
-
const end_date = dateFns.addDays(main_date, number_of_days);
|
|
62
|
-
return {
|
|
63
|
-
start_date: dateFns.startOfDay(start_date),
|
|
64
|
-
end_date: dateFns.endOfDay(end_date)
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
get_custom_date_range({ start_date, end_date }) {
|
|
68
|
-
return {
|
|
69
|
-
start_date: dateFns.startOfDay(this.get_local_date(start_date)),
|
|
70
|
-
end_date: dateFns.endOfDay(this.get_local_date(end_date))
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
this_week_date_range() {
|
|
74
|
-
return {
|
|
75
|
-
start_date: dateFns.startOfWeek(this.get_local_date()),
|
|
76
|
-
end_date: dateFns.endOfWeek(this.get_local_date())
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
this_month_date_range() {
|
|
80
|
-
return {
|
|
81
|
-
start_date: dateFns.startOfMonth(this.get_local_date()),
|
|
82
|
-
end_date: dateFns.endOfMonth(this.get_local_date())
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
this_year_date_range() {
|
|
86
|
-
return {
|
|
87
|
-
start_date: dateFns.startOfYear(this.get_local_date()),
|
|
88
|
-
end_date: dateFns.endOfYear(this.get_local_date())
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const DateUtil = new DateUtil_;
|
|
93
|
-
exports.DateUtil = DateUtil;
|
|
@@ -1,48 +0,0 @@
|
|
|
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.winston = exports.morgan = void 0;
|
|
7
|
-
const env_1 = __importDefault(require("../env"));
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const morgan_1 = __importDefault(require("morgan"));
|
|
11
|
-
const winston_1 = require("winston");
|
|
12
|
-
class LoggerUtil {
|
|
13
|
-
morgan() {
|
|
14
|
-
let dev_format = '[:date[web] :remote-addr :remote-user ] :method :url HTTP/:http-version | :status :response-time ms';
|
|
15
|
-
let prod_format = '[:date[web] :remote-addr :remote-user ] :method :url HTTP/:http-version :referrer - :user-agent | :status :response-time ms';
|
|
16
|
-
let morgan_format = env_1.default.NODE_ENV === 'prod' ? prod_format : dev_format;
|
|
17
|
-
let request_log_stream = (0, fs_1.createWriteStream)((0, path_1.resolve)(__dirname, `../../logs/request.log`), { flags: 'a' });
|
|
18
|
-
return (0, morgan_1.default)(morgan_format, { stream: request_log_stream });
|
|
19
|
-
}
|
|
20
|
-
winston() {
|
|
21
|
-
let { colorize, combine, printf, timestamp } = winston_1.format;
|
|
22
|
-
let log_transports = {
|
|
23
|
-
console: new winston_1.transports.Console({ level: 'warn' }),
|
|
24
|
-
combined_log: new winston_1.transports.File({ level: 'info', filename: `logs/combined.log` }),
|
|
25
|
-
error_log: new winston_1.transports.File({ level: 'error', filename: `logs/error.log` }),
|
|
26
|
-
exception_log: new winston_1.transports.File({ filename: 'logs/exception.log' }),
|
|
27
|
-
};
|
|
28
|
-
let log_format = printf(({ level, message, timestamp }) => `[${timestamp} : ${level}] - ${message}`);
|
|
29
|
-
let logger = (0, winston_1.createLogger)({
|
|
30
|
-
transports: [
|
|
31
|
-
log_transports.console,
|
|
32
|
-
log_transports.combined_log,
|
|
33
|
-
log_transports.error_log,
|
|
34
|
-
],
|
|
35
|
-
exceptionHandlers: [
|
|
36
|
-
log_transports.exception_log,
|
|
37
|
-
],
|
|
38
|
-
exitOnError: false,
|
|
39
|
-
format: combine(colorize(), timestamp(), log_format)
|
|
40
|
-
});
|
|
41
|
-
return logger;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const loggerUtil = new LoggerUtil();
|
|
45
|
-
const morgan = loggerUtil.morgan();
|
|
46
|
-
exports.morgan = morgan;
|
|
47
|
-
const winston = loggerUtil.winston();
|
|
48
|
-
exports.winston = winston;
|
|
@@ -1,48 +0,0 @@
|
|
|
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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const jwt = __importStar(require("jsonwebtoken"));
|
|
30
|
-
const env_1 = __importDefault(require("../env"));
|
|
31
|
-
const user_response_1 = require("../api-response/user.response");
|
|
32
|
-
class TokenUtil {
|
|
33
|
-
sign_admin_user(payload, expiresIn) {
|
|
34
|
-
return jwt.sign(payload, env_1.default?.ADMIN_JWT_KEY, { expiresIn: expiresIn ? expiresIn : '1d' });
|
|
35
|
-
}
|
|
36
|
-
verify_admin_user(token) {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
try {
|
|
39
|
-
const resp = jwt.verify(token, env_1.default.ADMIN_JWT_KEY);
|
|
40
|
-
resolve(resp);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
reject({ error, ...user_response_1.UserApiResp.NOT_AUTHORIZED });
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.default = new TokenUtil;
|
|
@@ -1,35 +0,0 @@
|
|
|
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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const joi = __importStar(require("joi"));
|
|
27
|
-
class SampleValidator {
|
|
28
|
-
constructor() {
|
|
29
|
-
this.create = joi.object({
|
|
30
|
-
name: joi.string().required(),
|
|
31
|
-
description: joi.string().required()
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.default = new SampleValidator;
|
package/dist/package.json
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@vasrefil/api-toolkit",
|
|
3
|
-
"description": "This is Vasrefil API toolkit",
|
|
4
|
-
"version": "1.0.43",
|
|
5
|
-
"author": "Sodiq Alabi",
|
|
6
|
-
"main": "dist/public-api.js",
|
|
7
|
-
"types": "dist/public-api.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"start": "ts-node-dev src/index.ts",
|
|
10
|
-
"build": "tsc",
|
|
11
|
-
"prepublishOnly": "npm run build",
|
|
12
|
-
"serve": "node dist/index.js",
|
|
13
|
-
"dev": "nodemon --exec ts-node src/index.ts",
|
|
14
|
-
"run-ts-node": "ts-node-dev"
|
|
15
|
-
},
|
|
16
|
-
"engines": {
|
|
17
|
-
"node": "20.11.0",
|
|
18
|
-
"npm": "10.2.4"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@airbrake/node": "^2.1.8",
|
|
22
|
-
"@types/jsonwebtoken": "^8.5.0",
|
|
23
|
-
"axios": "^1.7.8",
|
|
24
|
-
"chalk": "^4.1.0",
|
|
25
|
-
"cors": "^2.8.5",
|
|
26
|
-
"date-fns": "^2.29.3",
|
|
27
|
-
"dotenv": "^8.2.0",
|
|
28
|
-
"errorhandler": "^1.5.1",
|
|
29
|
-
"express": "^4.18.3",
|
|
30
|
-
"helmet": "^4.2.0",
|
|
31
|
-
"ioredis": "^5.4.1",
|
|
32
|
-
"joi": "^17.3.0",
|
|
33
|
-
"json-stringify-safe": "^5.0.1",
|
|
34
|
-
"mongoose": "^6.0.14",
|
|
35
|
-
"morgan": "^1.10.0",
|
|
36
|
-
"winston": "^3.3.3"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@types/body-parser": "1.19.0",
|
|
40
|
-
"@types/cors": "^2.8.17",
|
|
41
|
-
"@types/errorhandler": "1.5.0",
|
|
42
|
-
"@types/morgan": "^1.9.3",
|
|
43
|
-
"@types/node": "^14.14.7",
|
|
44
|
-
"cross-env": "^7.0.2",
|
|
45
|
-
"nodemon": "^3.1.0",
|
|
46
|
-
"ts-node": "^10.9.2",
|
|
47
|
-
"ts-node-dev": "^2.0.0",
|
|
48
|
-
"typescript": "^5.3.3"
|
|
49
|
-
},
|
|
50
|
-
"files": [
|
|
51
|
-
"dist",
|
|
52
|
-
"README.md"
|
|
53
|
-
]
|
|
54
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const jwt = __importStar(require("jsonwebtoken"));
|
|
30
|
-
const env_1 = __importDefault(require("../env"));
|
|
31
|
-
const user_response_1 = require("../api-response/user.response");
|
|
32
|
-
class TokenUtil {
|
|
33
|
-
sign_admin_user(payload, expiresIn) {
|
|
34
|
-
return jwt.sign(payload, env_1.default?.ADMIN_JWT_KEY, { expiresIn: expiresIn ? expiresIn : '1d' });
|
|
35
|
-
}
|
|
36
|
-
verify_admin_user(token) {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
try {
|
|
39
|
-
const resp = jwt.verify(token, env_1.default.ADMIN_JWT_KEY);
|
|
40
|
-
resolve(resp);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
reject({ error, ...user_response_1.UserApiResp.NOT_AUTHORIZED });
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.default = new TokenUtil;
|