@bbloker/sdk 0.3.0 → 0.4.1

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.
@@ -45,7 +45,7 @@ function normalizeExpressRequest(req) {
45
45
  headerNames.push(lower);
46
46
  }
47
47
  const forwarded = _optionalChain([headers, 'access', _ => _["x-forwarded-for"], 'optionalAccess', _2 => _2.split, 'call', _3 => _3(","), 'access', _4 => _4[0], 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]);
48
- const ip = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(req.ip, () => ( forwarded)), () => ( _optionalChain([req, 'access', _7 => _7.socket, 'optionalAccess', _8 => _8.remoteAddress]))), () => ( "0.0.0.0"));
48
+ const ip = stripIPv6Prefix(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(forwarded, () => ( headers["x-real-ip"])), () => ( req.ip)), () => ( _optionalChain([req, 'access', _7 => _7.socket, 'optionalAccess', _8 => _8.remoteAddress]))), () => ( "0.0.0.0")));
49
49
  return {
50
50
  ip,
51
51
  userAgent: _nullishCoalesce(headers["user-agent"], () => ( "")),
@@ -55,6 +55,9 @@ function normalizeExpressRequest(req) {
55
55
  method: _nullishCoalesce(req.method, () => ( "GET"))
56
56
  };
57
57
  }
58
+ function stripIPv6Prefix(ip) {
59
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
60
+ }
58
61
 
59
62
 
60
63
 
@@ -45,7 +45,7 @@ function normalizeExpressRequest(req) {
45
45
  headerNames.push(lower);
46
46
  }
47
47
  const forwarded = headers["x-forwarded-for"]?.split(",")[0]?.trim();
48
- const ip = req.ip ?? forwarded ?? req.socket?.remoteAddress ?? "0.0.0.0";
48
+ const ip = stripIPv6Prefix(forwarded ?? headers["x-real-ip"] ?? req.ip ?? req.socket?.remoteAddress ?? "0.0.0.0");
49
49
  return {
50
50
  ip,
51
51
  userAgent: headers["user-agent"] ?? "",
@@ -55,6 +55,9 @@ function normalizeExpressRequest(req) {
55
55
  method: req.method ?? "GET"
56
56
  };
57
57
  }
58
+ function stripIPv6Prefix(ip) {
59
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
60
+ }
58
61
  export {
59
62
  Bbloker,
60
63
  createMiddleware
@@ -48,7 +48,7 @@ function normalizeFastifyRequest(req) {
48
48
  headerNames.push(lower);
49
49
  }
50
50
  const forwarded = _optionalChain([headers, 'access', _ => _["x-forwarded-for"], 'optionalAccess', _2 => _2.split, 'call', _3 => _3(","), 'access', _4 => _4[0], 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]);
51
- const ip = _nullishCoalesce(_nullishCoalesce(req.ip, () => ( forwarded)), () => ( "0.0.0.0"));
51
+ const ip = stripIPv6Prefix(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(forwarded, () => ( headers["x-real-ip"])), () => ( req.ip)), () => ( "0.0.0.0")));
52
52
  return {
53
53
  ip,
54
54
  userAgent: _nullishCoalesce(headers["user-agent"], () => ( "")),
@@ -58,6 +58,9 @@ function normalizeFastifyRequest(req) {
58
58
  method: _nullishCoalesce(req.method, () => ( "GET"))
59
59
  };
60
60
  }
61
+ function stripIPv6Prefix(ip) {
62
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
63
+ }
61
64
 
62
65
 
63
66
 
@@ -48,7 +48,7 @@ function normalizeFastifyRequest(req) {
48
48
  headerNames.push(lower);
49
49
  }
50
50
  const forwarded = headers["x-forwarded-for"]?.split(",")[0]?.trim();
51
- const ip = req.ip ?? forwarded ?? "0.0.0.0";
51
+ const ip = stripIPv6Prefix(forwarded ?? headers["x-real-ip"] ?? req.ip ?? "0.0.0.0");
52
52
  return {
53
53
  ip,
54
54
  userAgent: headers["user-agent"] ?? "",
@@ -58,6 +58,9 @@ function normalizeFastifyRequest(req) {
58
58
  method: req.method ?? "GET"
59
59
  };
60
60
  }
61
+ function stripIPv6Prefix(ip) {
62
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
63
+ }
61
64
  export {
62
65
  Bbloker,
63
66
  createPlugin
@@ -39,7 +39,7 @@ function normalizeHonoRequest(c) {
39
39
  });
40
40
  const forwarded = _optionalChain([headers, 'access', _ => _["x-forwarded-for"], 'optionalAccess', _2 => _2.split, 'call', _3 => _3(","), 'access', _4 => _4[0], 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]);
41
41
  const cfIp = headers["cf-connecting-ip"];
42
- const ip = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(cfIp, () => ( forwarded)), () => ( headers["x-real-ip"])), () => ( "0.0.0.0"));
42
+ const ip = stripIPv6Prefix(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(cfIp, () => ( forwarded)), () => ( headers["x-real-ip"])), () => ( "0.0.0.0")));
43
43
  return {
44
44
  ip,
45
45
  userAgent: _nullishCoalesce(headers["user-agent"], () => ( "")),
@@ -49,6 +49,9 @@ function normalizeHonoRequest(c) {
49
49
  method: c.req.method
50
50
  };
51
51
  }
52
+ function stripIPv6Prefix(ip) {
53
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
54
+ }
52
55
 
53
56
 
54
57
 
@@ -39,7 +39,7 @@ function normalizeHonoRequest(c) {
39
39
  });
40
40
  const forwarded = headers["x-forwarded-for"]?.split(",")[0]?.trim();
41
41
  const cfIp = headers["cf-connecting-ip"];
42
- const ip = cfIp ?? forwarded ?? headers["x-real-ip"] ?? "0.0.0.0";
42
+ const ip = stripIPv6Prefix(cfIp ?? forwarded ?? headers["x-real-ip"] ?? "0.0.0.0");
43
43
  return {
44
44
  ip,
45
45
  userAgent: headers["user-agent"] ?? "",
@@ -49,6 +49,9 @@ function normalizeHonoRequest(c) {
49
49
  method: c.req.method
50
50
  };
51
51
  }
52
+ function stripIPv6Prefix(ip) {
53
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
54
+ }
52
55
  export {
53
56
  Bbloker,
54
57
  createMiddleware
@@ -39,7 +39,9 @@ function normalizeNextRequest(req) {
39
39
  headerNames.push(lower);
40
40
  });
41
41
  return {
42
- ip: _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(req.ip, () => ( _optionalChain([headers, 'access', _ => _["x-forwarded-for"], 'optionalAccess', _2 => _2.split, 'call', _3 => _3(","), 'access', _4 => _4[0], 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]))), () => ( headers["x-real-ip"])), () => ( "0.0.0.0")),
42
+ ip: stripIPv6Prefix(
43
+ _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([headers, 'access', _ => _["x-forwarded-for"], 'optionalAccess', _2 => _2.split, 'call', _3 => _3(","), 'access', _4 => _4[0], 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]), () => ( headers["x-real-ip"])), () => ( req.ip)), () => ( "0.0.0.0"))
44
+ ),
43
45
  userAgent: _nullishCoalesce(headers["user-agent"], () => ( "")),
44
46
  headers,
45
47
  headerNames,
@@ -47,6 +49,9 @@ function normalizeNextRequest(req) {
47
49
  method: req.method
48
50
  };
49
51
  }
52
+ function stripIPv6Prefix(ip) {
53
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
54
+ }
50
55
 
51
56
 
52
57
 
@@ -39,7 +39,9 @@ function normalizeNextRequest(req) {
39
39
  headerNames.push(lower);
40
40
  });
41
41
  return {
42
- ip: req.ip ?? headers["x-forwarded-for"]?.split(",")[0]?.trim() ?? headers["x-real-ip"] ?? "0.0.0.0",
42
+ ip: stripIPv6Prefix(
43
+ headers["x-forwarded-for"]?.split(",")[0]?.trim() ?? headers["x-real-ip"] ?? req.ip ?? "0.0.0.0"
44
+ ),
43
45
  userAgent: headers["user-agent"] ?? "",
44
46
  headers,
45
47
  headerNames,
@@ -47,6 +49,9 @@ function normalizeNextRequest(req) {
47
49
  method: req.method
48
50
  };
49
51
  }
52
+ function stripIPv6Prefix(ip) {
53
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
54
+ }
50
55
  export {
51
56
  Bbloker,
52
57
  createMiddleware
@@ -44,7 +44,7 @@ function normalizeNodeRequest(req) {
44
44
  headerNames.push(lower);
45
45
  }
46
46
  const forwarded = _optionalChain([headers, 'access', _ => _["x-forwarded-for"], 'optionalAccess', _2 => _2.split, 'call', _3 => _3(","), 'access', _4 => _4[0], 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]);
47
- const ip = _nullishCoalesce(_nullishCoalesce(forwarded, () => ( _optionalChain([req, 'access', _7 => _7.socket, 'optionalAccess', _8 => _8.remoteAddress]))), () => ( "0.0.0.0"));
47
+ const ip = stripIPv6Prefix(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(forwarded, () => ( headers["x-real-ip"])), () => ( _optionalChain([req, 'access', _7 => _7.socket, 'optionalAccess', _8 => _8.remoteAddress]))), () => ( "0.0.0.0")));
48
48
  return {
49
49
  ip,
50
50
  userAgent: _nullishCoalesce(headers["user-agent"], () => ( "")),
@@ -54,6 +54,9 @@ function normalizeNodeRequest(req) {
54
54
  method: _nullishCoalesce(req.method, () => ( "GET"))
55
55
  };
56
56
  }
57
+ function stripIPv6Prefix(ip) {
58
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
59
+ }
57
60
 
58
61
 
59
62
 
@@ -44,7 +44,7 @@ function normalizeNodeRequest(req) {
44
44
  headerNames.push(lower);
45
45
  }
46
46
  const forwarded = headers["x-forwarded-for"]?.split(",")[0]?.trim();
47
- const ip = forwarded ?? req.socket?.remoteAddress ?? "0.0.0.0";
47
+ const ip = stripIPv6Prefix(forwarded ?? headers["x-real-ip"] ?? req.socket?.remoteAddress ?? "0.0.0.0");
48
48
  return {
49
49
  ip,
50
50
  userAgent: headers["user-agent"] ?? "",
@@ -54,6 +54,9 @@ function normalizeNodeRequest(req) {
54
54
  method: req.method ?? "GET"
55
55
  };
56
56
  }
57
+ function stripIPv6Prefix(ip) {
58
+ return ip.startsWith("::ffff:") ? ip.slice(7) : ip;
59
+ }
57
60
  export {
58
61
  Bbloker,
59
62
  createHandler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbloker/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "description": "AI bot blocker SDK — shared intelligence network to detect and block AI crawlers",
6
6
  "sideEffects": false,