@vasrefil/api-toolkit 1.11.2 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/env.d.ts
CHANGED
|
@@ -14,19 +14,23 @@ declare const env: {
|
|
|
14
14
|
ERROR_MESSAGE: string;
|
|
15
15
|
VASREFIL: {
|
|
16
16
|
BASEURL: string;
|
|
17
|
-
API_KEY: string
|
|
17
|
+
API_KEY: string;
|
|
18
18
|
};
|
|
19
19
|
VAS_VOUCHER: {
|
|
20
20
|
BASEURL: string;
|
|
21
|
-
API_KEY: string
|
|
21
|
+
API_KEY: string;
|
|
22
22
|
};
|
|
23
23
|
EDUCATION: {
|
|
24
24
|
BASEURL: string;
|
|
25
|
-
API_KEY: string
|
|
25
|
+
API_KEY: string;
|
|
26
26
|
};
|
|
27
27
|
LOG: {
|
|
28
28
|
BASEURL: string;
|
|
29
|
-
API_KEY: string
|
|
29
|
+
API_KEY: string;
|
|
30
|
+
};
|
|
31
|
+
LOYALTY: {
|
|
32
|
+
BASEURL: string;
|
|
33
|
+
API_KEY: string;
|
|
30
34
|
};
|
|
31
35
|
AIRBRAKE: {
|
|
32
36
|
PROJECT_ID: number;
|
package/dist/env.js
CHANGED
|
@@ -37,6 +37,10 @@ const env = {
|
|
|
37
37
|
BASEURL: process.env.NODE_ENV === NODE_ENVS.PROD ? 'https://log-api.vasrefil.com' : 'https://log-api-dev.vasrefil.com',
|
|
38
38
|
API_KEY: process.env.VASREFIL_LOG_API_KEY
|
|
39
39
|
},
|
|
40
|
+
LOYALTY: {
|
|
41
|
+
BASEURL: process.env.NODE_ENV === NODE_ENVS.PROD ? 'https://loyalty-api.vasrefil.com' : 'https://loyalty-api-dev.vasrefil.com',
|
|
42
|
+
API_KEY: process.env.VASREFIL_LOYALTY_API_KEY
|
|
43
|
+
},
|
|
40
44
|
AIRBRAKE: {
|
|
41
45
|
PROJECT_ID: process.env.AIRBRAKE_PROJECT_ID,
|
|
42
46
|
PROJECT_KEY: process.env.AIRBRAKE_PROJECT_KEY
|
package/dist/interfaces/index.js
CHANGED
|
@@ -22,3 +22,4 @@ __exportStar(require("./env.interface"), exports);
|
|
|
22
22
|
__exportStar(require("./transaction.interface"), exports);
|
|
23
23
|
__exportStar(require("./voucher.interface"), exports);
|
|
24
24
|
__exportStar(require("./job.interface"), exports);
|
|
25
|
+
__exportStar(require("./log.interface"), exports);
|
|
@@ -2,11 +2,13 @@ import { Response, NextFunction } from 'express';
|
|
|
2
2
|
import { RootService } from '../services/_root.service';
|
|
3
3
|
import { AdminRequestI } from '../interfaces/admin.interface';
|
|
4
4
|
declare class AdminAuthMidWare_ extends RootService {
|
|
5
|
+
private get_admin;
|
|
6
|
+
private validate_auth;
|
|
5
7
|
auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
|
|
6
8
|
voucher_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
|
|
7
9
|
edu_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
|
|
8
10
|
log_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
|
|
9
|
-
|
|
11
|
+
loyalty_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
|
|
10
12
|
}
|
|
11
13
|
declare const AdminAuthMidWare: AdminAuthMidWare_;
|
|
12
14
|
export { AdminAuthMidWare };
|
|
@@ -12,82 +12,6 @@ const request_helper_1 = require("../helpers/request.helper");
|
|
|
12
12
|
class AdminAuthMidWare_ extends _root_service_1.RootService {
|
|
13
13
|
constructor() {
|
|
14
14
|
super(...arguments);
|
|
15
|
-
this.auth = async (req, res, next) => {
|
|
16
|
-
const actionType = 'ADMIN_AUTH_MIDWARE';
|
|
17
|
-
try {
|
|
18
|
-
const apiKey = req.headers['api-key'];
|
|
19
|
-
if (apiKey) {
|
|
20
|
-
if (apiKey !== env_1.default.VASREFIL.API_KEY)
|
|
21
|
-
throw user_response_1.UserApiResp.NO_API_KEY;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const { admin_user } = await this.get_admin(req);
|
|
25
|
-
req.admin = admin_user;
|
|
26
|
-
}
|
|
27
|
-
next();
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
const { status, message, data } = this.get_error(error);
|
|
31
|
-
return this.sendResponse({ req, res, status, actionType, message, data, error });
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
this.voucher_auth = async (req, res, next) => {
|
|
35
|
-
const actionType = 'VOUCHER_ADMIN_AUTH_MIDWARE';
|
|
36
|
-
try {
|
|
37
|
-
const apiKey = req.headers['api-key'];
|
|
38
|
-
if (apiKey) {
|
|
39
|
-
if (apiKey !== env_1.default.VAS_VOUCHER.API_KEY)
|
|
40
|
-
throw user_response_1.UserApiResp.NO_API_KEY;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const { admin_user } = await this.get_admin(req);
|
|
44
|
-
req.admin = admin_user;
|
|
45
|
-
}
|
|
46
|
-
next();
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
const { status, message, data } = this.get_error(error);
|
|
50
|
-
return this.sendResponse({ req, res, status, actionType, message, data, error });
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
this.edu_auth = async (req, res, next) => {
|
|
54
|
-
const actionType = 'EDU_ADMIN_AUTH_MIDWARE';
|
|
55
|
-
try {
|
|
56
|
-
const apiKey = req.headers['api-key'];
|
|
57
|
-
if (apiKey) {
|
|
58
|
-
if (apiKey !== env_1.default.EDUCATION.API_KEY)
|
|
59
|
-
throw user_response_1.UserApiResp.NO_API_KEY;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
const { admin_user } = await this.get_admin(req);
|
|
63
|
-
req.admin = admin_user;
|
|
64
|
-
}
|
|
65
|
-
next();
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
const { status, message, data } = this.get_error(error);
|
|
69
|
-
return this.sendResponse({ req, res, status, actionType, message, data, error });
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
this.log_auth = async (req, res, next) => {
|
|
73
|
-
const actionType = 'LOG_ADMIN_AUTH_MIDWARE';
|
|
74
|
-
try {
|
|
75
|
-
const apiKey = req.headers['api-key'];
|
|
76
|
-
if (apiKey) {
|
|
77
|
-
if (apiKey !== env_1.default.LOG.API_KEY)
|
|
78
|
-
throw user_response_1.UserApiResp.NO_API_KEY;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
const { admin_user } = await this.get_admin(req);
|
|
82
|
-
req.admin = admin_user;
|
|
83
|
-
}
|
|
84
|
-
next();
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
const { status, message, data } = this.get_error(error);
|
|
88
|
-
return this.sendResponse({ req, res, status, actionType, message, data, error });
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
15
|
this.get_admin = async (req) => {
|
|
92
16
|
try {
|
|
93
17
|
const baseurl = env_1.default.VASREFIL.BASEURL;
|
|
@@ -106,6 +30,31 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
|
|
|
106
30
|
throw err;
|
|
107
31
|
}
|
|
108
32
|
};
|
|
33
|
+
this.validate_auth = (valid_api_key, actionType) => {
|
|
34
|
+
return async (req, res, next) => {
|
|
35
|
+
try {
|
|
36
|
+
const apiKey = req.headers['api-key'];
|
|
37
|
+
if (apiKey) {
|
|
38
|
+
if (apiKey !== valid_api_key)
|
|
39
|
+
throw user_response_1.UserApiResp.NO_API_KEY;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const { admin_user } = await this.get_admin(req);
|
|
43
|
+
req.admin = admin_user;
|
|
44
|
+
}
|
|
45
|
+
next();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const { status, message, data } = this.get_error(error);
|
|
49
|
+
return this.sendResponse({ req, res, status, actionType, message, data, error });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
this.auth = this.validate_auth(env_1.default.VASREFIL.API_KEY, 'ADMIN_AUTH_MIDWARE');
|
|
54
|
+
this.voucher_auth = this.validate_auth(env_1.default.VAS_VOUCHER.API_KEY, 'VOUCHER_ADMIN_AUTH_MIDWARE');
|
|
55
|
+
this.edu_auth = this.validate_auth(env_1.default.EDUCATION.API_KEY, 'EDU_ADMIN_AUTH_MIDWARE');
|
|
56
|
+
this.log_auth = this.validate_auth(env_1.default.LOG.API_KEY, 'LOG_ADMIN_AUTH_MIDWARE');
|
|
57
|
+
this.loyalty_auth = this.validate_auth(env_1.default.LOYALTY.API_KEY, 'LOYALTY_ADMIN_AUTH_MIDWARE');
|
|
109
58
|
}
|
|
110
59
|
}
|
|
111
60
|
const AdminAuthMidWare = new AdminAuthMidWare_;
|