@adwait12345/telemetry-express 0.1.2 → 0.1.3

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
@@ -27,7 +27,7 @@ var import_telemetry_core = require("@adwait12345/telemetry-core");
27
27
  function telemetryMiddleware(config) {
28
28
  return function(req, res, next) {
29
29
  const userAgent = req.get("user-agent") || "";
30
- const ip = req.ip || req.headers["x-forwarded-for"] || "";
30
+ const ip = (0, import_telemetry_core.extractClientIp)((h) => req.headers[h]) || req.ip || "";
31
31
  const path = req.originalUrl || req.url;
32
32
  if (config.ignorePaths) {
33
33
  for (const ignorePath of config.ignorePaths) {
@@ -40,7 +40,7 @@ function telemetryMiddleware(config) {
40
40
  }
41
41
  const normalizedReq = {
42
42
  userAgent,
43
- ip: Array.isArray(ip) ? ip[0] : ip.split(",")[0],
43
+ ip,
44
44
  path,
45
45
  method: req.method,
46
46
  referrer: req.get("referrer") || null,
package/dist/index.mjs CHANGED
@@ -2,12 +2,13 @@
2
2
  import {
3
3
  detectBot,
4
4
  extractAutomationHeaders,
5
+ extractClientIp,
5
6
  sendToTelemetry
6
7
  } from "@adwait12345/telemetry-core";
7
8
  function telemetryMiddleware(config) {
8
9
  return function(req, res, next) {
9
10
  const userAgent = req.get("user-agent") || "";
10
- const ip = req.ip || req.headers["x-forwarded-for"] || "";
11
+ const ip = extractClientIp((h) => req.headers[h]) || req.ip || "";
11
12
  const path = req.originalUrl || req.url;
12
13
  if (config.ignorePaths) {
13
14
  for (const ignorePath of config.ignorePaths) {
@@ -20,7 +21,7 @@ function telemetryMiddleware(config) {
20
21
  }
21
22
  const normalizedReq = {
22
23
  userAgent,
23
- ip: Array.isArray(ip) ? ip[0] : ip.split(",")[0],
24
+ ip,
24
25
  path,
25
26
  method: req.method,
26
27
  referrer: req.get("referrer") || null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adwait12345/telemetry-express",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Express middleware for Telemetry SDK - track AI bots and crawlers",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -12,12 +12,18 @@
12
12
  "types": "./dist/index.d.ts"
13
13
  }
14
14
  },
15
+ "scripts": {
16
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
17
+ "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
18
+ "typecheck": "tsc --noEmit",
19
+ "clean": "rm -rf dist"
20
+ },
15
21
  "files": [
16
22
  "dist",
17
23
  "README.md"
18
24
  ],
19
25
  "dependencies": {
20
- "@adwait12345/telemetry-core": ">=0.1.0"
26
+ "@adwait12345/telemetry-core": "^0.1.5"
21
27
  },
22
28
  "devDependencies": {
23
29
  "@types/express": "^4.17.21",
@@ -27,11 +33,5 @@
27
33
  },
28
34
  "peerDependencies": {
29
35
  "express": ">=4.0.0"
30
- },
31
- "scripts": {
32
- "build": "tsup src/index.ts --format esm,cjs --dts --clean",
33
- "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
34
- "typecheck": "tsc --noEmit",
35
- "clean": "rm -rf dist"
36
36
  }
37
37
  }