@vasrefil/api-toolkit 1.8.3 → 1.9.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/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const logger_util_1 = require("./utilities/logger.util");
|
|
|
14
14
|
// import { airbrake, airbrakeExpress } from './app-middlewares/airbrake';
|
|
15
15
|
const port = process.env.PORT || 8012;
|
|
16
16
|
const app = (0, express_1.default)();
|
|
17
|
+
app.set('trust proxy', true);
|
|
17
18
|
//configure application
|
|
18
19
|
app.use(express_1.default.static(path_1.default.join(__dirname, "public")));
|
|
19
20
|
//mount json form parser
|
package/dist/utilities/index.js
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClientIp = void 0;
|
|
4
|
+
const getClientIp = (req) => {
|
|
5
|
+
// Use req.ip (which Express populates if 'trust proxy' is set)
|
|
6
|
+
// or fallback to headers/connection
|
|
7
|
+
let ip = req.ip || req.headers['x-forwarded-for'] || req.connection.remoteAddress || '';
|
|
8
|
+
// If x-forwarded-for contains multiple IPs, the first one is the client
|
|
9
|
+
if (Array.isArray(ip)) {
|
|
10
|
+
ip = ip[0];
|
|
11
|
+
}
|
|
12
|
+
else if (typeof ip === 'string' && ip.includes(',')) {
|
|
13
|
+
ip = ip.split(',')[0].trim();
|
|
14
|
+
}
|
|
15
|
+
// Handle IPv6 mapped IPv4 (e.g., ::ffff:127.0.0.1 -> 127.0.0.1)
|
|
16
|
+
if (typeof ip === 'string' && ip.startsWith('::ffff:')) {
|
|
17
|
+
ip = ip.substring(7);
|
|
18
|
+
}
|
|
19
|
+
return ip;
|
|
20
|
+
};
|
|
21
|
+
exports.getClientIp = getClientIp;
|
|
@@ -8,6 +8,7 @@ const airbrake_1 = require("../app-middlewares/airbrake");
|
|
|
8
8
|
const api_request_util_1 = require("./api-request.util");
|
|
9
9
|
const json_stringify_safe = require('json-stringify-safe');
|
|
10
10
|
const env_1 = __importDefault(require("../env"));
|
|
11
|
+
const ip_util_1 = require("./ip.util");
|
|
11
12
|
class LogUtil_ {
|
|
12
13
|
constructor() {
|
|
13
14
|
this.user_event = async (dto) => {
|
|
@@ -61,7 +62,7 @@ class LogUtil_ {
|
|
|
61
62
|
const { password, pin, old_pin, new_pin, bvn, nin, file, ...body_ } = req.body;
|
|
62
63
|
const { params, query, method, url, statusCode, hostname, originalUrl, baseUrl } = req;
|
|
63
64
|
delete headers_['pin-token'];
|
|
64
|
-
const ip =
|
|
65
|
+
const ip = (0, ip_util_1.getClientIp)(req);
|
|
65
66
|
const request = {
|
|
66
67
|
params,
|
|
67
68
|
query,
|
|
@@ -99,6 +100,9 @@ class LogUtil_ {
|
|
|
99
100
|
// if(this.cronjobs_events.includes(actionType)) {
|
|
100
101
|
// distinct_id = 'cron-job.org';
|
|
101
102
|
// }
|
|
103
|
+
if (req.user_token_data) {
|
|
104
|
+
distinct_id = req.user_token_data.email;
|
|
105
|
+
}
|
|
102
106
|
if (actionType.toLowerCase().includes('webhook')) {
|
|
103
107
|
distinct_id = actionType.toLowerCase();
|
|
104
108
|
}
|