@go-mailer/jarvis 2.1.0 → 3.0.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/lib/clients/go-flags.js +2 -2
- package/lib/middlewares/auth.js +3 -3
- package/lib/middlewares/logger.js +94 -91
- package/package.json +1 -1
package/lib/clients/go-flags.js
CHANGED
|
@@ -3,13 +3,13 @@ const Env = require("../env");
|
|
|
3
3
|
const BASE_URI = Env.fetch("GO_FLAGS_URI", true);
|
|
4
4
|
const API_KEY = Env.fetch("GO_FLAGS_KEY", true);
|
|
5
5
|
|
|
6
|
-
const verifyFeatureFlag = async (flag_name, criteria = {}) => {
|
|
6
|
+
const verifyFeatureFlag = async (flag_name, criteria = {}, environment = '') => {
|
|
7
7
|
const { error, payload } = (
|
|
8
8
|
await axios.post(
|
|
9
9
|
`${BASE_URI}/api/v1/flags/${flag_name}`,
|
|
10
10
|
{
|
|
11
11
|
payload: criteria,
|
|
12
|
-
environment: Env.fetch("
|
|
12
|
+
environment: environment || Env.fetch("GO_FLAGS_ENV", true)
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
headers: {
|
package/lib/middlewares/auth.js
CHANGED
|
@@ -21,7 +21,7 @@ const extract_token = (headers) => {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
// main
|
|
24
|
-
const
|
|
24
|
+
const authenticateUser = async (request, response, next) => {
|
|
25
25
|
try {
|
|
26
26
|
// env vars
|
|
27
27
|
const DEFAULT_TOKEN = Env.fetch("DEFAULT_TOKEN", true);
|
|
@@ -43,7 +43,7 @@ const JWTAuth = async (request, response, next) => {
|
|
|
43
43
|
|
|
44
44
|
next();
|
|
45
45
|
} catch (e) {
|
|
46
|
-
authLogger.error(e, "
|
|
46
|
+
authLogger.error(e, "authenticateUser");
|
|
47
47
|
return response.status(403).json(Errors.UNAUTHORIZED);
|
|
48
48
|
}
|
|
49
49
|
};
|
|
@@ -70,4 +70,4 @@ const authenticateBearerKey = async (request, response, next) => {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
module.exports = { authenticateBearerKey, authenticateParamKey,
|
|
73
|
+
module.exports = { authenticateBearerKey, authenticateParamKey, authenticateUser };
|
|
@@ -2,94 +2,97 @@
|
|
|
2
2
|
* @author Oguntuberu Nathan O. <nateoguns.work@gmail.com>
|
|
3
3
|
**/
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
5
|
+
const Env = require("../env");
|
|
6
|
+
const { randomUUID } = require("crypto");
|
|
7
|
+
const { Logtail } = require("@logtail/node");
|
|
8
|
+
const LOGTAIL_SECRET = Env.fetch("LOGTAIL_SECRET", true);
|
|
9
|
+
const logtail = new Logtail(LOGTAIL_SECRET);
|
|
10
|
+
|
|
11
|
+
function RequestLogger() {
|
|
12
|
+
const app_name = Env.fetch("APP_NAME", true);
|
|
13
|
+
return (request, response, next) => {
|
|
14
|
+
if (!request.request_id) request.request_id = randomUUID();
|
|
15
|
+
|
|
16
|
+
//
|
|
17
|
+
const {
|
|
18
|
+
query,
|
|
19
|
+
params,
|
|
20
|
+
headers: { host, origin, "user-agent": user_agent, "sec-ch-ua-platform": os, referer },
|
|
21
|
+
request_id,
|
|
22
|
+
tenant_id,
|
|
23
|
+
} = request;
|
|
24
|
+
|
|
25
|
+
response.on("finish", () => {
|
|
26
|
+
const {
|
|
27
|
+
_parsedUrl: { pathname },
|
|
28
|
+
httpVersion,
|
|
29
|
+
_startTime,
|
|
30
|
+
_remoteAddress,
|
|
31
|
+
payload,
|
|
32
|
+
} = response.req;
|
|
33
|
+
const { statusCode, statusMessage } = response.req.res;
|
|
34
|
+
const duration = Date.now() - Date.parse(_startTime);
|
|
35
|
+
const log = {
|
|
36
|
+
app_name,
|
|
37
|
+
request_id,
|
|
38
|
+
tenant_id,
|
|
39
|
+
query,
|
|
40
|
+
params,
|
|
41
|
+
host,
|
|
42
|
+
origin,
|
|
43
|
+
user_agent,
|
|
44
|
+
os,
|
|
45
|
+
referer,
|
|
46
|
+
httpVersion,
|
|
47
|
+
_remoteAddress,
|
|
48
|
+
pathname,
|
|
49
|
+
duration,
|
|
50
|
+
type: "request",
|
|
51
|
+
status_code: payload ? payload.status_code : statusCode,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
let error = payload ? payload.error : statusMessage;
|
|
55
|
+
if (error) {
|
|
56
|
+
log.error = error;
|
|
57
|
+
logtail.error(pathname, log);
|
|
58
|
+
} else {
|
|
59
|
+
logtail.info(pathname, log);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
logtail.flush();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
next();
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class ProcessLogger {
|
|
70
|
+
constructor(service = "System") {
|
|
71
|
+
this.service = service;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
error(error, method = "unspecified_method", params = {}) {
|
|
75
|
+
logtail.error(`${this.service}:${method}:${error.message}`, {
|
|
76
|
+
app_name: Env.fetch("APP_NAME", true),
|
|
77
|
+
type: "process",
|
|
78
|
+
message: error.message,
|
|
79
|
+
trace: error.stack,
|
|
80
|
+
params,
|
|
81
|
+
});
|
|
82
|
+
logtail.flush();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
info(info, method = "unspecified_method", params = {}) {
|
|
86
|
+
const message_str = `${this.service}:${method}:${info}`;
|
|
87
|
+
console.log(message_str);
|
|
88
|
+
logtail.info(message_str, {
|
|
89
|
+
app_name: Env.fetch("APP_NAME", true),
|
|
90
|
+
type: "process",
|
|
91
|
+
message: info,
|
|
92
|
+
params,
|
|
93
|
+
});
|
|
94
|
+
logtail.flush();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = { RequestLogger, ProcessLogger };
|