powr-sdk-api 4.8.1 → 4.8.2

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.
@@ -5,34 +5,42 @@
5
5
  * (uses X-Forwarded-For, X-Real-IP, req.ip, or socket address).
6
6
  */
7
7
  function getClientIp(req) {
8
- const forwarded = req.headers["x-forwarded-for"];
9
- const realIp = req.headers["x-real-ip"];
8
+ const h = req.headers || {};
9
+ const signals = {
10
+ "x-forwarded-for": h["x-forwarded-for"],
11
+ "x-real-ip": h["x-real-ip"],
12
+ "cf-connecting-ip": h["cf-connecting-ip"],
13
+ "true-client-ip": h["true-client-ip"],
14
+ "x-client-ip": h["x-client-ip"],
15
+ forwarded: h["forwarded"],
16
+ reqIp: req.ip,
17
+ socketRemoteAddress: req.socket && req.socket.remoteAddress,
18
+ connectionRemoteAddress: req.connection && req.connection.remoteAddress
19
+ };
20
+ console.log("[getClientIp] IP signals (all candidates):", JSON.stringify(signals));
21
+ const forwarded = h["x-forwarded-for"];
10
22
  if (typeof forwarded === "string" && forwarded.length > 0) {
11
23
  const first = forwarded.split(",")[0].trim();
12
24
  if (first) {
13
- console.log("[getClientIp] using x-forwarded-for:", first);
25
+ console.log("[getClientIp] chosen: x-forwarded-for (first hop) ->", first);
14
26
  return first;
15
27
  }
16
28
  }
29
+ const realIp = h["x-real-ip"];
17
30
  if (typeof realIp === "string" && realIp.trim()) {
18
31
  const v = realIp.trim();
19
- console.log("[getClientIp] using x-real-ip:", v);
32
+ console.log("[getClientIp] chosen: x-real-ip ->", v);
20
33
  return v;
21
34
  }
22
35
  if (req.ip) {
23
- console.log("[getClientIp] using req.ip:", req.ip);
36
+ console.log("[getClientIp] chosen: req.ip ->", req.ip);
24
37
  return req.ip;
25
38
  }
26
39
  if (req.socket && req.socket.remoteAddress) {
27
- console.log("[getClientIp] using socket.remoteAddress:", req.socket.remoteAddress);
40
+ console.log("[getClientIp] chosen: socket.remoteAddress ->", req.socket.remoteAddress);
28
41
  return req.socket.remoteAddress;
29
42
  }
30
- console.log("[getClientIp] no IP found", {
31
- "x-forwarded-for": forwarded,
32
- "x-real-ip": realIp,
33
- reqIp: req.ip,
34
- remoteAddress: req.socket && req.socket.remoteAddress
35
- });
43
+ console.log("[getClientIp] chosen: none (no usable IP)");
36
44
  return null;
37
45
  }
38
46
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-api",
3
- "version": "4.8.1",
3
+ "version": "4.8.2",
4
4
  "description": "Shared API core library for PowrStack projects. Zero dependencies - works with Express, Next.js API routes, and other frameworks. All features are optional and install only what you need.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",