@vasrefil/api-toolkit 1.8.3 → 1.8.5
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/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,
|